Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
Arun Kumar K.R | 6364fa6 | 2015-01-08 16:08:51 -0800 | [diff] [blame] | 3 | * Copyright (c) 2010-2015, The Linux Foundation. All rights reserved. |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 4 | * |
| 5 | * Not a Contribution, Apache license notifications and license are retained |
| 6 | * for attribution purposes only. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 7 | * |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | */ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 20 | #include <cutils/log.h> |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 21 | #include <sys/resource.h> |
| 22 | #include <sys/prctl.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 23 | |
| 24 | #include <stdint.h> |
| 25 | #include <string.h> |
| 26 | #include <unistd.h> |
| 27 | #include <errno.h> |
| 28 | #include <fcntl.h> |
| 29 | |
| 30 | #include <sys/ioctl.h> |
| 31 | #include <sys/types.h> |
| 32 | #include <sys/mman.h> |
| 33 | |
| 34 | #include <linux/msm_kgsl.h> |
| 35 | |
| 36 | #include <EGL/eglplatform.h> |
| 37 | #include <cutils/native_handle.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 38 | |
| 39 | #include <copybit.h> |
| 40 | #include <alloc_controller.h> |
| 41 | #include <memalloc.h> |
| 42 | |
| 43 | #include "c2d2.h" |
| 44 | #include "software_converter.h" |
| 45 | |
| 46 | #include <dlfcn.h> |
| 47 | |
| 48 | using gralloc::IMemAlloc; |
| 49 | using gralloc::IonController; |
| 50 | using gralloc::alloc_data; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 51 | |
| 52 | C2D_STATUS (*LINK_c2dCreateSurface)( uint32 *surface_id, |
| 53 | uint32 surface_bits, |
| 54 | C2D_SURFACE_TYPE surface_type, |
| 55 | void *surface_definition ); |
| 56 | |
| 57 | C2D_STATUS (*LINK_c2dUpdateSurface)( uint32 surface_id, |
| 58 | uint32 surface_bits, |
| 59 | C2D_SURFACE_TYPE surface_type, |
| 60 | void *surface_definition ); |
| 61 | |
| 62 | C2D_STATUS (*LINK_c2dReadSurface)( uint32 surface_id, |
| 63 | C2D_SURFACE_TYPE surface_type, |
| 64 | void *surface_definition, |
| 65 | int32 x, int32 y ); |
| 66 | |
| 67 | C2D_STATUS (*LINK_c2dDraw)( uint32 target_id, |
| 68 | uint32 target_config, C2D_RECT *target_scissor, |
| 69 | uint32 target_mask_id, uint32 target_color_key, |
| 70 | C2D_OBJECT *objects_list, uint32 num_objects ); |
| 71 | |
| 72 | C2D_STATUS (*LINK_c2dFinish)( uint32 target_id); |
| 73 | |
| 74 | C2D_STATUS (*LINK_c2dFlush)( uint32 target_id, c2d_ts_handle *timestamp); |
| 75 | |
| 76 | C2D_STATUS (*LINK_c2dWaitTimestamp)( c2d_ts_handle timestamp ); |
| 77 | |
| 78 | C2D_STATUS (*LINK_c2dDestroySurface)( uint32 surface_id ); |
| 79 | |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 80 | C2D_STATUS (*LINK_c2dMapAddr) ( int mem_fd, void * hostptr, size_t len, |
| 81 | size_t offset, uint32 flags, void ** gpuaddr); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 82 | |
| 83 | C2D_STATUS (*LINK_c2dUnMapAddr) ( void * gpuaddr); |
| 84 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 85 | C2D_STATUS (*LINK_c2dGetDriverCapabilities) ( C2D_DRIVER_INFO * driver_info); |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 86 | |
| 87 | /* create a fence fd for the timestamp */ |
| 88 | C2D_STATUS (*LINK_c2dCreateFenceFD) ( uint32 target_id, c2d_ts_handle timestamp, |
| 89 | int32 *fd); |
Naseer Ahmed | 183939d | 2013-03-14 20:44:17 -0400 | [diff] [blame] | 90 | |
| 91 | C2D_STATUS (*LINK_c2dFillSurface) ( uint32 surface_id, uint32 fill_color, |
| 92 | C2D_RECT * fill_rect); |
| 93 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 94 | /******************************************************************************/ |
| 95 | |
| 96 | #if defined(COPYBIT_Z180) |
| 97 | #define MAX_SCALE_FACTOR (4096) |
| 98 | #define MAX_DIMENSION (4096) |
| 99 | #else |
| 100 | #error "Unsupported HW version" |
| 101 | #endif |
| 102 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 103 | // The following defines can be changed as required i.e. as we encounter |
| 104 | // complex use cases. |
Sushil Chauhan | b00f59d | 2013-04-29 18:35:54 -0700 | [diff] [blame] | 105 | #define MAX_RGB_SURFACES 32 // Max. RGB layers currently supported per draw |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 106 | #define MAX_YUV_2_PLANE_SURFACES 4// Max. 2-plane YUV layers currently supported per draw |
| 107 | #define MAX_YUV_3_PLANE_SURFACES 1// Max. 3-plane YUV layers currently supported per draw |
| 108 | // +1 for the destination surface. We cannot have multiple destination surfaces. |
| 109 | #define MAX_SURFACES (MAX_RGB_SURFACES + MAX_YUV_2_PLANE_SURFACES + MAX_YUV_3_PLANE_SURFACES + 1) |
| 110 | #define NUM_SURFACE_TYPES 3 // RGB_SURFACE + YUV_SURFACE_2_PLANES + YUV_SURFACE_3_PLANES |
| 111 | #define MAX_BLIT_OBJECT_COUNT 50 // Max. blit objects that can be passed per draw |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 112 | |
| 113 | enum { |
| 114 | RGB_SURFACE, |
| 115 | YUV_SURFACE_2_PLANES, |
| 116 | YUV_SURFACE_3_PLANES |
| 117 | }; |
| 118 | |
| 119 | enum eConversionType { |
| 120 | CONVERT_TO_ANDROID_FORMAT, |
| 121 | CONVERT_TO_C2D_FORMAT |
| 122 | }; |
| 123 | |
| 124 | enum eC2DFlags { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 125 | FLAGS_PREMULTIPLIED_ALPHA = 1<<0, |
| 126 | FLAGS_YUV_DESTINATION = 1<<1, |
| 127 | FLAGS_TEMP_SRC_DST = 1<<2 |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 128 | }; |
| 129 | |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 130 | static gralloc::IAllocController* sAlloc = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 131 | /******************************************************************************/ |
| 132 | |
| 133 | /** State information for each device instance */ |
| 134 | struct copybit_context_t { |
| 135 | struct copybit_device_t device; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 136 | // Templates for the various source surfaces. These templates are created |
| 137 | // to avoid the expensive create/destroy C2D Surfaces |
| 138 | C2D_OBJECT_STR blit_rgb_object[MAX_RGB_SURFACES]; |
| 139 | C2D_OBJECT_STR blit_yuv_2_plane_object[MAX_YUV_2_PLANE_SURFACES]; |
| 140 | C2D_OBJECT_STR blit_yuv_3_plane_object[MAX_YUV_3_PLANE_SURFACES]; |
| 141 | C2D_OBJECT_STR blit_list[MAX_BLIT_OBJECT_COUNT]; // Z-ordered list of blit objects |
| 142 | C2D_DRIVER_INFO c2d_driver_info; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 143 | void *libc2d2; |
| 144 | alloc_data temp_src_buffer; |
| 145 | alloc_data temp_dst_buffer; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 146 | unsigned int dst[NUM_SURFACE_TYPES]; // dst surfaces |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 147 | uintptr_t mapped_gpu_addr[MAX_SURFACES]; // GPU addresses mapped inside copybit |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 148 | int blit_rgb_count; // Total RGB surfaces being blit |
| 149 | int blit_yuv_2_plane_count; // Total 2 plane YUV surfaces being |
| 150 | int blit_yuv_3_plane_count; // Total 3 plane YUV surfaces being blit |
| 151 | int blit_count; // Total blit objects. |
| 152 | unsigned int trg_transform; /* target transform */ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 153 | int fb_width; |
| 154 | int fb_height; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 155 | int src_global_alpha; |
| 156 | int config_mask; |
| 157 | int dst_surface_type; |
| 158 | bool is_premultiplied_alpha; |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 159 | void* time_stamp; |
Arun Kumar K.R | 14031eb | 2013-04-15 14:26:43 -0700 | [diff] [blame] | 160 | bool dst_surface_mapped; // Set when dst surface is mapped to GPU addr |
| 161 | void* dst_surface_base; // Stores the dst surface addr |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 162 | |
| 163 | // used for signaling the wait thread |
| 164 | bool wait_timestamp; |
| 165 | pthread_t wait_thread_id; |
| 166 | bool stop_thread; |
| 167 | pthread_mutex_t wait_cleanup_lock; |
| 168 | pthread_cond_t wait_cleanup_cond; |
| 169 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | struct bufferInfo { |
| 173 | int width; |
| 174 | int height; |
| 175 | int format; |
| 176 | }; |
| 177 | |
| 178 | struct yuvPlaneInfo { |
| 179 | int yStride; //luma stride |
| 180 | int plane1_stride; |
| 181 | int plane2_stride; |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 182 | size_t plane1_offset; |
| 183 | size_t plane2_offset; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | /** |
| 187 | * Common hardware methods |
| 188 | */ |
| 189 | |
| 190 | static int open_copybit(const struct hw_module_t* module, const char* name, |
| 191 | struct hw_device_t** device); |
| 192 | |
| 193 | static struct hw_module_methods_t copybit_module_methods = { |
| 194 | open: open_copybit |
| 195 | }; |
| 196 | |
| 197 | /* |
| 198 | * The COPYBIT Module |
| 199 | */ |
| 200 | struct copybit_module_t HAL_MODULE_INFO_SYM = { |
| 201 | common: { |
| 202 | tag: HARDWARE_MODULE_TAG, |
| 203 | version_major: 1, |
| 204 | version_minor: 0, |
| 205 | id: COPYBIT_HARDWARE_MODULE_ID, |
| 206 | name: "QCT COPYBIT C2D 2.0 Module", |
| 207 | author: "Qualcomm", |
| 208 | methods: ©bit_module_methods |
| 209 | } |
| 210 | }; |
| 211 | |
| 212 | |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 213 | /* thread function which waits on the timeStamp and cleans up the surfaces */ |
| 214 | static void* c2d_wait_loop(void* ptr) { |
| 215 | copybit_context_t* ctx = (copybit_context_t*)(ptr); |
| 216 | char thread_name[64] = "copybitWaitThr"; |
| 217 | prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0); |
| 218 | setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); |
| 219 | |
| 220 | while(ctx->stop_thread == false) { |
| 221 | pthread_mutex_lock(&ctx->wait_cleanup_lock); |
| 222 | while(ctx->wait_timestamp == false && !ctx->stop_thread) { |
| 223 | pthread_cond_wait(&(ctx->wait_cleanup_cond), |
| 224 | &(ctx->wait_cleanup_lock)); |
| 225 | } |
| 226 | if(ctx->wait_timestamp) { |
| 227 | if(LINK_c2dWaitTimestamp(ctx->time_stamp)) { |
| 228 | ALOGE("%s: LINK_c2dWaitTimeStamp ERROR!!", __FUNCTION__); |
| 229 | } |
| 230 | ctx->wait_timestamp = false; |
| 231 | // Unmap any mapped addresses. |
| 232 | for (int i = 0; i < MAX_SURFACES; i++) { |
| 233 | if (ctx->mapped_gpu_addr[i]) { |
| 234 | LINK_c2dUnMapAddr( (void*)ctx->mapped_gpu_addr[i]); |
| 235 | ctx->mapped_gpu_addr[i] = 0; |
| 236 | } |
| 237 | } |
| 238 | // Reset the counts after the draw. |
| 239 | ctx->blit_rgb_count = 0; |
| 240 | ctx->blit_yuv_2_plane_count = 0; |
| 241 | ctx->blit_yuv_3_plane_count = 0; |
| 242 | ctx->blit_count = 0; |
Arun Kumar K.R | 14031eb | 2013-04-15 14:26:43 -0700 | [diff] [blame] | 243 | ctx->dst_surface_mapped = false; |
| 244 | ctx->dst_surface_base = 0; |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 245 | } |
| 246 | pthread_mutex_unlock(&ctx->wait_cleanup_lock); |
| 247 | if(ctx->stop_thread) |
| 248 | break; |
| 249 | } |
| 250 | pthread_exit(NULL); |
| 251 | return NULL; |
| 252 | } |
| 253 | |
| 254 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 255 | /* convert COPYBIT_FORMAT to C2D format */ |
| 256 | static int get_format(int format) { |
| 257 | switch (format) { |
| 258 | case HAL_PIXEL_FORMAT_RGB_565: return C2D_COLOR_FORMAT_565_RGB; |
Omprakash Dhyade | 3cc819e | 2014-05-30 16:52:46 -0700 | [diff] [blame] | 259 | case HAL_PIXEL_FORMAT_RGB_888: return C2D_COLOR_FORMAT_888_RGB | |
| 260 | C2D_FORMAT_SWAP_RB; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 261 | case HAL_PIXEL_FORMAT_RGBX_8888: return C2D_COLOR_FORMAT_8888_ARGB | |
| 262 | C2D_FORMAT_SWAP_RB | |
| 263 | C2D_FORMAT_DISABLE_ALPHA; |
| 264 | case HAL_PIXEL_FORMAT_RGBA_8888: return C2D_COLOR_FORMAT_8888_ARGB | |
| 265 | C2D_FORMAT_SWAP_RB; |
| 266 | case HAL_PIXEL_FORMAT_BGRA_8888: return C2D_COLOR_FORMAT_8888_ARGB; |
Ramkumar Radhakrishnan | 9643952 | 2014-10-09 13:37:52 -0700 | [diff] [blame] | 267 | case HAL_PIXEL_FORMAT_RGBA_5551: return C2D_COLOR_FORMAT_5551_RGBA; |
| 268 | case HAL_PIXEL_FORMAT_RGBA_4444: return C2D_COLOR_FORMAT_4444_RGBA; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 269 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: return C2D_COLOR_FORMAT_420_NV12; |
| 270 | case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:return C2D_COLOR_FORMAT_420_NV12; |
| 271 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: return C2D_COLOR_FORMAT_420_NV21; |
| 272 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: return C2D_COLOR_FORMAT_420_NV12 | |
| 273 | C2D_FORMAT_MACROTILED; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 274 | default: ALOGE("%s: invalid format (0x%x", |
| 275 | __FUNCTION__, format); |
| 276 | return -EINVAL; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 277 | } |
| 278 | return -EINVAL; |
| 279 | } |
| 280 | |
| 281 | /* Get the C2D formats needed for conversion to YUV */ |
| 282 | static int get_c2d_format_for_yuv_destination(int halFormat) { |
| 283 | switch (halFormat) { |
| 284 | // We do not swap the RB when the target is YUV |
| 285 | case HAL_PIXEL_FORMAT_RGBX_8888: return C2D_COLOR_FORMAT_8888_ARGB | |
| 286 | C2D_FORMAT_DISABLE_ALPHA; |
| 287 | case HAL_PIXEL_FORMAT_RGBA_8888: return C2D_COLOR_FORMAT_8888_ARGB; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 288 | // The U and V need to be interchanged when the target is YUV |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 289 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: return C2D_COLOR_FORMAT_420_NV21; |
| 290 | case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:return C2D_COLOR_FORMAT_420_NV21; |
| 291 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: return C2D_COLOR_FORMAT_420_NV12; |
| 292 | default: return get_format(halFormat); |
| 293 | } |
| 294 | return -EINVAL; |
| 295 | } |
| 296 | |
| 297 | /* ------------------------------------------------------------------- *//*! |
| 298 | * \internal |
| 299 | * \brief Get the bpp for a particular color format |
| 300 | * \param color format |
| 301 | * \return bits per pixel |
| 302 | *//* ------------------------------------------------------------------- */ |
| 303 | int c2diGetBpp(int32 colorformat) |
| 304 | { |
| 305 | |
| 306 | int c2dBpp = 0; |
| 307 | |
| 308 | switch(colorformat&0xFF) |
| 309 | { |
| 310 | case C2D_COLOR_FORMAT_4444_RGBA: |
| 311 | case C2D_COLOR_FORMAT_4444_ARGB: |
| 312 | case C2D_COLOR_FORMAT_1555_ARGB: |
| 313 | case C2D_COLOR_FORMAT_565_RGB: |
| 314 | case C2D_COLOR_FORMAT_5551_RGBA: |
| 315 | c2dBpp = 16; |
| 316 | break; |
| 317 | case C2D_COLOR_FORMAT_8888_RGBA: |
| 318 | case C2D_COLOR_FORMAT_8888_ARGB: |
| 319 | c2dBpp = 32; |
| 320 | break; |
Sushil Chauhan | 43755de | 2014-05-15 11:20:32 -0700 | [diff] [blame] | 321 | case C2D_COLOR_FORMAT_888_RGB: |
| 322 | c2dBpp = 24; |
| 323 | break; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 324 | case C2D_COLOR_FORMAT_8_L: |
| 325 | case C2D_COLOR_FORMAT_8_A: |
| 326 | c2dBpp = 8; |
| 327 | break; |
| 328 | case C2D_COLOR_FORMAT_4_A: |
| 329 | c2dBpp = 4; |
| 330 | break; |
| 331 | case C2D_COLOR_FORMAT_1: |
| 332 | c2dBpp = 1; |
| 333 | break; |
| 334 | default: |
| 335 | ALOGE("%s ERROR", __func__); |
| 336 | break; |
| 337 | } |
| 338 | return c2dBpp; |
| 339 | } |
| 340 | |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 341 | static size_t c2d_get_gpuaddr(copybit_context_t* ctx, |
Arun Kumar K.R | 14031eb | 2013-04-15 14:26:43 -0700 | [diff] [blame] | 342 | struct private_handle_t *handle, int &mapped_idx) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 343 | { |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 344 | uint32 memtype; |
| 345 | size_t *gpuaddr = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 346 | C2D_STATUS rc; |
Arun Kumar K.R | 14031eb | 2013-04-15 14:26:43 -0700 | [diff] [blame] | 347 | int freeindex = 0; |
| 348 | bool mapaddr = false; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 349 | |
| 350 | if(!handle) |
| 351 | return 0; |
| 352 | |
Naseer Ahmed | 8d0d72a | 2014-12-19 16:25:09 -0500 | [diff] [blame] | 353 | if (handle->flags & private_handle_t::PRIV_FLAGS_USES_ION) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 354 | memtype = KGSL_USER_MEM_TYPE_ION; |
| 355 | else { |
| 356 | ALOGE("Invalid handle flags: 0x%x", handle->flags); |
| 357 | return 0; |
| 358 | } |
| 359 | |
Arun Kumar K.R | 14031eb | 2013-04-15 14:26:43 -0700 | [diff] [blame] | 360 | // Check for a freeindex in the mapped_gpu_addr list |
| 361 | for (freeindex = 0; freeindex < MAX_SURFACES; freeindex++) { |
| 362 | if (ctx->mapped_gpu_addr[freeindex] == 0) { |
| 363 | // free index is available |
| 364 | // map GPU addr and use this as mapped_idx |
| 365 | mapaddr = true; |
| 366 | break; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 367 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 368 | } |
Arun Kumar K.R | 14031eb | 2013-04-15 14:26:43 -0700 | [diff] [blame] | 369 | |
| 370 | if(mapaddr) { |
| 371 | rc = LINK_c2dMapAddr(handle->fd, (void*)handle->base, handle->size, |
| 372 | handle->offset, memtype, (void**)&gpuaddr); |
| 373 | |
| 374 | if (rc == C2D_STATUS_OK) { |
| 375 | // We have mapped the GPU address inside copybit. We need to unmap |
| 376 | // this address after the blit. Store this address |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 377 | ctx->mapped_gpu_addr[freeindex] = (size_t)gpuaddr; |
Arun Kumar K.R | 14031eb | 2013-04-15 14:26:43 -0700 | [diff] [blame] | 378 | mapped_idx = freeindex; |
| 379 | } |
| 380 | } |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 381 | return (size_t)gpuaddr; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 384 | static void unmap_gpuaddr(copybit_context_t* ctx, int mapped_idx) |
| 385 | { |
| 386 | if (!ctx || (mapped_idx == -1)) |
| 387 | return; |
| 388 | |
| 389 | if (ctx->mapped_gpu_addr[mapped_idx]) { |
| 390 | LINK_c2dUnMapAddr( (void*)ctx->mapped_gpu_addr[mapped_idx]); |
| 391 | ctx->mapped_gpu_addr[mapped_idx] = 0; |
| 392 | } |
| 393 | } |
| 394 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 395 | static int is_supported_rgb_format(int format) |
| 396 | { |
| 397 | switch(format) { |
| 398 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 399 | case HAL_PIXEL_FORMAT_RGBX_8888: |
Sushil Chauhan | 43755de | 2014-05-15 11:20:32 -0700 | [diff] [blame] | 400 | case HAL_PIXEL_FORMAT_RGB_888: |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 401 | case HAL_PIXEL_FORMAT_RGB_565: |
Ramkumar Radhakrishnan | 9643952 | 2014-10-09 13:37:52 -0700 | [diff] [blame] | 402 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 403 | case HAL_PIXEL_FORMAT_RGBA_5551: |
| 404 | case HAL_PIXEL_FORMAT_RGBA_4444: { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 405 | return COPYBIT_SUCCESS; |
| 406 | } |
| 407 | default: |
| 408 | return COPYBIT_FAILURE; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | static int get_num_planes(int format) |
| 413 | { |
| 414 | switch(format) { |
| 415 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
| 416 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 417 | case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: |
| 418 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: { |
| 419 | return 2; |
| 420 | } |
| 421 | case HAL_PIXEL_FORMAT_YV12: { |
| 422 | return 3; |
| 423 | } |
| 424 | default: |
| 425 | return COPYBIT_FAILURE; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | static int is_supported_yuv_format(int format) |
| 430 | { |
| 431 | switch(format) { |
| 432 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
| 433 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 434 | case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: |
| 435 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: { |
| 436 | return COPYBIT_SUCCESS; |
| 437 | } |
| 438 | default: |
| 439 | return COPYBIT_FAILURE; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | static int is_valid_destination_format(int format) |
| 444 | { |
| 445 | if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) { |
| 446 | // C2D does not support NV12Tile as a destination format. |
| 447 | return COPYBIT_FAILURE; |
| 448 | } |
| 449 | return COPYBIT_SUCCESS; |
| 450 | } |
| 451 | |
| 452 | static int calculate_yuv_offset_and_stride(const bufferInfo& info, |
| 453 | yuvPlaneInfo& yuvInfo) |
| 454 | { |
| 455 | int width = info.width; |
| 456 | int height = info.height; |
| 457 | int format = info.format; |
| 458 | |
| 459 | int aligned_height = 0; |
| 460 | int aligned_width = 0, size = 0; |
| 461 | |
| 462 | switch (format) { |
| 463 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: { |
| 464 | /* NV12 Tile buffers have their luma height aligned to 32bytes and width |
| 465 | * aligned to 128 bytes. The chroma offset starts at an 8K boundary |
| 466 | */ |
| 467 | aligned_height = ALIGN(height, 32); |
| 468 | aligned_width = ALIGN(width, 128); |
| 469 | size = aligned_width * aligned_height; |
| 470 | yuvInfo.plane1_offset = ALIGN(size,8192); |
| 471 | yuvInfo.yStride = aligned_width; |
| 472 | yuvInfo.plane1_stride = aligned_width; |
| 473 | break; |
| 474 | } |
| 475 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
| 476 | case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: |
| 477 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: { |
| 478 | aligned_width = ALIGN(width, 32); |
| 479 | yuvInfo.yStride = aligned_width; |
| 480 | yuvInfo.plane1_stride = aligned_width; |
| 481 | if (HAL_PIXEL_FORMAT_NV12_ENCODEABLE == format) { |
| 482 | // The encoder requires a 2K aligned chroma offset |
| 483 | yuvInfo.plane1_offset = ALIGN(aligned_width * height, 2048); |
| 484 | } else |
| 485 | yuvInfo.plane1_offset = aligned_width * height; |
| 486 | |
| 487 | break; |
| 488 | } |
| 489 | default: { |
| 490 | return COPYBIT_FAILURE; |
| 491 | } |
| 492 | } |
| 493 | return COPYBIT_SUCCESS; |
| 494 | } |
| 495 | |
| 496 | /** create C2D surface from copybit image */ |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 497 | static int set_image(copybit_context_t* ctx, uint32 surfaceId, |
| 498 | const struct copybit_image_t *rhs, |
| 499 | const eC2DFlags flags, int &mapped_idx) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 500 | { |
| 501 | struct private_handle_t* handle = (struct private_handle_t*)rhs->handle; |
| 502 | C2D_SURFACE_TYPE surfaceType; |
| 503 | int status = COPYBIT_SUCCESS; |
Naseer Ahmed | 9eb5e09 | 2014-09-25 13:24:44 -0400 | [diff] [blame] | 504 | uint64_t gpuaddr = 0; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 505 | int c2d_format; |
| 506 | mapped_idx = -1; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 507 | |
| 508 | if (flags & FLAGS_YUV_DESTINATION) { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 509 | c2d_format = get_c2d_format_for_yuv_destination(rhs->format); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 510 | } else { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 511 | c2d_format = get_format(rhs->format); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 514 | if(c2d_format == -EINVAL) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 515 | ALOGE("%s: invalid format", __FUNCTION__); |
| 516 | return -EINVAL; |
| 517 | } |
| 518 | |
| 519 | if(handle == NULL) { |
| 520 | ALOGE("%s: invalid handle", __func__); |
| 521 | return -EINVAL; |
| 522 | } |
| 523 | |
| 524 | if (handle->gpuaddr == 0) { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 525 | gpuaddr = c2d_get_gpuaddr(ctx, handle, mapped_idx); |
| 526 | if(!gpuaddr) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 527 | ALOGE("%s: c2d_get_gpuaddr failed", __FUNCTION__); |
| 528 | return COPYBIT_FAILURE; |
| 529 | } |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 530 | } else { |
| 531 | gpuaddr = handle->gpuaddr; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | /* create C2D surface */ |
| 535 | if(is_supported_rgb_format(rhs->format) == COPYBIT_SUCCESS) { |
| 536 | /* RGB */ |
| 537 | C2D_RGB_SURFACE_DEF surfaceDef; |
| 538 | |
| 539 | surfaceType = (C2D_SURFACE_TYPE) (C2D_SURFACE_RGB_HOST | C2D_SURFACE_WITH_PHYS); |
| 540 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 541 | surfaceDef.phys = (void*) gpuaddr; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 542 | surfaceDef.buffer = (void*) (handle->base); |
| 543 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 544 | surfaceDef.format = c2d_format | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 545 | ((flags & FLAGS_PREMULTIPLIED_ALPHA) ? C2D_FORMAT_PREMULTIPLIED : 0); |
| 546 | surfaceDef.width = rhs->w; |
| 547 | surfaceDef.height = rhs->h; |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 548 | int aligned_width = ALIGN((int)surfaceDef.width,32); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 549 | surfaceDef.stride = (aligned_width * c2diGetBpp(surfaceDef.format))>>3; |
| 550 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 551 | if(LINK_c2dUpdateSurface( surfaceId,C2D_TARGET | C2D_SOURCE, surfaceType, |
| 552 | &surfaceDef)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 553 | ALOGE("%s: RGB Surface c2dUpdateSurface ERROR", __FUNCTION__); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 554 | unmap_gpuaddr(ctx, mapped_idx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 555 | status = COPYBIT_FAILURE; |
| 556 | } |
| 557 | } else if (is_supported_yuv_format(rhs->format) == COPYBIT_SUCCESS) { |
| 558 | C2D_YUV_SURFACE_DEF surfaceDef; |
| 559 | memset(&surfaceDef, 0, sizeof(surfaceDef)); |
| 560 | surfaceType = (C2D_SURFACE_TYPE)(C2D_SURFACE_YUV_HOST | C2D_SURFACE_WITH_PHYS); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 561 | surfaceDef.format = c2d_format; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 562 | |
| 563 | bufferInfo info; |
| 564 | info.width = rhs->w; |
| 565 | info.height = rhs->h; |
| 566 | info.format = rhs->format; |
| 567 | |
Naseer Ahmed | b16edac | 2012-07-15 23:56:21 -0700 | [diff] [blame] | 568 | yuvPlaneInfo yuvInfo = {0}; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 569 | status = calculate_yuv_offset_and_stride(info, yuvInfo); |
| 570 | if(status != COPYBIT_SUCCESS) { |
| 571 | ALOGE("%s: calculate_yuv_offset_and_stride error", __FUNCTION__); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 572 | unmap_gpuaddr(ctx, mapped_idx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | surfaceDef.width = rhs->w; |
| 576 | surfaceDef.height = rhs->h; |
| 577 | surfaceDef.plane0 = (void*) (handle->base); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 578 | surfaceDef.phys0 = (void*) (gpuaddr); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 579 | surfaceDef.stride0 = yuvInfo.yStride; |
| 580 | |
| 581 | surfaceDef.plane1 = (void*) (handle->base + yuvInfo.plane1_offset); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 582 | surfaceDef.phys1 = (void*) (gpuaddr + yuvInfo.plane1_offset); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 583 | surfaceDef.stride1 = yuvInfo.plane1_stride; |
| 584 | if (3 == get_num_planes(rhs->format)) { |
| 585 | surfaceDef.plane2 = (void*) (handle->base + yuvInfo.plane2_offset); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 586 | surfaceDef.phys2 = (void*) (gpuaddr + yuvInfo.plane2_offset); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 587 | surfaceDef.stride2 = yuvInfo.plane2_stride; |
| 588 | } |
| 589 | |
| 590 | if(LINK_c2dUpdateSurface( surfaceId,C2D_TARGET | C2D_SOURCE, surfaceType, |
| 591 | &surfaceDef)) { |
| 592 | ALOGE("%s: YUV Surface c2dUpdateSurface ERROR", __FUNCTION__); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 593 | unmap_gpuaddr(ctx, mapped_idx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 594 | status = COPYBIT_FAILURE; |
| 595 | } |
| 596 | } else { |
| 597 | ALOGE("%s: invalid format 0x%x", __FUNCTION__, rhs->format); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 598 | unmap_gpuaddr(ctx, mapped_idx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 599 | status = COPYBIT_FAILURE; |
| 600 | } |
| 601 | |
| 602 | return status; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 605 | /** copy the bits */ |
| 606 | static int msm_copybit(struct copybit_context_t *ctx, unsigned int target) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 607 | { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 608 | if (ctx->blit_count == 0) { |
| 609 | return COPYBIT_SUCCESS; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 612 | for (int i = 0; i < ctx->blit_count; i++) |
| 613 | { |
| 614 | ctx->blit_list[i].next = &(ctx->blit_list[i+1]); |
| 615 | } |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 616 | ctx->blit_list[ctx->blit_count-1].next = NULL; |
Arun Kumar K.R | b2fc956 | 2013-02-25 16:28:51 -0800 | [diff] [blame] | 617 | uint32_t target_transform = ctx->trg_transform; |
| 618 | if (ctx->c2d_driver_info.capabilities_mask & |
| 619 | C2D_DRIVER_SUPPORTS_OVERRIDE_TARGET_ROTATE_OP) { |
| 620 | // For A3xx - set 0x0 as the transform is set in the config_mask |
| 621 | target_transform = 0x0; |
| 622 | } |
| 623 | if(LINK_c2dDraw(target, target_transform, 0x0, 0, 0, ctx->blit_list, |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 624 | ctx->blit_count)) { |
| 625 | ALOGE("%s: LINK_c2dDraw ERROR", __FUNCTION__); |
| 626 | return COPYBIT_FAILURE; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 627 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 628 | return COPYBIT_SUCCESS; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 631 | |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 632 | |
| 633 | static int flush_get_fence_copybit (struct copybit_device_t *dev, int* fd) |
| 634 | { |
| 635 | struct copybit_context_t* ctx = (struct copybit_context_t*)dev; |
| 636 | int status = COPYBIT_FAILURE; |
| 637 | if (!ctx) |
| 638 | return COPYBIT_FAILURE; |
| 639 | pthread_mutex_lock(&ctx->wait_cleanup_lock); |
| 640 | status = msm_copybit(ctx, ctx->dst[ctx->dst_surface_type]); |
| 641 | |
| 642 | if(LINK_c2dFlush(ctx->dst[ctx->dst_surface_type], &ctx->time_stamp)) { |
| 643 | ALOGE("%s: LINK_c2dFlush ERROR", __FUNCTION__); |
| 644 | // unlock the mutex and return failure |
| 645 | pthread_mutex_unlock(&ctx->wait_cleanup_lock); |
| 646 | return COPYBIT_FAILURE; |
| 647 | } |
| 648 | if(LINK_c2dCreateFenceFD(ctx->dst[ctx->dst_surface_type], ctx->time_stamp, |
| 649 | fd)) { |
| 650 | ALOGE("%s: LINK_c2dCreateFenceFD ERROR", __FUNCTION__); |
| 651 | status = COPYBIT_FAILURE; |
| 652 | } |
| 653 | if(status == COPYBIT_SUCCESS) { |
| 654 | //signal the wait_thread |
| 655 | ctx->wait_timestamp = true; |
| 656 | pthread_cond_signal(&ctx->wait_cleanup_cond); |
| 657 | } |
| 658 | pthread_mutex_unlock(&ctx->wait_cleanup_lock); |
| 659 | return status; |
| 660 | } |
| 661 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 662 | static int finish_copybit(struct copybit_device_t *dev) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 663 | { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 664 | struct copybit_context_t* ctx = (struct copybit_context_t*)dev; |
| 665 | if (!ctx) |
| 666 | return COPYBIT_FAILURE; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 667 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 668 | int status = msm_copybit(ctx, ctx->dst[ctx->dst_surface_type]); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 669 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 670 | if(LINK_c2dFinish(ctx->dst[ctx->dst_surface_type])) { |
| 671 | ALOGE("%s: LINK_c2dFinish ERROR", __FUNCTION__); |
| 672 | return COPYBIT_FAILURE; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 675 | // Unmap any mapped addresses. |
| 676 | for (int i = 0; i < MAX_SURFACES; i++) { |
| 677 | if (ctx->mapped_gpu_addr[i]) { |
| 678 | LINK_c2dUnMapAddr( (void*)ctx->mapped_gpu_addr[i]); |
| 679 | ctx->mapped_gpu_addr[i] = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 680 | } |
| 681 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 682 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 683 | // Reset the counts after the draw. |
| 684 | ctx->blit_rgb_count = 0; |
| 685 | ctx->blit_yuv_2_plane_count = 0; |
| 686 | ctx->blit_yuv_3_plane_count = 0; |
| 687 | ctx->blit_count = 0; |
Pawan Kumar | 74d9ea9 | 2013-05-03 14:25:49 +0530 | [diff] [blame] | 688 | ctx->dst_surface_mapped = false; |
| 689 | ctx->dst_surface_base = 0; |
| 690 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 691 | return status; |
| 692 | } |
| 693 | |
Naseer Ahmed | 183939d | 2013-03-14 20:44:17 -0400 | [diff] [blame] | 694 | static int clear_copybit(struct copybit_device_t *dev, |
| 695 | struct copybit_image_t const *buf, |
| 696 | struct copybit_rect_t *rect) |
| 697 | { |
Arun Kumar K.R | 71cfd81 | 2013-04-03 11:25:41 -0700 | [diff] [blame] | 698 | int ret = COPYBIT_SUCCESS; |
Naseer Ahmed | 183939d | 2013-03-14 20:44:17 -0400 | [diff] [blame] | 699 | int flags = FLAGS_PREMULTIPLIED_ALPHA; |
| 700 | int mapped_dst_idx = -1; |
| 701 | struct copybit_context_t* ctx = (struct copybit_context_t*)dev; |
| 702 | C2D_RECT c2drect = {rect->l, rect->t, rect->r - rect->l, rect->b - rect->t}; |
Arun Kumar K.R | 71cfd81 | 2013-04-03 11:25:41 -0700 | [diff] [blame] | 703 | pthread_mutex_lock(&ctx->wait_cleanup_lock); |
Arun Kumar K.R | 14031eb | 2013-04-15 14:26:43 -0700 | [diff] [blame] | 704 | if(!ctx->dst_surface_mapped) { |
| 705 | ret = set_image(ctx, ctx->dst[RGB_SURFACE], buf, |
| 706 | (eC2DFlags)flags, mapped_dst_idx); |
| 707 | if(ret) { |
| 708 | ALOGE("%s: set_image error", __FUNCTION__); |
| 709 | unmap_gpuaddr(ctx, mapped_dst_idx); |
| 710 | pthread_mutex_unlock(&ctx->wait_cleanup_lock); |
| 711 | return COPYBIT_FAILURE; |
| 712 | } |
| 713 | //clear_copybit is the first call made by HWC for each composition |
| 714 | //with the dest surface, hence set dst_surface_mapped. |
| 715 | ctx->dst_surface_mapped = true; |
| 716 | ctx->dst_surface_base = buf->base; |
| 717 | ret = LINK_c2dFillSurface(ctx->dst[RGB_SURFACE], 0x0, &c2drect); |
Naseer Ahmed | 183939d | 2013-03-14 20:44:17 -0400 | [diff] [blame] | 718 | } |
Arun Kumar K.R | 71cfd81 | 2013-04-03 11:25:41 -0700 | [diff] [blame] | 719 | pthread_mutex_unlock(&ctx->wait_cleanup_lock); |
Naseer Ahmed | 183939d | 2013-03-14 20:44:17 -0400 | [diff] [blame] | 720 | return ret; |
| 721 | } |
| 722 | |
| 723 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 724 | /** setup rectangles */ |
| 725 | static void set_rects(struct copybit_context_t *ctx, |
| 726 | C2D_OBJECT *c2dObject, |
| 727 | const struct copybit_rect_t *dst, |
| 728 | const struct copybit_rect_t *src, |
| 729 | const struct copybit_rect_t *scissor) |
| 730 | { |
| 731 | // Set the target rect. |
| 732 | if((ctx->trg_transform & C2D_TARGET_ROTATE_90) && |
| 733 | (ctx->trg_transform & C2D_TARGET_ROTATE_180)) { |
| 734 | /* target rotation is 270 */ |
| 735 | c2dObject->target_rect.x = (dst->t)<<16; |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 736 | c2dObject->target_rect.y = ctx->fb_width? |
| 737 | (ALIGN(ctx->fb_width,32)- dst->r):dst->r; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 738 | c2dObject->target_rect.y = c2dObject->target_rect.y<<16; |
| 739 | c2dObject->target_rect.height = ((dst->r) - (dst->l))<<16; |
| 740 | c2dObject->target_rect.width = ((dst->b) - (dst->t))<<16; |
| 741 | } else if(ctx->trg_transform & C2D_TARGET_ROTATE_90) { |
| 742 | c2dObject->target_rect.x = ctx->fb_height?(ctx->fb_height - dst->b):dst->b; |
| 743 | c2dObject->target_rect.x = c2dObject->target_rect.x<<16; |
| 744 | c2dObject->target_rect.y = (dst->l)<<16; |
| 745 | c2dObject->target_rect.height = ((dst->r) - (dst->l))<<16; |
| 746 | c2dObject->target_rect.width = ((dst->b) - (dst->t))<<16; |
| 747 | } else if(ctx->trg_transform & C2D_TARGET_ROTATE_180) { |
| 748 | c2dObject->target_rect.y = ctx->fb_height?(ctx->fb_height - dst->b):dst->b; |
| 749 | c2dObject->target_rect.y = c2dObject->target_rect.y<<16; |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 750 | c2dObject->target_rect.x = ctx->fb_width? |
| 751 | (ALIGN(ctx->fb_width,32) - dst->r):dst->r; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 752 | c2dObject->target_rect.x = c2dObject->target_rect.x<<16; |
| 753 | c2dObject->target_rect.height = ((dst->b) - (dst->t))<<16; |
| 754 | c2dObject->target_rect.width = ((dst->r) - (dst->l))<<16; |
| 755 | } else { |
| 756 | c2dObject->target_rect.x = (dst->l)<<16; |
| 757 | c2dObject->target_rect.y = (dst->t)<<16; |
| 758 | c2dObject->target_rect.height = ((dst->b) - (dst->t))<<16; |
| 759 | c2dObject->target_rect.width = ((dst->r) - (dst->l))<<16; |
| 760 | } |
| 761 | c2dObject->config_mask |= C2D_TARGET_RECT_BIT; |
| 762 | |
| 763 | // Set the source rect |
| 764 | c2dObject->source_rect.x = (src->l)<<16; |
| 765 | c2dObject->source_rect.y = (src->t)<<16; |
| 766 | c2dObject->source_rect.height = ((src->b) - (src->t))<<16; |
| 767 | c2dObject->source_rect.width = ((src->r) - (src->l))<<16; |
| 768 | c2dObject->config_mask |= C2D_SOURCE_RECT_BIT; |
| 769 | |
| 770 | // Set the scissor rect |
| 771 | c2dObject->scissor_rect.x = scissor->l; |
| 772 | c2dObject->scissor_rect.y = scissor->t; |
| 773 | c2dObject->scissor_rect.height = (scissor->b) - (scissor->t); |
| 774 | c2dObject->scissor_rect.width = (scissor->r) - (scissor->l); |
| 775 | c2dObject->config_mask |= C2D_SCISSOR_RECT_BIT; |
| 776 | } |
| 777 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 778 | /*****************************************************************************/ |
| 779 | |
| 780 | /** Set a parameter to value */ |
| 781 | static int set_parameter_copybit( |
| 782 | struct copybit_device_t *dev, |
| 783 | int name, |
| 784 | int value) |
| 785 | { |
| 786 | struct copybit_context_t* ctx = (struct copybit_context_t*)dev; |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 787 | int status = COPYBIT_SUCCESS; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 788 | if (!ctx) { |
| 789 | ALOGE("%s: null context", __FUNCTION__); |
| 790 | return -EINVAL; |
| 791 | } |
| 792 | |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 793 | pthread_mutex_lock(&ctx->wait_cleanup_lock); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 794 | switch(name) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 795 | case COPYBIT_PLANE_ALPHA: |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 796 | { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 797 | if (value < 0) value = 0; |
| 798 | if (value >= 256) value = 255; |
| 799 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 800 | ctx->src_global_alpha = value; |
| 801 | if (value < 255) |
| 802 | ctx->config_mask |= C2D_GLOBAL_ALPHA_BIT; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 803 | else |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 804 | ctx->config_mask &= ~C2D_GLOBAL_ALPHA_BIT; |
| 805 | } |
| 806 | break; |
| 807 | case COPYBIT_BLEND_MODE: |
| 808 | { |
| 809 | if (value == COPYBIT_BLENDING_NONE) { |
| 810 | ctx->config_mask |= C2D_ALPHA_BLEND_NONE; |
| 811 | ctx->is_premultiplied_alpha = true; |
| 812 | } else if (value == COPYBIT_BLENDING_PREMULT) { |
| 813 | ctx->is_premultiplied_alpha = true; |
| 814 | } else { |
| 815 | ctx->config_mask &= ~C2D_ALPHA_BLEND_NONE; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 816 | } |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 817 | } |
| 818 | break; |
| 819 | case COPYBIT_TRANSFORM: |
| 820 | { |
| 821 | unsigned int transform = 0; |
| 822 | uint32 config_mask = 0; |
| 823 | config_mask |= C2D_OVERRIDE_GLOBAL_TARGET_ROTATE_CONFIG; |
| 824 | if((value & 0x7) == COPYBIT_TRANSFORM_ROT_180) { |
| 825 | transform = C2D_TARGET_ROTATE_180; |
| 826 | config_mask |= C2D_OVERRIDE_TARGET_ROTATE_180; |
| 827 | } else if((value & 0x7) == COPYBIT_TRANSFORM_ROT_270) { |
| 828 | transform = C2D_TARGET_ROTATE_90; |
| 829 | config_mask |= C2D_OVERRIDE_TARGET_ROTATE_90; |
| 830 | } else if(value == COPYBIT_TRANSFORM_ROT_90) { |
| 831 | transform = C2D_TARGET_ROTATE_270; |
| 832 | config_mask |= C2D_OVERRIDE_TARGET_ROTATE_270; |
| 833 | } else { |
| 834 | config_mask |= C2D_OVERRIDE_TARGET_ROTATE_0; |
| 835 | if(value & COPYBIT_TRANSFORM_FLIP_H) { |
| 836 | config_mask |= C2D_MIRROR_H_BIT; |
| 837 | } else if(value & COPYBIT_TRANSFORM_FLIP_V) { |
| 838 | config_mask |= C2D_MIRROR_V_BIT; |
| 839 | } |
| 840 | } |
| 841 | |
Arun Kumar K.R | b2fc956 | 2013-02-25 16:28:51 -0800 | [diff] [blame] | 842 | if (ctx->c2d_driver_info.capabilities_mask & |
| 843 | C2D_DRIVER_SUPPORTS_OVERRIDE_TARGET_ROTATE_OP) { |
| 844 | ctx->config_mask |= config_mask; |
| 845 | } else { |
| 846 | // The transform for this surface does not match the current |
| 847 | // target transform. Draw all previous surfaces. This will be |
| 848 | // changed once we have a new mechanism to send different |
| 849 | // target rotations to c2d. |
| 850 | finish_copybit(dev); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 851 | } |
| 852 | ctx->trg_transform = transform; |
| 853 | } |
| 854 | break; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 855 | case COPYBIT_FRAMEBUFFER_WIDTH: |
| 856 | ctx->fb_width = value; |
| 857 | break; |
| 858 | case COPYBIT_FRAMEBUFFER_HEIGHT: |
| 859 | ctx->fb_height = value; |
| 860 | break; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 861 | case COPYBIT_ROTATION_DEG: |
| 862 | case COPYBIT_DITHER: |
| 863 | case COPYBIT_BLUR: |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 864 | case COPYBIT_BLIT_TO_FRAMEBUFFER: |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 865 | // Do nothing |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 866 | break; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 867 | default: |
| 868 | ALOGE("%s: default case param=0x%x", __FUNCTION__, name); |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 869 | status = -EINVAL; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 870 | break; |
| 871 | } |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 872 | pthread_mutex_unlock(&ctx->wait_cleanup_lock); |
| 873 | return status; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | /** Get a static info value */ |
| 877 | static int get(struct copybit_device_t *dev, int name) |
| 878 | { |
| 879 | struct copybit_context_t* ctx = (struct copybit_context_t*)dev; |
| 880 | int value; |
| 881 | |
| 882 | if (!ctx) { |
| 883 | ALOGE("%s: null context error", __FUNCTION__); |
| 884 | return -EINVAL; |
| 885 | } |
| 886 | |
| 887 | switch(name) { |
| 888 | case COPYBIT_MINIFICATION_LIMIT: |
| 889 | value = MAX_SCALE_FACTOR; |
| 890 | break; |
| 891 | case COPYBIT_MAGNIFICATION_LIMIT: |
| 892 | value = MAX_SCALE_FACTOR; |
| 893 | break; |
| 894 | case COPYBIT_SCALING_FRAC_BITS: |
| 895 | value = 32; |
| 896 | break; |
| 897 | case COPYBIT_ROTATION_STEP_DEG: |
| 898 | value = 1; |
| 899 | break; |
| 900 | default: |
| 901 | ALOGE("%s: default case param=0x%x", __FUNCTION__, name); |
| 902 | value = -EINVAL; |
| 903 | } |
| 904 | return value; |
| 905 | } |
| 906 | |
| 907 | static int is_alpha(int cformat) |
| 908 | { |
| 909 | int alpha = 0; |
| 910 | switch (cformat & 0xFF) { |
| 911 | case C2D_COLOR_FORMAT_8888_ARGB: |
| 912 | case C2D_COLOR_FORMAT_8888_RGBA: |
| 913 | case C2D_COLOR_FORMAT_5551_RGBA: |
| 914 | case C2D_COLOR_FORMAT_4444_ARGB: |
| 915 | alpha = 1; |
| 916 | break; |
| 917 | default: |
| 918 | alpha = 0; |
| 919 | break; |
| 920 | } |
| 921 | |
| 922 | if(alpha && (cformat&C2D_FORMAT_DISABLE_ALPHA)) |
| 923 | alpha = 0; |
| 924 | |
| 925 | return alpha; |
| 926 | } |
| 927 | |
| 928 | /* Function to check if we need a temporary buffer for the blit. |
| 929 | * This would happen if the requested destination stride and the |
| 930 | * C2D stride do not match. We ignore RGB buffers, since their |
| 931 | * stride is always aligned to 32. |
| 932 | */ |
| 933 | static bool need_temp_buffer(struct copybit_image_t const *img) |
| 934 | { |
| 935 | if (COPYBIT_SUCCESS == is_supported_rgb_format(img->format)) |
| 936 | return false; |
| 937 | |
| 938 | struct private_handle_t* handle = (struct private_handle_t*)img->handle; |
| 939 | |
| 940 | // The width parameter in the handle contains the aligned_w. We check if we |
| 941 | // need to convert based on this param. YUV formats have bpp=1, so checking |
| 942 | // if the requested stride is aligned should suffice. |
| 943 | if (0 == (handle->width)%32) { |
| 944 | return false; |
| 945 | } |
| 946 | |
| 947 | return true; |
| 948 | } |
| 949 | |
| 950 | /* Function to extract the information from the copybit image and set the corresponding |
| 951 | * values in the bufferInfo struct. |
| 952 | */ |
| 953 | static void populate_buffer_info(struct copybit_image_t const *img, bufferInfo& info) |
| 954 | { |
| 955 | info.width = img->w; |
| 956 | info.height = img->h; |
| 957 | info.format = img->format; |
| 958 | } |
| 959 | |
| 960 | /* Function to get the required size for a particular format, inorder for C2D to perform |
| 961 | * the blit operation. |
| 962 | */ |
Shalaj Jain | a70b435 | 2014-06-15 13:47:47 -0700 | [diff] [blame] | 963 | static int get_size(const bufferInfo& info) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 964 | { |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 965 | int size = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 966 | int w = info.width; |
| 967 | int h = info.height; |
| 968 | int aligned_w = ALIGN(w, 32); |
| 969 | switch(info.format) { |
| 970 | case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: |
| 971 | { |
| 972 | // Chroma for this format is aligned to 2K. |
| 973 | size = ALIGN((aligned_w*h), 2048) + |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 974 | ALIGN(aligned_w/2, 32) * (h/2) *2; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 975 | size = ALIGN(size, 4096); |
| 976 | } break; |
| 977 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
| 978 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 979 | { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 980 | size = aligned_w * h + |
| 981 | ALIGN(aligned_w/2, 32) * (h/2) * 2; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 982 | size = ALIGN(size, 4096); |
| 983 | } break; |
| 984 | default: break; |
| 985 | } |
| 986 | return size; |
| 987 | } |
| 988 | |
| 989 | /* Function to allocate memory for the temporary buffer. This memory is |
| 990 | * allocated from Ashmem. It is the caller's responsibility to free this |
| 991 | * memory. |
| 992 | */ |
| 993 | static int get_temp_buffer(const bufferInfo& info, alloc_data& data) |
| 994 | { |
| 995 | ALOGD("%s E", __FUNCTION__); |
| 996 | // Alloc memory from system heap |
| 997 | data.base = 0; |
| 998 | data.fd = -1; |
| 999 | data.offset = 0; |
| 1000 | data.size = get_size(info); |
| 1001 | data.align = getpagesize(); |
| 1002 | data.uncached = true; |
Naseer Ahmed | 8d0d72a | 2014-12-19 16:25:09 -0500 | [diff] [blame] | 1003 | int allocFlags = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1004 | |
| 1005 | if (sAlloc == 0) { |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 1006 | sAlloc = gralloc::IAllocController::getInstance(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | if (sAlloc == 0) { |
| 1010 | ALOGE("%s: sAlloc is still NULL", __FUNCTION__); |
| 1011 | return COPYBIT_FAILURE; |
| 1012 | } |
| 1013 | |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 1014 | int err = sAlloc->allocate(data, allocFlags); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1015 | if (0 != err) { |
| 1016 | ALOGE("%s: allocate failed", __FUNCTION__); |
| 1017 | return COPYBIT_FAILURE; |
| 1018 | } |
| 1019 | |
| 1020 | ALOGD("%s X", __FUNCTION__); |
| 1021 | return err; |
| 1022 | } |
| 1023 | |
| 1024 | /* Function to free the temporary allocated memory.*/ |
| 1025 | static void free_temp_buffer(alloc_data &data) |
| 1026 | { |
| 1027 | if (-1 != data.fd) { |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 1028 | IMemAlloc* memalloc = sAlloc->getAllocator(data.allocType); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1029 | memalloc->free_buffer(data.base, data.size, 0, data.fd); |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | /* Function to perform the software color conversion. Convert the |
| 1034 | * C2D compatible format to the Android compatible format |
| 1035 | */ |
| 1036 | static int copy_image(private_handle_t *src_handle, |
| 1037 | struct copybit_image_t const *rhs, |
| 1038 | eConversionType conversionType) |
| 1039 | { |
| 1040 | if (src_handle->fd == -1) { |
| 1041 | ALOGE("%s: src_handle fd is invalid", __FUNCTION__); |
| 1042 | return COPYBIT_FAILURE; |
| 1043 | } |
| 1044 | |
| 1045 | // Copy the info. |
| 1046 | int ret = COPYBIT_SUCCESS; |
| 1047 | switch(rhs->format) { |
| 1048 | case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: |
| 1049 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
| 1050 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 1051 | { |
| 1052 | if (CONVERT_TO_ANDROID_FORMAT == conversionType) { |
| 1053 | return convert_yuv_c2d_to_yuv_android(src_handle, rhs); |
| 1054 | } else { |
| 1055 | return convert_yuv_android_to_yuv_c2d(src_handle, rhs); |
| 1056 | } |
| 1057 | |
| 1058 | } break; |
| 1059 | default: { |
| 1060 | ALOGE("%s: invalid format 0x%x", __FUNCTION__, rhs->format); |
| 1061 | ret = COPYBIT_FAILURE; |
| 1062 | } break; |
| 1063 | } |
| 1064 | return ret; |
| 1065 | } |
| 1066 | |
| 1067 | static void delete_handle(private_handle_t *handle) |
| 1068 | { |
| 1069 | if (handle) { |
| 1070 | delete handle; |
| 1071 | handle = 0; |
| 1072 | } |
| 1073 | } |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1074 | |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 1075 | static bool need_to_execute_draw(eC2DFlags flags) |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1076 | { |
| 1077 | if (flags & FLAGS_TEMP_SRC_DST) { |
| 1078 | return true; |
| 1079 | } |
| 1080 | if (flags & FLAGS_YUV_DESTINATION) { |
| 1081 | return true; |
| 1082 | } |
| 1083 | return false; |
| 1084 | } |
| 1085 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1086 | /** do a stretch blit type operation */ |
| 1087 | static int stretch_copybit_internal( |
| 1088 | struct copybit_device_t *dev, |
| 1089 | struct copybit_image_t const *dst, |
| 1090 | struct copybit_image_t const *src, |
| 1091 | struct copybit_rect_t const *dst_rect, |
| 1092 | struct copybit_rect_t const *src_rect, |
| 1093 | struct copybit_region_t const *region, |
| 1094 | bool enableBlend) |
| 1095 | { |
| 1096 | struct copybit_context_t* ctx = (struct copybit_context_t*)dev; |
| 1097 | int status = COPYBIT_SUCCESS; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1098 | int flags = 0; |
| 1099 | int src_surface_type; |
| 1100 | int mapped_src_idx = -1, mapped_dst_idx = -1; |
| 1101 | C2D_OBJECT_STR src_surface; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1102 | |
| 1103 | if (!ctx) { |
| 1104 | ALOGE("%s: null context error", __FUNCTION__); |
| 1105 | return -EINVAL; |
| 1106 | } |
| 1107 | |
| 1108 | if (src->w > MAX_DIMENSION || src->h > MAX_DIMENSION) { |
| 1109 | ALOGE("%s: src dimension error", __FUNCTION__); |
| 1110 | return -EINVAL; |
| 1111 | } |
| 1112 | |
| 1113 | if (dst->w > MAX_DIMENSION || dst->h > MAX_DIMENSION) { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1114 | ALOGE("%s : dst dimension error dst w %d h %d", __FUNCTION__, dst->w, |
| 1115 | dst->h); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1116 | return -EINVAL; |
| 1117 | } |
| 1118 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1119 | if (is_valid_destination_format(dst->format) == COPYBIT_FAILURE) { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1120 | ALOGE("%s: Invalid destination format format = 0x%x", __FUNCTION__, |
| 1121 | dst->format); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1122 | return COPYBIT_FAILURE; |
| 1123 | } |
| 1124 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1125 | int dst_surface_type; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1126 | if (is_supported_rgb_format(dst->format) == COPYBIT_SUCCESS) { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1127 | dst_surface_type = RGB_SURFACE; |
| 1128 | flags |= FLAGS_PREMULTIPLIED_ALPHA; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1129 | } else if (is_supported_yuv_format(dst->format) == COPYBIT_SUCCESS) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1130 | int num_planes = get_num_planes(dst->format); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1131 | flags |= FLAGS_YUV_DESTINATION; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1132 | if (num_planes == 2) { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1133 | dst_surface_type = YUV_SURFACE_2_PLANES; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1134 | } else if (num_planes == 3) { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1135 | dst_surface_type = YUV_SURFACE_3_PLANES; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1136 | } else { |
| 1137 | ALOGE("%s: dst number of YUV planes is invalid dst format = 0x%x", |
| 1138 | __FUNCTION__, dst->format); |
| 1139 | return COPYBIT_FAILURE; |
| 1140 | } |
| 1141 | } else { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1142 | ALOGE("%s: Invalid dst surface format 0x%x", __FUNCTION__, |
| 1143 | dst->format); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1144 | return COPYBIT_FAILURE; |
| 1145 | } |
| 1146 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1147 | if (ctx->blit_rgb_count == MAX_RGB_SURFACES || |
| 1148 | ctx->blit_yuv_2_plane_count == MAX_YUV_2_PLANE_SURFACES || |
| 1149 | ctx->blit_yuv_3_plane_count == MAX_YUV_2_PLANE_SURFACES || |
| 1150 | ctx->blit_count == MAX_BLIT_OBJECT_COUNT || |
| 1151 | ctx->dst_surface_type != dst_surface_type) { |
| 1152 | // we have reached the max. limits of our internal structures or |
| 1153 | // changed the target. |
| 1154 | // Draw the remaining surfaces. We need to do the finish here since |
| 1155 | // we need to free up the surface templates. |
| 1156 | finish_copybit(dev); |
| 1157 | } |
| 1158 | |
| 1159 | ctx->dst_surface_type = dst_surface_type; |
| 1160 | |
| 1161 | // Update the destination |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1162 | copybit_image_t dst_image; |
| 1163 | dst_image.w = dst->w; |
| 1164 | dst_image.h = dst->h; |
| 1165 | dst_image.format = dst->format; |
| 1166 | dst_image.handle = dst->handle; |
| 1167 | // Check if we need a temp. copy for the destination. We'd need this the destination |
| 1168 | // width is not aligned to 32. This case occurs for YUV formats. RGB formats are |
| 1169 | // aligned to 32. |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1170 | bool need_temp_dst = need_temp_buffer(dst); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1171 | bufferInfo dst_info; |
| 1172 | populate_buffer_info(dst, dst_info); |
| 1173 | private_handle_t* dst_hnd = new private_handle_t(-1, 0, 0, 0, dst_info.format, |
| 1174 | dst_info.width, dst_info.height); |
| 1175 | if (dst_hnd == NULL) { |
| 1176 | ALOGE("%s: dst_hnd is null", __FUNCTION__); |
| 1177 | return COPYBIT_FAILURE; |
| 1178 | } |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1179 | if (need_temp_dst) { |
Naseer Ahmed | 9eb5e09 | 2014-09-25 13:24:44 -0400 | [diff] [blame] | 1180 | if (get_size(dst_info) != (int) ctx->temp_dst_buffer.size) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1181 | free_temp_buffer(ctx->temp_dst_buffer); |
| 1182 | // Create a temp buffer and set that as the destination. |
| 1183 | if (COPYBIT_FAILURE == get_temp_buffer(dst_info, ctx->temp_dst_buffer)) { |
| 1184 | ALOGE("%s: get_temp_buffer(dst) failed", __FUNCTION__); |
| 1185 | delete_handle(dst_hnd); |
| 1186 | return COPYBIT_FAILURE; |
| 1187 | } |
| 1188 | } |
| 1189 | dst_hnd->fd = ctx->temp_dst_buffer.fd; |
| 1190 | dst_hnd->size = ctx->temp_dst_buffer.size; |
| 1191 | dst_hnd->flags = ctx->temp_dst_buffer.allocType; |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 1192 | dst_hnd->base = (uintptr_t)(ctx->temp_dst_buffer.base); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1193 | dst_hnd->offset = ctx->temp_dst_buffer.offset; |
| 1194 | dst_hnd->gpuaddr = 0; |
| 1195 | dst_image.handle = dst_hnd; |
| 1196 | } |
Arun Kumar K.R | 14031eb | 2013-04-15 14:26:43 -0700 | [diff] [blame] | 1197 | if(!ctx->dst_surface_mapped) { |
| 1198 | //map the destination surface to GPU address |
| 1199 | status = set_image(ctx, ctx->dst[ctx->dst_surface_type], &dst_image, |
| 1200 | (eC2DFlags)flags, mapped_dst_idx); |
| 1201 | if(status) { |
| 1202 | ALOGE("%s: dst: set_image error", __FUNCTION__); |
| 1203 | delete_handle(dst_hnd); |
| 1204 | unmap_gpuaddr(ctx, mapped_dst_idx); |
| 1205 | return COPYBIT_FAILURE; |
| 1206 | } |
| 1207 | ctx->dst_surface_mapped = true; |
| 1208 | ctx->dst_surface_base = dst->base; |
| 1209 | } else if(ctx->dst_surface_mapped && ctx->dst_surface_base != dst->base) { |
| 1210 | // Destination surface for the operation should be same for multiple |
| 1211 | // requests, this check is catch if there is any case when the |
| 1212 | // destination changes |
| 1213 | ALOGE("%s: a different destination surface!!", __FUNCTION__); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1216 | // Update the source |
| 1217 | flags = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1218 | if(is_supported_rgb_format(src->format) == COPYBIT_SUCCESS) { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1219 | src_surface_type = RGB_SURFACE; |
| 1220 | src_surface = ctx->blit_rgb_object[ctx->blit_rgb_count]; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1221 | } else if (is_supported_yuv_format(src->format) == COPYBIT_SUCCESS) { |
| 1222 | int num_planes = get_num_planes(src->format); |
| 1223 | if (num_planes == 2) { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1224 | src_surface_type = YUV_SURFACE_2_PLANES; |
| 1225 | src_surface = ctx->blit_yuv_2_plane_object[ctx->blit_yuv_2_plane_count]; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1226 | } else if (num_planes == 3) { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1227 | src_surface_type = YUV_SURFACE_3_PLANES; |
| 1228 | src_surface = ctx->blit_yuv_3_plane_object[ctx->blit_yuv_2_plane_count]; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1229 | } else { |
| 1230 | ALOGE("%s: src number of YUV planes is invalid src format = 0x%x", |
| 1231 | __FUNCTION__, src->format); |
| 1232 | delete_handle(dst_hnd); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1233 | unmap_gpuaddr(ctx, mapped_dst_idx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1234 | return -EINVAL; |
| 1235 | } |
| 1236 | } else { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1237 | ALOGE("%s: Invalid source surface format 0x%x", __FUNCTION__, |
| 1238 | src->format); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1239 | delete_handle(dst_hnd); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1240 | unmap_gpuaddr(ctx, mapped_dst_idx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1241 | return -EINVAL; |
| 1242 | } |
| 1243 | |
| 1244 | copybit_image_t src_image; |
| 1245 | src_image.w = src->w; |
| 1246 | src_image.h = src->h; |
| 1247 | src_image.format = src->format; |
| 1248 | src_image.handle = src->handle; |
| 1249 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1250 | bool need_temp_src = need_temp_buffer(src); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1251 | bufferInfo src_info; |
| 1252 | populate_buffer_info(src, src_info); |
| 1253 | private_handle_t* src_hnd = new private_handle_t(-1, 0, 0, 0, src_info.format, |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1254 | src_info.width, src_info.height); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1255 | if (NULL == src_hnd) { |
| 1256 | ALOGE("%s: src_hnd is null", __FUNCTION__); |
| 1257 | delete_handle(dst_hnd); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1258 | unmap_gpuaddr(ctx, mapped_dst_idx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1259 | return COPYBIT_FAILURE; |
| 1260 | } |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1261 | if (need_temp_src) { |
Naseer Ahmed | 9eb5e09 | 2014-09-25 13:24:44 -0400 | [diff] [blame] | 1262 | if (get_size(src_info) != (int) ctx->temp_src_buffer.size) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1263 | free_temp_buffer(ctx->temp_src_buffer); |
| 1264 | // Create a temp buffer and set that as the destination. |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1265 | if (COPYBIT_SUCCESS != get_temp_buffer(src_info, |
| 1266 | ctx->temp_src_buffer)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1267 | ALOGE("%s: get_temp_buffer(src) failed", __FUNCTION__); |
| 1268 | delete_handle(dst_hnd); |
| 1269 | delete_handle(src_hnd); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1270 | unmap_gpuaddr(ctx, mapped_dst_idx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1271 | return COPYBIT_FAILURE; |
| 1272 | } |
| 1273 | } |
| 1274 | src_hnd->fd = ctx->temp_src_buffer.fd; |
| 1275 | src_hnd->size = ctx->temp_src_buffer.size; |
| 1276 | src_hnd->flags = ctx->temp_src_buffer.allocType; |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 1277 | src_hnd->base = (uintptr_t)(ctx->temp_src_buffer.base); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1278 | src_hnd->offset = ctx->temp_src_buffer.offset; |
| 1279 | src_hnd->gpuaddr = 0; |
| 1280 | src_image.handle = src_hnd; |
| 1281 | |
| 1282 | // Copy the source. |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1283 | status = copy_image((private_handle_t *)src->handle, &src_image, |
| 1284 | CONVERT_TO_C2D_FORMAT); |
| 1285 | if (status == COPYBIT_FAILURE) { |
| 1286 | ALOGE("%s:copy_image failed in temp source",__FUNCTION__); |
| 1287 | delete_handle(dst_hnd); |
| 1288 | delete_handle(src_hnd); |
| 1289 | unmap_gpuaddr(ctx, mapped_dst_idx); |
| 1290 | return status; |
| 1291 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1292 | |
Naseer Ahmed | aeab91f | 2013-03-20 21:01:19 -0400 | [diff] [blame] | 1293 | // Clean the cache |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 1294 | IMemAlloc* memalloc = sAlloc->getAllocator(src_hnd->flags); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1295 | if (memalloc->clean_buffer((void *)(src_hnd->base), src_hnd->size, |
Naseer Ahmed | aeab91f | 2013-03-20 21:01:19 -0400 | [diff] [blame] | 1296 | src_hnd->offset, src_hnd->fd, |
| 1297 | gralloc::CACHE_CLEAN)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1298 | ALOGE("%s: clean_buffer failed", __FUNCTION__); |
| 1299 | delete_handle(dst_hnd); |
| 1300 | delete_handle(src_hnd); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1301 | unmap_gpuaddr(ctx, mapped_dst_idx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1302 | return COPYBIT_FAILURE; |
| 1303 | } |
| 1304 | } |
| 1305 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1306 | flags |= (ctx->is_premultiplied_alpha) ? FLAGS_PREMULTIPLIED_ALPHA : 0; |
| 1307 | flags |= (ctx->dst_surface_type != RGB_SURFACE) ? FLAGS_YUV_DESTINATION : 0; |
| 1308 | status = set_image(ctx, src_surface.surface_id, &src_image, |
| 1309 | (eC2DFlags)flags, mapped_src_idx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1310 | if(status) { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1311 | ALOGE("%s: set_image (src) error", __FUNCTION__); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1312 | delete_handle(dst_hnd); |
| 1313 | delete_handle(src_hnd); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1314 | unmap_gpuaddr(ctx, mapped_dst_idx); |
| 1315 | unmap_gpuaddr(ctx, mapped_src_idx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1316 | return COPYBIT_FAILURE; |
| 1317 | } |
| 1318 | |
Arun Kumar K.R | e29916b | 2013-03-20 11:42:53 -0700 | [diff] [blame] | 1319 | src_surface.config_mask = C2D_NO_ANTIALIASING_BIT | ctx->config_mask; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1320 | src_surface.global_alpha = ctx->src_global_alpha; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1321 | if (enableBlend) { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1322 | if(src_surface.config_mask & C2D_GLOBAL_ALPHA_BIT) { |
| 1323 | src_surface.config_mask &= ~C2D_ALPHA_BLEND_NONE; |
| 1324 | if(!(src_surface.global_alpha)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1325 | // src alpha is zero |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1326 | delete_handle(dst_hnd); |
| 1327 | delete_handle(src_hnd); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1328 | unmap_gpuaddr(ctx, mapped_dst_idx); |
| 1329 | unmap_gpuaddr(ctx, mapped_src_idx); |
| 1330 | return COPYBIT_FAILURE; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1331 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1332 | } |
| 1333 | } else { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1334 | src_surface.config_mask |= C2D_ALPHA_BLEND_NONE; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1337 | if (src_surface_type == RGB_SURFACE) { |
| 1338 | ctx->blit_rgb_object[ctx->blit_rgb_count] = src_surface; |
| 1339 | ctx->blit_rgb_count++; |
| 1340 | } else if (src_surface_type == YUV_SURFACE_2_PLANES) { |
| 1341 | ctx->blit_yuv_2_plane_object[ctx->blit_yuv_2_plane_count] = src_surface; |
| 1342 | ctx->blit_yuv_2_plane_count++; |
| 1343 | } else { |
| 1344 | ctx->blit_yuv_3_plane_object[ctx->blit_yuv_3_plane_count] = src_surface; |
| 1345 | ctx->blit_yuv_3_plane_count++; |
| 1346 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1347 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1348 | struct copybit_rect_t clip; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1349 | while ((status == 0) && region->next(region, &clip)) { |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1350 | set_rects(ctx, &(src_surface), dst_rect, src_rect, &clip); |
| 1351 | if (ctx->blit_count == MAX_BLIT_OBJECT_COUNT) { |
| 1352 | ALOGW("Reached end of blit count"); |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 1353 | finish_copybit(dev); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1354 | } |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1355 | ctx->blit_list[ctx->blit_count] = src_surface; |
| 1356 | ctx->blit_count++; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1359 | // Check if we need to perform an early draw-finish. |
| 1360 | flags |= (need_temp_dst || need_temp_src) ? FLAGS_TEMP_SRC_DST : 0; |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 1361 | if (need_to_execute_draw((eC2DFlags)flags)) |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1362 | { |
| 1363 | finish_copybit(dev); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1364 | } |
| 1365 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1366 | if (need_temp_dst) { |
| 1367 | // copy the temp. destination without the alignment to the actual |
| 1368 | // destination. |
| 1369 | status = copy_image(dst_hnd, dst, CONVERT_TO_ANDROID_FORMAT); |
| 1370 | if (status == COPYBIT_FAILURE) { |
| 1371 | ALOGE("%s:copy_image failed in temp Dest",__FUNCTION__); |
| 1372 | delete_handle(dst_hnd); |
| 1373 | delete_handle(src_hnd); |
| 1374 | unmap_gpuaddr(ctx, mapped_dst_idx); |
| 1375 | unmap_gpuaddr(ctx, mapped_src_idx); |
| 1376 | return status; |
| 1377 | } |
Naseer Ahmed | aeab91f | 2013-03-20 21:01:19 -0400 | [diff] [blame] | 1378 | // Clean the cache. |
Naseer Ahmed | 01d3fd3 | 2012-07-14 21:08:13 -0700 | [diff] [blame] | 1379 | IMemAlloc* memalloc = sAlloc->getAllocator(dst_hnd->flags); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1380 | memalloc->clean_buffer((void *)(dst_hnd->base), dst_hnd->size, |
Naseer Ahmed | aeab91f | 2013-03-20 21:01:19 -0400 | [diff] [blame] | 1381 | dst_hnd->offset, dst_hnd->fd, |
| 1382 | gralloc::CACHE_CLEAN); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1383 | } |
| 1384 | delete_handle(dst_hnd); |
| 1385 | delete_handle(src_hnd); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1386 | |
| 1387 | ctx->is_premultiplied_alpha = false; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1388 | ctx->fb_width = 0; |
| 1389 | ctx->fb_height = 0; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1390 | ctx->config_mask = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1391 | return status; |
| 1392 | } |
| 1393 | |
Terence Hampson | adf4730 | 2013-05-23 12:21:02 -0400 | [diff] [blame] | 1394 | static int set_sync_copybit(struct copybit_device_t *dev, |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 1395 | int /*acquireFenceFd*/) |
Terence Hampson | adf4730 | 2013-05-23 12:21:02 -0400 | [diff] [blame] | 1396 | { |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 1397 | if(!dev) |
| 1398 | return -EINVAL; |
| 1399 | |
Terence Hampson | adf4730 | 2013-05-23 12:21:02 -0400 | [diff] [blame] | 1400 | return 0; |
| 1401 | } |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1402 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1403 | static int stretch_copybit( |
| 1404 | struct copybit_device_t *dev, |
| 1405 | struct copybit_image_t const *dst, |
| 1406 | struct copybit_image_t const *src, |
| 1407 | struct copybit_rect_t const *dst_rect, |
| 1408 | struct copybit_rect_t const *src_rect, |
| 1409 | struct copybit_region_t const *region) |
| 1410 | { |
| 1411 | struct copybit_context_t* ctx = (struct copybit_context_t*)dev; |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 1412 | int status = COPYBIT_SUCCESS; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1413 | bool needsBlending = (ctx->src_global_alpha != 0); |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 1414 | pthread_mutex_lock(&ctx->wait_cleanup_lock); |
| 1415 | status = stretch_copybit_internal(dev, dst, src, dst_rect, src_rect, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1416 | region, needsBlending); |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 1417 | pthread_mutex_unlock(&ctx->wait_cleanup_lock); |
| 1418 | return status; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | /** Perform a blit type operation */ |
| 1422 | static int blit_copybit( |
| 1423 | struct copybit_device_t *dev, |
| 1424 | struct copybit_image_t const *dst, |
| 1425 | struct copybit_image_t const *src, |
| 1426 | struct copybit_region_t const *region) |
| 1427 | { |
Arun Kumar K.R | 71cfd81 | 2013-04-03 11:25:41 -0700 | [diff] [blame] | 1428 | int status = COPYBIT_SUCCESS; |
| 1429 | struct copybit_context_t* ctx = (struct copybit_context_t*)dev; |
Naseer Ahmed | bb887bd | 2013-04-16 14:12:27 -0400 | [diff] [blame] | 1430 | struct copybit_rect_t dr = { 0, 0, (int)dst->w, (int)dst->h }; |
| 1431 | struct copybit_rect_t sr = { 0, 0, (int)src->w, (int)src->h }; |
Arun Kumar K.R | 71cfd81 | 2013-04-03 11:25:41 -0700 | [diff] [blame] | 1432 | pthread_mutex_lock(&ctx->wait_cleanup_lock); |
| 1433 | status = stretch_copybit_internal(dev, dst, src, &dr, &sr, region, false); |
| 1434 | pthread_mutex_unlock(&ctx->wait_cleanup_lock); |
| 1435 | return status; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
Sushil Chauhan | 943797c | 2013-10-21 17:35:55 -0700 | [diff] [blame] | 1438 | /** Fill the rect on dst with RGBA color **/ |
| 1439 | static int fill_color(struct copybit_device_t *dev, |
| 1440 | struct copybit_image_t const *dst, |
| 1441 | struct copybit_rect_t const *rect, |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 1442 | uint32_t /*color*/) |
Sushil Chauhan | 943797c | 2013-10-21 17:35:55 -0700 | [diff] [blame] | 1443 | { |
| 1444 | // TODO: Implement once c2d driver supports color fill |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 1445 | if(!dev || !dst || !rect) |
| 1446 | return -EINVAL; |
| 1447 | |
Sushil Chauhan | 943797c | 2013-10-21 17:35:55 -0700 | [diff] [blame] | 1448 | return -EINVAL; |
| 1449 | } |
| 1450 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1451 | /*****************************************************************************/ |
| 1452 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1453 | static void clean_up(copybit_context_t* ctx) |
| 1454 | { |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 1455 | void* ret; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1456 | if (!ctx) |
| 1457 | return; |
| 1458 | |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 1459 | // stop the wait_cleanup_thread |
| 1460 | pthread_mutex_lock(&ctx->wait_cleanup_lock); |
| 1461 | ctx->stop_thread = true; |
| 1462 | // Signal waiting thread |
| 1463 | pthread_cond_signal(&ctx->wait_cleanup_cond); |
| 1464 | pthread_mutex_unlock(&ctx->wait_cleanup_lock); |
| 1465 | // waits for the cleanup thread to exit |
| 1466 | pthread_join(ctx->wait_thread_id, &ret); |
| 1467 | pthread_mutex_destroy(&ctx->wait_cleanup_lock); |
| 1468 | pthread_cond_destroy (&ctx->wait_cleanup_cond); |
| 1469 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1470 | for (int i = 0; i < NUM_SURFACE_TYPES; i++) { |
| 1471 | if (ctx->dst[i]) |
| 1472 | LINK_c2dDestroySurface(ctx->dst[i]); |
| 1473 | } |
| 1474 | |
| 1475 | for (int i = 0; i < MAX_RGB_SURFACES; i++) { |
| 1476 | if (ctx->blit_rgb_object[i].surface_id) |
| 1477 | LINK_c2dDestroySurface(ctx->blit_rgb_object[i].surface_id); |
| 1478 | } |
| 1479 | |
| 1480 | for (int i = 0; i < MAX_YUV_2_PLANE_SURFACES; i++) { |
| 1481 | if (ctx->blit_yuv_2_plane_object[i].surface_id) |
| 1482 | LINK_c2dDestroySurface(ctx->blit_yuv_2_plane_object[i].surface_id); |
| 1483 | } |
| 1484 | |
| 1485 | for (int i = 0; i < MAX_YUV_3_PLANE_SURFACES; i++) { |
| 1486 | if (ctx->blit_yuv_3_plane_object[i].surface_id) |
| 1487 | LINK_c2dDestroySurface(ctx->blit_yuv_3_plane_object[i].surface_id); |
| 1488 | } |
| 1489 | |
| 1490 | if (ctx->libc2d2) { |
| 1491 | ::dlclose(ctx->libc2d2); |
| 1492 | ALOGV("dlclose(libc2d2)"); |
| 1493 | } |
| 1494 | |
| 1495 | free(ctx); |
| 1496 | } |
| 1497 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1498 | /** Close the copybit device */ |
| 1499 | static int close_copybit(struct hw_device_t *dev) |
| 1500 | { |
| 1501 | struct copybit_context_t* ctx = (struct copybit_context_t*)dev; |
| 1502 | if (ctx) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1503 | free_temp_buffer(ctx->temp_src_buffer); |
| 1504 | free_temp_buffer(ctx->temp_dst_buffer); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1505 | } |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1506 | clean_up(ctx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1507 | return 0; |
| 1508 | } |
| 1509 | |
| 1510 | /** Open a new instance of a copybit device using name */ |
| 1511 | static int open_copybit(const struct hw_module_t* module, const char* name, |
| 1512 | struct hw_device_t** device) |
| 1513 | { |
| 1514 | int status = COPYBIT_SUCCESS; |
Praveena Pachipulusu | aef031c | 2014-02-12 11:46:39 +0530 | [diff] [blame] | 1515 | if (strcmp(name, COPYBIT_HARDWARE_COPYBIT0)) { |
| 1516 | return COPYBIT_FAILURE; |
| 1517 | } |
| 1518 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1519 | C2D_RGB_SURFACE_DEF surfDefinition = {0}; |
| 1520 | C2D_YUV_SURFACE_DEF yuvSurfaceDef = {0} ; |
| 1521 | struct copybit_context_t *ctx; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1522 | |
| 1523 | ctx = (struct copybit_context_t *)malloc(sizeof(struct copybit_context_t)); |
| 1524 | if(!ctx) { |
| 1525 | ALOGE("%s: malloc failed", __FUNCTION__); |
| 1526 | return COPYBIT_FAILURE; |
| 1527 | } |
| 1528 | |
| 1529 | /* initialize drawstate */ |
| 1530 | memset(ctx, 0, sizeof(*ctx)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1531 | ctx->libc2d2 = ::dlopen("libC2D2.so", RTLD_NOW); |
| 1532 | if (!ctx->libc2d2) { |
| 1533 | ALOGE("FATAL ERROR: could not dlopen libc2d2.so: %s", dlerror()); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1534 | clean_up(ctx); |
| 1535 | status = COPYBIT_FAILURE; |
| 1536 | *device = NULL; |
| 1537 | return status; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1538 | } |
| 1539 | *(void **)&LINK_c2dCreateSurface = ::dlsym(ctx->libc2d2, |
| 1540 | "c2dCreateSurface"); |
| 1541 | *(void **)&LINK_c2dUpdateSurface = ::dlsym(ctx->libc2d2, |
| 1542 | "c2dUpdateSurface"); |
| 1543 | *(void **)&LINK_c2dReadSurface = ::dlsym(ctx->libc2d2, |
| 1544 | "c2dReadSurface"); |
| 1545 | *(void **)&LINK_c2dDraw = ::dlsym(ctx->libc2d2, "c2dDraw"); |
| 1546 | *(void **)&LINK_c2dFlush = ::dlsym(ctx->libc2d2, "c2dFlush"); |
| 1547 | *(void **)&LINK_c2dFinish = ::dlsym(ctx->libc2d2, "c2dFinish"); |
| 1548 | *(void **)&LINK_c2dWaitTimestamp = ::dlsym(ctx->libc2d2, |
| 1549 | "c2dWaitTimestamp"); |
| 1550 | *(void **)&LINK_c2dDestroySurface = ::dlsym(ctx->libc2d2, |
| 1551 | "c2dDestroySurface"); |
| 1552 | *(void **)&LINK_c2dMapAddr = ::dlsym(ctx->libc2d2, |
| 1553 | "c2dMapAddr"); |
| 1554 | *(void **)&LINK_c2dUnMapAddr = ::dlsym(ctx->libc2d2, |
| 1555 | "c2dUnMapAddr"); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1556 | *(void **)&LINK_c2dGetDriverCapabilities = ::dlsym(ctx->libc2d2, |
| 1557 | "c2dGetDriverCapabilities"); |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 1558 | *(void **)&LINK_c2dCreateFenceFD = ::dlsym(ctx->libc2d2, |
| 1559 | "c2dCreateFenceFD"); |
Naseer Ahmed | 183939d | 2013-03-14 20:44:17 -0400 | [diff] [blame] | 1560 | *(void **)&LINK_c2dFillSurface = ::dlsym(ctx->libc2d2, |
| 1561 | "c2dFillSurface"); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1562 | |
| 1563 | if (!LINK_c2dCreateSurface || !LINK_c2dUpdateSurface || !LINK_c2dReadSurface |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1564 | || !LINK_c2dDraw || !LINK_c2dFlush || !LINK_c2dWaitTimestamp || |
| 1565 | !LINK_c2dFinish || !LINK_c2dDestroySurface || |
Naseer Ahmed | 183939d | 2013-03-14 20:44:17 -0400 | [diff] [blame] | 1566 | !LINK_c2dGetDriverCapabilities || !LINK_c2dCreateFenceFD || |
| 1567 | !LINK_c2dFillSurface) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1568 | ALOGE("%s: dlsym ERROR", __FUNCTION__); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1569 | clean_up(ctx); |
| 1570 | status = COPYBIT_FAILURE; |
| 1571 | *device = NULL; |
| 1572 | return status; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | ctx->device.common.tag = HARDWARE_DEVICE_TAG; |
| 1576 | ctx->device.common.version = 1; |
| 1577 | ctx->device.common.module = (hw_module_t*)(module); |
| 1578 | ctx->device.common.close = close_copybit; |
| 1579 | ctx->device.set_parameter = set_parameter_copybit; |
| 1580 | ctx->device.get = get; |
| 1581 | ctx->device.blit = blit_copybit; |
Terence Hampson | adf4730 | 2013-05-23 12:21:02 -0400 | [diff] [blame] | 1582 | ctx->device.set_sync = set_sync_copybit; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1583 | ctx->device.stretch = stretch_copybit; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1584 | ctx->device.finish = finish_copybit; |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 1585 | ctx->device.flush_get_fence = flush_get_fence_copybit; |
Naseer Ahmed | 183939d | 2013-03-14 20:44:17 -0400 | [diff] [blame] | 1586 | ctx->device.clear = clear_copybit; |
Sushil Chauhan | 943797c | 2013-10-21 17:35:55 -0700 | [diff] [blame] | 1587 | ctx->device.fill_color = fill_color; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1588 | |
| 1589 | /* Create RGB Surface */ |
| 1590 | surfDefinition.buffer = (void*)0xdddddddd; |
| 1591 | surfDefinition.phys = (void*)0xdddddddd; |
| 1592 | surfDefinition.stride = 1 * 4; |
| 1593 | surfDefinition.width = 1; |
| 1594 | surfDefinition.height = 1; |
| 1595 | surfDefinition.format = C2D_COLOR_FORMAT_8888_ARGB; |
| 1596 | if (LINK_c2dCreateSurface(&(ctx->dst[RGB_SURFACE]), C2D_TARGET | C2D_SOURCE, |
| 1597 | (C2D_SURFACE_TYPE)(C2D_SURFACE_RGB_HOST | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1598 | C2D_SURFACE_WITH_PHYS | |
| 1599 | C2D_SURFACE_WITH_PHYS_DUMMY ), |
| 1600 | &surfDefinition)) { |
| 1601 | ALOGE("%s: create ctx->dst_surface[RGB_SURFACE] failed", __FUNCTION__); |
| 1602 | ctx->dst[RGB_SURFACE] = 0; |
| 1603 | clean_up(ctx); |
| 1604 | status = COPYBIT_FAILURE; |
| 1605 | *device = NULL; |
| 1606 | return status; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1609 | unsigned int surface_id = 0; |
| 1610 | for (int i = 0; i < MAX_RGB_SURFACES; i++) |
| 1611 | { |
| 1612 | if (LINK_c2dCreateSurface(&surface_id, C2D_TARGET | C2D_SOURCE, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1613 | (C2D_SURFACE_TYPE)(C2D_SURFACE_RGB_HOST | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1614 | C2D_SURFACE_WITH_PHYS | |
| 1615 | C2D_SURFACE_WITH_PHYS_DUMMY ), |
| 1616 | &surfDefinition)) { |
| 1617 | ALOGE("%s: create RGB source surface %d failed", __FUNCTION__, i); |
| 1618 | ctx->blit_rgb_object[i].surface_id = 0; |
| 1619 | status = COPYBIT_FAILURE; |
| 1620 | break; |
| 1621 | } else { |
| 1622 | ctx->blit_rgb_object[i].surface_id = surface_id; |
| 1623 | ALOGW("%s i = %d surface_id=%d", __FUNCTION__, i, |
| 1624 | ctx->blit_rgb_object[i].surface_id); |
| 1625 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1628 | if (status == COPYBIT_FAILURE) { |
| 1629 | clean_up(ctx); |
| 1630 | status = COPYBIT_FAILURE; |
| 1631 | *device = NULL; |
| 1632 | return status; |
| 1633 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1634 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1635 | // Create 2 plane YUV surfaces |
| 1636 | yuvSurfaceDef.format = C2D_COLOR_FORMAT_420_NV12; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1637 | yuvSurfaceDef.width = 4; |
| 1638 | yuvSurfaceDef.height = 4; |
| 1639 | yuvSurfaceDef.plane0 = (void*)0xaaaaaaaa; |
| 1640 | yuvSurfaceDef.phys0 = (void*) 0xaaaaaaaa; |
| 1641 | yuvSurfaceDef.stride0 = 4; |
| 1642 | |
| 1643 | yuvSurfaceDef.plane1 = (void*)0xaaaaaaaa; |
| 1644 | yuvSurfaceDef.phys1 = (void*) 0xaaaaaaaa; |
| 1645 | yuvSurfaceDef.stride1 = 4; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1646 | if (LINK_c2dCreateSurface(&(ctx->dst[YUV_SURFACE_2_PLANES]), |
| 1647 | C2D_TARGET | C2D_SOURCE, |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1648 | (C2D_SURFACE_TYPE)(C2D_SURFACE_YUV_HOST | |
| 1649 | C2D_SURFACE_WITH_PHYS | |
| 1650 | C2D_SURFACE_WITH_PHYS_DUMMY), |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1651 | &yuvSurfaceDef)) { |
| 1652 | ALOGE("%s: create ctx->dst[YUV_SURFACE_2_PLANES] failed", __FUNCTION__); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1653 | ctx->dst[YUV_SURFACE_2_PLANES] = 0; |
| 1654 | clean_up(ctx); |
| 1655 | status = COPYBIT_FAILURE; |
| 1656 | *device = NULL; |
| 1657 | return status; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1660 | for (int i=0; i < MAX_YUV_2_PLANE_SURFACES; i++) |
| 1661 | { |
| 1662 | if (LINK_c2dCreateSurface(&surface_id, C2D_TARGET | C2D_SOURCE, |
| 1663 | (C2D_SURFACE_TYPE)(C2D_SURFACE_YUV_HOST | |
| 1664 | C2D_SURFACE_WITH_PHYS | |
| 1665 | C2D_SURFACE_WITH_PHYS_DUMMY ), |
| 1666 | &yuvSurfaceDef)) { |
| 1667 | ALOGE("%s: create YUV source %d failed", __FUNCTION__, i); |
| 1668 | ctx->blit_yuv_2_plane_object[i].surface_id = 0; |
| 1669 | status = COPYBIT_FAILURE; |
| 1670 | break; |
| 1671 | } else { |
| 1672 | ctx->blit_yuv_2_plane_object[i].surface_id = surface_id; |
| 1673 | ALOGW("%s: 2 Plane YUV i=%d surface_id=%d", __FUNCTION__, i, |
| 1674 | ctx->blit_yuv_2_plane_object[i].surface_id); |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | if (status == COPYBIT_FAILURE) { |
| 1679 | clean_up(ctx); |
| 1680 | status = COPYBIT_FAILURE; |
| 1681 | *device = NULL; |
| 1682 | return status; |
| 1683 | } |
| 1684 | |
| 1685 | // Create YUV 3 plane surfaces |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1686 | yuvSurfaceDef.format = C2D_COLOR_FORMAT_420_YV12; |
| 1687 | yuvSurfaceDef.plane2 = (void*)0xaaaaaaaa; |
| 1688 | yuvSurfaceDef.phys2 = (void*) 0xaaaaaaaa; |
| 1689 | yuvSurfaceDef.stride2 = 4; |
| 1690 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1691 | if (LINK_c2dCreateSurface(&(ctx->dst[YUV_SURFACE_3_PLANES]), |
| 1692 | C2D_TARGET | C2D_SOURCE, |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1693 | (C2D_SURFACE_TYPE)(C2D_SURFACE_YUV_HOST | |
| 1694 | C2D_SURFACE_WITH_PHYS | |
| 1695 | C2D_SURFACE_WITH_PHYS_DUMMY), |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1696 | &yuvSurfaceDef)) { |
| 1697 | ALOGE("%s: create ctx->dst[YUV_SURFACE_3_PLANES] failed", __FUNCTION__); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1698 | ctx->dst[YUV_SURFACE_3_PLANES] = 0; |
| 1699 | clean_up(ctx); |
| 1700 | status = COPYBIT_FAILURE; |
| 1701 | *device = NULL; |
| 1702 | return status; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1703 | } |
| 1704 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1705 | for (int i=0; i < MAX_YUV_3_PLANE_SURFACES; i++) |
| 1706 | { |
| 1707 | if (LINK_c2dCreateSurface(&(surface_id), |
| 1708 | C2D_TARGET | C2D_SOURCE, |
| 1709 | (C2D_SURFACE_TYPE)(C2D_SURFACE_YUV_HOST | |
| 1710 | C2D_SURFACE_WITH_PHYS | |
| 1711 | C2D_SURFACE_WITH_PHYS_DUMMY), |
| 1712 | &yuvSurfaceDef)) { |
| 1713 | ALOGE("%s: create 3 plane YUV surface %d failed", __FUNCTION__, i); |
| 1714 | ctx->blit_yuv_3_plane_object[i].surface_id = 0; |
| 1715 | status = COPYBIT_FAILURE; |
| 1716 | break; |
| 1717 | } else { |
| 1718 | ctx->blit_yuv_3_plane_object[i].surface_id = surface_id; |
| 1719 | ALOGW("%s: 3 Plane YUV i=%d surface_id=%d", __FUNCTION__, i, |
| 1720 | ctx->blit_yuv_3_plane_object[i].surface_id); |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | if (status == COPYBIT_FAILURE) { |
| 1725 | clean_up(ctx); |
| 1726 | status = COPYBIT_FAILURE; |
| 1727 | *device = NULL; |
| 1728 | return status; |
| 1729 | } |
| 1730 | |
| 1731 | if (LINK_c2dGetDriverCapabilities(&(ctx->c2d_driver_info))) { |
| 1732 | ALOGE("%s: LINK_c2dGetDriverCapabilities failed", __FUNCTION__); |
| 1733 | clean_up(ctx); |
| 1734 | status = COPYBIT_FAILURE; |
| 1735 | *device = NULL; |
| 1736 | return status; |
| 1737 | } |
| 1738 | // Initialize context variables. |
| 1739 | ctx->trg_transform = C2D_TARGET_ROTATE_0; |
| 1740 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1741 | ctx->temp_src_buffer.fd = -1; |
| 1742 | ctx->temp_src_buffer.base = 0; |
| 1743 | ctx->temp_src_buffer.size = 0; |
| 1744 | |
| 1745 | ctx->temp_dst_buffer.fd = -1; |
| 1746 | ctx->temp_dst_buffer.base = 0; |
| 1747 | ctx->temp_dst_buffer.size = 0; |
| 1748 | |
| 1749 | ctx->fb_width = 0; |
| 1750 | ctx->fb_height = 0; |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 1751 | |
| 1752 | ctx->blit_rgb_count = 0; |
| 1753 | ctx->blit_yuv_2_plane_count = 0; |
| 1754 | ctx->blit_yuv_3_plane_count = 0; |
| 1755 | ctx->blit_count = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1756 | |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 1757 | ctx->wait_timestamp = false; |
| 1758 | ctx->stop_thread = false; |
| 1759 | pthread_mutex_init(&(ctx->wait_cleanup_lock), NULL); |
| 1760 | pthread_cond_init(&(ctx->wait_cleanup_cond), NULL); |
| 1761 | /* Start the wait thread */ |
| 1762 | pthread_attr_t attr; |
| 1763 | pthread_attr_init(&attr); |
| 1764 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); |
| 1765 | |
| 1766 | pthread_create(&ctx->wait_thread_id, &attr, &c2d_wait_loop, |
| 1767 | (void *)ctx); |
| 1768 | pthread_attr_destroy(&attr); |
| 1769 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1770 | *device = &ctx->device.common; |
| 1771 | return status; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1772 | } |