Android-x86
Fork
Faire un don

  • R/O
  • HTTP
  • SSH
  • HTTPS

device-generic-goldfish-opengl: Commit

device/generic/goldfish-opengl


Commit MetaInfo

Révision8a78b215c555fa8a3f793c72f12f50b199c57d7d (tree)
l'heure2017-06-24 05:45:13
AuteurLingfeng Yang <lfy@goog...>
Commiterandroid-build-team Robot

Message de Log

gralloc ashmem hack to delay cb close

Tired of public emulators not working with O

See this CL for context:

https://android-review.googlesource.com/#/c/372376/

This CL moves that to the guest, and detects if
each gralloc cb has been opened at least once
before allowing gralloc_free to call rcCloseColorBuffer.

Images using Treble / HIDL gralloc that have this CL
should work with older emulator versions.

Bug: 37302997

Test: Build and run sdk_google_aw_x86-userdebug emulator

Change-Id: Ice72269e4295497825050385b15dbdec2258100c
(cherry picked from commit ef6676015bfec4538a552204b51e32f02d721fb0)

Change Summary

Modification

--- a/Android.mk
+++ b/Android.mk
@@ -24,6 +24,10 @@ EMUGL_COMMON_INCLUDES := $(EMUGL_PATH)/host/include/libOpenglRender $(EMUGL_PATH
2424 #
2525 EMUGL_COMMON_CFLAGS := -DWITH_GLES2 -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION)
2626
27+ifeq (O, $(PLATFORM_VERSION_CODENAME))
28+ EMUGL_COMMON_CFLAGS += -DGOLDFISH_HIDL_GRALLOC
29+endif
30+
2731 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 18 && echo PreJellyBeanMr2),PreJellyBeanMr2)
2832 ifeq ($(ARCH_ARM_HAVE_TLS_REGISTER),true)
2933 EMUGL_COMMON_CFLAGS += -DHAVE_ARM_TLS_REGISTER
--- a/system/gralloc/gralloc.cpp
+++ b/system/gralloc/gralloc.cpp
@@ -51,6 +51,23 @@
5151
5252 #define DBG_FUNC DBG("%s\n", __FUNCTION__)
5353
54+#ifdef GOLDFISH_HIDL_GRALLOC
55+static bool isHidlGralloc = true;
56+#else
57+static bool isHidlGralloc = false;
58+#endif
59+
60+int32_t* getOpenCountPtr(cb_handle_t* cb) {
61+ return ((int32_t*)cb->ashmemBase) + 1;
62+}
63+
64+uint32_t getAshmemColorOffset(cb_handle_t* cb) {
65+ uint32_t res = 0;
66+ if (cb->canBePosted()) res = sizeof(intptr_t);
67+ if (isHidlGralloc) res = sizeof(intptr_t) * 2;
68+ return res;
69+}
70+
5471 //
5572 // our private gralloc module structure
5673 //
@@ -262,6 +279,9 @@ static int map_buffer(cb_handle_t *cb, void **vaddr)
262279 return -EINVAL;
263280 }
264281
282+ int map_flags = MAP_SHARED;
283+ if (isHidlGralloc) map_flags |= MAP_ANONYMOUS;
284+
265285 void *addr = mmap(0, cb->ashmemSize, PROT_READ | PROT_WRITE,
266286 MAP_SHARED, cb->fd, 0);
267287 if (addr == MAP_FAILED) {
@@ -526,9 +546,39 @@ static int gralloc_alloc(alloc_device_t* dev,
526546 return -EINVAL;
527547 }
528548
529- if (usage & GRALLOC_USAGE_HW_FB) {
530- // keep space for postCounter
531- ashmem_size += sizeof(uint32_t);
549+ //
550+ // Allocate ColorBuffer handle on the host (only if h/w access is allowed)
551+ // Only do this for some h/w usages, not all.
552+ // Also do this if we need to read from the surface, in this case the
553+ // rendering will still happen on the host but we also need to be able to
554+ // read back from the color buffer, which requires that there is a buffer
555+ //
556+ bool needHostCb = (!yuv_format ||
557+ frameworkFormat == HAL_PIXEL_FORMAT_YV12 ||
558+ frameworkFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) &&
559+#if PLATFORM_SDK_VERSION >= 15
560+ (usage & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER |
561+ GRALLOC_USAGE_HW_2D | GRALLOC_USAGE_HW_COMPOSER |
562+ GRALLOC_USAGE_HW_VIDEO_ENCODER |
563+ GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_SW_READ_MASK))
564+#else // PLATFORM_SDK_VERSION
565+ (usage & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER |
566+ GRALLOC_USAGE_HW_2D |
567+ GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_SW_READ_MASK))
568+#endif // PLATFORM_SDK_VERSION
569+ ;
570+
571+ if (isHidlGralloc) {
572+ if (needHostCb || (usage & GRALLOC_USAGE_HW_FB)) {
573+ // keep space for postCounter
574+ // AND openCounter for all host cb
575+ ashmem_size += sizeof(uint32_t) * 2;
576+ }
577+ } else {
578+ if (usage & GRALLOC_USAGE_HW_FB) {
579+ // keep space for postCounter
580+ ashmem_size += sizeof(uint32_t) * 1;
581+ }
532582 }
533583
534584 if (sw_read || sw_write || hw_cam_write || hw_vid_enc_read) {
@@ -598,43 +648,25 @@ static int gralloc_alloc(alloc_device_t* dev,
598648 cb->goldfish_dma.fd = -1;
599649 }
600650
601- //
602- // Allocate ColorBuffer handle on the host (only if h/w access is allowed)
603- // Only do this for some h/w usages, not all.
604- // Also do this if we need to read from the surface, in this case the
605- // rendering will still happen on the host but we also need to be able to
606- // read back from the color buffer, which requires that there is a buffer
607- //
608- if (!yuv_format ||
609- frameworkFormat == HAL_PIXEL_FORMAT_YV12 ||
610- frameworkFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) {
611-#if PLATFORM_SDK_VERSION >= 15
612- if (usage & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER |
613- GRALLOC_USAGE_HW_2D | GRALLOC_USAGE_HW_COMPOSER |
614- GRALLOC_USAGE_HW_VIDEO_ENCODER |
615- GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_SW_READ_MASK) ) {
616-#else // PLATFORM_SDK_VERSION
617- if (usage & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER |
618- GRALLOC_USAGE_HW_2D |
619- GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_SW_READ_MASK) ) {
620-#endif // PLATFORM_SDK_VERSION
621- if (hostCon && rcEnc) {
622- if (s_grdma) {
623- cb->hostHandle = rcEnc->rcCreateColorBufferDMA(rcEnc, w, h, glFormat, cb->emuFrameworkFormat);
624- } else {
625- cb->hostHandle = rcEnc->rcCreateColorBuffer(rcEnc, w, h, glFormat);
626- }
627- D("Created host ColorBuffer 0x%x\n", cb->hostHandle);
651+ if (needHostCb) {
652+ if (hostCon && rcEnc) {
653+ if (s_grdma) {
654+ cb->hostHandle = rcEnc->rcCreateColorBufferDMA(rcEnc, w, h, glFormat, cb->emuFrameworkFormat);
655+ } else {
656+ cb->hostHandle = rcEnc->rcCreateColorBuffer(rcEnc, w, h, glFormat);
628657 }
658+ D("Created host ColorBuffer 0x%x\n", cb->hostHandle);
659+ }
629660
630- if (!cb->hostHandle) {
631- // Could not create colorbuffer on host !!!
632- close(fd);
633- delete cb;
634- ALOGD("%s: failed to create host cb! -EIO", __FUNCTION__);
635- return -EIO;
636- }
661+ if (!cb->hostHandle) {
662+ // Could not create colorbuffer on host !!!
663+ close(fd);
664+ delete cb;
665+ ALOGD("%s: failed to create host cb! -EIO", __FUNCTION__);
666+ return -EIO;
637667 }
668+
669+ if (isHidlGralloc) { *getOpenCountPtr(cb) = 0; }
638670 }
639671
640672 //
@@ -678,9 +710,19 @@ static int gralloc_free(alloc_device_t* dev,
678710 __FUNCTION__, handle, cb->ashmemBase, cb->ashmemSize);
679711
680712 if (cb->hostHandle) {
681- DEFINE_AND_VALIDATE_HOST_CONNECTION;
682- D("Closing host ColorBuffer 0x%x\n", cb->hostHandle);
683- rcEnc->rcCloseColorBuffer(rcEnc, cb->hostHandle);
713+ int32_t openCount = 1;
714+ int32_t* openCountPtr = &openCount;
715+
716+ if (isHidlGralloc) { openCountPtr = getOpenCountPtr(cb); }
717+
718+ if (*openCountPtr > 0) {
719+ DEFINE_AND_VALIDATE_HOST_CONNECTION;
720+ D("Closing host ColorBuffer 0x%x\n", cb->hostHandle);
721+ rcEnc->rcCloseColorBuffer(rcEnc, cb->hostHandle);
722+ } else {
723+ D("A rcCloseColorBuffer is owed!!! sdk ver: %d", PLATFORM_SDK_VERSION);
724+ *openCountPtr = -1;
725+ }
684726 }
685727
686728 //
@@ -873,6 +915,11 @@ static int gralloc_register_buffer(gralloc_module_t const* module,
873915 }
874916 cb->mappedPid = getpid();
875917
918+ if (isHidlGralloc) {
919+ int32_t* openCountPtr = getOpenCountPtr(cb);
920+ if (!*openCountPtr) *openCountPtr = 1;
921+ }
922+
876923 DEFINE_AND_VALIDATE_HOST_CONNECTION;
877924 if (rcEnc->getDmaVersion() > 0) {
878925 init_gralloc_dmaregion();
@@ -909,6 +956,19 @@ static int gralloc_unregister_buffer(gralloc_module_t const* module,
909956 D("Closing host ColorBuffer 0x%x\n", cb->hostHandle);
910957 DEFINE_AND_VALIDATE_HOST_CONNECTION;
911958 rcEnc->rcCloseColorBuffer(rcEnc, cb->hostHandle);
959+
960+ if (isHidlGralloc) {
961+ // Queue up another rcCloseColorBuffer if applicable.
962+ // invariant: have ashmem.
963+ if (cb->ashmemSize > 0 && cb->mappedPid == getpid()) {
964+ int32_t* openCountPtr = getOpenCountPtr(cb);
965+ if (*openCountPtr == -1) {
966+ D("%s: revenge of the rcCloseColorBuffer!", __func__);
967+ rcEnc->rcCloseColorBuffer(rcEnc, cb->hostHandle);
968+ *openCountPtr = -2;
969+ }
970+ }
971+ }
912972 }
913973
914974 //
@@ -1019,13 +1079,7 @@ static int gralloc_lock(gralloc_module_t const* module,
10191079 return -EACCES;
10201080 }
10211081
1022- if (cb->canBePosted()) {
1023- postCount = *((intptr_t *)cb->ashmemBase);
1024- cpu_addr = (void *)(cb->ashmemBase + sizeof(intptr_t));
1025- }
1026- else {
1027- cpu_addr = (void *)(cb->ashmemBase);
1028- }
1082+ cpu_addr = (void *)(cb->ashmemBase + getAshmemColorOffset(cb));
10291083 }
10301084
10311085 if (cb->hostHandle) {
@@ -1117,13 +1171,7 @@ static int gralloc_unlock(gralloc_module_t const* module,
11171171 // Make sure we have host connection
11181172 DEFINE_AND_VALIDATE_HOST_CONNECTION;
11191173
1120- void *cpu_addr;
1121- if (cb->canBePosted()) {
1122- cpu_addr = (void *)(cb->ashmemBase + sizeof(int));
1123- }
1124- else {
1125- cpu_addr = (void *)(cb->ashmemBase);
1126- }
1174+ void *cpu_addr = (void *)(cb->ashmemBase + getAshmemColorOffset(cb));
11271175
11281176 char* rgb_addr = (char *)cpu_addr;
11291177 if (cb->lockedWidth < cb->width || cb->lockedHeight < cb->height) {
@@ -1180,13 +1228,7 @@ static int gralloc_lock_ycbcr(gralloc_module_t const* module,
11801228 }
11811229
11821230 uint8_t *cpu_addr = NULL;
1183-
1184- if (cb->canBePosted()) {
1185- cpu_addr = (uint8_t *)(cb->ashmemBase + sizeof(int));
1186- }
1187- else {
1188- cpu_addr = (uint8_t *)(cb->ashmemBase);
1189- }
1231+ cpu_addr = (uint8_t *)(cb->ashmemBase) + getAshmemColorOffset(cb);
11901232
11911233 // Calculate offsets to underlying YUV data
11921234 size_t yStride;
Afficher sur ancien navigateur de dépôt.