am 23839223: Merge "emulator gralloc: Make the cb_handle_t::validate static"

* commit '23839223b97e2bba2091627a90bbc2a9454545c1':
  emulator gralloc: Make the cb_handle_t::validate static
This commit is contained in:
David Turner
2011-07-01 03:17:42 -07:00
committed by Android Git Automerger
2 changed files with 16 additions and 10 deletions

View File

@@ -53,10 +53,11 @@ struct cb_handle_t : public native_handle {
numInts = CB_HANDLE_NUM_INTS(numFds); numInts = CB_HANDLE_NUM_INTS(numFds);
} }
bool validate() const { static bool validate(cb_handle_t * hnd) {
return (version == sizeof(native_handle) && return (hnd &&
magic == BUFFER_HANDLE_MAGIC && hnd->version == sizeof(native_handle) &&
numInts == CB_HANDLE_NUM_INTS(numFds)); hnd->magic == BUFFER_HANDLE_MAGIC &&
hnd->numInts == CB_HANDLE_NUM_INTS(hnd->numFds));
} }
bool canBePosted() { bool canBePosted() {

View File

@@ -245,7 +245,8 @@ static int gralloc_free(alloc_device_t* dev,
buffer_handle_t handle) buffer_handle_t handle)
{ {
const cb_handle_t *cb = (const cb_handle_t *)handle; const cb_handle_t *cb = (const cb_handle_t *)handle;
if (!cb || !cb->validate()) { if (!cb_handle_t::validate((cb_handle_t*)cb)) {
ERR("gralloc_free: invalid handle");
return -EINVAL; return -EINVAL;
} }
@@ -322,7 +323,7 @@ static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer)
fb_device_t *fbdev = (fb_device_t *)dev; fb_device_t *fbdev = (fb_device_t *)dev;
cb_handle_t *cb = (cb_handle_t *)buffer; cb_handle_t *cb = (cb_handle_t *)buffer;
if (!fbdev || !cb || !cb->validate() || !cb->canBePosted()) { if (!fbdev || !cb_handle_t::validate(cb) || !cb->canBePosted()) {
return -EINVAL; return -EINVAL;
} }
@@ -402,7 +403,8 @@ static int gralloc_register_buffer(gralloc_module_t const* module,
{ {
private_module_t *gr = (private_module_t *)module; private_module_t *gr = (private_module_t *)module;
cb_handle_t *cb = (cb_handle_t *)handle; cb_handle_t *cb = (cb_handle_t *)handle;
if (!gr || !cb || !cb->validate()) { if (!gr || !cb_handle_t::validate(cb)) {
ERR("gralloc_register_buffer: invalid buffer");
return -EINVAL; return -EINVAL;
} }
@@ -414,6 +416,7 @@ static int gralloc_register_buffer(gralloc_module_t const* module,
void *vaddr; void *vaddr;
int err = map_buffer(cb, &vaddr); int err = map_buffer(cb, &vaddr);
if (err) { if (err) {
ERR("gralloc_register_buffer: map failed");
return -err; return -err;
} }
cb->mappedPid = getpid(); cb->mappedPid = getpid();
@@ -427,7 +430,8 @@ static int gralloc_unregister_buffer(gralloc_module_t const* module,
{ {
private_module_t *gr = (private_module_t *)module; private_module_t *gr = (private_module_t *)module;
cb_handle_t *cb = (cb_handle_t *)handle; cb_handle_t *cb = (cb_handle_t *)handle;
if (!gr || !cb || !cb->validate()) { if (!gr || !cb_handle_t::validate(cb)) {
ERR("gralloc_unregister_buffer: invalid buffer");
return -EINVAL; return -EINVAL;
} }
@@ -439,6 +443,7 @@ static int gralloc_unregister_buffer(gralloc_module_t const* module,
void *vaddr; void *vaddr;
int err = munmap((void *)cb->ashmemBase, cb->ashmemSize); int err = munmap((void *)cb->ashmemBase, cb->ashmemSize);
if (err) { if (err) {
ERR("gralloc_unregister_buffer: unmap failed");
return -EINVAL; return -EINVAL;
} }
cb->ashmemBase = NULL; cb->ashmemBase = NULL;
@@ -455,7 +460,7 @@ static int gralloc_lock(gralloc_module_t const* module,
{ {
private_module_t *gr = (private_module_t *)module; private_module_t *gr = (private_module_t *)module;
cb_handle_t *cb = (cb_handle_t *)handle; cb_handle_t *cb = (cb_handle_t *)handle;
if (!gr || !cb || !cb->validate()) { if (!gr || !cb_handle_t::validate(cb)) {
LOGE("gralloc_lock bad handle\n"); LOGE("gralloc_lock bad handle\n");
return -EINVAL; return -EINVAL;
} }
@@ -543,7 +548,7 @@ static int gralloc_unlock(gralloc_module_t const* module,
{ {
private_module_t *gr = (private_module_t *)module; private_module_t *gr = (private_module_t *)module;
cb_handle_t *cb = (cb_handle_t *)handle; cb_handle_t *cb = (cb_handle_t *)handle;
if (!gr || !cb || !cb->validate()) { if (!gr || !cb_handle_t::validate(cb)) {
return -EINVAL; return -EINVAL;
} }