Commit 6059e6a8f25e15e934a268d1f022044736f8ba33
- Diff rendering mode:
- inline
- side by side
src/egl/drivers/android/droid.h
(11 / 0)
|   | |||
| 40 | 40 | struct droid_loader; | |
| 41 | 41 | struct droid_context; | |
| 42 | 42 | struct droid_drawable; | |
| 43 | struct droid_image; | ||
| 43 | 44 | struct droid_surface; | |
| 44 | 45 | ||
| 45 | 46 | struct droid_backend { | |
| … | … | ||
| 62 | 62 | struct droid_surface *(*create_window_surface)(struct droid_backend *backend, | |
| 63 | 63 | _EGLSurface *surf, | |
| 64 | 64 | NativeWindowType win); | |
| 65 | struct droid_surface *(*create_image_surface)(struct droid_backend *backend, | ||
| 66 | NativePixmapType pix, | ||
| 67 | int *depth); | ||
| 65 | 68 | void (*destroy_surface)(struct droid_backend *backend, struct droid_surface *surf); | |
| 66 | 69 | void (*swap_native_buffers)(struct droid_backend *backend, | |
| 67 | 70 | struct droid_surface *surf); | |
| … | … | ||
| 79 | 79 | ||
| 80 | 80 | const __DRIconfig **dri_configs; | |
| 81 | 81 | int num_dri_configs; | |
| 82 | |||
| 83 | #define DROID_MAX_IMAGE_DEPTH 32 | ||
| 84 | const __DRIconfig *image_configs[DROID_MAX_IMAGE_DEPTH + 1]; | ||
| 82 | 85 | }; | |
| 83 | 86 | ||
| 84 | 87 | struct droid_backend * | |
| … | … | ||
| 113 | 113 | droid_screen_create_drawable(struct droid_screen *screen, | |
| 114 | 114 | const __DRIconfig *conf, | |
| 115 | 115 | struct droid_surface *surf); | |
| 116 | |||
| 117 | void * | ||
| 118 | droid_screen_get_drawable_data(struct droid_screen *screen, | ||
| 119 | struct droid_drawable *drawable); | ||
| 116 | 120 | ||
| 117 | 121 | void | |
| 118 | 122 | droid_screen_destroy_drawable(struct droid_screen *screen, |
|   | |||
| 46 | 46 | ||
| 47 | 47 | enum { | |
| 48 | 48 | INTEL_SURFACE_TYPE_WINDOW, | |
| 49 | INTEL_SURFACE_TYPE_IMAGE, | ||
| 49 | 50 | }; | |
| 50 | 51 | ||
| 51 | 52 | struct droid_backend_intel { | |
| … | … | ||
| 59 | 59 | int type; | |
| 60 | 60 | union { | |
| 61 | 61 | NativeWindowType win; | |
| 62 | NativePixmapType pix; | ||
| 62 | 63 | } native; | |
| 63 | 64 | __DRIbuffer native_buffer; | |
| 64 | 65 | unsigned int native_width, native_height; | |
| … | … | ||
| 221 | 221 | } | |
| 222 | 222 | else { | |
| 223 | 223 | 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 | } | ||
| 229 | 238 | } | |
| 230 | 239 | num++; | |
| 231 | 240 | } | |
| … | … | ||
| 269 | 269 | width = isurf->native.win->width; | |
| 270 | 270 | height = isurf->native.win->height; | |
| 271 | 271 | 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; | ||
| 272 | 279 | default: | |
| 273 | 280 | name = cpp = pitch = width = height = 0; | |
| 274 | 281 | break; | |
| … | … | ||
| 334 | 334 | return (struct droid_surface *) isurf; | |
| 335 | 335 | } | |
| 336 | 336 | ||
| 337 | static struct droid_surface * | ||
| 338 | intel_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 | |||
| 337 | 381 | static void | |
| 338 | 382 | intel_destroy_surface(struct droid_backend *backend, struct droid_surface *surf) | |
| 339 | 383 | { | |
| … | … | ||
| 462 | 462 | intel->base.get_surface_buffers = intel_get_surface_buffers; | |
| 463 | 463 | ||
| 464 | 464 | intel->base.create_window_surface = intel_create_window_surface; | |
| 465 | intel->base.create_image_surface = intel_create_image_surface; | ||
| 465 | 466 | intel->base.destroy_surface = intel_destroy_surface; | |
| 466 | 467 | intel->base.swap_native_buffers = intel_swap_native_buffers; | |
| 467 | 468 |
|   | |||
| 33 | 33 | #include <assert.h> | |
| 34 | 34 | ||
| 35 | 35 | #include "droid.h" | |
| 36 | #include "EGL/internal/eglimage_dri.h" | ||
| 36 | 37 | ||
| 37 | 38 | #ifndef DROID_DRIVER_PATH | |
| 38 | 39 | #define DROID_DRIVER_PATH "/system/lib" | |
| … | … | ||
| 58 | 58 | struct droid_surface *surface; | |
| 59 | 59 | ||
| 60 | 60 | __DRIdrawable *dri_drawable; | |
| 61 | const __DRIconfig *dri_config; | ||
| 62 | __DRIEGLImage *dri_image; | ||
| 61 | 63 | }; | |
| 62 | 64 | ||
| 63 | 65 | static __DRIbuffer * | |
| … | … | ||
| 209 | 209 | backend->destroy(backend); | |
| 210 | 210 | } | |
| 211 | 211 | ||
| 212 | static void | ||
| 213 | screen_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 | |||
| 212 | 254 | struct droid_screen * | |
| 213 | 255 | droid_screen_create(struct droid_backend *backend) | |
| 214 | 256 | { | |
| … | … | ||
| 313 | 313 | ; | |
| 314 | 314 | screen->num_dri_configs = i; | |
| 315 | 315 | ||
| 316 | screen_find_image_configs(screen); | ||
| 317 | |||
| 316 | 318 | return screen; | |
| 317 | 319 | ||
| 318 | 320 | fail: | |
| … | … | ||
| 447 | 447 | /* needed in GetBuffers */ | |
| 448 | 448 | drawable->loader = loader; | |
| 449 | 449 | drawable->surface = surf; | |
| 450 | drawable->dri_config = conf; | ||
| 450 | 451 | ||
| 451 | 452 | drawable->dri_drawable = | |
| 452 | 453 | loader->dri2->createNewDrawable(screen->dri_screen, | |
| … | … | ||
| 461 | 461 | return drawable; | |
| 462 | 462 | } | |
| 463 | 463 | ||
| 464 | void * | ||
| 465 | droid_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 | |||
| 464 | 491 | void | |
| 465 | 492 | droid_screen_destroy_drawable(struct droid_screen *screen, | |
| 466 | 493 | struct droid_drawable *drawable) | |
| 467 | 494 | { | |
| 468 | 495 | struct droid_loader *loader = screen->loader; | |
| 496 | if (drawable->dri_image) | ||
| 497 | free(drawable->dri_image); | ||
| 469 | 498 | loader->core->destroyDrawable(drawable->dri_drawable); | |
| 470 | 499 | free(drawable); | |
| 471 | 500 | } |
|   | |||
| 32 | 32 | #include "eglsurface.h" | |
| 33 | 33 | #include "eglimage.h" | |
| 34 | 34 | ||
| 35 | #include "EGL/internal/eglimage_dri.h" | ||
| 36 | |||
| 37 | 35 | #include "droid.h" | |
| 38 | 36 | ||
| 39 | 37 | #ifndef DROID_DEVICE_PATH | |
| … | … | ||
| 71 | 71 | struct droid_surface *surface; | |
| 72 | 72 | }; | |
| 73 | 73 | ||
| 74 | struct droid_egl_image { | ||
| 75 | _EGLImage base; | ||
| 76 | struct droid_drawable *drawable; | ||
| 77 | struct droid_surface *surface; | ||
| 78 | }; | ||
| 79 | |||
| 74 | 80 | struct droid_egl_config { | |
| 75 | 81 | _EGLConfig base; | |
| 76 | 82 | const __DRIconfig *config; | |
| … | … | ||
| 106 | 106 | return (struct droid_egl_surface *) surface; | |
| 107 | 107 | } | |
| 108 | 108 | ||
| 109 | static INLINE struct droid_egl_image * | ||
| 110 | lookup_image(_EGLImage *image) | ||
| 111 | { | ||
| 112 | return (struct droid_egl_image *) image; | ||
| 113 | } | ||
| 114 | |||
| 109 | 115 | static INLINE struct droid_egl_config * | |
| 110 | 116 | lookup_config(_EGLConfig *conf) | |
| 111 | 117 | { | |
| … | … | ||
| 194 | 194 | droid_create_configs(dpy, droid_dpy, droid_dpy->screen->dri_configs, | |
| 195 | 195 | droid_dpy->screen->num_dri_configs); | |
| 196 | 196 | ||
| 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 | |||
| 197 | 205 | droid_drv->default_display = droid_dpy; | |
| 198 | 206 | } | |
| 199 | 207 | ||
| … | … | ||
| 398 | 398 | return EGL_TRUE; | |
| 399 | 399 | } | |
| 400 | 400 | ||
| 401 | #if EGL_KHR_image_base | ||
| 402 | |||
| 403 | static _EGLImage * | ||
| 404 | droid_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 | |||
| 401 | 463 | static EGLBoolean | |
| 464 | droid_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 | |||
| 478 | static EGLBoolean | ||
| 402 | 479 | droid_eglWaitClient(_EGLDriver *drv, _EGLDisplay *dpy) | |
| 403 | 480 | { | |
| 404 | 481 | struct droid_egl_driver *droid_drv = lookup_driver(drv); | |
| … | … | ||
| 541 | 541 | droid_drv->base.API.CreateWindowSurface = droid_eglCreateWindowSurface; | |
| 542 | 542 | droid_drv->base.API.DestroySurface = droid_eglDestroySurface; | |
| 543 | 543 | 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 */ | ||
| 544 | 548 | droid_drv->base.API.WaitClient = droid_eglWaitClient; | |
| 545 | 549 | droid_drv->base.API.WaitNative = droid_eglWaitNative; | |
| 546 | 550 |

