From 4438e2f942abff3f6fbf3ef170faa85b85c04495 Mon Sep 17 00:00:00 2001 From: Naomi Luis Date: Mon, 19 Dec 2011 11:40:05 -0800 Subject: [PATCH] libQcomUI: Implement clearRegion for C2D/MDP/CPU composition. Implement clearRegion for C2D/MDP/CPU composition. This prevents glClear and therefore the glFinish from being called, thus improving performance. Change-Id: I03d9230e03cce11d9fe7e2bd34e4df8328ad2e00 --- libhwcomposer/hwcomposer.cpp | 9 ---- libqcomui/Android.mk | 3 +- libqcomui/qcom_ui.cpp | 96 ++++++++++++++++++++++++++++++++++++ libqcomui/qcom_ui.h | 29 +++++++++++ 4 files changed, 127 insertions(+), 10 deletions(-) diff --git a/libhwcomposer/hwcomposer.cpp b/libhwcomposer/hwcomposer.cpp index 5eec149..d41c5f2 100755 --- a/libhwcomposer/hwcomposer.cpp +++ b/libhwcomposer/hwcomposer.cpp @@ -45,15 +45,6 @@ #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) -// Enum containing the supported composition types -enum { - COMPOSITION_TYPE_GPU = 0, - COMPOSITION_TYPE_MDP = 0x1, - COMPOSITION_TYPE_C2D = 0x2, - COMPOSITION_TYPE_CPU = 0x4, - COMPOSITION_TYPE_DYN = 0x8 -}; - enum HWCLayerType{ HWC_SINGLE_VIDEO = 0x1, HWC_ORIG_RESOLUTION = 0x2, diff --git a/libqcomui/Android.mk b/libqcomui/Android.mk index 2b786d9..11b9909 100644 --- a/libqcomui/Android.mk +++ b/libqcomui/Android.mk @@ -8,7 +8,8 @@ LOCAL_SHARED_LIBRARIES := \ libutils \ libcutils \ libmemalloc \ - libui + libui \ + libEGL LOCAL_C_INCLUDES := $(TOP)/hardware/qcom/display/libgralloc \ LOCAL_CFLAGS := -DLOG_TAG=\"libQcomUI\" diff --git a/libqcomui/qcom_ui.cpp b/libqcomui/qcom_ui.cpp index 24995e6..f1cd7aa 100644 --- a/libqcomui/qcom_ui.cpp +++ b/libqcomui/qcom_ui.cpp @@ -28,17 +28,22 @@ */ #include +#include #include #include #include #include #include +#include +#include using gralloc::IMemAlloc; using gralloc::IonController; using gralloc::alloc_data; using android::sp; +static int sCompositionType = -1; + namespace { static android::sp sAlloc = 0; @@ -311,3 +316,94 @@ bool isUpdatingFB(HWCCompositionType compositionType) }; } +/* + * Get the current composition Type + * + * @return the compositon Type + */ +int getCompositionType() { + char property[PROPERTY_VALUE_MAX]; + int compositionType = 0; + if (property_get("debug.sf.hw", property, NULL) > 0) { + if(atoi(property) == 0) { + compositionType = COMPOSITION_TYPE_CPU; + } else { //debug.sf.hw = 1 + property_get("debug.composition.type", property, NULL); + if (property == NULL) { + compositionType = COMPOSITION_TYPE_GPU; + } else if ((strncmp(property, "mdp", 3)) == 0) { + compositionType = COMPOSITION_TYPE_MDP; + } else if ((strncmp(property, "c2d", 3)) == 0) { + compositionType = COMPOSITION_TYPE_C2D; + } else if ((strncmp(property, "dyn", 3)) == 0) { + compositionType = COMPOSITION_TYPE_DYN; + } else { + compositionType = COMPOSITION_TYPE_GPU; + } + } + } else { //debug.sf.hw is not set. Use cpu composition + compositionType = COMPOSITION_TYPE_CPU; + } + return compositionType; +} + +/* + * Clear Region implementation for C2D/MDP versions. + * + * @param: region to be cleared + * @param: EGL Display + * @param: EGL Surface + * + * @return 0 on success + */ +int qcomuiClearRegion(Region region, EGLDisplay dpy, EGLSurface sur) +{ + int ret = 0; + + if (-1 == sCompositionType) { + sCompositionType = getCompositionType(); + } + + if ((COMPOSITION_TYPE_MDP != sCompositionType) && + (COMPOSITION_TYPE_C2D != sCompositionType) && + (COMPOSITION_TYPE_CPU != sCompositionType)) { + // For non CPU/C2D/MDP composition, return an error, so that SF can use + // the GPU to draw the wormhole. + return -1; + } + + android_native_buffer_t *renderBuffer = (android_native_buffer_t *) + eglGetRenderBufferANDROID(dpy, sur); + if (!renderBuffer) { + LOGE("%s: eglGetRenderBufferANDROID returned NULL buffer", + __FUNCTION__); + return -1; + } + private_handle_t *fbHandle = (private_handle_t *)renderBuffer->handle; + if(!fbHandle) { + LOGE("%s: Framebuffer handle is NULL", __FUNCTION__); + return -1; + } + + int bytesPerPixel = 4; + if (HAL_PIXEL_FORMAT_RGB_565 == fbHandle->format) { + bytesPerPixel = 2; + } + + Region::const_iterator it = region.begin(); + Region::const_iterator const end = region.end(); + const int32_t stride = renderBuffer->stride*bytesPerPixel; + while (it != end) { + const Rect& r = *it++; + uint8_t* dst = (uint8_t*) fbHandle->base + + (r.left + r.top*renderBuffer->stride)*bytesPerPixel; + int w = r.width()*bytesPerPixel; + int h = r.height(); + do { + android_memset32((uint32_t*)dst, 0, w); + dst += stride; + } while(--h); + } + + return 0; +} diff --git a/libqcomui/qcom_ui.h b/libqcomui/qcom_ui.h index 0909365..d54280e 100644 --- a/libqcomui/qcom_ui.h +++ b/libqcomui/qcom_ui.h @@ -33,7 +33,10 @@ #include #include #include +#include +#include +using namespace android; using android::sp; using android::GraphicBuffer; @@ -45,6 +48,15 @@ enum { NATIVE_WINDOW_UPDATE_BUFFERS_GEOMETRY = 0x20000000, }; +// Enum containing the supported composition types +enum { + COMPOSITION_TYPE_GPU = 0, + COMPOSITION_TYPE_MDP = 0x1, + COMPOSITION_TYPE_C2D = 0x2, + COMPOSITION_TYPE_CPU = 0x4, + COMPOSITION_TYPE_DYN = 0x8 +}; + /* * Layer Attributes */ @@ -171,4 +183,21 @@ int getPerFrameFlags(int hwclFlags, int layerFlags); bool isUpdatingFB(HWCCompositionType compositionType); +/* + * Get the current composition Type + * + * @return the compositon Type + */ +int getCompositionType(); + +/* + * Clear region implementation for C2D/MDP versions. + * + * @param: region to be cleared + * @param: EGL Display + * @param: EGL Surface + * + * @return 0 on success + */ +int qcomuiClearRegion(Region region, EGLDisplay dpy, EGLSurface sur); #endif // INCLUDE_LIBQCOM_UI