2 * Copyright (C) 2011 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <cutils/ashmem.h>
24 #include "gralloc_cb.h"
25 #include "HostConnection.h"
26 #include "ProcessPipe.h"
28 #include <cutils/log.h>
29 #include <cutils/properties.h>
31 /* Set to 1 or 2 to enable debug traces */
35 # define D(...) ALOGD(__VA_ARGS__)
37 # define D(...) ((void)0)
41 # define DD(...) ALOGD(__VA_ARGS__)
43 # define DD(...) ((void)0)
46 #define DBG_FUNC DBG("%s\n", __FUNCTION__)
49 // our private gralloc module structure
51 struct private_module_t {
52 gralloc_module_t base;
55 /* If not NULL, this is a pointer to the fallback module.
56 * This really is gralloc.default, which we'll use if we detect
57 * that the emulator we're running in does not support GPU emulation.
59 static gralloc_module_t* sFallback;
60 static pthread_once_t sFallbackOnce = PTHREAD_ONCE_INIT;
62 static void fallback_init(void); // forward
65 typedef struct _alloc_list_node {
66 buffer_handle_t handle;
67 _alloc_list_node *next;
68 _alloc_list_node *prev;
72 // Our gralloc device structure (alloc interface)
74 struct gralloc_device_t {
75 alloc_device_t device;
77 AllocListNode *allocListHead; // double linked list of allocated buffers
82 // Our framebuffer device structure
85 framebuffer_device_t device;
88 static int map_buffer(cb_handle_t *cb, void **vaddr)
90 if (cb->fd < 0 || cb->ashmemSize <= 0) {
94 void *addr = mmap(0, cb->ashmemSize, PROT_READ | PROT_WRITE,
95 MAP_SHARED, cb->fd, 0);
96 if (addr == MAP_FAILED) {
100 cb->ashmemBase = intptr_t(addr);
101 cb->ashmemBasePid = getpid();
107 #define DEFINE_HOST_CONNECTION \
108 HostConnection *hostCon = HostConnection::get(); \
109 renderControl_encoder_context_t *rcEnc = (hostCon ? hostCon->rcEncoder() : NULL)
111 #define EXIT_GRALLOCONLY_HOST_CONNECTION \
112 HostConnection *hostCon = HostConnection::get(); \
113 if (hostCon && hostCon->isGrallocOnly()) { \
114 ALOGD("%s: exiting HostConnection (is buffer-handling thread)", \
116 HostConnection::exit(); \
119 #define DEFINE_AND_VALIDATE_HOST_CONNECTION \
120 HostConnection *hostCon = HostConnection::get(); \
122 ALOGE("gralloc: Failed to get host connection\n"); \
125 renderControl_encoder_context_t *rcEnc = hostCon->rcEncoder(); \
127 ALOGE("gralloc: Failed to get renderControl encoder context\n"); \
131 #if PLATFORM_SDK_VERSION < 18
132 // On older APIs, just define it as a value no one is going to use.
133 #define HAL_PIXEL_FORMAT_YCbCr_420_888 0xFFFFFFFF
137 // gralloc device functions (alloc interface)
139 static int gralloc_alloc(alloc_device_t* dev,
140 int w, int h, int format, int usage,
141 buffer_handle_t* pHandle, int* pStride)
143 D("gralloc_alloc w=%d h=%d usage=0x%x format=0x%x\n", w, h, usage, format);
145 gralloc_device_t *grdev = (gralloc_device_t *)dev;
146 if (!grdev || !pHandle || !pStride) {
147 ALOGE("gralloc_alloc: Bad inputs (grdev: %p, pHandle: %p, pStride: %p",
148 grdev, pHandle, pStride);
153 // Note: in screen capture mode, both sw_write and hw_write will be on
154 // and this is a valid usage
156 bool sw_write = (0 != (usage & GRALLOC_USAGE_SW_WRITE_MASK));
157 bool hw_write = (usage & GRALLOC_USAGE_HW_RENDER);
158 bool sw_read = (0 != (usage & GRALLOC_USAGE_SW_READ_MASK));
159 #if PLATFORM_SDK_VERSION >= 17
160 bool hw_cam_write = (usage & GRALLOC_USAGE_HW_CAMERA_WRITE);
161 bool hw_cam_read = (usage & GRALLOC_USAGE_HW_CAMERA_READ);
162 #else // PLATFORM_SDK_VERSION
163 bool hw_cam_write = false;
164 bool hw_cam_read = false;
165 #endif // PLATFORM_SDK_VERSION
166 #if PLATFORM_SDK_VERSION >= 15
167 bool hw_vid_enc_read = usage & GRALLOC_USAGE_HW_VIDEO_ENCODER;
168 #else // PLATFORM_SDK_VERSION
169 bool hw_vid_enc_read = false;
170 #endif // PLATFORM_SDK_VERSION
172 // Keep around original requested format for later validation
173 int frameworkFormat = format;
174 // Pick the right concrete pixel format given the endpoints as encoded in
175 // the usage bits. Every end-point pair needs explicit listing here.
176 #if PLATFORM_SDK_VERSION >= 17
177 if (format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
178 // Camera as producer
179 if (usage & GRALLOC_USAGE_HW_CAMERA_WRITE) {
180 if (usage & GRALLOC_USAGE_HW_TEXTURE) {
181 // Camera-to-display is RGBA
182 format = HAL_PIXEL_FORMAT_RGBA_8888;
183 } else if (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) {
184 // Camera-to-encoder is NV21
185 format = HAL_PIXEL_FORMAT_YCrCb_420_SP;
186 } else if ((usage & GRALLOC_USAGE_HW_CAMERA_MASK) ==
187 GRALLOC_USAGE_HW_CAMERA_ZSL) {
188 // Camera-to-ZSL-queue is RGB_888
189 format = HAL_PIXEL_FORMAT_RGB_888;
193 if (format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
194 ALOGE("gralloc_alloc: Requested auto format selection, "
195 "but no known format for this usage: %d x %d, usage %x",
200 else if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
201 ALOGW("gralloc_alloc: Requested YCbCr_420_888, taking experimental path. "
202 "usage: %d x %d, usage %x",
205 #endif // PLATFORM_SDK_VERSION >= 17
206 bool yuv_format = false;
217 case HAL_PIXEL_FORMAT_RGBA_8888:
218 case HAL_PIXEL_FORMAT_RGBX_8888:
219 case HAL_PIXEL_FORMAT_BGRA_8888:
222 glType = GL_UNSIGNED_BYTE;
224 case HAL_PIXEL_FORMAT_RGB_888:
227 glType = GL_UNSIGNED_BYTE;
229 case HAL_PIXEL_FORMAT_RGB_565:
232 glType = GL_UNSIGNED_SHORT_5_6_5;
234 #if PLATFORM_SDK_VERSION >= 21
235 case HAL_PIXEL_FORMAT_RAW16:
236 case HAL_PIXEL_FORMAT_Y16:
237 #elif PLATFORM_SDK_VERSION >= 16
238 case HAL_PIXEL_FORMAT_RAW_SENSOR:
242 if (! ((sw_read || hw_cam_read) && (sw_write || hw_cam_write) ) ) {
243 // Raw sensor data or Y16 only goes between camera and CPU
246 // Not expecting to actually create any GL surfaces for this
247 glFormat = GL_LUMINANCE;
248 glType = GL_UNSIGNED_SHORT;
250 #if PLATFORM_SDK_VERSION >= 17
251 case HAL_PIXEL_FORMAT_BLOB:
253 if (! (sw_read && hw_cam_write) ) {
254 // Blob data cannot be used by HW other than camera emulator
257 // Not expecting to actually create any GL surfaces for this
258 glFormat = GL_LUMINANCE;
259 glType = GL_UNSIGNED_BYTE;
261 #endif // PLATFORM_SDK_VERSION >= 17
262 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
264 bpp = 1; // per-channel bpp
266 // Not expecting to actually create any GL surfaces for this
268 case HAL_PIXEL_FORMAT_YV12:
270 bpp = 1; // per-channel bpp
272 // We are going to use RGB888 on the host
274 glType = GL_UNSIGNED_BYTE;
276 case HAL_PIXEL_FORMAT_YCbCr_420_888:
277 ALOGD("%s: 420_888 format experimental path. "
278 "Initialize rgb565 gl format\n", __FUNCTION__);
280 bpp = 1; // per-channel bpp
282 // We are going to use RGB888 on the host
284 glType = GL_UNSIGNED_BYTE;
287 ALOGE("gralloc_alloc: Unknown format %d", format);
291 if (usage & GRALLOC_USAGE_HW_FB) {
292 // keep space for postCounter
293 ashmem_size += sizeof(uint32_t);
296 if (sw_read || sw_write || hw_cam_write || hw_vid_enc_read) {
297 // keep space for image on guest memory if SW access is needed
298 // or if the camera is doing writing
300 size_t yStride = (w*bpp + (align - 1)) & ~(align-1);
301 size_t uvStride = (yStride / 2 + (align - 1)) & ~(align-1);
302 size_t uvHeight = h / 2;
303 ashmem_size += yStride * h + 2 * (uvHeight * uvStride);
304 stride = yStride / bpp;
306 size_t bpr = (w*bpp + (align-1)) & ~(align-1);
307 ashmem_size += (bpr * h);
312 D("gralloc_alloc format=%d, ashmem_size=%d, stride=%d, tid %d\n", format,
313 ashmem_size, stride, gettid());
316 // Allocate space in ashmem if needed
319 if (ashmem_size > 0) {
320 // round to page size;
321 ashmem_size = (ashmem_size + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
323 fd = ashmem_create_region("gralloc-buffer", ashmem_size);
325 ALOGE("gralloc_alloc failed to create ashmem region: %s\n",
331 cb_handle_t *cb = new cb_handle_t(fd, ashmem_size, usage,
332 w, h, frameworkFormat, format,
335 if (ashmem_size > 0) {
337 // map ashmem region if exist
340 int err = map_buffer(cb, &vaddr);
351 // Allocate ColorBuffer handle on the host (only if h/w access is allowed)
352 // Only do this for some h/w usages, not all.
353 // Also do this if we need to read from the surface, in this case the
354 // rendering will still happen on the host but we also need to be able to
355 // read back from the color buffer, which requires that there is a buffer
358 frameworkFormat == HAL_PIXEL_FORMAT_YV12 ||
359 frameworkFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) {
360 #if PLATFORM_SDK_VERSION >= 15
361 if (usage & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER |
362 GRALLOC_USAGE_HW_2D | GRALLOC_USAGE_HW_COMPOSER |
363 GRALLOC_USAGE_HW_VIDEO_ENCODER |
364 GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_SW_READ_MASK) ) {
365 #else // PLATFORM_SDK_VERSION
366 if (usage & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER |
367 GRALLOC_USAGE_HW_2D |
368 GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_SW_READ_MASK) ) {
369 #endif // PLATFORM_SDK_VERSION
370 ALOGD("%s: format %d and usage 0x%x imply creation of host color buffer",
371 __FUNCTION__, frameworkFormat, usage);
372 DEFINE_HOST_CONNECTION;
373 if (hostCon && rcEnc) {
374 cb->hostHandle = rcEnc->rcCreateColorBuffer(rcEnc, w, h, glFormat);
375 D("Created host ColorBuffer 0x%x\n", cb->hostHandle);
378 if (!cb->hostHandle) {
379 // Could not create colorbuffer on host !!!
382 ALOGD("%s: failed to create host cb! -EIO", __FUNCTION__);
389 // alloc succeeded - insert the allocated handle to the allocated list
391 AllocListNode *node = new AllocListNode();
392 pthread_mutex_lock(&grdev->lock);
394 node->next = grdev->allocListHead;
396 if (grdev->allocListHead) {
397 grdev->allocListHead->prev = node;
399 grdev->allocListHead = node;
400 pthread_mutex_unlock(&grdev->lock);
403 switch (frameworkFormat) {
404 case HAL_PIXEL_FORMAT_YCbCr_420_888:
414 static int gralloc_free(alloc_device_t* dev,
415 buffer_handle_t handle)
417 const cb_handle_t *cb = (const cb_handle_t *)handle;
418 if (!cb_handle_t::validate((cb_handle_t*)cb)) {
419 ERR("gralloc_free: invalid handle");
423 if (cb->hostHandle != 0) {
424 DEFINE_AND_VALIDATE_HOST_CONNECTION;
425 D("Closing host ColorBuffer 0x%x\n", cb->hostHandle);
426 rcEnc->rcCloseColorBuffer(rcEnc, cb->hostHandle);
430 // detach and unmap ashmem area if present
433 if (cb->ashmemSize > 0 && cb->ashmemBase) {
434 munmap((void *)cb->ashmemBase, cb->ashmemSize);
439 // remove it from the allocated list
440 gralloc_device_t *grdev = (gralloc_device_t *)dev;
441 pthread_mutex_lock(&grdev->lock);
442 AllocListNode *n = grdev->allocListHead;
443 while( n && n->handle != cb ) {
447 // buffer found on list - remove it from list
449 n->next->prev = n->prev;
452 n->prev->next = n->next;
455 grdev->allocListHead = n->next;
460 pthread_mutex_unlock(&grdev->lock);
467 static int gralloc_device_close(struct hw_device_t *dev)
469 gralloc_device_t* d = reinterpret_cast<gralloc_device_t*>(dev);
472 // free still allocated buffers
473 while( d->allocListHead != NULL ) {
474 gralloc_free(&d->device, d->allocListHead->handle);
483 static int fb_compositionComplete(struct framebuffer_device_t* dev)
491 // Framebuffer device functions
493 static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer)
495 fb_device_t *fbdev = (fb_device_t *)dev;
496 cb_handle_t *cb = (cb_handle_t *)buffer;
498 if (!fbdev || !cb_handle_t::validate(cb) || !cb->canBePosted()) {
502 // Make sure we have host connection
503 DEFINE_AND_VALIDATE_HOST_CONNECTION;
505 // increment the post count of the buffer
506 intptr_t *postCountPtr = (intptr_t *)cb->ashmemBase;
508 // This should not happen
513 // send post request to host
514 rcEnc->rcFBPost(rcEnc, cb->hostHandle);
520 static int fb_setUpdateRect(struct framebuffer_device_t* dev,
521 int l, int t, int w, int h)
523 fb_device_t *fbdev = (fb_device_t *)dev;
534 // Make sure we have host connection
535 DEFINE_AND_VALIDATE_HOST_CONNECTION;
537 // send request to host
538 // TODO: XXX - should be implemented
544 static int fb_setSwapInterval(struct framebuffer_device_t* dev,
547 fb_device_t *fbdev = (fb_device_t *)dev;
553 // Make sure we have host connection
554 DEFINE_AND_VALIDATE_HOST_CONNECTION;
556 // send request to host
557 rcEnc->rcFBSetSwapInterval(rcEnc, interval);
563 static int fb_close(struct hw_device_t *dev)
565 fb_device_t *fbdev = (fb_device_t *)dev;
574 // gralloc module functions - refcount + locking interface
576 static int gralloc_register_buffer(gralloc_module_t const* module,
577 buffer_handle_t handle)
579 pthread_once(&sFallbackOnce, fallback_init);
580 if (sFallback != NULL) {
581 return sFallback->registerBuffer(sFallback, handle);
584 D("gralloc_register_buffer(%p) called", handle);
586 private_module_t *gr = (private_module_t *)module;
587 cb_handle_t *cb = (cb_handle_t *)handle;
588 if (!gr || !cb_handle_t::validate(cb)) {
589 ERR("gralloc_register_buffer(%p): invalid buffer", cb);
593 if (cb->hostHandle != 0) {
594 DEFINE_AND_VALIDATE_HOST_CONNECTION;
595 D("Opening host ColorBuffer 0x%x\n", cb->hostHandle);
596 rcEnc->rcOpenColorBuffer2(rcEnc, cb->hostHandle);
600 // if the color buffer has ashmem region and it is not mapped in this
601 // process map it now.
603 if (cb->ashmemSize > 0 && cb->mappedPid != getpid()) {
605 int err = map_buffer(cb, &vaddr);
607 ERR("gralloc_register_buffer(%p): map failed: %s", cb, strerror(-err));
610 cb->mappedPid = getpid();
616 static int gralloc_unregister_buffer(gralloc_module_t const* module,
617 buffer_handle_t handle)
619 if (sFallback != NULL) {
620 return sFallback->unregisterBuffer(sFallback, handle);
623 private_module_t *gr = (private_module_t *)module;
624 cb_handle_t *cb = (cb_handle_t *)handle;
625 if (!gr || !cb_handle_t::validate(cb)) {
626 ERR("gralloc_unregister_buffer(%p): invalid buffer", cb);
630 if (cb->hostHandle != 0) {
631 DEFINE_AND_VALIDATE_HOST_CONNECTION;
632 D("Closing host ColorBuffer 0x%x\n", cb->hostHandle);
633 rcEnc->rcCloseColorBuffer(rcEnc, cb->hostHandle);
637 // unmap ashmem region if it was previously mapped in this process
638 // (through register_buffer)
640 if (cb->ashmemSize > 0 && cb->mappedPid == getpid()) {
642 int err = munmap((void *)cb->ashmemBase, cb->ashmemSize);
644 ERR("gralloc_unregister_buffer(%p): unmap failed", cb);
651 D("gralloc_unregister_buffer(%p) done\n", cb);
653 EXIT_GRALLOCONLY_HOST_CONNECTION;
657 static signed clamp_rgb(signed value) {
660 } else if (value < 0) {
666 static void rgb565_to_yv12(char* dest, char* src, int width, int height,
667 int left, int top, int right, int bottom) {
669 int yStride = (width + (align -1)) & ~(align-1);
670 int cStride = (yStride / 2 + (align - 1)) & ~(align-1);
672 int cSize = cStride * height/2;
674 uint16_t *rgb_ptr0 = (uint16_t *)src;
675 uint8_t *yv12_y0 = (uint8_t *)dest;
676 uint8_t *yv12_v0 = yv12_y0 + yStride * height;
677 uint8_t *yv12_u0 = yv12_v0 + cSize;
679 for (int j = top; j <= bottom; ++j) {
680 uint8_t *yv12_y = yv12_y0 + j * yStride;
681 uint8_t *yv12_v = yv12_v0 + (j/2) * cStride;
682 uint8_t *yv12_u = yv12_v + cSize;
683 uint16_t *rgb_ptr = rgb_ptr0 + j * width;
684 bool jeven = (j & 1) == 0;
685 for (int i = left; i <= right; ++i) {
686 uint8_t r = ((rgb_ptr[i]) >> 11) & 0x01f;
687 uint8_t g = ((rgb_ptr[i]) >> 5) & 0x03f;
688 uint8_t b = (rgb_ptr[i]) & 0x01f;
690 // http://stackoverflow.com/questions/2442576/how-does-one-convert-16-bit-rgb565-to-24-bit-rgb888
691 uint8_t R = (r * 527 + 23) >> 6;
692 uint8_t G = (g * 259 + 33) >> 6;
693 uint8_t B = (b * 527 + 23) >> 6;
695 // frameworks/base/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp
696 yv12_y[i] = clamp_rgb((77 * R + 150 * G + 29 * B) >> 8);
697 bool ieven = (i & 1) == 0;
698 if (jeven && ieven) {
699 yv12_u[i] = clamp_rgb((( -43 * R - 85 * G + 128 * B) >> 8) + 128);
700 yv12_v[i] = clamp_rgb((( 128 * R - 107 * G - 21 * B) >> 8) + 128);
706 static void rgb888_to_yv12(char* dest, char* src, int width, int height,
707 int left, int top, int right, int bottom) {
708 DD("%s convert %d by %d", __func__, width, height);
710 int yStride = (width + (align -1)) & ~(align-1);
711 int cStride = (yStride / 2 + (align - 1)) & ~(align-1);
713 int cSize = cStride * height/2;
716 uint8_t *rgb_ptr0 = (uint8_t *)src;
717 uint8_t *yv12_y0 = (uint8_t *)dest;
718 uint8_t *yv12_v0 = yv12_y0 + yStride * height;
719 uint8_t *yv12_u0 = yv12_v0 + cSize;
721 for (int j = top; j <= bottom; ++j) {
722 uint8_t *yv12_y = yv12_y0 + j * yStride;
723 uint8_t *yv12_v = yv12_v0 + (j/2) * cStride;
724 uint8_t *yv12_u = yv12_v + cSize;
725 uint8_t *rgb_ptr = rgb_ptr0 + j * width*rgb_stride;
726 bool jeven = (j & 1) == 0;
727 for (int i = left; i <= right; ++i) {
728 uint8_t R = rgb_ptr[i*rgb_stride];
729 uint8_t G = rgb_ptr[i*rgb_stride+1];
730 uint8_t B = rgb_ptr[i*rgb_stride+2];
732 // frameworks/base/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp
733 yv12_y[i] = clamp_rgb((77 * R + 150 * G + 29 * B) >> 8);
734 bool ieven = (i & 1) == 0;
735 if (jeven && ieven) {
736 yv12_u[i] = clamp_rgb((( -43 * R - 85 * G + 128 * B) >> 8) + 128);
737 yv12_v[i] = clamp_rgb((( 128 * R - 107 * G - 21 * B) >> 8) + 128);
743 static void rgb888_to_yuv420p(char* dest, char* src, int width, int height,
744 int left, int top, int right, int bottom) {
745 DD("%s convert %d by %d", __func__, width, height);
747 int cStride = yStride / 2;
749 int cSize = cStride * height/2;
752 uint8_t *rgb_ptr0 = (uint8_t *)src;
753 uint8_t *yv12_y0 = (uint8_t *)dest;
754 uint8_t *yv12_u0 = yv12_y0 + yStride * height;
755 uint8_t *yv12_v0 = yv12_u0 + cSize;
757 for (int j = top; j <= bottom; ++j) {
758 uint8_t *yv12_y = yv12_y0 + j * yStride;
759 uint8_t *yv12_u = yv12_u0 + (j/2) * cStride;
760 uint8_t *yv12_v = yv12_u + cStride;
761 uint8_t *rgb_ptr = rgb_ptr0 + j * width*rgb_stride;
762 bool jeven = (j & 1) == 0;
763 for (int i = left; i <= right; ++i) {
764 uint8_t R = rgb_ptr[i*rgb_stride];
765 uint8_t G = rgb_ptr[i*rgb_stride+1];
766 uint8_t B = rgb_ptr[i*rgb_stride+2];
768 // frameworks/base/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp
769 yv12_y[i] = clamp_rgb((77 * R + 150 * G + 29 * B) >> 8);
770 bool ieven = (i & 1) == 0;
771 if (jeven && ieven) {
772 yv12_u[i] = clamp_rgb((( -43 * R - 85 * G + 128 * B) >> 8) + 128);
773 yv12_v[i] = clamp_rgb((( 128 * R - 107 * G - 21 * B) >> 8) + 128);
779 static int gralloc_lock(gralloc_module_t const* module,
780 buffer_handle_t handle, int usage,
781 int l, int t, int w, int h,
784 if (sFallback != NULL) {
785 return sFallback->lock(sFallback, handle, usage, l, t, w, h, vaddr);
788 private_module_t *gr = (private_module_t *)module;
789 cb_handle_t *cb = (cb_handle_t *)handle;
790 if (!gr || !cb_handle_t::validate(cb)) {
791 ALOGE("gralloc_lock bad handle\n");
796 // 1. cannot be locked for hw access
797 // 2. lock for either sw read or write.
798 // 3. locked sw access must match usage during alloc time.
799 bool sw_read = (0 != (usage & GRALLOC_USAGE_SW_READ_MASK));
800 bool sw_write = (0 != (usage & GRALLOC_USAGE_SW_WRITE_MASK));
801 bool hw_read = (usage & GRALLOC_USAGE_HW_TEXTURE);
802 bool hw_write = (usage & GRALLOC_USAGE_HW_RENDER);
803 #if PLATFORM_SDK_VERSION >= 17
804 bool hw_cam_write = (usage & GRALLOC_USAGE_HW_CAMERA_WRITE);
805 bool hw_cam_read = (usage & GRALLOC_USAGE_HW_CAMERA_READ);
806 #else // PLATFORM_SDK_VERSION
807 bool hw_cam_write = false;
808 bool hw_cam_read = false;
809 #endif // PLATFORM_SDK_VERSION
811 #if PLATFORM_SDK_VERSION >= 15
812 bool hw_vid_enc_read = (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER);
813 #else // PLATFORM_SDK_VERSION
814 bool hw_vid_enc_read = false;
815 #endif // PLATFORM_SDK_VERSION
817 bool sw_read_allowed = (0 != (cb->usage & GRALLOC_USAGE_SW_READ_MASK));
819 #if PLATFORM_SDK_VERSION >= 15
821 // a buffer was created for GRALLOC_USAGE_HW_VIDEO_ENCODER usage but
822 // later a software encoder is reading this buffer: this is actually
824 sw_read_allowed = sw_read_allowed || (cb->usage & GRALLOC_USAGE_HW_VIDEO_ENCODER);
825 #endif // PLATFORM_SDK_VERSION >= 15
827 bool sw_write_allowed = (0 != (cb->usage & GRALLOC_USAGE_SW_WRITE_MASK));
829 if ( (hw_read || hw_write) ||
830 (!sw_read && !sw_write &&
831 !hw_cam_write && !hw_cam_read &&
833 (sw_read && !sw_read_allowed) ||
834 (sw_write && !sw_write_allowed) ) {
835 ALOGE("gralloc_lock usage mismatch usage=0x%x cb->usage=0x%x\n", usage,
837 //This is not exactly an error and loose it up.
842 intptr_t postCount = 0;
843 void *cpu_addr = NULL;
846 // make sure ashmem area is mapped if needed
848 if (cb->canBePosted() || sw_read || sw_write ||
849 hw_cam_write || hw_cam_read ||
851 if (cb->ashmemBasePid != getpid() || !cb->ashmemBase) {
855 if (cb->canBePosted()) {
856 postCount = *((intptr_t *)cb->ashmemBase);
857 cpu_addr = (void *)(cb->ashmemBase + sizeof(intptr_t));
860 cpu_addr = (void *)(cb->ashmemBase);
864 if (cb->hostHandle) {
865 // Make sure we have host connection
866 DEFINE_AND_VALIDATE_HOST_CONNECTION;
869 // flush color buffer write cache on host and get its sync status.
871 int hostSyncStatus = rcEnc->rcColorBufferCacheFlush(rcEnc, cb->hostHandle,
874 if (hostSyncStatus < 0) {
875 // host failed the color buffer sync - probably since it was already
876 // locked for write access. fail the lock.
877 ALOGE("gralloc_lock cacheFlush failed postCount=%d sw_read=%d\n",
883 void* rgb_addr = cpu_addr;
885 if (cb->frameworkFormat == HAL_PIXEL_FORMAT_YV12 ||
886 cb->frameworkFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) {
887 // We are using RGB88
888 tmpBuf = new char[cb->width * cb->height * 3];
891 D("gralloc_lock read back color buffer %d %d\n", cb->width, cb->height);
892 rcEnc->rcReadColorBuffer(rcEnc, cb->hostHandle,
893 0, 0, cb->width, cb->height, cb->glFormat, cb->glType, rgb_addr);
895 if (cb->frameworkFormat == HAL_PIXEL_FORMAT_YV12) {
896 rgb888_to_yv12((char*)cpu_addr, tmpBuf, cb->width, cb->height, l, t, l+w-1, t+h-1);
897 } else if (cb->frameworkFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) {
898 rgb888_to_yuv420p((char*)cpu_addr, tmpBuf, cb->width, cb->height, l, t, l+w-1, t+h-1);
906 // is virtual address required ?
908 if (sw_read || sw_write || hw_cam_write || hw_cam_read || hw_vid_enc_read) {
912 if (sw_write || hw_cam_write) {
914 // Keep locked region if locked for s/w write access.
919 cb->lockedHeight = h;
922 DD("gralloc_lock success. vaddr: %p, *vaddr: %p, usage: %x, cpu_addr: %p",
923 vaddr, vaddr ? *vaddr : 0, usage, cpu_addr);
928 // YV12 is aka YUV420Planar, or YUV420p; the only difference is that YV12 has
929 // certain stride requirements for Y and UV respectively.
930 static void yv12_to_rgb565(char* dest, char* src, int width, int height,
931 int left, int top, int right, int bottom) {
932 DD("%s convert %d by %d", __func__, width, height);
934 int yStride = (width + (align -1)) & ~(align-1);
935 int cStride = (yStride / 2 + (align - 1)) & ~(align-1);
937 int cSize = cStride * height/2;
939 uint16_t *rgb_ptr0 = (uint16_t *)dest;
940 uint8_t *yv12_y0 = (uint8_t *)src;
941 uint8_t *yv12_v0 = yv12_y0 + yStride * height;
942 uint8_t *yv12_u0 = yv12_v0 + cSize;
944 for (int j = top; j <= bottom; ++j) {
945 uint8_t *yv12_y = yv12_y0 + j * yStride;
946 uint8_t *yv12_v = yv12_v0 + (j/2) * cStride;
947 uint8_t *yv12_u = yv12_v + cSize;
948 uint16_t *rgb_ptr = rgb_ptr0 + (j-top) * (right-left+1);
949 for (int i = left; i <= right; ++i) {
951 // frameworks/av/media/libstagefright/colorconversion/ColorConverter.cpp
952 signed y1 = (signed)yv12_y[i] - 16;
953 signed u = (signed)yv12_u[i / 2] - 128;
954 signed v = (signed)yv12_v[i / 2] - 128;
956 signed u_b = u * 517;
957 signed u_g = -u * 100;
958 signed v_g = -v * 208;
959 signed v_r = v * 409;
961 signed tmp1 = y1 * 298;
962 signed b1 = clamp_rgb((tmp1 + u_b) / 256);
963 signed g1 = clamp_rgb((tmp1 + v_g + u_g) / 256);
964 signed r1 = clamp_rgb((tmp1 + v_r) / 256);
966 uint16_t rgb1 = ((r1 >> 3) << 11) | ((g1 >> 2) << 5) | (b1 >> 3);
968 rgb_ptr[i-left] = rgb1;
973 // YV12 is aka YUV420Planar, or YUV420p; the only difference is that YV12 has
974 // certain stride requirements for Y and UV respectively.
975 static void yv12_to_rgb888(char* dest, char* src, int width, int height,
976 int left, int top, int right, int bottom) {
977 DD("%s convert %d by %d", __func__, width, height);
979 int yStride = (width + (align -1)) & ~(align-1);
980 int cStride = (yStride / 2 + (align - 1)) & ~(align-1);
982 int cSize = cStride * height/2;
985 uint8_t *rgb_ptr0 = (uint8_t *)dest;
986 uint8_t *yv12_y0 = (uint8_t *)src;
987 uint8_t *yv12_v0 = yv12_y0 + yStride * height;
988 uint8_t *yv12_u0 = yv12_v0 + cSize;
990 for (int j = top; j <= bottom; ++j) {
991 uint8_t *yv12_y = yv12_y0 + j * yStride;
992 uint8_t *yv12_v = yv12_v0 + (j/2) * cStride;
993 uint8_t *yv12_u = yv12_v + cSize;
994 uint8_t *rgb_ptr = rgb_ptr0 + (j-top) * (right-left+1) * rgb_stride;
995 for (int i = left; i <= right; ++i) {
997 // frameworks/av/media/libstagefright/colorconversion/ColorConverter.cpp
998 signed y1 = (signed)yv12_y[i] - 16;
999 signed u = (signed)yv12_u[i / 2] - 128;
1000 signed v = (signed)yv12_v[i / 2] - 128;
1002 signed u_b = u * 517;
1003 signed u_g = -u * 100;
1004 signed v_g = -v * 208;
1005 signed v_r = v * 409;
1007 signed tmp1 = y1 * 298;
1008 signed b1 = clamp_rgb((tmp1 + u_b) / 256);
1009 signed g1 = clamp_rgb((tmp1 + v_g + u_g) / 256);
1010 signed r1 = clamp_rgb((tmp1 + v_r) / 256);
1012 rgb_ptr[(i-left)*rgb_stride] = r1;
1013 rgb_ptr[(i-left)*rgb_stride+1] = g1;
1014 rgb_ptr[(i-left)*rgb_stride+2] = b1;
1019 // YV12 is aka YUV420Planar, or YUV420p; the only difference is that YV12 has
1020 // certain stride requirements for Y and UV respectively.
1021 static void yuv420p_to_rgb888(char* dest, char* src, int width, int height,
1022 int left, int top, int right, int bottom) {
1023 DD("%s convert %d by %d", __func__, width, height);
1024 int yStride = width;
1025 int cStride = yStride / 2;
1027 int cSize = cStride * height/2;
1030 uint8_t *rgb_ptr0 = (uint8_t *)dest;
1031 uint8_t *yv12_y0 = (uint8_t *)src;
1032 uint8_t *yv12_u0 = yv12_y0 + yStride * height;
1033 uint8_t *yv12_v0 = yv12_u0 + cSize;
1035 for (int j = top; j <= bottom; ++j) {
1036 uint8_t *yv12_y = yv12_y0 + j * yStride;
1037 uint8_t *yv12_u = yv12_u0 + (j/2) * cStride;
1038 uint8_t *yv12_v = yv12_u + cSize;
1039 uint8_t *rgb_ptr = rgb_ptr0 + (j-top) * (right-left+1) * rgb_stride;
1040 for (int i = left; i <= right; ++i) {
1042 // frameworks/av/media/libstagefright/colorconversion/ColorConverter.cpp
1043 signed y1 = (signed)yv12_y[i] - 16;
1044 signed u = (signed)yv12_u[i / 2] - 128;
1045 signed v = (signed)yv12_v[i / 2] - 128;
1047 signed u_b = u * 517;
1048 signed u_g = -u * 100;
1049 signed v_g = -v * 208;
1050 signed v_r = v * 409;
1052 signed tmp1 = y1 * 298;
1053 signed b1 = clamp_rgb((tmp1 + u_b) / 256);
1054 signed g1 = clamp_rgb((tmp1 + v_g + u_g) / 256);
1055 signed r1 = clamp_rgb((tmp1 + v_r) / 256);
1057 rgb_ptr[(i-left)*rgb_stride] = r1;
1058 rgb_ptr[(i-left)*rgb_stride+1] = g1;
1059 rgb_ptr[(i-left)*rgb_stride+2] = b1;
1064 static int gralloc_unlock(gralloc_module_t const* module,
1065 buffer_handle_t handle)
1067 if (sFallback != NULL) {
1068 return sFallback->unlock(sFallback, handle);
1071 private_module_t *gr = (private_module_t *)module;
1072 cb_handle_t *cb = (cb_handle_t *)handle;
1073 if (!gr || !cb_handle_t::validate(cb)) {
1074 ALOGD("%s: invalid gr or cb handle. -EINVAL", __FUNCTION__);
1079 // if buffer was locked for s/w write, we need to update the host with
1082 if (cb->hostHandle) {
1084 // Make sure we have host connection
1085 DEFINE_AND_VALIDATE_HOST_CONNECTION;
1088 if (cb->canBePosted()) {
1089 cpu_addr = (void *)(cb->ashmemBase + sizeof(int));
1092 cpu_addr = (void *)(cb->ashmemBase);
1095 char* rgb_addr = (char *)cpu_addr;
1096 if (cb->lockedWidth < cb->width || cb->lockedHeight < cb->height) {
1097 int bpp = glUtilsPixelBitSize(cb->glFormat, cb->glType) >> 3;
1098 char *tmpBuf = new char[cb->lockedWidth * cb->lockedHeight * bpp];
1099 if (cb->frameworkFormat == HAL_PIXEL_FORMAT_YV12) {
1100 yv12_to_rgb888(tmpBuf, (char*)cpu_addr, cb->width, cb->height, cb->lockedLeft,
1101 cb->lockedTop, cb->lockedLeft+cb->lockedWidth-1, cb->lockedTop+cb->lockedHeight-1);
1102 } else if (cb->frameworkFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) {
1103 yuv420p_to_rgb888(tmpBuf, (char*)cpu_addr, cb->width, cb->height, cb->lockedLeft,
1104 cb->lockedTop, cb->lockedLeft+cb->lockedWidth-1, cb->lockedTop+cb->lockedHeight-1);
1106 int dst_line_len = cb->lockedWidth * bpp;
1107 int src_line_len = cb->width * bpp;
1108 char *src = (char *)rgb_addr + cb->lockedTop*src_line_len + cb->lockedLeft*bpp;
1110 for (int y=0; y<cb->lockedHeight; y++) {
1111 memcpy(dst, src, dst_line_len);
1112 src += src_line_len;
1113 dst += dst_line_len;
1117 rcEnc->rcUpdateColorBuffer(rcEnc, cb->hostHandle,
1118 cb->lockedLeft, cb->lockedTop,
1119 cb->lockedWidth, cb->lockedHeight,
1120 cb->glFormat, cb->glType,
1127 if (cb->frameworkFormat == HAL_PIXEL_FORMAT_YV12) {
1128 // for this format, we need to convert to RGB888 format
1129 // before updating host
1130 rgbBuf = new char[cb->width * cb->height * 3];
1131 yv12_to_rgb888(rgbBuf, (char*)cpu_addr, cb->width, cb->height, 0, 0, cb->width-1, cb->height-1);
1133 } else if (cb->frameworkFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) {
1134 // for this format, we need to convert to RGB888 format
1135 // before updating host
1136 rgbBuf = new char[cb->width * cb->height * 3];
1137 yuv420p_to_rgb888(rgbBuf, (char*)cpu_addr, cb->width, cb->height, 0, 0, cb->width-1, cb->height-1);
1141 rcEnc->rcUpdateColorBuffer(rcEnc, cb->hostHandle, 0, 0,
1142 cb->width, cb->height,
1143 cb->glFormat, cb->glType,
1150 DD("gralloc_unlock success. cpu_addr: %p", cpu_addr);
1153 cb->lockedWidth = cb->lockedHeight = 0;
1157 #if PLATFORM_SDK_VERSION >= 18
1158 static int gralloc_lock_ycbcr(gralloc_module_t const* module,
1159 buffer_handle_t handle, int usage,
1160 int l, int t, int w, int h,
1161 android_ycbcr *ycbcr)
1163 // Not supporting fallback module for YCbCr
1164 if (sFallback != NULL) {
1165 ALOGD("%s: has fallback, return -EINVAL", __FUNCTION__);
1170 ALOGE("%s: got NULL ycbcr struct! -EINVAL", __FUNCTION__);
1174 private_module_t *gr = (private_module_t *)module;
1175 cb_handle_t *cb = (cb_handle_t *)handle;
1176 if (!gr || !cb_handle_t::validate(cb)) {
1177 ALOGE("%s: bad colorbuffer handle. -EINVAL", __FUNCTION__);
1181 if (cb->frameworkFormat != HAL_PIXEL_FORMAT_YV12 &&
1182 cb->frameworkFormat != HAL_PIXEL_FORMAT_YCbCr_420_888) {
1183 ALOGE("gralloc_lock_ycbcr can only be used with "
1184 "HAL_PIXEL_FORMAT_YCbCr_420_888 or HAL_PIXEL_FORMAT_YV12, got %x instead. "
1186 cb->frameworkFormat);
1190 // Make sure memory is mapped, get address
1191 if (cb->ashmemBasePid != getpid() || !cb->ashmemBase) {
1192 ALOGD("%s: ashmembase not mapped. -EACCESS", __FUNCTION__);
1196 uint8_t *cpu_addr = NULL;
1198 if (cb->canBePosted()) {
1199 cpu_addr = (uint8_t *)(cb->ashmemBase + sizeof(int));
1202 cpu_addr = (uint8_t *)(cb->ashmemBase);
1205 // Calculate offsets to underlying YUV data
1214 switch (cb->format) {
1215 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
1216 yStride = cb->width;
1217 cStride = cb->width;
1219 vOffset = yStride * cb->height;
1220 uOffset = vOffset + 1;
1223 case HAL_PIXEL_FORMAT_YV12:
1224 // https://developer.android.com/reference/android/graphics/ImageFormat.html#YV12
1226 yStride = (cb->width + (align -1)) & ~(align-1);
1227 cStride = (yStride / 2 + (align - 1)) & ~(align-1);
1229 cSize = cStride * cb->height/2;
1230 vOffset = yStride * cb->height;
1231 uOffset = vOffset + cSize;
1234 case HAL_PIXEL_FORMAT_YCbCr_420_888:
1236 yStride = cb->width;
1237 cStride = yStride / 2;
1239 cSize = cStride * cb->height/2;
1240 uOffset = yStride * cb->height;
1241 vOffset = uOffset + cSize;
1245 ALOGE("gralloc_lock_ycbcr unexpected internal format %x",
1250 ycbcr->y = cpu_addr + yOffset;
1251 ycbcr->cb = cpu_addr + uOffset;
1252 ycbcr->cr = cpu_addr + vOffset;
1253 ycbcr->ystride = yStride;
1254 ycbcr->cstride = cStride;
1255 ycbcr->chroma_step = cStep;
1257 // Zero out reserved fields
1258 memset(ycbcr->reserved, 0, sizeof(ycbcr->reserved));
1261 // Keep locked region if locked for s/w write access.
1265 cb->lockedWidth = w;
1266 cb->lockedHeight = h;
1268 DD("gralloc_lock_ycbcr success. usage: %x, ycbcr.y: %p, .cb: %p, .cr: %p, "
1269 ".ystride: %d , .cstride: %d, .chroma_step: %d", usage,
1270 ycbcr->y, ycbcr->cb, ycbcr->cr, ycbcr->ystride, ycbcr->cstride,
1271 ycbcr->chroma_step);
1275 #endif // PLATFORM_SDK_VERSION >= 18
1277 static int gralloc_device_open(const hw_module_t* module,
1279 hw_device_t** device)
1281 int status = -EINVAL;
1283 D("gralloc_device_open %s\n", name);
1285 pthread_once( &sFallbackOnce, fallback_init );
1286 if (sFallback != NULL) {
1287 return sFallback->common.methods->open(&sFallback->common, name, device);
1290 if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) {
1292 // Create host connection and keep it in the TLS.
1293 // return error if connection with host can not be established
1294 HostConnection *hostCon = HostConnection::get();
1296 ALOGE("gralloc: failed to get host connection while opening %s\n", name);
1301 // Allocate memory for the gralloc device (alloc interface)
1303 gralloc_device_t *dev;
1304 dev = (gralloc_device_t*)malloc(sizeof(gralloc_device_t));
1309 // Initialize our device structure
1311 dev->device.common.tag = HARDWARE_DEVICE_TAG;
1312 dev->device.common.version = 0;
1313 dev->device.common.module = const_cast<hw_module_t*>(module);
1314 dev->device.common.close = gralloc_device_close;
1316 dev->device.alloc = gralloc_alloc;
1317 dev->device.free = gralloc_free;
1318 dev->allocListHead = NULL;
1319 pthread_mutex_init(&dev->lock, NULL);
1321 *device = &dev->device.common;
1324 else if (!strcmp(name, GRALLOC_HARDWARE_FB0)) {
1326 // return error if connection with host can not be established
1327 DEFINE_AND_VALIDATE_HOST_CONNECTION;
1330 // Query the host for Framebuffer attributes
1332 D("gralloc: query Frabuffer attribs\n");
1333 EGLint width = rcEnc->rcGetFBParam(rcEnc, FB_WIDTH);
1334 D("gralloc: width=%d\n", width);
1335 EGLint height = rcEnc->rcGetFBParam(rcEnc, FB_HEIGHT);
1336 D("gralloc: height=%d\n", height);
1337 EGLint xdpi = rcEnc->rcGetFBParam(rcEnc, FB_XDPI);
1338 D("gralloc: xdpi=%d\n", xdpi);
1339 EGLint ydpi = rcEnc->rcGetFBParam(rcEnc, FB_YDPI);
1340 D("gralloc: ydpi=%d\n", ydpi);
1341 EGLint fps = rcEnc->rcGetFBParam(rcEnc, FB_FPS);
1342 D("gralloc: fps=%d\n", fps);
1343 EGLint min_si = rcEnc->rcGetFBParam(rcEnc, FB_MIN_SWAP_INTERVAL);
1344 D("gralloc: min_swap=%d\n", min_si);
1345 EGLint max_si = rcEnc->rcGetFBParam(rcEnc, FB_MAX_SWAP_INTERVAL);
1346 D("gralloc: max_swap=%d\n", max_si);
1349 // Allocate memory for the framebuffer device
1352 dev = (fb_device_t*)malloc(sizeof(fb_device_t));
1356 memset(dev, 0, sizeof(fb_device_t));
1358 // Initialize our device structure
1360 dev->device.common.tag = HARDWARE_DEVICE_TAG;
1361 dev->device.common.version = 0;
1362 dev->device.common.module = const_cast<hw_module_t*>(module);
1363 dev->device.common.close = fb_close;
1364 dev->device.setSwapInterval = fb_setSwapInterval;
1365 dev->device.post = fb_post;
1366 dev->device.setUpdateRect = 0; //fb_setUpdateRect;
1367 dev->device.compositionComplete = fb_compositionComplete; //XXX: this is a dummy
1369 const_cast<uint32_t&>(dev->device.flags) = 0;
1370 const_cast<uint32_t&>(dev->device.width) = width;
1371 const_cast<uint32_t&>(dev->device.height) = height;
1372 const_cast<int&>(dev->device.stride) = width;
1373 const_cast<int&>(dev->device.format) = HAL_PIXEL_FORMAT_RGBA_8888;
1374 const_cast<float&>(dev->device.xdpi) = xdpi;
1375 const_cast<float&>(dev->device.ydpi) = ydpi;
1376 const_cast<float&>(dev->device.fps) = fps;
1377 const_cast<int&>(dev->device.minSwapInterval) = min_si;
1378 const_cast<int&>(dev->device.maxSwapInterval) = max_si;
1379 *device = &dev->device.common;
1388 // define the HMI symbol - our module interface
1390 static struct hw_module_methods_t gralloc_module_methods = {
1391 open: gralloc_device_open
1394 struct private_module_t HAL_MODULE_INFO_SYM = {
1397 tag: HARDWARE_MODULE_TAG,
1398 #if PLATFORM_SDK_VERSION >= 18
1399 module_api_version: GRALLOC_MODULE_API_VERSION_0_2,
1401 #elif PLATFORM_SDK_VERSION >= 16
1402 module_api_version: 1,
1404 #else // PLATFORM_SDK_VERSION
1407 #endif // PLATFORM_SDK_VERSION
1408 id: GRALLOC_HARDWARE_MODULE_ID,
1409 name: "Graphics Memory Allocator Module",
1410 author: "The Android Open Source Project",
1411 methods: &gralloc_module_methods,
1415 registerBuffer: gralloc_register_buffer,
1416 unregisterBuffer: gralloc_unregister_buffer,
1418 unlock: gralloc_unlock,
1420 #if PLATFORM_SDK_VERSION >= 18
1421 lock_ycbcr: gralloc_lock_ycbcr,
1422 #endif // PLATFORM_SDK_VERSION >= 18
1426 /* This function is called once to detect whether the emulator supports
1427 * GPU emulation (this is done by looking at the qemu.gles kernel
1428 * parameter, which must be == 1 if this is the case).
1430 * If not, then load gralloc.default instead as a fallback.
1435 char prop[PROPERTY_VALUE_MAX];
1438 // qemu.gles=0 -> no GLES 2.x support (only 1.x through software).
1439 // qemu.gles=1 -> host-side GPU emulation through EmuGL
1440 // qemu.gles=2 -> guest-side GPU emulation.
1441 property_get("ro.kernel.qemu.gles", prop, "0");
1442 if (atoi(prop) == 1) {
1445 ALOGD("Emulator without host-side GPU emulation detected.");
1447 module = dlopen("/system/lib64/hw/gralloc.default.so", RTLD_LAZY|RTLD_LOCAL);
1449 module = dlopen("/system/lib/hw/gralloc.default.so", RTLD_LAZY|RTLD_LOCAL);
1451 if (module != NULL) {
1452 sFallback = reinterpret_cast<gralloc_module_t*>(dlsym(module, HAL_MODULE_INFO_SYM_AS_STR));
1453 if (sFallback == NULL) {
1457 if (sFallback == NULL) {
1458 ALOGE("Could not find software fallback module!?");