display: Use temporary buffer for internal conversion
(cherry picked from commit 7945ee46591ceba584b1b2167e5f750d3489d69c) Change-Id: Ie71a8745e8810ade310103fdfed7db03cd170980
This commit is contained in:
		
				
					committed by
					
						
						Andrew Sutherland
					
				
			
			
				
	
			
			
			
						parent
						
							128d5de4b5
						
					
				
				
					commit
					d19d1e2ff9
				
			@@ -387,3 +387,48 @@ size_t getBufferSizeAndDimensions(int width, int height, int format,
 | 
			
		||||
 | 
			
		||||
    return size;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Allocate buffer from width, height and format into a
 | 
			
		||||
// private_handle_t. It is the responsibility of the caller
 | 
			
		||||
// to free the buffer using the free_buffer function
 | 
			
		||||
int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage)
 | 
			
		||||
{
 | 
			
		||||
     alloc_data data;
 | 
			
		||||
     int alignedw, alignedh;
 | 
			
		||||
     android::sp<gralloc::IAllocController> sAlloc =
 | 
			
		||||
         gralloc::IAllocController::getInstance(false);
 | 
			
		||||
     data.base = 0;
 | 
			
		||||
     data.fd = -1;
 | 
			
		||||
     data.offset = 0;
 | 
			
		||||
     data.size = getBufferSizeAndDimensions(w, h, format, alignedw, alignedh);
 | 
			
		||||
     data.align = getpagesize();
 | 
			
		||||
     data.uncached = true;
 | 
			
		||||
     int allocFlags = usage;
 | 
			
		||||
 | 
			
		||||
     int err = sAlloc->allocate(data, allocFlags, 0);
 | 
			
		||||
     if (0 != err) {
 | 
			
		||||
         LOGE("%s: allocate failed", __FUNCTION__);
 | 
			
		||||
         return -ENOMEM;
 | 
			
		||||
     }
 | 
			
		||||
 | 
			
		||||
     private_handle_t* hnd = new private_handle_t(data.fd, data.size,
 | 
			
		||||
                             data.allocType, 0, format, alignedw, alignedh);
 | 
			
		||||
     hnd->base = (int) data.base;
 | 
			
		||||
     hnd->offset = data.offset;
 | 
			
		||||
     hnd->gpuaddr = 0;
 | 
			
		||||
     *pHnd = hnd;
 | 
			
		||||
     return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void free_buffer(private_handle_t *hnd)
 | 
			
		||||
{
 | 
			
		||||
    android::sp<gralloc::IAllocController> sAlloc =
 | 
			
		||||
        gralloc::IAllocController::getInstance(false);
 | 
			
		||||
    if (hnd && hnd->fd > 0) {
 | 
			
		||||
        sp<IMemAlloc> memalloc = sAlloc->getAllocator(hnd->flags);
 | 
			
		||||
        memalloc->free_buffer((void*)hnd->base, hnd->size, hnd->offset, hnd->fd);
 | 
			
		||||
    }
 | 
			
		||||
    if(hnd)
 | 
			
		||||
        delete hnd;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -56,6 +56,12 @@ size_t getBufferSizeAndDimensions(int width, int height, int format,
 | 
			
		||||
int decideBufferHandlingMechanism(int format, const char *compositionUsed,
 | 
			
		||||
                                   int hasBlitEngine, int *needConversion,
 | 
			
		||||
                                   int *useBufferDirectly);
 | 
			
		||||
 | 
			
		||||
// Allocate buffer from width, height, format into a private_handle_t
 | 
			
		||||
// It is the responsibility of the caller to free the buffer
 | 
			
		||||
int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage);
 | 
			
		||||
void free_buffer(private_handle_t *hnd);
 | 
			
		||||
 | 
			
		||||
/*****************************************************************************/
 | 
			
		||||
 | 
			
		||||
class Locker {
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ include $(CLEAR_VARS)
 | 
			
		||||
LOCAL_PRELINK_MODULE := false
 | 
			
		||||
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
 | 
			
		||||
LOCAL_SHARED_LIBRARIES := liblog libcutils libEGL libhardware libutils liboverlay
 | 
			
		||||
LOCAL_SHARED_LIBRARIES += libgenlock libui libQcomUI
 | 
			
		||||
LOCAL_SHARED_LIBRARIES += libgenlock libQcomUI libmemalloc
 | 
			
		||||
 | 
			
		||||
LOCAL_SRC_FILES := 	\
 | 
			
		||||
	hwcomposer.cpp
 | 
			
		||||
 
 | 
			
		||||
@@ -39,6 +39,7 @@
 | 
			
		||||
#include <gralloc_priv.h>
 | 
			
		||||
#include <genlock.h>
 | 
			
		||||
#include <qcom_ui.h>
 | 
			
		||||
#include <gr.h>
 | 
			
		||||
 | 
			
		||||
/*****************************************************************************/
 | 
			
		||||
#define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
 | 
			
		||||
@@ -1069,7 +1070,7 @@ static int drawLayerUsingCopybit(hwc_composer_device_t *dev, hwc_layer_t *layer,
 | 
			
		||||
    }
 | 
			
		||||
    int32_t dsdx = screen_w/src_crop_width;
 | 
			
		||||
    int32_t dtdy = screen_h/src_crop_height;
 | 
			
		||||
    sp<GraphicBuffer> tempBitmap;
 | 
			
		||||
    private_handle_t *tmpHnd = NULL;
 | 
			
		||||
 | 
			
		||||
    if(dsdx  > copybitsMaxScale || dtdy > copybitsMaxScale){
 | 
			
		||||
        // The requested scale is out of the range the hardware
 | 
			
		||||
@@ -1089,18 +1090,17 @@ static int drawLayerUsingCopybit(hwc_composer_device_t *dev, hwc_layer_t *layer,
 | 
			
		||||
       int tmp_h =  src_crop_height*copybitsMaxScale;
 | 
			
		||||
 | 
			
		||||
       LOGD("%s:%d::tmp_w = %d,tmp_h = %d",__FUNCTION__,__LINE__,tmp_w,tmp_h);
 | 
			
		||||
       tempBitmap = new GraphicBuffer(
 | 
			
		||||
                    tmp_w, tmp_h, src.format,
 | 
			
		||||
                    GraphicBuffer::USAGE_HW_2D);
 | 
			
		||||
 | 
			
		||||
       err = tempBitmap->initCheck();
 | 
			
		||||
       if (err == android::NO_ERROR){
 | 
			
		||||
       int usage = GRALLOC_USAGE_PRIVATE_ADSP_HEAP |
 | 
			
		||||
                   GRALLOC_USAGE_PRIVATE_MM_HEAP;
 | 
			
		||||
 | 
			
		||||
       if (0 == alloc_buffer(&tmpHnd, tmp_w, tmp_h, src.format, usage)){
 | 
			
		||||
            copybit_image_t tmp_dst;
 | 
			
		||||
            copybit_rect_t tmp_rect;
 | 
			
		||||
            tmp_dst.w = tmp_w;
 | 
			
		||||
            tmp_dst.h = tmp_h;
 | 
			
		||||
            tmp_dst.format = tempBitmap->format;
 | 
			
		||||
            tmp_dst.handle = (native_handle_t*)tempBitmap->getNativeBuffer()->handle;
 | 
			
		||||
            tmp_dst.format = tmpHnd->format;
 | 
			
		||||
            tmp_dst.handle = tmpHnd;
 | 
			
		||||
            tmp_dst.horiz_padding = src.horiz_padding;
 | 
			
		||||
            tmp_dst.vert_padding = src.vert_padding;
 | 
			
		||||
            tmp_rect.l = 0;
 | 
			
		||||
@@ -1117,6 +1117,8 @@ static int drawLayerUsingCopybit(hwc_composer_device_t *dev, hwc_layer_t *layer,
 | 
			
		||||
            err = copybit->stretch(copybit,&tmp_dst, &src, &tmp_rect, &srcRect, &tmp_it);
 | 
			
		||||
            if(err < 0){
 | 
			
		||||
                LOGE("%s:%d::tmp copybit stretch failed",__FUNCTION__,__LINE__);
 | 
			
		||||
                if(tmpHnd)
 | 
			
		||||
                    free_buffer(tmpHnd);
 | 
			
		||||
                return err;
 | 
			
		||||
            }
 | 
			
		||||
            // copy new src and src rect crop
 | 
			
		||||
@@ -1139,6 +1141,9 @@ static int drawLayerUsingCopybit(hwc_composer_device_t *dev, hwc_layer_t *layer,
 | 
			
		||||
                            (dst.format == HAL_PIXEL_FORMAT_RGB_565)? COPYBIT_ENABLE : COPYBIT_DISABLE);
 | 
			
		||||
    err = copybit->stretch(copybit, &dst, &src, &dstRect, &srcRect, ©bitRegion);
 | 
			
		||||
 | 
			
		||||
    if(tmpHnd)
 | 
			
		||||
        free_buffer(tmpHnd);
 | 
			
		||||
 | 
			
		||||
    if(err < 0)
 | 
			
		||||
        LOGE("copybit stretch failed");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user