diff options
Diffstat (limited to 'recipes-graphics/wayland/weston/0009-MGS-1284-xwld-Re-implement-weston-2d-renderer-with-p.patch')
-rw-r--r-- | recipes-graphics/wayland/weston/0009-MGS-1284-xwld-Re-implement-weston-2d-renderer-with-p.patch | 2843 |
1 files changed, 0 insertions, 2843 deletions
diff --git a/recipes-graphics/wayland/weston/0009-MGS-1284-xwld-Re-implement-weston-2d-renderer-with-p.patch b/recipes-graphics/wayland/weston/0009-MGS-1284-xwld-Re-implement-weston-2d-renderer-with-p.patch deleted file mode 100644 index f48785f1..00000000 --- a/recipes-graphics/wayland/weston/0009-MGS-1284-xwld-Re-implement-weston-2d-renderer-with-p.patch +++ /dev/null | |||
@@ -1,2843 +0,0 @@ | |||
1 | From 7bcbb14a149d0955176855e8ab6289cf68d099e5 Mon Sep 17 00:00:00 2001 | ||
2 | From: "yong.gan" <yong.gan@nxp.com> | ||
3 | Date: Fri, 11 Mar 2016 10:55:48 +0800 | ||
4 | Subject: [PATCH 1/3] MGS-1284: xwld: Re-implement weston 2d renderer with | ||
5 | porting g2d API | ||
6 | |||
7 | Use G2D API to replace Gal2D API. | ||
8 | Fix the errors in multi display mode. | ||
9 | Use the standard FB API to operate the frame buffer. | ||
10 | |||
11 | Date: Feb 22, 2016 | ||
12 | Upstream Status: Inappropriate [i.MX specific] | ||
13 | |||
14 | Signed-off-by: Yong Gan <yong.gan@freescale.com> | ||
15 | --- | ||
16 | Makefile.am | 16 +- | ||
17 | src/compositor-fbdev.c | 74 +-- | ||
18 | src/g2d-renderer.c | 1175 +++++++++++++++++++++++++++++++++++++++++++ | ||
19 | src/g2d-renderer.h | 48 ++ | ||
20 | src/gal2d-renderer.c | 1307 ------------------------------------------------ | ||
21 | src/gal2d-renderer.h | 50 -- | ||
22 | 6 files changed, 1255 insertions(+), 1415 deletions(-) | ||
23 | create mode 100644 src/g2d-renderer.c | ||
24 | create mode 100644 src/g2d-renderer.h | ||
25 | delete mode 100644 src/gal2d-renderer.c | ||
26 | delete mode 100644 src/gal2d-renderer.h | ||
27 | |||
28 | Index: weston-1.11.1/Makefile.am | ||
29 | =================================================================== | ||
30 | --- weston-1.11.1.orig/Makefile.am 2017-01-14 08:59:52.293865810 -0600 | ||
31 | +++ weston-1.11.1/Makefile.am 2017-01-14 09:08:38.000000000 -0600 | ||
32 | @@ -247,16 +247,16 @@ | ||
33 | src/vertex-clipping.h \ | ||
34 | shared/helpers.h | ||
35 | endif | ||
36 | -module_LTLIBRARIES += gal2d-renderer.la | ||
37 | -gal2d_renderer_la_LDFLAGS = -module -avoid-version | ||
38 | -gal2d_renderer_la_LIBADD = $(COMPOSITOR_LIBS) $(EGL_LIBS) | ||
39 | -gal2d_renderer_la_CFLAGS = \ | ||
40 | +module_LTLIBRARIES += g2d-renderer.la | ||
41 | +g2d_renderer_la_LDFLAGS = -module -avoid-version | ||
42 | +g2d_renderer_la_LIBADD = $(COMPOSITOR_LIBS) $(EGL_LIBS) -lg2d | ||
43 | +g2d_renderer_la_CFLAGS = \ | ||
44 | $(COMPOSITOR_CFLAGS) \ | ||
45 | $(EGL_CFLAGS) \ | ||
46 | - $(GCC_CFLAGS) | ||
47 | -gal2d_renderer_la_SOURCES = \ | ||
48 | - src/gal2d-renderer.h \ | ||
49 | - src/gal2d-renderer.c \ | ||
50 | + $(GCC_CFLAGS) -DHAVE_G2D | ||
51 | +g2d_renderer_la_SOURCES = \ | ||
52 | + src/g2d-renderer.h \ | ||
53 | + src/g2d-renderer.c \ | ||
54 | src/vertex-clipping.c \ | ||
55 | src/vertex-clipping.h | ||
56 | |||
57 | Index: weston-1.11.1/src/compositor-fbdev.c | ||
58 | =================================================================== | ||
59 | --- weston-1.11.1.orig/src/compositor-fbdev.c 2017-01-14 08:59:52.473866702 -0600 | ||
60 | +++ weston-1.11.1/src/compositor-fbdev.c 2017-01-14 09:19:12.000000000 -0600 | ||
61 | @@ -50,7 +50,7 @@ | ||
62 | #include "libinput-seat.h" | ||
63 | #include "gl-renderer.h" | ||
64 | #include "presentation-time-server-protocol.h" | ||
65 | -#include "gal2d-renderer.h" | ||
66 | +#include "g2d-renderer.h" | ||
67 | |||
68 | struct fbdev_backend { | ||
69 | struct weston_backend base; | ||
70 | @@ -60,7 +60,7 @@ | ||
71 | struct udev *udev; | ||
72 | struct udev_input input; | ||
73 | int use_pixman; | ||
74 | - int use_gal2d; | ||
75 | + int use_g2d; | ||
76 | uint32_t output_transform; | ||
77 | struct wl_listener session_listener; | ||
78 | NativeDisplayType display; | ||
79 | @@ -102,7 +102,7 @@ | ||
80 | }; | ||
81 | |||
82 | struct gl_renderer_interface *gl_renderer; | ||
83 | -struct gal2d_renderer_interface *gal2d_renderer; | ||
84 | +struct g2d_renderer_interface *g2d_renderer; | ||
85 | |||
86 | static const char default_seat[] = "seat0"; | ||
87 | |||
88 | @@ -519,36 +519,10 @@ | ||
89 | if (backend->use_pixman) { | ||
90 | if (pixman_renderer_output_create(&output->base) < 0) | ||
91 | goto out_hw_surface; | ||
92 | - } else if(backend->use_gal2d) { | ||
93 | - | ||
94 | - char* fbenv = getenv("FB_FRAMEBUFFER_0"); | ||
95 | - setenv("FB_FRAMEBUFFER_0", device, 1); | ||
96 | - output->display = fbGetDisplay(backend->compositor->wl_display); | ||
97 | - if (output->display == NULL) { | ||
98 | - fprintf(stderr, "failed to get display\n"); | ||
99 | - return 0; | ||
100 | - } | ||
101 | - | ||
102 | - output->window = fbCreateWindow(output->display, -1, -1, 0, 0); | ||
103 | - if (output->window == NULL) { | ||
104 | - fprintf(stderr, "failed to create window\n"); | ||
105 | - return 0; | ||
106 | - } | ||
107 | - /* restore the previous value*/ | ||
108 | - if(fbenv != NULL) | ||
109 | - { | ||
110 | - setenv("FB_FRAMEBUFFER_0", fbenv, 1); | ||
111 | - } | ||
112 | - else | ||
113 | - { | ||
114 | - unsetenv("FB_FRAMEBUFFER_0"); | ||
115 | - } | ||
116 | - | ||
117 | - | ||
118 | - if (gal2d_renderer->output_create(&output->base, | ||
119 | - output->display, | ||
120 | - (NativeWindowType)output->window) < 0) { | ||
121 | - weston_log("gal_renderer_output_create failed.\n"); | ||
122 | + } else if(backend->use_g2d) { | ||
123 | + if (g2d_renderer->output_create(&output->base, | ||
124 | + backend->compositor->wl_display, device) < 0) { | ||
125 | + weston_log("g2d_renderer_output_create failed.\n"); | ||
126 | goto out_hw_surface; | ||
127 | } | ||
128 | |||
129 | @@ -607,8 +581,8 @@ | ||
130 | if (backend->use_pixman) { | ||
131 | if (base->renderer_state != NULL) | ||
132 | pixman_renderer_output_destroy(base); | ||
133 | - } else if (backend->use_gal2d) { | ||
134 | - gal2d_renderer->output_destroy(base); | ||
135 | + } else if (backend->use_g2d) { | ||
136 | + g2d_renderer->output_destroy(base); | ||
137 | } else { | ||
138 | gl_renderer->output_destroy(base); | ||
139 | } | ||
140 | @@ -820,8 +794,8 @@ | ||
141 | backend->base.restore = fbdev_restore; | ||
142 | |||
143 | backend->prev_state = WESTON_COMPOSITOR_ACTIVE; | ||
144 | - backend->use_pixman = !(param->use_gl || param->use_gal2d); | ||
145 | - backend->use_gal2d = param->use_gal2d; | ||
146 | + backend->use_pixman = !(param->use_gl || param->use_g2d); | ||
147 | + backend->use_g2d = param->use_g2d; | ||
148 | backend->output_transform = param->output_transform; | ||
149 | |||
150 | weston_setup_vt_switch_bindings(compositor); | ||
151 | @@ -830,21 +804,21 @@ | ||
152 | if (pixman_renderer_init(compositor) < 0) | ||
153 | goto out_launcher; | ||
154 | } | ||
155 | - else if (backend->use_gal2d) { | ||
156 | + else if (backend->use_g2d) { | ||
157 | int x = 0, y = 0; | ||
158 | int i=0; | ||
159 | int count = 0; | ||
160 | int k=0, dispCount = 0; | ||
161 | char displays[5][32]; | ||
162 | - gal2d_renderer = weston_load_module("gal2d-renderer.so", | ||
163 | - "gal2d_renderer_interface"); | ||
164 | - if (!gal2d_renderer) { | ||
165 | - weston_log("could not load gal2d renderer\n"); | ||
166 | + g2d_renderer = weston_load_module("g2d-renderer.so", | ||
167 | + "g2d_renderer_interface"); | ||
168 | + if (!g2d_renderer) { | ||
169 | + weston_log("could not load g2d renderer\n"); | ||
170 | goto out_launcher; | ||
171 | } | ||
172 | |||
173 | - if (gal2d_renderer->create(backend->compositor) < 0) { | ||
174 | - weston_log("gal2d_renderer_create failed.\n"); | ||
175 | + if (g2d_renderer->create(backend->compositor) < 0) { | ||
176 | + weston_log("g2d_renderer_create failed.\n"); | ||
177 | goto out_launcher; | ||
178 | } | ||
179 | |||
180 | @@ -893,7 +867,7 @@ | ||
181 | goto out_launcher; | ||
182 | } | ||
183 | } | ||
184 | - if(!backend->use_gal2d) | ||
185 | + if(!backend->use_g2d) | ||
186 | if (fbdev_output_create(backend, 0, 0, param->device) < 0) | ||
187 | goto out_launcher; | ||
188 | |||
189 | @@ -922,13 +896,8 @@ | ||
190 | * udev, rather than passing a device node in as a parameter. */ | ||
191 | config->tty = 0; /* default to current tty */ | ||
192 | config->device = "/dev/fb0"; /* default frame buffer */ | ||
193 | -#ifdef ENABLE_EGL | ||
194 | - config->use_gl = 1; | ||
195 | - config->use_gal2d = 0; | ||
196 | -#else | ||
197 | config->use_gl = 0; | ||
198 | - config->use_gal2d = 1; | ||
199 | -#endif | ||
200 | + config->use_g2d = 0; | ||
201 | config->output_transform = WL_OUTPUT_TRANSFORM_NORMAL; | ||
202 | } | ||
203 | |||
204 | Index: weston-1.11.1/src/g2d-renderer.c | ||
205 | =================================================================== | ||
206 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
207 | +++ weston-1.11.1/src/g2d-renderer.c 2017-01-14 09:08:38.000000000 -0600 | ||
208 | @@ -0,0 +1,1175 @@ | ||
209 | +/* | ||
210 | + * Copyright (c) 2016 Freescale Semiconductor, Inc. | ||
211 | + * Copyright © 2012 Intel Corporation | ||
212 | + * Copyright © 2015 Collabora, Ltd. | ||
213 | + * | ||
214 | + * Permission is hereby granted, free of charge, to any person obtaining | ||
215 | + * a copy of this software and associated documentation files (the | ||
216 | + * "Software"), to deal in the Software without restriction, including | ||
217 | + * without limitation the rights to use, copy, modify, merge, publish, | ||
218 | + * distribute, sublicense, and/or sell copies of the Software, and to | ||
219 | + * permit persons to whom the Software is furnished to do so, subject to | ||
220 | + * the following conditions: | ||
221 | + * | ||
222 | + * The above copyright notice and this permission notice (including the | ||
223 | + * next paragraph) shall be included in all copies or substantial | ||
224 | + * portions of the Software. | ||
225 | + * | ||
226 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
227 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
228 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
229 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
230 | + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
231 | + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
232 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
233 | + * SOFTWARE. | ||
234 | + */ | ||
235 | + | ||
236 | +#define _GNU_SOURCE | ||
237 | + | ||
238 | +#include <stdlib.h> | ||
239 | +#include <string.h> | ||
240 | +#include <ctype.h> | ||
241 | +#include <float.h> | ||
242 | +#include <assert.h> | ||
243 | +#include <pthread.h> | ||
244 | +#include <linux/fb.h> | ||
245 | +#include <sys/ioctl.h> | ||
246 | +#include <fcntl.h> | ||
247 | +#include <unistd.h> | ||
248 | + | ||
249 | +#include "compositor.h" | ||
250 | +#include "g2d-renderer.h" | ||
251 | +#include "vertex-clipping.h" | ||
252 | +#include "shared/helpers.h" | ||
253 | +#include "HAL/gc_hal_eglplatform.h" | ||
254 | +#include "g2dExt.h" | ||
255 | + | ||
256 | +#define BUFFER_DAMAGE_COUNT 2 | ||
257 | + | ||
258 | +typedef struct _g2dRECT | ||
259 | +{ | ||
260 | + int left; | ||
261 | + int top; | ||
262 | + int right; | ||
263 | + int bottom; | ||
264 | +} g2dRECT; | ||
265 | + | ||
266 | +struct fb_screeninfo { | ||
267 | + struct fb_var_screeninfo varinfo; | ||
268 | + struct fb_fix_screeninfo fixinfo; | ||
269 | + unsigned int x_resolution; | ||
270 | + unsigned int y_resolution; | ||
271 | + size_t buffer_length; /* length of frame buffer memory in bytes */ | ||
272 | + size_t physical; | ||
273 | + enum g2d_format pixel_format; /* frame buffer pixel format */ | ||
274 | +}; | ||
275 | + | ||
276 | +struct g2d_output_state { | ||
277 | + int current_buffer; | ||
278 | + pixman_region32_t buffer_damage[BUFFER_DAMAGE_COUNT]; | ||
279 | + struct g2d_surfaceEx *renderSurf; | ||
280 | + int nNumBuffers; | ||
281 | + int activebuffer; | ||
282 | + struct g2d_surfaceEx offscreenSurface; | ||
283 | + struct g2d_buf *offscreen_buf; | ||
284 | + struct fb_screeninfo fb_info; | ||
285 | + int directBlit; | ||
286 | + int width; | ||
287 | + int height; | ||
288 | + int fb_fd; | ||
289 | +}; | ||
290 | + | ||
291 | +struct g2d_surface_state { | ||
292 | + float color[4]; | ||
293 | + struct weston_buffer_reference buffer_ref; | ||
294 | + int pitch; /* in pixels */ | ||
295 | + int attached; | ||
296 | + pixman_region32_t texture_damage; | ||
297 | + struct g2d_surfaceEx g2d_surface; | ||
298 | + struct g2d_buf *shm_buf; | ||
299 | + int shm_buf_length; | ||
300 | + int bpp; | ||
301 | + | ||
302 | + struct weston_surface *surface; | ||
303 | + struct wl_listener surface_destroy_listener; | ||
304 | + struct wl_listener renderer_destroy_listener; | ||
305 | +}; | ||
306 | + | ||
307 | +struct g2d_renderer { | ||
308 | + struct weston_renderer base; | ||
309 | + struct wl_signal destroy_signal; | ||
310 | + struct wl_global *viv_global; | ||
311 | + void *handle; | ||
312 | +}; | ||
313 | + | ||
314 | +static int | ||
315 | +g2d_renderer_create_surface(struct weston_surface *surface); | ||
316 | + | ||
317 | +static inline struct g2d_surface_state * | ||
318 | +get_surface_state(struct weston_surface *surface) | ||
319 | +{ | ||
320 | + if (!surface->renderer_state) | ||
321 | + g2d_renderer_create_surface(surface); | ||
322 | + return (struct g2d_surface_state *)surface->renderer_state; | ||
323 | +} | ||
324 | + | ||
325 | +static inline struct g2d_renderer * | ||
326 | +get_renderer(struct weston_compositor *ec) | ||
327 | +{ | ||
328 | + return (struct g2d_renderer *)ec->renderer; | ||
329 | +} | ||
330 | + | ||
331 | +#define max(a, b) (((a) > (b)) ? (a) : (b)) | ||
332 | +#define min(a, b) (((a) > (b)) ? (b) : (a)) | ||
333 | +/* | ||
334 | + * Compute the boundary vertices of the intersection of the global coordinate | ||
335 | + * aligned rectangle 'rect', and an arbitrary quadrilateral produced from | ||
336 | + * 'surf_rect' when transformed from surface coordinates into global coordinates. | ||
337 | + * The vertices are written to 'ex' and 'ey', and the return value is the | ||
338 | + * number of vertices. Vertices are produced in clockwise winding order. | ||
339 | + * Guarantees to produce either zero vertices, or 3-8 vertices with non-zero | ||
340 | + * polygon area. | ||
341 | + */ | ||
342 | +static int | ||
343 | +calculate_edges(struct weston_view *ev, pixman_box32_t *rect, | ||
344 | + pixman_box32_t *surf_rect, float *ex, float *ey) | ||
345 | +{ | ||
346 | + | ||
347 | + struct clip_context ctx; | ||
348 | + int i, n; | ||
349 | + float min_x, max_x, min_y, max_y; | ||
350 | + struct polygon8 surf = { | ||
351 | + { surf_rect->x1, surf_rect->x2, surf_rect->x2, surf_rect->x1 }, | ||
352 | + { surf_rect->y1, surf_rect->y1, surf_rect->y2, surf_rect->y2 }, | ||
353 | + 4 | ||
354 | + }; | ||
355 | + | ||
356 | + ctx.clip.x1 = rect->x1; | ||
357 | + ctx.clip.y1 = rect->y1; | ||
358 | + ctx.clip.x2 = rect->x2; | ||
359 | + ctx.clip.y2 = rect->y2; | ||
360 | + | ||
361 | + /* transform surface to screen space: */ | ||
362 | + for (i = 0; i < surf.n; i++) | ||
363 | + weston_view_to_global_float(ev, surf.x[i], surf.y[i], | ||
364 | + &surf.x[i], &surf.y[i]); | ||
365 | + | ||
366 | + /* find bounding box: */ | ||
367 | + min_x = max_x = surf.x[0]; | ||
368 | + min_y = max_y = surf.y[0]; | ||
369 | + | ||
370 | + for (i = 1; i < surf.n; i++) { | ||
371 | + min_x = min(min_x, surf.x[i]); | ||
372 | + max_x = max(max_x, surf.x[i]); | ||
373 | + min_y = min(min_y, surf.y[i]); | ||
374 | + max_y = max(max_y, surf.y[i]); | ||
375 | + } | ||
376 | + | ||
377 | + /* First, simple bounding box check to discard early transformed | ||
378 | + * surface rects that do not intersect with the clip region: | ||
379 | + */ | ||
380 | + if ((min_x >= ctx.clip.x2) || (max_x <= ctx.clip.x1) || | ||
381 | + (min_y >= ctx.clip.y2) || (max_y <= ctx.clip.y1)) | ||
382 | + return 0; | ||
383 | + | ||
384 | + /* Simple case, bounding box edges are parallel to surface edges, | ||
385 | + * there will be only four edges. We just need to clip the surface | ||
386 | + * vertices to the clip rect bounds: | ||
387 | + */ | ||
388 | + if (!ev->transform.enabled) | ||
389 | + return clip_simple(&ctx, &surf, ex, ey); | ||
390 | + | ||
391 | + /* Transformed case: use a general polygon clipping algorithm to | ||
392 | + * clip the surface rectangle with each side of 'rect'. | ||
393 | + * The algorithm is Sutherland-Hodgman, as explained in | ||
394 | + * http://www.codeguru.com/cpp/misc/misc/graphics/article.php/c8965/Polygon-Clipping.htm | ||
395 | + * but without looking at any of that code. | ||
396 | + */ | ||
397 | + n = clip_transformed(&ctx, &surf, ex, ey); | ||
398 | + | ||
399 | + if (n < 3) | ||
400 | + return 0; | ||
401 | + | ||
402 | + return n; | ||
403 | +} | ||
404 | + | ||
405 | + | ||
406 | +static inline struct g2d_output_state * | ||
407 | +get_output_state(struct weston_output *output) | ||
408 | +{ | ||
409 | + return (struct g2d_output_state *)output->renderer_state; | ||
410 | +} | ||
411 | + | ||
412 | +static void | ||
413 | +g2d_getG2dTiling(IN gceTILING tiling, enum g2d_tiling* g2dTiling) | ||
414 | +{ | ||
415 | + switch(tiling) | ||
416 | + { | ||
417 | + case gcvLINEAR: | ||
418 | + *g2dTiling = G2D_LINEAR; | ||
419 | + break; | ||
420 | + case gcvTILED: | ||
421 | + *g2dTiling = G2D_TILED; | ||
422 | + break; | ||
423 | + case gcvSUPERTILED: | ||
424 | + *g2dTiling = G2D_SUPERTILED; | ||
425 | + break; | ||
426 | + default: | ||
427 | + weston_log("Error in function %s\n", __func__); | ||
428 | + break; | ||
429 | + } | ||
430 | +} | ||
431 | + | ||
432 | +static void | ||
433 | +g2d_getG2dFormat(IN gceSURF_FORMAT Format, enum g2d_format* g2dFormat) | ||
434 | +{ | ||
435 | + switch(Format) | ||
436 | + { | ||
437 | + case gcvSURF_R5G6B5: | ||
438 | + *g2dFormat = G2D_RGB565; | ||
439 | + break; | ||
440 | + case gcvSURF_A8B8G8R8: | ||
441 | + *g2dFormat = G2D_RGBA8888; | ||
442 | + break; | ||
443 | + case gcvSURF_X8B8G8R8: | ||
444 | + *g2dFormat = G2D_RGBA8888; | ||
445 | + break; | ||
446 | + case gcvSURF_A8R8G8B8: | ||
447 | + *g2dFormat = G2D_BGRA8888; | ||
448 | + break; | ||
449 | + case gcvSURF_X8R8G8B8: | ||
450 | + *g2dFormat = G2D_BGRX8888; | ||
451 | + break; | ||
452 | + case gcvSURF_B5G6R5: | ||
453 | + *g2dFormat = G2D_BGR565; | ||
454 | + break; | ||
455 | + case gcvSURF_B8G8R8A8: | ||
456 | + *g2dFormat = G2D_ARGB8888; | ||
457 | + break; | ||
458 | + case gcvSURF_R8G8B8A8: | ||
459 | + *g2dFormat = G2D_ABGR8888; | ||
460 | + break; | ||
461 | + case gcvSURF_B8G8R8X8: | ||
462 | + *g2dFormat = G2D_XRGB8888; | ||
463 | + break; | ||
464 | + case gcvSURF_R8G8B8X8: | ||
465 | + *g2dFormat = G2D_XBGR8888; | ||
466 | + break; | ||
467 | + case gcvSURF_NV12: | ||
468 | + *g2dFormat = G2D_NV12; | ||
469 | + break; | ||
470 | + case gcvSURF_NV21: | ||
471 | + *g2dFormat = G2D_NV21; | ||
472 | + break; | ||
473 | + case gcvSURF_I420: | ||
474 | + *g2dFormat = G2D_I420; | ||
475 | + break; | ||
476 | + case gcvSURF_YV12: | ||
477 | + *g2dFormat = G2D_YV12; | ||
478 | + break; | ||
479 | + case gcvSURF_YUY2: | ||
480 | + *g2dFormat = G2D_YUYV; | ||
481 | + break; | ||
482 | + case gcvSURF_YVYU: | ||
483 | + *g2dFormat = G2D_YVYU; | ||
484 | + break; | ||
485 | + case gcvSURF_UYVY: | ||
486 | + *g2dFormat = G2D_UYVY; | ||
487 | + break; | ||
488 | + case gcvSURF_VYUY: | ||
489 | + *g2dFormat = G2D_VYUY; | ||
490 | + break; | ||
491 | + case gcvSURF_NV16: | ||
492 | + *g2dFormat = G2D_NV16; | ||
493 | + break; | ||
494 | + case gcvSURF_NV61: | ||
495 | + *g2dFormat = G2D_NV61; | ||
496 | + break; | ||
497 | + default: | ||
498 | + weston_log("Error in function %s, Format not supported\n", __func__); | ||
499 | + break; | ||
500 | + } | ||
501 | +} | ||
502 | + | ||
503 | +static void printG2dSurfaceInfo(struct g2d_surfaceEx* g2dSurface) | ||
504 | +{ | ||
505 | + weston_log("physicAddr = %d left = %d right = %d top=%d bottom=%d stride= %d tiling = %d, format=%d \n", | ||
506 | + g2dSurface->base.planes[0], | ||
507 | + g2dSurface->base.left, | ||
508 | + g2dSurface->base.right, | ||
509 | + g2dSurface->base.top, | ||
510 | + g2dSurface->base.bottom, | ||
511 | + g2dSurface->base.stride, | ||
512 | + g2dSurface->tiling, | ||
513 | + g2dSurface->base.format); | ||
514 | +} | ||
515 | + | ||
516 | +static void | ||
517 | +get_g2dSurface(gcsWL_VIV_BUFFER *buffer, struct g2d_surfaceEx *g2dSurface) | ||
518 | +{ | ||
519 | + if(buffer->width < 0 || buffer->height < 0) | ||
520 | + { | ||
521 | + weston_log("invalid EGL buffer in function %s\n", __func__); | ||
522 | + return; | ||
523 | + } | ||
524 | + int width = buffer->alignedWidth; | ||
525 | + int height = buffer->alignedHeight; | ||
526 | + g2d_getG2dFormat(buffer->format, &g2dSurface->base.format); | ||
527 | + g2d_getG2dTiling(buffer->tiling, &g2dSurface->tiling); | ||
528 | + g2dSurface->base.planes[0] = buffer->physical[0]; | ||
529 | + g2dSurface->base.planes[1] = buffer->physical[1]; | ||
530 | + g2dSurface->base.planes[2] = buffer->physical[2]; | ||
531 | + g2dSurface->base.left = 0; | ||
532 | + g2dSurface->base.top = 0; | ||
533 | + g2dSurface->base.right = buffer->width; | ||
534 | + g2dSurface->base.bottom = buffer->height; | ||
535 | + g2dSurface->base.stride = width; | ||
536 | + g2dSurface->base.width = width; | ||
537 | + g2dSurface->base.height = height; | ||
538 | + g2dSurface->base.rot = G2D_ROTATION_0; | ||
539 | +} | ||
540 | + | ||
541 | +static void | ||
542 | +g2d_SetSurfaceRect(struct g2d_surfaceEx* g2dSurface, g2dRECT* rect) | ||
543 | +{ | ||
544 | + if(g2dSurface && rect) | ||
545 | + { | ||
546 | + g2dSurface->base.left = rect->left; | ||
547 | + g2dSurface->base.top = rect->top; | ||
548 | + g2dSurface->base.right = rect->right; | ||
549 | + g2dSurface->base.bottom = rect->bottom; | ||
550 | + } | ||
551 | +} | ||
552 | + | ||
553 | +static int | ||
554 | +g2d_blitSurface(void *handle, struct g2d_surfaceEx * srcG2dSurface, struct g2d_surfaceEx *dstG2dSurface, | ||
555 | + g2dRECT *srcRect, g2dRECT *dstRect) | ||
556 | +{ | ||
557 | + g2d_SetSurfaceRect(srcG2dSurface, srcRect); | ||
558 | + g2d_SetSurfaceRect(dstG2dSurface, dstRect); | ||
559 | + srcG2dSurface->base.blendfunc = G2D_ONE; | ||
560 | + dstG2dSurface->base.blendfunc = G2D_ONE_MINUS_SRC_ALPHA; | ||
561 | + | ||
562 | + if(g2d_blitEx(handle, srcG2dSurface, dstG2dSurface)) | ||
563 | + { | ||
564 | + printG2dSurfaceInfo(srcG2dSurface); | ||
565 | + printG2dSurfaceInfo(dstG2dSurface); | ||
566 | + return -1; | ||
567 | + } | ||
568 | + return 0; | ||
569 | +} | ||
570 | + | ||
571 | +static void | ||
572 | +g2d_flip_surface(struct weston_output *output) | ||
573 | +{ | ||
574 | + struct g2d_output_state *go = get_output_state(output); | ||
575 | + go->fb_info.varinfo.yoffset = go->activebuffer * go->fb_info.y_resolution; | ||
576 | + | ||
577 | + if(ioctl(go->fb_fd, FBIOPAN_DISPLAY, &(go->fb_info.varinfo)) < 0) | ||
578 | + { | ||
579 | + weston_log("FBIOPAN_DISPLAY Failed\n"); | ||
580 | + } | ||
581 | + go->activebuffer = (go->activebuffer + 1) % go->nNumBuffers; | ||
582 | +} | ||
583 | + | ||
584 | +static void | ||
585 | +copy_to_framebuffer(struct weston_output *output) | ||
586 | +{ | ||
587 | + struct g2d_renderer *gr = get_renderer(output->compositor); | ||
588 | + struct g2d_output_state *go = get_output_state(output); | ||
589 | + if(!go->directBlit && go->nNumBuffers == 1) | ||
590 | + { | ||
591 | + g2dRECT srcRect = {0, 0, go->offscreenSurface.base.width, go->offscreenSurface.base.height}; | ||
592 | + g2dRECT dstrect = srcRect; | ||
593 | + g2dRECT clipRect = srcRect; | ||
594 | + g2d_set_clipping(gr->handle, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom); | ||
595 | + g2d_blitSurface(gr->handle, &go->offscreenSurface, | ||
596 | + &go->renderSurf[go->activebuffer], &srcRect, &dstrect); | ||
597 | + } | ||
598 | + | ||
599 | + g2d_finish(gr->handle); | ||
600 | + | ||
601 | + if(go->nNumBuffers > 1) | ||
602 | + { | ||
603 | + g2d_flip_surface(output); | ||
604 | + } | ||
605 | +} | ||
606 | + | ||
607 | +static int | ||
608 | +is_view_visible(struct weston_view *view) | ||
609 | +{ | ||
610 | + /* Return false, if surface is guaranteed to be totally obscured. */ | ||
611 | + int ret; | ||
612 | + pixman_region32_t unocc; | ||
613 | + | ||
614 | + pixman_region32_init(&unocc); | ||
615 | + pixman_region32_subtract(&unocc, &view->transform.boundingbox, | ||
616 | + &view->clip); | ||
617 | + ret = pixman_region32_not_empty(&unocc); | ||
618 | + pixman_region32_fini(&unocc); | ||
619 | + | ||
620 | + return ret; | ||
621 | +} | ||
622 | + | ||
623 | +static void | ||
624 | +use_output(struct weston_output *output) | ||
625 | +{ | ||
626 | + struct weston_compositor *compositor = output->compositor; | ||
627 | + struct weston_view *view; | ||
628 | + struct g2d_output_state *go = get_output_state(output); | ||
629 | + int visibleViews=0; | ||
630 | + int fullscreenViews=0; | ||
631 | + | ||
632 | + if(go->nNumBuffers == 1) | ||
633 | + { | ||
634 | + wl_list_for_each_reverse(view, &compositor->view_list, link) | ||
635 | + if (view->plane == &compositor->primary_plane && is_view_visible(view)) | ||
636 | + { | ||
637 | + visibleViews++; | ||
638 | + if(view->surface->width == go->width && view->surface->height == go->height) | ||
639 | + { | ||
640 | + pixman_box32_t *bb_rects; | ||
641 | + int nbb=0; | ||
642 | + bb_rects = pixman_region32_rectangles(&view->transform.boundingbox, &nbb); | ||
643 | + if(nbb == 1) | ||
644 | + if(bb_rects[0].x1 == 0 && bb_rects[0].y1 ==0) | ||
645 | + fullscreenViews++; | ||
646 | + } | ||
647 | + } | ||
648 | + | ||
649 | + go->directBlit = ((visibleViews == 1) || (fullscreenViews > 1)); | ||
650 | + } | ||
651 | +} | ||
652 | + | ||
653 | +static int | ||
654 | +g2d_renderer_read_pixels(struct weston_output *output, | ||
655 | + pixman_format_code_t format, void *pixels, | ||
656 | + uint32_t x, uint32_t y, | ||
657 | + uint32_t width, uint32_t height) | ||
658 | +{ | ||
659 | + return 0; | ||
660 | +} | ||
661 | + | ||
662 | +static int g2d_int_from_double(double d) | ||
663 | +{ | ||
664 | + return wl_fixed_to_int(wl_fixed_from_double(d)); | ||
665 | +} | ||
666 | + | ||
667 | +static void | ||
668 | +repaint_region(struct weston_view *ev, struct weston_output *output, struct g2d_output_state *go, pixman_region32_t *region, | ||
669 | + pixman_region32_t *surf_region){ | ||
670 | + | ||
671 | + struct g2d_renderer *gr = get_renderer(ev->surface->compositor); | ||
672 | + struct g2d_surface_state *gs = get_surface_state(ev->surface); | ||
673 | + | ||
674 | + pixman_box32_t *rects, *surf_rects, *bb_rects; | ||
675 | + int i, j, nrects, nsurf, nbb=0; | ||
676 | + g2dRECT srcRect = {0}; | ||
677 | + g2dRECT dstrect = {0}; | ||
678 | + g2dRECT clipRect = {0}; | ||
679 | + int dstWidth = 0; | ||
680 | + int dstHeight = 0; | ||
681 | + struct g2d_surfaceEx *dstsurface; | ||
682 | + | ||
683 | + bb_rects = pixman_region32_rectangles(&ev->transform.boundingbox, &nbb); | ||
684 | + | ||
685 | + if(!gs->attached || nbb <= 0) | ||
686 | + { | ||
687 | + return; | ||
688 | + } | ||
689 | + | ||
690 | + rects = pixman_region32_rectangles(region, &nrects); | ||
691 | + surf_rects = pixman_region32_rectangles(surf_region, &nsurf); | ||
692 | + srcRect.left = ev->geometry.x < 0.0 ? g2d_int_from_double(fabsf(ev->geometry.x)) : 0; | ||
693 | + srcRect.top = ev->geometry.y < 0.0 ? g2d_int_from_double(fabsf(ev->geometry.y)) : 0; | ||
694 | + srcRect.right = ev->surface->width; | ||
695 | + srcRect.bottom = ev->surface->height; | ||
696 | + if(go->nNumBuffers > 1 || go->directBlit) | ||
697 | + { | ||
698 | + dstsurface = &go->renderSurf[go->activebuffer]; | ||
699 | + } | ||
700 | + else | ||
701 | + { | ||
702 | + dstsurface = &go->offscreenSurface; | ||
703 | + } | ||
704 | + dstWidth = dstsurface->base.width; | ||
705 | + dstHeight = dstsurface->base.height; | ||
706 | + for (i = 0; i < nrects; i++) | ||
707 | + { | ||
708 | + pixman_box32_t *rect = &rects[i]; | ||
709 | + gctFLOAT min_x, max_x, min_y, max_y; | ||
710 | + | ||
711 | + dstrect.left = (bb_rects[0].x1 < 0) ? rect->x1 : bb_rects[0].x1; | ||
712 | + dstrect.top = (bb_rects[0].y1 < 0) ? rect->y1 : bb_rects[0].y1; | ||
713 | + dstrect.right = bb_rects[0].x2; | ||
714 | + dstrect.bottom = bb_rects[0].y2; | ||
715 | + /*Multi display support*/ | ||
716 | + if(output->x > 0) | ||
717 | + { | ||
718 | + dstrect.left = dstrect.left - output->x; | ||
719 | + dstrect.right = dstrect.right - output->x; | ||
720 | + } | ||
721 | + if(dstrect.left < 0) | ||
722 | + { | ||
723 | + srcRect.left -= dstrect.left; | ||
724 | + dstrect.left = 0; | ||
725 | + if(srcRect.left > ev->surface->width) | ||
726 | + break; | ||
727 | + } | ||
728 | + if(dstrect.right > dstWidth) | ||
729 | + { | ||
730 | + dstrect.right = dstWidth; | ||
731 | + srcRect.right = srcRect.left + dstrect.right - dstrect.left; | ||
732 | + if(srcRect.right > ev->surface->width) | ||
733 | + break; | ||
734 | + } | ||
735 | + if(dstrect.bottom > dstHeight) | ||
736 | + { | ||
737 | + dstrect.bottom = dstHeight; | ||
738 | + srcRect.bottom = srcRect.top + dstrect.bottom - dstrect.top; | ||
739 | + if(srcRect.bottom < 0) | ||
740 | + break; | ||
741 | + } | ||
742 | + | ||
743 | + for (j = 0; j < nsurf; j++) | ||
744 | + { | ||
745 | + pixman_box32_t *surf_rect = &surf_rects[j]; | ||
746 | + gctFLOAT ex[8], ey[8]; /* edge points in screen space */ | ||
747 | + int n; | ||
748 | + int m=0; | ||
749 | + n = calculate_edges(ev, rect, surf_rect, ex, ey); | ||
750 | + if (n < 3) | ||
751 | + continue; | ||
752 | + | ||
753 | + min_x = max_x = ex[0]; | ||
754 | + min_y = max_y = ey[0]; | ||
755 | + for (m = 1; m < n; m++) | ||
756 | + { | ||
757 | + min_x = min(min_x, ex[m]); | ||
758 | + max_x = max(max_x, ex[m]); | ||
759 | + min_y = min(min_y, ey[m]); | ||
760 | + max_y = max(max_y, ey[m]); | ||
761 | + } | ||
762 | + | ||
763 | + clipRect.left = g2d_int_from_double(min_x); | ||
764 | + clipRect.top = g2d_int_from_double(min_y); | ||
765 | + clipRect.right = g2d_int_from_double(max_x); | ||
766 | + clipRect.bottom = g2d_int_from_double(max_y); | ||
767 | + | ||
768 | + if(output->x > 0) | ||
769 | + { | ||
770 | + clipRect.left = clipRect.left - output->x; | ||
771 | + clipRect.right = clipRect.right - output->x; | ||
772 | + } | ||
773 | + g2d_set_clipping(gr->handle, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom); | ||
774 | + g2d_blitSurface(gr->handle, &gs->g2d_surface, dstsurface, &srcRect, &dstrect); | ||
775 | + } | ||
776 | + } | ||
777 | +} | ||
778 | + | ||
779 | +static void | ||
780 | +draw_view(struct weston_view *ev, struct weston_output *output, | ||
781 | + pixman_region32_t *damage) /* in global coordinates */ | ||
782 | +{ | ||
783 | + struct weston_compositor *ec = ev->surface->compositor; | ||
784 | + struct g2d_output_state *go = get_output_state(output); | ||
785 | + struct g2d_surface_state *gs = get_surface_state(ev->surface); | ||
786 | + /* repaint bounding region in global coordinates: */ | ||
787 | + pixman_region32_t repaint; | ||
788 | + /* non-opaque region in surface coordinates: */ | ||
789 | + pixman_region32_t surface_blend; | ||
790 | + pixman_region32_t *buffer_damage; | ||
791 | + | ||
792 | + pixman_region32_init(&repaint); | ||
793 | + pixman_region32_intersect(&repaint, | ||
794 | + &ev->transform.boundingbox, damage); | ||
795 | + pixman_region32_subtract(&repaint, &repaint, &ev->clip); | ||
796 | + | ||
797 | + if (!pixman_region32_not_empty(&repaint)) | ||
798 | + goto out; | ||
799 | + | ||
800 | + buffer_damage = &go->buffer_damage[go->current_buffer]; | ||
801 | + pixman_region32_subtract(buffer_damage, buffer_damage, &repaint); | ||
802 | + | ||
803 | + /* blended region is whole surface minus opaque region: */ | ||
804 | + pixman_region32_init_rect(&surface_blend, 0, 0, | ||
805 | + ev->surface->width, ev->surface->height); | ||
806 | + pixman_region32_subtract(&surface_blend, &surface_blend, &ev->surface->opaque); | ||
807 | + | ||
808 | + struct g2d_renderer *gr = get_renderer(ec); | ||
809 | + if (pixman_region32_not_empty(&ev->surface->opaque)) { | ||
810 | + repaint_region(ev, output, go, &repaint, &ev->surface->opaque); | ||
811 | + } | ||
812 | + | ||
813 | + if (pixman_region32_not_empty(&surface_blend)) { | ||
814 | + g2d_enable(gr->handle,G2D_BLEND); | ||
815 | + if (ev->alpha < 1.0) | ||
816 | + { | ||
817 | + g2d_enable(gr->handle, G2D_GLOBAL_ALPHA); | ||
818 | + gs->g2d_surface.base.global_alpha = ev->alpha * 0xFF; | ||
819 | + } | ||
820 | + repaint_region(ev, output, go, &repaint, &surface_blend); | ||
821 | + g2d_disable(gr->handle, G2D_GLOBAL_ALPHA); | ||
822 | + g2d_disable(gr->handle, G2D_BLEND); | ||
823 | + } | ||
824 | + pixman_region32_fini(&surface_blend); | ||
825 | + | ||
826 | +out: | ||
827 | + pixman_region32_fini(&repaint); | ||
828 | +} | ||
829 | + | ||
830 | +static void | ||
831 | +repaint_views(struct weston_output *output, pixman_region32_t *damage) | ||
832 | +{ | ||
833 | + struct weston_compositor *compositor = output->compositor; | ||
834 | + struct weston_view *view; | ||
835 | + | ||
836 | + wl_list_for_each_reverse(view, &compositor->view_list, link) | ||
837 | + if (view->plane == &compositor->primary_plane) | ||
838 | + draw_view(view, output, damage); | ||
839 | +} | ||
840 | + | ||
841 | +static void | ||
842 | +g2d_renderer_repaint_output(struct weston_output *output, | ||
843 | + pixman_region32_t *output_damage) | ||
844 | +{ | ||
845 | + struct g2d_output_state *go = get_output_state(output); | ||
846 | + int i; | ||
847 | + | ||
848 | + use_output(output); | ||
849 | + for (i = 0; i < 2; i++) | ||
850 | + pixman_region32_union(&go->buffer_damage[i], | ||
851 | + &go->buffer_damage[i], | ||
852 | + output_damage); | ||
853 | + | ||
854 | + pixman_region32_union(output_damage, output_damage, | ||
855 | + &go->buffer_damage[go->current_buffer]); | ||
856 | + | ||
857 | + repaint_views(output, output_damage); | ||
858 | + | ||
859 | + pixman_region32_copy(&output->previous_damage, output_damage); | ||
860 | + wl_signal_emit(&output->frame_signal, output); | ||
861 | + copy_to_framebuffer(output); | ||
862 | + go->current_buffer ^= 1; | ||
863 | +} | ||
864 | + | ||
865 | +static void | ||
866 | +g2d_renderer_attach_egl(struct weston_surface *es, struct weston_buffer *buffer) | ||
867 | +{ | ||
868 | + gcsWL_VIV_BUFFER *vivBuffer = wl_resource_get_user_data(buffer->resource); | ||
869 | + struct g2d_surface_state *gs = get_surface_state(es); | ||
870 | + buffer->width = vivBuffer->width; | ||
871 | + buffer->height = vivBuffer->height; | ||
872 | + get_g2dSurface(vivBuffer, &gs->g2d_surface); | ||
873 | +} | ||
874 | + | ||
875 | +static void | ||
876 | +g2d_renderer_flush_damage(struct weston_surface *surface) | ||
877 | +{ | ||
878 | + struct g2d_surface_state *gs = get_surface_state(surface); | ||
879 | + struct weston_buffer *buffer = gs->buffer_ref.buffer; | ||
880 | + struct weston_view *view; | ||
881 | + int texture_used; | ||
882 | + pixman_region32_union(&gs->texture_damage, | ||
883 | + &gs->texture_damage, &surface->damage); | ||
884 | + | ||
885 | + if (!buffer) | ||
886 | + return; | ||
887 | + | ||
888 | + texture_used = 0; | ||
889 | + wl_list_for_each(view, &surface->views, surface_link) { | ||
890 | + if (view->plane == &surface->compositor->primary_plane) { | ||
891 | + texture_used = 1; | ||
892 | + break; | ||
893 | + } | ||
894 | + } | ||
895 | + if (!texture_used) | ||
896 | + return; | ||
897 | + | ||
898 | + if (!pixman_region32_not_empty(&gs->texture_damage)) | ||
899 | + goto done; | ||
900 | + | ||
901 | + if(wl_shm_buffer_get(buffer->resource)) | ||
902 | + { | ||
903 | + uint8_t *src = wl_shm_buffer_get_data(buffer->shm_buffer); | ||
904 | + uint8_t *dst = gs->shm_buf->buf_vaddr; | ||
905 | + int bpp = gs->bpp; | ||
906 | + wl_shm_buffer_begin_access(buffer->shm_buffer); | ||
907 | + if(gs->shm_buf) | ||
908 | + { | ||
909 | + int alignedWidth = (buffer->width + 15) & ~15; | ||
910 | + if(alignedWidth == buffer->width) | ||
911 | + { | ||
912 | + int size = wl_shm_buffer_get_stride(buffer->shm_buffer)*buffer->height; | ||
913 | + memcpy(dst, src, size); | ||
914 | + } | ||
915 | + else | ||
916 | + { | ||
917 | + int i, j; | ||
918 | + for (i = 0; i < buffer->height; i++) | ||
919 | + { | ||
920 | + for (j = 0; j < buffer->width; j++) | ||
921 | + { | ||
922 | + int dstOff = i * alignedWidth + j; | ||
923 | + int srcOff = (i * buffer->width + j); | ||
924 | + memcpy(dst + dstOff * bpp, src + srcOff * bpp, bpp); | ||
925 | + } | ||
926 | + } | ||
927 | + } | ||
928 | + g2d_cache_op(gs->shm_buf, G2D_CACHE_CLEAN); | ||
929 | + } | ||
930 | + else | ||
931 | + { | ||
932 | + weston_log("Error: This shm buffer was not attached\n"); | ||
933 | + } | ||
934 | + wl_shm_buffer_end_access(buffer->shm_buffer); | ||
935 | + } | ||
936 | + else | ||
937 | + { | ||
938 | + g2d_renderer_attach_egl(surface, buffer); | ||
939 | + } | ||
940 | + | ||
941 | +done: | ||
942 | + pixman_region32_fini(&gs->texture_damage); | ||
943 | + pixman_region32_init(&gs->texture_damage); | ||
944 | + | ||
945 | + weston_buffer_reference(&gs->buffer_ref, NULL); | ||
946 | +} | ||
947 | + | ||
948 | +static void | ||
949 | +g2d_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer, | ||
950 | + struct wl_shm_buffer *shm_buffer) | ||
951 | +{ | ||
952 | + struct g2d_surface_state *gs = get_surface_state(es); | ||
953 | + int stride = 0; | ||
954 | + int buffer_length = 0; | ||
955 | + int alloc_new_buff = 1; | ||
956 | + int alignedWidth = 0; | ||
957 | + enum g2d_format g2dFormat = 0; | ||
958 | + buffer->shm_buffer = shm_buffer; | ||
959 | + buffer->width = wl_shm_buffer_get_width(shm_buffer); | ||
960 | + buffer->height = wl_shm_buffer_get_height(shm_buffer); | ||
961 | + alignedWidth = (buffer->width + 15) & ~15; | ||
962 | + stride = wl_shm_buffer_get_stride(shm_buffer); | ||
963 | + buffer_length = stride * buffer->height; | ||
964 | + | ||
965 | + switch (wl_shm_buffer_get_format(shm_buffer)) { | ||
966 | + case WL_SHM_FORMAT_XRGB8888: | ||
967 | + g2dFormat = G2D_XRGB8888; | ||
968 | + gs->bpp = 4; | ||
969 | + break; | ||
970 | + case WL_SHM_FORMAT_ARGB8888: | ||
971 | + g2dFormat = G2D_ARGB8888; | ||
972 | + gs->bpp = 4; | ||
973 | + break; | ||
974 | + case WL_SHM_FORMAT_RGB565: | ||
975 | + g2dFormat = G2D_RGB565; | ||
976 | + gs->bpp = 2; | ||
977 | + break; | ||
978 | + default: | ||
979 | + weston_log("warning: unknown shm buffer format: %08x\n", | ||
980 | + wl_shm_buffer_get_format(shm_buffer)); | ||
981 | + return; | ||
982 | + } | ||
983 | + | ||
984 | + buffer_length = alignedWidth * buffer->height * gs->bpp; | ||
985 | + | ||
986 | + /* Only allocate a new g2d buff if it is larger than existing one.*/ | ||
987 | + gs->shm_buf_length = buffer_length; | ||
988 | + if(gs->shm_buf && gs->shm_buf->buf_size > buffer_length) | ||
989 | + { | ||
990 | + alloc_new_buff = 0; | ||
991 | + } | ||
992 | + | ||
993 | + if(alloc_new_buff) | ||
994 | + { | ||
995 | + if(gs->shm_buf) | ||
996 | + g2d_free(gs->shm_buf); | ||
997 | + gs->shm_buf = g2d_alloc(buffer_length, 1); | ||
998 | + gs->g2d_surface.base.planes[0] = gs->shm_buf->buf_paddr; | ||
999 | + } | ||
1000 | + gs->g2d_surface.base.left = 0; | ||
1001 | + gs->g2d_surface.base.top = 0; | ||
1002 | + gs->g2d_surface.base.right = buffer->width; | ||
1003 | + gs->g2d_surface.base.bottom = buffer->height; | ||
1004 | + gs->g2d_surface.base.stride = alignedWidth; | ||
1005 | + gs->g2d_surface.base.width = buffer->width; | ||
1006 | + gs->g2d_surface.base.height = buffer->height; | ||
1007 | + gs->g2d_surface.base.rot = G2D_ROTATION_0; | ||
1008 | + gs->g2d_surface.base.clrcolor = 0xFF400000; | ||
1009 | + gs->g2d_surface.tiling = G2D_LINEAR; | ||
1010 | + gs->g2d_surface.base.format = g2dFormat; | ||
1011 | +} | ||
1012 | + | ||
1013 | +static void | ||
1014 | +g2d_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer) | ||
1015 | +{ | ||
1016 | + struct g2d_surface_state *gs = get_surface_state(es); | ||
1017 | + struct wl_shm_buffer *shm_buffer; | ||
1018 | + weston_buffer_reference(&gs->buffer_ref, buffer); | ||
1019 | + | ||
1020 | + if(buffer==NULL) | ||
1021 | + return; | ||
1022 | + | ||
1023 | + shm_buffer = wl_shm_buffer_get(buffer->resource); | ||
1024 | + | ||
1025 | + if(shm_buffer) | ||
1026 | + { | ||
1027 | + g2d_renderer_attach_shm(es, buffer, shm_buffer); | ||
1028 | + } | ||
1029 | + else | ||
1030 | + { | ||
1031 | + g2d_renderer_attach_egl(es, buffer); | ||
1032 | + } | ||
1033 | + gs->attached = 1; | ||
1034 | +} | ||
1035 | + | ||
1036 | +static void | ||
1037 | +surface_state_destroy(struct g2d_surface_state *gs, struct g2d_renderer *gr) | ||
1038 | +{ | ||
1039 | + wl_list_remove(&gs->surface_destroy_listener.link); | ||
1040 | + wl_list_remove(&gs->renderer_destroy_listener.link); | ||
1041 | + if(gs->surface) | ||
1042 | + gs->surface->renderer_state = NULL; | ||
1043 | + | ||
1044 | + if(gs->shm_buf) | ||
1045 | + { | ||
1046 | + g2d_free(gs->shm_buf); | ||
1047 | + gs->shm_buf = NULL; | ||
1048 | + } | ||
1049 | + | ||
1050 | + weston_buffer_reference(&gs->buffer_ref, NULL); | ||
1051 | + free(gs); | ||
1052 | +} | ||
1053 | + | ||
1054 | +static void | ||
1055 | +surface_state_handle_surface_destroy(struct wl_listener *listener, void *data) | ||
1056 | +{ | ||
1057 | + struct g2d_surface_state *gs; | ||
1058 | + struct g2d_renderer *gr; | ||
1059 | + | ||
1060 | + gs = container_of(listener, struct g2d_surface_state, | ||
1061 | + surface_destroy_listener); | ||
1062 | + | ||
1063 | + gr = get_renderer(gs->surface->compositor); | ||
1064 | + surface_state_destroy(gs, gr); | ||
1065 | +} | ||
1066 | + | ||
1067 | +static void | ||
1068 | +surface_state_handle_renderer_destroy(struct wl_listener *listener, void *data) | ||
1069 | +{ | ||
1070 | + struct g2d_surface_state *gs; | ||
1071 | + struct g2d_renderer *gr; | ||
1072 | + | ||
1073 | + gr = data; | ||
1074 | + | ||
1075 | + gs = container_of(listener, struct g2d_surface_state, | ||
1076 | + renderer_destroy_listener); | ||
1077 | + | ||
1078 | + surface_state_destroy(gs, gr); | ||
1079 | +} | ||
1080 | + | ||
1081 | + | ||
1082 | +static int | ||
1083 | +g2d_renderer_create_surface(struct weston_surface *surface) | ||
1084 | +{ | ||
1085 | + struct g2d_surface_state *gs; | ||
1086 | + struct g2d_renderer *gr = get_renderer(surface->compositor); | ||
1087 | + | ||
1088 | + gs = zalloc(sizeof *gs); | ||
1089 | + if (gs == NULL) | ||
1090 | + return -1; | ||
1091 | + | ||
1092 | + /* A buffer is never attached to solid color surfaces, yet | ||
1093 | + * they still go through texcoord computations. Do not divide | ||
1094 | + * by zero there. | ||
1095 | + */ | ||
1096 | + gs->pitch = 1; | ||
1097 | + | ||
1098 | + gs->surface = surface; | ||
1099 | + | ||
1100 | + pixman_region32_init(&gs->texture_damage); | ||
1101 | + surface->renderer_state = gs; | ||
1102 | + | ||
1103 | + gs->surface_destroy_listener.notify = | ||
1104 | + surface_state_handle_surface_destroy; | ||
1105 | + wl_signal_add(&surface->destroy_signal, | ||
1106 | + &gs->surface_destroy_listener); | ||
1107 | + | ||
1108 | + gs->renderer_destroy_listener.notify = | ||
1109 | + surface_state_handle_renderer_destroy; | ||
1110 | + wl_signal_add(&gr->destroy_signal, | ||
1111 | + &gs->renderer_destroy_listener); | ||
1112 | + | ||
1113 | + if (surface->buffer_ref.buffer) { | ||
1114 | + g2d_renderer_attach(surface, surface->buffer_ref.buffer); | ||
1115 | + g2d_renderer_flush_damage(surface); | ||
1116 | + } | ||
1117 | + | ||
1118 | + return 0; | ||
1119 | +} | ||
1120 | + | ||
1121 | +static void | ||
1122 | +g2d_renderer_surface_set_color(struct weston_surface *surface, | ||
1123 | + float red, float green, float blue, float alpha) | ||
1124 | +{ | ||
1125 | + struct g2d_surface_state *gs = get_surface_state(surface); | ||
1126 | + | ||
1127 | + gs->color[0] = red; | ||
1128 | + gs->color[1] = green; | ||
1129 | + gs->color[2] = blue; | ||
1130 | + gs->color[3] = alpha; | ||
1131 | +} | ||
1132 | + | ||
1133 | + | ||
1134 | +static void | ||
1135 | +g2d_renderer_output_destroy(struct weston_output *output) | ||
1136 | +{ | ||
1137 | + struct g2d_output_state *go = get_output_state(output); | ||
1138 | + gctUINT32 i; | ||
1139 | + | ||
1140 | + for (i = 0; i < 2; i++) | ||
1141 | + { | ||
1142 | + pixman_region32_fini(&go->buffer_damage[i]); | ||
1143 | + } | ||
1144 | + | ||
1145 | + if(go->offscreen_buf) | ||
1146 | + { | ||
1147 | + g2d_free(go->offscreen_buf); | ||
1148 | + go->offscreen_buf = NULL; | ||
1149 | + } | ||
1150 | + | ||
1151 | + if(go->fb_fd) | ||
1152 | + { | ||
1153 | + close(go->fb_fd); | ||
1154 | + go->fb_fd = 0; | ||
1155 | + } | ||
1156 | + | ||
1157 | + if(go->renderSurf) | ||
1158 | + { | ||
1159 | + free(go->renderSurf); | ||
1160 | + go->renderSurf = NULL; | ||
1161 | + } | ||
1162 | + | ||
1163 | + free(go); | ||
1164 | +} | ||
1165 | + | ||
1166 | +static void | ||
1167 | +g2d_renderer_destroy(struct weston_compositor *ec) | ||
1168 | +{ | ||
1169 | + struct g2d_renderer *gr = get_renderer(ec); | ||
1170 | + | ||
1171 | + wl_signal_emit(&gr->destroy_signal, gr); | ||
1172 | + wl_global_destroy(gr->viv_global); | ||
1173 | + g2d_close(gr->handle); | ||
1174 | + free(ec->renderer); | ||
1175 | + ec->renderer = NULL; | ||
1176 | +} | ||
1177 | + | ||
1178 | +static int | ||
1179 | +g2d_renderer_create(struct weston_compositor *ec) | ||
1180 | +{ | ||
1181 | + struct g2d_renderer *gr; | ||
1182 | + gr = malloc(sizeof *gr); | ||
1183 | + if (gr == NULL) | ||
1184 | + return -1; | ||
1185 | + | ||
1186 | + gr->base.read_pixels = g2d_renderer_read_pixels; | ||
1187 | + gr->base.repaint_output = g2d_renderer_repaint_output; | ||
1188 | + gr->base.flush_damage = g2d_renderer_flush_damage; | ||
1189 | + gr->base.attach = g2d_renderer_attach; | ||
1190 | + gr->base.surface_set_color = g2d_renderer_surface_set_color; | ||
1191 | + gr->base.destroy = g2d_renderer_destroy; | ||
1192 | + | ||
1193 | + if(g2d_open(&gr->handle)) | ||
1194 | + { | ||
1195 | + weston_log("g2d_open fail.\n"); | ||
1196 | + return -1; | ||
1197 | + } | ||
1198 | + ec->renderer = &gr->base; | ||
1199 | + wl_signal_init(&gr->destroy_signal); | ||
1200 | + return 0; | ||
1201 | +} | ||
1202 | + | ||
1203 | +static int | ||
1204 | +calculate_g2d_format(struct fb_var_screeninfo *varinfo, enum g2d_format *g2dFormat) | ||
1205 | +{ | ||
1206 | + /* Get the color format. */ | ||
1207 | + switch (varinfo->green.length) | ||
1208 | + { | ||
1209 | + case 6: | ||
1210 | + *g2dFormat= G2D_RGB565; | ||
1211 | + break; | ||
1212 | + | ||
1213 | + case 8: | ||
1214 | + if (varinfo->blue.offset == 0) | ||
1215 | + { | ||
1216 | + *g2dFormat = (varinfo->transp.length == 0) ? G2D_BGRX8888 : G2D_BGRA8888; | ||
1217 | + } | ||
1218 | + else | ||
1219 | + { | ||
1220 | + *g2dFormat = (varinfo->transp.length == 0) ? G2D_RGBX8888 : G2D_RGBA8888; | ||
1221 | + } | ||
1222 | + break; | ||
1223 | + | ||
1224 | + default: | ||
1225 | + *g2dFormat = -1; | ||
1226 | + break; | ||
1227 | + } | ||
1228 | + return 0; | ||
1229 | +} | ||
1230 | + | ||
1231 | +static int | ||
1232 | +get_G2dSurface_from_screeninfo(struct fb_screeninfo *info, struct g2d_surfaceEx* g2dSurface) | ||
1233 | +{ | ||
1234 | + if(info && g2dSurface) | ||
1235 | + { | ||
1236 | + g2dSurface->base.planes[0] = info->physical; | ||
1237 | + g2dSurface->base.left = 0; | ||
1238 | + g2dSurface->base.top = 0; | ||
1239 | + g2dSurface->base.right = info->x_resolution; | ||
1240 | + g2dSurface->base.bottom = info->y_resolution; | ||
1241 | + g2dSurface->base.stride = info->x_resolution; | ||
1242 | + g2dSurface->base.width = info->x_resolution; | ||
1243 | + g2dSurface->base.height = info->y_resolution; | ||
1244 | + g2dSurface->base.format = info->pixel_format; | ||
1245 | + g2dSurface->base.rot = G2D_ROTATION_0; | ||
1246 | + g2dSurface->base.clrcolor = 0xFF400000; | ||
1247 | + g2dSurface->tiling = G2D_LINEAR; | ||
1248 | + return 0; | ||
1249 | + } | ||
1250 | + return -1; | ||
1251 | +} | ||
1252 | + | ||
1253 | +static int | ||
1254 | +fb_query_screen_info(struct g2d_output_state *output, int fd, | ||
1255 | + struct fb_screeninfo *info) | ||
1256 | +{ | ||
1257 | + struct g2d_output_state *go = output; | ||
1258 | + struct fb_var_screeninfo *varinfo = &info->varinfo; | ||
1259 | + struct fb_fix_screeninfo *fixinfo = &info->fixinfo; | ||
1260 | + | ||
1261 | + /* Probe the device for screen information. */ | ||
1262 | + if (ioctl(fd, FBIOGET_VSCREENINFO, varinfo) < 0) { | ||
1263 | + return -1; | ||
1264 | + } | ||
1265 | + | ||
1266 | + if(go->nNumBuffers > 1){ | ||
1267 | + varinfo->yres_virtual = varinfo->yres * go->nNumBuffers; | ||
1268 | + if (ioctl(fd, FBIOPUT_VSCREENINFO, varinfo) < 0) | ||
1269 | + return -1; | ||
1270 | + } | ||
1271 | + | ||
1272 | + if (ioctl(fd, FBIOGET_FSCREENINFO, fixinfo) < 0 || | ||
1273 | + ioctl(fd, FBIOGET_VSCREENINFO, varinfo) < 0){ | ||
1274 | + return -1; | ||
1275 | + } | ||
1276 | + /* Store the pertinent data. */ | ||
1277 | + info->x_resolution = varinfo->xres; | ||
1278 | + info->y_resolution = varinfo->yres; | ||
1279 | + info->physical = fixinfo->smem_start; | ||
1280 | + info->buffer_length = fixinfo->smem_len; | ||
1281 | + calculate_g2d_format(varinfo, &info->pixel_format); | ||
1282 | + | ||
1283 | + if (info->pixel_format < 0) { | ||
1284 | + weston_log("Frame buffer uses an unsupported format.\n"); | ||
1285 | + return -1; | ||
1286 | + } | ||
1287 | + | ||
1288 | + return 0; | ||
1289 | +} | ||
1290 | + | ||
1291 | +static int | ||
1292 | +fb_frame_buffer_open(struct g2d_output_state *output, const char *fb_dev, | ||
1293 | + struct fb_screeninfo *screen_info) | ||
1294 | +{ | ||
1295 | + /* Open the frame buffer device. */ | ||
1296 | + output->fb_fd = open(fb_dev, O_RDWR | O_CLOEXEC); | ||
1297 | + if (output->fb_fd < 0) { | ||
1298 | + weston_log("Failed to open frame buffer device%s \n", fb_dev); | ||
1299 | + return -1; | ||
1300 | + } | ||
1301 | + | ||
1302 | + /* Grab the screen info. */ | ||
1303 | + if (fb_query_screen_info(output, output->fb_fd, screen_info) < 0) { | ||
1304 | + weston_log("Failed to get frame buffer info \n"); | ||
1305 | + | ||
1306 | + close(output->fb_fd); | ||
1307 | + return -1; | ||
1308 | + } | ||
1309 | + | ||
1310 | + return 0; | ||
1311 | +} | ||
1312 | + | ||
1313 | +static int | ||
1314 | +g2d_renderer_output_create(struct weston_output *output, struct wl_display *wl_display, const char *device) | ||
1315 | + | ||
1316 | + { | ||
1317 | + struct g2d_renderer *gr = get_renderer(output->compositor); | ||
1318 | + struct g2d_output_state *go; | ||
1319 | + int i = 0; | ||
1320 | + int offset = 0; | ||
1321 | + char *p = NULL; | ||
1322 | + go = zalloc(sizeof *go); | ||
1323 | + if (go == NULL) | ||
1324 | + return -1; | ||
1325 | + | ||
1326 | + output->renderer_state = go; | ||
1327 | + gr->viv_global = gcoOS_WaylandCreateVivGlobal(wl_display); | ||
1328 | + | ||
1329 | + p = getenv("FB_MULTI_BUFFER"); | ||
1330 | + if (p == gcvNULL) | ||
1331 | + { | ||
1332 | + go->nNumBuffers = 1; | ||
1333 | + } | ||
1334 | + else | ||
1335 | + { | ||
1336 | + go->nNumBuffers = atoi(p); | ||
1337 | + if (go->nNumBuffers < 1) | ||
1338 | + { | ||
1339 | + go->nNumBuffers = 1; | ||
1340 | + } | ||
1341 | + else if(go->nNumBuffers >= 2) | ||
1342 | + { | ||
1343 | + go->nNumBuffers = 2; | ||
1344 | + go->activebuffer = 1; | ||
1345 | + } | ||
1346 | + } | ||
1347 | + weston_log("FB_MULTI_BUFFER = %d\n", go->nNumBuffers); | ||
1348 | + | ||
1349 | + if(fb_frame_buffer_open(go, device, &go->fb_info) < 0) | ||
1350 | + { | ||
1351 | + weston_log("Open frame buffer failed.\n"); | ||
1352 | + return -1; | ||
1353 | + } | ||
1354 | + | ||
1355 | + go->renderSurf = zalloc(sizeof(struct g2d_surfaceEx) * go->nNumBuffers); | ||
1356 | + offset = go->fb_info.buffer_length/go->nNumBuffers; | ||
1357 | + for(i = 0; i < go->nNumBuffers; i++) | ||
1358 | + { | ||
1359 | + get_G2dSurface_from_screeninfo(&go->fb_info, &go->renderSurf[i]); | ||
1360 | + go->renderSurf[i].base.planes[0] = go->fb_info.physical | ||
1361 | + + (offset * i); | ||
1362 | + g2d_clear(gr->handle, &go->renderSurf[i].base); | ||
1363 | + } | ||
1364 | + | ||
1365 | + if(go->nNumBuffers == 1) | ||
1366 | + { | ||
1367 | + go->offscreenSurface = (go->renderSurf[go->activebuffer]); | ||
1368 | + go->offscreen_buf = g2d_alloc(go->fb_info.buffer_length, 0); | ||
1369 | + go->offscreenSurface.base.planes[0] = go->offscreen_buf->buf_paddr; | ||
1370 | + g2d_clear(gr->handle, &go->offscreenSurface.base); | ||
1371 | + } | ||
1372 | + | ||
1373 | + g2d_finish(gr->handle); | ||
1374 | + for (i = 0; i < 2; i++) | ||
1375 | + pixman_region32_init(&go->buffer_damage[i]); | ||
1376 | + return 0; | ||
1377 | + } | ||
1378 | + | ||
1379 | + WL_EXPORT struct g2d_renderer_interface g2d_renderer_interface = { | ||
1380 | + .create = g2d_renderer_create, | ||
1381 | + .output_create = g2d_renderer_output_create, | ||
1382 | + .output_destroy = g2d_renderer_output_destroy, | ||
1383 | +}; | ||
1384 | Index: weston-1.11.1/src/g2d-renderer.h | ||
1385 | =================================================================== | ||
1386 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
1387 | +++ weston-1.11.1/src/g2d-renderer.h 2017-01-14 09:08:38.000000000 -0600 | ||
1388 | @@ -0,0 +1,48 @@ | ||
1389 | +/* | ||
1390 | + * Copyright (c) 2015 Freescale Semiconductor, Inc. | ||
1391 | + * Copyright © 2013 Vasily Khoruzhick <anarsoul@gmail.com> | ||
1392 | + * | ||
1393 | + * Permission is hereby granted, free of charge, to any person obtaining | ||
1394 | + * a copy of this software and associated documentation files (the | ||
1395 | + * "Software"), to deal in the Software without restriction, including | ||
1396 | + * without limitation the rights to use, copy, modify, merge, publish, | ||
1397 | + * distribute, sublicense, and/or sell copies of the Software, and to | ||
1398 | + * permit persons to whom the Software is furnished to do so, subject to | ||
1399 | + * the following conditions: | ||
1400 | + * | ||
1401 | + * The above copyright notice and this permission notice (including the | ||
1402 | + * next paragraph) shall be included in all copies or substantial | ||
1403 | + * portions of the Software. | ||
1404 | + * | ||
1405 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
1406 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
1407 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
1408 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
1409 | + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
1410 | + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
1411 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
1412 | + * SOFTWARE. | ||
1413 | + */ | ||
1414 | +#ifndef __g2d_renderer_h_ | ||
1415 | +#define __g2d_renderer_h_ | ||
1416 | + | ||
1417 | +#include "compositor.h" | ||
1418 | +#ifdef ENABLE_EGL | ||
1419 | +#include <EGL/egl.h> | ||
1420 | +#else | ||
1421 | +#include <HAL/gc_hal_eglplatform.h> | ||
1422 | +#endif | ||
1423 | + | ||
1424 | + | ||
1425 | +struct g2d_renderer_interface { | ||
1426 | + | ||
1427 | + int (*create)(struct weston_compositor *ec); | ||
1428 | + | ||
1429 | + int (*output_create)(struct weston_output *output, | ||
1430 | + struct wl_display *wl_display, | ||
1431 | + const char *device); | ||
1432 | + | ||
1433 | + void (*output_destroy)(struct weston_output *output); | ||
1434 | +}; | ||
1435 | + | ||
1436 | +#endif | ||
1437 | Index: weston-1.11.1/src/gal2d-renderer.c | ||
1438 | =================================================================== | ||
1439 | --- weston-1.11.1.orig/src/gal2d-renderer.c 2017-01-14 08:59:52.753868091 -0600 | ||
1440 | +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
1441 | @@ -1,1307 +0,0 @@ | ||
1442 | -/* | ||
1443 | - * Copyright (c) 2015 Freescale Semiconductor, Inc. | ||
1444 | - * Copyright © 2012 Intel Corporation | ||
1445 | - * Copyright © 2015 Collabora, Ltd. | ||
1446 | - * | ||
1447 | - * Permission is hereby granted, free of charge, to any person obtaining | ||
1448 | - * a copy of this software and associated documentation files (the | ||
1449 | - * "Software"), to deal in the Software without restriction, including | ||
1450 | - * without limitation the rights to use, copy, modify, merge, publish, | ||
1451 | - * distribute, sublicense, and/or sell copies of the Software, and to | ||
1452 | - * permit persons to whom the Software is furnished to do so, subject to | ||
1453 | - * the following conditions: | ||
1454 | - * | ||
1455 | - * The above copyright notice and this permission notice (including the | ||
1456 | - * next paragraph) shall be included in all copies or substantial | ||
1457 | - * portions of the Software. | ||
1458 | - * | ||
1459 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
1460 | - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
1461 | - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
1462 | - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
1463 | - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
1464 | - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
1465 | - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
1466 | - * SOFTWARE. | ||
1467 | - */ | ||
1468 | - | ||
1469 | -#define _GNU_SOURCE | ||
1470 | - | ||
1471 | -#include <stdlib.h> | ||
1472 | -#include <string.h> | ||
1473 | -#include <ctype.h> | ||
1474 | -#include <float.h> | ||
1475 | -#include <assert.h> | ||
1476 | -#include <pthread.h> | ||
1477 | - | ||
1478 | -#include "compositor.h" | ||
1479 | -#include "gal2d-renderer.h" | ||
1480 | -#include "vertex-clipping.h" | ||
1481 | -#include "shared/helpers.h" | ||
1482 | -#include "HAL/gc_hal.h" | ||
1483 | -#include "HAL/gc_hal_raster.h" | ||
1484 | -#include "HAL/gc_hal_eglplatform.h" | ||
1485 | - | ||
1486 | -#define galONERROR(x) if(status < 0) printf("Error in function %s\n", __func__); | ||
1487 | - | ||
1488 | -struct gal2d_output_state { | ||
1489 | - | ||
1490 | - int current_buffer; | ||
1491 | - pixman_region32_t buffer_damage[2]; | ||
1492 | - NativeDisplayType display; | ||
1493 | - gcoSURF* renderSurf; | ||
1494 | - gctUINT32 nNumBuffers; | ||
1495 | - int activebuffer; | ||
1496 | - gcoSURF offscreenSurface; | ||
1497 | - gceSURF_FORMAT format; | ||
1498 | - pthread_mutex_t workerMutex; | ||
1499 | - pthread_t workerId; | ||
1500 | - gctUINT32 exitWorker; | ||
1501 | - gctSIGNAL signal; | ||
1502 | - gctSIGNAL busySignal; | ||
1503 | - gcsHAL_INTERFACE iface; | ||
1504 | - int directBlit; | ||
1505 | - gctINT width; | ||
1506 | - gctINT height; | ||
1507 | -}; | ||
1508 | - | ||
1509 | -struct gal2d_surface_state { | ||
1510 | - float color[4]; | ||
1511 | - struct weston_buffer_reference buffer_ref; | ||
1512 | - int pitch; /* in pixels */ | ||
1513 | - pixman_region32_t texture_damage; | ||
1514 | - gcoSURF gco_Surface; | ||
1515 | - | ||
1516 | - struct weston_surface *surface; | ||
1517 | - struct wl_listener surface_destroy_listener; | ||
1518 | - struct wl_listener renderer_destroy_listener; | ||
1519 | -}; | ||
1520 | - | ||
1521 | -struct gal2d_renderer { | ||
1522 | - struct weston_renderer base; | ||
1523 | - struct wl_signal destroy_signal; | ||
1524 | - gcoOS gcos; | ||
1525 | - gcoHAL gcoHal; | ||
1526 | - gco2D gcoEngine2d; | ||
1527 | - gctPOINTER localInfo; | ||
1528 | -}; | ||
1529 | - | ||
1530 | -static int | ||
1531 | -gal2d_renderer_create_surface(struct weston_surface *surface); | ||
1532 | - | ||
1533 | -static inline struct gal2d_surface_state * | ||
1534 | -get_surface_state(struct weston_surface *surface) | ||
1535 | -{ | ||
1536 | - if (!surface->renderer_state) | ||
1537 | - gal2d_renderer_create_surface(surface); | ||
1538 | - return (struct gal2d_surface_state *)surface->renderer_state; | ||
1539 | -} | ||
1540 | - | ||
1541 | -static inline struct gal2d_renderer * | ||
1542 | -get_renderer(struct weston_compositor *ec) | ||
1543 | -{ | ||
1544 | - return (struct gal2d_renderer *)ec->renderer; | ||
1545 | -} | ||
1546 | - | ||
1547 | - | ||
1548 | - | ||
1549 | -#define max(a, b) (((a) > (b)) ? (a) : (b)) | ||
1550 | -#define min(a, b) (((a) > (b)) ? (b) : (a)) | ||
1551 | -/* | ||
1552 | - * Compute the boundary vertices of the intersection of the global coordinate | ||
1553 | - * aligned rectangle 'rect', and an arbitrary quadrilateral produced from | ||
1554 | - * 'surf_rect' when transformed from surface coordinates into global coordinates. | ||
1555 | - * The vertices are written to 'ex' and 'ey', and the return value is the | ||
1556 | - * number of vertices. Vertices are produced in clockwise winding order. | ||
1557 | - * Guarantees to produce either zero vertices, or 3-8 vertices with non-zero | ||
1558 | - * polygon area. | ||
1559 | - */ | ||
1560 | -static int | ||
1561 | -calculate_edges(struct weston_view *ev, pixman_box32_t *rect, | ||
1562 | - pixman_box32_t *surf_rect, float *ex, float *ey) | ||
1563 | -{ | ||
1564 | - | ||
1565 | - struct clip_context ctx; | ||
1566 | - int i, n; | ||
1567 | - float min_x, max_x, min_y, max_y; | ||
1568 | - struct polygon8 surf = { | ||
1569 | - { surf_rect->x1, surf_rect->x2, surf_rect->x2, surf_rect->x1 }, | ||
1570 | - { surf_rect->y1, surf_rect->y1, surf_rect->y2, surf_rect->y2 }, | ||
1571 | - 4 | ||
1572 | - }; | ||
1573 | - | ||
1574 | - ctx.clip.x1 = rect->x1; | ||
1575 | - ctx.clip.y1 = rect->y1; | ||
1576 | - ctx.clip.x2 = rect->x2; | ||
1577 | - ctx.clip.y2 = rect->y2; | ||
1578 | - | ||
1579 | - /* transform surface to screen space: */ | ||
1580 | - for (i = 0; i < surf.n; i++) | ||
1581 | - weston_view_to_global_float(ev, surf.x[i], surf.y[i], | ||
1582 | - &surf.x[i], &surf.y[i]); | ||
1583 | - | ||
1584 | - /* find bounding box: */ | ||
1585 | - min_x = max_x = surf.x[0]; | ||
1586 | - min_y = max_y = surf.y[0]; | ||
1587 | - | ||
1588 | - for (i = 1; i < surf.n; i++) { | ||
1589 | - min_x = min(min_x, surf.x[i]); | ||
1590 | - max_x = max(max_x, surf.x[i]); | ||
1591 | - min_y = min(min_y, surf.y[i]); | ||
1592 | - max_y = max(max_y, surf.y[i]); | ||
1593 | - } | ||
1594 | - | ||
1595 | - /* First, simple bounding box check to discard early transformed | ||
1596 | - * surface rects that do not intersect with the clip region: | ||
1597 | - */ | ||
1598 | - if ((min_x >= ctx.clip.x2) || (max_x <= ctx.clip.x1) || | ||
1599 | - (min_y >= ctx.clip.y2) || (max_y <= ctx.clip.y1)) | ||
1600 | - return 0; | ||
1601 | - | ||
1602 | - /* Simple case, bounding box edges are parallel to surface edges, | ||
1603 | - * there will be only four edges. We just need to clip the surface | ||
1604 | - * vertices to the clip rect bounds: | ||
1605 | - */ | ||
1606 | - if (!ev->transform.enabled) | ||
1607 | - return clip_simple(&ctx, &surf, ex, ey); | ||
1608 | - | ||
1609 | - /* Transformed case: use a general polygon clipping algorithm to | ||
1610 | - * clip the surface rectangle with each side of 'rect'. | ||
1611 | - * The algorithm is Sutherland-Hodgman, as explained in | ||
1612 | - * http://www.codeguru.com/cpp/misc/misc/graphics/article.php/c8965/Polygon-Clipping.htm | ||
1613 | - * but without looking at any of that code. | ||
1614 | - */ | ||
1615 | - n = clip_transformed(&ctx, &surf, ex, ey); | ||
1616 | - | ||
1617 | - if (n < 3) | ||
1618 | - return 0; | ||
1619 | - | ||
1620 | - return n; | ||
1621 | -} | ||
1622 | - | ||
1623 | - | ||
1624 | -static inline struct gal2d_output_state * | ||
1625 | -get_output_state(struct weston_output *output) | ||
1626 | -{ | ||
1627 | - return (struct gal2d_output_state *)output->renderer_state; | ||
1628 | -} | ||
1629 | - | ||
1630 | -static gceSTATUS | ||
1631 | -gal2d_getSurfaceFormat(halDISPLAY_INFO info, gceSURF_FORMAT * Format) | ||
1632 | -{ | ||
1633 | - /* Get the color format. */ | ||
1634 | - switch (info.greenLength) | ||
1635 | - { | ||
1636 | - case 4: | ||
1637 | - if (info.blueOffset == 0) | ||
1638 | - { | ||
1639 | - *Format = (info.alphaLength == 0) ? gcvSURF_X4R4G4B4 : gcvSURF_A4R4G4B4; | ||
1640 | - } | ||
1641 | - else | ||
1642 | - { | ||
1643 | - *Format = (info.alphaLength == 0) ? gcvSURF_X4B4G4R4 : gcvSURF_A4B4G4R4; | ||
1644 | - } | ||
1645 | - break; | ||
1646 | - | ||
1647 | - case 5: | ||
1648 | - if (info.blueOffset == 0) | ||
1649 | - { | ||
1650 | - *Format = (info.alphaLength == 0) ? gcvSURF_X1R5G5B5 : gcvSURF_A1R5G5B5; | ||
1651 | - } | ||
1652 | - else | ||
1653 | - { | ||
1654 | - *Format = (info.alphaLength == 0) ? gcvSURF_X1B5G5R5 : gcvSURF_A1B5G5R5; | ||
1655 | - } | ||
1656 | - break; | ||
1657 | - | ||
1658 | - case 6: | ||
1659 | - *Format = gcvSURF_R5G6B5; | ||
1660 | - break; | ||
1661 | - | ||
1662 | - case 8: | ||
1663 | - if (info.blueOffset == 0) | ||
1664 | - { | ||
1665 | - *Format = (info.alphaLength == 0) ? gcvSURF_X8R8G8B8 : gcvSURF_A8R8G8B8; | ||
1666 | - } | ||
1667 | - else | ||
1668 | - { | ||
1669 | - *Format = (info.alphaLength == 0) ? gcvSURF_X8B8G8R8 : gcvSURF_A8B8G8R8; | ||
1670 | - } | ||
1671 | - break; | ||
1672 | - | ||
1673 | - default: | ||
1674 | - /* Unsupported color depth. */ | ||
1675 | - return gcvSTATUS_INVALID_ARGUMENT; | ||
1676 | - } | ||
1677 | - /* Success. */ | ||
1678 | - return gcvSTATUS_OK; | ||
1679 | -} | ||
1680 | - | ||
1681 | -static gceSTATUS galIsYUVFormat(IN gceSURF_FORMAT Format) | ||
1682 | -{ | ||
1683 | - switch (Format) | ||
1684 | - { | ||
1685 | - case gcvSURF_YUY2: | ||
1686 | - case gcvSURF_UYVY: | ||
1687 | - case gcvSURF_I420: | ||
1688 | - case gcvSURF_YV12: | ||
1689 | - case gcvSURF_NV16: | ||
1690 | - case gcvSURF_NV12: | ||
1691 | - case gcvSURF_NV61: | ||
1692 | - case gcvSURF_NV21: | ||
1693 | - | ||
1694 | - return gcvSTATUS_TRUE; | ||
1695 | - | ||
1696 | - default: | ||
1697 | - return gcvSTATUS_FALSE; | ||
1698 | - } | ||
1699 | -} | ||
1700 | - | ||
1701 | -static gceSTATUS galQueryUVStride( | ||
1702 | - IN gceSURF_FORMAT Format, | ||
1703 | - IN gctUINT32 yStride, | ||
1704 | - OUT gctUINT32_PTR uStride, | ||
1705 | - OUT gctUINT32_PTR vStride | ||
1706 | - ) | ||
1707 | -{ | ||
1708 | - switch (Format) | ||
1709 | - { | ||
1710 | - case gcvSURF_YUY2: | ||
1711 | - case gcvSURF_UYVY: | ||
1712 | - *uStride = *vStride = 0; | ||
1713 | - break; | ||
1714 | - | ||
1715 | - case gcvSURF_I420: | ||
1716 | - case gcvSURF_YV12: | ||
1717 | - *uStride = *vStride = yStride / 2; | ||
1718 | - break; | ||
1719 | - | ||
1720 | - case gcvSURF_NV16: | ||
1721 | - case gcvSURF_NV12: | ||
1722 | - case gcvSURF_NV61: | ||
1723 | - case gcvSURF_NV21: | ||
1724 | - | ||
1725 | - *uStride = yStride; | ||
1726 | - *vStride = 0; | ||
1727 | - break; | ||
1728 | - | ||
1729 | - default: | ||
1730 | - return gcvSTATUS_NOT_SUPPORTED; | ||
1731 | - } | ||
1732 | - | ||
1733 | - return gcvSTATUS_OK; | ||
1734 | -} | ||
1735 | - | ||
1736 | -static int | ||
1737 | -make_current(struct gal2d_renderer *gr, gcoSURF surface) | ||
1738 | -{ | ||
1739 | - gceSTATUS status = gcvSTATUS_OK; | ||
1740 | - gctUINT width = 0; | ||
1741 | - gctUINT height = 0; | ||
1742 | - gctINT stride = 0; | ||
1743 | - gctUINT32 physical[3]; | ||
1744 | - gctPOINTER va =0; | ||
1745 | - gceSURF_FORMAT format; | ||
1746 | - | ||
1747 | - if(!surface) | ||
1748 | - goto OnError; | ||
1749 | - | ||
1750 | - | ||
1751 | - gcmONERROR(gcoSURF_GetAlignedSize(surface, &width, &height, &stride)); | ||
1752 | - gcmONERROR(gcoSURF_GetFormat(surface, gcvNULL, &format)); | ||
1753 | - gcmONERROR(gcoSURF_Lock(surface, &physical[0], (gctPOINTER *)&va)); | ||
1754 | - gco2D_SetGenericTarget(gr->gcoEngine2d, | ||
1755 | - &physical[0], 1, | ||
1756 | - &stride, 1, | ||
1757 | - gcvLINEAR, format, | ||
1758 | - gcvSURF_0_DEGREE, width, height); | ||
1759 | - | ||
1760 | - gcmONERROR(gcoSURF_Unlock(surface, (gctPOINTER *)&va)); | ||
1761 | -OnError: | ||
1762 | - galONERROR(status); | ||
1763 | - return status; | ||
1764 | -} | ||
1765 | - | ||
1766 | -static gceSTATUS | ||
1767 | -gal2d_clear(struct weston_output *base) | ||
1768 | -{ | ||
1769 | - struct gal2d_renderer *gr = get_renderer(base->compositor); | ||
1770 | - struct gal2d_output_state *go = get_output_state(base); | ||
1771 | - gceSTATUS status = gcvSTATUS_OK; | ||
1772 | - | ||
1773 | - gctINT stride = 0; | ||
1774 | - gctUINT width = 0, height = 0; | ||
1775 | - gcsRECT dstRect = {0}; | ||
1776 | - gcmONERROR(gcoSURF_GetAlignedSize(go->renderSurf[go->activebuffer], | ||
1777 | - &width, &height, &stride)); | ||
1778 | - dstRect.right = width; | ||
1779 | - dstRect.bottom = height; | ||
1780 | - gcmONERROR(gco2D_SetSource(gr->gcoEngine2d, &dstRect)); | ||
1781 | - gcmONERROR(gco2D_SetClipping(gr->gcoEngine2d, &dstRect)); | ||
1782 | - gcmONERROR(gco2D_Clear(gr->gcoEngine2d, 1, &dstRect, 0xff0000ff, 0xCC, 0xCC, go->format)); | ||
1783 | - gcmONERROR(gcoHAL_Commit(gr->gcoHal, gcvTRUE)); | ||
1784 | - | ||
1785 | -OnError: | ||
1786 | - galONERROR(status); | ||
1787 | - | ||
1788 | - return status; | ||
1789 | -} | ||
1790 | - | ||
1791 | -static gcoSURF getSurfaceFromShm(struct weston_surface *es, struct weston_buffer *buffer) | ||
1792 | -{ | ||
1793 | - struct gal2d_renderer *gr = get_renderer(es->compositor); | ||
1794 | - | ||
1795 | - gcoSURF surface = 0; | ||
1796 | - gceSURF_FORMAT format; | ||
1797 | - gcePOOL pool = gcvPOOL_DEFAULT; | ||
1798 | - | ||
1799 | - if (wl_shm_buffer_get_format(buffer->shm_buffer) == WL_SHM_FORMAT_XRGB8888) | ||
1800 | - format = gcvSURF_X8R8G8B8; | ||
1801 | - else | ||
1802 | - format = gcvSURF_A8R8G8B8; | ||
1803 | - | ||
1804 | - if(buffer->width == ((buffer->width + 0x7) & ~0x7)) | ||
1805 | - { | ||
1806 | - pool = gcvPOOL_USER; | ||
1807 | - } | ||
1808 | - | ||
1809 | - gcmVERIFY_OK(gcoSURF_Construct(gr->gcoHal, | ||
1810 | - (gctUINT) buffer->width, | ||
1811 | - (gctUINT) buffer->height, | ||
1812 | - 1, gcvSURF_BITMAP, | ||
1813 | - format, pool, &surface)); | ||
1814 | - | ||
1815 | - if(pool == gcvPOOL_USER) | ||
1816 | - { | ||
1817 | - gcmVERIFY_OK(gcoSURF_MapUserSurface(surface, 1, | ||
1818 | - (gctPOINTER)wl_shm_buffer_get_data(buffer->shm_buffer), gcvINVALID_ADDRESS)); | ||
1819 | - } | ||
1820 | - | ||
1821 | - return surface; | ||
1822 | -} | ||
1823 | - | ||
1824 | -static int | ||
1825 | -gal2dBindBuffer(struct weston_surface* es) | ||
1826 | -{ | ||
1827 | - struct gal2d_surface_state *gs = get_surface_state(es); | ||
1828 | - gceSTATUS status = gcvSTATUS_OK; | ||
1829 | - gcoSURF surface = gs->gco_Surface; | ||
1830 | - struct weston_buffer *buffer = gs->buffer_ref.buffer; | ||
1831 | - gcePOOL pool = gcvPOOL_DEFAULT; | ||
1832 | - | ||
1833 | - gcmVERIFY_OK(gcoSURF_QueryVidMemNode(surface, gcvNULL, | ||
1834 | - &pool, gcvNULL)); | ||
1835 | - | ||
1836 | - if(pool != gcvPOOL_USER) | ||
1837 | - { | ||
1838 | - gctUINT alignedWidth; | ||
1839 | - gctPOINTER logical = (gctPOINTER)wl_shm_buffer_get_data(buffer->shm_buffer); | ||
1840 | - gctPOINTER va =0; | ||
1841 | - | ||
1842 | - | ||
1843 | - gcmVERIFY_OK(gcoSURF_GetAlignedSize(surface, &alignedWidth, gcvNULL, gcvNULL)); | ||
1844 | - gcmVERIFY_OK(gcoSURF_Lock(surface, gcvNULL, (gctPOINTER *)&va)); | ||
1845 | - | ||
1846 | - if(alignedWidth == (unsigned int)buffer->width) | ||
1847 | - { | ||
1848 | - int size = wl_shm_buffer_get_stride(buffer->shm_buffer)*buffer->height; | ||
1849 | - memcpy(va, logical, size); | ||
1850 | - } | ||
1851 | - else | ||
1852 | - { | ||
1853 | - int i, j; | ||
1854 | - for (i = 0; i < buffer->height; i++) | ||
1855 | - { | ||
1856 | - for (j = 0; j < buffer->width; j++) | ||
1857 | - { | ||
1858 | - gctUINT dstOff = i * alignedWidth + j; | ||
1859 | - gctUINT srcOff = (i * buffer->width + j); | ||
1860 | - | ||
1861 | - memcpy(va + dstOff * 4, logical + srcOff * 4, 4); | ||
1862 | - } | ||
1863 | - } | ||
1864 | - } | ||
1865 | - gcmVERIFY_OK(gcoSURF_Unlock(surface, (gctPOINTER)va)); | ||
1866 | - } | ||
1867 | - | ||
1868 | - return status; | ||
1869 | -} | ||
1870 | - | ||
1871 | -static void | ||
1872 | -gal2d_flip_surface(struct weston_output *output) | ||
1873 | -{ | ||
1874 | - struct gal2d_output_state *go = get_output_state(output); | ||
1875 | - | ||
1876 | - if(go->nNumBuffers > 1) | ||
1877 | - { | ||
1878 | - gctUINT Offset; | ||
1879 | - gctINT X; | ||
1880 | - gctINT Y; | ||
1881 | - | ||
1882 | - gcmVERIFY_OK(gcoOS_GetDisplayBackbuffer(go->display, gcvNULL, | ||
1883 | - gcvNULL, gcvNULL, &Offset, &X, &Y)); | ||
1884 | - | ||
1885 | - gcmVERIFY_OK(gcoOS_SetDisplayVirtual(go->display, gcvNULL, | ||
1886 | - Offset, X, Y)); | ||
1887 | - } | ||
1888 | -} | ||
1889 | - | ||
1890 | -static void *gal2d_output_worker(void *arg) | ||
1891 | -{ | ||
1892 | - struct weston_output *output = (struct weston_output *)arg; | ||
1893 | - struct gal2d_output_state *go = get_output_state(output); | ||
1894 | - | ||
1895 | - while(1) | ||
1896 | - { | ||
1897 | - if(gcoOS_WaitSignal(gcvNULL, go->signal, gcvINFINITE) == gcvSTATUS_OK ) | ||
1898 | - { | ||
1899 | - gal2d_flip_surface(output); | ||
1900 | - gcoOS_Signal(gcvNULL,go->busySignal, gcvTRUE); | ||
1901 | - } | ||
1902 | - pthread_mutex_lock(&go->workerMutex); | ||
1903 | - if(go->exitWorker == 1) | ||
1904 | - { | ||
1905 | - pthread_mutex_unlock(&go->workerMutex); | ||
1906 | - break; | ||
1907 | - } | ||
1908 | - pthread_mutex_unlock(&go->workerMutex); | ||
1909 | - } | ||
1910 | - return 0; | ||
1911 | -} | ||
1912 | - | ||
1913 | -static int | ||
1914 | -update_surface(struct weston_output *output) | ||
1915 | -{ | ||
1916 | - struct gal2d_renderer *gr = get_renderer(output->compositor); | ||
1917 | - struct gal2d_output_state *go = get_output_state(output); | ||
1918 | - gceSTATUS status = gcvSTATUS_OK; | ||
1919 | - | ||
1920 | - if(go->nNumBuffers == 1) | ||
1921 | - { | ||
1922 | - if(!go->directBlit && go->offscreenSurface) | ||
1923 | - { | ||
1924 | - make_current(gr, go->renderSurf[go->activebuffer]); | ||
1925 | - | ||
1926 | - gctUINT srcWidth = 0; | ||
1927 | - gctUINT srcHeight = 0; | ||
1928 | - gceSURF_FORMAT srcFormat;; | ||
1929 | - gcsRECT dstRect = {0}; | ||
1930 | - gcoSURF srcSurface = go->offscreenSurface; | ||
1931 | - gctUINT32 srcPhyAddr[3]; | ||
1932 | - gctUINT32 srcStride[3]; | ||
1933 | - | ||
1934 | - gctPOINTER va =0; | ||
1935 | - | ||
1936 | - gcmONERROR(gcoSURF_GetAlignedSize(srcSurface, &srcWidth, &srcHeight, (gctINT *)&srcStride[0])); | ||
1937 | - gcmONERROR(gcoSURF_GetFormat(srcSurface, gcvNULL, &srcFormat)); | ||
1938 | - | ||
1939 | - gcmONERROR(gcoSURF_Lock(srcSurface, srcPhyAddr, (gctPOINTER *)&va)); | ||
1940 | - gcmONERROR(gco2D_SetCurrentSourceIndex(gr->gcoEngine2d, 0U)); | ||
1941 | - | ||
1942 | - gco2D_SetGenericSource(gr->gcoEngine2d, srcPhyAddr, 1, | ||
1943 | - srcStride, 1, | ||
1944 | - gcvLINEAR, srcFormat, gcvSURF_0_DEGREE, | ||
1945 | - srcWidth, srcHeight); | ||
1946 | - | ||
1947 | - dstRect.left = 0; | ||
1948 | - dstRect.top = 0; | ||
1949 | - dstRect.right = srcWidth; | ||
1950 | - dstRect.bottom = srcHeight; | ||
1951 | - | ||
1952 | - gcmONERROR(gco2D_SetSource(gr->gcoEngine2d, &dstRect)); | ||
1953 | - gcmONERROR(gco2D_SetClipping(gr->gcoEngine2d, &dstRect)); | ||
1954 | - gcmONERROR(gco2D_Blit(gr->gcoEngine2d, 1, &dstRect, 0xCC, 0xCC, go->format)); | ||
1955 | - gcmONERROR(gcoSURF_Unlock(srcSurface, (gctPOINTER *)&va)); | ||
1956 | - } | ||
1957 | - gcmONERROR(gcoHAL_Commit(gr->gcoHal, gcvFALSE)); | ||
1958 | - } | ||
1959 | - else if(go->nNumBuffers > 1) | ||
1960 | - { | ||
1961 | - gcoHAL_ScheduleEvent(gr->gcoHal, &go->iface); | ||
1962 | - gcmVERIFY_OK(gcoHAL_Commit(gr->gcoHal, gcvFALSE)); | ||
1963 | - } | ||
1964 | -OnError: | ||
1965 | - galONERROR(status); | ||
1966 | - return status; | ||
1967 | - } | ||
1968 | - | ||
1969 | -static int | ||
1970 | -is_view_visible(struct weston_view *view) | ||
1971 | -{ | ||
1972 | - /* Return false, if surface is guaranteed to be totally obscured. */ | ||
1973 | - int ret; | ||
1974 | - pixman_region32_t unocc; | ||
1975 | - | ||
1976 | - pixman_region32_init(&unocc); | ||
1977 | - pixman_region32_subtract(&unocc, &view->transform.boundingbox, | ||
1978 | - &view->clip); | ||
1979 | - ret = pixman_region32_not_empty(&unocc); | ||
1980 | - pixman_region32_fini(&unocc); | ||
1981 | - | ||
1982 | - return ret; | ||
1983 | -} | ||
1984 | - | ||
1985 | -static int | ||
1986 | -use_output(struct weston_output *output) | ||
1987 | -{ | ||
1988 | - struct weston_compositor *compositor = output->compositor; | ||
1989 | - struct weston_view *view; | ||
1990 | - struct gal2d_output_state *go = get_output_state(output); | ||
1991 | - struct gal2d_renderer *gr = get_renderer(output->compositor); | ||
1992 | - gceSTATUS status = gcvSTATUS_OK; | ||
1993 | - | ||
1994 | - gcoSURF surface; | ||
1995 | - int visibleViews=0; | ||
1996 | - int fullscreenViews=0; | ||
1997 | - | ||
1998 | - surface = go->renderSurf[go->activebuffer]; | ||
1999 | - if(go->nNumBuffers == 1) | ||
2000 | - { | ||
2001 | - wl_list_for_each_reverse(view, &compositor->view_list, link) | ||
2002 | - if (view->plane == &compositor->primary_plane && is_view_visible(view)) | ||
2003 | - { | ||
2004 | - visibleViews++; | ||
2005 | - if(view->surface->width == go->width && view->surface->height == go->height) | ||
2006 | - { | ||
2007 | - pixman_box32_t *bb_rects; | ||
2008 | - int nbb=0; | ||
2009 | - bb_rects = pixman_region32_rectangles(&view->transform.boundingbox, &nbb); | ||
2010 | - if(nbb == 1) | ||
2011 | - if(bb_rects[0].x1 == 0 && bb_rects[0].y1 ==0) | ||
2012 | - fullscreenViews++; | ||
2013 | - } | ||
2014 | - } | ||
2015 | - | ||
2016 | - go->directBlit = ((visibleViews == 1) || (fullscreenViews > 1)); | ||
2017 | - | ||
2018 | - if(!go->directBlit) | ||
2019 | - { | ||
2020 | - surface = go->offscreenSurface; | ||
2021 | - } | ||
2022 | - } | ||
2023 | - make_current(gr, surface); | ||
2024 | - return status; | ||
2025 | -} | ||
2026 | - | ||
2027 | -static int | ||
2028 | -gal2d_renderer_read_pixels(struct weston_output *output, | ||
2029 | - pixman_format_code_t format, void *pixels, | ||
2030 | - uint32_t x, uint32_t y, | ||
2031 | - uint32_t width, uint32_t height) | ||
2032 | -{ | ||
2033 | - return 0; | ||
2034 | -} | ||
2035 | - | ||
2036 | -static int gal2d_int_from_double(double d) | ||
2037 | -{ | ||
2038 | - return wl_fixed_to_int(wl_fixed_from_double(d)); | ||
2039 | -} | ||
2040 | - | ||
2041 | -static void | ||
2042 | -repaint_region(struct weston_view *ev, struct weston_output *output, struct gal2d_output_state *go, pixman_region32_t *region, | ||
2043 | - pixman_region32_t *surf_region){ | ||
2044 | - | ||
2045 | - struct gal2d_renderer *gr = get_renderer(ev->surface->compositor); | ||
2046 | - struct gal2d_surface_state *gs = get_surface_state(ev->surface); | ||
2047 | - | ||
2048 | - pixman_box32_t *rects, *surf_rects, *bb_rects; | ||
2049 | - int i, j, nrects, nsurf, nbb=0; | ||
2050 | - gceSTATUS status = gcvSTATUS_OK; | ||
2051 | - gcoSURF srcSurface = gs->gco_Surface; | ||
2052 | - gcsRECT srcRect = {0}; | ||
2053 | - gcsRECT dstrect = {0}; | ||
2054 | - gctUINT32 horFactor, verFactor; | ||
2055 | - int useFilterBlit = 0; | ||
2056 | - gctUINT srcWidth = 0; | ||
2057 | - gctUINT srcHeight = 0; | ||
2058 | - gctUINT32 srcStride[3]; | ||
2059 | - gceSURF_FORMAT srcFormat; | ||
2060 | - gctUINT32 srcPhyAddr[3]; | ||
2061 | - gctUINT32 dstPhyAddr[3]; | ||
2062 | - gctUINT dstWidth = 0; | ||
2063 | - gctUINT dstHeight = 0; | ||
2064 | - gctUINT32 dstStrides[3]; | ||
2065 | - gcoSURF dstsurface; | ||
2066 | - int geoWidth = ev->surface->width; | ||
2067 | - int geoheight = ev->surface->height; | ||
2068 | - gceTILING tiling; | ||
2069 | - | ||
2070 | - bb_rects = pixman_region32_rectangles(&ev->transform.boundingbox, &nbb); | ||
2071 | - | ||
2072 | - if(!srcSurface || nbb <= 0) | ||
2073 | - goto OnError; | ||
2074 | - rects = pixman_region32_rectangles(region, &nrects); | ||
2075 | - surf_rects = pixman_region32_rectangles(surf_region, &nsurf); | ||
2076 | - | ||
2077 | - gcmVERIFY_OK(gcoSURF_GetAlignedSize(srcSurface, &srcWidth, &srcHeight, (gctINT *)&srcStride[0])); | ||
2078 | - | ||
2079 | - gcmVERIFY_OK(gcoSURF_GetFormat(srcSurface, gcvNULL, &srcFormat)); | ||
2080 | - | ||
2081 | - if(galIsYUVFormat(srcFormat) == gcvSTATUS_TRUE) | ||
2082 | - { | ||
2083 | - useFilterBlit = 1; | ||
2084 | - } | ||
2085 | - | ||
2086 | - gcmVERIFY_OK(gcoSURF_Lock(srcSurface, &srcPhyAddr[0], gcvNULL)); | ||
2087 | - | ||
2088 | - gcmVERIFY_OK(gcoSURF_Unlock(srcSurface, gcvNULL)); | ||
2089 | - | ||
2090 | - srcRect.left = ev->geometry.x < 0.0 ? gal2d_int_from_double(fabsf(ev->geometry.x)) : 0; | ||
2091 | - srcRect.top = 0; /*es->geometry.y < 0.0 ? gal2d_int_from_double(fabsf(es->geometry.y)) : 0;*/ | ||
2092 | - srcRect.right = ev->surface->width; | ||
2093 | - srcRect.bottom = ev->surface->height; | ||
2094 | - | ||
2095 | - dstsurface = go->nNumBuffers > 1 ? | ||
2096 | - go->renderSurf[go->activebuffer] : | ||
2097 | - go->offscreenSurface; | ||
2098 | - gcmVERIFY_OK(gcoSURF_GetAlignedSize(dstsurface, &dstWidth, &dstHeight, (gctINT *)&dstStrides)); | ||
2099 | - gcmVERIFY_OK(gcoSURF_Lock(dstsurface, &dstPhyAddr[0], gcvNULL)); | ||
2100 | - gcmVERIFY_OK(gcoSURF_Unlock(dstsurface, gcvNULL)); | ||
2101 | - | ||
2102 | - if(galIsYUVFormat(srcFormat) == gcvSTATUS_TRUE) | ||
2103 | - { | ||
2104 | - useFilterBlit = 1; | ||
2105 | - } | ||
2106 | - else | ||
2107 | - { | ||
2108 | - gcoSURF_GetTiling(srcSurface, &tiling); | ||
2109 | - if (gcoHAL_IsFeatureAvailable(gr->gcoHal, gcvFEATURE_2D_TILING) != gcvTRUE && (tiling > gcvLINEAR)) | ||
2110 | - { | ||
2111 | - weston_log("Tiling not supported \n"); | ||
2112 | - status = gcvSTATUS_NOT_SUPPORTED; | ||
2113 | - gcmONERROR(status); | ||
2114 | - } | ||
2115 | - gco2D_SetGenericSource(gr->gcoEngine2d, srcPhyAddr, 1, | ||
2116 | - srcStride, 1, | ||
2117 | - tiling, srcFormat, gcvSURF_0_DEGREE, | ||
2118 | - srcWidth, srcHeight); | ||
2119 | - gcmVERIFY_OK(gco2D_SetSource(gr->gcoEngine2d, &srcRect)); | ||
2120 | - /* Setup mirror. */ | ||
2121 | - gcmONERROR(gco2D_SetBitBlitMirror(gr->gcoEngine2d, gcvFALSE, gcvFALSE)); | ||
2122 | - gcmONERROR(gco2D_SetROP(gr->gcoEngine2d, 0xCC, 0xCC)); | ||
2123 | - } | ||
2124 | - | ||
2125 | - for (i = 0; i < nrects; i++) | ||
2126 | - { | ||
2127 | - pixman_box32_t *rect = &rects[i]; | ||
2128 | - gctFLOAT min_x, max_x, min_y, max_y; | ||
2129 | - | ||
2130 | - dstrect.left = (bb_rects[0].x1 < 0) ? rect->x1 : bb_rects[0].x1; | ||
2131 | - dstrect.top = (bb_rects[0].y1 < 0) ? rect->y1 : bb_rects[0].y1; | ||
2132 | - dstrect.right = bb_rects[0].x2; | ||
2133 | - dstrect.bottom = bb_rects[0].y2; | ||
2134 | - | ||
2135 | - if(dstrect.right < 0 || dstrect.bottom < 0 || dstrect.left > dstWidth || dstrect.top > dstHeight) | ||
2136 | - { | ||
2137 | - break; | ||
2138 | - } | ||
2139 | - | ||
2140 | - for (j = 0; j < nsurf; j++) | ||
2141 | - { | ||
2142 | - pixman_box32_t *surf_rect = &surf_rects[j]; | ||
2143 | - gctFLOAT ex[8], ey[8]; /* edge points in screen space */ | ||
2144 | - int n; | ||
2145 | - gcsRECT clipRect = {0}; | ||
2146 | - int m=0; | ||
2147 | - n = calculate_edges(ev, rect, surf_rect, ex, ey); | ||
2148 | - if (n < 3) | ||
2149 | - continue; | ||
2150 | - | ||
2151 | - min_x = max_x = ex[0]; | ||
2152 | - min_y = max_y = ey[0]; | ||
2153 | - for (m = 1; m < n; m++) | ||
2154 | - { | ||
2155 | - min_x = min(min_x, ex[m]); | ||
2156 | - max_x = max(max_x, ex[m]); | ||
2157 | - min_y = min(min_y, ey[m]); | ||
2158 | - max_y = max(max_y, ey[m]); | ||
2159 | - } | ||
2160 | - | ||
2161 | - clipRect.left = gal2d_int_from_double(min_x); | ||
2162 | - clipRect.top = gal2d_int_from_double(min_y); | ||
2163 | - clipRect.right = gal2d_int_from_double(max_x); | ||
2164 | - clipRect.bottom = gal2d_int_from_double(max_y); | ||
2165 | - | ||
2166 | - if(output->x > 0) | ||
2167 | - { | ||
2168 | - dstrect.left = dstrect.left - output->x; | ||
2169 | - dstrect.right = dstrect.right - output->x; | ||
2170 | - clipRect.left = clipRect.left - output->x; | ||
2171 | - clipRect.right = clipRect.right - output->x; | ||
2172 | - } | ||
2173 | - | ||
2174 | - dstrect.left = (dstrect.left < 0) ? 0 : dstrect.left; | ||
2175 | - | ||
2176 | - status = gco2D_SetClipping(gr->gcoEngine2d, &clipRect); | ||
2177 | - if(status < 0) | ||
2178 | - { | ||
2179 | - weston_log("Error in gco2D_SetClipping %s\n", __func__); | ||
2180 | - goto OnError; | ||
2181 | - } | ||
2182 | - | ||
2183 | - if(useFilterBlit) | ||
2184 | - { | ||
2185 | - gctINT srcStrideNum; | ||
2186 | - gctINT srcAddressNum; | ||
2187 | - gcmVERIFY_OK(galQueryUVStride(srcFormat, srcStride[0], | ||
2188 | - &srcStride[1], &srcStride[2])); | ||
2189 | - | ||
2190 | - switch (srcFormat) | ||
2191 | - { | ||
2192 | - case gcvSURF_YUY2: | ||
2193 | - case gcvSURF_UYVY: | ||
2194 | - srcStrideNum = srcAddressNum = 1; | ||
2195 | - break; | ||
2196 | - | ||
2197 | - case gcvSURF_I420: | ||
2198 | - case gcvSURF_YV12: | ||
2199 | - srcStrideNum = srcAddressNum = 3; | ||
2200 | - break; | ||
2201 | - | ||
2202 | - case gcvSURF_NV16: | ||
2203 | - case gcvSURF_NV12: | ||
2204 | - case gcvSURF_NV61: | ||
2205 | - case gcvSURF_NV21: | ||
2206 | - srcStrideNum = srcAddressNum = 2; | ||
2207 | - break; | ||
2208 | - | ||
2209 | - default: | ||
2210 | - gcmONERROR(gcvSTATUS_NOT_SUPPORTED); | ||
2211 | - } | ||
2212 | - gco2D_FilterBlitEx2(gr->gcoEngine2d, | ||
2213 | - srcPhyAddr, srcAddressNum, | ||
2214 | - srcStride, srcStrideNum, | ||
2215 | - gcvLINEAR, srcFormat, gcvSURF_0_DEGREE, | ||
2216 | - geoWidth, geoheight, &srcRect, | ||
2217 | - dstPhyAddr, 1, | ||
2218 | - dstStrides, 1, | ||
2219 | - gcvLINEAR, go->format, gcvSURF_0_DEGREE, | ||
2220 | - dstWidth, dstHeight, | ||
2221 | - &dstrect, gcvNULL); | ||
2222 | - } | ||
2223 | - else | ||
2224 | - { | ||
2225 | - gcmVERIFY_OK(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.right - srcRect.left, | ||
2226 | - dstrect.right - dstrect.left, &horFactor)); | ||
2227 | - | ||
2228 | - gcmONERROR(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.bottom - srcRect.top, | ||
2229 | - dstrect.bottom - dstrect.top, &verFactor)); | ||
2230 | - | ||
2231 | - if(verFactor == 65536 && horFactor == 65536) | ||
2232 | - { | ||
2233 | - gcmVERIFY_OK(gco2D_Blit(gr->gcoEngine2d, 1, &dstrect, | ||
2234 | - 0xCC, 0xCC, go->format)); | ||
2235 | - } | ||
2236 | - else | ||
2237 | - { | ||
2238 | - dstrect.right = dstrect.right < dstWidth ? dstrect.right : dstWidth; | ||
2239 | - dstrect.bottom = dstrect.bottom < dstHeight ? dstrect.bottom : dstHeight; | ||
2240 | - srcRect.right = srcRect.right < dstWidth ? srcRect.right : dstWidth; | ||
2241 | - srcRect.bottom = srcRect.bottom < dstHeight ? srcRect.bottom : dstHeight; | ||
2242 | - | ||
2243 | - gcmVERIFY_OK(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.right - srcRect.left, | ||
2244 | - dstrect.right - dstrect.left, &horFactor)); | ||
2245 | - | ||
2246 | - gcmONERROR(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.bottom - srcRect.top, | ||
2247 | - dstrect.bottom - dstrect.top, &verFactor)); | ||
2248 | - /* Program the stretch factors. */ | ||
2249 | - gcmVERIFY_OK(gco2D_SetStretchFactors(gr->gcoEngine2d, horFactor, verFactor)); | ||
2250 | - | ||
2251 | - gcmVERIFY_OK(gco2D_StretchBlit(gr->gcoEngine2d, 1, &dstrect, | ||
2252 | - 0xCC, 0xCC, go->format)); | ||
2253 | - } | ||
2254 | - } | ||
2255 | - | ||
2256 | - if(status < 0) | ||
2257 | - { | ||
2258 | - printf("cr l=%d r=%d t=%d b=%d w=%d h=%d\n", | ||
2259 | - clipRect.left, clipRect.right, clipRect.top ,clipRect.bottom, | ||
2260 | - clipRect.right - clipRect.left, clipRect.bottom -clipRect.top); | ||
2261 | - printf("dr l=%d r=%d t=%d b=%d w=%d h=%d\n", | ||
2262 | - dstrect.left, dstrect.right, dstrect.top ,dstrect.bottom, | ||
2263 | - dstrect.right - dstrect.left, dstrect.bottom -dstrect.top); | ||
2264 | - printf("horFactor=%d, verFactor=%d\n",horFactor, verFactor); | ||
2265 | - | ||
2266 | - goto OnError; | ||
2267 | - } | ||
2268 | - } | ||
2269 | - } | ||
2270 | - | ||
2271 | -OnError: | ||
2272 | - galONERROR(status); | ||
2273 | -} | ||
2274 | - | ||
2275 | -static void | ||
2276 | -draw_view(struct weston_view *ev, struct weston_output *output, | ||
2277 | - pixman_region32_t *damage) /* in global coordinates */ | ||
2278 | -{ | ||
2279 | - struct weston_compositor *ec = ev->surface->compositor; | ||
2280 | - struct gal2d_output_state *go = get_output_state(output); | ||
2281 | - /* repaint bounding region in global coordinates: */ | ||
2282 | - pixman_region32_t repaint; | ||
2283 | - /* non-opaque region in surface coordinates: */ | ||
2284 | - pixman_region32_t surface_blend; | ||
2285 | - pixman_region32_t *buffer_damage; | ||
2286 | - | ||
2287 | - pixman_region32_init(&repaint); | ||
2288 | - pixman_region32_intersect(&repaint, | ||
2289 | - &ev->transform.boundingbox, damage); | ||
2290 | - pixman_region32_subtract(&repaint, &repaint, &ev->clip); | ||
2291 | - | ||
2292 | - if (!pixman_region32_not_empty(&repaint)) | ||
2293 | - goto out; | ||
2294 | - | ||
2295 | - buffer_damage = &go->buffer_damage[go->current_buffer]; | ||
2296 | - pixman_region32_subtract(buffer_damage, buffer_damage, &repaint); | ||
2297 | - | ||
2298 | - /* blended region is whole surface minus opaque region: */ | ||
2299 | - pixman_region32_init_rect(&surface_blend, 0, 0, | ||
2300 | - ev->surface->width, ev->surface->height); | ||
2301 | - pixman_region32_subtract(&surface_blend, &surface_blend, &ev->surface->opaque); | ||
2302 | - | ||
2303 | - struct gal2d_renderer *gr = get_renderer(ec); | ||
2304 | - gco2D_SetCurrentSourceIndex(gr->gcoEngine2d, 0U); | ||
2305 | - | ||
2306 | - if (pixman_region32_not_empty(&ev->surface->opaque)) { | ||
2307 | - repaint_region(ev, output, go, &repaint, &ev->surface->opaque); | ||
2308 | - } | ||
2309 | - | ||
2310 | - if (pixman_region32_not_empty(&surface_blend)) { | ||
2311 | - gco2D_EnableAlphaBlend(gr->gcoEngine2d, | ||
2312 | - ev->alpha * 0xFF, ev->alpha * 0xFF, | ||
2313 | - gcvSURF_PIXEL_ALPHA_STRAIGHT, gcvSURF_PIXEL_ALPHA_STRAIGHT, | ||
2314 | - gcvSURF_GLOBAL_ALPHA_SCALE, gcvSURF_GLOBAL_ALPHA_SCALE, | ||
2315 | - gcvSURF_BLEND_STRAIGHT, gcvSURF_BLEND_INVERSED, | ||
2316 | - gcvSURF_COLOR_STRAIGHT, gcvSURF_COLOR_STRAIGHT); | ||
2317 | - | ||
2318 | - repaint_region(ev, output, go, &repaint, &surface_blend); | ||
2319 | - } | ||
2320 | - | ||
2321 | - gco2D_DisableAlphaBlend(gr->gcoEngine2d); | ||
2322 | - pixman_region32_fini(&surface_blend); | ||
2323 | - | ||
2324 | -out: | ||
2325 | - pixman_region32_fini(&repaint); | ||
2326 | - | ||
2327 | -} | ||
2328 | - | ||
2329 | -static void | ||
2330 | -repaint_views(struct weston_output *output, pixman_region32_t *damage) | ||
2331 | -{ | ||
2332 | - struct weston_compositor *compositor = output->compositor; | ||
2333 | - struct weston_view *view; | ||
2334 | - struct gal2d_output_state *go = get_output_state(output); | ||
2335 | - | ||
2336 | - if(go->nNumBuffers > 1) | ||
2337 | - { | ||
2338 | - /*500ms is more than enough to process a frame */ | ||
2339 | - gcoOS_WaitSignal(gcvNULL, go->busySignal, 500); | ||
2340 | - } | ||
2341 | - go->activebuffer = (go->activebuffer+1) % go->nNumBuffers; | ||
2342 | - | ||
2343 | - wl_list_for_each_reverse(view, &compositor->view_list, link) | ||
2344 | - if (view->plane == &compositor->primary_plane) | ||
2345 | - draw_view(view, output, damage); | ||
2346 | -} | ||
2347 | - | ||
2348 | -static void | ||
2349 | -gal2d_renderer_repaint_output(struct weston_output *output, | ||
2350 | - pixman_region32_t *output_damage) | ||
2351 | -{ | ||
2352 | - struct gal2d_output_state *go = get_output_state(output); | ||
2353 | - gctUINT32 i; | ||
2354 | - | ||
2355 | - if (use_output(output) < 0) | ||
2356 | - return; | ||
2357 | - | ||
2358 | - for (i = 0; i < 2; i++) | ||
2359 | - pixman_region32_union(&go->buffer_damage[i], | ||
2360 | - &go->buffer_damage[i], | ||
2361 | - output_damage); | ||
2362 | - | ||
2363 | - pixman_region32_union(output_damage, output_damage, | ||
2364 | - &go->buffer_damage[go->current_buffer]); | ||
2365 | - | ||
2366 | - repaint_views(output, output_damage); | ||
2367 | - | ||
2368 | - pixman_region32_copy(&output->previous_damage, output_damage); | ||
2369 | - wl_signal_emit(&output->frame_signal, output); | ||
2370 | - | ||
2371 | - update_surface(output); | ||
2372 | - | ||
2373 | - go->current_buffer ^= 1; | ||
2374 | -} | ||
2375 | - | ||
2376 | -static void | ||
2377 | -gal2d_renderer_attach_egl(struct weston_surface *es, struct weston_buffer *buffer) | ||
2378 | -{ | ||
2379 | - gcsWL_VIV_BUFFER *vivBuffer = wl_resource_get_user_data(buffer->resource); | ||
2380 | - gcoSURF srcSurf = vivBuffer->surface; | ||
2381 | - gceSTATUS status = gcvSTATUS_OK; | ||
2382 | - struct gal2d_surface_state *gs = get_surface_state(es); | ||
2383 | - | ||
2384 | - if(gs->gco_Surface != gcvNULL) | ||
2385 | - { | ||
2386 | - gcmONERROR(gcoSURF_Destroy(gs->gco_Surface)); | ||
2387 | - } | ||
2388 | - | ||
2389 | - gs->gco_Surface = srcSurf; | ||
2390 | - gcoSURF_ReferenceSurface(srcSurf); | ||
2391 | - buffer->width = vivBuffer->width; | ||
2392 | - buffer->height = vivBuffer->height; | ||
2393 | - | ||
2394 | - OnError: | ||
2395 | - galONERROR(status); | ||
2396 | -} | ||
2397 | - | ||
2398 | -static void | ||
2399 | -gal2d_renderer_flush_damage(struct weston_surface *surface) | ||
2400 | -{ | ||
2401 | - struct gal2d_surface_state *gs = get_surface_state(surface); | ||
2402 | - struct weston_buffer *buffer = gs->buffer_ref.buffer; | ||
2403 | - struct weston_view *view; | ||
2404 | - int texture_used; | ||
2405 | - pixman_region32_union(&gs->texture_damage, | ||
2406 | - &gs->texture_damage, &surface->damage); | ||
2407 | - | ||
2408 | - if (!buffer) | ||
2409 | - return; | ||
2410 | - | ||
2411 | - texture_used = 0; | ||
2412 | - wl_list_for_each(view, &surface->views, surface_link) { | ||
2413 | - if (view->plane == &surface->compositor->primary_plane) { | ||
2414 | - texture_used = 1; | ||
2415 | - break; | ||
2416 | - } | ||
2417 | - } | ||
2418 | - if (!texture_used) | ||
2419 | - return; | ||
2420 | - | ||
2421 | - if (!pixman_region32_not_empty(&gs->texture_damage)) | ||
2422 | - goto done; | ||
2423 | - | ||
2424 | - if(wl_shm_buffer_get(buffer->resource)) | ||
2425 | - { | ||
2426 | - if(gs->gco_Surface==NULL) | ||
2427 | - { | ||
2428 | - gs->gco_Surface = getSurfaceFromShm(surface, buffer); | ||
2429 | - } | ||
2430 | - gal2dBindBuffer(surface); | ||
2431 | - } | ||
2432 | - else | ||
2433 | - gal2d_renderer_attach_egl(surface, buffer); | ||
2434 | - | ||
2435 | -done: | ||
2436 | - pixman_region32_fini(&gs->texture_damage); | ||
2437 | - pixman_region32_init(&gs->texture_damage); | ||
2438 | - | ||
2439 | - weston_buffer_reference(&gs->buffer_ref, NULL); | ||
2440 | -} | ||
2441 | - | ||
2442 | -static void | ||
2443 | -gal2d_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer) | ||
2444 | -{ | ||
2445 | - struct gal2d_surface_state *gs = get_surface_state(es); | ||
2446 | - struct wl_shm_buffer *shm_buffer; | ||
2447 | - weston_buffer_reference(&gs->buffer_ref, buffer); | ||
2448 | - | ||
2449 | - if(buffer==NULL) | ||
2450 | - return; | ||
2451 | - | ||
2452 | - shm_buffer = wl_shm_buffer_get(buffer->resource); | ||
2453 | - | ||
2454 | - if(shm_buffer) | ||
2455 | - { | ||
2456 | - buffer->width = wl_shm_buffer_get_width(shm_buffer); | ||
2457 | - buffer->height = wl_shm_buffer_get_height(shm_buffer); | ||
2458 | - buffer->shm_buffer = shm_buffer; | ||
2459 | - | ||
2460 | - if(gs->gco_Surface) | ||
2461 | - { | ||
2462 | - gcoSURF_Destroy(gs->gco_Surface); | ||
2463 | - gs->gco_Surface = getSurfaceFromShm(es, buffer); | ||
2464 | - } | ||
2465 | - } | ||
2466 | - else | ||
2467 | - gal2d_renderer_attach_egl(es, buffer); | ||
2468 | -} | ||
2469 | - | ||
2470 | -static void | ||
2471 | -surface_state_destroy(struct gal2d_surface_state *gs, struct gal2d_renderer *gr) | ||
2472 | -{ | ||
2473 | - if(gs->gco_Surface) | ||
2474 | - { | ||
2475 | - gcoSURF_Destroy(gs->gco_Surface); | ||
2476 | - } | ||
2477 | - wl_list_remove(&gs->surface_destroy_listener.link); | ||
2478 | - wl_list_remove(&gs->renderer_destroy_listener.link); | ||
2479 | - if(gs->surface) | ||
2480 | - gs->surface->renderer_state = NULL; | ||
2481 | - | ||
2482 | - weston_buffer_reference(&gs->buffer_ref, NULL); | ||
2483 | - free(gs); | ||
2484 | -} | ||
2485 | - | ||
2486 | -static void | ||
2487 | -surface_state_handle_surface_destroy(struct wl_listener *listener, void *data) | ||
2488 | -{ | ||
2489 | - struct gal2d_surface_state *gs; | ||
2490 | - struct gal2d_renderer *gr; | ||
2491 | - | ||
2492 | - gs = container_of(listener, struct gal2d_surface_state, | ||
2493 | - surface_destroy_listener); | ||
2494 | - | ||
2495 | - gr = get_renderer(gs->surface->compositor); | ||
2496 | - surface_state_destroy(gs, gr); | ||
2497 | -} | ||
2498 | - | ||
2499 | -static void | ||
2500 | -surface_state_handle_renderer_destroy(struct wl_listener *listener, void *data) | ||
2501 | -{ | ||
2502 | - struct gal2d_surface_state *gs; | ||
2503 | - struct gal2d_renderer *gr; | ||
2504 | - | ||
2505 | - gr = data; | ||
2506 | - | ||
2507 | - gs = container_of(listener, struct gal2d_surface_state, | ||
2508 | - renderer_destroy_listener); | ||
2509 | - | ||
2510 | - surface_state_destroy(gs, gr); | ||
2511 | -} | ||
2512 | - | ||
2513 | - | ||
2514 | -static int | ||
2515 | -gal2d_renderer_create_surface(struct weston_surface *surface) | ||
2516 | -{ | ||
2517 | - struct gal2d_surface_state *gs; | ||
2518 | - struct gal2d_renderer *gr = get_renderer(surface->compositor); | ||
2519 | - | ||
2520 | - gs = zalloc(sizeof *gs); | ||
2521 | - if (gs == NULL) | ||
2522 | - return -1; | ||
2523 | - | ||
2524 | - /* A buffer is never attached to solid color surfaces, yet | ||
2525 | - * they still go through texcoord computations. Do not divide | ||
2526 | - * by zero there. | ||
2527 | - */ | ||
2528 | - gs->pitch = 1; | ||
2529 | - | ||
2530 | - gs->surface = surface; | ||
2531 | - | ||
2532 | - pixman_region32_init(&gs->texture_damage); | ||
2533 | - surface->renderer_state = gs; | ||
2534 | - | ||
2535 | - gs->surface_destroy_listener.notify = | ||
2536 | - surface_state_handle_surface_destroy; | ||
2537 | - wl_signal_add(&surface->destroy_signal, | ||
2538 | - &gs->surface_destroy_listener); | ||
2539 | - | ||
2540 | - gs->renderer_destroy_listener.notify = | ||
2541 | - surface_state_handle_renderer_destroy; | ||
2542 | - wl_signal_add(&gr->destroy_signal, | ||
2543 | - &gs->renderer_destroy_listener); | ||
2544 | - | ||
2545 | - if (surface->buffer_ref.buffer) { | ||
2546 | - gal2d_renderer_attach(surface, surface->buffer_ref.buffer); | ||
2547 | - gal2d_renderer_flush_damage(surface); | ||
2548 | - } | ||
2549 | - | ||
2550 | - return 0; | ||
2551 | -} | ||
2552 | - | ||
2553 | -static void | ||
2554 | -gal2d_renderer_surface_set_color(struct weston_surface *surface, | ||
2555 | - float red, float green, float blue, float alpha) | ||
2556 | -{ | ||
2557 | - struct gal2d_surface_state *gs = get_surface_state(surface); | ||
2558 | - | ||
2559 | - gs->color[0] = red; | ||
2560 | - gs->color[1] = green; | ||
2561 | - gs->color[2] = blue; | ||
2562 | - gs->color[3] = alpha; | ||
2563 | -} | ||
2564 | - | ||
2565 | - | ||
2566 | -static void | ||
2567 | -gal2d_renderer_output_destroy(struct weston_output *output) | ||
2568 | -{ | ||
2569 | - struct gal2d_output_state *go = get_output_state(output); | ||
2570 | - gctUINT32 i; | ||
2571 | - | ||
2572 | - for (i = 0; i < 2; i++) | ||
2573 | - { | ||
2574 | - pixman_region32_fini(&go->buffer_damage[i]); | ||
2575 | - } | ||
2576 | - if(go->nNumBuffers <= 1 ) | ||
2577 | - { | ||
2578 | - if(go->offscreenSurface) | ||
2579 | - gcmVERIFY_OK(gcoSURF_Destroy(go->offscreenSurface)); | ||
2580 | - } | ||
2581 | - else | ||
2582 | - { | ||
2583 | - gcoOS_Signal(gcvNULL,go->signal, gcvTRUE); | ||
2584 | - pthread_mutex_lock(&go->workerMutex); | ||
2585 | - go->exitWorker = 1; | ||
2586 | - pthread_mutex_unlock(&go->workerMutex); | ||
2587 | - pthread_join(go->workerId, NULL); | ||
2588 | - } | ||
2589 | - | ||
2590 | - for(i=0; i < go->nNumBuffers; i++) | ||
2591 | - { | ||
2592 | - gcmVERIFY_OK(gcoSURF_Destroy(go->renderSurf[i])); | ||
2593 | - } | ||
2594 | - free(go->renderSurf); | ||
2595 | - go->renderSurf = gcvNULL; | ||
2596 | - | ||
2597 | - free(go); | ||
2598 | -} | ||
2599 | - | ||
2600 | -static void | ||
2601 | -gal2d_renderer_destroy(struct weston_compositor *ec) | ||
2602 | -{ | ||
2603 | - struct gal2d_renderer *gr = get_renderer(ec); | ||
2604 | - | ||
2605 | - wl_signal_emit(&gr->destroy_signal, gr); | ||
2606 | - free(ec->renderer); | ||
2607 | - ec->renderer = NULL; | ||
2608 | -} | ||
2609 | - | ||
2610 | - | ||
2611 | -static int | ||
2612 | -gal2d_renderer_create(struct weston_compositor *ec) | ||
2613 | -{ | ||
2614 | - struct gal2d_renderer *gr; | ||
2615 | - gceSTATUS status = gcvSTATUS_OK; | ||
2616 | - gr = malloc(sizeof *gr); | ||
2617 | - if (gr == NULL) | ||
2618 | - return -1; | ||
2619 | - | ||
2620 | - gr->base.read_pixels = gal2d_renderer_read_pixels; | ||
2621 | - gr->base.repaint_output = gal2d_renderer_repaint_output; | ||
2622 | - gr->base.flush_damage = gal2d_renderer_flush_damage; | ||
2623 | - gr->base.attach = gal2d_renderer_attach; | ||
2624 | - gr->base.surface_set_color = gal2d_renderer_surface_set_color; | ||
2625 | - gr->base.destroy = gal2d_renderer_destroy; | ||
2626 | - | ||
2627 | - /* Construct the gcoOS object. */ | ||
2628 | - gcmONERROR(gcoOS_Construct(gcvNULL, &gr->gcos)); | ||
2629 | - | ||
2630 | - /* Construct the gcoHAL object. */ | ||
2631 | - gcmONERROR(gcoHAL_Construct(gcvNULL, gr->gcos, &gr->gcoHal)); | ||
2632 | - gcmONERROR(gcoHAL_Get2DEngine(gr->gcoHal, &gr->gcoEngine2d)); | ||
2633 | - gcmONERROR(gcoHAL_SetHardwareType(gr->gcoHal, gcvHARDWARE_2D)); | ||
2634 | - | ||
2635 | - ec->renderer = &gr->base; | ||
2636 | - wl_signal_init(&gr->destroy_signal); | ||
2637 | -OnError: | ||
2638 | - galONERROR(status); | ||
2639 | - | ||
2640 | - /* Return the status. */ | ||
2641 | - return status; | ||
2642 | - | ||
2643 | -} | ||
2644 | - | ||
2645 | -static int | ||
2646 | -gal2d_renderer_output_create(struct weston_output *output, NativeDisplayType display, | ||
2647 | - NativeWindowType window) | ||
2648 | - | ||
2649 | - { | ||
2650 | - struct gal2d_renderer *gr = get_renderer(output->compositor); | ||
2651 | - struct gal2d_output_state *go; | ||
2652 | - halDISPLAY_INFO info; | ||
2653 | - gctUINT32 backOffset = 0; | ||
2654 | - gceSTATUS status = gcvSTATUS_OK; | ||
2655 | - gctUINT32 i; | ||
2656 | - | ||
2657 | - go = zalloc(sizeof *go); | ||
2658 | - if (go == NULL) | ||
2659 | - return -1; | ||
2660 | - | ||
2661 | - output->renderer_state = go; | ||
2662 | - go->display = display; | ||
2663 | - gcmONERROR(gcoOS_InitLocalDisplayInfo(go->display, &gr->localInfo)); | ||
2664 | - | ||
2665 | - /* Get display information. */ | ||
2666 | - gcmONERROR(gcoOS_GetDisplayInfoEx2( | ||
2667 | - go->display, gcvNULL, gr->localInfo, | ||
2668 | - sizeof(info), &info)); | ||
2669 | - go->nNumBuffers = info.multiBuffer; | ||
2670 | - | ||
2671 | - weston_log("Number of buffers=%d\n",go->nNumBuffers); | ||
2672 | - | ||
2673 | - gcmONERROR(gal2d_getSurfaceFormat(info, &go->format)); | ||
2674 | - backOffset = (gctUINT32)(info.stride * info.height ); | ||
2675 | - | ||
2676 | - go->activebuffer = 0; | ||
2677 | - | ||
2678 | - go->renderSurf = malloc(sizeof(gcoSURF) * go->nNumBuffers); | ||
2679 | - gcoOS_GetDisplayVirtual(go->display, &go->width, &go->height); | ||
2680 | - gcoOS_SetSwapInterval(go->display, 1); | ||
2681 | - | ||
2682 | - /*Needed only for multi Buffer */ | ||
2683 | - if(go->nNumBuffers > 1) | ||
2684 | - { | ||
2685 | - gcmVERIFY_OK(gcoOS_CreateSignal(gcvNULL, gcvFALSE, | ||
2686 | - &go->signal)); | ||
2687 | - gcmVERIFY_OK(gcoOS_CreateSignal(gcvNULL, gcvFALSE, | ||
2688 | - &go->busySignal)); | ||
2689 | - | ||
2690 | - go->iface.command = gcvHAL_SIGNAL; | ||
2691 | - go->iface.u.Signal.signal = gcmPTR_TO_UINT64(go->signal); | ||
2692 | - go->iface.u.Signal.auxSignal = 0; | ||
2693 | - go->iface.u.Signal.process = gcmPTR_TO_UINT64(gcoOS_GetCurrentProcessID()); | ||
2694 | - go->iface.u.Signal.fromWhere = gcvKERNEL_PIXEL; | ||
2695 | - | ||
2696 | - go->exitWorker = 0; | ||
2697 | - pthread_create(&go->workerId, NULL, gal2d_output_worker, output); | ||
2698 | - pthread_mutex_init(&go->workerMutex, gcvNULL); | ||
2699 | - } | ||
2700 | - for(i=0; i < go->nNumBuffers; i++) | ||
2701 | - { | ||
2702 | - gcmONERROR(gcoSURF_Construct(gr->gcoHal, info.width, info.height, 1, | ||
2703 | - gcvSURF_BITMAP, go->format, gcvPOOL_USER, &go->renderSurf[i])); | ||
2704 | - | ||
2705 | - gcoSURF_MapUserSurface(go->renderSurf[i], 0,info.logical + (i * backOffset), | ||
2706 | - info.physical + (i * backOffset)); | ||
2707 | - | ||
2708 | - //Clear surfaces | ||
2709 | - make_current(gr, go->renderSurf[go->activebuffer]); | ||
2710 | - gal2d_clear(output); | ||
2711 | - gal2d_flip_surface(output); | ||
2712 | - } | ||
2713 | - if(go->nNumBuffers <= 1) | ||
2714 | - go->activebuffer = 0; | ||
2715 | - else | ||
2716 | - go->activebuffer = 1; | ||
2717 | - | ||
2718 | - if(go->nNumBuffers <= 1 ) | ||
2719 | - { | ||
2720 | - gcmVERIFY_OK(gcoSURF_Construct(gr->gcoHal, | ||
2721 | - (gctUINT) info.width, | ||
2722 | - (gctUINT) info.height, | ||
2723 | - 1, | ||
2724 | - gcvSURF_BITMAP, | ||
2725 | - go->format, | ||
2726 | - gcvPOOL_DEFAULT, | ||
2727 | - &go->offscreenSurface)); | ||
2728 | - make_current(gr, go->offscreenSurface); | ||
2729 | - gal2d_clear(output); | ||
2730 | - } | ||
2731 | - else | ||
2732 | - { | ||
2733 | - gcoOS_Signal(gcvNULL,go->busySignal, gcvTRUE); | ||
2734 | - } | ||
2735 | - | ||
2736 | - for (i = 0; i < 2; i++) | ||
2737 | - pixman_region32_init(&go->buffer_damage[i]); | ||
2738 | -OnError: | ||
2739 | - galONERROR(status); | ||
2740 | - /* Return the status. */ | ||
2741 | - return status; | ||
2742 | - } | ||
2743 | - | ||
2744 | - WL_EXPORT struct gal2d_renderer_interface gal2d_renderer_interface = { | ||
2745 | - .create = gal2d_renderer_create, | ||
2746 | - .output_create = gal2d_renderer_output_create, | ||
2747 | - .output_destroy = gal2d_renderer_output_destroy, | ||
2748 | -}; | ||
2749 | Index: weston-1.11.1/src/gal2d-renderer.h | ||
2750 | =================================================================== | ||
2751 | --- weston-1.11.1.orig/src/gal2d-renderer.h 2017-01-14 08:59:52.297865829 -0600 | ||
2752 | +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
2753 | @@ -1,50 +0,0 @@ | ||
2754 | -/* | ||
2755 | - * Copyright (c) 2015 Freescale Semiconductor, Inc. | ||
2756 | - * Copyright © 2013 Vasily Khoruzhick <anarsoul@gmail.com> | ||
2757 | - * | ||
2758 | - * Permission is hereby granted, free of charge, to any person obtaining | ||
2759 | - * a copy of this software and associated documentation files (the | ||
2760 | - * "Software"), to deal in the Software without restriction, including | ||
2761 | - * without limitation the rights to use, copy, modify, merge, publish, | ||
2762 | - * distribute, sublicense, and/or sell copies of the Software, and to | ||
2763 | - * permit persons to whom the Software is furnished to do so, subject to | ||
2764 | - * the following conditions: | ||
2765 | - * | ||
2766 | - * The above copyright notice and this permission notice (including the | ||
2767 | - * next paragraph) shall be included in all copies or substantial | ||
2768 | - * portions of the Software. | ||
2769 | - * | ||
2770 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
2771 | - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
2772 | - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
2773 | - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
2774 | - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
2775 | - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
2776 | - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
2777 | - * SOFTWARE. | ||
2778 | - */ | ||
2779 | -#ifndef __gal_2d_renderer_h_ | ||
2780 | -#define __gal_2d_renderer_h_ | ||
2781 | - | ||
2782 | -#include "compositor.h" | ||
2783 | -#ifdef ENABLE_EGL | ||
2784 | -#include <EGL/egl.h> | ||
2785 | -#else | ||
2786 | -#include <HAL/gc_hal_eglplatform.h> | ||
2787 | -typedef HALNativeDisplayType NativeDisplayType; | ||
2788 | -typedef HALNativeWindowType NativeWindowType; | ||
2789 | -#endif | ||
2790 | - | ||
2791 | - | ||
2792 | -struct gal2d_renderer_interface { | ||
2793 | - | ||
2794 | - int (*create)(struct weston_compositor *ec); | ||
2795 | - | ||
2796 | - int (*output_create)(struct weston_output *output, | ||
2797 | - NativeDisplayType display, | ||
2798 | - NativeWindowType window); | ||
2799 | - | ||
2800 | - void (*output_destroy)(struct weston_output *output); | ||
2801 | -}; | ||
2802 | - | ||
2803 | -#endif | ||
2804 | Index: weston-1.11.1/src/main.c | ||
2805 | =================================================================== | ||
2806 | --- weston-1.11.1.orig/src/main.c 2017-01-14 08:59:52.297865829 -0600 | ||
2807 | +++ weston-1.11.1/src/main.c 2017-01-14 09:08:38.000000000 -0600 | ||
2808 | @@ -287,10 +287,10 @@ | ||
2809 | " --device=DEVICE\tThe framebuffer device to use\n" | ||
2810 | #if defined ENABLE_EGL | ||
2811 | " --use-gl=1\t\tUse the GL renderer (default is 1)\n" | ||
2812 | - " --use-gal2d=1\t\tUse the GAL2D renderer (default is 0)\n\n"); | ||
2813 | + " --use-g2d=1\t\tUse the G2D renderer (default is 0)\n\n"); | ||
2814 | #else | ||
2815 | " --use-gl=1\t\tUse the GL renderer (default is 0)\n" | ||
2816 | - " --use-gal2d=1\t\tUse the GAL2D renderer (default is 1)\n\n"); | ||
2817 | + " --use-g2d=1\t\tUse the G2D renderer (default is 1)\n\n"); | ||
2818 | #endif | ||
2819 | #endif | ||
2820 | |||
2821 | @@ -875,7 +875,7 @@ | ||
2822 | { WESTON_OPTION_INTEGER, "tty", 0, &config.tty }, | ||
2823 | { WESTON_OPTION_STRING, "device", 0, &config.device }, | ||
2824 | { WESTON_OPTION_INTEGER, "use-gl", 0, &config.use_gl }, | ||
2825 | - { WESTON_OPTION_INTEGER, "use-gal2d", 0, &config.use_gal2d }, | ||
2826 | + { WESTON_OPTION_INTEGER, "use-g2d", 0, &config.use_g2d }, | ||
2827 | }; | ||
2828 | |||
2829 | parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv); | ||
2830 | Index: weston-1.11.1/src/compositor-fbdev.h | ||
2831 | =================================================================== | ||
2832 | --- weston-1.11.1.orig/src/compositor-fbdev.h 2017-01-14 08:59:52.297865829 -0600 | ||
2833 | +++ weston-1.11.1/src/compositor-fbdev.h 2017-01-14 08:59:52.841868527 -0600 | ||
2834 | @@ -40,7 +40,8 @@ | ||
2835 | int tty; | ||
2836 | char *device; | ||
2837 | int use_gl; | ||
2838 | - int use_gal2d; | ||
2839 | + int use_g2d; | ||
2840 | + int clone_mode; | ||
2841 | |||
2842 | uint32_t output_transform; | ||
2843 | }; | ||