android的gralloc模块,Gralloc模块分析

Linux内核提供了统一的framebuffer显示驱动。Framebuffer是内核系统提供的图形硬件的抽象描述,称为buffer是因为它也占用了系统存储空间的一部分,是一块包含屏幕显示信息的缓冲区。Framebuffer借助于Linux文件系统向上层应用提供了统一而高效的操作接口,让用户空间运行的程序比较容易地适配多种显示设备。

Android系统中,每个显示屏被抽象为一个帧缓冲区,注册到FrameBuffer模块中,并在/dev/graphics目录下创建对应的fbX设备,framebuffer提供的设备节点为/dev/graphics/fb或者/dev/fb,Android系统在硬件抽象层中提供了一个Gralloc模块,封装了对帧缓冲区的所有访问操作。用户空间的应用程序在使用帧缓冲区之间,首先要加载Gralloc模块,并且获得一个gralloc设备和一个fb设备。有了gralloc设备之后,用户空间中的应用程序就可以申请分配一块图形缓冲区,并且将这块图形缓冲区映射到应用程序的地址空间来,以便可以向里面写入要绘制的画面的内容。

Android 硬件抽象库的加载简介

Android系统,为了隐藏各厂家自身特定硬件驱动实现细节,在用户空间定义了一套硬件抽象层,各厂商在Android的硬件抽象层实现特定硬件的操作细节,编译成动态库,以库的形式提供给用户使用。

hardware/libhardware/include/hardware/hardware.h 头文件中定义一个代表模块的结构体 (hw_module_t),其中包含模块的版本、名称和作者等元数据。Android系统 会根据这些元数据来找到并正确加载 HAL 模块。

typedef struct hw_module_t {

/** tag must be initialized to HARDWARE_MODULE_TAG */

uint32_t tag;

uint16_t module_api_version;

uint16_t hal_api_version;

const char *id;

const char *name;

const char *author;

struct hw_module_methods_t* methods;

void* dso;

#ifdef __LP64__

uint64_t reserved[32-7];

#else

/** padding to 128 bytes, reserved for future use */

uint32_t reserved[32-7];

#endif

} hw_module_t;

hw_module_t 结构体还包含指向另一个结构体 hw_module_methods_t 的指针,后面这个结构体包含指向相应模块的 open 函数的指针。此 open 函数用于与相关硬件(此 HAL 是其抽象形式)建立通信。每个硬件专用 HAL 通常都会使用该特定硬件的附加信息来扩展通用的 hw_module_t 结构体。例如,在相机 HAL 中,camera_module_t 结构体包含一个 hw_module_t 结构体以及相机专用的其他函数指针:

typedef struct camera_module {

hw_module_t common;

int (*get_number_of_cameras)(void);

int (*get_camera_info)(int camera_id, struct camera_info *info);

} camera_module_t;

实现 HAL 并创建模块结构体时,您必须将其命名为 HAL_MODULE_INFO_SYM,以下是 Nexus 9 音频 HAL 的示例:

struct audio_module HAL_MODULE_INFO_SYM = {

.common = {

.tag = HARDWARE_MODULE_TAG,

.module_api_version = AUDIO_MODULE_API_VERSION_0_1,

.hal_api_version = HARDWARE_HAL_API_VERSION,

.id = AUDIO_HARDWARE_MODULE_ID,

.name = "NVIDIA Tegra Audio HAL",

.author = "The Android Open Source Project",

.methods = &hal_module_methods,

},

};

HAL 设备

设备是产品硬件的抽象表示。例如,一个音频模块可能包含主音频设备、USB 音频设备或蓝牙 A2DP 音频设备。

设备由 hw_device_t 结构体表示。与模块类似,每类设备都定义了一个通用 hw_device_t 的详细版本,其中包含指向特定硬件功能的函数指针。例如,audio_hw_device_t 结构体类型会包含指向音频设备操作的函数指针:

struct audio_hw_device {

struct hw_device_t common;

/**

* used by audio flinger to enumerate what devices are supported by

* each audio_hw_device implementation.

*

* Return value is a bitmask of 1 or more values of audio_devices_t

*/

uint32_t (*get_supported_devices)(const struct audio_hw_device *dev);

...

};

typedef struct audio_hw_device audio_hw_device_t;

如何加载硬件抽象层的动态库?

int hw_get_module(const char *id, const struct hw_module_t **module)

{

return hw_get_module_by_class(id, NULL, module);

}

参数为模块的ID,最终会返回一个hw_module_t的结构体保存在参数module中。

每个硬件抽象层模块都必须定义HAL_MODULE_INFO_SYM符号,并且有自己唯一的ID。

hw_get_module会遍历规定的几个目录来查找名称对应的动态库,找到库的路径后,会调用load函数使用dlopen打开找到的库,并依据HAL_MODULE_INFO_SYM_AS_STR(其值为HMI)获取到hw_module_t(即HAL_MODULE_INFO_SYM)结构体指针。以及把dlopen返回的handle保存在hw_module_t中,而hw_module_t HMI 结构是一个全局结构。

每个硬件抽象层必须有自己的ID以及HAL_MODULE_INFO_SYM符号,Gralloc也不例外

/**

* The id of this module

*/

#define GRALLOC_HARDWARE_MODULE_ID "gralloc"

struct private_module_t HAL_MODULE_INFO_SYM = {

.base = {

.common = {

.tag = HARDWARE_MODULE_TAG,

.version_major = 1,

.version_minor = 0,

.id = GRALLOC_HARDWARE_MODULE_ID,

.name = "Graphics Memory Allocator Module",

.author = "The Android Open Source Project",

.methods = &gralloc_module_methods

},

.registerBuffer = gralloc_register_buffer,

.unregisterBuffer = gralloc_unregister_buffer,

.lock = gralloc_lock,

.unlock = gralloc_unlock,

},

.framebuffer = 0,

.flags = 0,

.numBuffers = 0,

.bufferMask = 0,

.lock = PTHREAD_MUTEX_INITIALIZER,

.currentBuffer = 0,

};

hw_get_module硬件加载方法根据gralloc的ID, 查找到gralloc模块定义的HAL_MODULE_INFO_SYM并返回给hw_module_t结构,但是HAL_MODULE_INFO_SYM是private_module_t结构类型,如何赋值呢?

Gralloc模块数据结构分析

struct private_module_t {

gralloc_module_t base;

private_handle_t* framebuffer; //指向系统帧缓冲区的句柄

uint32_t flags; //用来标志系统帧缓冲区是否支持双缓冲

uint32_t numBuffers; //表示系统帧缓冲区包含有多少个图形缓冲区

uint32_t bufferMask; //记录系统帧缓冲区中的图形缓冲区的使用情况

pthread_mutex_t lock; //一个互斥锁,用来保护结构体private_module_t的并行访问

buffer_handle_t currentBuffer; //用来描述当前正在被渲染的图形缓冲区

int pmem_master;

void* pmem_master_base;

struct fb_var_screeninfo info; //保存设备显示屏的动态属性信息

struct fb_fix_screeninfo finfo; //保存设备显示屏的固定属性信息

float xdpi; //描述设备显示屏在宽度

float ydpi; //描述设备显示屏在高度

float fps; //用来描述显示屏的刷新频率

};

private_module_t负责管理显示驱动framebuffer相关的信息,包括framebuffer的fd, 有多少个缓存,系统帧缓冲区使用情况,动态可变的信息,固定属性的信息,显示屏的宽高,刷新率等信息。

private_module_t 第一个变量是gralloc_module_t结构。

typedef struct gralloc_module_t {

struct hw_module_t common;

//映射一块图形缓冲区到一个进程的地址空间去

int (*registerBuffer)(struct gralloc_module_t const* module,

buffer_handle_t handle);

//取消映射到一个进程的地址空间去的图形缓冲区

int (*unregisterBuffer)(struct gralloc_module_t const* module,

buffer_handle_t handle);

//锁定一个指定的图形缓冲区

int (*lock)(struct gralloc_module_t const* module,

buffer_handle_t handle, int usage,

int l, int t, int w, int h,

void** vaddr);

//解锁一个指定的图形缓冲区

int (*unlock)(struct gralloc_module_t const* module,

buffer_handle_t handle);

int (*perform)(struct gralloc_module_t const* module,

int operation, ... );

int (*lock_ycbcr)(struct gralloc_module_t const* module,

buffer_handle_t handle, int usage,

int l, int t, int w, int h,

struct android_ycbcr *ycbcr);

int (*lockAsync)(struct gralloc_module_t const* module,

buffer_handle_t handle, int usage,

int l, int t, int w, int h,

void** vaddr, int fenceFd);

int (*unlockAsync)(struct gralloc_module_t const* module,

buffer_handle_t handle, int* fenceFd);

int (*lockAsync_ycbcr)(struct gralloc_module_t const* module,

buffer_handle_t handle, int usage,

int l, int t, int w, int h,

struct android_ycbcr *ycbcr, int fenceFd);

/* reserved for future use */

void* reserved_proc[3];

} gralloc_module_t;

gralloc_module_t 负责管理gralloc模块相关的操作,其第一个是属性是硬件抽象层规定的hw_module_t结构,其他都是关于gralloc模块图像buffer处理的相关操作方法。

hw_module_t结构如下:

/**

* 任何一个硬件模块都必须有一个名称为 HAL_MODULE_INFO_SYM的数据结构

* 并且这个数据结构必须以hw_module_t为第一个元素,其后再跟随这个模块特有的信息

*/

typedef struct hw_module_t {

/** tag must be initialized to HARDWARE_MODULE_TAG */

uint32_t tag; //标签

uint16_t module_api_version; //模块主设备号

uint16_t hal_api_version; //模块从设备号

const char *id; //模块ID

const char *name; //名称

const char *author; //作者

struct hw_module_methods_t* methods; //操作模块的方法

void* dso; //模块首地址

uint64_t reserved[32-7]; //保留信息

} hw_module_t;

typedef struct hw_module_methods_t {

/** Open a specific device */

int (*open)(const struct hw_module_t* module, const char* id,

struct hw_device_t** device);

} hw_module_methods_t;

硬件抽象层hw_module_t结构描述了硬件抽象层库相关的信息。如版本号,id, 名称,相关的操作方法等。

其中还定义了模块的打开模块的操作方法open.

根据以上的三个结构我们可以画出结构图如下:

7f63b976da92

gralloc数据结构

回到上面问题,为什么private_module_t可以赋值给hw_module_t呢?这样看就很简单了,private_module_t的第一个变量就是gralloc_module_t, 而gralloc_module_t的数据第一个元素就是hw_module_t。private_module_t的首地址和hw_module_t的首地址是一样的,所以可以直接赋值过去。

除了hw_module_t的数据结构外,gralloc模块还定义了两种设备相关的数据结构:

1: framebuffer_device_t 用来描述系统帧缓冲区的信息

typedef struct framebuffer_device_t {

struct hw_device_t common;

const uint32_t flags;//用来记录系统帧缓冲区的标志

const uint32_t width;//用来描述设备显示屏的宽度

const uint32_t height;//用来描述设备显示屏的高度

const int stride;//用来描述设备显示屏的一行有多少个像素点

const int format;//用来描述系统帧缓冲区的像素格式

const float xdpi;//用来描述设备显示屏在宽度上的密度

const float ydpi;//用来描述设备显示屏在高度上的密度

const float fps;//用来描述设备显示屏的刷新频率

const int minSwapInterval;//用来描述帧缓冲区交换前后两个图形缓冲区的最小时间间隔

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);

//用来将图形缓冲区buffer的内容渲染到帧缓冲区中去

int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer);

//用来通知fb设备,图形缓冲区的组合工作已经完成

int (*compositionComplete)(struct framebuffer_device_t* dev);

void (*dump)(struct framebuffer_device_t* dev, char *buff, int buff_len);

int (*enableScreen)(struct framebuffer_device_t* dev, int enable);

//保留

void* reserved_proc[6];

2:alloc_device_t 用于描述图像分配相关的信息

typedef struct alloc_device_t {

struct hw_device_t common;

//用于分配一块图形缓冲区

int (*alloc)(struct alloc_device_t* dev,int w, int h, int format, int usage,buffer_handle_t* handle, int* stride);

//用于释放指定的图形缓冲区

int (*free)(struct alloc_device_t* dev,buffer_handle_t handle);

void (*dump)(struct alloc_device_t *dev, char *buff, int buff_len);

void* reserved_proc[7];

} alloc_device_t;

Gralloc设备打开过程分析

从上一节数据结构分析的过程中可知,设备打开的方法是在hw_module_t结构中定义的,定义打开的方法为

struct private_module_t HAL_MODULE_INFO_SYM = {

.base = {

.common = {

...

.methods = &gralloc_module_methods

},

....

},

...

};

static struct hw_module_methods_t gralloc_module_methods = {

.open = gralloc_device_open

};

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)) {

gralloc_context_t *dev;

dev = (gralloc_context_t*)malloc(sizeof(*dev));

/* initialize our state here */

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(module);

dev->device.common.close = gralloc_close;

dev->device.alloc = gralloc_alloc;

dev->device.free = gralloc_free;

*device = &dev->device.common;

status = 0;

} else {

status = fb_device_open(module, name, device);

}

return status;

}

gralloc_device_open方法用来打开设备

参数hw_module_t为硬件抽象层加载得到的结构体

name 为打开目标设备的类型,分为两种

1:GRALLOC_HARDWARE_FB0 "fb0"

打开framebuffer_device_t, 负责将图像缓冲区的内容渲染到帧缓冲区,显示到屏幕上

2:GRALLOC_HARDWARE_GPU0 "gpu0"

打开alloc_device_t,负责图像缓冲区的分配和释放

参数hw_device_t为打开的设备保存的结构,返回给调用者

分别分析下打开两种设备的过程

1:打开GRALLOC_HARDWARE_FB0的过程

gralloc_device_open根据参数的不同来打开不同的设备,打开设备GRALLOC_HARDWARE_FB0,调用了fb_device_open方法

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;

//判断设备名称是否是GRALLOC_HARDWARE_FB0,如果不是的直接返回打开失败

if (!strcmp(name, GRALLOC_HARDWARE_FB0)) {

//初始化设备framebuffer的上下文结构

fb_context_t *dev = (fb_context_t*)malloc(sizeof(*dev));

memset(dev, 0, sizeof(*dev));

//初始化设备相关的变量

dev->device.common.tag = HARDWARE_DEVICE_TAG;

dev->device.common.version = 0;

dev->device.common.module = const_cast(module);

//初始化fb相关的操作函数

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;

//将fb映射到当前进程的地址空间

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)

? (m->info.red.offset ? HAL_PIXEL_FORMAT_BGRA_8888 : HAL_PIXEL_FORMAT_RGBX_8888)

: HAL_PIXEL_FORMAT_RGB_565;

const_cast(dev->device.flags) = 0;

const_cast(dev->device.width) = m->info.xres;

const_cast(dev->device.height) = m->info.yres;

const_cast(dev->device.stride) = stride;

const_cast(dev->device.format) = format;

const_cast(dev->device.xdpi) = m->xdpi;

const_cast(dev->device.ydpi) = m->ydpi;

const_cast(dev->device.fps) = m->fps;

const_cast(dev->device.minSwapInterval) = 1;

const_cast(dev->device.maxSwapInterval) = 1;

*device = &dev->device.common;

}

}

return status;

}

这个函数创建了一个fb_context_t的数据结构, 并对其进行初始化,fb_context_t的device变量就是framebuffer_device_t,用来描述fb设备的。

同时还注册了操作fb设备的几个函数, 其中fb_post函数比较关键,负责将图形缓冲区的内容渲染到Framebuffer的显存中。

然后使用mapFrameBuffer函数来获取帧缓冲区的信息,然后将信息保存到framebuffer_device_t结构中,并将fb设备映射到当前进程。

再看下mapFrameBuffer做了什么操作?

int mapFrameBufferLocked(struct private_module_t* module)

{

// framebuffer设备已经初始化则直接返回

if (module->framebuffer) {

return 0;

}

//从"/dev/graphics/和/dev/目录查找fb设备,并打开

char const * const device_template[] = {

"/dev/graphics/fb%u",

"/dev/fb%u",

0 };

int fd = -1;

int i=0;

char name[64];

while ((fd==-1) && device_template[i]) {

snprintf(name, 64, device_template[i], 0);

fd = open(name, O_RDWR, 0);

i++;

}

if (fd < 0)

return -errno;

//获取framebuffer设备的不可变的信息

struct fb_fix_screeninfo finfo;

if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1)

return -errno;

//获取framebuffer设备的可变信息

struct fb_var_screeninfo info;

if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1)

return -errno;

info.reserved[0] = 0;

info.reserved[1] = 0;

info.reserved[2] = 0;

info.xoffset = 0;

info.yoffset = 0;

info.activate = FB_ACTIVATE_NOW;

//fb_var_screeninfo的成员变量xres和yres用来描述显示屏的可视分辨率,而成员变量xres_virtual和

yres_virtual用来描述显示屏的虚拟分辨率。

//将虚拟分辨率的高度值设置为可视分辨率的高度值的NUM_BUFFERS倍

//当前声明为双缓存

info.yres_virtual = info.yres * NUM_BUFFERS;

//默认为双缓冲,如果不支持,则移除双缓冲的标志flag

uint32_t flags = PAGE_FLIP;

#if USE_PAN_DISPLAY

if (ioctl(fd, FBIOPAN_DISPLAY, &info) == -1) {

ALOGW("FBIOPAN_DISPLAY failed, page flipping not supported");

#else

if (ioctl(fd, FBIOPUT_VSCREENINFO, &info) == -1) {

ALOGW("FBIOPUT_VSCREENINFO failed, page flipping not supported");

#endif

info.yres_virtual = info.yres;

flags &= ~PAGE_FLIP;

}

if (info.yres_virtual < info.yres * 2) {

// we need at least 2 for page-flipping

info.yres_virtual = info.yres;

flags &= ~PAGE_FLIP;

ALOGW("page flipping not supported (yres_virtual=%d, requested=%d)",

info.yres_virtual, info.yres*2);

}

if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1)

return -errno;

//计算屏幕刷新频率

uint64_t refreshQuotient =

(

uint64_t( info.upper_margin + info.lower_margin + info.yres )

* ( info.left_margin + info.right_margin + info.xres )

* info.pixclock

);

/* Beware, info.pixclock might be 0 under emulation, so avoid a

* division-by-0 here (SIGFPE on ARM) */

int refreshRate = refreshQuotient > 0 ? (int)(1000000000000000LLU / refreshQuotient) : 0;

if (refreshRate == 0) {

// bleagh, bad info from the driver

refreshRate = 60*1000; // 60 Hz

}

//计算显示器像素密度

if (int(info.width) <= 0 || int(info.height) <= 0) {

// the driver doesn't return that information

// default to 160 dpi

info.width = ((info.xres * 25.4f)/160.0f + 0.5f);

info.height = ((info.yres * 25.4f)/160.0f + 0.5f);

}

float xdpi = (info.xres * 25.4f) / info.width;

float ydpi = (info.yres * 25.4f) / info.height;

float fps = refreshRate / 1000.0f;

//再次通过IO控制命令FBIOGET_FSCREENINFO来获得系统帧缓冲区的固定信息

if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1)

return -errno;

if (finfo.smem_len <= 0)

return -errno;

//得到的系统帧缓冲区的其它信息来初始化参数module所描述的一个private_module_t结构体

module->flags = flags;

module->info = info;

module->finfo = finfo;

module->xdpi = xdpi;

module->ydpi = ydpi;

module->fps = fps;

//整个系统帧缓冲区的大小=虚拟分辨率的高度值info.yres_virtual * 每一行所占用的字节数finfo.line_length,并将整个系统帧缓冲区的大小对齐到页面边界

int err;

size_t fbSize = roundUpToPageSize(finfo.line_length * info.yres_virtual);

//创建一个private_handle_t,用来描述整个系统帧缓冲区的信息

module->framebuffer = new private_handle_t(dup(fd), fbSize, 0);

//计算整个系统帧缓冲区可以划分为多少个图形缓冲区来使用

module->numBuffers = info.yres_virtual / info.yres;

//初始化所有缓冲区为空闲状态

module->bufferMask = 0;

//将帧缓冲区映射到当前进程地址空间中

void* vaddr = mmap(0, fbSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

if (vaddr == MAP_FAILED) {

ALOGE("Error mapping the framebuffer (%s)", strerror(errno));

return -errno;

}

//系统帧缓冲区在当前进程的地址空间中的起始地址保存到private_handle_t的域base中

module->framebuffer->base = intptr_t(vaddr);

//清空缓冲区的内存空间

memset(vaddr, 0, fbSize);

return 0;

}

mapFrameBuffer函数做了几件事情

1:打开fb设备,获取fb驱动的相关信息

2:设置fb的 yres_virtual为双缓冲大小

3:计算像素密度

4:计算双缓冲大小,并将其映射到当前进程,将缓冲区起始地址宝尊在framebuffer_device_t的base属性中。

至此FB设备打开过程就分析完了,FB设备打开过程做了什么事情?

打开fb设备,根据fb设备初始化相关的显示信息,并把fb设备显存映射到当前进程方便访问,同时还注册了几个操作fb设备的方法。

打开GRALLOC_HARDWARE_GPU0的过程

gralloc设备使用结构体alloc_device_t来描述。结构体alloc_device_t有两个成员函数alloc和free,分别用来分配和释放图形缓冲区。

if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) {

gralloc_context_t *dev;

dev = (gralloc_context_t*)malloc(sizeof(*dev));

/* initialize our state here */

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(module);

dev->device.common.close = gralloc_close;

dev->device.alloc = gralloc_alloc;

dev->device.free = gralloc_free;

*device = &dev->device.common;

status = 0;

}

首先创建了一个gralloc_context_t的上下文,gralloc_context_t的device就是alloc_device_t, 对其进行初始化 ,同时注册了几个操作alloc_device_t设备的函数, gralloc_alloc和gralloc_free用于分配和释放图形缓冲区。

什么地方打开了这两种设备?

分析了两种设备打开的过程, 但是什么时候会打开这两种设备呢?

1:FB设备打开时机

// Load and prepare the FB HAL, which uses the gralloc module. Sets mFbDev.

int HWComposer::loadFbHalModule()

{

hw_module_t const* module;

int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);

if (err != 0) {

ALOGE("%s module not found", GRALLOC_HARDWARE_MODULE_ID);

return err;

}

return framebuffer_open(module, &mFbDev);

}

FB设备打开时机实在HWCompser构造函数中打开的,说明HWCompser会操作fb设备,渲染图像缓冲区到显示缓冲区, 具体在分析HWCompser的时候在进行分析。

2:gralloc设备打开时机

GraphicBufferAllocator::GraphicBufferAllocator()

: mAllocDev(0)

{

hw_module_t const* module;

int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);

ALOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID);

if (err == 0) {

gralloc_open(module, &mAllocDev);

}

}

gralloc设备用于管理GraphicBuffer图形缓冲区,是在GraphicBufferAllocator中打开的,GraphicBufferAllocator负责图形缓冲区的分配和释放。后续在做详细分析

文章参考:Android图形显示之硬件抽象层Gralloc

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值