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