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
This commit is contained in:
Naomi Luis 2011-12-19 11:40:05 -08:00 committed by Giulio Cervera
parent eae32cda02
commit 4438e2f942
4 changed files with 127 additions and 10 deletions

View File

@ -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,

View File

@ -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\"

View File

@ -28,17 +28,22 @@
*/
#include <cutils/log.h>
#include <cutils/memory.h>
#include <qcom_ui.h>
#include <gralloc_priv.h>
#include <alloc_controller.h>
#include <memalloc.h>
#include <errno.h>
#include <cutils/properties.h>
#include <EGL/eglext.h>
using gralloc::IMemAlloc;
using gralloc::IonController;
using gralloc::alloc_data;
using android::sp;
static int sCompositionType = -1;
namespace {
static android::sp<gralloc::IAllocController> 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;
}

View File

@ -33,7 +33,10 @@
#include <cutils/native_handle.h>
#include <ui/GraphicBuffer.h>
#include <hardware/hwcomposer.h>
#include <ui/Region.h>
#include <EGL/egl.h>
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