/* * Copyright (c) 2011 Benjamin Franzke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include #include #include #include #include "wfddevice.h" #include "wfdsource.h" #include #define EGL_EGLEXT_PROTOTYPES #include #include struct wfd_source { uint32_t handle; uint32_t pitch; }; /* provided by mesa, but not part of the public api */ struct gbm_device * _gbm_mesa_get_device(int fd); static int egl_image_export(struct wfd_device *device, EGLImageKHR image, uint32_t *handle, uint32_t *pitch) { int fd = wfd_device_get_attribi(device, WFD_DEVICE_ID); struct gbm_device *gbm = _gbm_mesa_get_device(fd); struct gbm_bo *bo; bo = gbm_bo_create_from_egl_image(gbm, eglGetDisplay(gbm), image, 1, 1, GBM_BO_USE_SCANOUT); *handle = gbm_bo_get_handle(bo).u32; *pitch = gbm_bo_get_pitch(bo); gbm_bo_destroy(bo); gbm_device_destroy(gbm); return 0; } void wfd_source_destroy(struct wfd_device *device, struct wfd_source *source) { free(source); } struct wfd_source * wfd_source_create(struct wfd_device *device, struct wfd_pipeline *pipeline, WFDEGLImage image, const WFDint *attrib_list) { struct wfd_source *source; source = calloc(1, sizeof *source); if (source == NULL) return NULL; egl_image_export(device, (EGLImageKHR) image, &source->handle, &source->pitch); return source; } uint32_t wfd_source_get_pitch(struct wfd_source *source) { return source->pitch; } uint32_t wfd_source_get_handle(struct wfd_source *source) { return source->handle; }