author: "The Android Open Source Project",
methods: &gralloc_module_methods
},
-registerBuffer: gralloc_register_buffer,
- unregisterBuffer: gralloc_unregister_buffer,
- lock: gralloc_lock,
- unlock: gralloc_unlock,
+ 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,
- ionfd: -1,
+ framebuffer: 0,
+ flags: 0,
+ numBuffers: 0,
+ bufferMask: 0,
+ lock: PTHREAD_MUTEX_INITIALIZER,
+ currentBuffer: 0,
+ ionfd: -1,
};
/*****************************************************************************/
ion_flags, &fd2);
if (err)
goto err2;
- }
- *hnd = new private_handle_t(fd, fd1, fd2, luma_size, usage, w, h, format,
- *stride, luma_vstride);
+ *hnd = new private_handle_t(fd, fd1, fd2, luma_size, usage, w, h,
+ format, *stride, luma_vstride);
+ } else {
+ *hnd = new private_handle_t(fd, fd1, luma_size, usage, w, h, format,
+ *stride, luma_vstride);
+ }
return err;
err2:
return 0;
err:
close(hnd->fd);
- if (hnd->fd1 > 0)
+ if (hnd->fd1 >= 0)
close(hnd->fd1);
- if (hnd->fd2 > 0)
+ if (hnd->fd2 >= 0)
close(hnd->fd2);
return err;
}
grallocUnmap(module, const_cast<private_handle_t*>(hnd));
close(hnd->fd);
- if (hnd->fd1 > 0)
+ if (hnd->fd1 >= 0)
close(hnd->fd1);
- if (hnd->fd2 > 0)
+ if (hnd->fd2 >= 0)
close(hnd->fd2);
delete hnd;
return gralloc_unmap(module, hnd);
}
+int getIonFd(gralloc_module_t const *module)
+{
+ private_module_t* m = const_cast<private_module_t*>(reinterpret_cast<const private_module_t*>(module));
+ if (m->ionfd == -1)
+ m->ionfd = ion_open();
+ return m->ionfd;
+}
+
static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER;
/*****************************************************************************/
private_handle_t* hnd = (private_handle_t*)handle;
ALOGV("%s: base %p %d %d %d %d\n", __func__, hnd->base, hnd->size,
hnd->width, hnd->height, hnd->stride);
+
+ int ret;
+ ret = ion_import(getIonFd(module), hnd->fd, &hnd->handle);
+ if (ret)
+ ALOGE("error importing handle %d %x\n", hnd->fd, hnd->format);
+ if (hnd->fd1 >= 0) {
+ ret = ion_import(getIonFd(module), hnd->fd1, &hnd->handle1);
+ if (ret)
+ ALOGE("error importing handle1 %d %x\n", hnd->fd1, hnd->format);
+ }
+ if (hnd->fd2 >= 0) {
+ ret = ion_import(getIonFd(module), hnd->fd2, &hnd->handle2);
+ if (ret)
+ ALOGE("error importing handle2 %d %x\n", hnd->fd2, hnd->format);
+ }
+
return err;
}
gralloc_unmap(module, handle);
+ if (hnd->handle)
+ ion_free(getIonFd(module), hnd->handle);
+ if (hnd->handle1)
+ ion_free(getIonFd(module), hnd->handle1);
+ if (hnd->handle2)
+ ion_free(getIonFd(module), hnd->handle2);
+
return 0;
}
// FIXME: the attributes below should be out-of-line
void *base;
+ void *base1;
+ void *base2;
+ struct ion_handle *handle;
+ struct ion_handle *handle1;
+ struct ion_handle *handle2;
#ifdef __cplusplus
static const int sNumFds = 3;
- static const int sNumInts = 10;
+ static const int sNumInts = 15;
static const int sMagic = 0x3141592;
private_handle_t(int fd, int size, int flags, int w,
int h, int format, int stride, int vstride) :
- fd(fd), magic(sMagic), flags(flags), size(size),
+ fd(fd), fd1(-1), fd2(-1), magic(sMagic), flags(flags), size(size),
offset(0), format(format), width(w), height(h), stride(stride),
- vstride(vstride), base(0)
+ vstride(vstride), base(0), handle(0), handle1(0), handle2(0)
{
version = sizeof(native_handle);
- numInts = sNumInts;
- numFds = sNumFds;
- fd1 = 0;
- fd2 = 0;
+ numInts = sNumInts + 2;
+ numFds = sNumFds - 2;
+ }
+
+ private_handle_t(int fd, int fd1, int size, int flags, int w,
+ int h, int format, int stride, int vstride) :
+ fd(fd), fd1(fd1), fd2(-1), magic(sMagic), flags(flags), size(size),
+ offset(0), format(format), width(w), height(h), stride(stride),
+ vstride(vstride), base(0), base1(0), base2(0), handle(0), handle1(0),
+ handle2(0)
+ {
+ version = sizeof(native_handle);
+ numInts = sNumInts + 1;
+ numFds = sNumFds - 1;
}
private_handle_t(int fd, int fd1, int fd2, int size, int flags, int w,
int h, int format, int stride, int vstride) :
fd(fd), fd1(fd1), fd2(fd2), magic(sMagic), flags(flags), size(size),
offset(0), format(format), width(w), height(h), stride(stride),
- vstride(vstride), base(0)
+ vstride(vstride), base(0), base1(0), base2(0), handle(0), handle1(0),
+ handle2(0)
{
version = sizeof(native_handle);
numInts = sNumInts;
static int validate(const native_handle* h) {
const private_handle_t* hnd = (const private_handle_t*)h;
if (!h || h->version != sizeof(native_handle) ||
- h->numInts != sNumInts || h->numFds != sNumFds ||
- hnd->magic != sMagic)
+ hnd->numInts + hnd->numFds != sNumInts + sNumFds ||
+ hnd->magic != sMagic)
{
ALOGE("invalid gralloc handle (at %p)", reinterpret_cast<void *>(const_cast<native_handle *>(h)));
return -EINVAL;