Android帧缓冲区(Frame Buffer)硬件抽象层(HAL)模块Gralloc的实现原理分析(5)
-
#define GRALLOC_HARDWARE_FB0 "fb0"
-
typedef struct framebuffer_device_t {
-
struct hw_device_t common;
-
-
/* flags describing some attributes of the framebuffer */
-
const uint32_t flags;
-
-
/* dimensions of the framebuffer in pixels */
-
const uint32_t width;
-
const uint32_t height;
-
-
/* frambuffer stride in pixels */
-
const int stride;
-
-
/* framebuffer pixel format */
-
const int format;
-
-
/* resolution of the framebuffer's display panel in pixel per inch*/
-
const float xdpi;
-
const float ydpi;
-
-
/* framebuffer's display panel refresh rate in frames per second */
-
const float fps;
-
-
/* min swap interval supported by this framebuffer */
-
const int minSwapInterval;
-
-
/* max swap interval supported by this framebuffer */
-
const int maxSwapInterval;
-
-
int reserved[8];
-
-
int (*setSwapInterval)(struct framebuffer_device_t* window,
-
int interval);
-
-
int (*setUpdateRect)(struct framebuffer_device_t* window,
-
int left, int top, int width, int height);
-
-
int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer);
-
-
int (*compositionComplete)(struct framebuffer_device_t* dev);
-
-
void* reserved_proc[8];
-
-
} framebuffer_device_t;
成员变量flags用来记录系统帧缓冲区的标志,目前没有使用这成员变量,它的值被设置为0。
-
static inline int framebuffer_open(const struct hw_module_t* module,
-
struct framebuffer_device_t** device) {
-
return module->methods->open(module,
-
GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device);
-
}
-
int gralloc_device_open(const hw_module_t* module, const char* name,
-
hw_device_t** device)
-
{
-
int status = -EINVAL;
-
if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) {
-
......
-
} else {
-
status = fb_device_open(module, name, device);
-
}
-
return status;
-
}
-
struct fb_context_t {
-
framebuffer_device_t device;
-
};
-
-
......
-
-
int fb_device_open(hw_module_t const* module, const char* name,
-
hw_device_t** device)
-
{
-
int status = -EINVAL;
-
if (!strcmp(name, GRALLOC_HARDWARE_FB0)) {
-
alloc_device_t* gralloc_device;
-
status = gralloc_open(module, &gralloc_device);
-
if (status < 0)
-
return status;
-
-
/* initialize our state here */
-
fb_context_t *dev = (fb_context_t*)malloc(sizeof(*dev));
-
memset(dev, 0, sizeof(*dev));
-
-
/* initialize the procs */
-
dev->device.common.tag = HARDWARE_DEVICE_TAG;
-
dev->device.common.version = 0;
-
dev->device.common.module = const_cast<hw_module_t*>(module);
-
dev->device.common.close = fb_close;
-
dev->device.setSwapInterval = fb_setSwapInterval;
-
dev->device.post = fb_post;
-
dev->device.setUpdateRect = 0;
-
-
private_module_t* m = (private_module_t*)module;
-
status = mapFrameBuffer(m);
-
if (status >= 0) {
-
int stride = m->finfo.line_length / (m->info.bits_per_pixel >> 3);
-
int format = (m->info.bits_per_pixel == 32)
-
? HAL_PIXEL_FORMAT_RGBX_8888
-
: HAL_PIXEL_FORMAT_RGB_565;
-
#ifdef NO_32BPP
-
format = HAL_PIXEL_FORMAT_RGB_565;
-
#endif
-
const_cast<uint32_t&>(dev->device.flags) = 0;
-
const_cast<uint32_t&>(dev->device.width) = m->info.xres;
-
const_cast<uint32_t&>(dev->device.height) = m->info.yres;
-
const_cast<int&>(dev->device.stride) = stride;
-
const_cast<int&>(dev->device.format) = format;
-
const_cast<float&>(dev->device.xdpi) = m->xdpi;
-
const_cast<float&>(dev->device.ydpi) = m->ydpi;
-
const_cast<float&>(dev->device.fps) = m->fps;
-
const_cast<int&>(dev->device.minSwapInterval) = 1;
-
const_cast<int&>(dev->device.maxSwapInterval) = 1;
-
*device = &dev->device.common;
-
}
-
}
-
return status;
-
}