2 * Copyright (C) 2013 Samsung Electronics Co.Ltd
4 * Inki Dae <inki.dae@samsung.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
24 #include <linux/stddef.h>
28 #include "libdrm_macros.h"
29 #include "exynos_drm.h"
30 #include "fimg2d_reg.h"
31 #include "exynos_fimg2d.h"
33 #define SET_BF(val, sc, si, scsa, scda, dc, di, dcsa, dcda) \
34 val.data.src_coeff = sc; \
35 val.data.inv_src_color_coeff = si; \
36 val.data.src_coeff_src_a = scsa; \
37 val.data.src_coeff_dst_a = scda; \
38 val.data.dst_coeff = dc; \
39 val.data.inv_dst_color_coeff = di; \
40 val.data.dst_coeff_src_a = dcsa; \
41 val.data.dst_coeff_dst_a = dcda;
43 #define MIN(a, b) ((a) < (b) ? (a) : (b))
45 #define MSG_PREFIX "exynos/fimg2d: "
47 enum g2d_base_addr_reg {
52 static unsigned int g2d_get_scaling(unsigned int src, unsigned int dst)
55 * The G2D hw scaling factor is a normalized inverse of the scaling factor.
56 * For example: When source width is 100 and destination width is 200
57 * (scaling of 2x), then the hw factor is NC * 100 / 200.
58 * The normalization factor (NC) is 2^16 = 0x10000.
61 return ((src << 16) / dst);
64 static unsigned int g2d_get_blend_op(enum e_g2d_op op)
66 union g2d_blend_func_val val;
71 * The switch statement is missing the default branch since
72 * we assume that the caller checks the blending operation
73 * via g2d_validate_blending_op() first.
77 case G2D_OP_DISJOINT_CLEAR:
78 case G2D_OP_CONJOINT_CLEAR:
79 SET_BF(val, G2D_COEFF_MODE_ZERO, 0, 0, 0, G2D_COEFF_MODE_ZERO,
83 case G2D_OP_DISJOINT_SRC:
84 case G2D_OP_CONJOINT_SRC:
85 SET_BF(val, G2D_COEFF_MODE_ONE, 0, 0, 0, G2D_COEFF_MODE_ZERO,
89 case G2D_OP_DISJOINT_DST:
90 case G2D_OP_CONJOINT_DST:
91 SET_BF(val, G2D_COEFF_MODE_ZERO, 0, 0, 0, G2D_COEFF_MODE_ONE,
95 SET_BF(val, G2D_COEFF_MODE_ONE, 0, 0, 0,
96 G2D_COEFF_MODE_SRC_ALPHA, 1, 0, 0);
98 case G2D_OP_INTERPOLATE:
99 SET_BF(val, G2D_COEFF_MODE_SRC_ALPHA, 0, 0, 0,
100 G2D_COEFF_MODE_SRC_ALPHA, 1, 0, 0);
108 * g2d_check_space - check if command buffers have enough space left.
110 * @ctx: a pointer to g2d_context structure.
111 * @num_cmds: number of (regular) commands.
112 * @num_gem_cmds: number of GEM commands.
114 static unsigned int g2d_check_space(const struct g2d_context *ctx,
115 unsigned int num_cmds, unsigned int num_gem_cmds)
117 if (ctx->cmd_nr + num_cmds >= G2D_MAX_CMD_NR ||
118 ctx->cmd_buf_nr + num_gem_cmds >= G2D_MAX_GEM_CMD_NR)
125 * g2d_validate_select_mode - validate select mode.
127 * @mode: the mode to validate
129 * Returns zero for an invalid mode and one otherwise.
131 static int g2d_validate_select_mode(
132 enum e_g2d_select_mode mode)
135 case G2D_SELECT_MODE_NORMAL:
136 case G2D_SELECT_MODE_FGCOLOR:
137 case G2D_SELECT_MODE_BGCOLOR:
145 * g2d_validate_blending_op - validate blending operation.
147 * @operation: the operation to validate
149 * Returns zero for an invalid mode and one otherwise.
151 static int g2d_validate_blending_op(
152 enum e_g2d_op operation)
159 case G2D_OP_INTERPOLATE:
160 case G2D_OP_DISJOINT_CLEAR:
161 case G2D_OP_DISJOINT_SRC:
162 case G2D_OP_DISJOINT_DST:
163 case G2D_OP_CONJOINT_CLEAR:
164 case G2D_OP_CONJOINT_SRC:
165 case G2D_OP_CONJOINT_DST:
173 * g2d_add_cmd - set given command and value to user side command buffer.
175 * @ctx: a pointer to g2d_context structure.
176 * @cmd: command data.
177 * @value: value data.
179 * The caller has to make sure that the commands buffers have enough space
180 * left to hold the command. Use g2d_check_space() to ensure this.
182 static void g2d_add_cmd(struct g2d_context *ctx, unsigned long cmd,
185 switch (cmd & ~(G2D_BUF_USERPTR)) {
186 case SRC_BASE_ADDR_REG:
187 case SRC_PLANE2_BASE_ADDR_REG:
188 case DST_BASE_ADDR_REG:
189 case DST_PLANE2_BASE_ADDR_REG:
190 case PAT_BASE_ADDR_REG:
191 case MASK_BASE_ADDR_REG:
192 assert(ctx->cmd_buf_nr < G2D_MAX_GEM_CMD_NR);
194 ctx->cmd_buf[ctx->cmd_buf_nr].offset = cmd;
195 ctx->cmd_buf[ctx->cmd_buf_nr].data = value;
199 assert(ctx->cmd_nr < G2D_MAX_CMD_NR);
201 ctx->cmd[ctx->cmd_nr].offset = cmd;
202 ctx->cmd[ctx->cmd_nr].data = value;
209 * g2d_add_base_addr - helper function to set dst/src base address register.
211 * @ctx: a pointer to g2d_context structure.
212 * @img: a pointer to the dst/src g2d_image structure.
213 * @reg: the register that should be set.
215 static void g2d_add_base_addr(struct g2d_context *ctx, struct g2d_image *img,
216 enum g2d_base_addr_reg reg)
218 const unsigned long cmd = (reg == g2d_dst) ?
219 DST_BASE_ADDR_REG : SRC_BASE_ADDR_REG;
221 if (img->buf_type == G2D_IMGBUF_USERPTR)
222 g2d_add_cmd(ctx, cmd | G2D_BUF_USERPTR,
223 (unsigned long)&img->user_ptr[0]);
225 g2d_add_cmd(ctx, cmd, img->bo[0]);
229 * g2d_reset - reset fimg2d hardware.
231 * @ctx: a pointer to g2d_context structure.
234 static void g2d_reset(struct g2d_context *ctx)
239 g2d_add_cmd(ctx, SOFT_RESET_REG, 0x01);
243 * g2d_flush - submit all commands and values in user side command buffer
244 * to command queue aware of fimg2d dma.
246 * @ctx: a pointer to g2d_context structure.
248 * This function should be called after all commands and values to user
249 * side command buffer are set. It submits that buffer to the kernel side driver.
251 static int g2d_flush(struct g2d_context *ctx)
254 struct drm_exynos_g2d_set_cmdlist cmdlist = {0};
256 if (ctx->cmd_nr == 0 && ctx->cmd_buf_nr == 0)
259 if (ctx->cmdlist_nr >= G2D_MAX_CMD_LIST_NR) {
260 fprintf(stderr, MSG_PREFIX "command list overflow.\n");
264 cmdlist.cmd = (uint64_t)(uintptr_t)&ctx->cmd[0];
265 cmdlist.cmd_buf = (uint64_t)(uintptr_t)&ctx->cmd_buf[0];
266 cmdlist.cmd_nr = ctx->cmd_nr;
267 cmdlist.cmd_buf_nr = ctx->cmd_buf_nr;
268 cmdlist.event_type = G2D_EVENT_NOT;
269 cmdlist.user_data = 0;
274 ret = drmIoctl(ctx->fd, DRM_IOCTL_EXYNOS_G2D_SET_CMDLIST, &cmdlist);
276 fprintf(stderr, MSG_PREFIX "failed to set cmdlist.\n");
286 * g2d_init - create a new g2d context and get hardware version.
288 * fd: a file descriptor to an opened drm device.
290 struct g2d_context *g2d_init(int fd)
292 struct drm_exynos_g2d_get_ver ver;
293 struct g2d_context *ctx;
296 ctx = calloc(1, sizeof(*ctx));
298 fprintf(stderr, MSG_PREFIX "failed to allocate context.\n");
304 ret = drmIoctl(fd, DRM_IOCTL_EXYNOS_G2D_GET_VER, &ver);
306 fprintf(stderr, MSG_PREFIX "failed to get version.\n");
311 ctx->major = ver.major;
312 ctx->minor = ver.minor;
314 printf(MSG_PREFIX "G2D version (%d.%d).\n", ctx->major, ctx->minor);
318 void g2d_fini(struct g2d_context *ctx)
324 * g2d_exec - start the dma to process all commands summited by g2d_flush().
326 * @ctx: a pointer to g2d_context structure.
328 int g2d_exec(struct g2d_context *ctx)
330 struct drm_exynos_g2d_exec exec;
333 if (ctx->cmdlist_nr == 0)
338 ret = drmIoctl(ctx->fd, DRM_IOCTL_EXYNOS_G2D_EXEC, &exec);
340 fprintf(stderr, MSG_PREFIX "failed to execute.\n");
350 * g2d_solid_fill - fill given buffer with given color data.
352 * @ctx: a pointer to g2d_context structure.
353 * @img: a pointer to g2d_image structure including image and buffer
355 * @x: x start position to buffer filled with given color data.
356 * @y: y start position to buffer filled with given color data.
357 * @w: width value to buffer filled with given color data.
358 * @h: height value to buffer filled with given color data.
361 g2d_solid_fill(struct g2d_context *ctx, struct g2d_image *img,
362 unsigned int x, unsigned int y, unsigned int w,
365 union g2d_bitblt_cmd_val bitblt;
366 union g2d_point_val pt;
368 if (g2d_check_space(ctx, 7, 1))
371 g2d_add_cmd(ctx, DST_SELECT_REG, G2D_SELECT_MODE_NORMAL);
372 g2d_add_cmd(ctx, DST_COLOR_MODE_REG, img->color_mode);
373 g2d_add_base_addr(ctx, img, g2d_dst);
374 g2d_add_cmd(ctx, DST_STRIDE_REG, img->stride);
376 if (x + w > img->width)
378 if (y + h > img->height)
383 g2d_add_cmd(ctx, DST_LEFT_TOP_REG, pt.val);
387 g2d_add_cmd(ctx, DST_RIGHT_BOTTOM_REG, pt.val);
389 g2d_add_cmd(ctx, SF_COLOR_REG, img->color);
392 bitblt.data.fast_solid_color_fill_en = 1;
393 g2d_add_cmd(ctx, BITBLT_COMMAND_REG, bitblt.val);
395 return g2d_flush(ctx);
399 * g2d_copy - copy contents in source buffer to destination buffer.
401 * @ctx: a pointer to g2d_context structure.
402 * @src: a pointer to g2d_image structure including image and buffer
403 * information to source.
404 * @dst: a pointer to g2d_image structure including image and buffer
405 * information to destination.
406 * @src_x: x start position to source buffer.
407 * @src_y: y start position to source buffer.
408 * @dst_x: x start position to destination buffer.
409 * @dst_y: y start position to destination buffer.
410 * @w: width value to source and destination buffers.
411 * @h: height value to source and destination buffers.
414 g2d_copy(struct g2d_context *ctx, struct g2d_image *src,
415 struct g2d_image *dst, unsigned int src_x, unsigned int src_y,
416 unsigned int dst_x, unsigned dst_y, unsigned int w,
419 union g2d_rop4_val rop4;
420 union g2d_point_val pt;
421 unsigned int src_w, src_h, dst_w, dst_h;
425 if (src_x + src->width > w)
426 src_w = src->width - src_x;
427 if (src_y + src->height > h)
428 src_h = src->height - src_y;
432 if (dst_x + dst->width > w)
433 dst_w = dst->width - dst_x;
434 if (dst_y + dst->height > h)
435 dst_h = dst->height - dst_y;
437 w = MIN(src_w, dst_w);
438 h = MIN(src_h, dst_h);
440 if (w <= 0 || h <= 0) {
441 fprintf(stderr, MSG_PREFIX "invalid width or height.\n");
445 if (g2d_check_space(ctx, 11, 2))
448 g2d_add_cmd(ctx, DST_SELECT_REG, G2D_SELECT_MODE_BGCOLOR);
449 g2d_add_cmd(ctx, DST_COLOR_MODE_REG, dst->color_mode);
450 g2d_add_base_addr(ctx, dst, g2d_dst);
451 g2d_add_cmd(ctx, DST_STRIDE_REG, dst->stride);
453 g2d_add_cmd(ctx, SRC_SELECT_REG, G2D_SELECT_MODE_NORMAL);
454 g2d_add_cmd(ctx, SRC_COLOR_MODE_REG, src->color_mode);
455 g2d_add_base_addr(ctx, src, g2d_src);
456 g2d_add_cmd(ctx, SRC_STRIDE_REG, src->stride);
460 g2d_add_cmd(ctx, SRC_LEFT_TOP_REG, pt.val);
461 pt.data.x = src_x + w;
462 pt.data.y = src_y + h;
463 g2d_add_cmd(ctx, SRC_RIGHT_BOTTOM_REG, pt.val);
467 g2d_add_cmd(ctx, DST_LEFT_TOP_REG, pt.val);
468 pt.data.x = dst_x + w;
469 pt.data.y = dst_y + h;
470 g2d_add_cmd(ctx, DST_RIGHT_BOTTOM_REG, pt.val);
473 rop4.data.unmasked_rop3 = G2D_ROP3_SRC;
474 g2d_add_cmd(ctx, ROP4_REG, rop4.val);
476 return g2d_flush(ctx);
480 * g2d_copy_with_scale - copy contents in source buffer to destination buffer
481 * scaling up or down properly.
483 * @ctx: a pointer to g2d_context structure.
484 * @src: a pointer to g2d_image structure including image and buffer
485 * information to source.
486 * @dst: a pointer to g2d_image structure including image and buffer
487 * information to destination.
488 * @src_x: x start position to source buffer.
489 * @src_y: y start position to source buffer.
490 * @src_w: width value to source buffer.
491 * @src_h: height value to source buffer.
492 * @dst_x: x start position to destination buffer.
493 * @dst_y: y start position to destination buffer.
494 * @dst_w: width value to destination buffer.
495 * @dst_h: height value to destination buffer.
496 * @negative: indicate that it uses color negative to source and
497 * destination buffers.
500 g2d_copy_with_scale(struct g2d_context *ctx, struct g2d_image *src,
501 struct g2d_image *dst, unsigned int src_x,
502 unsigned int src_y, unsigned int src_w,
503 unsigned int src_h, unsigned int dst_x,
504 unsigned int dst_y, unsigned int dst_w,
505 unsigned int dst_h, unsigned int negative)
507 union g2d_rop4_val rop4;
508 union g2d_point_val pt;
509 unsigned int scale, repeat_pad;
510 unsigned int scale_x, scale_y;
512 /* Sanitize this parameter to facilitate space computation below. */
516 if (src_w == dst_w && src_h == dst_h)
520 scale_x = g2d_get_scaling(src_w, dst_w);
521 scale_y = g2d_get_scaling(src_h, dst_h);
524 repeat_pad = src->repeat_mode == G2D_REPEAT_MODE_PAD ? 1 : 0;
526 if (src_x + src_w > src->width)
527 src_w = src->width - src_x;
528 if (src_y + src_h > src->height)
529 src_h = src->height - src_y;
531 if (dst_x + dst_w > dst->width)
532 dst_w = dst->width - dst_x;
533 if (dst_y + dst_h > dst->height)
534 dst_h = dst->height - dst_y;
536 if (src_w <= 0 || src_h <= 0 || dst_w <= 0 || dst_h <= 0) {
537 fprintf(stderr, MSG_PREFIX "invalid width or height.\n");
541 if (g2d_check_space(ctx, 12 + scale * 3 + negative + repeat_pad, 2))
544 g2d_add_cmd(ctx, DST_SELECT_REG, G2D_SELECT_MODE_BGCOLOR);
545 g2d_add_cmd(ctx, DST_COLOR_MODE_REG, dst->color_mode);
546 g2d_add_base_addr(ctx, dst, g2d_dst);
547 g2d_add_cmd(ctx, DST_STRIDE_REG, dst->stride);
549 g2d_add_cmd(ctx, SRC_SELECT_REG, G2D_SELECT_MODE_NORMAL);
550 g2d_add_cmd(ctx, SRC_COLOR_MODE_REG, src->color_mode);
552 g2d_add_cmd(ctx, SRC_REPEAT_MODE_REG, src->repeat_mode);
554 g2d_add_cmd(ctx, SRC_PAD_VALUE_REG, dst->color);
556 g2d_add_base_addr(ctx, src, g2d_src);
557 g2d_add_cmd(ctx, SRC_STRIDE_REG, src->stride);
560 rop4.data.unmasked_rop3 = G2D_ROP3_SRC;
563 g2d_add_cmd(ctx, BG_COLOR_REG, 0x00FFFFFF);
564 rop4.data.unmasked_rop3 ^= G2D_ROP3_DST;
567 g2d_add_cmd(ctx, ROP4_REG, rop4.val);
570 g2d_add_cmd(ctx, SRC_SCALE_CTRL_REG, G2D_SCALE_MODE_BILINEAR);
571 g2d_add_cmd(ctx, SRC_XSCALE_REG, scale_x);
572 g2d_add_cmd(ctx, SRC_YSCALE_REG, scale_y);
577 g2d_add_cmd(ctx, SRC_LEFT_TOP_REG, pt.val);
578 pt.data.x = src_x + src_w;
579 pt.data.y = src_y + src_h;
580 g2d_add_cmd(ctx, SRC_RIGHT_BOTTOM_REG, pt.val);
584 g2d_add_cmd(ctx, DST_LEFT_TOP_REG, pt.val);
585 pt.data.x = dst_x + dst_w;
586 pt.data.y = dst_y + dst_h;
587 g2d_add_cmd(ctx, DST_RIGHT_BOTTOM_REG, pt.val);
589 return g2d_flush(ctx);
593 * g2d_blend - blend image data in source and destination buffers.
595 * @ctx: a pointer to g2d_context structure.
596 * @src: a pointer to g2d_image structure including image and buffer
597 * information to source.
598 * @dst: a pointer to g2d_image structure including image and buffer
599 * information to destination.
600 * @src_x: x start position to source buffer.
601 * @src_y: y start position to source buffer.
602 * @dst_x: x start position to destination buffer.
603 * @dst_y: y start position to destination buffer.
604 * @w: width value to source and destination buffer.
605 * @h: height value to source and destination buffer.
606 * @op: blend operation type.
609 g2d_blend(struct g2d_context *ctx, struct g2d_image *src,
610 struct g2d_image *dst, unsigned int src_x,
611 unsigned int src_y, unsigned int dst_x, unsigned int dst_y,
612 unsigned int w, unsigned int h, enum e_g2d_op op)
614 union g2d_point_val pt;
615 union g2d_bitblt_cmd_val bitblt;
616 union g2d_blend_func_val blend;
617 unsigned int gem_space;
618 unsigned int src_w, src_h, dst_w, dst_h;
622 if (src_x + w > src->width)
623 src_w = src->width - src_x;
624 if (src_y + h > src->height)
625 src_h = src->height - src_y;
629 if (dst_x + w > dst->width)
630 dst_w = dst->width - dst_x;
631 if (dst_y + h > dst->height)
632 dst_h = dst->height - dst_y;
634 w = MIN(src_w, dst_w);
635 h = MIN(src_h, dst_h);
637 if (w <= 0 || h <= 0) {
638 fprintf(stderr, MSG_PREFIX "invalid width or height.\n");
642 if (!g2d_validate_select_mode(src->select_mode)) {
643 fprintf(stderr , MSG_PREFIX "invalid select mode for source.\n");
647 if (!g2d_validate_blending_op(op)) {
648 fprintf(stderr , MSG_PREFIX "unsupported blending operation.\n");
652 gem_space = src->select_mode == G2D_SELECT_MODE_NORMAL ? 2 : 1;
654 if (g2d_check_space(ctx, 12, gem_space))
660 if (op == G2D_OP_SRC || op == G2D_OP_CLEAR)
661 g2d_add_cmd(ctx, DST_SELECT_REG, G2D_SELECT_MODE_BGCOLOR);
663 g2d_add_cmd(ctx, DST_SELECT_REG, G2D_SELECT_MODE_NORMAL);
665 g2d_add_cmd(ctx, DST_COLOR_MODE_REG, dst->color_mode);
666 g2d_add_base_addr(ctx, dst, g2d_dst);
667 g2d_add_cmd(ctx, DST_STRIDE_REG, dst->stride);
669 g2d_add_cmd(ctx, SRC_SELECT_REG, src->select_mode);
670 g2d_add_cmd(ctx, SRC_COLOR_MODE_REG, src->color_mode);
672 switch (src->select_mode) {
673 case G2D_SELECT_MODE_NORMAL:
674 g2d_add_base_addr(ctx, src, g2d_src);
675 g2d_add_cmd(ctx, SRC_STRIDE_REG, src->stride);
677 case G2D_SELECT_MODE_FGCOLOR:
678 g2d_add_cmd(ctx, FG_COLOR_REG, src->color);
680 case G2D_SELECT_MODE_BGCOLOR:
681 g2d_add_cmd(ctx, BG_COLOR_REG, src->color);
685 bitblt.data.alpha_blend_mode = G2D_ALPHA_BLEND_MODE_ENABLE;
686 blend.val = g2d_get_blend_op(op);
687 g2d_add_cmd(ctx, BITBLT_COMMAND_REG, bitblt.val);
688 g2d_add_cmd(ctx, BLEND_FUNCTION_REG, blend.val);
692 g2d_add_cmd(ctx, SRC_LEFT_TOP_REG, pt.val);
693 pt.data.x = src_x + w;
694 pt.data.y = src_y + h;
695 g2d_add_cmd(ctx, SRC_RIGHT_BOTTOM_REG, pt.val);
699 g2d_add_cmd(ctx, DST_LEFT_TOP_REG, pt.val);
700 pt.data.x = dst_x + w;
701 pt.data.y = dst_y + h;
702 g2d_add_cmd(ctx, DST_RIGHT_BOTTOM_REG, pt.val);
704 return g2d_flush(ctx);
708 * g2d_scale_and_blend - apply scaling to source buffer and then blend to destination buffer
710 * @ctx: a pointer to g2d_context structure.
711 * @src: a pointer to g2d_image structure including image and buffer
712 * information to source.
713 * @dst: a pointer to g2d_image structure including image and buffer
714 * information to destination.
715 * @src_x: x start position to source buffer.
716 * @src_y: y start position to source buffer.
717 * @src_w: width value to source buffer.
718 * @src_h: height value to source buffer.
719 * @dst_x: x start position to destination buffer.
720 * @dst_y: y start position to destination buffer.
721 * @dst_w: width value to destination buffer.
722 * @dst_h: height value to destination buffer.
723 * @op: blend operation type.
726 g2d_scale_and_blend(struct g2d_context *ctx, struct g2d_image *src,
727 struct g2d_image *dst, unsigned int src_x, unsigned int src_y,
728 unsigned int src_w, unsigned int src_h, unsigned int dst_x,
729 unsigned int dst_y, unsigned int dst_w, unsigned int dst_h,
732 union g2d_point_val pt;
733 union g2d_bitblt_cmd_val bitblt;
734 union g2d_blend_func_val blend;
735 unsigned int scale, gem_space;
736 unsigned int scale_x, scale_y;
738 if (src_w == dst_w && src_h == dst_h)
742 scale_x = g2d_get_scaling(src_w, dst_w);
743 scale_y = g2d_get_scaling(src_h, dst_h);
746 if (src_x + src_w > src->width)
747 src_w = src->width - src_x;
748 if (src_y + src_h > src->height)
749 src_h = src->height - src_y;
751 if (dst_x + dst_w > dst->width)
752 dst_w = dst->width - dst_x;
753 if (dst_y + dst_h > dst->height)
754 dst_h = dst->height - dst_y;
756 if (src_w <= 0 || src_h <= 0 || dst_w <= 0 || dst_h <= 0) {
757 fprintf(stderr, MSG_PREFIX "invalid width or height.\n");
761 if (!g2d_validate_select_mode(src->select_mode)) {
762 fprintf(stderr , MSG_PREFIX "invalid select mode for source.\n");
766 if (!g2d_validate_blending_op(op)) {
767 fprintf(stderr , MSG_PREFIX "unsupported blending operation.\n");
771 gem_space = src->select_mode == G2D_SELECT_MODE_NORMAL ? 2 : 1;
773 if (g2d_check_space(ctx, 12 + scale * 3, gem_space))
779 if (op == G2D_OP_SRC || op == G2D_OP_CLEAR)
780 g2d_add_cmd(ctx, DST_SELECT_REG, G2D_SELECT_MODE_BGCOLOR);
782 g2d_add_cmd(ctx, DST_SELECT_REG, G2D_SELECT_MODE_NORMAL);
784 g2d_add_cmd(ctx, DST_COLOR_MODE_REG, dst->color_mode);
785 g2d_add_base_addr(ctx, dst, g2d_dst);
786 g2d_add_cmd(ctx, DST_STRIDE_REG, dst->stride);
788 g2d_add_cmd(ctx, SRC_SELECT_REG, src->select_mode);
789 g2d_add_cmd(ctx, SRC_COLOR_MODE_REG, src->color_mode);
791 switch (src->select_mode) {
792 case G2D_SELECT_MODE_NORMAL:
793 g2d_add_base_addr(ctx, src, g2d_src);
794 g2d_add_cmd(ctx, SRC_STRIDE_REG, src->stride);
796 case G2D_SELECT_MODE_FGCOLOR:
797 g2d_add_cmd(ctx, FG_COLOR_REG, src->color);
799 case G2D_SELECT_MODE_BGCOLOR:
800 g2d_add_cmd(ctx, BG_COLOR_REG, src->color);
805 g2d_add_cmd(ctx, SRC_SCALE_CTRL_REG, G2D_SCALE_MODE_BILINEAR);
806 g2d_add_cmd(ctx, SRC_XSCALE_REG, scale_x);
807 g2d_add_cmd(ctx, SRC_YSCALE_REG, scale_y);
810 bitblt.data.alpha_blend_mode = G2D_ALPHA_BLEND_MODE_ENABLE;
811 blend.val = g2d_get_blend_op(op);
812 g2d_add_cmd(ctx, BITBLT_COMMAND_REG, bitblt.val);
813 g2d_add_cmd(ctx, BLEND_FUNCTION_REG, blend.val);
817 g2d_add_cmd(ctx, SRC_LEFT_TOP_REG, pt.val);
818 pt.data.x = src_x + src_w;
819 pt.data.y = src_y + src_h;
820 g2d_add_cmd(ctx, SRC_RIGHT_BOTTOM_REG, pt.val);
824 g2d_add_cmd(ctx, DST_LEFT_TOP_REG, pt.val);
825 pt.data.x = dst_x + dst_w;
826 pt.data.y = dst_y + dst_h;
827 g2d_add_cmd(ctx, DST_RIGHT_BOTTOM_REG, pt.val);
829 return g2d_flush(ctx);