Commit 6059e6a8f25e15e934a268d1f022044736f8ba33

  • avatar
  • Chia-I Wu <olvaffe @gm…l.com>
  • Fri Sep 18 12:36:14 CEST 2009
egl_android: Add untested support for EGLImage.
  
4040struct droid_loader;
4141struct droid_context;
4242struct droid_drawable;
43struct droid_image;
4344struct droid_surface;
4445
4546struct droid_backend {
6262 struct droid_surface *(*create_window_surface)(struct droid_backend *backend,
6363 _EGLSurface *surf,
6464 NativeWindowType win);
65 struct droid_surface *(*create_image_surface)(struct droid_backend *backend,
66 NativePixmapType pix,
67 int *depth);
6568 void (*destroy_surface)(struct droid_backend *backend, struct droid_surface *surf);
6669 void (*swap_native_buffers)(struct droid_backend *backend,
6770 struct droid_surface *surf);
7979
8080 const __DRIconfig **dri_configs;
8181 int num_dri_configs;
82
83#define DROID_MAX_IMAGE_DEPTH 32
84 const __DRIconfig *image_configs[DROID_MAX_IMAGE_DEPTH + 1];
8285};
8386
8487struct droid_backend *
113113droid_screen_create_drawable(struct droid_screen *screen,
114114 const __DRIconfig *conf,
115115 struct droid_surface *surf);
116
117void *
118droid_screen_get_drawable_data(struct droid_screen *screen,
119 struct droid_drawable *drawable);
116120
117121void
118122droid_screen_destroy_drawable(struct droid_screen *screen,
  
4646
4747enum {
4848 INTEL_SURFACE_TYPE_WINDOW,
49 INTEL_SURFACE_TYPE_IMAGE,
4950};
5051
5152struct droid_backend_intel {
5959 int type;
6060 union {
6161 NativeWindowType win;
62 NativePixmapType pix;
6263 } native;
6364 __DRIbuffer native_buffer;
6465 unsigned int native_width, native_height;
221221 }
222222 else {
223223 buffers[num].attachment = att;
224 handles[num] = create_buffer(intel->fd,
225 isurf->native_width,
226 isurf->native_height,
227 cpp,
228 &buffers[num]);
224
225 if (isurf->type == INTEL_SURFACE_TYPE_IMAGE &&
226 att == __DRI_BUFFER_FRONT_LEFT) {
227 buffers[num] = isurf->native_buffer;
228 buffers[num].attachment = att;
229 handles[num] = 0;
230 } else {
231 buffers[num].attachment = att;
232 handles[num] = create_buffer(intel->fd,
233 isurf->native_width,
234 isurf->native_height,
235 cpp,
236 &buffers[num]);
237 }
229238 }
230239 num++;
231240 }
269269 width = isurf->native.win->width;
270270 height = isurf->native.win->height;
271271 break;
272 case INTEL_SURFACE_TYPE_IMAGE:
273 name = isurf->native.pix->reserved;
274 cpp = ui_bytes_per_pixel(isurf->native.pix->format);
275 pitch = isurf->native.pix->stride * cpp;
276 width = isurf->native.pix->width;
277 height = isurf->native.pix->height;
278 break;
272279 default:
273280 name = cpp = pitch = width = height = 0;
274281 break;
334334 return (struct droid_surface *) isurf;
335335}
336336
337static struct droid_surface *
338intel_create_image_surface(struct droid_backend *backend,
339 NativePixmapType pix, int *depth)
340{
341 struct droid_surface_intel *isurf;
342 int cpp;
343
344 if (!pix) {
345 LOGE("invalid native pixmap");
346 _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCreateImage");
347 return NULL;
348 }
349
350 /* TODO lift this limitation */
351 if (!pix->reserved) {
352 LOGE("TODO support for non-gem based pixmap");
353 _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCreateImage");
354 return NULL;
355 }
356
357 cpp = ui_bytes_per_pixel(pix->format);
358 if (cpp * 8 > DROID_MAX_IMAGE_DEPTH) {
359 LOGE("pixmap of depth %d is not supported", cpp * 8);
360 _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCreateImage");
361 return NULL;
362 }
363
364 isurf = calloc(1, sizeof(*isurf));
365 if (!isurf) {
366 _eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface");
367 return NULL;
368 }
369
370 isurf->type = INTEL_SURFACE_TYPE_IMAGE;
371 isurf->native.pix = pix;
372
373 update_native_buffer((struct droid_surface *) isurf);
374
375 if (depth)
376 *depth = cpp * 8;
377
378 return (struct droid_surface *) isurf;
379}
380
337381static void
338382intel_destroy_surface(struct droid_backend *backend, struct droid_surface *surf)
339383{
462462 intel->base.get_surface_buffers = intel_get_surface_buffers;
463463
464464 intel->base.create_window_surface = intel_create_window_surface;
465 intel->base.create_image_surface = intel_create_image_surface;
465466 intel->base.destroy_surface = intel_destroy_surface;
466467 intel->base.swap_native_buffers = intel_swap_native_buffers;
467468
  
3333#include <assert.h>
3434
3535#include "droid.h"
36#include "EGL/internal/eglimage_dri.h"
3637
3738#ifndef DROID_DRIVER_PATH
3839#define DROID_DRIVER_PATH "/system/lib"
5858 struct droid_surface *surface;
5959
6060 __DRIdrawable *dri_drawable;
61 const __DRIconfig *dri_config;
62 __DRIEGLImage *dri_image;
6163};
6264
6365static __DRIbuffer *
209209 backend->destroy(backend);
210210}
211211
212static void
213screen_find_image_configs(struct droid_screen *screen)
214{
215 struct droid_loader *loader = screen->loader;
216 int depth, i;
217
218 for (depth = 0; depth < DROID_MAX_IMAGE_DEPTH + 1; depth++) {
219 for (i = 0; i < screen->num_dri_configs; i++) {
220 const __DRIconfig *conf = screen->dri_configs[i];
221 _EGLConfig egl_conf;
222 EGLint rgba, val;
223
224 droid_screen_convert_config(screen, conf, &egl_conf);
225
226 val = GET_CONFIG_ATTRIB(&egl_conf, EGL_CONFIG_CAVEAT);
227 if (val == EGL_SLOW_CONFIG)
228 continue;
229
230 rgba = GET_CONFIG_ATTRIB(&egl_conf, EGL_RED_SIZE);
231 rgba += GET_CONFIG_ATTRIB(&egl_conf, EGL_GREEN_SIZE);
232 rgba += GET_CONFIG_ATTRIB(&egl_conf, EGL_BLUE_SIZE);
233 rgba += GET_CONFIG_ATTRIB(&egl_conf, EGL_ALPHA_SIZE);
234 if (depth != rgba)
235 continue;
236
237 if (depth == 32) {
238 val = GET_CONFIG_ATTRIB(&egl_conf, EGL_BIND_TO_TEXTURE_RGBA);
239 if (val) {
240 screen->image_configs[depth] = conf;
241 break;
242 }
243 }
244
245 val = GET_CONFIG_ATTRIB(&egl_conf, EGL_BIND_TO_TEXTURE_RGB);
246 if (val) {
247 screen->image_configs[depth] = conf;
248 break;
249 }
250 }
251 }
252}
253
212254struct droid_screen *
213255droid_screen_create(struct droid_backend *backend)
214256{
313313 ;
314314 screen->num_dri_configs = i;
315315
316 screen_find_image_configs(screen);
317
316318 return screen;
317319
318320fail:
447447 /* needed in GetBuffers */
448448 drawable->loader = loader;
449449 drawable->surface = surf;
450 drawable->dri_config = conf;
450451
451452 drawable->dri_drawable =
452453 loader->dri2->createNewDrawable(screen->dri_screen,
461461 return drawable;
462462}
463463
464void *
465droid_screen_get_drawable_data(struct droid_screen *screen,
466 struct droid_drawable *drawable)
467{
468 struct droid_loader *loader = screen->loader;
469 __DRIEGLImage *img = drawable->dri_image;
470
471 if (!img) {
472 unsigned int val;
473
474 img = calloc(1, sizeof(__DRIEGLImage));
475 if (!img)
476 return NULL;
477
478 img->magic = __DRI_EGL_IMAGE_MAGIC;
479 img->drawable = drawable->dri_drawable;
480 img->level = 0;
481 if (loader->core->getConfigAttrib(drawable->dri_config,
482 EGL_BIND_TO_TEXTURE_RGBA, &val))
483 img->texture_format_rgba = val;
484
485 drawable->dri_image = img;
486 }
487
488 return (void *) img;
489}
490
464491void
465492droid_screen_destroy_drawable(struct droid_screen *screen,
466493 struct droid_drawable *drawable)
467494{
468495 struct droid_loader *loader = screen->loader;
496 if (drawable->dri_image)
497 free(drawable->dri_image);
469498 loader->core->destroyDrawable(drawable->dri_drawable);
470499 free(drawable);
471500}
  
3232#include "eglsurface.h"
3333#include "eglimage.h"
3434
35#include "EGL/internal/eglimage_dri.h"
36
3735#include "droid.h"
3836
3937#ifndef DROID_DEVICE_PATH
7171 struct droid_surface *surface;
7272};
7373
74struct droid_egl_image {
75 _EGLImage base;
76 struct droid_drawable *drawable;
77 struct droid_surface *surface;
78};
79
7480struct droid_egl_config {
7581 _EGLConfig base;
7682 const __DRIconfig *config;
106106 return (struct droid_egl_surface *) surface;
107107}
108108
109static INLINE struct droid_egl_image *
110lookup_image(_EGLImage *image)
111{
112 return (struct droid_egl_image *) image;
113}
114
109115static INLINE struct droid_egl_config *
110116lookup_config(_EGLConfig *conf)
111117{
194194 droid_create_configs(dpy, droid_dpy, droid_dpy->screen->dri_configs,
195195 droid_dpy->screen->num_dri_configs);
196196
197#if EGL_KHR_image_base
198 if (droid_dpy->backend->create_image_surface) {
199 dpy->Extensions.KHR_image = EGL_TRUE;
200 dpy->Extensions.KHR_image_base = EGL_TRUE;
201 dpy->Extensions.KHR_image_pixmap = EGL_TRUE;
202 }
203#endif
204
197205 droid_drv->default_display = droid_dpy;
198206 }
199207
398398 return EGL_TRUE;
399399}
400400
401#if EGL_KHR_image_base
402
403static _EGLImage *
404droid_eglCreateImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
405 EGLenum target, EGLClientBuffer buffer, const EGLint *attr_list)
406{
407 struct droid_egl_display *droid_dpy = lookup_display(dpy);
408 struct droid_egl_image *droid_img;
409 const __DRIconfig *dri_conf;
410 int depth;
411
412 if (target != EGL_NATIVE_PIXMAP_KHR || ctx) {
413 _eglError(EGL_BAD_PARAMETER, "eglCreateImageKHR");
414 return NULL;
415 }
416
417 droid_img = calloc(1, sizeof(*droid_img));
418 if (!droid_img) {
419 _eglError(EGL_BAD_ALLOC, "eglCreateImageKHR");
420 return NULL;
421 }
422
423 if (!_eglInitImage(drv, &droid_img->base, attr_list)) {
424 free(droid_img);
425 return NULL;
426 }
427
428 droid_img->surface =
429 droid_dpy->backend->create_image_surface(droid_dpy->backend,
430 (NativePixmapType) buffer,
431 &depth);
432 if (!droid_img->surface) {
433 free(droid_img);
434 return NULL;
435 }
436
437 dri_conf = droid_dpy->screen->image_configs[depth];
438 if (!dri_conf) {
439 droid_dpy->backend->destroy_surface(droid_dpy->backend,
440 droid_img->surface);
441 free(droid_img);
442 return NULL;
443 }
444
445 droid_img->drawable =
446 droid_screen_create_drawable(droid_dpy->screen, dri_conf,
447 droid_img->surface);
448
449 if (!droid_img->drawable) {
450 droid_dpy->backend->destroy_surface(droid_dpy->backend,
451 droid_img->surface);
452 free(droid_img);
453 return NULL;
454 }
455
456 droid_img->base.ClientData =
457 droid_screen_get_drawable_data(droid_dpy->screen, droid_img->drawable);
458
459 return &droid_img->base;
460}
461
462
401463static EGLBoolean
464droid_eglDestroyImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *img)
465{
466 struct droid_egl_display *droid_dpy = lookup_display(dpy);
467 struct droid_egl_image *droid_img = lookup_image(img);
468
469 droid_screen_destroy_drawable(droid_dpy->screen, droid_img->drawable);
470 droid_dpy->backend->destroy_surface(droid_dpy->backend, droid_img->surface);
471 free(droid_img);
472
473 return EGL_TRUE;
474}
475
476#endif /* EGL_KHR_image_base */
477
478static EGLBoolean
402479droid_eglWaitClient(_EGLDriver *drv, _EGLDisplay *dpy)
403480{
404481 struct droid_egl_driver *droid_drv = lookup_driver(drv);
541541 droid_drv->base.API.CreateWindowSurface = droid_eglCreateWindowSurface;
542542 droid_drv->base.API.DestroySurface = droid_eglDestroySurface;
543543 droid_drv->base.API.SwapBuffers = droid_eglSwapBuffers;
544#if EGL_KHR_image_base
545 droid_drv->base.API.CreateImageKHR = droid_eglCreateImageKHR;
546 droid_drv->base.API.DestroyImageKHR = droid_eglDestroyImageKHR;
547#endif /* EGL_KHR_image_base */
544548 droid_drv->base.API.WaitClient = droid_eglWaitClient;
545549 droid_drv->base.API.WaitNative = droid_eglWaitNative;
546550