blob: d787828c827fa20321056902a709bb99ea776485 [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;
132 case HAL_PIXEL_FORMAT_YCrCb_422_SP: return MDP_Y_CBCR_H2V1;
133 case HAL_PIXEL_FORMAT_YCrCb_420_SP: return MDP_Y_CBCR_H2V2;
134 case HAL_PIXEL_FORMAT_YCbCr_422_SP: return MDP_Y_CRCB_H2V1;
135 case HAL_PIXEL_FORMAT_YCbCr_420_SP: return MDP_Y_CRCB_H2V2;
136 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: return MDP_Y_CBCR_H2V2_ADRENO;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800137 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: return MDP_Y_CBCR_H2V2;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700138 }
139 return -1;
140}
141
142/** convert from copybit image to mdp image structure */
143static void set_image(struct mdp_img *img, const struct copybit_image_t *rhs)
144{
145 private_handle_t* hnd = (private_handle_t*)rhs->handle;
146 if(hnd == NULL){
147 ALOGE("copybit: Invalid handle");
148 return;
149 }
150 img->width = rhs->w;
151 img->height = rhs->h;
152 img->format = get_format(rhs->format);
153 img->offset = hnd->offset;
154 img->memory_id = hnd->fd;
155}
156/** setup rectangles */
157static void set_rects(struct copybit_context_t *dev,
158 struct mdp_blit_req *e,
159 const struct copybit_rect_t *dst,
160 const struct copybit_rect_t *src,
161 const struct copybit_rect_t *scissor,
162 uint32_t horiz_padding,
163 uint32_t vert_padding) {
164 struct copybit_rect_t clip;
165 intersect(&clip, scissor, dst);
166
167 e->dst_rect.x = clip.l;
168 e->dst_rect.y = clip.t;
169 e->dst_rect.w = clip.r - clip.l;
170 e->dst_rect.h = clip.b - clip.t;
171
172 uint32_t W, H, delta_x, delta_y;
173 if (dev->mFlags & COPYBIT_TRANSFORM_ROT_90) {
174 delta_x = (clip.t - dst->t);
175 delta_y = (dst->r - clip.r);
176 e->src_rect.w = (clip.b - clip.t);
177 e->src_rect.h = (clip.r - clip.l);
178 W = dst->b - dst->t;
179 H = dst->r - dst->l;
180 } else {
181 delta_x = (clip.l - dst->l);
182 delta_y = (clip.t - dst->t);
183 e->src_rect.w = (clip.r - clip.l);
184 e->src_rect.h = (clip.b - clip.t);
185 W = dst->r - dst->l;
186 H = dst->b - dst->t;
187 }
188
189 MULDIV(&delta_x, &e->src_rect.w, src->r - src->l, W);
190 MULDIV(&delta_y, &e->src_rect.h, src->b - src->t, H);
191
192 e->src_rect.x = delta_x + src->l;
193 e->src_rect.y = delta_y + src->t;
194
195 if (dev->mFlags & COPYBIT_TRANSFORM_FLIP_V) {
196 if (dev->mFlags & COPYBIT_TRANSFORM_ROT_90) {
197 e->src_rect.x = (src->l + src->r) - (e->src_rect.x + e->src_rect.w);
198 }else{
199 e->src_rect.y = (src->t + src->b) - (e->src_rect.y + e->src_rect.h);
200 }
201 }
202
203 if (dev->mFlags & COPYBIT_TRANSFORM_FLIP_H) {
204 if (dev->mFlags & COPYBIT_TRANSFORM_ROT_90) {
205 e->src_rect.y = (src->t + src->b) - (e->src_rect.y + e->src_rect.h);
206 }else{
207 e->src_rect.x = (src->l + src->r) - (e->src_rect.x + e->src_rect.w);
208 }
209 }
210}
211
212/** setup mdp request */
213static void set_infos(struct copybit_context_t *dev,
214 struct mdp_blit_req *req, int flags)
215{
216 req->alpha = dev->mAlpha;
217 req->transp_mask = MDP_TRANSP_NOP;
218 req->flags = dev->mFlags | flags;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700219 // check if we are blitting to f/b
220 if (COPYBIT_ENABLE == dev->mBlitToFB) {
221 req->flags |= MDP_MEMORY_ID_TYPE_FB;
222 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700223#if defined(COPYBIT_QSD8K)
224 req->flags |= MDP_BLEND_FG_PREMULT;
225#endif
226}
227
228/** copy the bits */
229static int msm_copybit(struct copybit_context_t *dev, void const *list)
230{
Terence Hampsonadf47302013-05-23 12:21:02 -0400231 int err = ioctl(dev->mFD, MSMFB_ASYNC_BLIT,
232 (struct mdp_async_blit_req_list const*)list);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700233 ALOGE_IF(err<0, "copyBits failed (%s)", strerror(errno));
234 if (err == 0) {
235 return 0;
236 } else {
237#if DEBUG_MDP_ERRORS
Terence Hampsonadf47302013-05-23 12:21:02 -0400238 struct mdp_async_blit_req_list const* l =
239 (struct mdp_async_blit_req_list const*)list;
Naseer Ahmedb16edac2012-07-15 23:56:21 -0700240 for (unsigned int i=0 ; i<l->count ; i++) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700241 ALOGE("%d: src={w=%d, h=%d, f=%d, rect={%d,%d,%d,%d}}\n"
242 " dst={w=%d, h=%d, f=%d, rect={%d,%d,%d,%d}}\n"
Naseer Ahmedb16edac2012-07-15 23:56:21 -0700243 " flags=%08x"
Naseer Ahmed29a26812012-06-14 00:56:20 -0700244 ,
245 i,
246 l->req[i].src.width,
247 l->req[i].src.height,
248 l->req[i].src.format,
249 l->req[i].src_rect.x,
250 l->req[i].src_rect.y,
251 l->req[i].src_rect.w,
252 l->req[i].src_rect.h,
253 l->req[i].dst.width,
254 l->req[i].dst.height,
255 l->req[i].dst.format,
256 l->req[i].dst_rect.x,
257 l->req[i].dst_rect.y,
258 l->req[i].dst_rect.w,
259 l->req[i].dst_rect.h,
260 l->req[i].flags
261 );
262 }
263#endif
264 return -errno;
265 }
266}
267
268/*****************************************************************************/
269
270/** Set a parameter to value */
271static int set_parameter_copybit(
272 struct copybit_device_t *dev,
273 int name,
274 int value)
275{
276 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
277 int status = 0;
278 if (ctx) {
279 switch(name) {
280 case COPYBIT_ROTATION_DEG:
281 switch (value) {
282 case 0:
283 ctx->mFlags &= ~0x7;
284 break;
285 case 90:
286 ctx->mFlags &= ~0x7;
287 ctx->mFlags |= MDP_ROT_90;
288 break;
289 case 180:
290 ctx->mFlags &= ~0x7;
291 ctx->mFlags |= MDP_ROT_180;
292 break;
293 case 270:
294 ctx->mFlags &= ~0x7;
295 ctx->mFlags |= MDP_ROT_270;
296 break;
297 default:
298 ALOGE("Invalid value for COPYBIT_ROTATION_DEG");
299 status = -EINVAL;
300 break;
301 }
302 break;
303 case COPYBIT_PLANE_ALPHA:
304 if (value < 0) value = MDP_ALPHA_NOP;
305 if (value >= 256) value = 255;
306 ctx->mAlpha = value;
307 break;
308 case COPYBIT_DITHER:
309 if (value == COPYBIT_ENABLE) {
310 ctx->mFlags |= MDP_DITHER;
311 } else if (value == COPYBIT_DISABLE) {
312 ctx->mFlags &= ~MDP_DITHER;
313 }
314 break;
315 case COPYBIT_BLUR:
316 if (value == COPYBIT_ENABLE) {
317 ctx->mFlags |= MDP_BLUR;
318 } else if (value == COPYBIT_DISABLE) {
319 ctx->mFlags &= ~MDP_BLUR;
320 }
321 break;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800322 case COPYBIT_BLEND_MODE:
323 if(value == COPYBIT_BLENDING_PREMULT) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700324 ctx->mFlags |= MDP_BLEND_FG_PREMULT;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800325 } else {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700326 ctx->mFlags &= ~MDP_BLEND_FG_PREMULT;
327 }
328 break;
329 case COPYBIT_TRANSFORM:
330 ctx->mFlags &= ~0x7;
331 ctx->mFlags |= value & 0x7;
332 break;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700333 case COPYBIT_BLIT_TO_FRAMEBUFFER:
334 if (COPYBIT_ENABLE == value) {
335 ctx->mBlitToFB = value;
336 } else if (COPYBIT_DISABLE == value) {
337 ctx->mBlitToFB = value;
338 } else {
339 ALOGE ("%s:Invalid input for COPYBIT_BLIT_TO_FRAMEBUFFER : %d",
340 __FUNCTION__, value);
341 }
342 break;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700343 default:
344 status = -EINVAL;
345 break;
346 }
347 } else {
348 status = -EINVAL;
349 }
350 return status;
351}
352
353/** Get a static info value */
354static int get(struct copybit_device_t *dev, int name)
355{
356 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
357 int value;
358 if (ctx) {
359 switch(name) {
360 case COPYBIT_MINIFICATION_LIMIT:
361 value = MAX_SCALE_FACTOR;
362 break;
363 case COPYBIT_MAGNIFICATION_LIMIT:
364 value = MAX_SCALE_FACTOR;
365 break;
366 case COPYBIT_SCALING_FRAC_BITS:
367 value = 32;
368 break;
369 case COPYBIT_ROTATION_STEP_DEG:
370 value = 90;
371 break;
372 default:
373 value = -EINVAL;
374 }
375 } else {
376 value = -EINVAL;
377 }
378 return value;
379}
380
Terence Hampsonadf47302013-05-23 12:21:02 -0400381static int set_sync_copybit(struct copybit_device_t *dev,
382 int acquireFenceFd)
383{
384 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
385 if (acquireFenceFd != -1) {
386 if (ctx->sync.acq_fen_fd_cnt < (MDP_MAX_FENCE_FD - 1)) {
387 ctx->acqFence[ctx->sync.acq_fen_fd_cnt++] = acquireFenceFd;
388 } else {
389 int ret = -EINVAL;
390 struct blitReq *list = &ctx->list;
391
392 // Since fence is full kick off what is already in the list
393 ret = msm_copybit(ctx, list);
394 if (ret < 0) {
395 ALOGE("%s: Blit call failed", __FUNCTION__);
396 return -EINVAL;
397 }
398 list->count = 0;
399 ctx->sync.acq_fen_fd_cnt = 0;
400 ctx->acqFence[ctx->sync.acq_fen_fd_cnt++] = ctx->relFence;
401 ctx->acqFence[ctx->sync.acq_fen_fd_cnt++] = acquireFenceFd;
402 ctx->relFence = -1;
403 }
404 }
405 return 0;
406}
407
Naseer Ahmed29a26812012-06-14 00:56:20 -0700408/** do a stretch blit type operation */
409static int stretch_copybit(
410 struct copybit_device_t *dev,
411 struct copybit_image_t const *dst,
412 struct copybit_image_t const *src,
413 struct copybit_rect_t const *dst_rect,
414 struct copybit_rect_t const *src_rect,
415 struct copybit_region_t const *region)
416{
417 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
Terence Hampsonadf47302013-05-23 12:21:02 -0400418 struct blitReq *list;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700419 int status = 0;
420 private_handle_t *yv12_handle = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700421
Terence Hampsonadf47302013-05-23 12:21:02 -0400422 if (ctx) {
423 list = &ctx->list;
424
Naseer Ahmed29a26812012-06-14 00:56:20 -0700425 if (ctx->mAlpha < 255) {
426 switch (src->format) {
427 // we don't support plane alpha with RGBA formats
428 case HAL_PIXEL_FORMAT_RGBA_8888:
429 case HAL_PIXEL_FORMAT_BGRA_8888:
430 case HAL_PIXEL_FORMAT_RGBA_5551:
431 case HAL_PIXEL_FORMAT_RGBA_4444:
432 ALOGE ("%s : Unsupported Pixel format %d", __FUNCTION__,
433 src->format);
434 return -EINVAL;
435 }
436 }
437
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800438 if (src_rect->l < 0 || (uint32_t)src_rect->r > src->w ||
439 src_rect->t < 0 || (uint32_t)src_rect->b > src->h) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700440 // this is always invalid
441 ALOGE ("%s : Invalid source rectangle : src_rect l %d t %d r %d b %d",\
442 __FUNCTION__, src_rect->l, src_rect->t, src_rect->r, src_rect->b);
443
444 return -EINVAL;
445 }
446
447 if (src->w > MAX_DIMENSION || src->h > MAX_DIMENSION) {
448 ALOGE ("%s : Invalid source dimensions w %d h %d", __FUNCTION__, src->w, src->h);
449 return -EINVAL;
450 }
451
452 if (dst->w > MAX_DIMENSION || dst->h > MAX_DIMENSION) {
453 ALOGE ("%s : Invalid DST dimensions w %d h %d", __FUNCTION__, dst->w, dst->h);
454 return -EINVAL;
455 }
456
457 if(src->format == HAL_PIXEL_FORMAT_YV12) {
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800458 int usage =
Terence Hampson0124cc72013-04-18 23:45:56 -0700459 GRALLOC_USAGE_PRIVATE_IOMMU_HEAP | GRALLOC_USAGE_PRIVATE_UNCACHED;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700460 if (0 == alloc_buffer(&yv12_handle,src->w,src->h,
461 src->format, usage)){
462 if(0 == convertYV12toYCrCb420SP(src,yv12_handle)){
463 (const_cast<copybit_image_t *>(src))->format =
464 HAL_PIXEL_FORMAT_YCrCb_420_SP;
465 (const_cast<copybit_image_t *>(src))->handle =
466 yv12_handle;
467 (const_cast<copybit_image_t *>(src))->base =
468 (void *)yv12_handle->base;
469 }
470 else{
471 ALOGE("Error copybit conversion from yv12 failed");
472 if(yv12_handle)
473 free_buffer(yv12_handle);
474 return -EINVAL;
475 }
476 }
477 else{
478 ALOGE("Error:unable to allocate memeory for yv12 software conversion");
479 return -EINVAL;
480 }
481 }
Terence Hampsonadf47302013-05-23 12:21:02 -0400482 const uint32_t maxCount = sizeof(list->req)/sizeof(list->req[0]);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700483 const struct copybit_rect_t bounds = { 0, 0, dst->w, dst->h };
484 struct copybit_rect_t clip;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700485 status = 0;
486 while ((status == 0) && region->next(region, &clip)) {
487 intersect(&clip, &bounds, &clip);
Terence Hampsonadf47302013-05-23 12:21:02 -0400488 mdp_blit_req* req = &list->req[list->count];
Naseer Ahmed29a26812012-06-14 00:56:20 -0700489 int flags = 0;
490
491 private_handle_t* src_hnd = (private_handle_t*)src->handle;
492 if(src_hnd != NULL && src_hnd->flags & private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH) {
493 flags |= MDP_BLIT_NON_CACHED;
494 }
495
496 set_infos(ctx, req, flags);
497 set_image(&req->dst, dst);
498 set_image(&req->src, src);
499 set_rects(ctx, req, dst_rect, src_rect, &clip, src->horiz_padding, src->vert_padding);
500
501 if (req->src_rect.w<=0 || req->src_rect.h<=0)
502 continue;
503
504 if (req->dst_rect.w<=0 || req->dst_rect.h<=0)
505 continue;
506
Terence Hampsonadf47302013-05-23 12:21:02 -0400507 if (++list->count == maxCount) {
508 status = msm_copybit(ctx, list);
509 if (ctx->relFence != -1) {
510 ctx->sync.acq_fen_fd_cnt = 1;
511 ctx->sync.acq_fen_fd[0] = ctx->relFence;
512 } else {
513 ctx->sync.acq_fen_fd_cnt = 0;
514 }
515 list->count = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700516 }
517 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700518 } else {
519 ALOGE ("%s : Invalid COPYBIT context", __FUNCTION__);
520 status = -EINVAL;
521 }
522 if(yv12_handle)
523 free_buffer(yv12_handle);
524 return status;
525}
526
527/** Perform a blit type operation */
528static int blit_copybit(
529 struct copybit_device_t *dev,
530 struct copybit_image_t const *dst,
531 struct copybit_image_t const *src,
532 struct copybit_region_t const *region)
533{
534 struct copybit_rect_t dr = { 0, 0, dst->w, dst->h };
535 struct copybit_rect_t sr = { 0, 0, src->w, src->h };
536 return stretch_copybit(dev, dst, src, &dr, &sr, region);
537}
538
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800539static int finish_copybit(struct copybit_device_t *dev)
540{
541 // NOP for MDP copybit
Terence Hampson0124cc72013-04-18 23:45:56 -0700542 return 0;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800543}
544
Naseer Ahmed29a26812012-06-14 00:56:20 -0700545/*****************************************************************************/
546
547/** Close the copybit device */
548static int close_copybit(struct hw_device_t *dev)
549{
550 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
551 if (ctx) {
552 close(ctx->mFD);
553 free(ctx);
554 }
555 return 0;
556}
557
Terence Hampson0124cc72013-04-18 23:45:56 -0700558static int flush_get_fence(struct copybit_device_t *dev, int* fd)
559{
Terence Hampsonadf47302013-05-23 12:21:02 -0400560 struct copybit_context_t* ctx = (struct copybit_context_t*)dev;
561 struct blitReq *list = &ctx->list;
562 int ret = -EINVAL;
563
564 if (list->count) {
565 ret = msm_copybit(ctx, list);
566 if (ret < 0)
567 ALOGE("%s: Blit call failed", __FUNCTION__);
568 list->count = 0;
569 ctx->sync.acq_fen_fd_cnt = 0;
570 }
571 *fd = ctx->relFence;
572 ctx->relFence = -1;
573 return ret;
Terence Hampson0124cc72013-04-18 23:45:56 -0700574}
575
Naseer Ahmed29a26812012-06-14 00:56:20 -0700576/** Open a new instance of a copybit device using name */
577static int open_copybit(const struct hw_module_t* module, const char* name,
578 struct hw_device_t** device)
579{
580 int status = -EINVAL;
581 copybit_context_t *ctx;
582 ctx = (copybit_context_t *)malloc(sizeof(copybit_context_t));
583 memset(ctx, 0, sizeof(*ctx));
584
585 ctx->device.common.tag = HARDWARE_DEVICE_TAG;
586 ctx->device.common.version = 1;
587 ctx->device.common.module = const_cast<hw_module_t*>(module);
588 ctx->device.common.close = close_copybit;
589 ctx->device.set_parameter = set_parameter_copybit;
590 ctx->device.get = get;
591 ctx->device.blit = blit_copybit;
Terence Hampsonadf47302013-05-23 12:21:02 -0400592 ctx->device.set_sync = set_sync_copybit;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700593 ctx->device.stretch = stretch_copybit;
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800594 ctx->device.finish = finish_copybit;
Terence Hampson0124cc72013-04-18 23:45:56 -0700595 ctx->device.flush_get_fence = flush_get_fence;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700596 ctx->mAlpha = MDP_ALPHA_NOP;
597 ctx->mFlags = 0;
Terence Hampsonadf47302013-05-23 12:21:02 -0400598 ctx->sync.flags = 0;
599 ctx->sync.acq_fen_fd_cnt = 0;
600 ctx->sync.acq_fen_fd = ctx->acqFence;
601 ctx->sync.rel_fen_fd = &ctx->relFence;
602 ctx->list.count = 0;
603 ctx->list.sync.rel_fen_fd = ctx->sync.rel_fen_fd;
604 ctx->list.sync.acq_fen_fd = ctx->sync.acq_fen_fd;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700605 ctx->mFD = open("/dev/graphics/fb0", O_RDWR, 0);
606 if (ctx->mFD < 0) {
607 status = errno;
608 ALOGE("Error opening frame buffer errno=%d (%s)",
609 status, strerror(status));
610 status = -status;
611 } else {
Terence Hampson0124cc72013-04-18 23:45:56 -0700612 status = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700613 *device = &ctx->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700614 }
615 return status;
616}