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