1/*
2 * Copyright (C) Texas Instruments - http://www.ti.com/
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef __RGZ_2D__
17#define __RGZ_2D__
18
19#include <linux/bltsville.h>
20
21/*
22 * Maximum number of layers used to generate subregion rectangles in a
23 * horizontal region.
24 */
25#define RGZ_MAXLAYERS 13
26
27/*
28 * Maximum number of layers the regionizer will accept as input. Account for an
29 * additional 'background layer' to generate empty subregion rectangles.
30 */
31#define RGZ_INPUT_MAXLAYERS (RGZ_MAXLAYERS - 1)
32
33/*
34 * Regionizer data
35 *
36 * This is an oqaque structure passed in by the client
37 */
38struct rgz;
39typedef struct rgz rgz_t;
40
41/*
42 * With an open framebuffer file descriptor get the geometry of
43 * the device
44 */
45int rgz_get_screengeometry(int fd, struct bvsurfgeom *geom, int fmt);
46
47/*
48 * Regionizer input parameters
49 */
50struct rgz_in_hwc {
51    int flags;
52    int layerno;
53    hwc_layer_1_t *layers;
54    struct bvsurfgeom *dstgeom;
55};
56
57typedef struct rgz_in_params {
58    int op; /* See RGZ_IN_* */
59    union {
60        struct rgz_in_hwc hwc;
61    } data;
62} rgz_in_params_t;
63
64/*
65 * Validate whether the HWC layers can be rendered
66 *
67 * Arguments (rgz_in_params_t):
68 * op                RGZ_IN_HWCCHK
69 * data.hwc.layers   HWC layer array
70 * data.hwc.layerno  HWC layer array size
71 *
72 * Returns:
73 * rv = RGZ_ALL, -1 failure
74 */
75#define RGZ_IN_HWCCHK 1
76
77/*
78 * Regionize the HWC layers
79 *
80 * This generates region data which can be used with regionizer
81 * output function. This call will validate whether all or some of the
82 * layers can be rendered.
83 *
84 * The caller must use rgz_release when done with the region data
85 *
86 * Arguments (rgz_in_params_t):
87 * op                RGZ_IN_HWC
88 * data.hwc.layers   HWC layer array
89 * data.hwc.layerno  HWC layer array size
90 *
91 * Returns:
92 * rv = RGZ_ALL, -1 failure
93 */
94#define RGZ_IN_HWC 2
95
96int rgz_in(rgz_in_params_t *param, rgz_t *rgz);
97
98/* This means all layers can be blitted */
99#define RGZ_ALL 1
100
101/*
102 * Free regionizer resources
103 */
104void rgz_release(rgz_t *rgz);
105
106/*
107 * Regionizer output operations
108 */
109struct rgz_out_bvcmd {
110    void *cmdp;
111    int cmdlen;
112    struct bvsurfgeom *dstgeom;
113    int noblend;
114    buffer_handle_t out_hndls[RGZ_INPUT_MAXLAYERS]; /* OUTPUT */
115    int out_nhndls; /* OUTPUT */
116    int out_blits; /* OUTPUT */
117};
118
119struct rgz_out_svg {
120    int dispw;
121    int disph;
122    int htmlw;
123    int htmlh;
124};
125
126struct rgz_out_bvdirect {
127    struct bvbuffdesc *dstdesc;
128    struct bvsurfgeom *dstgeom;
129    int noblend;
130};
131
132typedef struct rgz_out_params {
133    int op; /* See RGZ_OUT_* */
134    union {
135        struct rgz_out_bvcmd bvc;
136        struct rgz_out_bvdirect bv;
137        struct rgz_out_svg svg;
138    } data;
139} rgz_out_params_t;
140
141/*
142 * Regionizer output commands
143 */
144
145/*
146 * Output SVG from regionizer
147 *
148 * rgz_out_params_t:
149 *
150 * op              RGZ_OUT_SVG
151 * data.svg.dispw
152 * data.svg.disph  Display width and height these values will be the
153 *                 viewport dimensions i.e. the logical coordinate space
154 *                 rather than the physical size
155 * data.svg.htmlw
156 * data.svg.htmlh  HTML output dimensions
157 */
158#define RGZ_OUT_SVG 0
159
160/*
161 * This commands generates bltsville command data structures for HWC which will
162 * paint layer by layer
163 *
164 * rgz_out_params_t:
165 *
166 * op                   RGZ_OUT_BVCMD_PAINT
167 * data.bvc.cmdp        Pointer to buffer with cmd data
168 * data.bvc.cmdlen      length of cmdp
169 * data.bvc.dstgeom     bltsville struct describing the destination geometry
170 * data.bvc.noblend     Test option to disable blending
171 * data.bvc.out_hndls   Array of buffer handles (OUTPUT)
172 * data.bvc.out_nhndls  Number of buffer handles (OUTPUT)
173 * data.bvc.out_blits   Number of blits (OUTPUT)
174 */
175#define RGZ_OUT_BVCMD_PAINT 1
176
177/*
178 * This commands generates bltsville command data structures for HWC which will
179 * render via regions. This will involve a complete redraw of the screen.
180 *
181 * See RGZ_OUT_BVCMD_PAINT
182 */
183#define RGZ_OUT_BVCMD_REGION 2
184
185/*
186 * Perform actual blits painting each layer from back to front - this is a test
187 * command
188 *
189 * rgz_out_params_t:
190 *
191 * op                  RGZ_OUT_BVDIRECT_PAINT
192 * data.bv.dstdesc     bltsville struct describing the destination buffer
193 * data.bv.dstgeom     bltsville struct describing the destination geometry
194 * data.bv.list        List of HWC layers to blit, only HWC_OVERLAY layers
195 *                     will be rendered
196 * data.bv.noblend     Test option to disable blending
197 */
198#define RGZ_OUT_BVDIRECT_PAINT 3
199/*
200 * Perform actual blits where each blit is a subregion - this is a test mode
201 */
202#define RGZ_OUT_BVDIRECT_REGION 5
203
204int rgz_out(rgz_t *rgz, rgz_out_params_t* params);
205
206/*
207 * Produce instrumented logging of layer data
208 */
209void rgz_profile_hwc(hwc_display_contents_1_t* list, int dispw, int disph);
210
211/*
212 * ----------------------------------
213 * IMPLEMENTATION DETAILS FOLLOW HERE
214 * ----------------------------------
215 */
216
217/*
218 * Regionizer blit data structures
219 */
220typedef struct blit_rect {
221    int left, top, right, bottom;
222} blit_rect_t;
223
224/*
225 * A hregion is a horizontal area generated from the intersection of layers
226 * for a given composition.
227 *
228 * ----------------------------------------
229 * | layer 0                              |
230 * |           xxxxxxxxxxxxxxxxxx         |
231 * |           x layer 1        x         |
232 * |           x                x         |
233 * |           x        xxxxxxxxxxxxxxxxxxx
234 * |           x        x layer 2         x
235 * |           x        x                 x
236 * |           xxxxxxxxxx                 x
237 * |                    x                 x
238 * |                    x                 x
239 * ---------------------xxxxxxxxxxxxxxxxxxx
240 *
241 * This can be broken up into a number of horizontal regions:
242 *
243 * ----------------------------------------
244 * | H1                                l0 |
245 * |-----------xxxxxxxxxxxxxxxxxx---------|
246 * | H2        x                x         |
247 * |        l0 x            l01 x      l0 |
248 * |-----------x--------xxxxxxxxxxxxxxxxxxx
249 * | H3        x        x       x         x
250 * |        l0 x    l01 x  l012 x     l02 x
251 * |-----------xxxxxxxxxxxxxxxxxx---------x
252 * | H4                 x                 x
253 * |                 l0 x             l02 x
254 * ---------------------xxxxxxxxxxxxxxxxxxx
255 *
256 * Each hregion is just an array of rectangles. By accounting for the layers
257 * at different z-order, and hregion becomes a multi-dimensional array e.g. in
258 * the diagram above H4 has 2 sub-regions, layer 0 intersects with the first
259 * region and layers 0 and 2 intersect with the second region.
260 */
261#define RGZ_SUBREGIONMAX ((RGZ_MAXLAYERS << 1) - 1)
262#define RGZ_MAX_BLITS (RGZ_SUBREGIONMAX * RGZ_SUBREGIONMAX)
263
264typedef struct rgz_layer {
265    hwc_layer_1_t *hwc_layer;
266    int buffidx;
267    int dirty_count;
268    void* dirty_hndl;
269} rgz_layer_t;
270
271typedef struct blit_hregion {
272    blit_rect_t rect;
273    rgz_layer_t *rgz_layers[RGZ_MAXLAYERS];
274    int nlayers;
275    int nsubregions;
276    blit_rect_t blitrects[RGZ_MAXLAYERS][RGZ_SUBREGIONMAX]; /* z-order | rectangle */
277} blit_hregion_t;
278
279enum { RGZ_STATE_INIT = 1, RGZ_REGION_DATA = 2} ;
280
281struct rgz {
282    /* All fields here are opaque to the caller */
283    blit_hregion_t *hregions;
284    int nhregions;
285    int state;
286    unsigned int rgz_layerno;
287    rgz_layer_t rgz_layers[RGZ_MAXLAYERS];
288};
289
290#endif /* __RGZ_2D__ */
291