diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-05-17 08:06:36 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-05-17 08:06:36 +0000 |
commit | 16a66c65f99c9cfa5d419f5eaf573792b1b631bb (patch) | |
tree | 424c0ce7a838fc10e955494d061f35b7a0c0e819 | |
parent | 2135ee06c4c1c1626ac2b635e4f025cfaa6676ac (diff) | |
parent | 8b0bfc77449832d148016ffc516d304dca9671a1 (diff) | |
download | device_generic_goldfish-opengl-16a66c65f99c9cfa5d419f5eaf573792b1b631bb.tar.gz device_generic_goldfish-opengl-16a66c65f99c9cfa5d419f5eaf573792b1b631bb.tar.bz2 device_generic_goldfish-opengl-16a66c65f99c9cfa5d419f5eaf573792b1b631bb.zip |
release-request-655284b0-7f0b-48b5-b01d-27f48a99f2c0-for-git_oc-mr1-release-4017105 snap-temp-L82600000064873863
Change-Id: I8394a0c645edfec274708c2ae6e601f4b3ccdc52
-rw-r--r-- | Android.mk | 8 | ||||
-rw-r--r-- | common.mk | 4 | ||||
-rw-r--r-- | system/OpenglSystemCommon/Android.mk | 6 | ||||
-rw-r--r-- | system/OpenglSystemCommon/EGLImage.h | 5 | ||||
-rw-r--r-- | system/egl/Android.mk | 4 | ||||
-rw-r--r-- | system/gralloc/gralloc.cpp | 189 |
6 files changed, 153 insertions, 63 deletions
@@ -24,6 +24,14 @@ EMUGL_COMMON_INCLUDES := $(EMUGL_PATH)/host/include/libOpenglRender $(EMUGL_PATH # EMUGL_COMMON_CFLAGS := -DWITH_GLES2 -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION) +ifeq (O, $(PLATFORM_VERSION_CODENAME)) + EMUGL_COMMON_CFLAGS += -DGOLDFISH_HIDL_GRALLOC +endif + +ifeq ($(PLATFORM_VERSION_CODENAME.PPR1),P) + EMUGL_COMMON_CFLAGS += -DEMULATOR_OPENGL_POST_O=1 +endif + ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 18 && echo PreJellyBeanMr2),PreJellyBeanMr2) ifeq ($(ARCH_ARM_HAVE_TLS_REGISTER),true) EMUGL_COMMON_CFLAGS += -DHAVE_ARM_TLS_REGISTER @@ -102,6 +102,10 @@ EMUGL_EXPORT_TYPES := \ STATIC_LIBRARIES \ ADDITIONAL_DEPENDENCIES +ifeq ($(PLATFORM_VERSION_CODENAME.PPR1),P) +EMUGL_EXPORT_TYPES += HEADER_LIBRARIES +endif + # Initialize a module in our database # $1: Module name # $2: Module type diff --git a/system/OpenglSystemCommon/Android.mk b/system/OpenglSystemCommon/Android.mk index 9853f29a..007b5039 100644 --- a/system/OpenglSystemCommon/Android.mk +++ b/system/OpenglSystemCommon/Android.mk @@ -11,6 +11,12 @@ LOCAL_SRC_FILES := \ QemuPipeStream.cpp \ ThreadInfo.cpp +ifeq ($(PLATFORM_VERSION_CODENAME.PPR1),P) +LOCAL_HEADER_LIBRARIES += libnativebase_headers + +$(call emugl-export,HEADER_LIBRARIES,libnativebase_headers) +endif + $(call emugl-export,C_INCLUDES,$(LOCAL_PATH) bionic/libc/private) $(call emugl-end-module) diff --git a/system/OpenglSystemCommon/EGLImage.h b/system/OpenglSystemCommon/EGLImage.h index 9f8f9014..6cb74318 100644 --- a/system/OpenglSystemCommon/EGLImage.h +++ b/system/OpenglSystemCommon/EGLImage.h @@ -21,7 +21,10 @@ #include <GLES/gl.h> #if PLATFORM_SDK_VERSION >= 16 -#include <system/window.h> +#if EMULATOR_OPENGL_POST_O >= 1 +#include <nativebase/nativebase.h> +#endif +#include <cutils/native_handle.h> #else // PLATFORM_SDK_VERSION >= 16 #include <private/ui/android_natives_priv.h> #endif // PLATFORM_SDK_VERSION >= 16 diff --git a/system/egl/Android.mk b/system/egl/Android.mk index f7dcc70e..476cf948 100644 --- a/system/egl/Android.mk +++ b/system/egl/Android.mk @@ -13,7 +13,11 @@ LOCAL_SRC_FILES := \ egl.cpp \ ClientAPIExts.cpp +ifeq ($(PLATFORM_VERSION_CODENAME.PPR1),P) +LOCAL_SHARED_LIBRARIES += libdl libnativewindow +else LOCAL_SHARED_LIBRARIES += libdl +endif # Used to access the Bionic private OpenGL TLS slot LOCAL_C_INCLUDES += bionic/libc/private diff --git a/system/gralloc/gralloc.cpp b/system/gralloc/gralloc.cpp index 4e63b003..0b6785e7 100644 --- a/system/gralloc/gralloc.cpp +++ b/system/gralloc/gralloc.cpp @@ -51,6 +51,23 @@ #define DBG_FUNC DBG("%s\n", __FUNCTION__) +#ifdef GOLDFISH_HIDL_GRALLOC +static bool isHidlGralloc = true; +#else +static bool isHidlGralloc = false; +#endif + +int32_t* getOpenCountPtr(cb_handle_t* cb) { + return ((int32_t*)cb->ashmemBase) + 1; +} + +uint32_t getAshmemColorOffset(cb_handle_t* cb) { + uint32_t res = 0; + if (cb->canBePosted()) res = sizeof(intptr_t); + if (isHidlGralloc) res = sizeof(intptr_t) * 2; + return res; +} + // // our private gralloc module structure // @@ -262,6 +279,9 @@ static int map_buffer(cb_handle_t *cb, void **vaddr) return -EINVAL; } + int map_flags = MAP_SHARED; + if (isHidlGralloc) map_flags |= MAP_ANONYMOUS; + void *addr = mmap(0, cb->ashmemSize, PROT_READ | PROT_WRITE, MAP_SHARED, cb->fd, 0); if (addr == MAP_FAILED) { @@ -370,6 +390,15 @@ static void updateHostColorBuffer(cb_handle_t* cb, if (convertedBuf) delete [] convertedBuf; } +#ifndef GL_RGBA16F +#define GL_RGBA16F 0x881A +#endif // GL_RGBA16F +#ifndef GL_UNSIGNED_INT_10_10_10_2 +#define GL_UNSIGNED_INT_10_10_10_2 0x8DF6 +#endif // GL_UNSIGNED_INT_10_10_10_2 +#ifndef GL_HALF_FLOAT +#define GL_HALF_FLOAT 0x140B +#endif // GL_HALF_FLOAT // // gralloc device functions (alloc interface) // @@ -469,6 +498,18 @@ static int gralloc_alloc(alloc_device_t* dev, glFormat = GL_RGB; glType = GL_UNSIGNED_SHORT_5_6_5; break; +#if PLATFORM_SDK_VERSION >= 26 + case HAL_PIXEL_FORMAT_RGBA_FP16: + bpp = 8; + glFormat = GL_RGBA16F; + glType = GL_HALF_FLOAT; + break; + case HAL_PIXEL_FORMAT_RGBA_1010102: + bpp = 4; + glFormat = GL_RGBA; + glType = GL_UNSIGNED_INT_10_10_10_2; + break; +#endif // PLATFORM_SDK_VERSION >= 26 #if PLATFORM_SDK_VERSION >= 21 case HAL_PIXEL_FORMAT_RAW16: case HAL_PIXEL_FORMAT_Y16: @@ -488,8 +529,10 @@ static int gralloc_alloc(alloc_device_t* dev, #if PLATFORM_SDK_VERSION >= 17 case HAL_PIXEL_FORMAT_BLOB: bpp = 1; - if (! (sw_read && hw_cam_write) ) { + if (! (sw_read) ) { // Blob data cannot be used by HW other than camera emulator + // But there is a CTS test trying to have access to it + // BUG: https://buganizer.corp.google.com/issues/37719518 return -EINVAL; } // Not expecting to actually create any GL surfaces for this @@ -526,9 +569,39 @@ static int gralloc_alloc(alloc_device_t* dev, return -EINVAL; } - if (usage & GRALLOC_USAGE_HW_FB) { - // keep space for postCounter - ashmem_size += sizeof(uint32_t); + // + // Allocate ColorBuffer handle on the host (only if h/w access is allowed) + // Only do this for some h/w usages, not all. + // Also do this if we need to read from the surface, in this case the + // rendering will still happen on the host but we also need to be able to + // read back from the color buffer, which requires that there is a buffer + // + bool needHostCb = (!yuv_format || + frameworkFormat == HAL_PIXEL_FORMAT_YV12 || + frameworkFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) && +#if PLATFORM_SDK_VERSION >= 15 + (usage & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER | + GRALLOC_USAGE_HW_2D | GRALLOC_USAGE_HW_COMPOSER | + GRALLOC_USAGE_HW_VIDEO_ENCODER | + GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_SW_READ_MASK)) +#else // PLATFORM_SDK_VERSION + (usage & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER | + GRALLOC_USAGE_HW_2D | + GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_SW_READ_MASK)) +#endif // PLATFORM_SDK_VERSION + ; + + if (isHidlGralloc) { + if (needHostCb || (usage & GRALLOC_USAGE_HW_FB)) { + // keep space for postCounter + // AND openCounter for all host cb + ashmem_size += sizeof(uint32_t) * 2; + } + } else { + if (usage & GRALLOC_USAGE_HW_FB) { + // keep space for postCounter + ashmem_size += sizeof(uint32_t) * 1; + } } if (sw_read || sw_write || hw_cam_write || hw_vid_enc_read) { @@ -598,43 +671,25 @@ static int gralloc_alloc(alloc_device_t* dev, cb->goldfish_dma.fd = -1; } - // - // Allocate ColorBuffer handle on the host (only if h/w access is allowed) - // Only do this for some h/w usages, not all. - // Also do this if we need to read from the surface, in this case the - // rendering will still happen on the host but we also need to be able to - // read back from the color buffer, which requires that there is a buffer - // - if (!yuv_format || - frameworkFormat == HAL_PIXEL_FORMAT_YV12 || - frameworkFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) { -#if PLATFORM_SDK_VERSION >= 15 - if (usage & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER | - GRALLOC_USAGE_HW_2D | GRALLOC_USAGE_HW_COMPOSER | - GRALLOC_USAGE_HW_VIDEO_ENCODER | - GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_SW_READ_MASK) ) { -#else // PLATFORM_SDK_VERSION - if (usage & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER | - GRALLOC_USAGE_HW_2D | - GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_SW_READ_MASK) ) { -#endif // PLATFORM_SDK_VERSION - if (hostCon && rcEnc) { - if (s_grdma) { - cb->hostHandle = rcEnc->rcCreateColorBufferDMA(rcEnc, w, h, glFormat, cb->emuFrameworkFormat); - } else { - cb->hostHandle = rcEnc->rcCreateColorBuffer(rcEnc, w, h, glFormat); - } - D("Created host ColorBuffer 0x%x\n", cb->hostHandle); + if (needHostCb) { + if (hostCon && rcEnc) { + if (s_grdma) { + cb->hostHandle = rcEnc->rcCreateColorBufferDMA(rcEnc, w, h, glFormat, cb->emuFrameworkFormat); + } else { + cb->hostHandle = rcEnc->rcCreateColorBuffer(rcEnc, w, h, glFormat); } + D("Created host ColorBuffer 0x%x\n", cb->hostHandle); + } - if (!cb->hostHandle) { - // Could not create colorbuffer on host !!! - close(fd); - delete cb; - ALOGD("%s: failed to create host cb! -EIO", __FUNCTION__); - return -EIO; - } + if (!cb->hostHandle) { + // Could not create colorbuffer on host !!! + close(fd); + delete cb; + ALOGD("%s: failed to create host cb! -EIO", __FUNCTION__); + return -EIO; } + + if (isHidlGralloc) { *getOpenCountPtr(cb) = 0; } } // @@ -678,9 +733,19 @@ static int gralloc_free(alloc_device_t* dev, __FUNCTION__, handle, cb->ashmemBase, cb->ashmemSize); if (cb->hostHandle) { - DEFINE_AND_VALIDATE_HOST_CONNECTION; - D("Closing host ColorBuffer 0x%x\n", cb->hostHandle); - rcEnc->rcCloseColorBuffer(rcEnc, cb->hostHandle); + int32_t openCount = 1; + int32_t* openCountPtr = &openCount; + + if (isHidlGralloc) { openCountPtr = getOpenCountPtr(cb); } + + if (*openCountPtr > 0) { + DEFINE_AND_VALIDATE_HOST_CONNECTION; + D("Closing host ColorBuffer 0x%x\n", cb->hostHandle); + rcEnc->rcCloseColorBuffer(rcEnc, cb->hostHandle); + } else { + D("A rcCloseColorBuffer is owed!!! sdk ver: %d", PLATFORM_SDK_VERSION); + *openCountPtr = -1; + } } // @@ -873,6 +938,11 @@ static int gralloc_register_buffer(gralloc_module_t const* module, } cb->mappedPid = getpid(); + if (isHidlGralloc) { + int32_t* openCountPtr = getOpenCountPtr(cb); + if (!*openCountPtr) *openCountPtr = 1; + } + DEFINE_AND_VALIDATE_HOST_CONNECTION; if (rcEnc->getDmaVersion() > 0) { init_gralloc_dmaregion(); @@ -909,6 +979,19 @@ static int gralloc_unregister_buffer(gralloc_module_t const* module, D("Closing host ColorBuffer 0x%x\n", cb->hostHandle); DEFINE_AND_VALIDATE_HOST_CONNECTION; rcEnc->rcCloseColorBuffer(rcEnc, cb->hostHandle); + + if (isHidlGralloc) { + // Queue up another rcCloseColorBuffer if applicable. + // invariant: have ashmem. + if (cb->ashmemSize > 0 && cb->mappedPid == getpid()) { + int32_t* openCountPtr = getOpenCountPtr(cb); + if (*openCountPtr == -1) { + D("%s: revenge of the rcCloseColorBuffer!", __func__); + rcEnc->rcCloseColorBuffer(rcEnc, cb->hostHandle); + *openCountPtr = -2; + } + } + } } // @@ -1019,13 +1102,7 @@ static int gralloc_lock(gralloc_module_t const* module, return -EACCES; } - if (cb->canBePosted()) { - postCount = *((intptr_t *)cb->ashmemBase); - cpu_addr = (void *)(cb->ashmemBase + sizeof(intptr_t)); - } - else { - cpu_addr = (void *)(cb->ashmemBase); - } + cpu_addr = (void *)(cb->ashmemBase + getAshmemColorOffset(cb)); } if (cb->hostHandle) { @@ -1117,13 +1194,7 @@ static int gralloc_unlock(gralloc_module_t const* module, // Make sure we have host connection DEFINE_AND_VALIDATE_HOST_CONNECTION; - void *cpu_addr; - if (cb->canBePosted()) { - cpu_addr = (void *)(cb->ashmemBase + sizeof(int)); - } - else { - cpu_addr = (void *)(cb->ashmemBase); - } + void *cpu_addr = (void *)(cb->ashmemBase + getAshmemColorOffset(cb)); char* rgb_addr = (char *)cpu_addr; if (cb->lockedWidth < cb->width || cb->lockedHeight < cb->height) { @@ -1180,13 +1251,7 @@ static int gralloc_lock_ycbcr(gralloc_module_t const* module, } uint8_t *cpu_addr = NULL; - - if (cb->canBePosted()) { - cpu_addr = (uint8_t *)(cb->ashmemBase + sizeof(int)); - } - else { - cpu_addr = (uint8_t *)(cb->ashmemBase); - } + cpu_addr = (uint8_t *)(cb->ashmemBase) + getAshmemColorOffset(cb); // Calculate offsets to underlying YUV data size_t yStride; |