diff options
author | WuZhen <wuzhen@jidemail.com> | 2016-06-18 21:57:23 +0800 |
---|---|---|
committer | Mauro Rossi <issor.oruam@gmail.com> | 2016-11-01 20:41:59 +0100 |
commit | 61025f0b269c8c31ec76dba5f72d98590d001949 (patch) | |
tree | 8fa72e679966ebc183b85be8360cabcdec2871db /src | |
parent | 74f550427c7fffe637917e2caa79a6bb6c378db4 (diff) | |
download | external_mesa3d-61025f0b269c8c31ec76dba5f72d98590d001949.zip external_mesa3d-61025f0b269c8c31ec76dba5f72d98590d001949.tar.gz external_mesa3d-61025f0b269c8c31ec76dba5f72d98590d001949.tar.bz2 |
android: support swrast
System boots up with gles_mesa/softpipe/llvmpipe.
NO_REF_TASK
Tested: local run
Change-Id: I629ed0ca9fad12e32270eb8e8bfa9f7681b68474
Signed-off-by: Chih-Wei Huang <cwhuang@linux.org.tw>
Diffstat (limited to 'src')
-rw-r--r-- | src/egl/Android.mk | 1 | ||||
-rw-r--r-- | src/egl/drivers/dri2/egl_dri2.c | 1 | ||||
-rw-r--r-- | src/egl/drivers/dri2/platform_android.c | 384 | ||||
-rw-r--r-- | src/gallium/Android.mk | 2 | ||||
-rw-r--r-- | src/gallium/drivers/llvmpipe/Android.mk | 37 | ||||
-rw-r--r-- | src/gallium/include/state_tracker/drm_driver.h | 10 | ||||
-rw-r--r-- | src/gallium/state_trackers/dri/dri2.c | 6 | ||||
-rw-r--r-- | src/gallium/state_trackers/dri/drisw.c | 46 | ||||
-rw-r--r-- | src/gallium/targets/dri/Android.mk | 8 | ||||
-rw-r--r-- | src/gallium/winsys/sw/dri/Android.mk | 2 | ||||
-rw-r--r-- | src/gallium/winsys/sw/dri/dri_sw_winsys.c | 64 | ||||
-rw-r--r-- | src/mesa/drivers/dri/common/dri_util.c | 4 | ||||
-rw-r--r-- | src/mesa/drivers/dri/common/dri_util.h | 2 |
13 files changed, 545 insertions, 22 deletions
diff --git a/src/egl/Android.mk b/src/egl/Android.mk index bfd56a7..a309bb7 100644 --- a/src/egl/Android.mk +++ b/src/egl/Android.mk @@ -46,6 +46,7 @@ LOCAL_CFLAGS := \ LOCAL_C_INCLUDES := \ $(MESA_TOP)/src/egl/main \ $(MESA_TOP)/src/egl/drivers/dri2 \ + $(MESA_TOP)/src/gallium/include \ LOCAL_STATIC_LIBRARIES := \ libmesa_loader diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index d9e2ad7..b12c26c 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -401,6 +401,7 @@ static const struct dri2_extension_match swrast_driver_extensions[] = { static const struct dri2_extension_match swrast_core_extensions[] = { { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer) }, + { __DRI_IMAGE, 1, offsetof(struct dri2_egl_display, image) }, { NULL, 0, 0 } }; diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c index 2d8d7df..3c14086 100644 --- a/src/egl/drivers/dri2/platform_android.c +++ b/src/egl/drivers/dri2/platform_android.c @@ -39,6 +39,7 @@ #include "loader.h" #include "egl_dri2.h" #include "egl_dri2_fallbacks.h" +#include "state_tracker/drm_driver.h" #include "gralloc_drm.h" #include "gralloc_drm_handle.h" @@ -121,6 +122,8 @@ get_native_buffer_name(struct ANativeWindowBuffer *buf) return (handle) ? handle->name : 0; } +static const gralloc_module_t *gr_module = NULL; + static EGLBoolean droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf) { @@ -302,9 +305,14 @@ droid_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type, if (!config) goto cleanup_surface; - dri2_surf->dri_drawable = - (*dri2_dpy->dri2->createNewDrawable)(dri2_dpy->dri_screen, config, - dri2_surf); + if (dri2_dpy->dri2) { + dri2_surf->dri_drawable = + dri2_dpy->dri2->createNewDrawable(dri2_dpy->dri_screen, config, dri2_surf); + } else { + dri2_surf->dri_drawable = + dri2_dpy->swrast->createNewDrawable(dri2_dpy->dri_screen, config, dri2_surf); + } + if (dri2_surf->dri_drawable == NULL) { _eglError(EGL_BAD_ALLOC, "dri2->createNewDrawable"); goto cleanup_surface; @@ -809,20 +817,260 @@ droid_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *dpy) return (count != 0); } +static int swrastUpdateBuffer(struct dri2_egl_surface *dri2_surf) +{ + if (dri2_surf->base.Type == EGL_WINDOW_BIT) { + if (!dri2_surf->buffer && !droid_window_dequeue_buffer(dri2_surf)) { + _eglLog(_EGL_WARNING, "failed to dequeue buffer for window"); + return 1; + } + dri2_surf->base.Width = dri2_surf->buffer->width; + dri2_surf->base.Height = dri2_surf->buffer->height; + } + return 0; +} + +static void +swrastGetDrawableInfo(__DRIdrawable * draw, + int *x, int *y, int *w, int *h, + void *loaderPrivate) +{ + struct dri2_egl_surface *dri2_surf = loaderPrivate; + + swrastUpdateBuffer(dri2_surf); + + *x = 0; + *y = 0; + *w = dri2_surf->base.Width; + *h = dri2_surf->base.Height; +} + +static void +swrastPutImage2(__DRIdrawable * draw, int op, + int x, int y, int w, int h, int stride, + char *data, void *loaderPrivate) +{ + struct dri2_egl_surface *dri2_surf = loaderPrivate; + struct _EGLDisplay *egl_dpy = dri2_surf->base.Resource.Display; + char *dstPtr, *srcPtr; + size_t BPerPixel, dstStride, copyWidth, xOffset; + +// _eglLog(_EGL_WARNING, "calling swrastPutImage with draw=%p, private=%p, x=%d, y=%d, w=%d, h=%d", +// draw, loaderPrivate, x, y, w, h); + + if (swrastUpdateBuffer(dri2_surf)) { + return; + } + + BPerPixel = get_format_bpp(dri2_surf->buffer->format); + dstStride = BPerPixel * dri2_surf->buffer->stride; + copyWidth = BPerPixel * w; + xOffset = BPerPixel * x; + + /* drivers expect we do these checks (and some rely on it) */ + if (copyWidth > dstStride - xOffset) + copyWidth = dstStride - xOffset; + if (h > dri2_surf->base.Height - y) + h = dri2_surf->base.Height - y; + + if (gr_module->lock(gr_module, dri2_surf->buffer->handle, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, + 0, 0, dri2_surf->buffer->width, dri2_surf->buffer->height, (void**)&dstPtr)) { + _eglLog(_EGL_WARNING, "can not lock window buffer"); + return; + } + + dstPtr += y * dstStride + xOffset; + srcPtr = data; + + for (; h>0; h--) { + memcpy(dstPtr, srcPtr, copyWidth); + srcPtr += stride; + dstPtr += dstStride; + } + + if (gr_module->unlock(gr_module, dri2_surf->buffer->handle)) { + _eglLog(_EGL_WARNING, "unlock buffer failed"); + } + + droid_window_enqueue_buffer(egl_dpy, dri2_surf); +} + +static void +swrastPutImage(__DRIdrawable * draw, int op, + int x, int y, int w, int h, + char *data, void *loaderPrivate) +{ + struct dri2_egl_surface *dri2_surf = loaderPrivate; + int stride; + + if (swrastUpdateBuffer(dri2_surf)) { + return; + } + + stride = get_format_bpp(dri2_surf->buffer->format) * w; + swrastPutImage2(draw, op, x, y, w, h, stride, data, loaderPrivate); +} + +static void +swrastGetImage(__DRIdrawable * read, + int x, int y, int w, int h, + char *data, void *loaderPrivate) +{ + struct dri2_egl_surface *dri2_surf = loaderPrivate; + size_t BPerPixel, srcStride, copyWidth, xOffset; + char *dstPtr, *srcPtr; + + _eglLog(_EGL_WARNING, "calling swrastGetImage with read=%p, private=%p, w=%d, h=%d", read, loaderPrivate, w, h); + + if (swrastUpdateBuffer(dri2_surf)) { + _eglLog(_EGL_WARNING, "swrastGetImage failed data unchanged"); + return; + } + + BPerPixel = get_format_bpp(dri2_surf->buffer->format); + srcStride = BPerPixel * dri2_surf->buffer->stride; + copyWidth = BPerPixel * w; + xOffset = BPerPixel * x; + + if (gr_module->lock(gr_module, dri2_surf->buffer->handle, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, + 0, 0, dri2_surf->buffer->width, dri2_surf->buffer->height, (void**)&srcPtr)) { + _eglLog(_EGL_WARNING, "can not lock window buffer"); + memset(data, 0, copyWidth * h); + return; + } + + srcPtr += y * srcStride + xOffset; + dstPtr = data; + + for (; h>0; h--) { + memcpy(dstPtr, srcPtr, copyWidth); + srcPtr += srcStride; + dstPtr += copyWidth; + } + + if (gr_module->unlock(gr_module, dri2_surf->buffer->handle)) { + _eglLog(_EGL_WARNING, "unlock buffer failed"); + } +} + +static EGLBoolean +swrast_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); + + dri2_dpy->core->swapBuffers(dri2_surf->dri_drawable); + + return EGL_TRUE; +} + +static _EGLImage * +swrast_create_image_android_native_buffer(_EGLDisplay *disp, _EGLContext *ctx, + struct ANativeWindowBuffer *buf) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_image *dri2_img; + struct winsys_handle whandle; + EGLint format; + + if (ctx != NULL) { + /* From the EGL_ANDROID_image_native_buffer spec: + * + * * If <target> is EGL_NATIVE_BUFFER_ANDROID and <ctx> is not + * EGL_NO_CONTEXT, the error EGL_BAD_CONTEXT is generated. + */ + _eglError(EGL_BAD_CONTEXT, "eglCreateEGLImageKHR: for " + "EGL_NATIVE_BUFFER_ANDROID, the context must be " + "EGL_NO_CONTEXT"); + return NULL; + } + + if (!buf || buf->common.magic != ANDROID_NATIVE_BUFFER_MAGIC || + buf->common.version != sizeof(*buf)) { + _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR"); + return NULL; + } + + /* see the table in droid_add_configs_for_visuals */ + format = get_format(buf->format); + if (format < 0) + return NULL; + + dri2_img = calloc(1, sizeof(*dri2_img)); + if (!dri2_img) { + _eglError(EGL_BAD_ALLOC, "droid_create_image_mesa_drm"); + return NULL; + } + + if (!_eglInitImage(&dri2_img->base, disp)) { + free(dri2_img); + return NULL; + } + + memset(&whandle, 0, sizeof(whandle)); + whandle.type = DRM_API_HANDLE_TYPE_BUFFER; + whandle.externalBuffer = buf; + whandle.stride = buf->stride * get_format_bpp(buf->format); + + dri2_img->dri_image = + dri2_dpy->swrast->createImageFromWinsys(dri2_dpy->dri_screen, + buf->width, + buf->height, + format, + 1, &whandle, + dri2_img); + + if (!dri2_img->dri_image) { + free(dri2_img); + _eglError(EGL_BAD_ALLOC, "droid_create_image_mesa_drm"); + return NULL; + } + + return &dri2_img->base; +} + +static _EGLImage * +swrast_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, + _EGLContext *ctx, EGLenum target, + EGLClientBuffer buffer, const EGLint *attr_list) +{ + switch (target) { + case EGL_NATIVE_BUFFER_ANDROID: + return swrast_create_image_android_native_buffer(disp, ctx, + (struct ANativeWindowBuffer *) buffer); + default: + return dri2_fallback_create_image_khr(drv, disp, ctx, target, buffer, attr_list); + } +} + static int -droid_open_device(void) +load_gralloc(void) { const hw_module_t *mod; - int fd = -1, err; + int err; err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &mod); if (!err) { - const gralloc_module_t *gr = (gralloc_module_t *) mod; - - err = -EINVAL; - if (gr->perform) - err = gr->perform(gr, GRALLOC_MODULE_PERFORM_GET_DRM_FD, &fd); + gr_module = (gralloc_module_t *) mod; + } else { + _eglLog(_EGL_WARNING, "fail to load gralloc"); } + return err; +} + +static int +is_drm_gralloc(void) +{ + /* need a cleaner way to distinguish drm_gralloc and gralloc.default */ + return !!gr_module->perform; +} + +static int +droid_open_device(void) +{ + int fd = -1, err; + + err = gr_module->perform(gr_module, GRALLOC_MODULE_PERFORM_GET_DRM_FD, &fd); if (err || fd < 0) { _eglLog(_EGL_WARNING, "fail to get drm fd"); fd = -1; @@ -912,8 +1160,8 @@ static const __DRIextension *droid_image_loader_extensions[] = { NULL, }; -EGLBoolean -dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy) +static EGLBoolean +dri2_initialize_android_drm(_EGLDriver *drv, _EGLDisplay *dpy) { struct dri2_egl_display *dri2_dpy; const char *err; @@ -989,3 +1237,115 @@ cleanup_display: return _eglError(EGL_NOT_INITIALIZED, err); } + +/* differs with droid_display_vtbl in create_image, swap_buffers */ +static struct dri2_egl_display_vtbl swrast_display_vtbl = { + .authenticate = NULL, + .create_window_surface = droid_create_window_surface, + .create_pixmap_surface = dri2_fallback_create_pixmap_surface, + .create_pbuffer_surface = droid_create_pbuffer_surface, + .destroy_surface = droid_destroy_surface, + .create_image = swrast_create_image_khr, + .swap_interval = dri2_fallback_swap_interval, + .swap_buffers = swrast_swap_buffers, + .swap_buffers_with_damage = dri2_fallback_swap_buffers_with_damage, + .swap_buffers_region = dri2_fallback_swap_buffers_region, + .post_sub_buffer = dri2_fallback_post_sub_buffer, + .copy_buffers = dri2_fallback_copy_buffers, + .query_buffer_age = dri2_fallback_query_buffer_age, + .create_wayland_buffer_from_image = dri2_fallback_create_wayland_buffer_from_image, + .get_sync_values = dri2_fallback_get_sync_values, + .get_dri_drawable = dri2_surface_get_dri_drawable, +}; + +static EGLBoolean +dri2_initialize_android_swrast(_EGLDriver *drv, _EGLDisplay *dpy) +{ + struct dri2_egl_display *dri2_dpy; + const char *err = ""; + const hw_module_t *mod; + + _eglSetLogProc(droid_log); + + loader_set_logger(_eglLog); + + dri2_dpy = calloc(1, sizeof(*dri2_dpy)); + if (!dri2_dpy) + return _eglError(EGL_BAD_ALLOC, "eglInitialize"); + + dpy->DriverData = (void *) dri2_dpy; + + dri2_dpy->driver_name = strdup("swrast"); + if (!dri2_load_driver_swrast(dpy)) { + err = "DRISW: failed to load swrast driver"; + goto cleanup_driver_name; + } + + dri2_dpy->swrast_loader_extension.base.name = __DRI_SWRAST_LOADER; + dri2_dpy->swrast_loader_extension.base.version = 2; + dri2_dpy->swrast_loader_extension.getDrawableInfo = swrastGetDrawableInfo; + dri2_dpy->swrast_loader_extension.putImage = swrastPutImage; + dri2_dpy->swrast_loader_extension.putImage2 = swrastPutImage2; + dri2_dpy->swrast_loader_extension.getImage = swrastGetImage; + + dri2_dpy->extensions[0] = &dri2_dpy->swrast_loader_extension.base; + dri2_dpy->extensions[1] = &image_lookup_extension.base; + dri2_dpy->extensions[2] = NULL; + + if (!dri2_create_screen(dpy)) { + err = "DRISW: failed to create screen"; + goto cleanup_driver; + } + + if (!droid_add_configs_for_visuals(drv, dpy)) { + err = "DRISW: failed to add configs"; + goto cleanup_screen; + } + + dpy->Extensions.ANDROID_framebuffer_target = EGL_TRUE; + dpy->Extensions.ANDROID_image_native_buffer = EGL_TRUE; + dpy->Extensions.ANDROID_recordable = EGL_TRUE; + dpy->Extensions.KHR_image_base = EGL_TRUE; + + /* Fill vtbl last to prevent accidentally calling virtual function during + * initialization. + */ + dri2_dpy->vtbl = &swrast_display_vtbl; + + return EGL_TRUE; + +cleanup_screen: + dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); +cleanup_driver: + dlclose(dri2_dpy->driver); +cleanup_driver_name: + free(dri2_dpy->driver_name); + free(dri2_dpy); + + return _eglError(EGL_NOT_INITIALIZED, err); +} + +EGLBoolean +dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy) +{ + EGLBoolean initialized = EGL_TRUE; + + if (load_gralloc()) { + return EGL_FALSE; + } + + int droid_hw_accel = (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL) && is_drm_gralloc(); + + if (droid_hw_accel) { + if (!dri2_initialize_android_drm(drv, dpy)) { + initialized = dri2_initialize_android_swrast(drv, dpy); + if (initialized) { + _eglLog(_EGL_INFO, "Android: Fallback to software renderer"); + } + } + } else { + initialized = dri2_initialize_android_swrast(drv, dpy); + } + + return initialized; +} diff --git a/src/gallium/Android.mk b/src/gallium/Android.mk index 2b469b6..690b289 100644 --- a/src/gallium/Android.mk +++ b/src/gallium/Android.mk @@ -35,7 +35,7 @@ SUBDIRS += auxiliary/pipe-loader # swrast ifneq ($(filter swrast,$(MESA_GPU_DRIVERS)),) -SUBDIRS += winsys/sw/dri drivers/softpipe +SUBDIRS += winsys/sw/dri drivers/llvmpipe drivers/softpipe endif # freedreno diff --git a/src/gallium/drivers/llvmpipe/Android.mk b/src/gallium/drivers/llvmpipe/Android.mk new file mode 100644 index 0000000..b074e34 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/Android.mk @@ -0,0 +1,37 @@ +# Mesa 3-D graphics library +# +# Copyright (C) 2015-2016 Zhen Wu <wuzhen@jidemail.com> +# Copyright (C) 2015-2016 Jide Inc. +# +# 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. + +LOCAL_PATH := $(call my-dir) + +# get C_SOURCES +include $(LOCAL_PATH)/Makefile.sources + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + $(C_SOURCES) + +LOCAL_MODULE := libmesa_pipe_llvmpipe + +include $(GALLIUM_COMMON_MK) +include $(BUILD_STATIC_LIBRARY) diff --git a/src/gallium/include/state_tracker/drm_driver.h b/src/gallium/include/state_tracker/drm_driver.h index c80fb09..b8dfd23 100644 --- a/src/gallium/include/state_tracker/drm_driver.h +++ b/src/gallium/include/state_tracker/drm_driver.h @@ -11,6 +11,7 @@ struct pipe_resource; #define DRM_API_HANDLE_TYPE_SHARED 0 #define DRM_API_HANDLE_TYPE_KMS 1 #define DRM_API_HANDLE_TYPE_FD 2 +#define DRM_API_HANDLE_TYPE_BUFFER 3 /** @@ -20,11 +21,18 @@ struct winsys_handle { /** * Input for texture_from_handle, valid values are - * DRM_API_HANDLE_TYPE_SHARED or DRM_API_HANDLE_TYPE_FD. + * DRM_API_HANDLE_TYPE_SHARED or DRM_API_HANDLE_TYPE_FD or DRM_API_HANDLE_TYPE_BUFFER. * Input to texture_get_handle, * to select handle for kms, flink, or prime. */ unsigned type; + + /** + * Input to texture_from_handle. + * Output for texture_get_handle. + */ + void* externalBuffer; + /** * Input for texture_get_handle, allows to export the offset * of a specific layer of an array texture. diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c index db8f70e..8c058f7 100644 --- a/src/gallium/state_trackers/dri/dri2.c +++ b/src/gallium/state_trackers/dri/dri2.c @@ -765,7 +765,7 @@ dri2_update_tex_buffer(struct dri_drawable *drawable, /* no-op */ } -static __DRIimage * +__DRIimage * dri2_lookup_egl_image(struct dri_screen *screen, void *handle) { const __DRIimageLookupExtension *loader = screen->sPriv->dri2.image; @@ -780,7 +780,7 @@ dri2_lookup_egl_image(struct dri_screen *screen, void *handle) return img; } -static __DRIimage * +__DRIimage * dri2_create_image_from_winsys(__DRIscreen *_screen, int width, int height, int format, int num_handles, struct winsys_handle *whandle, @@ -1374,7 +1374,7 @@ dri2_unmap_image(__DRIcontext *context, __DRIimage *image, void *data) pipe_transfer_unmap(pipe, (struct pipe_transfer *)data); } -static void +void dri2_destroy_image(__DRIimage *img) { pipe_resource_reference(&img->texture, NULL); diff --git a/src/gallium/state_trackers/dri/drisw.c b/src/gallium/state_trackers/dri/drisw.c index b85a73c..9b62b96 100644 --- a/src/gallium/state_trackers/dri/drisw.c +++ b/src/gallium/state_trackers/dri/drisw.c @@ -361,14 +361,57 @@ drisw_update_tex_buffer(struct dri_drawable *drawable, pipe_transfer_unmap(pipe, transfer); } +extern __DRIimage *dri2_lookup_egl_image(struct dri_screen *screen, void *handle); + +extern __DRIimage *dri2_create_image_from_winsys(__DRIscreen *_screen, + int width, int height, int format, + int num_handles, struct winsys_handle *whandle, + void *loaderPrivate); + +extern void dri2_destroy_image(__DRIimage *img); + +static GLboolean +drisw_query_image(__DRIimage *image, int attrib, int *value) +{ + switch (attrib) { + case __DRI_IMAGE_ATTRIB_FORMAT: + *value = image->dri_format; + return GL_TRUE; + case __DRI_IMAGE_ATTRIB_WIDTH: + *value = image->texture->width0; + return GL_TRUE; + case __DRI_IMAGE_ATTRIB_HEIGHT: + *value = image->texture->height0; + return GL_TRUE; + case __DRI_IMAGE_ATTRIB_COMPONENTS: + if (image->dri_components == 0) + return GL_FALSE; + *value = image->dri_components; + return GL_TRUE; + case __DRI_IMAGE_ATTRIB_NUM_PLANES: + *value = 1; + return GL_TRUE; + default: + return GL_FALSE; + } +} + /* * Backend function for init_screen. */ +static const __DRIimageExtension driswImageExtension = { + .base = { __DRI_IMAGE, 11 }, + + .destroyImage = dri2_destroy_image, + .queryImage = drisw_query_image, +}; + static const __DRIextension *drisw_screen_extensions[] = { &driTexBufferExtension.base, &dri2RendererQueryExtension.base, &dri2ConfigQueryExtension.base, + &driswImageExtension.base, NULL }; @@ -407,6 +450,9 @@ drisw_init_screen(__DRIscreen * sPriv) if (!configs) goto fail; + screen->lookup_egl_image = dri2_lookup_egl_image; + driSWRastExtension.createImageFromWinsys = dri2_create_image_from_winsys; + return configs; fail: dri_destroy_screen_helper(screen); diff --git a/src/gallium/targets/dri/Android.mk b/src/gallium/targets/dri/Android.mk index f1a5b0e..13505c8 100644 --- a/src/gallium/targets/dri/Android.mk +++ b/src/gallium/targets/dri/Android.mk @@ -49,6 +49,7 @@ LOCAL_SHARED_LIBRARIES := \ liblog \ libglapi \ libexpat \ + libhardware \ ifneq ($(filter freedreno,$(MESA_GPU_DRIVERS)),) LOCAL_CFLAGS += -DGALLIUM_FREEDRENO @@ -88,8 +89,9 @@ gallium_DRIVERS += libmesa_winsys_radeon libmesa_pipe_radeon libmesa_amdgpu_addr LOCAL_SHARED_LIBRARIES += libdrm_radeon endif ifneq ($(filter swrast,$(MESA_GPU_DRIVERS)),) -gallium_DRIVERS += libmesa_pipe_softpipe libmesa_winsys_sw_dri -LOCAL_CFLAGS += -DGALLIUM_SOFTPIPE +gallium_DRIVERS += libmesa_pipe_llvmpipe libmesa_pipe_softpipe libmesa_winsys_sw_dri +LOCAL_CFLAGS += -DGALLIUM_LLVMPIPE -DGALLIUM_SOFTPIPE +LOCAL_SHARED_LIBRARIES += libLLVM endif ifneq ($(filter vc4,$(MESA_GPU_DRIVERS)),) LOCAL_CFLAGS += -DGALLIUM_VC4 @@ -133,5 +135,7 @@ LOCAL_STATIC_LIBRARIES += \ LOCAL_LDLIBS += $(if $(filter true,$(MESA_LOLLIPOP_BUILD)),-lgcc) endif +LOCAL_ADDITION_DEPENDENCIES := $(LOCAL_PATH)/Android.mk + include $(GALLIUM_COMMON_MK) include $(BUILD_SHARED_LIBRARY) diff --git a/src/gallium/winsys/sw/dri/Android.mk b/src/gallium/winsys/sw/dri/Android.mk index 72fb920..d25e677 100644 --- a/src/gallium/winsys/sw/dri/Android.mk +++ b/src/gallium/winsys/sw/dri/Android.mk @@ -29,6 +29,8 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := $(C_SOURCES) +LOCAL_CFLAGS += -DHAVE_ANDROID_PLATFORM + LOCAL_MODULE := libmesa_winsys_sw_dri include $(GALLIUM_COMMON_MK) diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.c b/src/gallium/winsys/sw/dri/dri_sw_winsys.c index 94d5092..ea1fe58 100644 --- a/src/gallium/winsys/sw/dri/dri_sw_winsys.c +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.c @@ -34,8 +34,14 @@ #include "util/u_memory.h" #include "state_tracker/sw_winsys.h" +#include "state_tracker/drm_driver.h" #include "dri_sw_winsys.h" +#ifdef HAVE_ANDROID_PLATFORM +#include <system/graphics.h> +#include <system/window.h> +#include <hardware/gralloc.h> +#endif struct dri_sw_displaytarget { @@ -45,11 +51,31 @@ struct dri_sw_displaytarget unsigned stride; unsigned map_flags; +#ifdef HAVE_ANDROID_PLATFORM + struct ANativeWindowBuffer *androidBuffer; +#endif void *data; void *mapped; const void *front_private; }; +#ifdef HAVE_ANDROID_PLATFORM +const struct gralloc_module_t* get_gralloc() +{ + static const struct gralloc_module_t* gr_module = NULL; + const hw_module_t *mod; + int err; + + if (!gr_module) { + err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &mod); + if (!err) { + gr_module = (gralloc_module_t *) mod; + } + } + return gr_module; +} +#endif + struct dri_sw_winsys { struct sw_winsys base; @@ -125,6 +151,12 @@ dri_sw_displaytarget_destroy(struct sw_winsys *ws, { struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt); +#ifdef HAVE_ANDROID_PLATFORM + if (dri_sw_dt->androidBuffer) { + dri_sw_dt->androidBuffer->common.decRef(&dri_sw_dt->androidBuffer->common); + } +#endif + align_free(dri_sw_dt->data); FREE(dri_sw_dt); @@ -136,6 +168,17 @@ dri_sw_displaytarget_map(struct sw_winsys *ws, unsigned flags) { struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt); +#ifdef HAVE_ANDROID_PLATFORM + if (dri_sw_dt->androidBuffer) { + if (!get_gralloc()->lock(get_gralloc(), dri_sw_dt->androidBuffer->handle, + GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, + 0, 0, dri_sw_dt->androidBuffer->width, dri_sw_dt->androidBuffer->height, + (void**)&dri_sw_dt->mapped)) { + dri_sw_dt->map_flags = flags; + return dri_sw_dt->mapped; + } + } +#endif dri_sw_dt->mapped = dri_sw_dt->data; if (dri_sw_dt->front_private && (flags & PIPE_TRANSFER_READ)) { @@ -156,6 +199,11 @@ dri_sw_displaytarget_unmap(struct sw_winsys *ws, dri_sw_ws->lf->put_image2((void *)dri_sw_dt->front_private, dri_sw_dt->data, 0, 0, dri_sw_dt->width, dri_sw_dt->height, dri_sw_dt->stride); } dri_sw_dt->map_flags = 0; +#ifdef HAVE_ANDROID_PLATFORM + if (dri_sw_dt->androidBuffer) { + get_gralloc()->unlock(get_gralloc(), dri_sw_dt->androidBuffer->handle); + } +#endif dri_sw_dt->mapped = NULL; } @@ -165,6 +213,22 @@ dri_sw_displaytarget_from_handle(struct sw_winsys *winsys, struct winsys_handle *whandle, unsigned *stride) { +#ifdef HAVE_ANDROID_PLATFORM + struct dri_sw_displaytarget *dri_sw_dt; + + if (whandle->type == DRM_API_HANDLE_TYPE_BUFFER) { + dri_sw_dt = CALLOC_STRUCT(dri_sw_displaytarget); + dri_sw_dt->width = templ->width0; + dri_sw_dt->height = templ->height0; + dri_sw_dt->androidBuffer = whandle->externalBuffer; + dri_sw_dt->stride = whandle->stride; + + dri_sw_dt->androidBuffer->common.incRef(&dri_sw_dt->androidBuffer->common); + *stride = dri_sw_dt->stride; + + return dri_sw_dt; + } +#endif assert(0); return NULL; } diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c index 79cb050..eafd152 100644 --- a/src/mesa/drivers/dri/common/dri_util.c +++ b/src/mesa/drivers/dri/common/dri_util.c @@ -781,8 +781,8 @@ const __DRIdri2Extension driDRI2Extension = { .createNewScreen2 = driCreateNewScreen2, }; -const __DRIswrastExtension driSWRastExtension = { - .base = { __DRI_SWRAST, 4 }, +__DRIswrastExtension driSWRastExtension = { + .base = { __DRI_SWRAST, 5 }, .createNewScreen = driSWRastCreateNewScreen, .createNewDrawable = driCreateNewDrawable, diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h index 6987f55..79148fa 100644 --- a/src/mesa/drivers/dri/common/dri_util.h +++ b/src/mesa/drivers/dri/common/dri_util.h @@ -63,7 +63,7 @@ * Extensions. */ extern const __DRIcoreExtension driCoreExtension; -extern const __DRIswrastExtension driSWRastExtension; +extern __DRIswrastExtension driSWRastExtension; extern const __DRIdri2Extension driDRI2Extension; extern const __DRI2configQueryExtension dri2ConfigQueryExtension; extern const __DRIcopySubBufferExtension driCopySubBufferExtension; |