2012-02-15 02:45:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
2012-06-01 20:02:02 +00:00
|
|
|
* Modified by:
|
|
|
|
* Andrew Sutherland <dr3wsuth3rland@gmail.com>
|
2012-02-15 02:45:54 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <hardware/hardware.h>
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <cutils/log.h>
|
|
|
|
#include <cutils/atomic.h>
|
|
|
|
#include <cutils/properties.h>
|
|
|
|
|
2012-06-01 20:02:02 +00:00
|
|
|
#include <gralloc_priv.h>
|
2012-02-15 02:45:54 +00:00
|
|
|
#include <hardware/hwcomposer.h>
|
2012-06-01 20:02:02 +00:00
|
|
|
#include <copybit.h>
|
2012-02-15 02:45:54 +00:00
|
|
|
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <EGL/eglext.h>
|
|
|
|
#include <ui/android_native_buffer.h>
|
|
|
|
#include <genlock.h>
|
|
|
|
#include <qcom_ui.h>
|
2012-03-17 06:36:07 +00:00
|
|
|
#include <gr.h>
|
2012-06-01 20:02:02 +00:00
|
|
|
#include <utils/profiler.h>
|
2012-02-15 02:45:54 +00:00
|
|
|
|
|
|
|
#define HWC_DEBUG 0
|
|
|
|
/*****************************************************************************/
|
|
|
|
#define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
|
|
|
|
|
|
|
|
struct hwc_context_t {
|
|
|
|
hwc_composer_device_t device;
|
|
|
|
/* our private state goes below here */
|
|
|
|
};
|
|
|
|
|
|
|
|
static int hwc_device_open(const struct hw_module_t* module, const char* name,
|
|
|
|
struct hw_device_t** device);
|
|
|
|
|
|
|
|
static struct hw_module_methods_t hwc_module_methods = {
|
|
|
|
open: hwc_device_open
|
|
|
|
};
|
|
|
|
|
|
|
|
struct private_hwc_module_t {
|
|
|
|
hwc_module_t base;
|
|
|
|
copybit_device_t *copybitEngine;
|
|
|
|
framebuffer_device_t *fbDevice;
|
|
|
|
int compositionType;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct private_hwc_module_t HAL_MODULE_INFO_SYM = {
|
|
|
|
base: {
|
|
|
|
common: {
|
|
|
|
tag: HARDWARE_MODULE_TAG,
|
|
|
|
version_major: 1,
|
|
|
|
version_minor: 0,
|
|
|
|
id: HWC_HARDWARE_MODULE_ID,
|
|
|
|
name: "Hardware Composer Module",
|
|
|
|
author: "The Android Open Source Project",
|
|
|
|
methods: &hwc_module_methods,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
copybitEngine: NULL,
|
|
|
|
fbDevice: NULL,
|
|
|
|
compositionType: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
static void dump_layer(hwc_layer_t const* l) {
|
2012-06-01 20:02:02 +00:00
|
|
|
LOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}, {%d,%d,%d,%d}",
|
2012-02-15 02:45:54 +00:00
|
|
|
l->compositionType, l->flags, l->handle, l->transform, l->blending,
|
|
|
|
l->sourceCrop.left,
|
|
|
|
l->sourceCrop.top,
|
|
|
|
l->sourceCrop.right,
|
|
|
|
l->sourceCrop.bottom,
|
|
|
|
l->displayFrame.left,
|
|
|
|
l->displayFrame.top,
|
|
|
|
l->displayFrame.right,
|
|
|
|
l->displayFrame.bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list) {
|
|
|
|
|
|
|
|
// if there is no list or geometry is not changed,
|
|
|
|
// there is no need to do any work here
|
|
|
|
if( !list || (!(list->flags & HWC_GEOMETRY_CHANGED)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
private_hwc_module_t* hwcModule = reinterpret_cast<private_hwc_module_t*>(
|
|
|
|
dev->common.module);
|
|
|
|
|
|
|
|
if (!hwcModule) {
|
2012-06-01 20:02:02 +00:00
|
|
|
LOGE("%s: invalid module", __FUNCTION__);
|
2012-02-15 02:45:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-06-01 20:02:02 +00:00
|
|
|
LOGD_IF(HWC_DEBUG,"%s: found %d layers",__FUNCTION__,list->numHwLayers);
|
2012-02-15 02:45:54 +00:00
|
|
|
for (size_t i=0 ; i<list->numHwLayers ; i++) {
|
|
|
|
// check for skip layer
|
|
|
|
if (list->hwLayers[i].flags & HWC_SKIP_LAYER) {
|
2012-06-01 20:02:02 +00:00
|
|
|
LOGD_IF(HWC_DEBUG,"%s: HWC_SKIP_LAYER on layer %d",__FUNCTION__,i);
|
2012-02-27 05:20:15 +00:00
|
|
|
ssize_t layer_countdown = ((ssize_t)i) - 1;
|
|
|
|
// Mark every layer below the SKIP layer to be composed by the GPU
|
|
|
|
while (layer_countdown >= 0)
|
|
|
|
{
|
|
|
|
list->hwLayers[layer_countdown].compositionType = HWC_FRAMEBUFFER;
|
|
|
|
list->hwLayers[layer_countdown].hints &= ~HWC_HINT_CLEAR_FB;
|
|
|
|
layer_countdown--;
|
2012-02-15 02:45:54 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2012-06-01 20:02:02 +00:00
|
|
|
// Copybit is all we have; use it for everything
|
2012-02-15 02:45:54 +00:00
|
|
|
if (hwcModule->compositionType & COMPOSITION_TYPE_MDP) {
|
2012-06-01 20:02:02 +00:00
|
|
|
LOGD_IF(HWC_DEBUG,"%s: using copybit for layer %d",__FUNCTION__,i);
|
2012-02-15 02:45:54 +00:00
|
|
|
list->hwLayers[i].compositionType = HWC_USE_COPYBIT;
|
|
|
|
} else {
|
2012-06-01 20:02:02 +00:00
|
|
|
LOGD_IF(HWC_DEBUG,"%s: copybit flag not set, using framebuffer for layer %d",__FUNCTION__,i);
|
|
|
|
list->hwLayers[i].compositionType = HWC_FRAMEBUFFER;
|
2012-02-15 02:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
struct range {
|
|
|
|
int current;
|
|
|
|
int end;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct region_iterator : public copybit_region_t {
|
|
|
|
|
|
|
|
region_iterator(hwc_region_t region) {
|
|
|
|
mRegion = region;
|
|
|
|
r.end = region.numRects;
|
|
|
|
r.current = 0;
|
|
|
|
this->next = iterate;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static int iterate(copybit_region_t const * self, copybit_rect_t* rect) {
|
|
|
|
|
|
|
|
if (!self) {
|
2012-06-01 20:02:02 +00:00
|
|
|
LOGE("%s: invalid param: region",__FUNCTION__);
|
2012-02-15 02:45:54 +00:00
|
|
|
return 0;
|
|
|
|
} else if (!rect) {
|
2012-06-01 20:02:02 +00:00
|
|
|
LOGE("%s: invalid param: rect",__FUNCTION__);
|
2012-02-15 02:45:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
region_iterator const* me = static_cast<region_iterator const*>(self);
|
|
|
|
if (me->r.current != me->r.end) {
|
|
|
|
rect->l = me->mRegion.rects[me->r.current].left;
|
|
|
|
rect->t = me->mRegion.rects[me->r.current].top;
|
|
|
|
rect->r = me->mRegion.rects[me->r.current].right;
|
|
|
|
rect->b = me->mRegion.rects[me->r.current].bottom;
|
|
|
|
me->r.current++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
hwc_region_t mRegion;
|
|
|
|
mutable range r;
|
|
|
|
};
|
|
|
|
|
2012-06-01 20:02:02 +00:00
|
|
|
static int drawLayerUsingCopybit(hwc_composer_device_t *dev, hwc_layer_t *layer, EGLDisplay dpy,
|
|
|
|
EGLSurface surface)
|
2012-02-15 02:45:54 +00:00
|
|
|
{
|
|
|
|
hwc_context_t* ctx = (hwc_context_t*)(dev);
|
|
|
|
if(!ctx) {
|
2012-06-01 20:02:02 +00:00
|
|
|
LOGE("%s: null context ", __FUNCTION__);
|
2012-02-15 02:45:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private_hwc_module_t* hwcModule = reinterpret_cast<private_hwc_module_t*>(dev->common.module);
|
|
|
|
if(!hwcModule) {
|
2012-06-01 20:02:02 +00:00
|
|
|
LOGE("%s: null module ", __FUNCTION__);
|
2012-02-15 02:45:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private_handle_t *hnd = (private_handle_t *)layer->handle;
|
|
|
|
if(!hnd) {
|
2012-06-01 20:02:02 +00:00
|
|
|
LOGE("%s: invalid handle", __FUNCTION__);
|
2012-02-15 02:45:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lock this buffer for read.
|
|
|
|
genlock_lock_type lockType = GENLOCK_READ_LOCK;
|
|
|
|
int err = genlock_lock_buffer(hnd, lockType, GENLOCK_MAX_TIMEOUT);
|
|
|
|
if (GENLOCK_FAILURE == err) {
|
2012-03-17 06:36:07 +00:00
|
|
|
LOGE("%s: genlock_lock_buffer(READ) failed", __FUNCTION__);
|
2012-02-15 02:45:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
//render buffer
|
|
|
|
android_native_buffer_t *renderBuffer = (android_native_buffer_t *)eglGetRenderBufferANDROID(dpy, surface);
|
|
|
|
if (!renderBuffer) {
|
2012-03-17 06:36:07 +00:00
|
|
|
LOGE("%s: eglGetRenderBufferANDROID returned NULL buffer", __FUNCTION__);
|
2012-02-15 02:45:54 +00:00
|
|
|
genlock_unlock_buffer(hnd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
private_handle_t *fbHandle = (private_handle_t *)renderBuffer->handle;
|
|
|
|
if(!fbHandle) {
|
2012-03-17 06:36:07 +00:00
|
|
|
LOGE("%s: Framebuffer handle is NULL", __FUNCTION__);
|
2012-02-15 02:45:54 +00:00
|
|
|
genlock_unlock_buffer(hnd);
|
|
|
|
return -1;
|
|
|
|
}
|
2012-06-01 20:02:02 +00:00
|
|
|
|
|
|
|
// Set the copybit source:
|
2012-02-15 02:45:54 +00:00
|
|
|
copybit_image_t src;
|
2012-06-01 20:02:02 +00:00
|
|
|
src.w = hnd->width;
|
2012-02-15 02:45:54 +00:00
|
|
|
src.h = hnd->height;
|
|
|
|
src.format = hnd->format;
|
|
|
|
src.base = (void *)hnd->base;
|
|
|
|
src.handle = (native_handle_t *)layer->handle;
|
|
|
|
src.horiz_padding = src.w - hnd->width;
|
|
|
|
// Initialize vertical padding to zero for now,
|
|
|
|
// this needs to change to accomodate vertical stride
|
|
|
|
// if needed in the future
|
|
|
|
src.vert_padding = 0;
|
|
|
|
|
|
|
|
// Copybit source rect
|
|
|
|
hwc_rect_t sourceCrop = layer->sourceCrop;
|
|
|
|
copybit_rect_t srcRect = {sourceCrop.left, sourceCrop.top,
|
|
|
|
sourceCrop.right,
|
|
|
|
sourceCrop.bottom};
|
|
|
|
|
|
|
|
// Copybit destination rect
|
|
|
|
hwc_rect_t displayFrame = layer->displayFrame;
|
|
|
|
copybit_rect_t dstRect = {displayFrame.left, displayFrame.top,
|
|
|
|
displayFrame.right,
|
|
|
|
displayFrame.bottom};
|
|
|
|
|
|
|
|
// Copybit dst
|
|
|
|
copybit_image_t dst;
|
2012-06-01 20:02:02 +00:00
|
|
|
dst.w = ALIGN(fbHandle->width,32);
|
2012-02-15 02:45:54 +00:00
|
|
|
dst.h = fbHandle->height;
|
|
|
|
dst.format = fbHandle->format;
|
|
|
|
dst.base = (void *)fbHandle->base;
|
|
|
|
dst.handle = (native_handle_t *)renderBuffer->handle;
|
|
|
|
|
2012-02-27 05:20:15 +00:00
|
|
|
copybit_device_t *copybit = hwcModule->copybitEngine;
|
|
|
|
|
|
|
|
int32_t screen_w = displayFrame.right - displayFrame.left;
|
|
|
|
int32_t screen_h = displayFrame.bottom - displayFrame.top;
|
|
|
|
int32_t src_crop_width = sourceCrop.right - sourceCrop.left;
|
|
|
|
int32_t src_crop_height = sourceCrop.bottom -sourceCrop.top;
|
|
|
|
|
2012-03-17 06:36:07 +00:00
|
|
|
float copybitsMaxScale = (float)copybit->get(copybit,COPYBIT_MAGNIFICATION_LIMIT);
|
2012-06-01 20:02:02 +00:00
|
|
|
float copybitsMinScale = (float)copybit->get(copybit,COPYBIT_MINIFICATION_LIMIT);
|
2012-02-27 05:20:15 +00:00
|
|
|
|
2012-03-17 06:36:07 +00:00
|
|
|
if((layer->transform == HWC_TRANSFORM_ROT_90) ||
|
|
|
|
(layer->transform == HWC_TRANSFORM_ROT_270)) {
|
2012-02-27 05:20:15 +00:00
|
|
|
//swap screen width and height
|
|
|
|
int tmp = screen_w;
|
|
|
|
screen_w = screen_h;
|
|
|
|
screen_h = tmp;
|
|
|
|
}
|
2012-03-17 06:36:07 +00:00
|
|
|
private_handle_t *tmpHnd = NULL;
|
|
|
|
|
|
|
|
if(screen_w <=0 || screen_h<=0 ||src_crop_width<=0 || src_crop_height<=0 ) {
|
|
|
|
LOGE("%s: wrong params for display screen_w=%d src_crop_width=%d screen_w=%d \
|
|
|
|
src_crop_width=%d", __FUNCTION__, screen_w,
|
|
|
|
src_crop_width,screen_w,src_crop_width);
|
|
|
|
genlock_unlock_buffer(hnd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
float dsdx = (float)screen_w/src_crop_width;
|
|
|
|
float dtdy = (float)screen_h/src_crop_height;
|
|
|
|
|
2012-06-01 20:02:02 +00:00
|
|
|
float scaleLimitMax = copybitsMaxScale * copybitsMaxScale;
|
|
|
|
float scaleLimitMin = copybitsMinScale * copybitsMinScale;
|
|
|
|
if(dsdx > scaleLimitMax || dtdy > scaleLimitMax || dsdx < 1/scaleLimitMin || dtdy < 1/scaleLimitMin) {
|
|
|
|
LOGE("%s: greater than max supported size dsdx=%f dtdy=%f scaleLimitMax=%f scaleLimitMin=%f", __FUNCTION__,dsdx,dtdy,scaleLimitMax,1/scaleLimitMin);
|
2012-03-17 06:36:07 +00:00
|
|
|
genlock_unlock_buffer(hnd);
|
|
|
|
return -1;
|
|
|
|
}
|
2012-06-01 20:02:02 +00:00
|
|
|
if(dsdx > copybitsMaxScale || dtdy > copybitsMaxScale || dsdx < 1/copybitsMinScale || dtdy < 1/copybitsMinScale){
|
2012-02-27 05:20:15 +00:00
|
|
|
// The requested scale is out of the range the hardware
|
|
|
|
// can support.
|
2012-06-01 20:02:02 +00:00
|
|
|
LOGD("%s:%d::Need to scale twice dsdx=%f, dtdy=%f,copybitsMaxScale=%f,copybitsMinScale=%f,screen_w=%d,screen_h=%d \
|
2012-02-27 05:20:15 +00:00
|
|
|
src_crop_width=%d src_crop_height=%d",__FUNCTION__,__LINE__,
|
2012-06-01 20:02:02 +00:00
|
|
|
dsdx,dtdy,copybitsMaxScale,1/copybitsMinScale,screen_w,screen_h,src_crop_width,src_crop_height);
|
2012-02-27 05:20:15 +00:00
|
|
|
|
|
|
|
//Driver makes width and height as even
|
|
|
|
//that may cause wrong calculation of the ratio
|
|
|
|
//in display and crop.Hence we make
|
|
|
|
//crop width and height as even.
|
|
|
|
src_crop_width = (src_crop_width/2)*2;
|
|
|
|
src_crop_height = (src_crop_height/2)*2;
|
|
|
|
|
2012-06-01 20:02:02 +00:00
|
|
|
int tmp_w = src_crop_width;
|
|
|
|
int tmp_h = src_crop_height;
|
|
|
|
|
|
|
|
if (dsdx > copybitsMaxScale || dtdy > copybitsMaxScale ){
|
|
|
|
tmp_w = src_crop_width*copybitsMaxScale;
|
|
|
|
tmp_h = src_crop_height*copybitsMaxScale;
|
|
|
|
}else if (dsdx < 1/copybitsMinScale ||dtdy < 1/copybitsMinScale ){
|
|
|
|
tmp_w = src_crop_width/copybitsMinScale;
|
|
|
|
tmp_h = src_crop_height/copybitsMinScale;
|
|
|
|
tmp_w = (tmp_w/2)*2;
|
|
|
|
tmp_h = (tmp_h/2)*2;
|
|
|
|
}
|
2012-02-27 05:20:15 +00:00
|
|
|
LOGD("%s:%d::tmp_w = %d,tmp_h = %d",__FUNCTION__,__LINE__,tmp_w,tmp_h);
|
|
|
|
|
2012-03-17 06:36:07 +00:00
|
|
|
int usage = GRALLOC_USAGE_PRIVATE_ADSP_HEAP |
|
|
|
|
GRALLOC_USAGE_PRIVATE_MM_HEAP;
|
|
|
|
|
|
|
|
if (0 == alloc_buffer(&tmpHnd, tmp_w, tmp_h, fbHandle->format, usage)){
|
2012-02-27 05:20:15 +00:00
|
|
|
copybit_image_t tmp_dst;
|
|
|
|
copybit_rect_t tmp_rect;
|
|
|
|
tmp_dst.w = tmp_w;
|
|
|
|
tmp_dst.h = tmp_h;
|
2012-03-17 06:36:07 +00:00
|
|
|
tmp_dst.format = tmpHnd->format;
|
|
|
|
tmp_dst.handle = tmpHnd;
|
2012-02-27 05:20:15 +00:00
|
|
|
tmp_dst.horiz_padding = src.horiz_padding;
|
|
|
|
tmp_dst.vert_padding = src.vert_padding;
|
|
|
|
tmp_rect.l = 0;
|
|
|
|
tmp_rect.t = 0;
|
|
|
|
tmp_rect.r = tmp_dst.w;
|
|
|
|
tmp_rect.b = tmp_dst.h;
|
|
|
|
//create one clip region
|
|
|
|
hwc_rect tmp_hwc_rect = {0,0,tmp_rect.r,tmp_rect.b};
|
|
|
|
hwc_region_t tmp_hwc_reg = {1,(hwc_rect_t const*)&tmp_hwc_rect};
|
|
|
|
region_iterator tmp_it(tmp_hwc_reg);
|
|
|
|
copybit->set_parameter(copybit,COPYBIT_TRANSFORM,0);
|
|
|
|
copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA,
|
|
|
|
(layer->blending == HWC_BLENDING_NONE) ? -1 : layer->alpha);
|
|
|
|
err = copybit->stretch(copybit,&tmp_dst, &src, &tmp_rect, &srcRect, &tmp_it);
|
|
|
|
if(err < 0){
|
|
|
|
LOGE("%s:%d::tmp copybit stretch failed",__FUNCTION__,__LINE__);
|
2012-03-17 06:36:07 +00:00
|
|
|
if(tmpHnd)
|
|
|
|
free_buffer(tmpHnd);
|
|
|
|
genlock_unlock_buffer(hnd);
|
2012-02-27 05:20:15 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
// copy new src and src rect crop
|
|
|
|
src = tmp_dst;
|
|
|
|
srcRect = tmp_rect;
|
|
|
|
}
|
|
|
|
}
|
2012-02-15 02:45:54 +00:00
|
|
|
// Copybit region
|
|
|
|
hwc_region_t region = layer->visibleRegionScreen;
|
|
|
|
region_iterator copybitRegion(region);
|
|
|
|
|
|
|
|
copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_WIDTH, renderBuffer->width);
|
|
|
|
copybit->set_parameter(copybit, COPYBIT_FRAMEBUFFER_HEIGHT, renderBuffer->height);
|
|
|
|
copybit->set_parameter(copybit, COPYBIT_TRANSFORM, layer->transform);
|
|
|
|
copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA,
|
|
|
|
(layer->blending == HWC_BLENDING_NONE) ? -1 : layer->alpha);
|
|
|
|
copybit->set_parameter(copybit, COPYBIT_PREMULTIPLIED_ALPHA,
|
|
|
|
(layer->blending == HWC_BLENDING_PREMULT)? COPYBIT_ENABLE : COPYBIT_DISABLE);
|
2012-02-27 05:20:15 +00:00
|
|
|
copybit->set_parameter(copybit, COPYBIT_DITHER,
|
|
|
|
(dst.format == HAL_PIXEL_FORMAT_RGB_565)? COPYBIT_ENABLE : COPYBIT_DISABLE);
|
2012-02-15 02:45:54 +00:00
|
|
|
err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect, ©bitRegion);
|
|
|
|
|
2012-03-17 06:36:07 +00:00
|
|
|
if(tmpHnd)
|
|
|
|
free_buffer(tmpHnd);
|
|
|
|
|
2012-02-15 02:45:54 +00:00
|
|
|
if(err < 0)
|
2012-06-01 20:02:02 +00:00
|
|
|
LOGE("%s: copybit stretch failed",__FUNCTION__);
|
2012-02-15 02:45:54 +00:00
|
|
|
|
|
|
|
// Unlock this buffer since copybit is done with it.
|
|
|
|
err = genlock_unlock_buffer(hnd);
|
|
|
|
if (GENLOCK_FAILURE == err) {
|
2012-03-17 06:36:07 +00:00
|
|
|
LOGE("%s: genlock_unlock_buffer failed", __FUNCTION__);
|
2012-02-15 02:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hwc_set(hwc_composer_device_t *dev,
|
|
|
|
hwc_display_t dpy,
|
|
|
|
hwc_surface_t sur,
|
|
|
|
hwc_layer_list_t* list)
|
|
|
|
{
|
|
|
|
|
|
|
|
private_hwc_module_t* hwcModule = reinterpret_cast<private_hwc_module_t*>(
|
|
|
|
dev->common.module);
|
|
|
|
|
|
|
|
if (!hwcModule) {
|
2012-03-17 06:36:07 +00:00
|
|
|
LOGE("%s: invalid module", __FUNCTION__);
|
2012-02-15 02:45:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-03-17 06:36:07 +00:00
|
|
|
if (list) {
|
|
|
|
for (size_t i=0; i<list->numHwLayers; i++) {
|
|
|
|
if (list->hwLayers[i].flags & HWC_SKIP_LAYER) {
|
|
|
|
continue;
|
|
|
|
} else if (list->flags & HWC_SKIP_COMPOSITION) {
|
|
|
|
continue;
|
|
|
|
} else if (list->hwLayers[i].compositionType == HWC_USE_COPYBIT) {
|
2012-06-01 20:02:02 +00:00
|
|
|
drawLayerUsingCopybit(dev, &(list->hwLayers[i]), (EGLDisplay)dpy, (EGLSurface)sur);
|
2012-03-17 06:36:07 +00:00
|
|
|
}
|
2012-02-15 02:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 06:36:07 +00:00
|
|
|
bool canSkipComposition = list && list->flags & HWC_SKIP_COMPOSITION;
|
|
|
|
|
|
|
|
if(canSkipComposition)
|
|
|
|
LOGD_IF(HWC_DEBUG,"%s: skipping eglSwapBuffer call", __FUNCTION__);
|
2012-02-27 05:20:15 +00:00
|
|
|
|
2012-02-15 02:45:54 +00:00
|
|
|
// Do not call eglSwapBuffers if the skip composition flag is set on the list.
|
2012-03-17 06:36:07 +00:00
|
|
|
if (dpy && sur && !canSkipComposition) {
|
2012-02-15 02:45:54 +00:00
|
|
|
EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
|
|
|
|
if (!sucess) {
|
2012-03-17 06:36:07 +00:00
|
|
|
LOGE("%s: eglSwapBuffers() failed", __FUNCTION__);
|
2012-02-15 02:45:54 +00:00
|
|
|
return HWC_EGL_ERROR;
|
|
|
|
}
|
2012-06-01 20:02:02 +00:00
|
|
|
} else {
|
|
|
|
CALC_FPS();
|
2012-02-15 02:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hwc_device_close(struct hw_device_t *dev)
|
|
|
|
{
|
|
|
|
if(!dev) {
|
2012-06-01 20:02:02 +00:00
|
|
|
LOGE("%s: null device pointer",__FUNCTION__);
|
2012-02-15 02:45:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct hwc_context_t* ctx = (struct hwc_context_t*)dev;
|
|
|
|
|
|
|
|
private_hwc_module_t* hwcModule = reinterpret_cast<private_hwc_module_t*>(
|
|
|
|
ctx->device.common.module);
|
|
|
|
// Close the copybit module
|
|
|
|
if(hwcModule->copybitEngine) {
|
|
|
|
copybit_close(hwcModule->copybitEngine);
|
|
|
|
hwcModule->copybitEngine = NULL;
|
|
|
|
}
|
|
|
|
if(hwcModule->fbDevice) {
|
|
|
|
framebuffer_close(hwcModule->fbDevice);
|
|
|
|
hwcModule->fbDevice = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx) {
|
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static int hwc_module_initialize(struct private_hwc_module_t* hwcModule)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Open the copybit module
|
|
|
|
hw_module_t const *module;
|
|
|
|
if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) {
|
|
|
|
copybit_open(module, &(hwcModule->copybitEngine));
|
|
|
|
}
|
|
|
|
if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {
|
|
|
|
framebuffer_open(module, &(hwcModule->fbDevice));
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the current composition type
|
|
|
|
char property[PROPERTY_VALUE_MAX];
|
|
|
|
if (property_get("debug.sf.hw", property, NULL) > 0) {
|
|
|
|
if(atoi(property) == 0) {
|
|
|
|
//debug.sf.hw = 0
|
|
|
|
hwcModule->compositionType = COMPOSITION_TYPE_CPU;
|
|
|
|
} else { //debug.sf.hw = 1
|
|
|
|
// Get the composition type
|
|
|
|
property_get("debug.composition.type", property, NULL);
|
|
|
|
if (property == NULL) {
|
|
|
|
hwcModule->compositionType = COMPOSITION_TYPE_GPU;
|
|
|
|
} else if ((strncmp(property, "mdp", 3)) == 0) {
|
|
|
|
hwcModule->compositionType = COMPOSITION_TYPE_MDP;
|
|
|
|
} else {
|
|
|
|
hwcModule->compositionType = COMPOSITION_TYPE_GPU;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!hwcModule->copybitEngine)
|
|
|
|
hwcModule->compositionType = COMPOSITION_TYPE_GPU;
|
|
|
|
}
|
|
|
|
} else { //debug.sf.hw is not set. Use cpu composition
|
|
|
|
hwcModule->compositionType = COMPOSITION_TYPE_CPU;
|
|
|
|
}
|
|
|
|
|
2012-06-01 20:02:02 +00:00
|
|
|
CALC_INIT();
|
2012-02-15 02:45:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hwc_device_open(const struct hw_module_t* module, const char* name,
|
|
|
|
struct hw_device_t** device)
|
|
|
|
{
|
|
|
|
int status = -EINVAL;
|
|
|
|
if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
|
|
|
|
private_hwc_module_t* hwcModule = reinterpret_cast<private_hwc_module_t*>
|
|
|
|
(const_cast<hw_module_t*>(module));
|
|
|
|
|
|
|
|
hwc_module_initialize(hwcModule);
|
|
|
|
|
|
|
|
struct hwc_context_t *dev;
|
|
|
|
dev = (hwc_context_t*)malloc(sizeof(*dev));
|
|
|
|
|
|
|
|
/* initialize our state here */
|
|
|
|
memset(dev, 0, sizeof(*dev));
|
|
|
|
|
|
|
|
/* initialize the procs */
|
|
|
|
dev->device.common.tag = HARDWARE_DEVICE_TAG;
|
|
|
|
dev->device.common.version = 0;
|
|
|
|
dev->device.common.module = const_cast<hw_module_t*>(module);
|
|
|
|
dev->device.common.close = hwc_device_close;
|
|
|
|
|
|
|
|
dev->device.prepare = hwc_prepare;
|
|
|
|
dev->device.set = hwc_set;
|
|
|
|
|
|
|
|
*device = &dev->device.common;
|
|
|
|
status = 0;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|