blob: f205dfce8e55e62cb1478f5d49913557fab21631 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
Praveena Pachipulusuaef031c2014-02-12 11:46:39 +05303 * Copyright (c) 2010 - 2014, The Linux Foundation. All rights reserved.
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -08004 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
Naseer Ahmed29a26812012-06-14 00:56:20 -07007 *
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 */
20
Naseer Ahmed29a26812012-06-14 00:56:20 -070021#include <cutils/log.h>
22
23#include <linux/msm_mdp.h>
24#include <linux/fb.h>
25
26#include <stdint.h>
27#include <string.h>
28#include <unistd.h>
29#include <errno.h>
30#include <fcntl.h>
31
32#include <sys/ioctl.h>
33#include <sys/types.h>
34#include <sys/mman.h>
35
36#include <copybit.h>
37
38#include "gralloc_priv.h"
39#include "software_converter.h"
Sushil Chauhan0265c472014-10-01 16:39:02 -070040#include <qdMetaData.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070041
42#define DEBUG_MDP_ERRORS 1
43
44/******************************************************************************/
45
Naseer Ahmed29a26812012-06-14 00:56:20 -070046#define MAX_SCALE_FACTOR (4)
47#define MAX_DIMENSION (4096)
Naseer Ahmed29a26812012-06-14 00:56:20 -070048
49/******************************************************************************/
Terence Hampsonadf47302013-05-23 12:21:02 -040050struct blitReq{
51 struct mdp_buf_sync sync;
52 uint32_t count;
53 struct mdp_blit_req req[10];
54};
Naseer Ahmed29a26812012-06-14 00:56:20 -070055
56/** State information for each device instance */
57struct copybit_context_t {
58 struct copybit_device_t device;
59 int mFD;
60 uint8_t mAlpha;
61 int mFlags;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070062 bool mBlitToFB;
Terence Hampsonadf47302013-05-23 12:21:02 -040063 int acqFence[MDP_MAX_FENCE_FD];
64 int relFence;
65 struct mdp_buf_sync sync;
66 struct blitReq list;
Ramakant Singh140965d2015-01-08 23:45:04 +053067 uint8_t dynamic_fps;
Naseer Ahmed29a26812012-06-14 00:56:20 -070068};
69
70/**
71 * Common hardware methods
72 */
73
74static int open_copybit(const struct hw_module_t* module, const char* name,
75 struct hw_device_t** device);
76
77static struct hw_module_methods_t copybit_module_methods = {
78open: open_copybit
79};
80
81/*
82 * The COPYBIT Module
83 */
84struct copybit_module_t HAL_MODULE_INFO_SYM = {
85common: {
86tag: HARDWARE_MODULE_TAG,
87 version_major: 1,
88 version_minor: 0,
89 id: COPYBIT_HARDWARE_MODULE_ID,
90 name: "QCT MSM7K COPYBIT Module",
91 author: "Google, Inc.",
92 methods: &copybit_module_methods
93 }
94};
95
96/******************************************************************************/
97
98/** min of int a, b */
99static inline int min(int a, int b) {
100 return (a<b) ? a : b;
101}
102
103/** max of int a, b */
104static inline int max(int a, int b) {
105 return (a>b) ? a : b;
106}
107
108/** scale each parameter by mul/div. Assume div isn't 0 */
109static inline void MULDIV(uint32_t *a, uint32_t *b, int mul, int div) {
110 if (mul != div) {
111 *a = (mul * *a) / div;
112 *b = (mul * *b) / div;
113 }
114}
115
116/** Determine the intersection of lhs & rhs store in out */
117static void intersect(struct copybit_rect_t *out,
118 const struct copybit_rect_t *lhs,
119 const struct copybit_rect_t *rhs) {
120 out->l = max(lhs->l, rhs->l);
121 out->t = max(lhs->t, rhs->t);
122 out->r = min(lhs->r, rhs->r);
123 out->b = min(lhs->b, rhs->b);
124}
125
126/** convert COPYBIT_FORMAT to MDP format */
127static int get_format(int format) {
128 switch (format) {
129 case HAL_PIXEL_FORMAT_RGB_565: return MDP_RGB_565;
Ramkumar Radhakrishnanb8eb16d2014-10-09 13:54:07 -0700130 case HAL_PIXEL_FORMAT_RGBA_5551: return MDP_RGBA_5551;
131 case HAL_PIXEL_FORMAT_RGBA_4444: return MDP_RGBA_4444;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700132 case HAL_PIXEL_FORMAT_RGBX_8888: return MDP_RGBX_8888;
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -0700133 case HAL_PIXEL_FORMAT_BGRX_8888: return MDP_BGRX_8888;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700134 case HAL_PIXEL_FORMAT_RGB_888: return MDP_RGB_888;
135 case HAL_PIXEL_FORMAT_RGBA_8888: return MDP_RGBA_8888;
136 case HAL_PIXEL_FORMAT_BGRA_8888: return MDP_BGRA_8888;
Ramkumar Radhakrishnanb52399c2013-08-06 20:17:29 -0700137 case HAL_PIXEL_FORMAT_YCrCb_422_I: return MDP_YCRYCB_H2V1;
138 case HAL_PIXEL_FORMAT_YCbCr_422_I: return MDP_YCBYCR_H2V1;
Raj kamale77f4ec2013-07-03 23:57:50 +0530139 case HAL_PIXEL_FORMAT_YCrCb_422_SP: return MDP_Y_CRCB_H2V1;
140 case HAL_PIXEL_FORMAT_YCrCb_420_SP: return MDP_Y_CRCB_H2V2;
141 case HAL_PIXEL_FORMAT_YCbCr_422_SP: return MDP_Y_CBCR_H2V1;
142 case HAL_PIXEL_FORMAT_YCbCr_420_SP: return MDP_Y_CBCR_H2V2;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700143 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: return MDP_Y_CBCR_H2V2_ADRENO;
Radhika Ranjan Soni21175f92013-07-12 17:32:15 +0530144 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: return MDP_Y_CBCR_H2V2_VENUS;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800145 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: return MDP_Y_CBCR_H2V2;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700146 }
147 return -1;
148}
149
150/** convert from copybit image to mdp image structure */
151static void set_image(struct mdp_img *img, const struct copybit_image_t *rhs)
152{
153 private_handle_t* hnd = (private_handle_t*)rhs->handle;
154 if(hnd == NULL){
155 ALOGE("copybit: Invalid handle");
156 return;
157 }
158 img->width = rhs->w;
159 img->height = rhs->h;
160 img->format = get_format(rhs->format);
Praveena Pachipulusuaef031c2014-02-12 11:46:39 +0530161 img->offset = (uint32_t)hnd->offset;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700162 img->memory_id = hnd->fd;
163}
164/** setup rectangles */
165static void set_rects(struct copybit_context_t *dev,
166 struct mdp_blit_req *e,
167 const struct copybit_rect_t *dst,
168 const struct copybit_rect_t *src,
Praveena Pachipulusuaef031c2014-02-12 11:46:39 +0530169 const struct copybit_rect_t *scissor) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700170 struct copybit_rect_t clip;
171 intersect(&clip, scissor, dst);
172
173 e->dst_rect.x = clip.l;
174 e->dst_rect.y = clip.t;
175 e->dst_rect.w = clip.r - clip.l;
176 e->dst_rect.h = clip.b - clip.t;
177
178 uint32_t W, H, delta_x, delta_y;
179 if (dev->mFlags & COPYBIT_TRANSFORM_ROT_90) {
180 delta_x = (clip.t - dst->t);
181 delta_y = (dst->r - clip.r);
182 e->src_rect.w = (clip.b - clip.t);
183 e->src_rect.h = (clip.r - clip.l);
184 W = dst->b - dst->t;
185 H = dst->r - dst->l;
186 } else {
187 delta_x = (clip.l - dst->l);
188 delta_y = (clip.t - dst->t);
189 e->src_rect.w = (clip.r - clip.l);
190 e->src_rect.h = (clip.b - clip.t);
191 W = dst->r - dst->l;
192 H = dst->b - dst->t;
193 }
194
195 MULDIV(&delta_x, &e->src_rect.w, src->r - src->l, W);
196 MULDIV(&delta_y, &e->src_rect.h, src->b - src->t, H);
197
198 e->src_rect.x = delta_x + src->l;
199 e->src_rect.y = delta_y + src->t;
200
201 if (dev->mFlags & COPYBIT_TRANSFORM_FLIP_V) {
202 if (dev->mFlags & COPYBIT_TRANSFORM_ROT_90) {
203 e->src_rect.x = (src->l + src->r) - (e->src_rect.x + e->src_rect.w);
204 }else{
205 e->src_rect.y = (src->t + src->b) - (e->src_rect.y + e->src_rect.h);
206 }
207 }
208
209 if (dev->mFlags & COPYBIT_TRANSFORM_FLIP_H) {
210 if (dev->mFlags & COPYBIT_TRANSFORM_ROT_90) {
211 e->src_rect.y = (src->t + src->b) - (e->src_rect.y + e->src_rect.h);
212 }else{
213 e->src_rect.x = (src->l + src->r) - (e->src_rect.x + e->src_rect.w);
214 }
215 }
216}
217
218/** setup mdp request */
219static void set_infos(struct copybit_context_t *dev,
220 struct mdp_blit_req *req, int flags)
221{
222 req->alpha = dev->mAlpha;
Ramakant Singh140965d2015-01-08 23:45:04 +0530223 req->fps = dev->dynamic_fps;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700224 req->transp_mask = MDP_TRANSP_NOP;
225 req->flags = dev->mFlags | flags;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700226 // check if we are blitting to f/b
227 if (COPYBIT_ENABLE == dev->mBlitToFB) {
228 req->flags |= MDP_MEMORY_ID_TYPE_FB;
229 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700230#if defined(COPYBIT_QSD8K)
231 req->flags |= MDP_BLEND_FG_PREMULT;
232#endif
233}
234
235/** copy the bits */
236static int msm_copybit(struct copybit_context_t *dev, void const *list)
237{
Terence Hampsonb6e4b1e2013-09-13 17:17:11 -0400238 int err;
239 if (dev->relFence != -1) {
240 close(dev->relFence);
241 dev->relFence = -1;
242 }
243 err = ioctl(dev->mFD, MSMFB_ASYNC_BLIT,
Terence Hampsonadf47302013-05-23 12:21:02 -0400244 (struct mdp_async_blit_req_list const*)list);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700245 ALOGE_IF(err<0, "copyBits failed (%s)", strerror(errno));
246 if (err == 0) {
247 return 0;
248 } else {
249#if DEBUG_MDP_ERRORS
Terence Hampsonadf47302013-05-23 12:21:02 -0400250 struct mdp_async_blit_req_list const* l =
251 (struct mdp_async_blit_req_list const*)list;
Naseer Ahmedb16edac2012-07-15 23:56:21 -0700252 for (unsigned int i=0 ; i<l->count ; i++) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700253 ALOGE("%d: src={w=%d, h=%d, f=%d, rect={%d,%d,%d,%d}}\n"
254 " dst={w=%d, h=%d, f=%d, rect={%d,%d,%d,%d}}\n"
Ramakant Singh140965d2015-01-08 23:45:04 +0530255 " flags=%08x, fps=%d"
Naseer Ahmed29a26812012-06-14 00:56:20 -0700256 ,
257 i,
258 l->req[i].src.width,
259 l->req[i].src.height,
260 l->req[i].src.format,
261 l->req[i].src_rect.x,
262 l->req[i].src_rect.y,
263 l->req[i].src_rect.w,
264 l->req[i].src_rect.h,
265 l->req[i].dst.width,
266 l->req[i].dst.height,
267 l->req[i].dst.format,
268 l->req[i].dst_rect.x,
269 l->req[i].dst_rect.y,
270 l->req[i].dst_rect.w,
271 l->req[i].dst_rect.h,
Ramakant Singh140965d2015-01-08 23:45:04 +0530272 l->req[i].flags,
273 l->req[i].fps
Naseer Ahmed29a26812012-06-14 00:56:20 -0700274 );
275 }
276#endif
277 return -errno;
278 }
279}
280
281/*****************************************************************************/
282
283/** Set a parameter to value */
284static int set_parameter_copybit(
285 struct copybit_device_t *dev,
286 int name,
287 int value)
288{
289 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
290 int status = 0;
291 if (ctx) {
292 switch(name) {
293 case COPYBIT_ROTATION_DEG:
294 switch (value) {
295 case 0:
296 ctx->mFlags &= ~0x7;
297 break;
298 case 90:
299 ctx->mFlags &= ~0x7;
300 ctx->mFlags |= MDP_ROT_90;
301 break;
302 case 180:
303 ctx->mFlags &= ~0x7;
304 ctx->mFlags |= MDP_ROT_180;
305 break;
306 case 270:
307 ctx->mFlags &= ~0x7;
308 ctx->mFlags |= MDP_ROT_270;
309 break;
310 default:
311 ALOGE("Invalid value for COPYBIT_ROTATION_DEG");
312 status = -EINVAL;
313 break;
314 }
315 break;
316 case COPYBIT_PLANE_ALPHA:
317 if (value < 0) value = MDP_ALPHA_NOP;
318 if (value >= 256) value = 255;
Praveena Pachipulusuaef031c2014-02-12 11:46:39 +0530319 ctx->mAlpha = (uint8_t)value;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700320 break;
Ramakant Singh140965d2015-01-08 23:45:04 +0530321 case COPYBIT_DYNAMIC_FPS:
322 ctx->dynamic_fps = (uint8_t)value;
323 break;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700324 case COPYBIT_DITHER:
325 if (value == COPYBIT_ENABLE) {
326 ctx->mFlags |= MDP_DITHER;
327 } else if (value == COPYBIT_DISABLE) {
328 ctx->mFlags &= ~MDP_DITHER;
329 }
330 break;
331 case COPYBIT_BLUR:
332 if (value == COPYBIT_ENABLE) {
333 ctx->mFlags |= MDP_BLUR;
334 } else if (value == COPYBIT_DISABLE) {
335 ctx->mFlags &= ~MDP_BLUR;
336 }
337 break;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800338 case COPYBIT_BLEND_MODE:
339 if(value == COPYBIT_BLENDING_PREMULT) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700340 ctx->mFlags |= MDP_BLEND_FG_PREMULT;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800341 } else {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700342 ctx->mFlags &= ~MDP_BLEND_FG_PREMULT;
343 }
344 break;
345 case COPYBIT_TRANSFORM:
346 ctx->mFlags &= ~0x7;
347 ctx->mFlags |= value & 0x7;
348 break;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700349 case COPYBIT_BLIT_TO_FRAMEBUFFER:
350 if (COPYBIT_ENABLE == value) {
351 ctx->mBlitToFB = value;
352 } else if (COPYBIT_DISABLE == value) {
353 ctx->mBlitToFB = value;
354 } else {
355 ALOGE ("%s:Invalid input for COPYBIT_BLIT_TO_FRAMEBUFFER : %d",
356 __FUNCTION__, value);
357 }
358 break;
Shivaraj Shettye86506a2013-08-06 12:56:30 +0530359 case COPYBIT_FG_LAYER:
360 if(value == COPYBIT_ENABLE) {
361 ctx->mFlags |= MDP_IS_FG;
362 } else if (value == COPYBIT_DISABLE) {
363 ctx->mFlags &= ~MDP_IS_FG;
364 }
365 break ;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700366 default:
367 status = -EINVAL;
368 break;
369 }
370 } else {
371 status = -EINVAL;
372 }
373 return status;
374}
375
376/** Get a static info value */
377static int get(struct copybit_device_t *dev, int name)
378{
379 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
380 int value;
381 if (ctx) {
382 switch(name) {
383 case COPYBIT_MINIFICATION_LIMIT:
384 value = MAX_SCALE_FACTOR;
385 break;
386 case COPYBIT_MAGNIFICATION_LIMIT:
387 value = MAX_SCALE_FACTOR;
388 break;
389 case COPYBIT_SCALING_FRAC_BITS:
390 value = 32;
391 break;
392 case COPYBIT_ROTATION_STEP_DEG:
393 value = 90;
394 break;
395 default:
396 value = -EINVAL;
397 }
398 } else {
399 value = -EINVAL;
400 }
401 return value;
402}
403
Terence Hampsonadf47302013-05-23 12:21:02 -0400404static int set_sync_copybit(struct copybit_device_t *dev,
405 int acquireFenceFd)
406{
407 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
408 if (acquireFenceFd != -1) {
Terence Hampson1d8db6f2013-07-17 11:05:36 -0400409 if (ctx->list.sync.acq_fen_fd_cnt < (MDP_MAX_FENCE_FD - 1)) {
410 ctx->acqFence[ctx->list.sync.acq_fen_fd_cnt++] = acquireFenceFd;
Terence Hampsonadf47302013-05-23 12:21:02 -0400411 } else {
412 int ret = -EINVAL;
413 struct blitReq *list = &ctx->list;
414
415 // Since fence is full kick off what is already in the list
416 ret = msm_copybit(ctx, list);
417 if (ret < 0) {
418 ALOGE("%s: Blit call failed", __FUNCTION__);
419 return -EINVAL;
420 }
421 list->count = 0;
Terence Hampson1d8db6f2013-07-17 11:05:36 -0400422 list->sync.acq_fen_fd_cnt = 0;
423 ctx->acqFence[list->sync.acq_fen_fd_cnt++] = acquireFenceFd;
Terence Hampsonadf47302013-05-23 12:21:02 -0400424 }
425 }
426 return 0;
427}
428
Naseer Ahmed29a26812012-06-14 00:56:20 -0700429/** do a stretch blit type operation */
430static int stretch_copybit(
431 struct copybit_device_t *dev,
432 struct copybit_image_t const *dst,
433 struct copybit_image_t const *src,
434 struct copybit_rect_t const *dst_rect,
435 struct copybit_rect_t const *src_rect,
436 struct copybit_region_t const *region)
437{
438 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
Terence Hampsonadf47302013-05-23 12:21:02 -0400439 struct blitReq *list;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700440 int status = 0;
441 private_handle_t *yv12_handle = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700442
Terence Hampsonadf47302013-05-23 12:21:02 -0400443 if (ctx) {
444 list = &ctx->list;
445
Naseer Ahmed29a26812012-06-14 00:56:20 -0700446 if (ctx->mAlpha < 255) {
447 switch (src->format) {
448 // we don't support plane alpha with RGBA formats
449 case HAL_PIXEL_FORMAT_RGBA_8888:
450 case HAL_PIXEL_FORMAT_BGRA_8888:
Ramkumar Radhakrishnan96439522014-10-09 13:37:52 -0700451 case HAL_PIXEL_FORMAT_RGBA_5551:
452 case HAL_PIXEL_FORMAT_RGBA_4444:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700453 ALOGE ("%s : Unsupported Pixel format %d", __FUNCTION__,
454 src->format);
455 return -EINVAL;
456 }
457 }
458
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800459 if (src_rect->l < 0 || (uint32_t)src_rect->r > src->w ||
460 src_rect->t < 0 || (uint32_t)src_rect->b > src->h) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700461 // this is always invalid
462 ALOGE ("%s : Invalid source rectangle : src_rect l %d t %d r %d b %d",\
463 __FUNCTION__, src_rect->l, src_rect->t, src_rect->r, src_rect->b);
464
465 return -EINVAL;
466 }
467
468 if (src->w > MAX_DIMENSION || src->h > MAX_DIMENSION) {
469 ALOGE ("%s : Invalid source dimensions w %d h %d", __FUNCTION__, src->w, src->h);
470 return -EINVAL;
471 }
472
473 if (dst->w > MAX_DIMENSION || dst->h > MAX_DIMENSION) {
474 ALOGE ("%s : Invalid DST dimensions w %d h %d", __FUNCTION__, dst->w, dst->h);
475 return -EINVAL;
476 }
477
478 if(src->format == HAL_PIXEL_FORMAT_YV12) {
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800479 int usage =
Terence Hampson0124cc72013-04-18 23:45:56 -0700480 GRALLOC_USAGE_PRIVATE_IOMMU_HEAP | GRALLOC_USAGE_PRIVATE_UNCACHED;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700481 if (0 == alloc_buffer(&yv12_handle,src->w,src->h,
482 src->format, usage)){
483 if(0 == convertYV12toYCrCb420SP(src,yv12_handle)){
484 (const_cast<copybit_image_t *>(src))->format =
485 HAL_PIXEL_FORMAT_YCrCb_420_SP;
486 (const_cast<copybit_image_t *>(src))->handle =
487 yv12_handle;
488 (const_cast<copybit_image_t *>(src))->base =
489 (void *)yv12_handle->base;
490 }
491 else{
492 ALOGE("Error copybit conversion from yv12 failed");
493 if(yv12_handle)
494 free_buffer(yv12_handle);
495 return -EINVAL;
496 }
497 }
498 else{
499 ALOGE("Error:unable to allocate memeory for yv12 software conversion");
500 return -EINVAL;
501 }
502 }
Praveena Pachipulusuaef031c2014-02-12 11:46:39 +0530503 const uint32_t maxCount =
504 (uint32_t)(sizeof(list->req)/sizeof(list->req[0]));
Dhivya Subramanian7c4baa42013-06-21 14:44:15 -0700505 const struct copybit_rect_t bounds = { 0, 0, (int)dst->w, (int)dst->h };
Naseer Ahmed29a26812012-06-14 00:56:20 -0700506 struct copybit_rect_t clip;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700507 status = 0;
508 while ((status == 0) && region->next(region, &clip)) {
509 intersect(&clip, &bounds, &clip);
Terence Hampsonadf47302013-05-23 12:21:02 -0400510 mdp_blit_req* req = &list->req[list->count];
Naseer Ahmed29a26812012-06-14 00:56:20 -0700511 int flags = 0;
512
513 private_handle_t* src_hnd = (private_handle_t*)src->handle;
Saurabh Shah1adcafe2014-12-19 10:05:41 -0800514 if(src_hnd != NULL &&
515 (!(src_hnd->flags & private_handle_t::PRIV_FLAGS_CACHED))) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700516 flags |= MDP_BLIT_NON_CACHED;
517 }
518
Sushil Chauhan0265c472014-10-01 16:39:02 -0700519 // Set Color Space for MDP to configure CSC matrix
520 req->color_space = ITU_R_601;
Ramakant Singhcab868b2015-02-25 16:19:43 +0530521 MetaData_t *metadata = NULL;
522
523 if (src_hnd != NULL)
524 metadata = (MetaData_t *)src_hnd->base_metadata;
525
Sushil Chauhan0265c472014-10-01 16:39:02 -0700526 if (metadata && (metadata->operation & UPDATE_COLOR_SPACE)) {
527 req->color_space = metadata->colorSpace;
528 }
529
Naseer Ahmed29a26812012-06-14 00:56:20 -0700530 set_infos(ctx, req, flags);
531 set_image(&req->dst, dst);
532 set_image(&req->src, src);
Praveena Pachipulusuaef031c2014-02-12 11:46:39 +0530533 set_rects(ctx, req, dst_rect, src_rect, &clip);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700534
535 if (req->src_rect.w<=0 || req->src_rect.h<=0)
536 continue;
537
538 if (req->dst_rect.w<=0 || req->dst_rect.h<=0)
539 continue;
540
Terence Hampsonadf47302013-05-23 12:21:02 -0400541 if (++list->count == maxCount) {
542 status = msm_copybit(ctx, list);
Terence Hampsonb6e4b1e2013-09-13 17:17:11 -0400543 list->sync.acq_fen_fd_cnt = 0;
Terence Hampsonadf47302013-05-23 12:21:02 -0400544 list->count = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700545 }
546 }
Terence Hampsonc67e87f2013-07-04 15:45:47 -0400547 if(yv12_handle) {
548 //Before freeing the buffer we need buffer passed through blit call
549 if (list->count != 0) {
550 status = msm_copybit(ctx, list);
Terence Hampsonb6e4b1e2013-09-13 17:17:11 -0400551 list->sync.acq_fen_fd_cnt = 0;
Terence Hampsonc67e87f2013-07-04 15:45:47 -0400552 list->count = 0;
553 }
554 free_buffer(yv12_handle);
555 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700556 } else {
557 ALOGE ("%s : Invalid COPYBIT context", __FUNCTION__);
558 status = -EINVAL;
559 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700560 return status;
561}
562
563/** Perform a blit type operation */
564static int blit_copybit(
565 struct copybit_device_t *dev,
566 struct copybit_image_t const *dst,
567 struct copybit_image_t const *src,
568 struct copybit_region_t const *region)
569{
Dhivya Subramanian7c4baa42013-06-21 14:44:15 -0700570 struct copybit_rect_t dr = { 0, 0, (int)dst->w, (int)dst->h };
571 struct copybit_rect_t sr = { 0, 0, (int)src->w, (int)src->h };
Naseer Ahmed29a26812012-06-14 00:56:20 -0700572 return stretch_copybit(dev, dst, src, &dr, &sr, region);
573}
574
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800575static int finish_copybit(struct copybit_device_t *dev)
576{
577 // NOP for MDP copybit
Praveena Pachipulusuaef031c2014-02-12 11:46:39 +0530578 if(!dev)
579 return -EINVAL;
580
Terence Hampson0124cc72013-04-18 23:45:56 -0700581 return 0;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800582}
Ramakant Singh613e3572013-10-17 15:25:14 +0530583static int clear_copybit(struct copybit_device_t *dev,
584 struct copybit_image_t const *buf,
585 struct copybit_rect_t *rect)
586{
587 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
588 uint32_t color = 0; // black color
589
590 if (!ctx) {
591 ALOGE ("%s: Invalid copybit context", __FUNCTION__);
592 return -EINVAL;
593 }
594
595 struct blitReq list1;
596 memset((char *)&list1 , 0 ,sizeof (struct blitReq) );
597 list1.count = 1;
Ramakant Singh613e3572013-10-17 15:25:14 +0530598 int my_tmp_get_fence = -1;
599
Terence Hampsonffbcf432013-12-30 17:18:33 -0500600 list1.sync.acq_fen_fd = ctx->acqFence;
Ramakant Singh613e3572013-10-17 15:25:14 +0530601 list1.sync.rel_fen_fd = &my_tmp_get_fence;
Terence Hampsonffbcf432013-12-30 17:18:33 -0500602 list1.sync.acq_fen_fd_cnt = ctx->list.sync.acq_fen_fd_cnt;
Ramakant Singh613e3572013-10-17 15:25:14 +0530603 mdp_blit_req* req = &list1.req[0];
604
605 if(!req) {
606 ALOGE ("%s : Invalid request", __FUNCTION__);
607 return -EINVAL;
608 }
609
610 set_image(&req->dst, buf);
611 set_image(&req->src, buf);
612
613 if (rect->l < 0 || (uint32_t)(rect->r - rect->l) > req->dst.width ||
614 rect->t < 0 || (uint32_t)(rect->b - rect->t) > req->dst.height) {
615 ALOGE ("%s : Invalid rect : src_rect l %d t %d r %d b %d",\
616 __FUNCTION__, rect->l, rect->t, rect->r, rect->b);
617 return -EINVAL;
618 }
619
620 req->dst_rect.x = rect->l;
621 req->dst_rect.y = rect->t;
622 req->dst_rect.w = rect->r - rect->l;
623 req->dst_rect.h = rect->b - rect->t;
624
625 req->src_rect = req->dst_rect;
626
627 req->const_color.b = (uint32_t)((color >> 16) & 0xff);
628 req->const_color.g = (uint32_t)((color >> 8) & 0xff);
629 req->const_color.r = (uint32_t)((color >> 0) & 0xff);
630 req->const_color.alpha = MDP_ALPHA_NOP;
631
632 req->transp_mask = MDP_TRANSP_NOP;
633 req->flags = MDP_SOLID_FILL | MDP_MEMORY_ID_TYPE_FB | MDP_BLEND_FG_PREMULT;
634 int status = msm_copybit(ctx, &list1);
635
Terence Hampsonffbcf432013-12-30 17:18:33 -0500636 ctx->list.sync.acq_fen_fd_cnt = 0;
Ramakant Singh613e3572013-10-17 15:25:14 +0530637 if (my_tmp_get_fence != -1)
638 close(my_tmp_get_fence);
639
640 return status;
641}
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800642
Sushil Chauhan943797c2013-10-21 17:35:55 -0700643/** Fill the rect on dst with RGBA color **/
644static int fill_color(struct copybit_device_t *dev,
645 struct copybit_image_t const *dst,
646 struct copybit_rect_t const *rect,
647 uint32_t color)
648{
649 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
650 if (!ctx) {
651 ALOGE("%s: Invalid copybit context", __FUNCTION__);
652 return -EINVAL;
653 }
654
655 if (dst->w > MAX_DIMENSION || dst->h > MAX_DIMENSION) {
656 ALOGE("%s: Invalid DST w=%d h=%d", __FUNCTION__, dst->w, dst->h);
657 return -EINVAL;
658 }
659
660 if (rect->l < 0 || (uint32_t)(rect->r - rect->l) > dst->w ||
661 rect->t < 0 || (uint32_t)(rect->b - rect->t) > dst->h) {
662 ALOGE("%s: Invalid destination rect: l=%d t=%d r=%d b=%d",
663 __FUNCTION__, rect->l, rect->t, rect->r, rect->b);
664 return -EINVAL;
665 }
666
Sushil Chauhan2babecc2013-12-04 17:29:48 -0800667 int status = 0;
Sushil Chauhan943797c2013-10-21 17:35:55 -0700668 struct blitReq* list = &ctx->list;
669 mdp_blit_req* req = &list->req[list->count++];
670 set_infos(ctx, req, MDP_SOLID_FILL);
671 set_image(&req->src, dst);
672 set_image(&req->dst, dst);
673
674 req->dst_rect.x = rect->l;
675 req->dst_rect.y = rect->t;
676 req->dst_rect.w = rect->r - rect->l;
677 req->dst_rect.h = rect->b - rect->t;
678 req->src_rect = req->dst_rect;
679
680 req->const_color.r = (uint32_t)((color >> 0) & 0xff);
681 req->const_color.g = (uint32_t)((color >> 8) & 0xff);
682 req->const_color.b = (uint32_t)((color >> 16) & 0xff);
683 req->const_color.alpha = (uint32_t)((color >> 24) & 0xff);
684
Sushil Chauhan2babecc2013-12-04 17:29:48 -0800685 if (list->count == sizeof(list->req)/sizeof(list->req[0])) {
686 status = msm_copybit(ctx, list);
687 list->sync.acq_fen_fd_cnt = 0;
688 list->count = 0;
689 }
Sushil Chauhan943797c2013-10-21 17:35:55 -0700690 return status;
691}
692
Naseer Ahmed29a26812012-06-14 00:56:20 -0700693/*****************************************************************************/
694
695/** Close the copybit device */
696static int close_copybit(struct hw_device_t *dev)
697{
698 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
699 if (ctx) {
700 close(ctx->mFD);
701 free(ctx);
702 }
703 return 0;
704}
705
Terence Hampson0124cc72013-04-18 23:45:56 -0700706static int flush_get_fence(struct copybit_device_t *dev, int* fd)
707{
Terence Hampsonadf47302013-05-23 12:21:02 -0400708 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
709 struct blitReq *list = &ctx->list;
710 int ret = -EINVAL;
711
712 if (list->count) {
713 ret = msm_copybit(ctx, list);
714 if (ret < 0)
715 ALOGE("%s: Blit call failed", __FUNCTION__);
716 list->count = 0;
Terence Hampsonadf47302013-05-23 12:21:02 -0400717 }
718 *fd = ctx->relFence;
Terence Hampson1d8db6f2013-07-17 11:05:36 -0400719 list->sync.acq_fen_fd_cnt = 0;
Terence Hampsonadf47302013-05-23 12:21:02 -0400720 ctx->relFence = -1;
721 return ret;
Terence Hampson0124cc72013-04-18 23:45:56 -0700722}
723
Naseer Ahmed29a26812012-06-14 00:56:20 -0700724/** Open a new instance of a copybit device using name */
725static int open_copybit(const struct hw_module_t* module, const char* name,
726 struct hw_device_t** device)
727{
728 int status = -EINVAL;
Praveena Pachipulusuaef031c2014-02-12 11:46:39 +0530729
Dileep Kumar Reddi8ec85af2014-06-26 09:43:49 +0530730 if (strcmp(name, COPYBIT_HARDWARE_COPYBIT0)) {
Praveena Pachipulusuaef031c2014-02-12 11:46:39 +0530731 return COPYBIT_FAILURE;
732 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700733 copybit_context_t *ctx;
734 ctx = (copybit_context_t *)malloc(sizeof(copybit_context_t));
Ramakant Singhcab868b2015-02-25 16:19:43 +0530735
736 if (ctx == NULL ) {
737 return COPYBIT_FAILURE;
738 }
739
Naseer Ahmed29a26812012-06-14 00:56:20 -0700740 memset(ctx, 0, sizeof(*ctx));
741
742 ctx->device.common.tag = HARDWARE_DEVICE_TAG;
743 ctx->device.common.version = 1;
744 ctx->device.common.module = const_cast<hw_module_t*>(module);
745 ctx->device.common.close = close_copybit;
746 ctx->device.set_parameter = set_parameter_copybit;
747 ctx->device.get = get;
748 ctx->device.blit = blit_copybit;
Terence Hampsonadf47302013-05-23 12:21:02 -0400749 ctx->device.set_sync = set_sync_copybit;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700750 ctx->device.stretch = stretch_copybit;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800751 ctx->device.finish = finish_copybit;
Sushil Chauhan943797c2013-10-21 17:35:55 -0700752 ctx->device.fill_color = fill_color;
Terence Hampson0124cc72013-04-18 23:45:56 -0700753 ctx->device.flush_get_fence = flush_get_fence;
Ramakant Singh613e3572013-10-17 15:25:14 +0530754 ctx->device.clear = clear_copybit;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700755 ctx->mAlpha = MDP_ALPHA_NOP;
Ramakant Singh140965d2015-01-08 23:45:04 +0530756 //dynamic_fps is zero means default
757 //panel refresh rate for driver.
758 ctx->dynamic_fps = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700759 ctx->mFlags = 0;
Terence Hampsonadf47302013-05-23 12:21:02 -0400760 ctx->sync.flags = 0;
Sushil Chauhan9be65422013-12-02 13:27:53 -0800761 ctx->relFence = -1;
762 for (int i=0; i < MDP_MAX_FENCE_FD; i++) {
763 ctx->acqFence[i] = -1;
764 }
Terence Hampsonadf47302013-05-23 12:21:02 -0400765 ctx->sync.acq_fen_fd = ctx->acqFence;
766 ctx->sync.rel_fen_fd = &ctx->relFence;
767 ctx->list.count = 0;
Terence Hampson1d8db6f2013-07-17 11:05:36 -0400768 ctx->list.sync.acq_fen_fd_cnt = 0;
Terence Hampsonadf47302013-05-23 12:21:02 -0400769 ctx->list.sync.rel_fen_fd = ctx->sync.rel_fen_fd;
770 ctx->list.sync.acq_fen_fd = ctx->sync.acq_fen_fd;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700771 ctx->mFD = open("/dev/graphics/fb0", O_RDWR, 0);
772 if (ctx->mFD < 0) {
773 status = errno;
774 ALOGE("Error opening frame buffer errno=%d (%s)",
775 status, strerror(status));
776 status = -status;
777 } else {
Terence Hampson0124cc72013-04-18 23:45:56 -0700778 status = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700779 *device = &ctx->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700780 }
781 return status;
782}