• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (C) 2013-2016 Freescale Semiconductor, Inc.
3  *  Copyright 2017-2019 NXP
4  *
5  *  Permission is hereby granted, free of charge, to any person obtaining
6  *  a copy of this software and associated documentation files (the
7  *  'Software'), to deal in the Software without restriction, including
8  *  without limitation the rights to use, copy, modify, merge, publish,
9  *  distribute, sub license, and/or sell copies of the Software, and to
10  *  permit persons to whom the Software is furnished to do so, subject
11  *  to the following conditions:
12 
13  *  The above copyright notice and this permission notice (including the
14  *  next paragraph) shall be included in all copies or substantial
15  *  portions of the Software.
16 
17  *  THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20  *  IN NO EVENT SHALL VIVANTE AND/OR ITS SUPPLIERS BE LIABLE FOR ANY
21  *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  *  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  *  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  */
26 
27 /*
28  *  g2d.h
29  *  Gpu 2d header file declare all g2d APIs exposed to application
30  *  History :
31  *  Date(y.m.d)        Author            Version        Description
32  *  2012-10-22         Li Xianzhong      0.1            Created
33  *  2013-02-22         Li Xianzhong      0.2            g2d_copy API is added
34  *  2013-03-21         Li Xianzhong      0.4            g2d clear/rotation/flip APIs are supported
35  *  2013-04-09         Li Xianzhong      0.5            g2d alpha blending feature is enhanced
36  *  2013-05-17         Li Xianzhong      0.6            support vg core in g2d library
37  *  2013-12-23         Li Xianzhong      0.7            support blend dim feature
38  *  2014-03-20         Li Xianzhong      0.8            support pre-multipied & de-mutlipy out alpha
39  *  2015-04-10         Meng Mingming     0.9            support multiple source blit
40  *  2015-11-03         Meng Mingming     1.0            support query 2D hardware type and feature
41  *  2016-05-24         Meng Mingming     1.1            support get g2d_buf from dma fd
42  *  2017-07-04         Prabhu Sundararaj 1.2            support get g2d_buf to export dma fd
43  *  2018-04-24         Yuchou Gan        1.3            Add AMPHION_TILED support
44  *  2019-12-30         Yong Gan          1.4            Add G2D_TILED_STATUS support
45  *  2020-01-08         Li Xianzhong      1.5            support BT_601 and BT_709
46 */
47 
48 #ifndef __G2D_H__
49 #define __G2D_H__
50 
51 #ifdef __cplusplus
52 extern "C"  {
53 #endif
54 
55 #define G2D_VERSION_MAJOR   1
56 #define G2D_VERSION_MINOR   2
57 #define G2D_VERSION_PATCH   0
58 
59 enum g2d_format {
60 // rgb formats
61     G2D_RGB565               = 0,
62     G2D_RGBA8888             = 1,
63     G2D_RGBX8888             = 2,
64     G2D_BGRA8888             = 3,
65     G2D_BGRX8888             = 4,
66     G2D_BGR565               = 5,
67 
68     G2D_ARGB8888             = 6,
69     G2D_ABGR8888             = 7,
70     G2D_XRGB8888             = 8,
71     G2D_XBGR8888             = 9,
72     G2D_RGB888               = 10,
73 
74 // yuv formats
75     G2D_NV12                 = 20,
76     G2D_I420                 = 21,
77     G2D_YV12                 = 22,
78     G2D_NV21                 = 23,
79     G2D_YUYV                 = 24,
80     G2D_YVYU                 = 25,
81     G2D_UYVY                 = 26,
82     G2D_VYUY                 = 27,
83     G2D_NV16                 = 28,
84     G2D_NV61                 = 29,
85     G2D_FORMAT_UNKNOWN       = -1,
86 };
87 
88 enum g2d_blend_func {
89 // basic blend
90     G2D_ZERO                  = 0,
91     G2D_ONE                   = 1,
92     G2D_SRC_ALPHA             = 2,
93     G2D_ONE_MINUS_SRC_ALPHA   = 3,
94     G2D_DST_ALPHA             = 4,
95     G2D_ONE_MINUS_DST_ALPHA   = 5,
96 
97 // extensive blend is set with basic blend together,
98 // such as, G2D_ONE | G2D_PRE_MULTIPLIED_ALPHA
99     G2D_PRE_MULTIPLIED_ALPHA  = 0x10,
100     G2D_DEMULTIPLY_OUT_ALPHA  = 0x20,
101 };
102 
103 enum g2d_cap_mode {
104     G2D_BLEND                 = 0,
105     G2D_DITHER                = 1,
106     G2D_GLOBAL_ALPHA          = 2,  // only support source global alpha
107     G2D_BLEND_DIM             = 3,  // support special blend effect
108     G2D_BLUR                  = 4,  // blur effect
109     G2D_YUV_BT_601            = 5,  // yuv BT.601
110     G2D_YUV_BT_709            = 6,  // yuv BT.709
111 };
112 
113 enum g2d_feature {
114     G2D_SCALING               = 0,
115     G2D_ROTATION,
116     G2D_SRC_YUV,
117     G2D_DST_YUV,
118     G2D_MULTI_SOURCE_BLT,
119 };
120 
121 enum g2d_rotation {
122     G2D_ROTATION_0            = 0,
123     G2D_ROTATION_90           = 1,
124     G2D_ROTATION_180          = 2,
125     G2D_ROTATION_270          = 3,
126     G2D_FLIP_H                = 4,
127     G2D_FLIP_V                = 5,
128 };
129 
130 enum g2d_cache_mode {
131     G2D_CACHE_CLEAN           = 0,
132     G2D_CACHE_FLUSH           = 1,
133     G2D_CACHE_INVALIDATE      = 2,
134 };
135 
136 enum g2d_hardware_type {
137     G2D_HARDWARE_2D           = 0,  // default type
138     G2D_HARDWARE_VG           = 1,
139 };
140 
141 enum g2d_status {
142     G2D_STATUS_FAIL           = -1,
143     G2D_STATUS_OK             = 0,
144     G2D_STATUS_NOT_SUPPORTED  = 1,
145 };
146 
147 struct g2d_surface {
148     enum g2d_format format;
149 
150     int planes[3];  // surface buffer addresses are set in physical planes separately
151                   // RGB:  planes[0] - RGB565/RGBA8888/RGBX8888/BGRA8888/BRGX8888
152                   // NV12: planes[0] - Y, planes[1] - packed UV
153                   // I420: planes[0] - Y, planes[1] - U, planes[2] - V
154                   // YV12: planes[0] - Y, planes[1] - V, planes[2] - U
155                   // NV21: planes[0] - Y, planes[1] - packed VU
156                   // YUYV: planes[0] - packed YUYV
157                   // YVYU: planes[0] - packed YVYU
158                   // UYVY: planes[0] - packed UYVY
159                   // VYUY: planes[0] - packed VYUY
160                   // NV16: planes[0] - Y, planes[1] - packed UV
161                   // NV61: planes[0] - Y, planes[1] - packed VU
162 
163     // blit rectangle in surface
164     int left;
165     int top;
166     int right;
167     int bottom;
168     int stride;                     // < buffer stride, in Pixels
169     int width;                      // < surface width, in Pixels
170     int height;                     // < surface height, in Pixels
171     enum g2d_blend_func blendfunc;  // < alpha blending parameters
172     int global_alpha;               // < value is 0 ~ 255
173     // clrcolor format is RGBA8888, used as dst for clear, as src for blend dim
174     int clrcolor;
175 
176     // rotation degree
177     enum g2d_rotation rot;
178 };
179 
180 struct g2d_surface_pair {
181     struct g2d_surface s;
182     struct g2d_surface d;
183 };
184 
185 struct g2d_buf {
186     void *buf_handle;
187     void *buf_vaddr;
188     int  buf_paddr;
189     int  buf_size;
190 };
191 
192 int g2d_open(void **handle);
193 int g2d_close(void *handle);
194 
195 int g2d_make_current(void *handle, enum g2d_hardware_type type);
196 
197 int g2d_clear(void *handle, struct g2d_surface *area);
198 int g2d_blit(void *handle, struct g2d_surface *src, struct g2d_surface *dst);
199 int g2d_copy(void *handle, struct g2d_buf *d, struct g2d_buf* s, int size);
200 int g2d_multi_blit(void *handle, struct g2d_surface_pair *sp[], int layers);
201 
202 int g2d_query_hardware(void *handle, enum g2d_hardware_type type, int *available);
203 int g2d_query_feature(void *handle, enum g2d_feature feature, int *available);
204 int g2d_query_cap(void *handle, enum g2d_cap_mode cap, int *enable);
205 int g2d_enable(void *handle, enum g2d_cap_mode cap);
206 int g2d_disable(void *handle, enum g2d_cap_mode cap);
207 
208 int g2d_cache_op(struct g2d_buf *buf, enum g2d_cache_mode op);
209 struct g2d_buf *g2d_alloc(int size, int cacheable);
210 struct g2d_buf *g2d_buf_from_fd(int fd);
211 int g2d_buf_export_fd(struct g2d_buf *);
212 struct g2d_buf *g2d_buf_from_virt_addr(void *vaddr, int size);
213 int g2d_free(struct g2d_buf *buf);
214 
215 int g2d_flush(void *handle);
216 int g2d_finish(void *handle);
217 
218 #ifdef __cplusplus
219 }
220 #endif
221 
222 #endif
223