blob: 25a2cae8ec4bd9b38c92b87d9d9bb047ffe8779f [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -08003 * Copyright (c) 2010 - 2013, The Linux Foundation. All rights reserved.
4 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
Naseer 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"
40
41#define DEBUG_MDP_ERRORS 1
42
43/******************************************************************************/
44
Naseer Ahmed29a26812012-06-14 00:56:20 -070045#define MAX_SCALE_FACTOR (4)
46#define MAX_DIMENSION (4096)
Naseer Ahmed29a26812012-06-14 00:56:20 -070047
48/******************************************************************************/
Terence Hampsonadf47302013-05-23 12:21:02 -040049struct blitReq{
50 struct mdp_buf_sync sync;
51 uint32_t count;
52 struct mdp_blit_req req[10];
53};
Naseer Ahmed29a26812012-06-14 00:56:20 -070054
55/** State information for each device instance */
56struct copybit_context_t {
57 struct copybit_device_t device;
58 int mFD;
59 uint8_t mAlpha;
60 int mFlags;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070061 bool mBlitToFB;
Terence Hampsonadf47302013-05-23 12:21:02 -040062 int acqFence[MDP_MAX_FENCE_FD];
63 int relFence;
64 struct mdp_buf_sync sync;
65 struct blitReq list;
Naseer Ahmed29a26812012-06-14 00:56:20 -070066};
67
68/**
69 * Common hardware methods
70 */
71
72static int open_copybit(const struct hw_module_t* module, const char* name,
73 struct hw_device_t** device);
74
75static struct hw_module_methods_t copybit_module_methods = {
76open: open_copybit
77};
78
79/*
80 * The COPYBIT Module
81 */
82struct copybit_module_t HAL_MODULE_INFO_SYM = {
83common: {
84tag: HARDWARE_MODULE_TAG,
85 version_major: 1,
86 version_minor: 0,
87 id: COPYBIT_HARDWARE_MODULE_ID,
88 name: "QCT MSM7K COPYBIT Module",
89 author: "Google, Inc.",
90 methods: &copybit_module_methods
91 }
92};
93
94/******************************************************************************/
95
96/** min of int a, b */
97static inline int min(int a, int b) {
98 return (a<b) ? a : b;
99}
100
101/** max of int a, b */
102static inline int max(int a, int b) {
103 return (a>b) ? a : b;
104}
105
106/** scale each parameter by mul/div. Assume div isn't 0 */
107static inline void MULDIV(uint32_t *a, uint32_t *b, int mul, int div) {
108 if (mul != div) {
109 *a = (mul * *a) / div;
110 *b = (mul * *b) / div;
111 }
112}
113
114/** Determine the intersection of lhs & rhs store in out */
115static void intersect(struct copybit_rect_t *out,
116 const struct copybit_rect_t *lhs,
117 const struct copybit_rect_t *rhs) {
118 out->l = max(lhs->l, rhs->l);
119 out->t = max(lhs->t, rhs->t);
120 out->r = min(lhs->r, rhs->r);
121 out->b = min(lhs->b, rhs->b);
122}
123
124/** convert COPYBIT_FORMAT to MDP format */
125static int get_format(int format) {
126 switch (format) {
127 case HAL_PIXEL_FORMAT_RGB_565: return MDP_RGB_565;
128 case HAL_PIXEL_FORMAT_RGBX_8888: return MDP_RGBX_8888;
129 case HAL_PIXEL_FORMAT_RGB_888: return MDP_RGB_888;
130 case HAL_PIXEL_FORMAT_RGBA_8888: return MDP_RGBA_8888;
131 case HAL_PIXEL_FORMAT_BGRA_8888: return MDP_BGRA_8888;
Raj kamale77f4ec2013-07-03 23:57:50 +0530132 case HAL_PIXEL_FORMAT_YCrCb_422_SP: return MDP_Y_CRCB_H2V1;
133 case HAL_PIXEL_FORMAT_YCrCb_420_SP: return MDP_Y_CRCB_H2V2;
134 case HAL_PIXEL_FORMAT_YCbCr_422_SP: return MDP_Y_CBCR_H2V1;
135 case HAL_PIXEL_FORMAT_YCbCr_420_SP: return MDP_Y_CBCR_H2V2;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700136 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: return MDP_Y_CBCR_H2V2_ADRENO;
Radhika Ranjan Soni21175f92013-07-12 17:32:15 +0530137 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: return MDP_Y_CBCR_H2V2_VENUS;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800138 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: return MDP_Y_CBCR_H2V2;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700139 }
140 return -1;
141}
142
143/** convert from copybit image to mdp image structure */
144static void set_image(struct mdp_img *img, const struct copybit_image_t *rhs)
145{
146 private_handle_t* hnd = (private_handle_t*)rhs->handle;
147 if(hnd == NULL){
148 ALOGE("copybit: Invalid handle");
149 return;
150 }
151 img->width = rhs->w;
152 img->height = rhs->h;
153 img->format = get_format(rhs->format);
154 img->offset = hnd->offset;
155 img->memory_id = hnd->fd;
156}
157/** setup rectangles */
158static void set_rects(struct copybit_context_t *dev,
159 struct mdp_blit_req *e,
160 const struct copybit_rect_t *dst,
161 const struct copybit_rect_t *src,
162 const struct copybit_rect_t *scissor,
163 uint32_t horiz_padding,
164 uint32_t vert_padding) {
165 struct copybit_rect_t clip;
166 intersect(&clip, scissor, dst);
167
168 e->dst_rect.x = clip.l;
169 e->dst_rect.y = clip.t;
170 e->dst_rect.w = clip.r - clip.l;
171 e->dst_rect.h = clip.b - clip.t;
172
173 uint32_t W, H, delta_x, delta_y;
174 if (dev->mFlags & COPYBIT_TRANSFORM_ROT_90) {
175 delta_x = (clip.t - dst->t);
176 delta_y = (dst->r - clip.r);
177 e->src_rect.w = (clip.b - clip.t);
178 e->src_rect.h = (clip.r - clip.l);
179 W = dst->b - dst->t;
180 H = dst->r - dst->l;
181 } else {
182 delta_x = (clip.l - dst->l);
183 delta_y = (clip.t - dst->t);
184 e->src_rect.w = (clip.r - clip.l);
185 e->src_rect.h = (clip.b - clip.t);
186 W = dst->r - dst->l;
187 H = dst->b - dst->t;
188 }
189
190 MULDIV(&delta_x, &e->src_rect.w, src->r - src->l, W);
191 MULDIV(&delta_y, &e->src_rect.h, src->b - src->t, H);
192
193 e->src_rect.x = delta_x + src->l;
194 e->src_rect.y = delta_y + src->t;
195
196 if (dev->mFlags & COPYBIT_TRANSFORM_FLIP_V) {
197 if (dev->mFlags & COPYBIT_TRANSFORM_ROT_90) {
198 e->src_rect.x = (src->l + src->r) - (e->src_rect.x + e->src_rect.w);
199 }else{
200 e->src_rect.y = (src->t + src->b) - (e->src_rect.y + e->src_rect.h);
201 }
202 }
203
204 if (dev->mFlags & COPYBIT_TRANSFORM_FLIP_H) {
205 if (dev->mFlags & COPYBIT_TRANSFORM_ROT_90) {
206 e->src_rect.y = (src->t + src->b) - (e->src_rect.y + e->src_rect.h);
207 }else{
208 e->src_rect.x = (src->l + src->r) - (e->src_rect.x + e->src_rect.w);
209 }
210 }
211}
212
213/** setup mdp request */
214static void set_infos(struct copybit_context_t *dev,
215 struct mdp_blit_req *req, int flags)
216{
217 req->alpha = dev->mAlpha;
218 req->transp_mask = MDP_TRANSP_NOP;
219 req->flags = dev->mFlags | flags;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700220 // check if we are blitting to f/b
221 if (COPYBIT_ENABLE == dev->mBlitToFB) {
222 req->flags |= MDP_MEMORY_ID_TYPE_FB;
223 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700224#if defined(COPYBIT_QSD8K)
225 req->flags |= MDP_BLEND_FG_PREMULT;
226#endif
227}
228
229/** copy the bits */
230static int msm_copybit(struct copybit_context_t *dev, void const *list)
231{
Terence Hampsonb6e4b1e2013-09-13 17:17:11 -0400232 int err;
233 if (dev->relFence != -1) {
234 close(dev->relFence);
235 dev->relFence = -1;
236 }
237 err = ioctl(dev->mFD, MSMFB_ASYNC_BLIT,
Terence Hampsonadf47302013-05-23 12:21:02 -0400238 (struct mdp_async_blit_req_list const*)list);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700239 ALOGE_IF(err<0, "copyBits failed (%s)", strerror(errno));
240 if (err == 0) {
241 return 0;
242 } else {
243#if DEBUG_MDP_ERRORS
Terence Hampsonadf47302013-05-23 12:21:02 -0400244 struct mdp_async_blit_req_list const* l =
245 (struct mdp_async_blit_req_list const*)list;
Naseer Ahmedb16edac2012-07-15 23:56:21 -0700246 for (unsigned int i=0 ; i<l->count ; i++) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700247 ALOGE("%d: src={w=%d, h=%d, f=%d, rect={%d,%d,%d,%d}}\n"
248 " dst={w=%d, h=%d, f=%d, rect={%d,%d,%d,%d}}\n"
Naseer Ahmedb16edac2012-07-15 23:56:21 -0700249 " flags=%08x"
Naseer Ahmed29a26812012-06-14 00:56:20 -0700250 ,
251 i,
252 l->req[i].src.width,
253 l->req[i].src.height,
254 l->req[i].src.format,
255 l->req[i].src_rect.x,
256 l->req[i].src_rect.y,
257 l->req[i].src_rect.w,
258 l->req[i].src_rect.h,
259 l->req[i].dst.width,
260 l->req[i].dst.height,
261 l->req[i].dst.format,
262 l->req[i].dst_rect.x,
263 l->req[i].dst_rect.y,
264 l->req[i].dst_rect.w,
265 l->req[i].dst_rect.h,
266 l->req[i].flags
267 );
268 }
269#endif
270 return -errno;
271 }
272}
273
274/*****************************************************************************/
275
276/** Set a parameter to value */
277static int set_parameter_copybit(
278 struct copybit_device_t *dev,
279 int name,
280 int value)
281{
282 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
283 int status = 0;
284 if (ctx) {
285 switch(name) {
286 case COPYBIT_ROTATION_DEG:
287 switch (value) {
288 case 0:
289 ctx->mFlags &= ~0x7;
290 break;
291 case 90:
292 ctx->mFlags &= ~0x7;
293 ctx->mFlags |= MDP_ROT_90;
294 break;
295 case 180:
296 ctx->mFlags &= ~0x7;
297 ctx->mFlags |= MDP_ROT_180;
298 break;
299 case 270:
300 ctx->mFlags &= ~0x7;
301 ctx->mFlags |= MDP_ROT_270;
302 break;
303 default:
304 ALOGE("Invalid value for COPYBIT_ROTATION_DEG");
305 status = -EINVAL;
306 break;
307 }
308 break;
309 case COPYBIT_PLANE_ALPHA:
310 if (value < 0) value = MDP_ALPHA_NOP;
311 if (value >= 256) value = 255;
312 ctx->mAlpha = value;
313 break;
314 case COPYBIT_DITHER:
315 if (value == COPYBIT_ENABLE) {
316 ctx->mFlags |= MDP_DITHER;
317 } else if (value == COPYBIT_DISABLE) {
318 ctx->mFlags &= ~MDP_DITHER;
319 }
320 break;
321 case COPYBIT_BLUR:
322 if (value == COPYBIT_ENABLE) {
323 ctx->mFlags |= MDP_BLUR;
324 } else if (value == COPYBIT_DISABLE) {
325 ctx->mFlags &= ~MDP_BLUR;
326 }
327 break;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800328 case COPYBIT_BLEND_MODE:
329 if(value == COPYBIT_BLENDING_PREMULT) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700330 ctx->mFlags |= MDP_BLEND_FG_PREMULT;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800331 } else {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700332 ctx->mFlags &= ~MDP_BLEND_FG_PREMULT;
333 }
334 break;
335 case COPYBIT_TRANSFORM:
336 ctx->mFlags &= ~0x7;
337 ctx->mFlags |= value & 0x7;
338 break;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700339 case COPYBIT_BLIT_TO_FRAMEBUFFER:
340 if (COPYBIT_ENABLE == value) {
341 ctx->mBlitToFB = value;
342 } else if (COPYBIT_DISABLE == value) {
343 ctx->mBlitToFB = value;
344 } else {
345 ALOGE ("%s:Invalid input for COPYBIT_BLIT_TO_FRAMEBUFFER : %d",
346 __FUNCTION__, value);
347 }
348 break;
Shivaraj Shettye86506a2013-08-06 12:56:30 +0530349 case COPYBIT_FG_LAYER:
350 if(value == COPYBIT_ENABLE) {
351 ctx->mFlags |= MDP_IS_FG;
352 } else if (value == COPYBIT_DISABLE) {
353 ctx->mFlags &= ~MDP_IS_FG;
354 }
355 break ;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700356 default:
357 status = -EINVAL;
358 break;
359 }
360 } else {
361 status = -EINVAL;
362 }
363 return status;
364}
365
366/** Get a static info value */
367static int get(struct copybit_device_t *dev, int name)
368{
369 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
370 int value;
371 if (ctx) {
372 switch(name) {
373 case COPYBIT_MINIFICATION_LIMIT:
374 value = MAX_SCALE_FACTOR;
375 break;
376 case COPYBIT_MAGNIFICATION_LIMIT:
377 value = MAX_SCALE_FACTOR;
378 break;
379 case COPYBIT_SCALING_FRAC_BITS:
380 value = 32;
381 break;
382 case COPYBIT_ROTATION_STEP_DEG:
383 value = 90;
384 break;
385 default:
386 value = -EINVAL;
387 }
388 } else {
389 value = -EINVAL;
390 }
391 return value;
392}
393
Terence Hampsonadf47302013-05-23 12:21:02 -0400394static int set_sync_copybit(struct copybit_device_t *dev,
395 int acquireFenceFd)
396{
397 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
398 if (acquireFenceFd != -1) {
Terence Hampson1d8db6f2013-07-17 11:05:36 -0400399 if (ctx->list.sync.acq_fen_fd_cnt < (MDP_MAX_FENCE_FD - 1)) {
400 ctx->acqFence[ctx->list.sync.acq_fen_fd_cnt++] = acquireFenceFd;
Terence Hampsonadf47302013-05-23 12:21:02 -0400401 } else {
402 int ret = -EINVAL;
403 struct blitReq *list = &ctx->list;
404
405 // Since fence is full kick off what is already in the list
406 ret = msm_copybit(ctx, list);
407 if (ret < 0) {
408 ALOGE("%s: Blit call failed", __FUNCTION__);
409 return -EINVAL;
410 }
411 list->count = 0;
Terence Hampson1d8db6f2013-07-17 11:05:36 -0400412 list->sync.acq_fen_fd_cnt = 0;
413 ctx->acqFence[list->sync.acq_fen_fd_cnt++] = acquireFenceFd;
Terence Hampsonadf47302013-05-23 12:21:02 -0400414 }
415 }
416 return 0;
417}
418
Naseer Ahmed29a26812012-06-14 00:56:20 -0700419/** do a stretch blit type operation */
420static int stretch_copybit(
421 struct copybit_device_t *dev,
422 struct copybit_image_t const *dst,
423 struct copybit_image_t const *src,
424 struct copybit_rect_t const *dst_rect,
425 struct copybit_rect_t const *src_rect,
426 struct copybit_region_t const *region)
427{
428 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
Terence Hampsonadf47302013-05-23 12:21:02 -0400429 struct blitReq *list;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700430 int status = 0;
431 private_handle_t *yv12_handle = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700432
Terence Hampsonadf47302013-05-23 12:21:02 -0400433 if (ctx) {
434 list = &ctx->list;
435
Naseer Ahmed29a26812012-06-14 00:56:20 -0700436 if (ctx->mAlpha < 255) {
437 switch (src->format) {
438 // we don't support plane alpha with RGBA formats
439 case HAL_PIXEL_FORMAT_RGBA_8888:
440 case HAL_PIXEL_FORMAT_BGRA_8888:
441 case HAL_PIXEL_FORMAT_RGBA_5551:
442 case HAL_PIXEL_FORMAT_RGBA_4444:
443 ALOGE ("%s : Unsupported Pixel format %d", __FUNCTION__,
444 src->format);
445 return -EINVAL;
446 }
447 }
448
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800449 if (src_rect->l < 0 || (uint32_t)src_rect->r > src->w ||
450 src_rect->t < 0 || (uint32_t)src_rect->b > src->h) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700451 // this is always invalid
452 ALOGE ("%s : Invalid source rectangle : src_rect l %d t %d r %d b %d",\
453 __FUNCTION__, src_rect->l, src_rect->t, src_rect->r, src_rect->b);
454
455 return -EINVAL;
456 }
457
458 if (src->w > MAX_DIMENSION || src->h > MAX_DIMENSION) {
459 ALOGE ("%s : Invalid source dimensions w %d h %d", __FUNCTION__, src->w, src->h);
460 return -EINVAL;
461 }
462
463 if (dst->w > MAX_DIMENSION || dst->h > MAX_DIMENSION) {
464 ALOGE ("%s : Invalid DST dimensions w %d h %d", __FUNCTION__, dst->w, dst->h);
465 return -EINVAL;
466 }
467
468 if(src->format == HAL_PIXEL_FORMAT_YV12) {
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800469 int usage =
Terence Hampson0124cc72013-04-18 23:45:56 -0700470 GRALLOC_USAGE_PRIVATE_IOMMU_HEAP | GRALLOC_USAGE_PRIVATE_UNCACHED;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700471 if (0 == alloc_buffer(&yv12_handle,src->w,src->h,
472 src->format, usage)){
473 if(0 == convertYV12toYCrCb420SP(src,yv12_handle)){
474 (const_cast<copybit_image_t *>(src))->format =
475 HAL_PIXEL_FORMAT_YCrCb_420_SP;
476 (const_cast<copybit_image_t *>(src))->handle =
477 yv12_handle;
478 (const_cast<copybit_image_t *>(src))->base =
479 (void *)yv12_handle->base;
480 }
481 else{
482 ALOGE("Error copybit conversion from yv12 failed");
483 if(yv12_handle)
484 free_buffer(yv12_handle);
485 return -EINVAL;
486 }
487 }
488 else{
489 ALOGE("Error:unable to allocate memeory for yv12 software conversion");
490 return -EINVAL;
491 }
492 }
Terence Hampsonadf47302013-05-23 12:21:02 -0400493 const uint32_t maxCount = sizeof(list->req)/sizeof(list->req[0]);
Dhivya Subramanian7c4baa42013-06-21 14:44:15 -0700494 const struct copybit_rect_t bounds = { 0, 0, (int)dst->w, (int)dst->h };
Naseer Ahmed29a26812012-06-14 00:56:20 -0700495 struct copybit_rect_t clip;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700496 status = 0;
497 while ((status == 0) && region->next(region, &clip)) {
498 intersect(&clip, &bounds, &clip);
Terence Hampsonadf47302013-05-23 12:21:02 -0400499 mdp_blit_req* req = &list->req[list->count];
Naseer Ahmed29a26812012-06-14 00:56:20 -0700500 int flags = 0;
501
502 private_handle_t* src_hnd = (private_handle_t*)src->handle;
503 if(src_hnd != NULL && src_hnd->flags & private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH) {
504 flags |= MDP_BLIT_NON_CACHED;
505 }
506
507 set_infos(ctx, req, flags);
508 set_image(&req->dst, dst);
509 set_image(&req->src, src);
510 set_rects(ctx, req, dst_rect, src_rect, &clip, src->horiz_padding, src->vert_padding);
511
512 if (req->src_rect.w<=0 || req->src_rect.h<=0)
513 continue;
514
515 if (req->dst_rect.w<=0 || req->dst_rect.h<=0)
516 continue;
517
Terence Hampsonadf47302013-05-23 12:21:02 -0400518 if (++list->count == maxCount) {
519 status = msm_copybit(ctx, list);
Terence Hampsonb6e4b1e2013-09-13 17:17:11 -0400520 list->sync.acq_fen_fd_cnt = 0;
Terence Hampsonadf47302013-05-23 12:21:02 -0400521 list->count = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700522 }
523 }
Terence Hampsonc67e87f2013-07-04 15:45:47 -0400524 if(yv12_handle) {
525 //Before freeing the buffer we need buffer passed through blit call
526 if (list->count != 0) {
527 status = msm_copybit(ctx, list);
Terence Hampsonb6e4b1e2013-09-13 17:17:11 -0400528 list->sync.acq_fen_fd_cnt = 0;
Terence Hampsonc67e87f2013-07-04 15:45:47 -0400529 list->count = 0;
530 }
531 free_buffer(yv12_handle);
532 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700533 } else {
534 ALOGE ("%s : Invalid COPYBIT context", __FUNCTION__);
535 status = -EINVAL;
536 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700537 return status;
538}
539
540/** Perform a blit type operation */
541static int blit_copybit(
542 struct copybit_device_t *dev,
543 struct copybit_image_t const *dst,
544 struct copybit_image_t const *src,
545 struct copybit_region_t const *region)
546{
Dhivya Subramanian7c4baa42013-06-21 14:44:15 -0700547 struct copybit_rect_t dr = { 0, 0, (int)dst->w, (int)dst->h };
548 struct copybit_rect_t sr = { 0, 0, (int)src->w, (int)src->h };
Naseer Ahmed29a26812012-06-14 00:56:20 -0700549 return stretch_copybit(dev, dst, src, &dr, &sr, region);
550}
551
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800552static int finish_copybit(struct copybit_device_t *dev)
553{
554 // NOP for MDP copybit
Terence Hampson0124cc72013-04-18 23:45:56 -0700555 return 0;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800556}
557
Naseer Ahmed29a26812012-06-14 00:56:20 -0700558/*****************************************************************************/
559
560/** Close the copybit device */
561static int close_copybit(struct hw_device_t *dev)
562{
563 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
564 if (ctx) {
565 close(ctx->mFD);
566 free(ctx);
567 }
568 return 0;
569}
570
Terence Hampson0124cc72013-04-18 23:45:56 -0700571static int flush_get_fence(struct copybit_device_t *dev, int* fd)
572{
Terence Hampsonadf47302013-05-23 12:21:02 -0400573 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
574 struct blitReq *list = &ctx->list;
575 int ret = -EINVAL;
576
577 if (list->count) {
578 ret = msm_copybit(ctx, list);
579 if (ret < 0)
580 ALOGE("%s: Blit call failed", __FUNCTION__);
581 list->count = 0;
Terence Hampsonadf47302013-05-23 12:21:02 -0400582 }
583 *fd = ctx->relFence;
Terence Hampson1d8db6f2013-07-17 11:05:36 -0400584 list->sync.acq_fen_fd_cnt = 0;
Terence Hampsonadf47302013-05-23 12:21:02 -0400585 ctx->relFence = -1;
586 return ret;
Terence Hampson0124cc72013-04-18 23:45:56 -0700587}
588
Naseer Ahmed29a26812012-06-14 00:56:20 -0700589/** Open a new instance of a copybit device using name */
590static int open_copybit(const struct hw_module_t* module, const char* name,
591 struct hw_device_t** device)
592{
593 int status = -EINVAL;
594 copybit_context_t *ctx;
595 ctx = (copybit_context_t *)malloc(sizeof(copybit_context_t));
596 memset(ctx, 0, sizeof(*ctx));
597
598 ctx->device.common.tag = HARDWARE_DEVICE_TAG;
599 ctx->device.common.version = 1;
600 ctx->device.common.module = const_cast<hw_module_t*>(module);
601 ctx->device.common.close = close_copybit;
602 ctx->device.set_parameter = set_parameter_copybit;
603 ctx->device.get = get;
604 ctx->device.blit = blit_copybit;
Terence Hampsonadf47302013-05-23 12:21:02 -0400605 ctx->device.set_sync = set_sync_copybit;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700606 ctx->device.stretch = stretch_copybit;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800607 ctx->device.finish = finish_copybit;
Terence Hampson0124cc72013-04-18 23:45:56 -0700608 ctx->device.flush_get_fence = flush_get_fence;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700609 ctx->mAlpha = MDP_ALPHA_NOP;
610 ctx->mFlags = 0;
Terence Hampsonadf47302013-05-23 12:21:02 -0400611 ctx->sync.flags = 0;
Terence Hampsonadf47302013-05-23 12:21:02 -0400612 ctx->sync.acq_fen_fd = ctx->acqFence;
613 ctx->sync.rel_fen_fd = &ctx->relFence;
614 ctx->list.count = 0;
Terence Hampson1d8db6f2013-07-17 11:05:36 -0400615 ctx->list.sync.acq_fen_fd_cnt = 0;
Terence Hampsonadf47302013-05-23 12:21:02 -0400616 ctx->list.sync.rel_fen_fd = ctx->sync.rel_fen_fd;
617 ctx->list.sync.acq_fen_fd = ctx->sync.acq_fen_fd;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700618 ctx->mFD = open("/dev/graphics/fb0", O_RDWR, 0);
619 if (ctx->mFD < 0) {
620 status = errno;
621 ALOGE("Error opening frame buffer errno=%d (%s)",
622 status, strerror(status));
623 status = -status;
624 } else {
Terence Hampson0124cc72013-04-18 23:45:56 -0700625 status = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700626 *device = &ctx->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700627 }
628 return status;
629}