1 /*
2 * Copyright (C) 2016 Rockchip Electronics Co., Ltd.
3 * Authors:
4 * Zhiqin Wei <wzq@rock-chips.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 #include "NormalRga.h"
19 #include "NormalRgaContext.h"
20
21 #ifdef ANDROID
22 #include "GrallocOps.h"
23 #include <cutils/properties.h>
24
25 #elif LINUX
26 #include <sys/ioctl.h>
27 #include <pthread.h>
28
29 pthread_mutex_t mMutex = PTHREAD_MUTEX_INITIALIZER;
30 #endif
31
32 #include "im2d_api/src/im2d_impl.h"
33
34 #define RGA_SRCOVER_EN 1
35
36 volatile int32_t refCount = 0;
37 struct rgaContext *rgaCtx = NULL;
38 extern struct im2d_job_manager g_im2d_job_manager;
39
is_debug_log(void)40 void is_debug_log(void) {
41 struct rgaContext *ctx = rgaCtx;
42 ctx->Is_debug = get_int_property();
43 }
44
is_out_log(void)45 int is_out_log( void ) {
46 struct rgaContext *ctx = rgaCtx;
47 return ctx->Is_debug;
48 }
49
get_int_property(void)50 int get_int_property(void) {
51 #ifdef ANDROID
52 char level[PROP_VALUE_MAX];
53 __system_property_get("vendor.rga.log" ,level);
54 #else
55 char *level = getenv("ROCKCHIP_RGA_LOG");
56 if (level == nullptr)
57 level = (char *)"0";
58 #endif
59
60 return atoi(level);
61 }
62
NormalRgaOpen(void ** context)63 int NormalRgaOpen(void **context) {
64 struct rgaContext *ctx = NULL;
65 int fd = -1;
66 int ret = 0;
67
68 if (!context) {
69 ret = -EINVAL;
70 goto mallocErr;
71 }
72
73 if (!rgaCtx) {
74 ctx = (struct rgaContext *)malloc(sizeof(struct rgaContext));
75 if(!ctx) {
76 ret = -ENOMEM;
77 ALOGE("malloc fail:%s.",strerror(errno));
78 goto mallocErr;
79 }
80
81 fd = open("/dev/rga", O_RDWR, 0);
82 if (fd < 0) {
83 ret = -ENODEV;
84 ALOGE("failed to open RGA:%s.",strerror(errno));
85 goto rgaOpenErr;
86 }
87 ctx->rgaFd = fd;
88
89 ret = ioctl(fd, RGA_IOC_GET_DRVIER_VERSION, &ctx->mDriverVersion);
90 if (ret >= 0) {
91 ret = ioctl(fd, RGA_IOC_GET_HW_VERSION, &ctx->mHwVersions);
92 if (ret < 0) {
93 ALOGE("librga fail to get hw versions!\n");
94 goto getVersionError;
95 }
96
97 /*
98 * For legacy: Because normalRGA requires a version greater
99 * than 2.0 to use rga2 normally.
100 */
101 ctx->mVersion = (float)3.2;
102
103 ctx->driver = RGA_DRIVER_IOC_MULTI_RGA;
104 } else {
105 /* Choose legacy mode. */
106 ctx->mHwVersions.size = 1;
107 /* Try to get the version of RGA2 */
108 ret = ioctl(fd, RGA2_GET_VERSION, ctx->mHwVersions.version[0].str);
109 if (ret < 0) {
110 /* Try to get the version of RGA1 */
111 ret = ioctl(fd, RGA_GET_VERSION, ctx->mHwVersions.version[0].str);
112 if (ret < 0) {
113 ALOGE("librga fail to get RGA2/RGA1 version! %s\n", strerror(ret));
114 goto getVersionError;
115 }
116 }
117
118 sscanf((char *)ctx->mHwVersions.version[0].str, "%x.%x.%x",
119 &ctx->mHwVersions.version[0].major,
120 &ctx->mHwVersions.version[0].minor,
121 &ctx->mHwVersions.version[0].revision);
122
123 ctx->mVersion = atof((char *)ctx->mHwVersions.version[0].str);
124
125 ctx->driver = RGA_DRIVER_IOC_RGA2;
126 ALOGE("librga fail to get driver version! Compatibility mode will be enabled.\n");
127 }
128
129 NormalRgaInitTables();
130
131 rgaCtx = ctx;
132 } else {
133 ctx = rgaCtx;
134 ALOGE("Had init the rga dev ctx = %p",ctx);
135 }
136
137 #ifdef ANDROID
138 android_atomic_inc(&refCount);
139 #elif LINUX
140 pthread_mutex_lock(&mMutex);
141 refCount++;
142 pthread_mutex_unlock(&mMutex);
143 #endif
144 *context = (void *)ctx;
145 return ret;
146
147 getVersionError:
148 rgaOpenErr:
149 free(ctx);
150 mallocErr:
151 return ret;
152 }
153
NormalRgaClose(void ** context)154 int NormalRgaClose(void **context) {
155 struct rgaContext *ctx = rgaCtx;
156
157 if (!ctx) {
158 ALOGE("Try to exit uninit rgaCtx=%p", ctx);
159 return -ENODEV;
160 }
161
162 if (!*context) {
163 ALOGE("Try to uninit rgaCtx=%p", *context);
164 return -ENODEV;
165 }
166
167 if (*context != ctx) {
168 ALOGE("Try to exit wrong ctx=%p",ctx);
169 return -ENODEV;
170 }
171
172 if (refCount <= 0) {
173 ALOGE("This can not be happened, close before init");
174 return 0;
175 }
176
177 #ifdef ANDROID
178 if (refCount > 0 && android_atomic_dec(&refCount) != 1)
179 return 0;
180 #elif LINUX
181 pthread_mutex_lock(&mMutex);
182 refCount--;
183
184 if (refCount < 0) {
185 refCount = 0;
186 pthread_mutex_unlock(&mMutex);
187 return 0;
188 }
189
190 if (refCount > 0)
191 {
192 pthread_mutex_unlock(&mMutex);
193 return 0;
194 }
195
196 pthread_mutex_unlock(&mMutex);
197 #endif
198
199 rgaCtx = NULL;
200 *context = NULL;
201
202 close(ctx->rgaFd);
203
204 free(ctx);
205
206 return 0;
207 }
208
RgaInit(void ** ctx)209 int RgaInit(void **ctx) {
210 int ret = 0;
211 ret = NormalRgaOpen(ctx);
212 if (ret < 0)
213 return ret;
214
215 /* check driver version. */
216 ret = rga_check_driver(rgaCtx->mDriverVersion);
217 if (ret == IM_STATUS_ERROR_VERSION)
218 return -1;
219
220 return ret;
221 }
222
RgaDeInit(void ** ctx)223 int RgaDeInit(void **ctx) {
224 int ret = 0;
225 ret = NormalRgaClose(ctx);
226 return ret;
227 }
228
229 #ifdef ANDROID
NormalRgaPaletteTable(buffer_handle_t dst,unsigned int v,drm_rga_t * rects)230 int NormalRgaPaletteTable(buffer_handle_t dst,
231 unsigned int v, drm_rga_t *rects) {
232 //check rects
233 //check buffer_handle_t with rects
234 struct rgaContext *ctx = rgaCtx;
235 int srcVirW,srcVirH,srcActW,srcActH,srcXPos,srcYPos;
236 int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
237 int srcType,dstType,srcMmuFlag,dstMmuFlag;
238 int dstFd = -1;
239 int ret = 0;
240 drm_rga_t tmpRects,relRects;
241 struct rga_req rgaReg;
242 void *srcBuf = NULL;
243 void *dstBuf = NULL;
244 RECT clip;
245
246 if (!ctx) {
247 ALOGE("Try to use uninit rgaCtx=%p",ctx);
248 return -ENODEV;
249 }
250
251 if (rects && (ctx->mLogAlways || ctx->mLogOnce)) {
252 ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
253 rects->src.xoffset,rects->src.yoffset,
254 rects->src.width, rects->src.height,
255 rects->src.wstride,rects->src.format, rects->src.size,
256 rects->dst.xoffset,rects->dst.yoffset,
257 rects->dst.width, rects->dst.height,
258 rects->dst.wstride,rects->dst.format, rects->dst.size);
259 }
260
261 memset(&rgaReg, 0, sizeof(struct rga_req));
262
263 srcType = dstType = srcMmuFlag = dstMmuFlag = 0;
264
265 ret = NormalRgaGetRects(NULL, dst, &srcType, &dstType, &tmpRects);
266 if (ret && !rects) {
267 ALOGE("%d:Has not rects for render", __LINE__);
268 return ret;
269 }
270
271 if (rects) {
272 if (rects->src.wstride > 0 && rects->dst.wstride > 0)
273 memcpy(&relRects, rects, sizeof(drm_rga_t));
274 else if (rects->src.wstride > 0) {
275 memcpy(&(relRects.src), &(rects->src), sizeof(rga_rect_t));
276 memcpy(&(relRects.dst), &(tmpRects.dst), sizeof(rga_rect_t));
277 } else if (rects->dst.wstride > 0) {
278 memcpy(&(relRects.src), &(tmpRects.src), sizeof(rga_rect_t));
279 memcpy(&(relRects.dst), &(rects->dst), sizeof(rga_rect_t));
280 }
281 } else
282 memcpy(&relRects, &tmpRects, sizeof(drm_rga_t));
283
284 if (ctx->mLogAlways || ctx->mLogOnce) {
285 ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
286 tmpRects.src.xoffset,tmpRects.src.yoffset,
287 tmpRects.src.width, tmpRects.src.height,
288 tmpRects.src.wstride,tmpRects.src.format, tmpRects.src.size,
289 tmpRects.dst.xoffset,tmpRects.dst.yoffset,
290 tmpRects.dst.width, tmpRects.dst.height,
291 tmpRects.dst.wstride,tmpRects.dst.format, tmpRects.dst.size);
292 ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
293 relRects.src.xoffset,relRects.src.yoffset,
294 relRects.src.width, relRects.src.height,
295 relRects.src.wstride,relRects.src.format, relRects.src.size,
296 relRects.dst.xoffset,relRects.dst.yoffset,
297 relRects.dst.width, relRects.dst.height,
298 relRects.dst.wstride,relRects.dst.format, relRects.dst.size);
299 }
300
301 RkRgaGetHandleMapAddress(dst, &dstBuf);
302 RkRgaGetHandleFd(dst, &dstFd);
303 if (dstFd == -1 && !dstBuf) {
304 ALOGE("%d:dst has not fd and address for render", __LINE__);
305 return ret;
306 }
307
308 if (dstFd == 0 && !dstBuf) {
309 ALOGE("dstFd is zero, now driver not support");
310 return -EINVAL;
311 } else
312 dstFd = -1;
313
314 srcVirW = relRects.src.wstride;
315 srcVirH = relRects.src.height;
316 srcXPos = relRects.src.xoffset;
317 srcYPos = relRects.src.yoffset;
318 srcActW = relRects.src.width;
319 srcActH = relRects.src.height;
320
321 dstVirW = relRects.dst.wstride;
322 dstVirH = relRects.dst.height;
323 dstXPos = relRects.dst.xoffset;
324 dstYPos = relRects.dst.yoffset;
325 dstActW = relRects.dst.width;
326 dstActH = relRects.dst.height;
327
328 NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
329 NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
330 NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
331 (unsigned long)srcBuf + srcVirW * srcVirH,
332 (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
333 srcVirW, srcVirH,
334 RkRgaGetRgaFormat(relRects.src.format),0);
335 /*dst*/
336 NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
337 (unsigned long)dstBuf + dstVirW * dstVirH,
338 (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
339 dstVirW, dstVirH, &clip,
340 RkRgaGetRgaFormat(relRects.dst.format),0);
341 NormalRgaSetPatInfo(&rgaReg, dstVirW, dstVirH,
342 dstXPos, dstYPos, relRects.dst.format);
343 NormalRgaSetFadingEnInfo(&rgaReg, v & 0xFF000000, v & 0xFF0000, v & 0xFF00);
344
345 /*mode*/
346 NormalRgaUpdatePaletteTableMode(&rgaReg, 0, v & 0xFF);
347
348 if (srcMmuFlag || dstMmuFlag) {
349 NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
350 NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
351 }
352
353 if (ctx->mLogAlways || ctx->mLogOnce)
354 NormalRgaLogOutRgaReq(rgaReg);
355
356 if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
357 printf(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
358 ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
359 }
360
361 if (ctx->mLogOnce)
362 ctx->mLogOnce = 0;
363
364 return 0;
365 }
366 #endif
367
RgaBlit(rga_info * src,rga_info * dst,rga_info * src1)368 int RgaBlit(rga_info *src, rga_info *dst, rga_info *src1) {
369 //check rects
370 //check buffer_handle_t with rects
371 struct rgaContext *ctx = rgaCtx;
372 int srcVirW,srcVirH,srcActW,srcActH,srcXPos,srcYPos;
373 int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
374 int src1VirW,src1VirH,src1ActW,src1ActH,src1XPos,src1YPos;
375 int scaleMode,rotateMode,orientation,ditherEn;
376 int srcType,dstType,src1Type,srcMmuFlag,dstMmuFlag,src1MmuFlag;
377 int planeAlpha;
378 int dstFd = -1;
379 int srcFd = -1;
380 int src1Fd = -1;
381 int rotation;
382 int stretch = 0;
383 float hScale = 1;
384 float vScale = 1;
385 int ret = 0;
386 rga_rect_t relSrcRect,tmpSrcRect,relDstRect,tmpDstRect;
387 rga_rect_t relSrc1Rect,tmpSrc1Rect;
388 struct rga_req rgaReg,tmprgaReg;
389 unsigned int blend;
390 unsigned int yuvToRgbMode;
391 bool perpixelAlpha = 0;
392 void *srcBuf = NULL;
393 void *dstBuf = NULL;
394 void *src1Buf = NULL;
395 RECT clip;
396 int sync_mode = RGA_BLIT_SYNC;
397
398 //init context
399 if (!ctx) {
400 ALOGE("Try to use uninit rgaCtx=%p",ctx);
401 return -ENODEV;
402 }
403
404 //init
405 memset(&rgaReg, 0, sizeof(struct rga_req));
406
407 srcType = dstType = srcMmuFlag = dstMmuFlag = 0;
408 src1Type = src1MmuFlag = 0;
409 rotation = 0;
410 blend = 0;
411 yuvToRgbMode = 0;
412
413 /* print debug log by setting property vendor.rga.log as 1 */
414 is_debug_log();
415 if(is_out_log())
416 ALOGD("<<<<-------- print rgaLog -------->>>>");
417
418 if (!src && !dst && !src1) {
419 ALOGE("src = %p, dst = %p, src1 = %p", src, dst, src1);
420 return -EINVAL;
421 }
422
423 if (!src && !dst) {
424 ALOGE("src = %p, dst = %p", src, dst);
425 return -EINVAL;
426 }
427
428 /*
429 * 1.if src exist, get some parameter from src, such as rotatiom.
430 * 2.if need to blend, need blend variable from src to decide how to blend.
431 * 3.get effective area from src, if the area is empty, choose to get parameter from handle.
432 * */
433 if (src) {
434 rotation = src->rotation;
435 blend = src->blend;
436 memcpy(&relSrcRect, &src->rect, sizeof(rga_rect_t));
437 }
438
439 /* get effective area from dst and src1, if the area is empty, choose to get parameter from handle. */
440 if (dst)
441 memcpy(&relDstRect, &dst->rect, sizeof(rga_rect_t));
442 if (src1)
443 memcpy(&relSrc1Rect, &src1->rect, sizeof(rga_rect_t));
444
445 srcFd = dstFd = src1Fd = -1;
446
447 if (is_out_log()) {
448 ALOGD("src->hnd = 0x%lx , dst->hnd = 0x%lx , src1->hnd = 0x%lx\n",
449 (unsigned long)src->hnd, (unsigned long)dst->hnd, (unsigned long)(src1 ? src1->hnd : 0));
450 ALOGD("src: handle = %d, Fd = %.2d ,phyAddr = %p ,virAddr = %p\n", src->handle, src->fd, src->phyAddr, src->virAddr);
451 if (src1)
452 ALOGD("src1: handle = %d, Fd = %.2d , phyAddr = %p , virAddr = %p\n", src1->handle, src1->fd, src1->phyAddr, src1->virAddr);
453 ALOGD("dst: handle = %d, Fd = %.2d ,phyAddr = %p ,virAddr = %p\n", dst->handle, dst->fd, dst->phyAddr, dst->virAddr);
454 }
455
456 if (src1) {
457 if (src->handle > 0 && dst->handle > 0 && src1->handle > 0) {
458 /* This will mark the use of handle */
459 rgaReg.handle_flag |= 1;
460 } else if ((src->handle > 0 || dst->handle > 0 || src1->handle > 0) &&
461 (src->handle <= 0 || dst->handle <= 0 || src1->handle <= 0)) {
462 ALOGE("librga only supports the use of handles only or no handles, [src,src1,dst] = [%d, %d, %d]\n",
463 src->handle, src1->handle, dst->handle);
464 return -EINVAL;
465 }
466 } else {
467 if (src->handle > 0 && dst->handle > 0) {
468 /* This will mark the use of handle */
469 rgaReg.handle_flag |= 1;
470 } else if ((src->handle > 0 || dst->handle > 0) &&
471 (src->handle <= 0 || dst->handle <= 0)) {
472 ALOGE("librga only supports the use of handles only or no handles, [src,dst] = [%d, %d]\n",
473 src->handle, dst->handle);
474 return -EINVAL;
475 }
476 }
477
478 /*********** get src addr *************/
479 if (src && src->handle) {
480 /* In order to minimize changes, the handle here will reuse the variable of Fd. */
481 srcFd = src->handle;
482 } else if (src && src->phyAddr) {
483 srcBuf = src->phyAddr;
484 } else if (src && src->fd > 0) {
485 srcFd = src->fd;
486 src->mmuFlag = 1;
487 } else if (src && src->virAddr) {
488 srcBuf = src->virAddr;
489 src->mmuFlag = 1;
490 }
491 /*
492 * After getting the fd or virtual address through the handle,
493 * set 'srcType' to 1, and at the end, and then judge
494 * the 'srcType' at the end whether to enable mmu.
495 */
496 #ifdef ANDROID
497 else if (src && src->hnd) {
498 #ifndef RK3188
499 /* RK3188 is special, cannot configure rga through fd. */
500 RkRgaGetHandleFd(src->hnd, &srcFd);
501 #endif
502 #ifndef ANDROID_8
503 if (srcFd < 0 || srcFd == 0) {
504 RkRgaGetHandleMapAddress(src->hnd, &srcBuf);
505 }
506 #endif
507 if ((srcFd < 0 || srcFd == 0) && srcBuf == NULL) {
508 ALOGE("src handle get fd and vir_addr fail ret = %d,hnd=%p", ret, &src->hnd);
509 printf("src handle get fd and vir_addr fail ret = %d,hnd=%p", ret, &src->hnd);
510 return ret;
511 }
512 else {
513 srcType = 1;
514 }
515 }
516
517 if (!isRectValid(relSrcRect)) {
518 ret = NormalRgaGetRect(src->hnd, &tmpSrcRect);
519 if (ret) {
520 ALOGE("dst handleGetRect fail ,ret = %d,hnd=%p", ret, &src->hnd);
521 printf("dst handleGetRect fail ,ret = %d,hnd=%p", ret, &src->hnd);
522 return ret;
523 }
524 memcpy(&relSrcRect, &tmpSrcRect, sizeof(rga_rect_t));
525 }
526 #endif
527 if (srcFd == -1 && !srcBuf) {
528 ALOGE("%d:src has not fd and address for render", __LINE__);
529 return ret;
530 }
531 if (srcFd == 0 && !srcBuf) {
532 ALOGE("srcFd is zero, now driver not support");
533 return -EINVAL;
534 }
535 /* Old rga driver cannot support fd as zero. */
536 if (srcFd == 0)
537 srcFd = -1;
538
539 /*********** get src1 addr *************/
540 if (src1) {
541 if (src1->handle) {
542 /* In order to minimize changes, the handle here will reuse the variable of Fd. */
543 src1Fd = src1->handle;
544 } else if (src1->phyAddr) {
545 src1Buf = src1->phyAddr;
546 } else if (src1->fd > 0) {
547 src1Fd = src1->fd;
548 src1->mmuFlag = 1;
549 } else if (src1->virAddr) {
550 src1Buf = src1->virAddr;
551 src1->mmuFlag = 1;
552 }
553 /*
554 * After getting the fd or virtual address through the handle,
555 * set 'src1Type' to 1, and at the end, and then judge
556 * the 'src1Type' at the end whether to enable mmu.
557 */
558 #ifdef ANDROID
559 else if (src1->hnd) {
560 #ifndef RK3188
561 /* RK3188 is special, cannot configure rga through fd. */
562 RkRgaGetHandleFd(src1->hnd, &src1Fd);
563 #endif
564 #ifndef ANDROID_8
565 if (src1Fd < 0 || src1Fd == 0) {
566 RkRgaGetHandleMapAddress(src1->hnd, &src1Buf);
567 }
568 #endif
569 if ((src1Fd < 0 || src1Fd == 0) && src1Buf == NULL) {
570 ALOGE("src1 handle get fd and vir_addr fail ret = %d,hnd=%p", ret, &src1->hnd);
571 printf("src1 handle get fd and vir_addr fail ret = %d,hnd=%p", ret, &src1->hnd);
572 return ret;
573 }
574 else {
575 src1Type = 1;
576 }
577 }
578
579 if (!isRectValid(relSrc1Rect)) {
580 ret = NormalRgaGetRect(src1->hnd, &tmpSrc1Rect);
581 if (ret) {
582 ALOGE("src1 handleGetRect fail ,ret = %d,hnd=%p", ret, &src1->hnd);
583 printf("src1 handleGetRect fail ,ret = %d,hnd=%p", ret, &src1->hnd);
584 return ret;
585 }
586 memcpy(&relSrc1Rect, &tmpSrc1Rect, sizeof(rga_rect_t));
587 }
588 #endif
589 if (src1Fd == -1 && !src1Buf) {
590 ALOGE("%d:src1 has not fd and address for render", __LINE__);
591 return ret;
592 }
593 if (src1Fd == 0 && !src1Buf) {
594 ALOGE("src1Fd is zero, now driver not support");
595 return -EINVAL;
596 }
597 /* Old rga driver cannot support fd as zero. */
598 if (src1Fd == 0)
599 src1Fd = -1;
600 }
601
602 /*********** get dst addr *************/
603 if (dst && dst->handle) {
604 /* In order to minimize changes, the handle here will reuse the variable of Fd. */
605 dstFd = dst->handle;
606 } else if (dst && dst->phyAddr) {
607 dstBuf = dst->phyAddr;
608 } else if (dst && dst->fd > 0) {
609 dstFd = dst->fd;
610 dst->mmuFlag = 1;
611 } else if (dst && dst->virAddr) {
612 dstBuf = dst->virAddr;
613 dst->mmuFlag = 1;
614 }
615 /*
616 * After getting the fd or virtual address through the handle,
617 * set 'dstType' to 1, and at the end, and then judge
618 * the 'dstType' at the end whether to enable mmu.
619 */
620 #ifdef ANDROID
621 else if (dst && dst->hnd) {
622 #ifndef RK3188
623 /* RK3188 is special, cannot configure rga through fd. */
624 RkRgaGetHandleFd(dst->hnd, &dstFd);
625 #endif
626 #ifndef ANDROID_8
627 if (dstFd < 0 || dstFd == 0) {
628 RkRgaGetHandleMapAddress(dst->hnd, &dstBuf);
629 }
630 #endif
631 if ((dstFd < 0 || dstFd == 0) && dstBuf == NULL) {
632 ALOGE("dst handle get fd and vir_addr fail ret = %d,hnd=%p", ret, &dst->hnd);
633 printf("dst handle get fd and vir_addr fail ret = %d,hnd=%p", ret, &dst->hnd);
634 return ret;
635 }
636 else {
637 dstType = 1;
638 }
639 }
640
641 if (!isRectValid(relDstRect)) {
642 ret = NormalRgaGetRect(dst->hnd, &tmpDstRect);
643 if (ret) {
644 ALOGE("dst handleGetRect fail ,ret = %d,hnd=%p", ret, &dst->hnd);
645 printf("dst handleGetRect fail ,ret = %d,hnd=%p", ret, &dst->hnd);
646 return ret;
647 }
648 memcpy(&relDstRect, &tmpDstRect, sizeof(rga_rect_t));
649 }
650 #endif
651
652 if (dstFd == -1 && !dstBuf) {
653 ALOGE("%d:dst has not fd and address for render", __LINE__);
654 return ret;
655 }
656 if (dstFd == 0 && !dstBuf) {
657 ALOGE("dstFd is zero, now driver not support");
658 return -EINVAL;
659 }
660 /* Old rga driver cannot support fd as zero. */
661 if (dstFd == 0)
662 dstFd = -1;
663
664 if(is_out_log()) {
665 ALOGD("handle_flag: 0x%x\n", rgaReg.handle_flag);
666 ALOGD("src: Fd/handle = %.2d , buf = %p, mmuFlag = %d, mmuType = %d\n", srcFd, srcBuf, src->mmuFlag, srcType);
667 if (src1)
668 ALOGD("src1: Fd/handle = %.2d , buf = %p, mmuFlag = %d, mmuType = %d\n", src1Fd, src1Buf, src1->mmuFlag, src1Type);
669 ALOGD("dst: Fd/handle = %.2d , buf = %p, mmuFlag = %d, mmuType = %d\n", dstFd, dstBuf, dst->mmuFlag, dstType);
670 }
671
672 relSrcRect.format = RkRgaCompatibleFormat(relSrcRect.format);
673 relDstRect.format = RkRgaCompatibleFormat(relDstRect.format);
674 if (isRectValid(relSrc1Rect))
675 relSrc1Rect.format = RkRgaCompatibleFormat(relSrc1Rect.format);
676
677 #ifdef RK3126C
678 if ( (relSrcRect.width == relDstRect.width) && (relSrcRect.height == relDstRect.height ) &&
679 (relSrcRect.width + 2*relSrcRect.xoffset == relSrcRect.wstride) &&
680 (relSrcRect.height + 2*relSrcRect.yoffset == relSrcRect.hstride) &&
681 (relSrcRect.format == HAL_PIXEL_FORMAT_YCrCb_NV12) && (relSrcRect.xoffset > 0 && relSrcRect.yoffset > 0)
682 ) {
683 relSrcRect.width += 4;
684 //relSrcRect.height += 4;
685 relSrcRect.xoffset = (relSrcRect.wstride - relSrcRect.width) / 2;
686 }
687 #endif
688
689 /* blend bit[16:23] is to set global alpha. */
690 planeAlpha = (blend & 0xFF0000) >> 16;
691
692 /* determined by format, need pixel alpha or not. */
693 perpixelAlpha = NormalRgaFormatHasAlpha(RkRgaGetRgaFormat(relSrcRect.format));
694
695 if(is_out_log())
696 ALOGE("blend = %x , perpixelAlpha = %d",blend,perpixelAlpha);
697
698 /* blend bit[0:15] is to set which way to blend,such as whether need glabal alpha,and so on. */
699 switch ((blend & 0xFFFF)) {
700 case 0x0001:/* src */
701 NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 1, 1, 0);
702 break;
703
704 case 0x0002:/* dst */
705 NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 1, 2, 0);
706 break;
707
708 case 0x0105:/* src over , no need to Premultiplied. */
709 if (perpixelAlpha && planeAlpha < 255) {
710 NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha, 1, 9, 0);
711 } else if (perpixelAlpha)
712 NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 1, 3, 0);
713 else
714 NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha, 0, 0, 0);
715 break;
716
717 case 0x0405:/* src over , need to Premultiplied. */
718 if (perpixelAlpha && planeAlpha < 255)
719 NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha, 1, 9, 0);
720 else if (perpixelAlpha)
721 NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 1, 3, 0);
722 else
723 NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha, 0, 0, 0);
724
725 rgaReg.alpha_rop_flag |= (1 << 9); //real color mode
726
727 break;
728
729 case 0x0501:/* dst over , no need premultiplied. */
730 if (perpixelAlpha && planeAlpha < 255)
731 NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 1, 4, 0);
732 else if (perpixelAlpha)
733 NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, planeAlpha , 1, 4, 0);
734 else
735 NormalRgaSetAlphaEnInfo(&rgaReg, 1, 3, planeAlpha , 1, 4, 0);
736 break;
737
738 case 0x0504:/* dst over, need premultiplied. */
739 if (perpixelAlpha && planeAlpha < 255)
740 NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 1, 4, 0);
741 else if (perpixelAlpha)
742 NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, planeAlpha , 1, 4, 0);
743 else
744 NormalRgaSetAlphaEnInfo(&rgaReg, 1, 3, planeAlpha , 1, 4, 0);
745
746 rgaReg.alpha_rop_flag |= (1 << 9); //real color mode
747 break;
748
749 case 0x0100:
750 default:
751 /* Tips: BLENDING_NONE is non-zero value, handle zero value as
752 * BLENDING_NONE. */
753 /* C = Cs
754 * A = As */
755 break;
756 }
757
758 /* discripe a picture need high stride.If high stride not to be set, need use height as high stride. */
759 if (relSrcRect.hstride == 0)
760 relSrcRect.hstride = relSrcRect.height;
761
762 if (isRectValid(relSrc1Rect))
763 if (relSrc1Rect.hstride == 0)
764 relSrc1Rect.hstride = relSrc1Rect.height;
765
766 if (relDstRect.hstride == 0)
767 relDstRect.hstride = relDstRect.height;
768
769 /* do some check, check the area of src and dst whether is effective. */
770 if (src) {
771 ret = checkRectForRga(relSrcRect);
772 if (ret) {
773 printf("Error srcRect\n");
774 ALOGE("[%s,%d]Error srcRect \n", __func__, __LINE__);
775 return ret;
776 }
777 }
778
779 if (src1) {
780 ret = checkRectForRga(relSrc1Rect);
781 if (ret) {
782 printf("Error src1Rect\n");
783 ALOGE("[%s,%d]Error src1Rect \n", __func__, __LINE__);
784 return ret;
785 }
786 }
787
788 if (dst) {
789 ret = checkRectForRga(relDstRect);
790 if (ret) {
791 printf("Error dstRect\n");
792 ALOGE("[%s,%d]Error dstRect \n", __func__, __LINE__);
793 return ret;
794 }
795 }
796
797 /* check the scale magnification. */
798 if (src1 && src) {
799 hScale = (float)relSrcRect.width / relSrc1Rect.width;
800 vScale = (float)relSrcRect.height / relSrc1Rect.height;
801 if (rotation == HAL_TRANSFORM_ROT_90 || rotation == HAL_TRANSFORM_ROT_270) {
802 hScale = (float)relSrcRect.width / relSrc1Rect.height;
803 vScale = (float)relSrcRect.height / relSrc1Rect.width;
804 }
805 // check scale limit form low to high version, gradually strict, avoid invalid jugdement
806 if (ctx->mVersion <= 1.003 && (hScale < 1/2 || vScale < 1/2)) {
807 ALOGE("e scale[%f,%f] ver[%f]", hScale, vScale, ctx->mVersion);
808 return -EINVAL;
809 }
810 if (ctx->mVersion <= 2.0 && (hScale < 1/8 ||
811 hScale > 8 || vScale < 1/8 || vScale > 8)) {
812 ALOGE("Error scale[%f,%f] line %d", hScale, vScale, __LINE__);
813 return -EINVAL;
814 }
815 if (hScale < 1/16 || hScale > 16 || vScale < 1/16 || vScale > 16) {
816 ALOGE("Error scale[%f,%f] line %d", hScale, vScale, __LINE__);
817 return -EINVAL;
818 }
819
820 } else if (src && dst) {
821 hScale = (float)relSrcRect.width / relDstRect.width;
822 vScale = (float)relSrcRect.height / relDstRect.height;
823 if (rotation == HAL_TRANSFORM_ROT_90 || rotation == HAL_TRANSFORM_ROT_270) {
824 hScale = (float)relSrcRect.width / relDstRect.height;
825 vScale = (float)relSrcRect.height / relDstRect.width;
826 }
827 if (hScale < 1.0/16 || hScale > 16 || vScale < 1.0/16 || vScale > 16) {
828 ALOGE("Error scale[%f,%f] line %d", hScale, vScale, __LINE__);
829 return -EINVAL;
830 }
831 if (ctx->mVersion < 2.0 && (hScale < 1.0/8 ||
832 hScale > 8 || vScale < 1.0/8 || vScale > 8)) {
833 ALOGE("Error scale[%f,%f] line %d", hScale, vScale, __LINE__);
834 return -EINVAL;
835 }
836 if (ctx->mVersion <= 1.003 && (hScale < 1.0/2 || vScale < 1.0/2)) {
837 ALOGE("e scale[%f,%f] ver[%f]", hScale, vScale, ctx->mVersion);
838 return -EINVAL;
839 }
840 }
841
842 /* reselect the scale mode. */
843 scaleMode = 0;
844 stretch = (hScale != 1.0f) || (vScale != 1.0f);
845 /* scale up use bicubic */
846 if (hScale < 1 || vScale < 1) {
847 #ifdef ANDROID
848 if((src->format == HAL_PIXEL_FORMAT_RGBA_8888 ||src->format == HAL_PIXEL_FORMAT_BGRA_8888))
849 #elif LINUX
850 if((relSrcRect.format == RK_FORMAT_RGBA_8888 || relSrcRect.format == RK_FORMAT_BGRA_8888))
851 #endif
852 scaleMode = 0; // force change scale_mode to 0 ,for rga not support
853 }
854
855 if(is_out_log())
856 ALOGD("scaleMode = %d , stretch = %d;",scaleMode,stretch);
857
858 /*
859 * according to the rotation to set corresponding parameter.It's diffrient from the opengl.
860 * Following's config which use frequently
861 * */
862 switch (rotation & 0x0f) {
863 case HAL_TRANSFORM_FLIP_H:
864 orientation = 0;
865 rotateMode = 2;
866 srcVirW = relSrcRect.wstride;
867 srcVirH = relSrcRect.hstride;
868 srcXPos = relSrcRect.xoffset;
869 srcYPos = relSrcRect.yoffset;
870 srcActW = relSrcRect.width;
871 srcActH = relSrcRect.height;
872
873 src1VirW = relSrc1Rect.wstride;
874 src1VirH = relSrc1Rect.hstride;
875 src1XPos = relSrc1Rect.xoffset;
876 src1YPos = relSrc1Rect.yoffset;
877 src1ActW = relSrc1Rect.width;
878 src1ActH = relSrc1Rect.height;
879
880 dstVirW = relDstRect.wstride;
881 dstVirH = relDstRect.hstride;
882 dstXPos = relDstRect.xoffset;
883 dstYPos = relDstRect.yoffset;
884 dstActW = relDstRect.width;
885 dstActH = relDstRect.height;
886 break;
887 case HAL_TRANSFORM_FLIP_V:
888 orientation = 0;
889 rotateMode = 3;
890 srcVirW = relSrcRect.wstride;
891 srcVirH = relSrcRect.hstride;
892 srcXPos = relSrcRect.xoffset;
893 srcYPos = relSrcRect.yoffset;
894 srcActW = relSrcRect.width;
895 srcActH = relSrcRect.height;
896
897 src1VirW = relSrc1Rect.wstride;
898 src1VirH = relSrc1Rect.hstride;
899 src1XPos = relSrc1Rect.xoffset;
900 src1YPos = relSrc1Rect.yoffset;
901 src1ActW = relSrc1Rect.width;
902 src1ActH = relSrc1Rect.height;
903
904 dstVirW = relDstRect.wstride;
905 dstVirH = relDstRect.hstride;
906 dstXPos = relDstRect.xoffset;
907 dstYPos = relDstRect.yoffset;
908 dstActW = relDstRect.width;
909 dstActH = relDstRect.height;
910 break;
911 case HAL_TRANSFORM_FLIP_H_V:
912 orientation = 0;
913 rotateMode = 4;
914 srcVirW = relSrcRect.wstride;
915 srcVirH = relSrcRect.hstride;
916 srcXPos = relSrcRect.xoffset;
917 srcYPos = relSrcRect.yoffset;
918 srcActW = relSrcRect.width;
919 srcActH = relSrcRect.height;
920
921 src1VirW = relSrc1Rect.wstride;
922 src1VirH = relSrc1Rect.hstride;
923 src1XPos = relSrc1Rect.xoffset;
924 src1YPos = relSrc1Rect.yoffset;
925 src1ActW = relSrc1Rect.width;
926 src1ActH = relSrc1Rect.height;
927
928 dstVirW = relDstRect.wstride;
929 dstVirH = relDstRect.hstride;
930 dstXPos = relDstRect.xoffset;
931 dstYPos = relDstRect.yoffset;
932 dstActW = relDstRect.width;
933 dstActH = relDstRect.height;
934 break;
935 case HAL_TRANSFORM_ROT_90:
936 orientation = 90;
937 rotateMode = 1;
938 srcVirW = relSrcRect.wstride;
939 srcVirH = relSrcRect.hstride;
940 srcXPos = relSrcRect.xoffset;
941 srcYPos = relSrcRect.yoffset;
942 srcActW = relSrcRect.width;
943 srcActH = relSrcRect.height;
944
945 src1VirW = relSrc1Rect.wstride;
946 src1VirH = relSrc1Rect.hstride;
947 src1XPos = relSrc1Rect.xoffset;
948 src1YPos = relSrc1Rect.yoffset;
949 src1ActW = relSrc1Rect.height;
950 src1ActH = relSrc1Rect.width;
951
952 dstVirW = relDstRect.wstride;
953 dstVirH = relDstRect.hstride;
954 dstXPos = relDstRect.xoffset;
955 dstYPos = relDstRect.yoffset;
956 dstActW = relDstRect.height;
957 dstActH = relDstRect.width;
958 break;
959 case HAL_TRANSFORM_ROT_180:
960 orientation = 180;
961 rotateMode = 1;
962 srcVirW = relSrcRect.wstride;
963 srcVirH = relSrcRect.hstride;
964 srcXPos = relSrcRect.xoffset;
965 srcYPos = relSrcRect.yoffset;
966 srcActW = relSrcRect.width;
967 srcActH = relSrcRect.height;
968
969 src1VirW = relSrc1Rect.wstride;
970 src1VirH = relSrc1Rect.hstride;
971 src1XPos = relSrc1Rect.xoffset;
972 src1YPos = relSrc1Rect.yoffset;
973 src1ActW = relSrc1Rect.width;
974 src1ActH = relSrc1Rect.height;
975
976 dstVirW = relDstRect.wstride;
977 dstVirH = relDstRect.hstride;
978 dstXPos = relDstRect.xoffset;
979 dstYPos = relDstRect.yoffset;
980 dstActW = relDstRect.width;
981 dstActH = relDstRect.height;
982 break;
983 case HAL_TRANSFORM_ROT_270:
984 orientation = 270;
985 rotateMode = 1;
986 srcVirW = relSrcRect.wstride;
987 srcVirH = relSrcRect.hstride;
988 srcXPos = relSrcRect.xoffset;
989 srcYPos = relSrcRect.yoffset;
990 srcActW = relSrcRect.width;
991 srcActH = relSrcRect.height;
992
993 src1VirW = relSrc1Rect.wstride;
994 src1VirH = relSrc1Rect.hstride;
995 src1XPos = relSrc1Rect.xoffset;
996 src1YPos = relSrc1Rect.yoffset;
997 src1ActW = relSrc1Rect.height;
998 src1ActH = relSrc1Rect.width;
999
1000 dstVirW = relDstRect.wstride;
1001 dstVirH = relDstRect.hstride;
1002 dstXPos = relDstRect.xoffset;
1003 dstYPos = relDstRect.yoffset;
1004 dstActW = relDstRect.height;
1005 dstActH = relDstRect.width;
1006 break;
1007 default:
1008 orientation = 0;
1009 rotateMode = stretch;
1010 srcVirW = relSrcRect.wstride;
1011 srcVirH = relSrcRect.hstride;
1012 srcXPos = relSrcRect.xoffset;
1013 srcYPos = relSrcRect.yoffset;
1014 srcActW = relSrcRect.width;
1015 srcActH = relSrcRect.height;
1016
1017 src1VirW = relSrc1Rect.wstride;
1018 src1VirH = relSrc1Rect.hstride;
1019 src1XPos = relSrc1Rect.xoffset;
1020 src1YPos = relSrc1Rect.yoffset;
1021 src1ActW = relSrc1Rect.width;
1022 src1ActH = relSrc1Rect.height;
1023
1024 dstVirW = relDstRect.wstride;
1025 dstVirH = relDstRect.hstride;
1026 dstXPos = relDstRect.xoffset;
1027 dstYPos = relDstRect.yoffset;
1028 dstActW = relDstRect.width;
1029 dstActH = relDstRect.height;
1030 break;
1031 }
1032
1033 switch ((rotation & 0xF0) >> 4) {
1034 case HAL_TRANSFORM_FLIP_H :
1035 rotateMode |= (2 << 4);
1036 break;
1037 case HAL_TRANSFORM_FLIP_V :
1038 rotateMode |= (3 << 4);
1039 break;
1040 case HAL_TRANSFORM_FLIP_H_V:
1041 rotateMode |= (4 << 4);
1042 break;
1043 }
1044
1045 /* if pictual out of range should be cliped. */
1046 clip.xmin = 0;
1047 clip.xmax = dstVirW - 1;
1048 clip.ymin = 0;
1049 clip.ymax = dstVirH - 1;
1050
1051 if (NormalRgaIsRgbFormat(RkRgaGetRgaFormat(relSrcRect.format)) &&
1052 (RkRgaGetRgaFormat(relSrcRect.format) != RK_FORMAT_RGB_565 ||
1053 RkRgaGetRgaFormat(relSrcRect.format) != RK_FORMAT_BGR_565) &&
1054 (RkRgaGetRgaFormat(relDstRect.format) == RK_FORMAT_RGB_565 ||
1055 RkRgaGetRgaFormat(relDstRect.format) == RK_FORMAT_BGR_565))
1056 ditherEn = 1;
1057 else
1058 ditherEn = 0;
1059
1060 #if 0
1061 /* YUV HDS or VDS enable */
1062 if (NormalRgaIsYuvFormat(relDstRect.format)) {
1063 rgaReg.uvhds_mode = 1;
1064 if ((relDstRect.format == RK_FORMAT_YCbCr_420_SP ||
1065 relDstRect.format == RK_FORMAT_YCrCb_420_SP) &&
1066 rotation == 0 && hScale == 1.0f && vScale == 1.0f) {
1067 /* YUV420SP only support vds when without rotation and scale. */
1068 rgaReg.uvvds_mode = 1;
1069 }
1070 }
1071 #endif
1072
1073 if(is_out_log())
1074 ALOGE("rgaVersion = %lf , ditherEn =%d ",ctx->mVersion,ditherEn);
1075
1076 /* only to configure the parameter by driver version, because rga driver has too many version. */
1077 if (ctx->mVersion <= (float)1.003) {
1078 srcMmuFlag = dstMmuFlag = src1MmuFlag = 1;
1079
1080 #if defined(__arm64__) || defined(__aarch64__)
1081 NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
1082 (unsigned long)srcBuf + srcVirW * srcVirH,
1083 (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
1084 srcVirW, srcVirH,
1085 RkRgaGetRgaFormat(relSrcRect.format),0);
1086 /* src1 */
1087 if (src1)
1088 NormalRgaSetPatVirtualInfo(&rgaReg, (unsigned long)src1Buf,
1089 (unsigned long)src1Buf + src1VirW * src1VirH,
1090 (unsigned long)src1Buf + src1VirW * src1VirH * 5/4,
1091 src1VirW, src1VirH, &clip,
1092 RkRgaGetRgaFormat(relSrc1Rect.format),0);
1093 /*dst*/
1094 NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
1095 (unsigned long)dstBuf + dstVirW * dstVirH,
1096 (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
1097 dstVirW, dstVirH, &clip,
1098 RkRgaGetRgaFormat(relDstRect.format),0);
1099 #else
1100 NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
1101 (unsigned int)srcBuf + srcVirW * srcVirH,
1102 (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
1103 srcVirW, srcVirH,
1104 RkRgaGetRgaFormat(relSrcRect.format),0);
1105 /* src1 */
1106 if (src1)
1107 NormalRgaSetPatVirtualInfo(&rgaReg, (unsigned long)src1Buf,
1108 (unsigned int)src1Buf + src1VirW * src1VirH,
1109 (unsigned int)src1Buf + src1VirW * src1VirH * 5/4,
1110 src1VirW, src1VirH, &clip,
1111 RkRgaGetRgaFormat(relSrc1Rect.format),0);
1112 /*dst*/
1113 NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
1114 (unsigned int)dstBuf + dstVirW * dstVirH,
1115 (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
1116 dstVirW, dstVirH, &clip,
1117 RkRgaGetRgaFormat(relDstRect.format),0);
1118
1119 #endif
1120 /* the version 1.005 is different to assign fd from version 2.0 and above */
1121 } else if (ctx->mVersion < (float)1.6) {
1122 /*Src*/
1123 if (srcFd != -1) {
1124 srcMmuFlag = srcType ? 1 : 0;
1125 if (src && srcFd == src->fd)
1126 srcMmuFlag = src->mmuFlag ? 1 : 0;
1127 NormalRgaSetSrcVirtualInfo(&rgaReg, 0, 0, 0, srcVirW, srcVirH,
1128 RkRgaGetRgaFormat(relSrcRect.format),0);
1129 NormalRgaSetFdsOffsets(&rgaReg, srcFd, 0, 0, 0);
1130 } else {
1131 if (src && src->hnd)
1132 srcMmuFlag = srcType ? 1 : 0;
1133 if (src && srcBuf == src->virAddr)
1134 srcMmuFlag = 1;
1135 if (src && srcBuf == src->phyAddr)
1136 srcMmuFlag = 0;
1137 #if defined(__arm64__) || defined(__aarch64__)
1138 NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
1139 (unsigned long)srcBuf + srcVirW * srcVirH,
1140 (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
1141 srcVirW, srcVirH,
1142 RkRgaGetRgaFormat(relSrcRect.format),0);
1143 #else
1144 NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
1145 (unsigned int)srcBuf + srcVirW * srcVirH,
1146 (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
1147 srcVirW, srcVirH,
1148 RkRgaGetRgaFormat(relSrcRect.format),0);
1149 #endif
1150 }
1151 /* src1 */
1152 if (src1) {
1153 if (src1Fd != -1) {
1154 src1MmuFlag = src1Type ? 1 : 0;
1155 if (src1Fd == src1->fd)
1156 src1MmuFlag = src1->mmuFlag ? 1 : 0;
1157 NormalRgaSetPatVirtualInfo(&rgaReg, 0, 0, 0, src1VirW, src1VirH, &clip,
1158 RkRgaGetRgaFormat(relSrc1Rect.format),0);
1159 /*src dst fd*/
1160 NormalRgaSetFdsOffsets(&rgaReg, 0, src1Fd, 0, 0);
1161 } else {
1162 if (src1->hnd)
1163 src1MmuFlag = src1Type ? 1 : 0;
1164 if (src1Buf == src1->virAddr)
1165 src1MmuFlag = 1;
1166 if (src1Buf == src1->phyAddr)
1167 src1MmuFlag = 0;
1168 #if defined(__arm64__) || defined(__aarch64__)
1169 NormalRgaSetPatVirtualInfo(&rgaReg, (unsigned long)src1Buf,
1170 (unsigned long)src1Buf + src1VirW * src1VirH,
1171 (unsigned long)src1Buf + src1VirW * src1VirH * 5/4,
1172 src1VirW, src1VirH, &clip,
1173 RkRgaGetRgaFormat(relSrc1Rect.format),0);
1174 #else
1175 NormalRgaSetPatVirtualInfo(&rgaReg, (unsigned int)src1Buf,
1176 (unsigned int)src1Buf + src1VirW * src1VirH,
1177 (unsigned int)src1Buf + src1VirW * src1VirH * 5/4,
1178 src1VirW, src1VirH, &clip,
1179 RkRgaGetRgaFormat(relSrc1Rect.format),0);
1180 #endif
1181 }
1182 }
1183 /*dst*/
1184 if (dstFd != -1) {
1185 dstMmuFlag = dstType ? 1 : 0;
1186 if (dst && dstFd == dst->fd)
1187 dstMmuFlag = dst->mmuFlag ? 1 : 0;
1188 NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
1189 RkRgaGetRgaFormat(relDstRect.format),0);
1190 /*src dst fd*/
1191 NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
1192 } else {
1193 if (dst && dst->hnd)
1194 dstMmuFlag = dstType ? 1 : 0;
1195 if (dst && dstBuf == dst->virAddr)
1196 dstMmuFlag = 1;
1197 if (dst && dstBuf == dst->phyAddr)
1198 dstMmuFlag = 0;
1199 #if defined(__arm64__) || defined(__aarch64__)
1200 NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
1201 (unsigned long)dstBuf + dstVirW * dstVirH,
1202 (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
1203 dstVirW, dstVirH, &clip,
1204 RkRgaGetRgaFormat(relDstRect.format),0);
1205 #else
1206 NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
1207 (unsigned int)dstBuf + dstVirW * dstVirH,
1208 (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
1209 dstVirW, dstVirH, &clip,
1210 RkRgaGetRgaFormat(relDstRect.format),0);
1211 #endif
1212 }
1213 } else {
1214 if (src && src->hnd)
1215 srcMmuFlag = srcType ? 1 : 0;
1216 if (src && srcBuf == src->virAddr)
1217 srcMmuFlag = 1;
1218 if (src && srcBuf == src->phyAddr)
1219 srcMmuFlag = 0;
1220 if (srcFd != -1)
1221 srcMmuFlag = srcType ? 1 : 0;
1222 if (src && srcFd == src->fd)
1223 srcMmuFlag = src->mmuFlag ? 1 : 0;
1224
1225 if (src1) {
1226 if (src1->hnd)
1227 src1MmuFlag = src1Type ? 1 : 0;
1228 if (src1Buf == src1->virAddr)
1229 src1MmuFlag = 1;
1230 if (src1Buf == src1->phyAddr)
1231 src1MmuFlag = 0;
1232 if (src1Fd != -1)
1233 src1MmuFlag = src1Type ? 1 : 0;
1234 if (src1Fd == src1->fd)
1235 src1MmuFlag = src1->mmuFlag ? 1 : 0;
1236 }
1237
1238 if (dst && dst->hnd)
1239 dstMmuFlag = dstType ? 1 : 0;
1240 if (dst && dstBuf == dst->virAddr)
1241 dstMmuFlag = 1;
1242 if (dst && dstBuf == dst->phyAddr)
1243 dstMmuFlag = 0;
1244 if (dstFd != -1)
1245 dstMmuFlag = dstType ? 1 : 0;
1246 if (dst && dstFd == dst->fd)
1247 dstMmuFlag = dst->mmuFlag ? 1 : 0;
1248
1249 #if defined(__arm64__) || defined(__aarch64__)
1250 NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
1251 (unsigned long)srcBuf,
1252 (unsigned long)srcBuf + srcVirW * srcVirH,
1253 srcVirW, srcVirH,
1254 RkRgaGetRgaFormat(relSrcRect.format),0);
1255 /* src1 */
1256 if (src1)
1257 NormalRgaSetPatVirtualInfo(&rgaReg, src1Fd != -1 ? src1Fd : 0,
1258 (unsigned long)src1Buf,
1259 (unsigned long)src1Buf + src1VirW * src1VirH,
1260 src1VirW, src1VirH, &clip,
1261 RkRgaGetRgaFormat(relSrc1Rect.format),0);
1262 /*dst*/
1263 NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
1264 (unsigned long)dstBuf,
1265 (unsigned long)dstBuf + dstVirW * dstVirH,
1266 dstVirW, dstVirH, &clip,
1267 RkRgaGetRgaFormat(relDstRect.format),0);
1268
1269 #else
1270 NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
1271 (unsigned int)srcBuf,
1272 (unsigned int)srcBuf + srcVirW * srcVirH,
1273 srcVirW, srcVirH,
1274 RkRgaGetRgaFormat(relSrcRect.format),0);
1275 /* src1 */
1276 if (src1)
1277 NormalRgaSetPatVirtualInfo(&rgaReg, src1Fd != -1 ? src1Fd : 0,
1278 (unsigned int)src1Buf,
1279 (unsigned int)src1Buf + src1VirW * src1VirH,
1280 src1VirW, src1VirH, &clip,
1281 RkRgaGetRgaFormat(relSrc1Rect.format),0);
1282 /*dst*/
1283 NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
1284 (unsigned int)dstBuf,
1285 (unsigned int)dstBuf + dstVirW * dstVirH,
1286 dstVirW, dstVirH, &clip,
1287 RkRgaGetRgaFormat(relDstRect.format),0);
1288
1289 #endif
1290 }
1291
1292 /* set effective area of src and dst. */
1293 NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
1294 NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
1295 if (src1)
1296 NormalRgaSetPatActiveInfo(&rgaReg, src1ActW, src1ActH, src1XPos, src1YPos);
1297
1298 if (dst->color_space_mode & full_csc_mask) {
1299 NormalRgaFullColorSpaceConvert(&rgaReg, dst->color_space_mode);
1300 } else {
1301 if (src1) {
1302 /* special config for yuv + rgb => rgb */
1303 /* src0 y2r, src1 bupass, dst bupass */
1304 if (NormalRgaIsYuvFormat(RkRgaGetRgaFormat(relSrcRect.format)) &&
1305 NormalRgaIsRgbFormat(RkRgaGetRgaFormat(relSrc1Rect.format)) &&
1306 NormalRgaIsRgbFormat(RkRgaGetRgaFormat(relDstRect.format)))
1307 yuvToRgbMode |= 0x1 << 0;
1308
1309 /* special config for yuv + rgba => yuv on src1 */
1310 /* src0 y2r, src1 bupass, dst y2r */
1311 if (NormalRgaIsYuvFormat(RkRgaGetRgaFormat(relSrcRect.format)) &&
1312 NormalRgaIsRgbFormat(RkRgaGetRgaFormat(relSrc1Rect.format)) &&
1313 NormalRgaIsYuvFormat(RkRgaGetRgaFormat(relDstRect.format))) {
1314 yuvToRgbMode |= 0x1 << 0; //src0
1315 yuvToRgbMode |= 0x2 << 2; //dst
1316 }
1317
1318 /* special config for rgb + rgb => yuv on dst */
1319 /* src0 bupass, src1 bupass, dst y2r */
1320 if (NormalRgaIsRgbFormat(RkRgaGetRgaFormat(relSrcRect.format)) &&
1321 NormalRgaIsRgbFormat(RkRgaGetRgaFormat(relSrc1Rect.format)) &&
1322 NormalRgaIsYuvFormat(RkRgaGetRgaFormat(relDstRect.format)))
1323 yuvToRgbMode |= 0x2 << 2;
1324 } else {
1325 /* special config for yuv to rgb */
1326 if (NormalRgaIsYuvFormat(RkRgaGetRgaFormat(relSrcRect.format)) &&
1327 NormalRgaIsRgbFormat(RkRgaGetRgaFormat(relDstRect.format)))
1328 yuvToRgbMode |= 0x1 << 0;
1329
1330 /* special config for rgb to yuv */
1331 if (NormalRgaIsRgbFormat(RkRgaGetRgaFormat(relSrcRect.format)) &&
1332 NormalRgaIsYuvFormat(RkRgaGetRgaFormat(relDstRect.format)))
1333 yuvToRgbMode |= 0x2 << 2;
1334 }
1335
1336 if(dst->color_space_mode > 0)
1337 yuvToRgbMode = dst->color_space_mode;
1338 }
1339
1340 /* mode
1341 * scaleMode:set different algorithm to scale.
1342 * rotateMode:rotation mode
1343 * Orientation:rotation orientation
1344 * ditherEn:enable or not.
1345 * yuvToRgbMode:yuv to rgb, rgb to yuv , or others
1346 * */
1347 NormalRgaSetBitbltMode(&rgaReg, scaleMode, rotateMode, orientation,
1348 ditherEn, 0, yuvToRgbMode);
1349
1350 NormalRgaNNQuantizeMode(&rgaReg, dst);
1351
1352 NormalRgaDitherMode(&rgaReg, dst, relDstRect.format);
1353
1354 if (srcMmuFlag || dstMmuFlag) {
1355 NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
1356 NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
1357 }
1358 if (src1) {
1359 if (src1MmuFlag) {
1360 rgaReg.mmu_info.mmu_flag |= (0x1 << 11);
1361 rgaReg.mmu_info.mmu_flag |= (0x1 << 9);
1362 }
1363 /*enable src0 + src1 => dst*/
1364 rgaReg.bsfilter_flag = 1;
1365 }
1366
1367 /* ROP */
1368 /* This special Interface can do some basic logical operations */
1369 if(src->rop_code > 0)
1370 {
1371 rgaReg.rop_code = src->rop_code;
1372 rgaReg.alpha_rop_flag = 0x3;
1373 rgaReg.alpha_rop_mode = 0x1;
1374 }
1375
1376 /*color key*/
1377 /* if need this funtion, maybe should patch the rga driver. */
1378 if(src->colorkey_en == 1) {
1379 rgaReg.alpha_rop_flag |= (1 << 9); //real color mode
1380 switch (src->colorkey_mode) {
1381 case 0 :
1382 NormalRgaSetSrcTransModeInfo(&rgaReg, 0, 1, 1, 1, 1, src->colorkey_min, src->colorkey_max, 1);
1383 break;
1384 case 1 :
1385 NormalRgaSetSrcTransModeInfo(&rgaReg, 1, 1, 1, 1, 1, src->colorkey_min, src->colorkey_max, 1);
1386 break;
1387 }
1388 }
1389
1390 /* mosaic */
1391 memcpy(&rgaReg.mosaic_info, &src->mosaic_info, sizeof(struct rga_mosaic_info));
1392
1393 /* OSD */
1394 memcpy(&rgaReg.osd_info, &src->osd_info, sizeof(struct rga_osd_info));
1395
1396 /* pre_intr */
1397 memcpy(&rgaReg.pre_intr_info, &src->pre_intr, sizeof(src->pre_intr));
1398
1399 if(is_out_log()) {
1400 ALOGD("srcMmuFlag = %d , dstMmuFlag = %d , rotateMode = %d \n", srcMmuFlag, dstMmuFlag,rotateMode);
1401 ALOGD("<<<<-------- rgaReg -------->>>>\n");
1402 NormalRgaLogOutRgaReq(rgaReg);
1403 }
1404
1405 if(src->sync_mode == RGA_BLIT_ASYNC || dst->sync_mode == RGA_BLIT_ASYNC) {
1406 sync_mode = RGA_BLIT_ASYNC;
1407 }
1408
1409 /* rga3 rd_mode */
1410 /* If rd_mode is not configured, raster mode is executed by default. */
1411 rgaReg.src.rd_mode = src->rd_mode ? src->rd_mode : raster_mode;
1412 rgaReg.dst.rd_mode = dst->rd_mode ? dst->rd_mode : raster_mode;
1413 if (src1)
1414 rgaReg.pat.rd_mode = src1->rd_mode ? src1->rd_mode : raster_mode;
1415
1416 rgaReg.in_fence_fd = dst->in_fence_fd;
1417 rgaReg.core = dst->core;
1418 rgaReg.priority = dst->priority;
1419
1420 if (dst->job_handle > 0) {
1421 im_rga_job_t *job = NULL;
1422
1423 g_im2d_job_manager.mutex.lock();
1424
1425 job = g_im2d_job_manager.job_map[dst->job_handle];
1426 if (job->task_count >= RGA_TASK_NUM_MAX) {
1427 printf("job[%d] add task failed! too many tasks, count = %d\n", dst->job_handle, job->task_count);
1428
1429 g_im2d_job_manager.mutex.unlock();
1430 return -errno;
1431 }
1432
1433 job->req[job->task_count] = rgaReg;
1434 job->task_count++;
1435
1436 g_im2d_job_manager.mutex.unlock();
1437
1438 return 0;
1439 } else {
1440 void *ioc_req = NULL;
1441
1442 switch (ctx->driver) {
1443 case RGA_DRIVER_IOC_RGA2:
1444 rga2_req compat_req;
1445
1446 memset(&compat_req, 0x0, sizeof(compat_req));
1447 NormalRgaCompatModeConvertRga2(&compat_req, &rgaReg);
1448
1449 ioc_req = &compat_req;
1450 break;
1451
1452 case RGA_DRIVER_IOC_MULTI_RGA:
1453 ioc_req = &rgaReg;
1454 break;
1455
1456 default:
1457 printf("unknow driver[0x%x]\n", ctx->driver);
1458 return -errno;
1459 }
1460
1461 do {
1462 ret = ioctl(ctx->rgaFd, sync_mode, ioc_req);
1463 } while (ret == -1 && (errno == EINTR || errno == 512)); /* ERESTARTSYS is 512. */
1464 if(ret) {
1465 printf(" %s(%d) RGA_BLIT fail: %s\n",__FUNCTION__, __LINE__,strerror(errno));
1466 ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
1467 return -errno;
1468 }
1469 }
1470
1471 dst->out_fence_fd = rgaReg.out_fence_fd;
1472
1473 return 0;
1474 }
1475
RgaFlush()1476 int RgaFlush() {
1477 struct rgaContext *ctx = rgaCtx;
1478
1479 //init context
1480 if (!ctx) {
1481 ALOGE("Try to use uninit rgaCtx=%p",ctx);
1482 return -ENODEV;
1483 }
1484
1485 if(ioctl(ctx->rgaFd, RGA_FLUSH, NULL)) {
1486 printf(" %s(%d) RGA_FLUSH fail: %s",__FUNCTION__, __LINE__,strerror(errno));
1487 ALOGE(" %s(%d) RGA_FLUSH fail: %s",__FUNCTION__, __LINE__,strerror(errno));
1488 return -errno;
1489 }
1490 return 0;
1491 }
1492
RgaCollorFill(rga_info * dst)1493 int RgaCollorFill(rga_info *dst) {
1494 //check rects
1495 //check buffer_handle_t with rects
1496 struct rgaContext *ctx = rgaCtx;
1497 int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
1498 int dstType,dstMmuFlag;
1499 int dstFd = -1;
1500 int ret = 0;
1501 unsigned int color = 0x00000000;
1502 rga_rect_t relDstRect,tmpDstRect;
1503 struct rga_req rgaReg;
1504 COLOR_FILL fillColor ;
1505 void *dstBuf = NULL;
1506 RECT clip;
1507
1508 int sync_mode = RGA_BLIT_SYNC;
1509
1510 if (!ctx) {
1511 ALOGE("Try to use uninit rgaCtx=%p",ctx);
1512 return -ENODEV;
1513 }
1514
1515 memset(&rgaReg, 0, sizeof(struct rga_req));
1516
1517 dstType = dstMmuFlag = 0;
1518
1519 if (!dst) {
1520 ALOGE("dst = %p", dst);
1521 return -EINVAL;
1522 }
1523
1524 color = dst->color;
1525 memcpy(&relDstRect, &dst->rect, sizeof(rga_rect_t));
1526
1527 if (relDstRect.hstride == 0)
1528 relDstRect.hstride = relDstRect.height;
1529 #ifdef ANDROID
1530 if (dst->hnd) {
1531 ret = RkRgaGetHandleFd(dst->hnd, &dstFd);
1532 if (ret) {
1533 ALOGE("dst handle get fd fail ret = %d,hnd=%p", ret, &dst->hnd);
1534 printf("-dst handle get fd fail ret = %d,hnd=%p", ret, &dst->hnd);
1535 return ret;
1536 }
1537 if (!isRectValid(relDstRect)) {
1538 ret = NormalRgaGetRect(dst->hnd, &tmpDstRect);
1539 if (ret)
1540 return ret;
1541 memcpy(&relDstRect, &tmpDstRect, sizeof(rga_rect_t));
1542 }
1543 NormalRgaGetMmuType(dst->hnd, &dstType);
1544 }
1545 #endif
1546
1547 if (dst->handle > 0) {
1548 dstFd = dst->handle;
1549 /* This will mark the use of handle */
1550 rgaReg.handle_flag |= 1;
1551 } else {
1552 dstFd = dst->fd;
1553 }
1554
1555 if (dst->phyAddr)
1556 dstBuf = dst->phyAddr;
1557 else if (dst->virAddr)
1558 dstBuf = dst->virAddr;
1559 #ifdef ANDROID
1560 else if (dst->hnd)
1561 ret = RkRgaGetHandleMapAddress(dst->hnd, &dstBuf);
1562 #endif
1563
1564 if (dstFd == -1 && !dstBuf) {
1565 ALOGE("%d:dst has not fd and address for render", __LINE__);
1566 return ret;
1567 }
1568
1569 if (dstFd == 0 && !dstBuf) {
1570 ALOGE("dstFd is zero, now driver not support");
1571 return -EINVAL;
1572 }
1573
1574 relDstRect.format = RkRgaCompatibleFormat(relDstRect.format);
1575
1576 if (dstFd == 0)
1577 dstFd = -1;
1578
1579 if (relDstRect.hstride == 0)
1580 relDstRect.hstride = relDstRect.height;
1581
1582 dstVirW = relDstRect.wstride;
1583 dstVirH = relDstRect.hstride;
1584 dstXPos = relDstRect.xoffset;
1585 dstYPos = relDstRect.yoffset;
1586 dstActW = relDstRect.width;
1587 dstActH = relDstRect.height;
1588
1589 clip.xmin = 0;
1590 clip.xmax = dstActW - 1;
1591 clip.ymin = 0;
1592 clip.ymax = dstActH - 1;
1593
1594 if (ctx->mVersion <= 1.003) {
1595 #if defined(__arm64__) || defined(__aarch64__)
1596 /*dst*/
1597 NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
1598 (unsigned long)dstBuf + dstVirW * dstVirH,
1599 (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
1600 dstVirW, dstVirH, &clip,
1601 RkRgaGetRgaFormat(relDstRect.format),0);
1602 #else
1603 /*dst*/
1604 NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
1605 (unsigned int)dstBuf + dstVirW * dstVirH,
1606 (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
1607 dstVirW, dstVirH, &clip,
1608 RkRgaGetRgaFormat(relDstRect.format),0);
1609 #endif
1610 } else if (ctx->mVersion < 1.6 ) {
1611 /*dst*/
1612 if (dstFd != -1) {
1613 dstMmuFlag = dstType ? 1 : 0;
1614 if (dst && dstFd == dst->fd)
1615 dstMmuFlag = dst->mmuFlag ? 1 : 0;
1616 NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
1617 RkRgaGetRgaFormat(relDstRect.format),0);
1618 /*src dst fd*/
1619 NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
1620 } else {
1621 if (dst && dst->hnd)
1622 dstMmuFlag = dstType ? 1 : 0;
1623 if (dst && dstBuf == dst->virAddr)
1624 dstMmuFlag = 1;
1625 if (dst && dstBuf == dst->phyAddr)
1626 dstMmuFlag = 0;
1627 #if defined(__arm64__) || defined(__aarch64__)
1628 NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
1629 (unsigned long)dstBuf + dstVirW * dstVirH,
1630 (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
1631 dstVirW, dstVirH, &clip,
1632 RkRgaGetRgaFormat(relDstRect.format),0);
1633 #else
1634 NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
1635 (unsigned int)dstBuf + dstVirW * dstVirH,
1636 (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
1637 dstVirW, dstVirH, &clip,
1638 RkRgaGetRgaFormat(relDstRect.format),0);
1639 #endif
1640 }
1641 } else {
1642 if (dst && dst->hnd)
1643 dstMmuFlag = dstType ? 1 : 0;
1644 if (dst && dstBuf == dst->virAddr)
1645 dstMmuFlag = 1;
1646 if (dst && dstBuf == dst->phyAddr)
1647 dstMmuFlag = 0;
1648 if (dstFd != -1)
1649 dstMmuFlag = dstType ? 1 : 0;
1650 if (dst && dstFd == dst->fd)
1651 dstMmuFlag = dst->mmuFlag ? 1 : 0;
1652 #if defined(__arm64__) || defined(__aarch64__)
1653 /*dst*/
1654 NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
1655 (unsigned long)dstBuf,
1656 (unsigned long)dstBuf + dstVirW * dstVirH,
1657 dstVirW, dstVirH, &clip,
1658 RkRgaGetRgaFormat(relDstRect.format),0);
1659 #else
1660 /*dst*/
1661 NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
1662 (unsigned int)dstBuf,
1663 (unsigned int)dstBuf + dstVirW * dstVirH,
1664 dstVirW, dstVirH, &clip,
1665 RkRgaGetRgaFormat(relDstRect.format),0);
1666 #endif
1667 }
1668
1669 if (NormalRgaIsYuvFormat(RkRgaGetRgaFormat(relDstRect.format))) {
1670 rgaReg.yuv2rgb_mode |= 0x2 << 2;
1671 }
1672
1673 if(dst->color_space_mode > 0)
1674 rgaReg.yuv2rgb_mode = dst->color_space_mode;
1675
1676 NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
1677
1678 memset(&fillColor, 0x0, sizeof(COLOR_FILL));
1679
1680 /*mode*/
1681 NormalRgaSetColorFillMode(&rgaReg, &fillColor, 0, 0, color, 0, 0, 0, 0, 0);
1682
1683 if (dstMmuFlag) {
1684 NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
1685 NormalRgaMmuFlag(&rgaReg, dstMmuFlag, dstMmuFlag);
1686 }
1687
1688 #ifdef LINUX
1689 #if __DEBUG
1690 NormalRgaLogOutRgaReq(rgaReg);
1691 #endif
1692 #endif
1693
1694 if(dst->sync_mode == RGA_BLIT_ASYNC) {
1695 sync_mode = dst->sync_mode;
1696 }
1697
1698 /* rga3 rd_mode */
1699 /* If rd_mode is not configured, raster mode is executed by default. */
1700 rgaReg.dst.rd_mode = dst->rd_mode ? dst->rd_mode : raster_mode;
1701
1702 rgaReg.in_fence_fd = dst->in_fence_fd;
1703 rgaReg.core = dst->core;
1704 rgaReg.priority = dst->priority;
1705
1706 if (dst->job_handle > 0)
1707 {
1708 im_rga_job_t *job = NULL;
1709
1710 g_im2d_job_manager.mutex.lock();
1711
1712 job = g_im2d_job_manager.job_map[dst->job_handle];
1713 if (job->task_count >= RGA_TASK_NUM_MAX) {
1714 printf("job[%d] add task failed! too many tasks, count = %d\n", dst->job_handle, job->task_count);
1715
1716 g_im2d_job_manager.mutex.unlock();
1717 return -errno;
1718 }
1719
1720 job->req[job->task_count] = rgaReg;
1721 job->task_count++;
1722
1723 g_im2d_job_manager.mutex.unlock();
1724
1725 return 0;
1726 } else {
1727 void *ioc_req = NULL;
1728
1729 switch (ctx->driver) {
1730 case RGA_DRIVER_IOC_RGA2:
1731 rga2_req compat_req;
1732
1733 memset(&compat_req, 0x0, sizeof(compat_req));
1734 NormalRgaCompatModeConvertRga2(&compat_req, &rgaReg);
1735
1736 ioc_req = &compat_req;
1737 break;
1738
1739 case RGA_DRIVER_IOC_MULTI_RGA:
1740 ioc_req = &rgaReg;
1741 break;
1742
1743 default:
1744 printf("unknow driver[0x%x]\n", ctx->driver);
1745 return -errno;
1746 }
1747
1748 do {
1749 ret = ioctl(ctx->rgaFd, sync_mode, ioc_req);
1750 } while (ret == -1 && (errno == EINTR || errno == 512)); /* ERESTARTSYS is 512. */
1751 if(ret) {
1752 printf(" %s(%d) RGA_COLORFILL fail: %s\n",__FUNCTION__, __LINE__,strerror(errno));
1753 ALOGE(" %s(%d) RGA_COLORFILL fail: %s",__FUNCTION__, __LINE__,strerror(errno));
1754 return -errno;
1755 }
1756 }
1757
1758 dst->out_fence_fd = rgaReg.out_fence_fd;
1759
1760 return 0;
1761 }
1762
RgaCollorPalette(rga_info * src,rga_info * dst,rga_info * lut)1763 int RgaCollorPalette(rga_info *src, rga_info *dst, rga_info *lut) {
1764
1765 struct rgaContext *ctx = rgaCtx;
1766 struct rga_req Rga_Request;
1767 struct rga_req Rga_Request2;
1768 int srcVirW ,srcVirH ,srcActW ,srcActH ,srcXPos ,srcYPos;
1769 int dstVirW ,dstVirH ,dstActW ,dstActH ,dstXPos ,dstYPos;
1770 int lutVirW ,lutVirH ,lutActW ,lutActH ,lutXPos ,lutYPos;
1771 int srcType ,dstType ,lutType ,srcMmuFlag ,dstMmuFlag, lutMmuFlag;
1772 int dstFd = -1;
1773 int srcFd = -1;
1774 int lutFd = -1;
1775 int ret = 0;
1776 rga_rect_t relSrcRect,tmpSrcRect,relDstRect,tmpDstRect, relLutRect, tmpLutRect;
1777 struct rga_req rgaReg,tmprgaReg;
1778 void *srcBuf = NULL;
1779 void *dstBuf = NULL;
1780 void *lutBuf = NULL;
1781 RECT clip;
1782
1783 //init context
1784 if (!ctx) {
1785 ALOGE("Try to use uninit rgaCtx=%p",ctx);
1786 return -ENODEV;
1787 }
1788
1789 //init
1790 memset(&rgaReg, 0, sizeof(struct rga_req));
1791
1792 srcType = dstType = lutType = srcMmuFlag = dstMmuFlag = lutMmuFlag = 0;
1793
1794 /* print debug log by setting property vendor.rga.log as 1 */
1795 is_debug_log();
1796 if(is_out_log())
1797 ALOGD("<<<<-------- print rgaLog -------->>>>");
1798
1799 if (!src && !dst) {
1800 ALOGE("src = %p, dst = %p, lut = %p", src, dst, lut);
1801 return -EINVAL;
1802 }
1803
1804 /* get effective area from src、dst and lut, if the area is empty, choose to get parameter from handle. */
1805 if (src)
1806 memcpy(&relSrcRect, &src->rect, sizeof(rga_rect_t));
1807 if (dst)
1808 memcpy(&relDstRect, &dst->rect, sizeof(rga_rect_t));
1809 if (lut)
1810 memcpy(&relLutRect, &lut->rect, sizeof(rga_rect_t));
1811
1812 srcFd = dstFd = lutFd = -1;
1813
1814 if(is_out_log()) {
1815 ALOGD("src->hnd = 0x%lx , dst->hnd = 0x%lx, lut->hnd = 0x%lx \n",
1816 (unsigned long)src->hnd, (unsigned long)dst->hnd, (unsigned long)lut->hnd);
1817 ALOGD("src: Fd = %.2d , phyAddr = %p , virAddr = %p\n",src->fd,src->phyAddr,src->virAddr);
1818 ALOGD("dst: Fd = %.2d , phyAddr = %p , virAddr = %p\n",dst->fd,dst->phyAddr,dst->virAddr);
1819 ALOGD("lut: Fd = %.2d , phyAddr = %p , virAddr = %p\n",lut->fd,lut->phyAddr,lut->virAddr);
1820 }
1821
1822 if (lut) {
1823 if (src->handle <= 0 || dst->handle <= 0 || lut->handle <= 0) {
1824 ALOGE("librga only supports the use of handles only or no handles, [src,lut,dst] = [%d, %d, %d]\n",
1825 src->handle, lut->handle, dst->handle);
1826 return -EINVAL;
1827 }
1828
1829 /* This will mark the use of handle */
1830 rgaReg.handle_flag |= 1;
1831 } else if (src->handle > 0 && dst->handle > 0) {
1832 /* This will mark the use of handle */
1833 rgaReg.handle_flag |= 1;
1834 } else {
1835 ALOGE("librga only supports the use of handles only or no handles, [src,dst] = [%d, %d]\n",
1836 src->handle, dst->handle);
1837 return -EINVAL;
1838 }
1839
1840 /*********** get src addr *************/
1841 if (src && src->handle) {
1842 /* In order to minimize changes, the handle here will reuse the variable of Fd. */
1843 srcFd = src->handle;
1844 } else if (src && src->phyAddr) {
1845 srcBuf = src->phyAddr;
1846 } else if (src && src->fd > 0) {
1847 srcFd = src->fd;
1848 src->mmuFlag = 1;
1849 } else if (src && src->virAddr) {
1850 srcBuf = src->virAddr;
1851 src->mmuFlag = 1;
1852 }
1853 #ifdef ANDROID
1854 else if (src && src->hnd) {
1855 #ifndef RK3188
1856 /* RK3188 is special, cannot configure rga through fd. */
1857 RkRgaGetHandleFd(src->hnd, &srcFd);
1858 #endif
1859 #ifndef ANDROID_8
1860 if (srcFd < 0 || srcFd == 0) {
1861 RkRgaGetHandleMapAddress(src->hnd, &srcBuf);
1862 }
1863 #endif
1864 if ((srcFd < 0 || srcFd == 0) && srcBuf == NULL) {
1865 ALOGE("src handle get fd and vir_addr fail ret = %d,hnd=%p", ret, &src->hnd);
1866 printf("src handle get fd and vir_addr fail ret = %d,hnd=%p", ret, &src->hnd);
1867 return ret;
1868 }
1869 else {
1870 srcType = 1;
1871 }
1872 }
1873
1874 if (!isRectValid(relSrcRect)) {
1875 ret = NormalRgaGetRect(src->hnd, &tmpSrcRect);
1876 if (ret) {
1877 ALOGE("dst handleGetRect fail ,ret = %d,hnd=%p", ret, &src->hnd);
1878 printf("dst handleGetRect fail ,ret = %d,hnd=%p", ret, &src->hnd);
1879 return ret;
1880 }
1881 memcpy(&relSrcRect, &tmpSrcRect, sizeof(rga_rect_t));
1882 }
1883 #endif
1884
1885 if (srcFd == -1 && !srcBuf) {
1886 ALOGE("%d:src has not fd and address for render", __LINE__);
1887 return ret;
1888 }
1889 if (srcFd == 0 && !srcBuf) {
1890 ALOGE("srcFd is zero, now driver not support");
1891 return -EINVAL;
1892 }
1893 /* Old rga driver cannot support fd as zero. */
1894 if (srcFd == 0)
1895 srcFd = -1;
1896
1897 /*********** get dst addr *************/
1898 if (dst && dst->handle) {
1899 /* In order to minimize changes, the handle here will reuse the variable of Fd. */
1900 dstFd = dst->handle;
1901 } else if (dst && dst->phyAddr) {
1902 dstBuf = dst->phyAddr;
1903 } else if (dst && dst->fd > 0) {
1904 dstFd = dst->fd;
1905 dst->mmuFlag = 1;
1906 } else if (dst && dst->virAddr) {
1907 dstBuf = dst->virAddr;
1908 dst->mmuFlag = 1;
1909 }
1910 #ifdef ANDROID
1911 else if (dst && dst->hnd) {
1912 #ifndef RK3188
1913 /* RK3188 is special, cannot configure rga through fd. */
1914 RkRgaGetHandleFd(dst->hnd, &dstFd);
1915 #endif
1916 #ifndef ANDROID_8
1917 if (dstFd < 0 || dstFd == 0) {
1918 RkRgaGetHandleMapAddress(dst->hnd, &dstBuf);
1919 }
1920 #endif
1921 if ((dstFd < 0 || dstFd == 0) && dstBuf == NULL) {
1922 ALOGE("dst handle get fd and vir_addr fail ret = %d,hnd=%p", ret, &dst->hnd);
1923 printf("dst handle get fd and vir_addr fail ret = %d,hnd=%p", ret, &dst->hnd);
1924 return ret;
1925 }
1926 else {
1927 dstType = 1;
1928 }
1929 }
1930
1931 if (!isRectValid(relDstRect)) {
1932 ret = NormalRgaGetRect(dst->hnd, &tmpDstRect);
1933 if (ret) {
1934 ALOGE("dst handleGetRect fail ,ret = %d,hnd=%p", ret, &dst->hnd);
1935 printf("dst handleGetRect fail ,ret = %d,hnd=%p", ret, &dst->hnd);
1936 return ret;
1937 }
1938 memcpy(&relDstRect, &tmpDstRect, sizeof(rga_rect_t));
1939 }
1940 #endif
1941
1942 if (dstFd == -1 && !dstBuf) {
1943 ALOGE("%d:dst has not fd and address for render", __LINE__);
1944 return ret;
1945 }
1946 if (dstFd == 0 && !dstBuf) {
1947 ALOGE("dstFd is zero, now driver not support");
1948 return -EINVAL;
1949 }
1950 /* Old rga driver cannot support fd as zero. */
1951 if (dstFd == 0)
1952 dstFd = -1;
1953
1954 /*********** get lut addr *************/
1955 if (lut && lut->handle) {
1956 /* In order to minimize changes, the handle here will reuse the variable of Fd. */
1957 lutFd = lut->handle;
1958 } else if (lut && lut->phyAddr) {
1959 lutBuf = lut->phyAddr;
1960 } else if (lut && lut->fd > 0) {
1961 lutFd = lut->fd;
1962 lut->mmuFlag = 1;
1963 } else if (lut && lut->virAddr) {
1964 lutBuf = lut->virAddr;
1965 lut->mmuFlag = 1;
1966 }
1967 #ifdef ANDROID
1968 else if (lut && lut->hnd) {
1969 #ifndef RK3188
1970 /* RK3188 is special, cannot configure rga through fd. */
1971 RkRgaGetHandleFd(lut->hnd, &lutFd);
1972 #endif
1973 #ifndef ANDROID_8
1974 if (lutFd < 0 || lutFd == 0) {
1975 RkRgaGetHandleMapAddress(lut->hnd, &lutBuf);
1976 }
1977 #endif
1978 if ((lutFd < 0 || lutFd == 0) && lutBuf == NULL) {
1979 ALOGE("No lut address,not using update palette table mode.\n");
1980 printf("No lut address,not using update palette table mode.\n");
1981 }
1982 else {
1983 lutType = 1;
1984 }
1985
1986 ALOGD("lut->mmuFlag = %d", lut->mmuFlag);
1987 }
1988
1989 if (!isRectValid(relLutRect)) {
1990 ret = NormalRgaGetRect(lut->hnd, &tmpLutRect);
1991 if (ret) {
1992 ALOGE("lut handleGetRect fail ,ret = %d,hnd=%p", ret, &lut->hnd);
1993 printf("lut handleGetRect fail ,ret = %d,hnd=%p", ret, &lut->hnd);
1994 }
1995 memcpy(&relLutRect, &tmpLutRect, sizeof(rga_rect_t));
1996 }
1997 #endif
1998
1999 /* Old rga driver cannot support fd as zero. */
2000 if (lutFd == 0)
2001 lutFd = -1;
2002
2003 if(is_out_log()) {
2004 ALOGD("src: Fd = %.2d , buf = %p, mmuFlag = %d, mmuType = %d\n", srcFd, srcBuf, src->mmuFlag, srcType);
2005 ALOGD("dst: Fd = %.2d , buf = %p, mmuFlag = %d, mmuType = %d\n", dstFd, dstBuf, dst->mmuFlag, dstType);
2006 ALOGD("lut: Fd = %.2d , buf = %p, mmuFlag = %d, mmuType = %d\n", lutFd, lutBuf, lut->mmuFlag, lutType);
2007 }
2008
2009 relSrcRect.format = RkRgaCompatibleFormat(relSrcRect.format);
2010 relDstRect.format = RkRgaCompatibleFormat(relDstRect.format);
2011 relLutRect.format = RkRgaCompatibleFormat(relLutRect.format);
2012
2013 #ifdef RK3126C
2014 if ( (relSrcRect.width == relDstRect.width) && (relSrcRect.height == relDstRect.height ) &&
2015 (relSrcRect.width + 2*relSrcRect.xoffset == relSrcRect.wstride) &&
2016 (relSrcRect.height + 2*relSrcRect.yoffset == relSrcRect.hstride) &&
2017 (relSrcRect.format == HAL_PIXEL_FORMAT_YCrCb_NV12) && (relSrcRect.xoffset > 0 && relSrcRect.yoffset > 0)
2018 ) {
2019 relSrcRect.width += 4;
2020 //relSrcRect.height += 4;
2021 relSrcRect.xoffset = (relSrcRect.wstride - relSrcRect.width) / 2;
2022 }
2023 #endif
2024 /* discripe a picture need high stride.If high stride not to be set, need use height as high stride. */
2025 if (relSrcRect.hstride == 0)
2026 relSrcRect.hstride = relSrcRect.height;
2027
2028 if (relDstRect.hstride == 0)
2029 relDstRect.hstride = relDstRect.height;
2030
2031 /* do some check, check the area of src and dst whether is effective. */
2032 if (src) {
2033 ret = checkRectForRga(relSrcRect);
2034 if (ret) {
2035 printf("Error srcRect\n");
2036 ALOGE("[%s,%d]Error srcRect \n", __func__, __LINE__);
2037 return ret;
2038 }
2039 }
2040
2041 if (dst) {
2042 ret = checkRectForRga(relDstRect);
2043 if (ret) {
2044 printf("Error dstRect\n");
2045 ALOGE("[%s,%d]Error dstRect \n", __func__, __LINE__);
2046 return ret;
2047 }
2048 }
2049
2050 srcVirW = relSrcRect.wstride;
2051 srcVirH = relSrcRect.hstride;
2052 srcXPos = relSrcRect.xoffset;
2053 srcYPos = relSrcRect.yoffset;
2054 srcActW = relSrcRect.width;
2055 srcActH = relSrcRect.height;
2056
2057 dstVirW = relDstRect.wstride;
2058 dstVirH = relDstRect.hstride;
2059 dstXPos = relDstRect.xoffset;
2060 dstYPos = relDstRect.yoffset;
2061 dstActW = relDstRect.width;
2062 dstActH = relDstRect.height;
2063
2064 lutVirW = relLutRect.wstride;
2065 lutVirH = relLutRect.hstride;
2066 lutXPos = relLutRect.xoffset;
2067 lutYPos = relLutRect.yoffset;
2068 lutActW = relLutRect.width;
2069 lutActH = relLutRect.height;
2070
2071 /* if pictual out of range should be cliped. */
2072 clip.xmin = 0;
2073 clip.xmax = dstVirW - 1;
2074 clip.ymin = 0;
2075 clip.ymax = dstVirH - 1;
2076
2077 /* only to configure the parameter by driver version, because rga driver has too many version. */
2078 if (ctx->mVersion <= (float)1.003) {
2079 srcMmuFlag = dstMmuFlag = lutMmuFlag = 1;
2080
2081 #if defined(__arm64__) || defined(__aarch64__)
2082 NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
2083 (unsigned long)srcBuf + srcVirW * srcVirH,
2084 (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
2085 srcVirW, srcVirH,
2086 RkRgaGetRgaFormat(relSrcRect.format),0);
2087 /*dst*/
2088 NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
2089 (unsigned long)dstBuf + dstVirW * dstVirH,
2090 (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
2091 dstVirW, dstVirH, &clip,
2092 RkRgaGetRgaFormat(relDstRect.format),0);
2093 /*lut*/
2094 NormalRgaSetPatVirtualInfo(&rgaReg, (unsigned long)lutBuf,
2095 (unsigned long)lutBuf + lutVirW * lutVirH,
2096 (unsigned long)lutBuf + lutVirW * lutVirH * 5/4,
2097 lutVirW, lutVirH, &clip,
2098 RkRgaGetRgaFormat(relLutRect.format),0);
2099 #else
2100 NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
2101 (unsigned int)srcBuf + srcVirW * srcVirH,
2102 (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
2103 srcVirW, srcVirH,
2104 RkRgaGetRgaFormat(relSrcRect.format),0);
2105 /*dst*/
2106 NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
2107 (unsigned int)dstBuf + dstVirW * dstVirH,
2108 (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
2109 dstVirW, dstVirH, &clip,
2110 RkRgaGetRgaFormat(relDstRect.format),0);
2111 /*lut*/
2112 NormalRgaSetPatVirtualInfo(&rgaReg, (unsigned long)lutBuf,
2113 (unsigned int)lutBuf + lutVirW * lutVirH,
2114 (unsigned int)lutBuf + lutVirW * lutVirH * 5/4,
2115 lutVirW, lutVirH, &clip,
2116 RkRgaGetRgaFormat(relLutRect.format),0);
2117
2118 #endif
2119 /* the version 1.005 is different to assign fd from version 2.0 and above */
2120 } else if (ctx->mVersion < (float)1.6) {
2121 /*Src*/
2122 if (srcFd != -1) {
2123 srcMmuFlag = srcType ? 1 : 0;
2124 if (src && srcFd == src->fd)
2125 srcMmuFlag = src->mmuFlag ? 1 : 0;
2126 NormalRgaSetSrcVirtualInfo(&rgaReg, 0, 0, 0, srcVirW, srcVirH,
2127 RkRgaGetRgaFormat(relSrcRect.format),0);
2128 NormalRgaSetFdsOffsets(&rgaReg, srcFd, 0, 0, 0);
2129 } else {
2130 if (src && src->hnd)
2131 srcMmuFlag = srcType ? 1 : 0;
2132 if (src && srcBuf == src->virAddr)
2133 srcMmuFlag = 1;
2134 if (src && srcBuf == src->phyAddr)
2135 srcMmuFlag = 0;
2136 #if defined(__arm64__) || defined(__aarch64__)
2137 NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
2138 (unsigned long)srcBuf + srcVirW * srcVirH,
2139 (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
2140 srcVirW, srcVirH,
2141 RkRgaGetRgaFormat(relSrcRect.format),0);
2142 #else
2143 NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
2144 (unsigned int)srcBuf + srcVirW * srcVirH,
2145 (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
2146 srcVirW, srcVirH,
2147 RkRgaGetRgaFormat(relSrcRect.format),0);
2148 #endif
2149 }
2150 /*dst*/
2151 if (dstFd != -1) {
2152 dstMmuFlag = dstType ? 1 : 0;
2153 if (dst && dstFd == dst->fd)
2154 dstMmuFlag = dst->mmuFlag ? 1 : 0;
2155 NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
2156 RkRgaGetRgaFormat(relDstRect.format),0);
2157 /*src dst fd*/
2158 NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
2159 } else {
2160 if (dst && dst->hnd)
2161 dstMmuFlag = dstType ? 1 : 0;
2162 if (dst && dstBuf == dst->virAddr)
2163 dstMmuFlag = 1;
2164 if (dst && dstBuf == dst->phyAddr)
2165 dstMmuFlag = 0;
2166 #if defined(__arm64__) || defined(__aarch64__)
2167 NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
2168 (unsigned long)dstBuf + dstVirW * dstVirH,
2169 (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
2170 dstVirW, dstVirH, &clip,
2171 RkRgaGetRgaFormat(relDstRect.format),0);
2172 #else
2173 NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
2174 (unsigned int)dstBuf + dstVirW * dstVirH,
2175 (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
2176 dstVirW, dstVirH, &clip,
2177 RkRgaGetRgaFormat(relDstRect.format),0);
2178 #endif
2179 }
2180 /*lut*/
2181 if (lutFd != -1) {
2182 lutMmuFlag = lutType ? 1 : 0;
2183 if (lut && lutFd == lut->fd)
2184 lutMmuFlag = lut->mmuFlag ? 1 : 0;
2185 NormalRgaSetPatVirtualInfo(&rgaReg, 0, 0, 0, lutVirW, lutVirH, &clip,
2186 RkRgaGetRgaFormat(relLutRect.format),0);
2187 /*lut fd*/
2188 NormalRgaSetFdsOffsets(&rgaReg, 0, lutFd, 0, 0);
2189 } else {
2190 if (lut && lut->hnd)
2191 lutMmuFlag = lutType ? 1 : 0;
2192 if (lut && lutBuf == lut->virAddr)
2193 lutMmuFlag = 1;
2194 if (lut && lutBuf == lut->phyAddr)
2195 lutMmuFlag = 0;
2196 #if defined(__arm64__) || defined(__aarch64__)
2197 NormalRgaSetPatVirtualInfo(&rgaReg, (unsigned long)lutBuf,
2198 (unsigned long)lutBuf + lutVirW * lutVirH,
2199 (unsigned long)lutBuf + lutVirW * lutVirH * 5/4,
2200 lutVirW, lutVirH, &clip,
2201 RkRgaGetRgaFormat(relLutRect.format),0);
2202 #else
2203 NormalRgaSetPatVirtualInfo(&rgaReg, (unsigned int)lutBuf,
2204 (unsigned int)lutBuf + lutVirW * lutVirH,
2205 (unsigned int)lutBuf + lutVirW * lutVirH * 5/4,
2206 lutVirW, lutVirH, &clip,
2207 RkRgaGetRgaFormat(relLutRect.format),0);
2208 #endif
2209 }
2210 } else {
2211 if (src && src->hnd)
2212 srcMmuFlag = srcType ? 1 : 0;
2213 if (src && srcBuf == src->virAddr)
2214 srcMmuFlag = 1;
2215 if (src && srcBuf == src->phyAddr)
2216 srcMmuFlag = 0;
2217 if (srcFd != -1)
2218 srcMmuFlag = srcType ? 1 : 0;
2219 if (src && srcFd == src->fd)
2220 srcMmuFlag = src->mmuFlag ? 1 : 0;
2221
2222 if (dst && dst->hnd)
2223 dstMmuFlag = dstType ? 1 : 0;
2224 if (dst && dstBuf == dst->virAddr)
2225 dstMmuFlag = 1;
2226 if (dst && dstBuf == dst->phyAddr)
2227 dstMmuFlag = 0;
2228 if (dstFd != -1)
2229 dstMmuFlag = dstType ? 1 : 0;
2230 if (dst && dstFd == dst->fd)
2231 dstMmuFlag = dst->mmuFlag ? 1 : 0;
2232
2233 if (lut && lut->hnd)
2234 lutMmuFlag = lutType ? 1 : 0;
2235 if (lut && lutBuf == lut->virAddr)
2236 lutMmuFlag = 1;
2237 if (lut && lutBuf == lut->phyAddr)
2238 lutMmuFlag = 0;
2239 if (lutFd != -1)
2240 lutMmuFlag = lutType ? 1 : 0;
2241 if (lut && lutFd == lut->fd)
2242 lutMmuFlag = lut->mmuFlag ? 1 : 0;
2243
2244 #if defined(__arm64__) || defined(__aarch64__)
2245 NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
2246 (unsigned long)srcBuf,
2247 (unsigned long)srcBuf + srcVirW * srcVirH,
2248 srcVirW, srcVirH,
2249 RkRgaGetRgaFormat(relSrcRect.format),0);
2250 /*dst*/
2251 NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
2252 (unsigned long)dstBuf,
2253 (unsigned long)dstBuf + dstVirW * dstVirH,
2254 dstVirW, dstVirH, &clip,
2255 RkRgaGetRgaFormat(relDstRect.format),0);
2256
2257 /*lut*/
2258 NormalRgaSetPatVirtualInfo(&rgaReg, lutFd != -1 ? lutFd : 0,
2259 (unsigned long)lutBuf,
2260 (unsigned long)lutBuf + lutVirW * lutVirH,
2261 lutVirW, lutVirH, &clip,
2262 RkRgaGetRgaFormat(relLutRect.format),0);
2263 #else
2264 NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
2265 (unsigned int)srcBuf,
2266 (unsigned int)srcBuf + srcVirW * srcVirH,
2267 srcVirW, srcVirH,
2268 RkRgaGetRgaFormat(relSrcRect.format),0);
2269 /*dst*/
2270 NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
2271 (unsigned int)dstBuf,
2272 (unsigned int)dstBuf + dstVirW * dstVirH,
2273 dstVirW, dstVirH, &clip,
2274 RkRgaGetRgaFormat(relDstRect.format),0);
2275 /*lut*/
2276 NormalRgaSetPatVirtualInfo(&rgaReg, lutFd != -1 ? lutFd : 0,
2277 (unsigned int)lutBuf,
2278 (unsigned int)lutBuf + lutVirW * lutVirH,
2279 lutVirW, lutVirH, &clip,
2280 RkRgaGetRgaFormat(relLutRect.format),0);
2281
2282 #endif
2283 }
2284
2285 /* set effective area of src and dst. */
2286 NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
2287 NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
2288 NormalRgaSetPatActiveInfo(&rgaReg, lutActW, lutActH, lutXPos, lutYPos);
2289
2290 if (srcMmuFlag || dstMmuFlag || lutMmuFlag) {
2291 NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
2292 NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
2293 /*set lut mmu_flag*/
2294 if (lutMmuFlag) {
2295 rgaReg.mmu_info.mmu_flag |= (0x1 << 11);
2296 rgaReg.mmu_info.mmu_flag |= (0x1 << 9);
2297 }
2298
2299 }
2300
2301 if(is_out_log()) {
2302 ALOGD("srcMmuFlag = %d , dstMmuFlag = %d , lutMmuFlag = %d\n", srcMmuFlag, dstMmuFlag, lutMmuFlag);
2303 ALOGD("<<<<-------- rgaReg -------->>>>\n");
2304 NormalRgaLogOutRgaReq(rgaReg);
2305 }
2306
2307 switch (RkRgaGetRgaFormat(relSrcRect.format)) {
2308 case RK_FORMAT_BPP1 :
2309 rgaReg.palette_mode = 0;
2310 break;
2311 case RK_FORMAT_BPP2 :
2312 rgaReg.palette_mode = 1;
2313 break;
2314 case RK_FORMAT_BPP4 :
2315 rgaReg.palette_mode = 2;
2316 break;
2317 case RK_FORMAT_BPP8 :
2318 rgaReg.palette_mode = 3;
2319 break;
2320 }
2321
2322 /* rga3 rd_mode */
2323 /* If rd_mode is not configured, raster mode is executed by default. */
2324 rgaReg.src.rd_mode = src->rd_mode ? src->rd_mode : raster_mode;
2325 rgaReg.dst.rd_mode = dst->rd_mode ? dst->rd_mode : raster_mode;
2326 if (lut)
2327 rgaReg.pat.rd_mode = lut->rd_mode ? lut->rd_mode : raster_mode;
2328
2329 rgaReg.in_fence_fd = dst->in_fence_fd;
2330 rgaReg.core = dst->core;
2331 rgaReg.priority = dst->priority;
2332
2333 if (!(lutFd == -1 && lutBuf == NULL)) {
2334 rgaReg.fading.g = 0xff;
2335 rgaReg.render_mode = update_palette_table_mode;
2336
2337 if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg) != 0) {
2338 printf("update palette table mode ioctl err\n");
2339 return -1;
2340 }
2341 }
2342
2343 rgaReg.render_mode = color_palette_mode;
2344 rgaReg.endian_mode = 1;
2345
2346 void *ioc_req = NULL;
2347 rga2_req compat_req;
2348
2349 switch (ctx->driver) {
2350 case RGA_DRIVER_IOC_RGA2:
2351 memset(&compat_req, 0x0, sizeof(compat_req));
2352 NormalRgaCompatModeConvertRga2(&compat_req, &rgaReg);
2353
2354 ioc_req = &compat_req;
2355 break;
2356
2357 case RGA_DRIVER_IOC_MULTI_RGA:
2358 ioc_req = &rgaReg;
2359 break;
2360
2361 default:
2362 printf("unknow driver[0x%x]\n", ctx->driver);
2363 return -errno;
2364 }
2365
2366 do {
2367 ret = ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &ioc_req);
2368 } while (ret == -1 && (errno == EINTR || errno == 512)); /* ERESTARTSYS is 512. */
2369 if(ret) {
2370 printf(" %s(%d) RGA_COLOR_PALETTE fail: %s\n",__FUNCTION__, __LINE__,strerror(errno));
2371 ALOGE(" %s(%d) RGA_COLOR_PALETTE fail: %s",__FUNCTION__, __LINE__,strerror(errno));
2372 return -errno;
2373 }
2374
2375 dst->out_fence_fd = rgaReg.out_fence_fd;
2376
2377 return 0;
2378 }
2379
NormalRgaScale()2380 int NormalRgaScale() {
2381 return 1;
2382 }
2383
NormalRgaRoate()2384 int NormalRgaRoate() {
2385 return 1;
2386 }
2387
NormalRgaRoateScale()2388 int NormalRgaRoateScale() {
2389 return 1;
2390 }
2391