Compare commits

...

63 Commits

Author SHA1 Message Date
Chih-Wei Huang
559a79ff87 Merge remote-tracking branch 'x86/froyo-x86' into froyo-next 2011-04-07 16:50:48 +08:00
Chia-I Wu
e87d4d2e31 egl_android: assorted fixes 2011-03-29 06:31:15 +08:00
Chia-I Wu
0c1c261c2d gralloc: glFlush() should suffice for page flipping 2011-03-28 22:33:38 +08:00
Chia-I Wu
f27a8a3321 gralloc: improve page flip blocking
Use DRM_MODE_PAGE_FLIP_EVENT.
2011-03-28 22:20:29 +08:00
Chia-I Wu
98e1078d71 gralloc: boost radeon performance
Allocate buffer from GTT for 2D apps.
2011-03-26 15:59:05 +08:00
Chia-I Wu
1e21885cde gralloc: improve radeon sync issue 2011-03-26 15:46:32 +08:00
Chia-I Wu
7492794ef5 glsl: add missing generated files 2011-03-26 15:20:15 +08:00
Chia-I Wu
16ca82773e gralloc: kernel module name is i915 2011-03-25 16:50:37 +08:00
Chia-I Wu
f84d946322 android: fix building 2011-03-25 03:30:43 +08:00
Chia-I Wu
66c6b2520d st/egl: add support for loading radeon 2011-03-25 03:30:43 +08:00
Chia-I Wu
f3837c7094 egl_android: add support for loading radeon
For completeness.  Not used.
2011-03-25 03:30:43 +08:00
Chia-I Wu
d8ebb254c2 android: use __mmap2 for winsys/r600 2011-03-25 03:30:43 +08:00
Chia-I Wu
dd4929b30b gralloc: add radeon support 2011-03-25 03:30:43 +08:00
Chia-I Wu
0b9a9c408f gralloc: rename i915 to intel 2011-03-25 03:30:43 +08:00
Chia-I Wu
5dddfa8591 gralloc: add multiple driver support 2011-03-25 03:30:43 +08:00
Chia-I Wu
7baac8d734 mesa: fix glDrawTex*
As the case with _mesa_DrawPixels, the driver may install its vertex
shader and the vp override flag should be set.
2011-03-25 03:29:54 +08:00
Chia-I Wu
887b78bb5b auxiliary: disable SSE translate
It does not support FIXED.
2011-03-25 03:29:04 +08:00
Chia-I Wu
d175f38bc3 mesa: one more missing pre-generated file 2011-03-17 15:59:23 +08:00
Chia-I Wu
eeb3391bd5 mesa: add more pre-generated files 2011-03-17 14:46:57 +08:00
Chia-I Wu
06608674d0 egl_android: update surface geometry 2011-03-16 20:18:40 +08:00
Chia-I Wu
9f119b3c51 intel: advertise GL_OES_point_sprite 2011-03-16 20:18:40 +08:00
Chia-I Wu
c4d9c4f7f1 i965c: add MESA_FORMAT_RGBA8888_REV to brw_format_for_mesa_format
The framebuffer uses

  PIXEL_FORMAT_BGRA_8888 -> MESA_FORMAT_ARGB8888

while applications use

  PIXEL_FORMAT_RGBA_8888 -> MESA_FORMAT_RGBA8888_REV
  PIXEL_FORMAT_RGB_565   -> MESA_FORMAT_RGB565
2011-03-16 20:18:40 +08:00
Chia-I Wu
e4706d5cc8 mesa: advertise GL_ARB_texture_non_power_of_two
It maps to DisplayHardware::NPOT_EXTENSION in SurfaceFlinger.
2011-03-16 20:18:40 +08:00
Chia-I Wu
9a3759c3dd android: Add Android.mk's. 2011-03-16 20:18:40 +08:00
Chia-I Wu
f547fef2d0 android: Add pre-generated files.
make -C src/glsl builtin_function.cpp
  make -C src/es1api
  make -C src/es2api
  make -C src/shared-glapi
  make -C src/mesa/mai/api_exec_es{12}.c
2011-03-16 20:18:39 +08:00
Chia-I Wu
73d3113849 android: Add __DRI_IMAGE_FORMAT_RGBA8888_REV. 2011-03-16 20:18:39 +08:00
Chia-I Wu
2b1f1af17f android: Add DRM-based gralloc. 2011-03-16 20:18:39 +08:00
Chia-I Wu
8e698931d7 android: Make egl_android load DRI drivers. 2011-03-16 20:18:39 +08:00
Chia-I Wu
f60af24be7 android: Add new classic EGL driver for Android. 2011-03-16 20:18:39 +08:00
Chia-I Wu
17cd318e41 android: Add android backend for st/egl. 2011-03-16 20:18:39 +08:00
Chia-I Wu
f2d8241f01 android: Add Android EGL extensions. 2011-03-16 20:18:39 +08:00
Chia-I Wu
f9172081ca android: Add _EGL_PLATFORM_ANDROID. 2011-03-16 20:18:39 +08:00
Chia-I Wu
cb4afed922 android: Enable extensions required by ES1 for i915c. 2011-03-16 20:18:39 +08:00
Chia-I Wu
5d1e2165f7 android: Fix depth/stencil with i915c/i965c. 2011-03-16 20:18:39 +08:00
Chia-I Wu
39d1094301 android: Fix GL_OES_EGL_image with SurfaceFlinger. 2011-03-16 20:18:39 +08:00
Chia-I Wu
fb3c3f3079 android: Use __mmap2 in winsys/svga. 2011-03-16 20:18:39 +08:00
Chia-I Wu
c60978b2e0 android: Fix build with bionic. 2011-03-16 20:18:39 +08:00
Chia-I Wu
80a8e7d3d1 i965c: Fix a declaration in for loop. 2011-03-16 20:18:39 +08:00
Chia-I Wu
a0f0662e0c i965c: Add support for GL_FIXED.
Quick and dirty..
2011-03-16 20:18:29 +08:00
Chia-I Wu
d5d833a353 i915c: Add GL_OES_draw_texture support. 2011-03-16 14:17:52 +08:00
Chia-I Wu
32197c0094 i915: Free with FREE. 2011-03-16 14:17:43 +08:00
Chih-Wei Huang
f189dfe9e9 mesa: fix compiling issues with gcc 4.4.x
Gcc 4.4 requires a class with virtual functions has to
define the virtual destructor.
2010-12-29 17:35:47 +08:00
Chia-I Wu
d1ccafa5b7 android: Enable OpenGL ES 2.0. 2010-12-29 16:56:47 +08:00
Chia-I Wu
f7a0636329 i965: Add support for GL_FIXED. 2010-12-11 21:47:18 +08:00
Chih-Wei Huang
6269411b81 android: enable support of i965c 2010-12-09 20:01:35 -05:00
Chia-I Wu
88721c8555 android: Add Android.mk's. 2010-12-09 20:01:35 -05:00
Chia-I Wu
4128957d30 android: Add pre-generated files. 2010-12-09 20:01:35 -05:00
Chia-I Wu
07a8209c3f android: Add __DRI_IMAGE_FORMAT_RGBA8888_REV. 2010-12-09 20:01:35 -05:00
Chia-I Wu
b0a79b3512 android: Add DRM-based gralloc. 2010-12-09 20:01:35 -05:00
Chia-I Wu
121fc671f4 android: Add new classic EGL driver for Android. 2010-12-09 20:01:35 -05:00
Chia-I Wu
8148db591a android: Add android backend for st/egl. 2010-12-09 20:01:35 -05:00
Chia-I Wu
0d4dcb2584 android: Add Android EGL extensions. 2010-12-09 20:01:35 -05:00
Chia-I Wu
1337551451 android: Add _EGL_PLATFORM_ANDROID. 2010-12-09 20:01:35 -05:00
Chia-I Wu
6719d59a85 android: Enable extensions required by ES1 for i915c. 2010-12-09 20:01:35 -05:00
Chia-I Wu
3fe7753b70 android: Fix depth/stencil with i915c. 2010-12-09 20:01:34 -05:00
Chia-I Wu
017c563cff android: Fix GL_OES_EGL_image with SurfaceFlinger. 2010-12-09 20:01:34 -05:00
Chia-I Wu
bf21df37c6 android: Use __mmap2 in winsys/svga. 2010-12-09 20:01:34 -05:00
Chia-I Wu
17935c0191 android: Fix build with bionic. 2010-12-09 20:01:34 -05:00
Chia-I Wu
7aceb74db7 i915c: Add GL_OES_draw_texture support. 2010-12-09 20:01:34 -05:00
Chia-I Wu
88e9712a68 tnl: Add support for GL_FIXED. 2010-12-09 20:01:34 -05:00
Chia-I Wu
2e9e27c0f7 i915: Free with FREE. 2010-12-09 19:39:22 -05:00
Chia-I Wu
455a7585de targets/egl-gdi: Optional support for DRM screen. 2010-12-09 19:39:22 -05:00
Chia-I Wu
25ed79d830 Revert "egl: Drop broken _EGL_PLATFORM_NO_OS code"
This reverts commit 021a68b7e8.
2010-12-09 19:39:22 -05:00
98 changed files with 92683 additions and 17 deletions

3
Android.mk Normal file
View File

@@ -0,0 +1,3 @@
ifneq ($(TARGET_SIMULATOR),true)
include $(call all-subdir-makefiles)
endif

View File

@@ -390,6 +390,20 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOK) (EGLDisplay dpy, EG
#define EGL_Y_INVERTED_NOK 0x307F
#endif /* EGL_NOK_texture_from_pixmap */
#ifndef EGL_ANDROID_image_native_buffer
#define EGL_ANDROID_image_native_buffer 1
struct android_native_buffer_t;
#define EGL_NATIVE_BUFFER_ANDROID 0x3140 /* eglCreateImageKHR target */
#endif
#ifndef EGL_ANDROID_swap_rectangle
#define EGL_ANDROID_swap_rectangle 1
#ifdef EGL_EGLEXT_PROTOTYPES
EGLAPI EGLBoolean EGLAPIENTRY eglSetSwapRectangleANDROID (EGLDisplay dpy, EGLSurface draw, EGLint left, EGLint top, EGLint width, EGLint height);
#endif /* EGL_EGLEXT_PROTOTYPES */
typedef EGLBoolean (EGLAPIENTRYP PFNEGLSETSWAPRECTANGLEANDROIDPROC) (EGLDisplay dpy, EGLSurface draw, EGLint left, EGLint top, EGLint width, EGLint height);
#endif
#ifdef __cplusplus
}

View File

@@ -84,6 +84,15 @@ typedef struct wl_egl_display *EGLNativeDisplayType;
typedef struct wl_egl_pixmap *EGLNativePixmapType;
typedef struct wl_egl_window *EGLNativeWindowType;
#elif defined(ANDROID) /* Android */
struct android_native_window_t;
struct egl_native_pixmap_t;
typedef struct android_native_window_t* EGLNativeWindowType;
typedef struct egl_native_pixmap_t* EGLNativePixmapType;
typedef void* EGLNativeDisplayType;
#elif defined(__unix__) || defined(__unix)
#ifdef MESA_EGL_NO_X11_HEADERS

View File

@@ -813,6 +813,7 @@ struct __DRIdri2ExtensionRec {
#define __DRI_IMAGE_FORMAT_RGB565 0x1001
#define __DRI_IMAGE_FORMAT_XRGB8888 0x1002
#define __DRI_IMAGE_FORMAT_ARGB8888 0x1003
#define __DRI_IMAGE_FORMAT_RGBA8888_REV 0x1004
#define __DRI_IMAGE_USE_SHARE 0x0001
#define __DRI_IMAGE_USE_SCANOUT 0x0002

115
src/Android.mk Normal file
View File

@@ -0,0 +1,115 @@
# Either one of, or both of, MESA_BUILD_CLASSIC and MESA_BUILD_GALLIUM must be
# set. When MESA_BUILD_GALLIUM is not set, EGL consists of
#
# libmesa_classic_egl
# libmesa_egl
#
# and the rules for it can be found in egl/drivers/android/Android.mk.
#
# When MESA_BUILD_GALLIUM is set, EGL consists of
#
# libmesa_st_egl
# libmesa_egl
# libmesa_st_mesa
# libmesa_pipe_<DRIVER>
# libmesa_winsys_<DRIVER>
# libmesa_gallium
# <plus libmesa_classic_egl if MESA_BUILD_CLASSIC is also set>
#
# and the rules for it can be found in gallium/targets/Android.mk
#
# When MESA_BUILD_CLASSIC is set, DRI drivers are created. A DRI driver
# consists of
#
# libmesa_classic_mesa
# libmesa_glsl
# <driver-specific objects>
#
# and the rules for it can be found in mesa/drivers/Android.mk.
#
# As for gralloc, the goal is to provide a single module that is able to
# detect and support the hardware. This is not the case yet though.
LOCAL_PATH := $(call my-dir)
# DRI drivers
MESA_BUILD_CLASSIC := false
MESA_BUILD_I915C := false
MESA_BUILD_I965C := false
# Gallium drivers
MESA_BUILD_GALLIUM := false
MESA_BUILD_I915G := false
MESA_BUILD_R600G := false
MESA_BUILD_SWRAST := false
# gralloc modules
MESA_BUILD_INTEL := false
MESA_BUILD_RADEON := false
MESA_BUILD_VMWGFX := false
MESA_DO_BUILD := false
ifeq ($(strip $(BOARD_USES_I915C)),true)
MESA_BUILD_CLASSIC := true
MESA_BUILD_I915C := true
# gralloc
MESA_BUILD_INTEL := true
MESA_DO_BUILD := true
endif
ifeq ($(strip $(BOARD_USES_I915G)),true)
MESA_BUILD_GALLIUM := true
MESA_BUILD_I915G := true
# gralloc
MESA_BUILD_INTEL := true
MESA_DO_BUILD := true
endif
ifeq ($(strip $(BOARD_USES_I965C)),true)
MESA_BUILD_CLASSIC := true
MESA_BUILD_I965C := true
# gralloc
MESA_BUILD_INTEL := true
MESA_DO_BUILD := true
endif
ifeq ($(strip $(BOARD_USES_R600G)),true)
MESA_BUILD_GALLIUM := true
MESA_BUILD_R600G := true
# gralloc
MESA_BUILD_RADEON := true
MESA_DO_BUILD := true
endif
ifeq ($(strip $(BOARD_USES_VMWGFX)),true)
MESA_BUILD_GALLIUM := true
MESA_BUILD_SWRAST := true
# gralloc
MESA_BUILD_VMWGFX := true
MESA_DO_BUILD := true
endif
ifeq ($(strip $(MESA_DO_BUILD)),true)
# build the real modules
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
symlink := $(TARGET_OUT_SHARED_LIBRARIES)/hw/gralloc.$(TARGET_PRODUCT)$(TARGET_SHLIB_SUFFIX)
symlink_to := gralloc.mesa$(TARGET_SHLIB_SUFFIX)
$(symlink): PRIVATE_TO := $(symlink_to)
$(symlink): $(TARGET_OUT_SHARED_LIBRARIES)/hw/$(symlink_to)
@echo "Symlink: $@ -> $(PRIVATE_TO)"
@mkdir -p $(dir $@)
@rm -rf $@
$(hide) ln -sf $(PRIVATE_TO) $@
ALL_PREBUILT += $(symlink)
endif # MESA_DO_BUILD

111
src/egl/Android.mk Normal file
View File

@@ -0,0 +1,111 @@
# Android.mk for EGL
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# from main/Makefile
SOURCES = \
eglapi.c \
eglarray.c \
eglconfig.c \
eglcontext.c \
eglcurrent.c \
egldisplay.c \
egldriver.c \
eglfallbacks.c \
eglglobals.c \
eglimage.c \
egllog.c \
eglmisc.c \
eglmode.c \
eglscreen.c \
eglstring.c \
eglsurface.c \
eglsync.c
LOCAL_SRC_FILES := \
$(addprefix main/, $(SOURCES))
LOCAL_CFLAGS := \
-DPTHREADS \
-D_EGL_NATIVE_PLATFORM=_EGL_PLATFORM_ANDROID \
-D_EGL_DRIVER_SEARCH_DIR=\"/system/lib/egl\" \
-D_EGL_OS_UNIX=1 \
-fvisibility=hidden \
-Wno-sign-compare
ifeq ($(strip $(MESA_BUILD_CLASSIC)),true)
LOCAL_CFLAGS += -D_EGL_BUILT_IN_DRIVER_ANDROID
endif
ifeq ($(strip $(MESA_BUILD_GALLIUM)),true)
LOCAL_CFLAGS += -D_EGL_BUILT_IN_DRIVER_GALLIUM
endif
LOCAL_C_INCLUDES := \
external/mesa/include
LOCAL_MODULE := libmesa_egl
include $(BUILD_STATIC_LIBRARY)
ifeq ($(strip $(MESA_BUILD_CLASSIC)),true)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
drivers/android/egl_android.c \
drivers/android/droid.c \
drivers/android/droid_core.c \
drivers/android/droid_image.c
LOCAL_CFLAGS := \
-D_EGL_MAIN=_eglBuiltInDriverANDROID \
-DDEFAULT_DRIVER_DIR=\"/system/lib/dri\" \
-DPTHREADS \
-fvisibility=hidden \
-Wno-sign-compare
LOCAL_C_INCLUDES := \
external/mesa/include \
external/mesa/src/mapi \
external/mesa/src/egl/main \
external/mesa/src/gralloc \
external/drm \
external/drm/include/drm \
external/mesa/src/mesa/drivers \
external/mesa/src/gallium/include \
external/mesa/src/gallium/winsys
LOCAL_MODULE := libmesa_classic_egl
include $(BUILD_STATIC_LIBRARY)
# build libGLES if gallium is not enabled
ifneq ($(strip $(MESA_BUILD_GALLIUM)),true)
include $(CLEAR_VARS)
LOCAL_SRC_FILES :=
LOCAL_CFLAGS :=
LOCAL_C_INCLUDES :=
LOCAL_STATIC_LIBRARIES :=
LOCAL_WHOLE_STATIC_LIBRARIES := \
libmesa_classic_egl \
libmesa_egl
LOCAL_SHARED_LIBRARIES := \
libglapi \
libdrm \
libdl \
libhardware \
liblog \
libcutils
LOCAL_MODULE := libGLES_mesa
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/egl
include $(BUILD_SHARED_LIBRARY)
endif # MESA_BUILD_GALLIUM
endif # MESA_BUILD_CLASSIC

View File

@@ -0,0 +1,762 @@
/*
* Copyright © 2010 Intel Corporation
*
* 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 (including the next
* paragraph) 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.
*
* Authors:
* Kristian Høgsberg <krh@bitplanet.net>
*/
#define LOG_TAG "MESA-EGL"
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <cutils/log.h>
#include "droid.h"
static const __DRIuseInvalidateExtension use_invalidate = {
{ __DRI_USE_INVALIDATE, 1 }
};
static __DRIimage *
droid_lookup_egl_image(__DRIscreen *screen, void *image, void *data)
{
_EGLDisplay *disp = data;
struct droid_egl_image *dimg;
_EGLImage *img;
(void) screen;
img = _eglLookupImage(image, disp);
if (img == NULL) {
_eglError(EGL_BAD_PARAMETER, "droid_lookup_egl_image");
return NULL;
}
dimg = droid_egl_image(image);
return dimg->dri_image;
}
static const __DRIimageLookupExtension image_lookup_extension = {
{ __DRI_IMAGE_LOOKUP, 1 },
droid_lookup_egl_image
};
static int
get_format_bpp(int native)
{
int bpp;
/* see libpixelflinger/format.cpp */
switch (native) {
case GGL_PIXEL_FORMAT_RGBA_8888:
case GGL_PIXEL_FORMAT_RGBX_8888:
case GGL_PIXEL_FORMAT_BGRA_8888:
bpp = 4;
break;
case GGL_PIXEL_FORMAT_RGB_888:
bpp = 3;
break;
case GGL_PIXEL_FORMAT_RGB_565:
case GGL_PIXEL_FORMAT_RGBA_5551:
case GGL_PIXEL_FORMAT_RGBA_4444:
case GGL_PIXEL_FORMAT_LA_88:
bpp = 2;
break;
case GGL_PIXEL_FORMAT_RGB_332:
case GGL_PIXEL_FORMAT_A_8:
case GGL_PIXEL_FORMAT_L_8:
bpp = 1;
break;
default:
bpp = 0;
break;
}
return bpp;
}
#include <gralloc_gem.h>
int
get_native_buffer_name(struct android_native_buffer_t *buf)
{
struct drm_bo_t *bo;
bo = drm_gem_get(buf->handle);
return (bo) ? bo->name : 0;
}
EGLBoolean
droid_dequeue_buffer(struct droid_egl_surface *dsurf)
{
__DRIbuffer *buf = &dsurf->dri_buffer;
if (dsurf->window->dequeueBuffer(dsurf->window, &dsurf->buffer))
return EGL_FALSE;
dsurf->buffer->common.incRef(&dsurf->buffer->common);
dsurf->window->lockBuffer(dsurf->window, dsurf->buffer);
buf->attachment = __DRI_BUFFER_FAKE_FRONT_LEFT;
buf->name = get_native_buffer_name(dsurf->buffer);
buf->cpp = get_format_bpp(dsurf->buffer->format);
buf->pitch = dsurf->buffer->stride * buf->cpp;
buf->flags = 0;
return EGL_TRUE;
}
EGLBoolean
droid_enqueue_buffer(struct droid_egl_surface *dsurf)
{
dsurf->window->queueBuffer(dsurf->window, dsurf->buffer);
dsurf->buffer->common.decRef(&dsurf->buffer->common);
dsurf->buffer = NULL;
return EGL_TRUE;
}
static void
droid_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
{
}
static __DRIbuffer *
droid_get_buffers_with_format(__DRIdrawable * driDrawable,
int *width, int *height,
unsigned int *attachments, int count,
int *out_count, void *loaderPrivate)
{
struct droid_egl_surface *dsurf = loaderPrivate;
struct droid_egl_display *ddpy =
droid_egl_display(dsurf->base.Resource.Display);
if (!dsurf->buffer) {
if (!droid_dequeue_buffer(dsurf))
return NULL;
}
dsurf->base.Width = dsurf->buffer->width;
dsurf->base.Height = dsurf->buffer->height;
if (width)
*width = dsurf->buffer->width;
if (height)
*height = dsurf->buffer->height;
*out_count = 1;
return &dsurf->dri_buffer;
}
static const EGLint droid_to_egl_attribute_map[] = {
0,
EGL_BUFFER_SIZE, /* __DRI_ATTRIB_BUFFER_SIZE */
EGL_LEVEL, /* __DRI_ATTRIB_LEVEL */
EGL_RED_SIZE, /* __DRI_ATTRIB_RED_SIZE */
EGL_GREEN_SIZE, /* __DRI_ATTRIB_GREEN_SIZE */
EGL_BLUE_SIZE, /* __DRI_ATTRIB_BLUE_SIZE */
EGL_LUMINANCE_SIZE, /* __DRI_ATTRIB_LUMINANCE_SIZE */
EGL_ALPHA_SIZE, /* __DRI_ATTRIB_ALPHA_SIZE */
0, /* __DRI_ATTRIB_ALPHA_MASK_SIZE */
EGL_DEPTH_SIZE, /* __DRI_ATTRIB_DEPTH_SIZE */
EGL_STENCIL_SIZE, /* __DRI_ATTRIB_STENCIL_SIZE */
0, /* __DRI_ATTRIB_ACCUM_RED_SIZE */
0, /* __DRI_ATTRIB_ACCUM_GREEN_SIZE */
0, /* __DRI_ATTRIB_ACCUM_BLUE_SIZE */
0, /* __DRI_ATTRIB_ACCUM_ALPHA_SIZE */
EGL_SAMPLE_BUFFERS, /* __DRI_ATTRIB_SAMPLE_BUFFERS */
EGL_SAMPLES, /* __DRI_ATTRIB_SAMPLES */
0, /* __DRI_ATTRIB_RENDER_TYPE, */
0, /* __DRI_ATTRIB_CONFIG_CAVEAT */
0, /* __DRI_ATTRIB_CONFORMANT */
0, /* __DRI_ATTRIB_DOUBLE_BUFFER */
0, /* __DRI_ATTRIB_STEREO */
0, /* __DRI_ATTRIB_AUX_BUFFERS */
0, /* __DRI_ATTRIB_TRANSPARENT_TYPE */
0, /* __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE */
0, /* __DRI_ATTRIB_TRANSPARENT_RED_VALUE */
0, /* __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE */
0, /* __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE */
0, /* __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE */
0, /* __DRI_ATTRIB_FLOAT_MODE */
0, /* __DRI_ATTRIB_RED_MASK */
0, /* __DRI_ATTRIB_GREEN_MASK */
0, /* __DRI_ATTRIB_BLUE_MASK */
0, /* __DRI_ATTRIB_ALPHA_MASK */
EGL_MAX_PBUFFER_WIDTH, /* __DRI_ATTRIB_MAX_PBUFFER_WIDTH */
EGL_MAX_PBUFFER_HEIGHT, /* __DRI_ATTRIB_MAX_PBUFFER_HEIGHT */
EGL_MAX_PBUFFER_PIXELS, /* __DRI_ATTRIB_MAX_PBUFFER_PIXELS */
0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH */
0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT */
0, /* __DRI_ATTRIB_VISUAL_SELECT_GROUP */
0, /* __DRI_ATTRIB_SWAP_METHOD */
EGL_MAX_SWAP_INTERVAL, /* __DRI_ATTRIB_MAX_SWAP_INTERVAL */
EGL_MIN_SWAP_INTERVAL, /* __DRI_ATTRIB_MIN_SWAP_INTERVAL */
0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGB */
0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA */
0, /* __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE */
0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */
EGL_Y_INVERTED_NOK, /* __DRI_ATTRIB_YINVERTED */
0, /* __DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE */
};
static struct droid_egl_config *
droid_add_config(_EGLDisplay *dpy, const __DRIconfig *dri_config, int id,
int depth, EGLint surface_type, int rgba_masks[4])
{
struct droid_egl_config *conf;
struct droid_egl_display *ddpy;
_EGLConfig base;
unsigned int attrib, value, double_buffer;
EGLint key;
int dri_masks[4] = { 0, 0, 0, 0 };
int i;
ddpy = dpy->DriverData;
_eglInitConfig(&base, dpy, id);
i = 0;
double_buffer = 0;
while (ddpy->core->indexConfigAttrib(dri_config, i++, &attrib, &value)) {
switch (attrib) {
case __DRI_ATTRIB_RENDER_TYPE:
if (value & __DRI_ATTRIB_RGBA_BIT)
value = EGL_RGB_BUFFER;
else if (value & __DRI_ATTRIB_LUMINANCE_BIT)
value = EGL_LUMINANCE_BUFFER;
else
assert(0);
_eglSetConfigKey(&base, EGL_COLOR_BUFFER_TYPE, value);
break;
case __DRI_ATTRIB_CONFIG_CAVEAT:
if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG)
value = EGL_NON_CONFORMANT_CONFIG;
else if (value & __DRI_ATTRIB_SLOW_BIT)
value = EGL_SLOW_CONFIG;
else
value = EGL_NONE;
_eglSetConfigKey(&base, EGL_CONFIG_CAVEAT, value);
break;
case __DRI_ATTRIB_DOUBLE_BUFFER:
double_buffer = value;
break;
case __DRI_ATTRIB_RED_MASK:
dri_masks[0] = value;
break;
case __DRI_ATTRIB_GREEN_MASK:
dri_masks[1] = value;
break;
case __DRI_ATTRIB_BLUE_MASK:
dri_masks[2] = value;
break;
case __DRI_ATTRIB_ALPHA_MASK:
dri_masks[3] = value;
break;
default:
key = droid_to_egl_attribute_map[attrib];
if (key != 0)
_eglSetConfigKey(&base, key, value);
break;
}
}
/* In EGL, double buffer or not isn't a config attribute. Pixmaps
* surfaces are always single buffered, pbuffer surfaces are always
* back buffers and windows can be either, selected by passing an
* attribute at window surface construction time. To support this
* we ignore all double buffer configs and manipulate the buffer we
* return in the getBuffer callback to get the behaviour we want. */
if (double_buffer)
return NULL;
if (depth > 0 && depth != _eglGetConfigKey(&base, EGL_BUFFER_SIZE))
return NULL;
if (memcmp(dri_masks, rgba_masks, sizeof(rgba_masks)))
return NULL;
_eglSetConfigKey(&base, EGL_NATIVE_RENDERABLE, EGL_TRUE);
_eglSetConfigKey(&base, EGL_SURFACE_TYPE, surface_type);
_eglSetConfigKey(&base, EGL_RENDERABLE_TYPE, dpy->ClientAPIs);
_eglSetConfigKey(&base, EGL_CONFORMANT, dpy->ClientAPIs);
if (!_eglValidateConfig(&base, EGL_FALSE)) {
_eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id);
return NULL;
}
conf = calloc(1, sizeof(*conf));
if (conf != NULL) {
memcpy(&conf->base, &base, sizeof(base));
conf->dri_config = dri_config;
_eglLinkConfig(&conf->base);
}
return conf;
}
static EGLBoolean
droid_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *dpy)
{
struct droid_egl_display *ddpy = droid_egl_display(dpy);
const struct {
int format;
int size;
int rgba_masks[4];
} visuals[] = {
{ GGL_PIXEL_FORMAT_RGBA_8888, 32, { 0xff, 0xff00, 0xff0000, 0xff000000 } },
{ GGL_PIXEL_FORMAT_RGBX_8888, 32, { 0xff, 0xff00, 0xff0000, 0x0 } },
{ GGL_PIXEL_FORMAT_RGB_888, 24, { 0xff, 0xff00, 0xff0000, 0x0 } },
{ GGL_PIXEL_FORMAT_RGB_565, 16, { 0xf800, 0x7e0, 0x1f, 0x0 } },
{ GGL_PIXEL_FORMAT_BGRA_8888, 32, { 0xff0000, 0xff00, 0xff, 0xff000000 } },
{ GGL_PIXEL_FORMAT_A_8, 8, { 0xf800, 0x7e0, 0x1f, 0x0 } },
{ 0, 0, { 0, 0, 0, 0 } }
};
int count, i, j;
count = 0;
for (i = 0; visuals[i].format; i++) {
int format_count = 0;
for (j = 0; ddpy->dri_configs[j]; j++) {
struct droid_egl_config *dconf;
dconf = droid_add_config(dpy, ddpy->dri_configs[j], count + 1,
visuals[i].size, EGL_WINDOW_BIT, visuals[i].rgba_masks);
if (dconf) {
_eglSetConfigKey(&dconf->base,
EGL_NATIVE_VISUAL_TYPE, visuals[i].format);
count++;
format_count++;
}
}
if (!format_count) {
_eglLog(_EGL_DEBUG, "No DRI config supports native format 0x%x",
visuals[i].format);
}
}
return (count != 0);
}
struct droid_extension_match {
const char *name;
int version;
int offset;
};
static struct droid_extension_match droid_driver_extensions[] = {
{ __DRI_CORE, 1, offsetof(struct droid_egl_display, core) },
{ __DRI_DRI2, 1, offsetof(struct droid_egl_display, dri2) },
{ NULL, 0, 0 }
};
static struct droid_extension_match droid_core_extensions[] = {
{ __DRI2_FLUSH, 1, offsetof(struct droid_egl_display, flush) },
{ __DRI_IMAGE, 1, offsetof(struct droid_egl_display, image) },
{ NULL, 0, 0 }
};
extern const __DRIextension *__driDriverExtensions[];
static EGLBoolean
droid_bind_extensions(struct droid_egl_display *ddpy,
struct droid_extension_match *matches,
const __DRIextension **extensions)
{
int i, j, ret = EGL_TRUE;
void *field;
for (i = 0; extensions[i]; i++) {
_eglLog(_EGL_DEBUG, "DRI2: found extension `%s'", extensions[i]->name);
for (j = 0; matches[j].name; j++) {
if (strcmp(extensions[i]->name, matches[j].name) == 0 &&
extensions[i]->version >= matches[j].version) {
field = ((char *) ddpy + matches[j].offset);
*(const __DRIextension **) field = extensions[i];
_eglLog(_EGL_INFO, "DRI2: found extension %s version %d",
extensions[i]->name, extensions[i]->version);
}
}
}
for (j = 0; matches[j].name; j++) {
field = ((char *) ddpy + matches[j].offset);
if (*(const __DRIextension **) field == NULL) {
_eglLog(_EGL_FATAL, "DRI2: did not find extension %s version %d",
matches[j].name, matches[j].version);
ret = EGL_FALSE;
}
}
return ret;
}
static EGLBoolean
droid_create_screen(_EGLDisplay *dpy)
{
struct droid_egl_display *ddpy = droid_egl_display(dpy);
const __DRIextension **extensions;
unsigned int api_mask;
ddpy->dri_screen =
ddpy->dri2->createNewScreen(0, ddpy->fd, ddpy->extensions,
&ddpy->dri_configs, dpy);
if (ddpy->dri_screen == NULL) {
_eglLog(_EGL_WARNING, "failed to create dri screen");
return EGL_FALSE;
}
extensions = ddpy->core->getExtensions(ddpy->dri_screen);
if (!droid_bind_extensions(ddpy, droid_core_extensions, extensions)) {
ddpy->core->destroyScreen(ddpy->dri_screen);
return EGL_FALSE;
}
if (ddpy->dri2->base.version >= 2)
api_mask = ddpy->dri2->getAPIMask(ddpy->dri_screen);
else
api_mask = 1 << __DRI_API_OPENGL;
dpy->ClientAPIs = 0;
if (api_mask & (1 <<__DRI_API_OPENGL))
dpy->ClientAPIs |= EGL_OPENGL_BIT;
if (api_mask & (1 <<__DRI_API_GLES))
dpy->ClientAPIs |= EGL_OPENGL_ES_BIT;
if (api_mask & (1 << __DRI_API_GLES2))
dpy->ClientAPIs |= EGL_OPENGL_ES2_BIT;
if (ddpy->dri2->base.version >= 2) {
dpy->Extensions.KHR_surfaceless_gles1 = EGL_TRUE;
dpy->Extensions.KHR_surfaceless_gles2 = EGL_TRUE;
dpy->Extensions.KHR_surfaceless_opengl = EGL_TRUE;
}
return EGL_TRUE;
}
static EGLBoolean
droid_load_driver(_EGLDisplay *dpy, const char *driver_name)
{
struct droid_egl_display *ddpy = droid_egl_display(dpy);
const __DRIextension **extensions;
char path[PATH_MAX], *base = NULL;
void *handle;
if (geteuid() == getuid()) {
/* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
base = getenv("LIBGL_DRIVERS_PATH");
}
if (!base)
base = DEFAULT_DRIVER_DIR;
snprintf(path, sizeof(path), "%s/%s_dri.so", base, driver_name);
handle = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
if (!handle) {
_eglLog(_EGL_WARNING, "DRI2: failed to load %s: %s", path, dlerror());
return EGL_FALSE;
}
_eglLog(_EGL_DEBUG, "DRI2: dlopen(%s)", path);
extensions = dlsym(handle, __DRI_DRIVER_EXTENSIONS);
if (!extensions) {
_eglLog(_EGL_WARNING, "DRI2: driver exports no extensions");
dlclose(handle);
return EGL_FALSE;
}
if (!droid_bind_extensions(ddpy, droid_driver_extensions, extensions)) {
dlclose(handle);
return EGL_FALSE;
}
ddpy->dri_handle = handle;
return EGL_TRUE;
}
#include <xf86drm.h>
/* for i915 */
#include <i915_drm.h>
#include "dri/intel/intel_chipset.h"
/* for radeon */
#include <radeon_drm.h>
#include "radeon/drm/radeon_drm_public.h"
static const char *
droid_get_driver_name(int fd)
{
drmVersionPtr version;
char *name = NULL;
version = drmGetVersion(fd);
if (!version) {
_eglLog(_EGL_WARNING, "invalid drm fd");
return NULL;
}
if (!version->name) {
_eglLog(_EGL_WARNING, "unable to determine the driver name");
drmFreeVersion(version);
return NULL;
}
if (strcmp(version->name, "i915") == 0) {
struct drm_i915_getparam gp;
int id, ret;
memset(&gp, 0, sizeof(gp));
gp.param = I915_PARAM_CHIPSET_ID;
gp.value = &id;
ret = drmCommandWriteRead(fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
if (ret) {
_eglLog(_EGL_WARNING, "failed to get param for i915");
}
else {
name = (IS_965(id)) ? "i965" : "i915";
}
}
else if (strcmp(version->name, "radeon") == 0) {
struct drm_radeon_info info;
int id, ret;
memset(&info, 0, sizeof(info));
info.request = RADEON_INFO_DEVICE_ID;
info.value = (long) &id;
ret = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info));
if (ret) {
_eglLog(_EGL_WARNING, "failed to get info for radeon");
}
else {
name = (is_r3xx(id)) ? "r300" : "r600";
}
}
drmFreeVersion(version);
return name;
}
static int
droid_open_device(void)
{
const hw_module_t *mod;
int fd = -1, 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);
}
if (err || fd < 0) {
_eglLog(_EGL_WARNING, "fail to get drm fd");
fd = -1;
}
return fd;
}
static EGLBoolean
droid_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy)
{
struct droid_egl_display *ddpy;
const char *driver_name;
int fd;
fd = droid_open_device();
if (fd < 0)
return EGL_FALSE;
driver_name = droid_get_driver_name(fd);
if (!driver_name)
return EGL_FALSE;
ddpy = calloc(1, sizeof(*ddpy));
if (!ddpy)
return _eglError(EGL_BAD_ALLOC, "eglInitialize");
ddpy->fd = fd;
dpy->DriverData = (void *) ddpy;
if (!droid_load_driver(dpy, driver_name))
return EGL_FALSE;
ddpy->loader_extension.base.name = __DRI_DRI2_LOADER;
ddpy->loader_extension.base.version = 3;
ddpy->loader_extension.getBuffers = NULL;
ddpy->loader_extension.flushFrontBuffer = droid_flush_front_buffer;
ddpy->loader_extension.getBuffersWithFormat =
droid_get_buffers_with_format;
ddpy->extensions[0] = &ddpy->loader_extension.base;
ddpy->extensions[1] = &image_lookup_extension.base;
ddpy->extensions[2] = &use_invalidate.base;
ddpy->extensions[3] = NULL;
if (!droid_create_screen(dpy)) {
free(ddpy);
return EGL_FALSE;
}
if (!droid_add_configs_for_visuals(drv, dpy)) {
ddpy->core->destroyScreen(ddpy->dri_screen);
free(ddpy);
}
dpy->Extensions.ANDROID_image_native_buffer = EGL_TRUE;
dpy->Extensions.KHR_image_base = EGL_TRUE;
/* we're supporting EGL 1.4 */
dpy->VersionMajor = 1;
dpy->VersionMinor = 4;
return EGL_TRUE;
}
static EGLBoolean
droid_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
{
struct droid_egl_display *ddpy = droid_egl_display(dpy);
_eglReleaseDisplayResources(drv, dpy);
_eglCleanupDisplay(dpy);
ddpy->core->destroyScreen(ddpy->dri_screen);
dlclose(ddpy->dri_handle);
free(ddpy);
dpy->DriverData = NULL;
return EGL_TRUE;
}
static EGLBoolean
droid_initialize(_EGLDriver *drv, _EGLDisplay *dpy)
{
/* not until swrast_dri is supported */
if (dpy->Options.UseFallback)
return EGL_FALSE;
switch (dpy->Platform) {
case _EGL_PLATFORM_ANDROID:
if (dpy->Options.TestOnly)
return EGL_TRUE;
return droid_initialize_android(drv, dpy);
default:
return EGL_FALSE;
}
}
static _EGLProc
droid_get_proc_address(_EGLDriver *drv, const char *procname)
{
struct droid_egl_driver *ddrv = droid_egl_driver(drv);
return ddrv->get_proc_address(procname);
}
static void
droid_log(EGLint level, const char *msg)
{
switch (level) {
case _EGL_DEBUG:
LOGD(msg);
break;
case _EGL_INFO:
LOGI(msg);
break;
case _EGL_WARNING:
LOGW(msg);
break;
case _EGL_FATAL:
LOG_FATAL(msg);
break;
default:
break;
}
}
static void
droid_unload(_EGLDriver *drv)
{
struct droid_egl_driver *ddrv = droid_egl_driver(drv);
free(ddrv);
}
#include "glapi/glapi.h" /* for _glapi_get_proc_address */
static EGLBoolean
droid_load(_EGLDriver *drv)
{
struct droid_egl_driver *ddrv = droid_egl_driver(drv);
ddrv->get_proc_address = (_EGLProc (*)(const char *)) _glapi_get_proc_address;
ddrv->glFlush = (void (*)(void))
ddrv->get_proc_address("glFlush");
ddrv->glFinish = (void (*)(void))
ddrv->get_proc_address("glFinish");
return EGL_TRUE;
}
_EGLDriver *
droid_create_driver(void)
{
struct droid_egl_driver *ddrv;
ddrv = calloc(1, sizeof(*ddrv));
if (!ddrv)
return NULL;
if (!droid_load(&ddrv->base))
return NULL;
_eglSetLogProc(droid_log);
ddrv->base.Name = "Droid";
ddrv->base.Unload = droid_unload;
_eglInitDriverFallbacks(&ddrv->base);
ddrv->base.API.Initialize = droid_initialize;
ddrv->base.API.Terminate = droid_terminate;
ddrv->base.API.GetProcAddress = droid_get_proc_address;
return &ddrv->base;
}

View File

@@ -0,0 +1,129 @@
/*
* Copyright © 2010 Intel Corporation
*
* 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 (including the next
* paragraph) 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.
*
* Authors:
* Kristian Høgsberg <krh@bitplanet.net>
*/
#ifndef _DROID_H_
#define _DROID_H_
#include <errno.h>
#include <ui/egl/android_natives.h>
#include <ui/android_native_buffer.h>
#include <pixelflinger/format.h>
#include <GL/gl.h>
#include <GL/internal/dri_interface.h>
#include "egldriver.h"
#include "egldisplay.h"
#include "eglcontext.h"
#include "eglsurface.h"
#include "eglconfig.h"
#include "eglimage.h"
#include "eglcurrent.h"
#include "egllog.h"
struct droid_egl_driver
{
_EGLDriver base;
_EGLProc (*get_proc_address)(const char *procname);
void (*glFlush)(void);
void (*glFinish)(void);
};
struct droid_egl_display
{
int fd;
void *dri_handle;
__DRIscreen *dri_screen;
const __DRIconfig **dri_configs;
__DRIcoreExtension *core;
__DRIdri2Extension *dri2;
__DRI2flushExtension *flush;
__DRIimageExtension *image;
__DRIdri2LoaderExtension loader_extension;
const __DRIextension *extensions[8];
};
struct droid_egl_context
{
_EGLContext base;
__DRIcontext *dri_context;
};
struct droid_egl_surface
{
_EGLSurface base;
__DRIdrawable *dri_drawable;
__DRIbuffer dri_buffer;
android_native_window_t *window;
android_native_buffer_t *buffer;
};
struct droid_egl_config
{
_EGLConfig base;
const __DRIconfig *dri_config;
};
struct droid_egl_image
{
_EGLImage base;
__DRIimage *dri_image;
};
/* standard typecasts */
_EGL_DRIVER_STANDARD_TYPECASTS(droid_egl)
_EGL_DRIVER_TYPECAST(droid_egl_image, _EGLImage, obj)
_EGLDriver *
droid_create_driver(void);
void
droid_init_core_functions(_EGLDriver *drv);
void
droid_init_image_functions(_EGLDriver *drv);
EGLBoolean
droid_dequeue_buffer(struct droid_egl_surface *dsurf);
EGLBoolean
droid_enqueue_buffer(struct droid_egl_surface *dsurf);
int
get_native_buffer_name(struct android_native_buffer_t *buf);
#endif /* _DROID_H_ */

View File

@@ -0,0 +1,347 @@
/*
* Copyright © 2010 Intel Corporation
*
* 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 (including the next
* paragraph) 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.
*
* Authors:
* Kristian Høgsberg <krh@bitplanet.net>
*/
#include "droid.h"
static _EGLContext *
droid_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
_EGLContext *share_list, const EGLint *attrib_list)
{
struct droid_egl_context *dctx;
struct droid_egl_display *ddpy = droid_egl_display(disp);
struct droid_egl_context *dctx_shared = droid_egl_context(share_list);
struct droid_egl_config *dconf = droid_egl_config(conf);
const __DRIconfig *dri_config;
int api;
(void) drv;
dctx = calloc(1, sizeof *dctx);
if (!dctx) {
_eglError(EGL_BAD_ALLOC, "eglCreateContext");
return NULL;
}
if (!_eglInitContext(&dctx->base, disp, conf, attrib_list))
goto cleanup;
switch (dctx->base.ClientAPI) {
case EGL_OPENGL_ES_API:
switch (dctx->base.ClientVersion) {
case 1:
api = __DRI_API_GLES;
break;
case 2:
api = __DRI_API_GLES2;
break;
default:
_eglError(EGL_BAD_PARAMETER, "eglCreateContext");
return NULL;
}
break;
case EGL_OPENGL_API:
api = __DRI_API_OPENGL;
break;
default:
_eglError(EGL_BAD_PARAMETER, "eglCreateContext");
return NULL;
}
if (conf != NULL)
dri_config = dconf->dri_config;
else
dri_config = NULL;
if (ddpy->dri2->base.version >= 2) {
dctx->dri_context =
ddpy->dri2->createNewContextForAPI(ddpy->dri_screen,
api,
dri_config,
dctx_shared ?
dctx_shared->dri_context : NULL,
dctx);
} else if (api == __DRI_API_OPENGL) {
dctx->dri_context =
ddpy->dri2->createNewContext(ddpy->dri_screen,
dconf->dri_config,
dctx_shared ?
dctx_shared->dri_context : NULL,
dctx);
} else {
/* fail */
}
if (!dctx->dri_context)
goto cleanup;
return &dctx->base;
cleanup:
free(dctx);
return NULL;
}
static EGLBoolean
droid_destroy_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx)
{
struct droid_egl_display *ddpy = droid_egl_display(disp);
struct droid_egl_context *dctx = droid_egl_context(ctx);
(void) drv;
if (!_eglPutContext(ctx))
return EGL_TRUE;
(*ddpy->core->destroyContext)(dctx->dri_context);
free(dctx);
return EGL_TRUE;
}
static _EGLSurface *
droid_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
_EGLConfig *conf, EGLNativeWindowType window,
const EGLint *attrib_list)
{
struct droid_egl_display *ddpy = droid_egl_display(disp);
struct droid_egl_config *dconf = droid_egl_config(conf);
struct droid_egl_surface *dsurf;
int format, vis_type;
(void) drv;
if (!window || window->common.magic != ANDROID_NATIVE_WINDOW_MAGIC) {
_eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface");
return NULL;
}
if (window->query(window, NATIVE_WINDOW_FORMAT, &format)) {
_eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface");
return NULL;
}
vis_type = _eglGetConfigKey(&dconf->base, EGL_NATIVE_VISUAL_TYPE);
if (format != vis_type) {
_eglLog(_EGL_WARNING, "Native format mismatch: 0x%x != 0x%x",
format, vis_type);
}
dsurf = calloc(1, sizeof *dsurf);
if (!dsurf) {
_eglError(EGL_BAD_ALLOC, "droid_create_surface");
return NULL;
}
if (!_eglInitSurface(&dsurf->base, disp, type, conf, attrib_list))
goto cleanup_surf;
dsurf->dri_drawable =
(*ddpy->dri2->createNewDrawable) (ddpy->dri_screen,
dconf->dri_config, dsurf);
if (dsurf->dri_drawable == NULL) {
_eglError(EGL_BAD_ALLOC, "dri2->createNewDrawable");
goto cleanup_pixmap;
}
window->common.incRef(&window->common);
window->query(window, NATIVE_WINDOW_WIDTH, &dsurf->base.Width);
window->query(window, NATIVE_WINDOW_HEIGHT, &dsurf->base.Height);
dsurf->window = window;
return &dsurf->base;
cleanup_dri_drawable:
ddpy->core->destroyDrawable(dsurf->dri_drawable);
cleanup_pixmap:
cleanup_surf:
free(dsurf);
return NULL;
}
static _EGLSurface *
droid_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
_EGLConfig *conf, EGLNativeWindowType window,
const EGLint *attrib_list)
{
return droid_create_surface(drv, disp, EGL_WINDOW_BIT, conf,
window, attrib_list);
}
static _EGLSurface *
droid_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *disp,
_EGLConfig *conf, EGLNativePixmapType pixmap,
const EGLint *attrib_list)
{
return NULL;
}
static _EGLSurface *
droid_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp,
_EGLConfig *conf, const EGLint *attrib_list)
{
return NULL;
}
static EGLBoolean
droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
{
struct droid_egl_display *ddpy = droid_egl_display(disp);
struct droid_egl_surface *dsurf = droid_egl_surface(surf);
(void) drv;
if (!_eglPutSurface(surf))
return EGL_TRUE;
(*ddpy->core->destroyDrawable)(dsurf->dri_drawable);
if (dsurf->buffer)
droid_enqueue_buffer(dsurf);
dsurf->window->common.decRef(&dsurf->window->common);
free(surf);
return EGL_TRUE;
}
static EGLBoolean
droid_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,
_EGLSurface *rsurf, _EGLContext *ctx)
{
struct droid_egl_driver *ddrv = droid_egl_driver(drv);
struct droid_egl_display *ddpy = droid_egl_display(disp);
struct droid_egl_surface *droid_dsurf = droid_egl_surface(dsurf);
struct droid_egl_surface *droid_rsurf = droid_egl_surface(rsurf);
struct droid_egl_context *dctx = droid_egl_context(ctx);
_EGLContext *old_ctx;
_EGLSurface *old_dsurf, *old_rsurf;
__DRIdrawable *ddraw, *rdraw;
__DRIcontext *cctx;
/* make new bindings */
if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf))
return EGL_FALSE;
/* flush before context switch */
if (old_ctx && ddrv->glFlush)
ddrv->glFlush();
ddraw = (droid_dsurf) ? droid_dsurf->dri_drawable : NULL;
rdraw = (droid_rsurf) ? droid_rsurf->dri_drawable : NULL;
cctx = (dctx) ? dctx->dri_context : NULL;
if ((cctx == NULL && ddraw == NULL && rdraw == NULL) ||
ddpy->core->bindContext(cctx, ddraw, rdraw)) {
droid_destroy_surface(drv, disp, old_dsurf);
droid_destroy_surface(drv, disp, old_rsurf);
if (old_ctx) {
/* unbind the old context only when there is no new context bound */
if (!ctx) {
__DRIcontext *old_cctx = droid_egl_context(old_ctx)->dri_context;
ddpy->core->unbindContext(old_cctx);
}
droid_destroy_context(drv, disp, old_ctx);
}
return EGL_TRUE;
} else {
/* undo the previous _eglBindContext */
_eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &dsurf, &rsurf);
assert(&dctx->base == ctx &&
&droid_dsurf->base == dsurf &&
&droid_rsurf->base == rsurf);
_eglPutSurface(dsurf);
_eglPutSurface(rsurf);
_eglPutContext(ctx);
_eglPutSurface(old_dsurf);
_eglPutSurface(old_rsurf);
_eglPutContext(old_ctx);
return EGL_FALSE;
}
}
static EGLBoolean
droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
{
struct droid_egl_driver *ddrv = droid_egl_driver(drv);
struct droid_egl_display *ddpy = droid_egl_display(disp);
struct droid_egl_surface *dsurf = droid_egl_surface(draw);
_EGLContext *ctx;
if (ddrv->glFlush) {
ctx = _eglGetCurrentContext();
if (ctx && ctx->DrawSurface == &dsurf->base)
ddrv->glFlush();
}
(*ddpy->flush->flush)(dsurf->dri_drawable);
if (dsurf->buffer)
droid_enqueue_buffer(dsurf);
(*ddpy->flush->invalidate)(dsurf->dri_drawable);
return EGL_TRUE;
}
static EGLBoolean
droid_wait_client(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx)
{
struct droid_egl_driver *ddrv = droid_egl_driver(drv);
struct droid_egl_display *ddpy = droid_egl_display(disp);
struct droid_egl_surface *dsurf = droid_egl_surface(ctx->DrawSurface);
if (ddrv->glFinish)
ddrv->glFinish();
if (dsurf)
(*ddpy->flush->flush)(dsurf->dri_drawable);
return EGL_TRUE;
}
void
droid_init_core_functions(_EGLDriver *drv)
{
struct droid_egl_driver *ddrv = droid_egl_driver(drv);
ddrv->base.API.CreateContext = droid_create_context;
ddrv->base.API.DestroyContext = droid_destroy_context;
ddrv->base.API.CreateWindowSurface = droid_create_window_surface;
ddrv->base.API.CreatePixmapSurface = droid_create_pixmap_surface;
ddrv->base.API.CreatePbufferSurface = droid_create_pbuffer_surface;
ddrv->base.API.DestroySurface = droid_destroy_surface;
ddrv->base.API.MakeCurrent = droid_make_current;
ddrv->base.API.SwapBuffers = droid_swap_buffers;
ddrv->base.API.WaitClient = droid_wait_client;
}

View File

@@ -0,0 +1,134 @@
/*
* Copyright © 2010 Intel Corporation
*
* 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 (including the next
* paragraph) 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.
*
* Authors:
* Kristian Høgsberg <krh@bitplanet.net>
*/
#include "droid.h"
static _EGLImage *
droid_create_image_android_native_buffer(_EGLDisplay *disp,
EGLClientBuffer buffer)
{
struct droid_egl_display *ddpy = droid_egl_display(disp);
struct android_native_buffer_t *buf =
(struct android_native_buffer_t *) buffer;
struct droid_egl_image *dimg;
EGLint format, name;
if (!buf || buf->common.magic != ANDROID_NATIVE_BUFFER_MAGIC ||
buf->common.version != sizeof(*buf)) {
_eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
return NULL;
}
name = get_native_buffer_name(buf);
if (!name) {
_eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
return NULL;
}
switch (buf->format) {
case HAL_PIXEL_FORMAT_BGRA_8888:
format = __DRI_IMAGE_FORMAT_ARGB8888;
break;
case HAL_PIXEL_FORMAT_RGB_565:
format = __DRI_IMAGE_FORMAT_RGB565;
break;
case HAL_PIXEL_FORMAT_RGBA_8888:
format = __DRI_IMAGE_FORMAT_RGBA8888_REV;
break;
case HAL_PIXEL_FORMAT_RGBX_8888:
case HAL_PIXEL_FORMAT_RGB_888:
case HAL_PIXEL_FORMAT_RGBA_5551:
case HAL_PIXEL_FORMAT_RGBA_4444:
/* unsupported */
default:
_eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", buf->format);
return NULL;
break;
}
dimg = calloc(1, sizeof(*dimg));
if (!dimg) {
_eglError(EGL_BAD_ALLOC, "droid_create_image_mesa_drm");
return NULL;
}
if (!_eglInitImage(&dimg->base, disp)) {
free(dimg);
return NULL;
}
dimg->dri_image =
ddpy->image->createImageFromName(ddpy->dri_screen,
buf->width,
buf->height,
format,
name,
buf->stride,
dimg);
if (!dimg->dri_image) {
free(dimg);
_eglError(EGL_BAD_ALLOC, "droid_create_image_mesa_drm");
return NULL;
}
return &dimg->base;
}
static _EGLImage *
droid_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 droid_create_image_android_native_buffer(disp, buffer);
default:
_eglError(EGL_BAD_PARAMETER, "droid_create_image_khr");
return EGL_NO_IMAGE_KHR;
}
}
static EGLBoolean
droid_destroy_image_khr(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *image)
{
struct droid_egl_display *ddpy = droid_egl_display(disp);
struct droid_egl_image *dimg = droid_egl_image(image);
ddpy->image->destroyImage(dimg->dri_image);
free(dimg);
return EGL_TRUE;
}
void
droid_init_image_functions(_EGLDriver *drv)
{
struct droid_egl_driver *ddrv = droid_egl_driver(drv);
ddrv->base.API.CreateImageKHR = droid_create_image_khr;
ddrv->base.API.DestroyImageKHR = droid_destroy_image_khr;
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright © 2010 Intel Corporation
*
* 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 (including the next
* paragraph) 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.
*
* Authors:
* Kristian Høgsberg <krh@bitplanet.net>
*/
#include "droid.h"
_EGLDriver *
_EGL_MAIN(const char *args)
{
_EGLDriver *drv;
drv = droid_create_driver();
if (drv) {
droid_init_core_functions(drv);
droid_init_image_functions(drv);
}
return drv;
}

View File

@@ -917,6 +917,9 @@ eglGetProcAddress(const char *procname)
#ifdef EGL_WL_bind_display
{ "eglBindWaylandDisplayWL", (_EGLProc) eglBindWaylandDisplayWL },
{ "eglUnbindWaylandDisplayWL", (_EGLProc) eglUnbindWaylandDisplayWL },
#endif
#ifdef EGL_ANDROID_swap_rectangle
{ "eglSetSwapRectangleANDROID", (_EGLProc) eglSetSwapRectangleANDROID },
#endif
{ NULL, NULL }
};
@@ -1535,3 +1538,25 @@ eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display)
RETURN_EGL_EVAL(disp, ret);
}
#endif
#ifdef EGL_ANDROID_swap_rectangle
EGLBoolean EGLAPIENTRY
eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw,
EGLint left, EGLint top,
EGLint width, EGLint height)
{
_EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLSurface *surf = _eglLookupSurface(draw, disp);
_EGLDriver *drv;
EGLBoolean ret;
_EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
if (!disp->Extensions.ANDROID_swap_rectangle)
RETURN_EGL_EVAL(disp, EGL_FALSE);
ret = drv->API.SetSwapRectangleANDROID(drv, disp, surf, left, top, width, height);
RETURN_EGL_EVAL(disp, ret);
}
#endif

View File

@@ -101,6 +101,10 @@ typedef EGLBoolean (*BindWaylandDisplayWL_t)(_EGLDriver *drv, _EGLDisplay *disp,
typedef EGLBoolean (*UnbindWaylandDisplayWL_t)(_EGLDriver *drv, _EGLDisplay *disp, struct wl_display *display);
#endif
#ifdef EGL_ANDROID_swap_rectangle
typedef EGLBoolean (*SetSwapRectangleANDROID_t)(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw, EGLint left, EGLint top, EGLint width, EGLint height);
#endif
/**
* The API dispatcher jumps through these functions
*/
@@ -180,6 +184,10 @@ struct _egl_api
BindWaylandDisplayWL_t BindWaylandDisplayWL;
UnbindWaylandDisplayWL_t UnbindWaylandDisplayWL;
#endif
#ifdef EGL_ANDROID_swap_rectangle
SetSwapRectangleANDROID_t SetSwapRectangleANDROID;
#endif
};
#endif /* EGLAPI_INCLUDED */

View File

@@ -29,7 +29,8 @@ _eglGetNativePlatformFromEnv(void)
{ _EGL_PLATFORM_X11, "x11" },
{ _EGL_PLATFORM_WAYLAND, "wayland" },
{ _EGL_PLATFORM_DRM, "drm" },
{ _EGL_PLATFORM_FBDEV, "fbdev" }
{ _EGL_PLATFORM_FBDEV, "fbdev" },
{ _EGL_PLATFORM_ANDROID, "android" }
};
_EGLPlatformType plat = _EGL_INVALID_PLATFORM;
const char *plat_name;

View File

@@ -14,6 +14,7 @@ enum _egl_platform_type {
_EGL_PLATFORM_WAYLAND,
_EGL_PLATFORM_DRM,
_EGL_PLATFORM_FBDEV,
_EGL_PLATFORM_ANDROID,
_EGL_NUM_PLATFORMS,
_EGL_INVALID_PLATFORM = -1
@@ -77,6 +78,9 @@ struct _egl_extensions
EGLBoolean NOK_swap_region;
EGLBoolean NOK_texture_from_pixmap;
EGLBoolean ANDROID_image_native_buffer;
EGLBoolean ANDROID_swap_rectangle;
};

View File

@@ -40,6 +40,9 @@ const struct {
#ifdef _EGL_BUILT_IN_DRIVER_GALLIUM
{ "egl_gallium", _eglBuiltInDriverGALLIUM },
#endif
#ifdef _EGL_BUILT_IN_DRIVER_ANDROID
{ "egl_android", _eglBuiltInDriverANDROID },
#endif
#ifdef _EGL_BUILT_IN_DRIVER_DRI2
{ "egl_dri2", _eglBuiltInDriverDRI2 },
#endif

View File

@@ -58,6 +58,10 @@ extern _EGLDriver *
_eglBuiltInDriverGALLIUM(const char *args);
extern _EGLDriver *
_eglBuiltInDriverANDROID(const char *args);
extern _EGLDriver *
_eglBuiltInDriverDRI2(const char *args);

View File

@@ -111,6 +111,9 @@ _eglUpdateExtensionsString(_EGLDisplay *dpy)
_EGL_CHECK_EXTENSION(NOK_swap_region);
_EGL_CHECK_EXTENSION(NOK_texture_from_pixmap);
_EGL_CHECK_EXTENSION(ANDROID_image_native_buffer);
_EGL_CHECK_EXTENSION(ANDROID_swap_rectangle);
#undef _EGL_CHECK_EXTENSION
}

3
src/gallium/Android.mk Normal file
View File

@@ -0,0 +1,3 @@
ifeq ($(strip $(MESA_BUILD_GALLIUM)),true)
include $(call all-subdir-makefiles)
endif

View File

@@ -0,0 +1,217 @@
LOCAL_PATH := $(call my-dir)
# from Makefile
C_SOURCES = \
cso_cache/cso_cache.c \
cso_cache/cso_context.c \
cso_cache/cso_hash.c \
draw/draw_context.c \
draw/draw_fs.c \
draw/draw_gs.c \
draw/draw_pipe.c \
draw/draw_pipe_aaline.c \
draw/draw_pipe_aapoint.c \
draw/draw_pipe_clip.c \
draw/draw_pipe_cull.c \
draw/draw_pipe_flatshade.c \
draw/draw_pipe_offset.c \
draw/draw_pipe_pstipple.c \
draw/draw_pipe_stipple.c \
draw/draw_pipe_twoside.c \
draw/draw_pipe_unfilled.c \
draw/draw_pipe_util.c \
draw/draw_pipe_validate.c \
draw/draw_pipe_vbuf.c \
draw/draw_pipe_wide_line.c \
draw/draw_pipe_wide_point.c \
draw/draw_pt.c \
draw/draw_pt_emit.c \
draw/draw_pt_fetch.c \
draw/draw_pt_fetch_emit.c \
draw/draw_pt_fetch_shade_emit.c \
draw/draw_pt_fetch_shade_pipeline.c \
draw/draw_pt_post_vs.c \
draw/draw_pt_so_emit.c \
draw/draw_pt_util.c \
draw/draw_pt_vsplit.c \
draw/draw_vertex.c \
draw/draw_vs.c \
draw/draw_vs_aos.c \
draw/draw_vs_aos_io.c \
draw/draw_vs_aos_machine.c \
draw/draw_vs_exec.c \
draw/draw_vs_ppc.c \
draw/draw_vs_sse.c \
draw/draw_vs_varient.c \
indices/u_indices_gen.c \
indices/u_unfilled_gen.c \
os/os_misc.c \
os/os_stream.c \
os/os_stream_log.c \
os/os_stream_null.c \
os/os_stream_stdc.c \
os/os_stream_str.c \
os/os_time.c \
pipebuffer/pb_buffer_fenced.c \
pipebuffer/pb_buffer_malloc.c \
pipebuffer/pb_bufmgr_alt.c \
pipebuffer/pb_bufmgr_cache.c \
pipebuffer/pb_bufmgr_debug.c \
pipebuffer/pb_bufmgr_mm.c \
pipebuffer/pb_bufmgr_ondemand.c \
pipebuffer/pb_bufmgr_pool.c \
pipebuffer/pb_bufmgr_slab.c \
pipebuffer/pb_validate.c \
rbug/rbug_connection.c \
rbug/rbug_context.c \
rbug/rbug_core.c \
rbug/rbug_demarshal.c \
rbug/rbug_texture.c \
rbug/rbug_shader.c \
rtasm/rtasm_cpu.c \
rtasm/rtasm_execmem.c \
rtasm/rtasm_ppc.c \
rtasm/rtasm_ppc_spe.c \
rtasm/rtasm_x86sse.c \
tgsi/tgsi_build.c \
tgsi/tgsi_dump.c \
tgsi/tgsi_exec.c \
tgsi/tgsi_info.c \
tgsi/tgsi_iterate.c \
tgsi/tgsi_parse.c \
tgsi/tgsi_ppc.c \
tgsi/tgsi_sanity.c \
tgsi/tgsi_scan.c \
tgsi/tgsi_sse2.c \
tgsi/tgsi_text.c \
tgsi/tgsi_transform.c \
tgsi/tgsi_ureg.c \
tgsi/tgsi_util.c \
translate/translate.c \
translate/translate_cache.c \
translate/translate_generic.c \
translate/translate_sse.c \
util/u_debug.c \
util/u_debug_describe.c \
util/u_debug_refcnt.c \
util/u_debug_stack.c \
util/u_debug_symbol.c \
util/u_dump_defines.c \
util/u_dump_state.c \
util/u_bitmask.c \
util/u_blit.c \
util/u_blitter.c \
util/u_cache.c \
util/u_caps.c \
util/u_cpu_detect.c \
util/u_dl.c \
util/u_draw_quad.c \
util/u_format.c \
util/u_format_other.c \
util/u_format_latc.c \
util/u_format_s3tc.c \
util/u_format_rgtc.c \
util/u_format_srgb.c \
util/u_format_table.c \
util/u_format_tests.c \
util/u_format_yuv.c \
util/u_format_zs.c \
util/u_framebuffer.c \
util/u_gen_mipmap.c \
util/u_half.c \
util/u_handle_table.c \
util/u_hash.c \
util/u_hash_table.c \
util/u_index_modify.c \
util/u_keymap.c \
util/u_linear.c \
util/u_linkage.c \
util/u_network.c \
util/u_math.c \
util/u_mm.c \
util/u_pstipple.c \
util/u_rect.c \
util/u_ringbuffer.c \
util/u_sampler.c \
util/u_simple_shaders.c \
util/u_slab.c \
util/u_snprintf.c \
util/u_staging.c \
util/u_surface.c \
util/u_surfaces.c \
util/u_texture.c \
util/u_tile.c \
util/u_transfer.c \
util/u_resource.c \
util/u_upload_mgr.c \
util/u_vbuf_mgr.c
GENERATED_SOURCES = \
indices/u_indices_gen.c \
indices/u_unfilled_gen.c \
util/u_format_srgb.c \
util/u_format_table.c \
util/u_half.c
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(filter-out $(GENERATED_SOURCES), $(C_SOURCES))
LOCAL_CFLAGS := \
-fvisibility=hidden \
-Wno-sign-compare
LOCAL_C_INCLUDES := \
external/mesa/include \
external/mesa/src/gallium/include \
external/mesa/src/gallium/auxiliary \
external/mesa/src/gallium/drivers \
external/mesa/src/gallium/auxiliary/util
LOCAL_MODULE := libmesa_gallium
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
intermediates := $(call local-intermediates-dir)
GEN_SCRIPT := $(LOCAL_PATH)/indices/u_indices_gen.py
GEN := $(intermediates)/indices/u_indices_gen.c
$(GEN): PRIVATE_CUSTOM_TOOL = python $< > $@
$(GEN): $(GEN_SCRIPT)
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
GEN_SCRIPT := $(LOCAL_PATH)/indices/u_unfilled_gen.py
GEN := $(intermediates)/indices/u_unfilled_gen.c
$(GEN): PRIVATE_CUSTOM_TOOL = python $< > $@
$(GEN): $(GEN_SCRIPT)
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
GEN_SCRIPT := $(LOCAL_PATH)/util/u_format_srgb.py
GEN := $(intermediates)/util/u_format_srgb.c
$(GEN): PRIVATE_CUSTOM_TOOL = python $< > $@
$(GEN): $(GEN_SCRIPT)
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
GEN_SCRIPT := $(LOCAL_PATH)/util/u_format_table.py
GEN := $(intermediates)/util/u_format_table.c
$(GEN): PRIVATE_CUSTOM_TOOL := python $(GEN_SCRIPT) $(LOCAL_PATH)/util/u_format.csv > $(GEN)
$(GEN): $(GEN_SCRIPT) $(LOCAL_PATH)/util/u_format.csv
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
GEN_SCRIPT := $(LOCAL_PATH)/util/u_half.py
GEN := $(intermediates)/util/u_half.c
$(GEN): PRIVATE_CUSTOM_TOOL = python $< > $@
$(GEN): $(GEN_SCRIPT)
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
include $(BUILD_STATIC_LIBRARY)

View File

@@ -307,7 +307,7 @@ typedef int64_t pipe_condvar;
* pipe_barrier
*/
#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED)
#if (defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED)) && !defined(PIPE_OS_ANDROID)
typedef pthread_barrier_t pipe_barrier;

View File

@@ -39,7 +39,7 @@ struct translate *translate_create( const struct translate_key *key )
struct translate *translate = NULL;
#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
translate = translate_sse2_create( key );
/*translate = translate_sse2_create( key );*/
if (translate)
return translate;
#else

View File

@@ -199,6 +199,16 @@ roundf(float x)
#endif /* _MSC_VER */
#ifdef PIPE_OS_ANDROID
static INLINE
double log2(double d)
{
return log(d) / M_LN2;
}
#endif

View File

@@ -0,0 +1 @@
include $(call all-subdir-makefiles)

View File

@@ -0,0 +1,48 @@
ifeq ($(strip $(MESA_BUILD_I915G)),true)
LOCAL_PATH := $(call my-dir)
# from Makefile
C_SOURCES = \
i915_blit.c \
i915_clear.c \
i915_flush.c \
i915_context.c \
i915_debug.c \
i915_debug_fp.c \
i915_state.c \
i915_state_immediate.c \
i915_state_dynamic.c \
i915_state_derived.c \
i915_state_emit.c \
i915_state_fpc.c \
i915_state_sampler.c \
i915_state_static.c \
i915_screen.c \
i915_prim_emit.c \
i915_prim_vbuf.c \
i915_resource.c \
i915_resource_texture.c \
i915_resource_buffer.c \
i915_fpc_emit.c \
i915_fpc_translate.c \
i915_surface.c
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(C_SOURCES)
LOCAL_CFLAGS := \
-fvisibility=hidden \
-Wno-sign-compare
LOCAL_C_INCLUDES := \
external/mesa/src/gallium/include \
external/mesa/src/gallium/auxiliary
LOCAL_MODULE := libmesa_pipe_i915
include $(BUILD_STATIC_LIBRARY)
endif # MESA_BUILD_I915G

View File

@@ -55,7 +55,7 @@ i915_buffer_destroy(struct pipe_screen *screen,
{
struct i915_buffer *buffer = i915_buffer(resource);
if (buffer->free_on_destroy)
align_free(buffer->data);
FREE(buffer->data);
FREE(buffer);
}

View File

@@ -0,0 +1,43 @@
ifeq ($(strip $(MESA_BUILD_R600G)),true)
LOCAL_PATH := $(call my-dir)
# from Makefile
C_SOURCES = \
r600_asm.c \
r600_blit.c \
r600_buffer.c \
r600_helper.c \
r600_pipe.c \
r600_query.c \
r600_resource.c \
r600_shader.c \
r600_state.c \
r600_texture.c \
r700_asm.c \
evergreen_state.c \
eg_asm.c \
r600_translate.c \
r600_state_common.c
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(C_SOURCES)
LOCAL_CFLAGS := \
-std=c99 \
-fvisibility=hidden \
-Wno-sign-compare
LOCAL_C_INCLUDES := \
external/mesa/src/gallium/include \
external/mesa/src/gallium/auxiliary \
external/drm \
external/drm/include/drm
LOCAL_MODULE := libmesa_pipe_r600
include $(BUILD_STATIC_LIBRARY)
endif # MESA_BUILD_R600G

View File

@@ -0,0 +1,52 @@
LOCAL_PATH := $(call my-dir)
# from Makefile
C_SOURCES = \
sp_fs_exec.c \
sp_fs_sse.c \
sp_clear.c \
sp_fence.c \
sp_flush.c \
sp_query.c \
sp_context.c \
sp_draw_arrays.c \
sp_prim_vbuf.c \
sp_quad_pipe.c \
sp_quad_stipple.c \
sp_quad_depth_test.c \
sp_quad_fs.c \
sp_quad_blend.c \
sp_screen.c \
sp_setup.c \
sp_state_blend.c \
sp_state_clip.c \
sp_state_derived.c \
sp_state_sampler.c \
sp_state_shader.c \
sp_state_so.c \
sp_state_rasterizer.c \
sp_state_surface.c \
sp_state_vertex.c \
sp_texture.c \
sp_tex_sample.c \
sp_tex_tile_cache.c \
sp_tile_cache.c \
sp_surface.c
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(C_SOURCES)
LOCAL_CFLAGS := \
-fvisibility=hidden \
-Wno-sign-compare
LOCAL_C_INCLUDES := \
external/mesa/include \
external/mesa/src/gallium/include \
external/mesa/src/gallium/auxiliary
LOCAL_MODULE := libmesa_pipe_softpipe
include $(BUILD_STATIC_LIBRARY)

View File

@@ -50,7 +50,7 @@ softpipe_flush( struct pipe_context *pipe,
draw_flush(softpipe->draw);
if (flags & SP_FLUSH_TEXTURE_CACHE) {
if (1 || (flags & SP_FLUSH_TEXTURE_CACHE)) {
for (i = 0; i < softpipe->num_fragment_sampler_views; i++) {
sp_flush_tex_tile_cache(softpipe->fragment_tex_cache[i]);
}

View File

@@ -0,0 +1,73 @@
ifeq ($(strip $(MESA_BUILD_VMWGFX)),true)
LOCAL_PATH := $(call my-dir)
# from Makefile
C_SOURCES = \
svgadump/svga_shader_dump.c \
svgadump/svga_shader_op.c \
svgadump/svga_dump.c \
svga_cmd.c \
svga_context.c \
svga_draw.c \
svga_draw_arrays.c \
svga_draw_elements.c \
svga_pipe_blend.c \
svga_pipe_blit.c \
svga_pipe_clear.c \
svga_pipe_constants.c \
svga_pipe_depthstencil.c \
svga_pipe_draw.c \
svga_pipe_flush.c \
svga_pipe_fs.c \
svga_pipe_misc.c \
svga_pipe_query.c \
svga_pipe_rasterizer.c \
svga_pipe_sampler.c \
svga_pipe_vertex.c \
svga_pipe_vs.c \
svga_screen.c \
svga_screen_cache.c \
svga_state.c \
svga_state_need_swtnl.c \
svga_state_constants.c \
svga_state_framebuffer.c \
svga_state_rss.c \
svga_state_tss.c \
svga_state_vdecl.c \
svga_state_fs.c \
svga_state_vs.c \
svga_swtnl_backend.c \
svga_swtnl_draw.c \
svga_swtnl_state.c \
svga_tgsi.c \
svga_tgsi_decl_sm20.c \
svga_tgsi_decl_sm30.c \
svga_tgsi_insn.c \
svga_sampler_view.c \
svga_surface.c \
svga_resource.c \
svga_resource_texture.c \
svga_resource_buffer.c \
svga_resource_buffer_upload.c
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(C_SOURCES)
LOCAL_CFLAGS := \
-fvisibility=hidden \
-Wno-sign-compare
LOCAL_C_INCLUDES := \
external/mesa/include \
external/mesa/src/gallium/include \
external/mesa/src/gallium/auxiliary \
external/mesa/src/gallium/drivers/svga/include
LOCAL_MODULE := libmesa_pipe_svga
include $(BUILD_STATIC_LIBRARY)
endif # MESA_BUILD_VMWGFX

View File

@@ -67,7 +67,9 @@ extern "C" {
#if !defined(__HAIKU__) && !defined(__USE_MISC)
#if !defined(PIPE_OS_ANDROID)
typedef unsigned int uint;
#endif
typedef unsigned short ushort;
#endif
typedef unsigned char ubyte;

View File

@@ -133,6 +133,14 @@
#define PIPE_OS_UNIX
#endif
/*
* Android defines __linux__ so PIPE_OS_LINUX and PIPE_OS_UNIX will also be
* defined.
*/
#if defined(ANDROID)
#define PIPE_OS_ANDROID
#endif
#if defined(__FreeBSD__)
#define PIPE_OS_FREEBSD
#define PIPE_OS_BSD

View File

@@ -0,0 +1,39 @@
LOCAL_PATH := $(call my-dir)
common_SOURCES := \
egl/common/egl_g3d.c \
egl/common/egl_g3d_api.c \
egl/common/egl_g3d_image.c \
egl/common/egl_g3d_st.c \
egl/common/egl_g3d_sync.c \
egl/common/native_helper.c
android_SOURCES := \
egl/android/native_android.cpp
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(common_SOURCES) \
$(android_SOURCES)
LOCAL_CFLAGS := \
-DHAVE_ANDROID_BACKEND \
-fvisibility=hidden \
-Wno-sign-compare
LOCAL_C_INCLUDES := \
external/mesa/include \
external/mesa/src/gallium/include \
external/mesa/src/gallium/auxiliary \
external/mesa/src/egl/main \
external/mesa/src/gallium/state_trackers/egl \
external/mesa/src/gallium/winsys \
external/mesa/src/gallium/winsys/sw \
external/mesa/src/gralloc \
external/drm \
external/drm/include/drm
LOCAL_MODULE := libmesa_st_egl
include $(BUILD_STATIC_LIBRARY)

View File

@@ -0,0 +1,737 @@
/*
* Mesa 3-D graphics library
* Version: 7.9
*
* Copyright (C) 2010 LunarG 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.
*
* Authors:
* Chia-I Wu <olv@lunarg.com>
*/
#define LOG_TAG "MESA-EGL"
#include <cutils/log.h>
#include <cutils/properties.h>
#include <ui/PixelFormat.h>
#include <ui/android_native_buffer.h>
extern "C" {
#include "egllog.h"
/* see get_drm_screen_name */
#include <xf86drm.h>
#include <radeon_drm.h>
#include "radeon/drm/radeon_drm_public.h"
}
#include "util/u_memory.h"
#include "util/u_inlines.h"
#include "util/u_format.h"
#include "common/native.h"
#include "common/native_helper.h"
#include "android/android_sw_winsys.h"
#include "state_tracker/drm_driver.h"
struct android_config;
struct android_display {
struct native_display base;
boolean use_drm;
struct native_event_handler *event_handler;
struct android_config *configs;
int num_configs;
};
struct android_surface {
struct native_surface base;
struct android_display *adpy;
android_native_window_t *win;
uint stamp;
android_native_buffer_t *buf;
struct pipe_resource *res;
/* cache the current front and back resources */
void *cache_handles[2];
struct pipe_resource *cache_resources[2];
};
struct android_config {
struct native_config base;
};
static INLINE struct android_display *
android_display(const struct native_display *ndpy)
{
return (struct android_display *) ndpy;
}
static INLINE struct android_surface *
android_surface(const struct native_surface *nsurf)
{
return (struct android_surface *) nsurf;
}
static INLINE struct android_config *
android_config(const struct native_config *nconf)
{
return (struct android_config *) nconf;
}
namespace android {
static enum pipe_format
get_pipe_format(int native)
{
enum pipe_format fmt;
/* see libpixelflinger/format.cpp */
switch (native) {
case PIXEL_FORMAT_RGBA_8888:
fmt = PIPE_FORMAT_R8G8B8A8_UNORM;
break;
case PIXEL_FORMAT_RGBX_8888:
fmt = PIPE_FORMAT_R8G8B8X8_UNORM;
break;
case PIXEL_FORMAT_RGB_888:
fmt = PIPE_FORMAT_R8G8B8_UNORM;
break;
case PIXEL_FORMAT_RGB_565:
fmt = PIPE_FORMAT_B5G6R5_UNORM;
break;
case PIXEL_FORMAT_BGRA_8888:
fmt = PIPE_FORMAT_B8G8R8A8_UNORM;
break;
case PIXEL_FORMAT_A_8:
fmt = PIPE_FORMAT_A8_UNORM;
break;
case PIXEL_FORMAT_L_8:
fmt = PIPE_FORMAT_L8_UNORM;
break;
case PIXEL_FORMAT_LA_88:
fmt = PIPE_FORMAT_L8A8_UNORM;
break;
case PIXEL_FORMAT_NONE:
case PIXEL_FORMAT_RGBA_5551:
case PIXEL_FORMAT_RGBA_4444:
case PIXEL_FORMAT_RGB_332:
default:
LOGE("unsupported native format 0x%x", native);
fmt = PIPE_FORMAT_NONE;
break;
}
return fmt;
}
#include <gralloc_gem.h>
static int
get_handle_name(buffer_handle_t handle)
{
struct drm_bo_t *bo;
bo = drm_gem_get(handle);
return (bo) ? bo->name : 0;
}
static struct pipe_resource *
import_buffer(struct android_display *adpy, const struct pipe_resource *templ,
struct android_native_buffer_t *abuf)
{
struct pipe_screen *screen = adpy->base.screen;
struct pipe_resource *res;
if (templ->bind & PIPE_BIND_RENDER_TARGET) {
if (!screen->is_format_supported(screen, templ->format,
templ->target, 0, PIPE_BIND_RENDER_TARGET))
LOGW("importing unsupported buffer as render target");
}
if (templ->bind & PIPE_BIND_SAMPLER_VIEW) {
if (!screen->is_format_supported(screen, templ->format,
templ->target, 0, PIPE_BIND_SAMPLER_VIEW))
LOGW("importing unsupported buffer as sampler view");
}
if (adpy->use_drm) {
struct winsys_handle handle;
memset(&handle, 0, sizeof(handle));
handle.type = DRM_API_HANDLE_TYPE_SHARED;
handle.handle = get_handle_name(abuf->handle);
if (!handle.handle) {
LOGE("unable to import invalid buffer %p", abuf);
return NULL;
}
handle.stride =
abuf->stride * util_format_get_blocksize(templ->format);
res = screen->resource_from_handle(screen, templ, &handle);
}
else {
struct android_winsys_handle handle;
memset(&handle, 0, sizeof(handle));
handle.handle = abuf->handle;
handle.stride =
abuf->stride * util_format_get_blocksize(templ->format);
res = screen->resource_from_handle(screen,
templ, (struct winsys_handle *) &handle);
}
if (!res)
LOGE("failed to import buffer %p", abuf);
return res;
}
static boolean
android_surface_dequeue_buffer(struct native_surface *nsurf)
{
struct android_surface *asurf = android_surface(nsurf);
void *handle;
int idx;
if (asurf->win->dequeueBuffer(asurf->win, &asurf->buf) != NO_ERROR) {
LOGE("failed to dequeue window %p", asurf->win);
return FALSE;
}
asurf->buf->common.incRef(&asurf->buf->common);
asurf->win->lockBuffer(asurf->win, asurf->buf);
if (asurf->adpy->use_drm)
handle = (void *) get_handle_name(asurf->buf->handle);
else
handle = (void *) asurf->buf->handle;
/* NULL is invalid */
if (!handle) {
LOGE("window %p returned an invalid buffer", asurf->win);
return TRUE;
}
/* find the slot to use */
for (idx = 0; idx < Elements(asurf->cache_handles); idx++) {
if (asurf->cache_handles[idx] == handle || !asurf->cache_handles[idx])
break;
}
if (idx == Elements(asurf->cache_handles)) {
/* buffer reallocated; clear the cache */
for (idx = 0; idx < Elements(asurf->cache_handles); idx++) {
asurf->cache_handles[idx] = 0;
pipe_resource_reference(&asurf->cache_resources[idx], NULL);
}
idx = 0;
}
/* update the cache */
if (!asurf->cache_handles[idx]) {
struct pipe_resource templ;
assert(!asurf->cache_resources[idx]);
memset(&templ, 0, sizeof(templ));
templ.target = PIPE_TEXTURE_2D;
templ.last_level = 0;
templ.width0 = asurf->buf->width;
templ.height0 = asurf->buf->height;
templ.depth0 = 1;
templ.bind = PIPE_BIND_RENDER_TARGET;
if (!asurf->adpy->use_drm) {
templ.bind |= PIPE_BIND_TRANSFER_WRITE |
PIPE_BIND_TRANSFER_READ;
}
templ.format = get_pipe_format(asurf->buf->format);
if (templ.format != PIPE_FORMAT_NONE) {
asurf->cache_resources[idx] =
import_buffer(asurf->adpy, &templ, asurf->buf);
}
else {
asurf->cache_resources[idx] = NULL;
}
asurf->cache_handles[idx] = handle;
}
pipe_resource_reference(&asurf->res, asurf->cache_resources[idx]);
return TRUE;
}
static boolean
android_surface_enqueue_buffer(struct native_surface *nsurf)
{
struct android_surface *asurf = android_surface(nsurf);
pipe_resource_reference(&asurf->res, NULL);
asurf->win->queueBuffer(asurf->win, asurf->buf);
asurf->buf->common.decRef(&asurf->buf->common);
asurf->buf = NULL;
return TRUE;
}
static boolean
android_surface_swap_buffers(struct native_surface *nsurf)
{
struct android_surface *asurf = android_surface(nsurf);
struct android_display *adpy = asurf->adpy;
if (!asurf->buf)
return FALSE;
android_surface_enqueue_buffer(&asurf->base);
asurf->stamp++;
adpy->event_handler->invalid_surface(&adpy->base,
&asurf->base, asurf->stamp);
return TRUE;
}
static boolean
android_surface_present(struct native_surface *nsurf,
enum native_attachment natt,
boolean preserve,
uint swap_interval)
{
boolean ret;
if (swap_interval || natt != NATIVE_ATTACHMENT_BACK_LEFT)
return FALSE;
return android_surface_swap_buffers(nsurf);
}
static boolean
android_surface_validate(struct native_surface *nsurf, uint attachment_mask,
unsigned int *seq_num, struct pipe_resource **textures,
int *width, int *height)
{
struct android_surface *asurf = android_surface(nsurf);
struct winsys_handle handle;
if (!asurf->buf) {
if (!android_surface_dequeue_buffer(&asurf->base))
return FALSE;
}
if (textures) {
const enum native_attachment att = NATIVE_ATTACHMENT_BACK_LEFT;
if (native_attachment_mask_test(attachment_mask, att)) {
textures[att] = NULL;
pipe_resource_reference(&textures[att], asurf->res);
}
}
if (seq_num)
*seq_num = asurf->stamp;
if (width)
*width = asurf->buf->width;
if (height)
*height = asurf->buf->height;
return TRUE;
}
static void
android_surface_wait(struct native_surface *nsurf)
{
}
static void
android_surface_destroy(struct native_surface *nsurf)
{
struct android_surface *asurf = android_surface(nsurf);
int i;
if (asurf->buf)
android_surface_enqueue_buffer(&asurf->base);
for (i = 0; i < Elements(asurf->cache_handles); i++)
pipe_resource_reference(&asurf->cache_resources[i], NULL);
asurf->win->common.decRef(&asurf->win->common);
FREE(asurf);
}
static struct native_surface *
android_display_create_window_surface(struct native_display *ndpy,
EGLNativeWindowType win,
const struct native_config *nconf)
{
struct android_display *adpy = android_display(ndpy);
struct android_config *aconf = android_config(nconf);
struct android_surface *asurf;
enum pipe_format format;
int val;
if (win->common.magic != ANDROID_NATIVE_WINDOW_MAGIC) {
LOGE("invalid native window with magic 0x%x", win->common.magic);
return NULL;
}
if (win->query(win, NATIVE_WINDOW_FORMAT, &val)) {
LOGE("failed to query native window format");
return NULL;
}
format = get_pipe_format(val);
if (format != nconf->color_format) {
LOGW("native window format 0x%x != config format 0x%x",
format, nconf->color_format);
if (!adpy->base.screen->is_format_supported(adpy->base.screen,
format, PIPE_TEXTURE_2D, 0, PIPE_BIND_RENDER_TARGET)) {
LOGE("and the native window cannot be used as a render target");
return NULL;
}
}
asurf = CALLOC_STRUCT(android_surface);
if (!asurf)
return NULL;
asurf->adpy = adpy;
asurf->win = win;
asurf->win->common.incRef(&asurf->win->common);
if (!adpy->use_drm) {
native_window_set_usage(asurf->win,
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
}
asurf->base.destroy = android_surface_destroy;
asurf->base.present = android_surface_present;
asurf->base.validate = android_surface_validate;
asurf->base.wait = android_surface_wait;
return &asurf->base;
}
static boolean
android_display_init_configs(struct native_display *ndpy)
{
struct android_display *adpy = android_display(ndpy);
const int native_formats[] = {
PIXEL_FORMAT_RGBA_8888,
PIXEL_FORMAT_RGBX_8888,
PIXEL_FORMAT_RGB_888,
PIXEL_FORMAT_RGB_565,
PIXEL_FORMAT_BGRA_8888,
PIXEL_FORMAT_A_8
};
int i;
adpy->configs = (struct android_config *)
CALLOC(Elements(native_formats), sizeof(*adpy->configs));
if (!adpy->configs)
return FALSE;
for (i = 0; i < Elements(native_formats); i++) {
enum pipe_format color_format;
struct android_config *aconf;
color_format = get_pipe_format(native_formats[i]);
if (color_format == PIPE_FORMAT_NONE ||
!adpy->base.screen->is_format_supported(adpy->base.screen,
color_format, PIPE_TEXTURE_2D, 0, PIPE_BIND_RENDER_TARGET)) {
LOGI("skip unsupported native format 0x%x", native_formats[i]);
continue;
}
aconf = &adpy->configs[adpy->num_configs++];
aconf->base.buffer_mask = 1 << NATIVE_ATTACHMENT_BACK_LEFT;
aconf->base.color_format = color_format;
aconf->base.window_bit = TRUE;
aconf->base.native_visual_type = native_formats[i];
}
return TRUE;
}
static const char *
get_drm_screen_name(int fd, drmVersionPtr version)
{
const char *name = version->name;
if (name && !strcmp(name, "radeon")) {
int chip_id;
struct drm_radeon_info info;
memset(&info, 0, sizeof(info));
info.request = RADEON_INFO_DEVICE_ID;
info.value = pointer_to_intptr(&chip_id);
if (drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)) != 0)
return NULL;
name = is_r3xx(chip_id) ? "r300" : "r600";
}
return name;
}
static boolean
android_display_init_drm(struct native_display *ndpy)
{
struct android_display *adpy = android_display(ndpy);
const hw_module_t *mod;
int fd, 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);
}
if (!err && fd >= 0) {
drmVersionPtr version;
const char *name;
version = drmGetVersion(fd);
if (version) {
name = get_drm_screen_name(fd, version);
if (name) {
adpy->base.screen =
adpy->event_handler->new_drm_screen(&adpy->base, name, fd);
}
drmFreeVersion(version);
}
else {
_eglLog(_EGL_WARNING, "invalid fd %d", fd);
err = -EINVAL;
}
if (adpy->base.screen)
adpy->use_drm = TRUE;
}
if (adpy->base.screen) {
LOGI("using DRM screen");
return TRUE;
}
else {
LOGE("failed to create DRM screen");
return FALSE;
}
}
static boolean
android_display_init_sw(struct native_display *ndpy)
{
struct android_display *adpy = android_display(ndpy);
struct sw_winsys *ws;
ws = android_create_sw_winsys();
if (ws) {
adpy->base.screen =
adpy->event_handler->new_sw_screen(&adpy->base, ws);
}
if (adpy->base.screen) {
LOGI("using SW screen");
return TRUE;
}
else {
LOGE("failed to create SW screen");
return FALSE;
}
}
static void
android_display_destroy(struct native_display *ndpy)
{
struct android_display *adpy = android_display(ndpy);
FREE(adpy->configs);
adpy->base.screen->destroy(adpy->base.screen);
FREE(adpy);
}
static const struct native_config **
android_display_get_configs(struct native_display *ndpy, int *num_configs)
{
struct android_display *adpy = android_display(ndpy);
const struct native_config **configs;
int i;
configs = (const struct native_config **)
MALLOC(adpy->num_configs * sizeof(*configs));
if (configs) {
for (i = 0; i < adpy->num_configs; i++)
configs[i] = (const struct native_config *) &adpy->configs[i];
if (num_configs)
*num_configs = adpy->num_configs;
}
return configs;
}
static int
android_display_get_param(struct native_display *ndpy,
enum native_param_type param)
{
int val;
switch (param) {
default:
val = 0;
break;
}
return val;
}
static struct pipe_resource *
android_display_import_buffer(struct native_display *ndpy,
const struct pipe_resource *templ,
void *buf)
{
struct android_display *adpy = android_display(ndpy);
struct android_native_buffer_t *abuf =
(struct android_native_buffer_t *) buf;
return import_buffer(adpy, templ, abuf);
}
static boolean
android_display_export_buffer(struct native_display *ndpy,
struct pipe_resource *res,
void *buf)
{
return FALSE;
}
static struct native_display_buffer android_display_buffer = {
android_display_import_buffer,
android_display_export_buffer
};
static struct android_display *
android_display_create(struct native_event_handler *event_handler,
boolean use_sw, void *user_data)
{
struct android_display *adpy;
char value[PROPERTY_VALUE_MAX];
boolean force_sw;
adpy = CALLOC_STRUCT(android_display);
if (!adpy)
return NULL;
adpy->event_handler = event_handler;
adpy->base.user_data = user_data;
if (property_get("debug.mesa.software", value, NULL))
force_sw = (atoi(value) != 0);
else
force_sw = debug_get_bool_option("EGL_SOFTWARE", FALSE);
if (force_sw || use_sw)
android_display_init_sw(&adpy->base);
else
android_display_init_drm(&adpy->base);
if (!adpy->base.screen) {
FREE(adpy);
return NULL;
}
if (!android_display_init_configs(&adpy->base)) {
adpy->base.screen->destroy(adpy->base.screen);
FREE(adpy);
return NULL;
}
adpy->base.destroy = android_display_destroy;
adpy->base.get_param = android_display_get_param;
adpy->base.get_configs = android_display_get_configs;
adpy->base.create_window_surface = android_display_create_window_surface;
adpy->base.buffer = &android_display_buffer;
return adpy;
}
static struct native_event_handler *android_event_handler;
static void
native_set_event_handler(struct native_event_handler *event_handler)
{
android_event_handler = event_handler;
}
static struct native_display *
native_create_display(void *dpy, boolean use_sw, void *user_data)
{
struct android_display *adpy;
adpy = android_display_create(android_event_handler, use_sw, user_data);
return (adpy) ? &adpy->base : NULL;
}
static const struct native_platform android_platform = {
"Android", /* name */
native_set_event_handler,
native_create_display
};
}; /* namespace android */
using namespace android;
static void
android_log(EGLint level, const char *msg)
{
switch (level) {
case _EGL_DEBUG:
LOGD(msg);
break;
case _EGL_INFO:
LOGI(msg);
break;
case _EGL_WARNING:
LOGW(msg);
break;
case _EGL_FATAL:
LOG_FATAL(msg);
break;
default:
break;
}
}
const struct native_platform *
native_get_android_platform(void)
{
_eglSetLogProc(android_log);
return &android_platform;
}

View File

@@ -119,6 +119,12 @@ egl_g3d_get_platform(_EGLDriver *drv, _EGLPlatformType plat)
plat_name = "FBDEV";
#ifdef HAVE_FBDEV_BACKEND
nplat = native_get_fbdev_platform();
#endif
break;
case _EGL_PLATFORM_ANDROID:
plat_name = "Android";
#ifdef HAVE_ANDROID_BACKEND
nplat = native_get_android_platform();
#endif
break;
default:
@@ -552,6 +558,11 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy)
if (dpy->Platform == _EGL_PLATFORM_WAYLAND && gdpy->native->buffer)
dpy->Extensions.MESA_drm_image = EGL_TRUE;
#ifdef EGL_ANDROID_image_native_buffer
if (dpy->Platform == _EGL_PLATFORM_ANDROID && gdpy->native->buffer)
dpy->Extensions.ANDROID_image_native_buffer = EGL_TRUE;
#endif
if (egl_g3d_add_configs(drv, dpy, 1) == 1) {
_eglError(EGL_NOT_INITIALIZED, "eglInitialize(unable to add configs)");
goto fail;

View File

@@ -93,6 +93,9 @@ struct egl_g3d_image {
struct pipe_resource *texture;
unsigned level;
unsigned layer;
EGLenum target;
EGLClientBuffer buffer;
};
/* standard typecasts */

View File

@@ -40,6 +40,11 @@
/* for struct winsys_handle */
#include "state_tracker/drm_driver.h"
#ifdef EGL_ANDROID_image_native_buffer
#include <ui/android_native_buffer.h>
#include "android/android_sw_winsys.h"
#endif
/**
* Reference and return the front left buffer of the native pixmap.
*/
@@ -179,6 +184,69 @@ egl_g3d_reference_drm_buffer(_EGLDisplay *dpy, EGLint name,
#endif /* EGL_MESA_drm_image */
#ifdef EGL_ANDROID_image_native_buffer
static struct pipe_resource *
egl_g3d_reference_android_native_buffer(_EGLDisplay *dpy,
struct android_native_buffer_t *buf)
{
struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
struct pipe_screen *screen = gdpy->native->screen;
enum pipe_format format;
struct pipe_resource templ, *res;
struct android_winsys_handle handle;
if (!buf || buf->common.magic != ANDROID_NATIVE_BUFFER_MAGIC ||
buf->common.version != sizeof(*buf)) {
_eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
return NULL;
}
switch (buf->format) {
case HAL_PIXEL_FORMAT_RGBA_8888:
format = PIPE_FORMAT_R8G8B8A8_UNORM;
break;
case HAL_PIXEL_FORMAT_RGBX_8888:
format = PIPE_FORMAT_R8G8B8X8_UNORM;
break;
case HAL_PIXEL_FORMAT_RGB_888:
format = PIPE_FORMAT_R8G8B8_UNORM;
break;
case HAL_PIXEL_FORMAT_RGB_565:
format = PIPE_FORMAT_B5G6R5_UNORM;
break;
case HAL_PIXEL_FORMAT_BGRA_8888:
format = PIPE_FORMAT_B8G8R8A8_UNORM;
break;
case HAL_PIXEL_FORMAT_RGBA_5551:
case HAL_PIXEL_FORMAT_RGBA_4444:
/* unsupported */
default:
_eglLog(_EGL_WARNING, "unsupported native format 0x%x", buf->format);
return NULL;
break;
}
memset(&templ, 0, sizeof(templ));
templ.target = PIPE_TEXTURE_2D;
templ.format = format;
/* assume for texturing only */
templ.bind = PIPE_BIND_SAMPLER_VIEW;
templ.width0 = buf->width;
templ.height0 = buf->height;
templ.depth0 = 1;
templ.array_size = 1;
res = gdpy->native->buffer->import_buffer(gdpy->native,
&templ, (void *) buf);
if (res)
buf->common.incRef(&buf->common);
return res;
}
#endif /* EGL_ANDROID_image_native_buffer */
_EGLImage *
egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
EGLenum target, EGLClientBuffer buffer,
@@ -199,6 +267,8 @@ egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
return NULL;
}
gimg->target = target;
switch (target) {
case EGL_NATIVE_PIXMAP_KHR:
ptex = egl_g3d_reference_native_pixmap(dpy,
@@ -209,6 +279,13 @@ egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
ptex = egl_g3d_reference_drm_buffer(dpy,
(EGLint) buffer, &gimg->base, attribs);
break;
#endif
#ifdef EGL_ANDROID_image_native_buffer
case EGL_NATIVE_BUFFER_ANDROID:
gimg->buffer = buffer;
ptex = egl_g3d_reference_android_native_buffer(dpy,
(struct android_native_buffer_t *) buffer);
break;
#endif
default:
ptex = NULL;
@@ -246,6 +323,14 @@ egl_g3d_destroy_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *img)
{
struct egl_g3d_image *gimg = egl_g3d_image(img);
#ifdef EGL_ANDROID_image_native_buffer
if (gimg->target == EGL_NATIVE_BUFFER_ANDROID) {
struct android_native_buffer_t * buf =
(struct android_native_buffer_t *) gimg->buffer;
buf->common.decRef(&buf->common);
}
#endif
pipe_resource_reference(&gimg->texture, NULL);
FREE(gimg);

View File

@@ -275,6 +275,9 @@ native_get_drm_platform(void);
const struct native_platform *
native_get_fbdev_platform(void);
const struct native_platform *
native_get_android_platform(void);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,121 @@
# Android.mk for Gallium EGL and gralloc
LOCAL_PATH := $(call my-dir)
# EGL
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
egl-static/egl.c \
egl-static/egl_pipe.c \
egl-static/egl_st.c
LOCAL_CFLAGS := \
-DFEATURE_ES1=1 \
-DFEATURE_ES2=1 \
-DGALLIUM_SOFTPIPE \
-D_EGL_MAIN=_eglBuiltInDriverGALLIUM \
-fvisibility=hidden \
-Wno-sign-compare
LOCAL_C_INCLUDES := \
external/mesa/include \
external/mesa/src/gallium/include \
external/mesa/src/gallium/auxiliary \
external/mesa/src/gallium/drivers \
external/mesa/src/gallium/winsys \
external/mesa/src/gallium/state_trackers/vega \
external/mesa/src/gallium/state_trackers/egl \
external/mesa/src/egl/main \
external/mesa/src/mesa
LOCAL_STATIC_LIBRARIES := \
libmesa_st_egl \
libmesa_winsys_sw \
libmesa_pipe_softpipe \
libmesa_st_mesa \
libmesa_glsl \
libmesa_st_mesa \
libmesa_gallium
LOCAL_WHOLE_STATIC_LIBRARIES := \
libmesa_egl
LOCAL_SHARED_LIBRARIES := \
libglapi \
libdl \
libhardware \
liblog \
libcutils
ifeq ($(strip $(MESA_BUILD_CLASSIC)),true)
LOCAL_STATIC_LIBRARIES := \
libmesa_classic_egl \
$(LOCAL_STATIC_LIBRARIES)
LOCAL_SHARED_LIBRARIES += libdrm
endif # MESA_BUILD_CLASSIC
ifeq ($(strip $(MESA_BUILD_I915G)),true)
LOCAL_CFLAGS += -D_EGL_PIPE_I915
LOCAL_STATIC_LIBRARIES := \
libmesa_winsys_i915 \
libmesa_pipe_i915 \
$(LOCAL_STATIC_LIBRARIES)
LOCAL_SHARED_LIBRARIES += \
libdrm \
libdrm_intel
endif # MESA_BUILD_I915G
ifeq ($(strip $(MESA_BUILD_R600G)),true)
LOCAL_CFLAGS += -D_EGL_PIPE_R600
LOCAL_STATIC_LIBRARIES := \
libmesa_pipe_r600 \
libmesa_winsys_r600 \
$(LOCAL_STATIC_LIBRARIES)
LOCAL_SHARED_LIBRARIES += \
libdrm \
libdrm_radeon
endif # MESA_BUILD_R600G
LOCAL_MODULE := libGLES_mesa
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/egl
include $(BUILD_SHARED_LIBRARY)
# gralloc (broken!)
ifeq ($(strip $(MESA_BUILD_VMWGFX)),true)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := egl/egl_pipe.c
LOCAL_CFLAGS := \
-D_EGL_PIPE_VMWGFX=1 \
-fvisibility=hidden \
-Wno-sign-compare
LOCAL_C_INCLUDES := \
external/mesa/src/gallium/include \
external/mesa/src/gallium/auxiliary \
external/mesa/src/gallium/drivers \
external/mesa/src/gallium/winsys
LOCAL_STATIC_LIBRARIES := \
libmesa_pipe_svga \
libmesa_winsys_svga \
libmesa_gallium
LOCAL_WHOLE_STATIC_LIBRARIES := \
libmesa_st_gralloc
LOCAL_SHARED_LIBRARIES := \
libdl \
liblog \
libcutils \
libdrm \
libEGL
LOCAL_MODULE := gralloc.mesa
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
include $(BUILD_SHARED_LIBRARY)
endif # MESA_BUILD_VMWGFX

View File

@@ -0,0 +1 @@
include $(call all-subdir-makefiles)

View File

@@ -0,0 +1,33 @@
ifeq ($(strip $(MESA_BUILD_I915G)),true)
LOCAL_PATH := $(call my-dir)
# from drm/Makefile
C_SOURCES = \
i915_drm_batchbuffer.c \
i915_drm_buffer.c \
i915_drm_fence.c \
i915_drm_winsys.c
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(addprefix drm/, $(C_SOURCES))
LOCAL_CFLAGS := \
-fvisibility=hidden \
-Wno-sign-compare
LOCAL_C_INCLUDES := \
external/mesa/src/gallium/include \
external/mesa/src/gallium/auxiliary \
external/mesa/src/gallium/drivers \
external/drm \
external/drm/include/drm \
external/drm/intel
LOCAL_MODULE := libmesa_winsys_i915
include $(BUILD_STATIC_LIBRARY)
endif # MESA_BUILD_I915G

View File

@@ -0,0 +1,38 @@
ifeq ($(strip $(MESA_BUILD_R600G)),true)
LOCAL_PATH := $(call my-dir)
# from drm/Makefile
C_SOURCES = \
bof.c \
evergreen_hw_context.c \
radeon_bo.c \
radeon_pciid.c \
r600_bo.c \
r600_drm.c \
r600_hw_context.c \
r600_bomgr.c
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(addprefix drm/, $(C_SOURCES))
LOCAL_CFLAGS := \
-std=c99 \
-fvisibility=hidden \
-Wno-sign-compare
LOCAL_C_INCLUDES := \
external/mesa/include \
external/mesa/src/gallium/include \
external/mesa/src/gallium/auxiliary \
external/mesa/src/gallium/drivers/r600 \
external/drm \
external/drm/include/drm
LOCAL_MODULE := libmesa_winsys_r600
include $(BUILD_STATIC_LIBRARY)
endif # MESA_BUILD_R600G

View File

@@ -33,6 +33,25 @@
#include "xf86drm.h"
#include "radeon_drm.h"
#ifdef ANDROID
extern void* __mmap2(void*, size_t, int, int, int, size_t);
#define MMAP2_SHIFT 12
static void* android_mmap2(void *addr, size_t size, int prot, int flags, int fd, unsigned long long offset)
{
if ( offset & ((1UL << MMAP2_SHIFT)-1) ) {
errno = EINVAL;
return MAP_FAILED;
}
return __mmap2(addr, size, prot, flags, fd, (size_t)(offset >> MMAP2_SHIFT));
}
#define mmap(addr, size, prot, flags, fd, offset) android_mmap2(addr, size, prot, flags, fd, offset)
#endif /* ANDROID */
static int radeon_bo_fixed_map(struct radeon *radeon, struct radeon_bo *bo)
{
struct drm_radeon_gem_mmap args;

View File

@@ -0,0 +1,39 @@
ifeq ($(strip $(MESA_BUILD_VMWGFX)),true)
LOCAL_PATH := $(call my-dir)
# from drm/Makefile
C_SOURCES = \
vmw_buffer.c \
vmw_context.c \
vmw_fence.c \
vmw_screen.c \
vmw_screen_dri.c \
vmw_screen_ioctl.c \
vmw_screen_pools.c \
vmw_screen_svga.c \
vmw_surface.c
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(addprefix drm/, $(C_SOURCES))
LOCAL_CFLAGS := \
-fvisibility=hidden \
-Wno-sign-compare
LOCAL_C_INCLUDES := \
external/mesa/include \
external/mesa/src/gallium/include \
external/mesa/src/gallium/auxiliary \
external/mesa/src/gallium/drivers/svga \
external/mesa/src/gallium/drivers/svga/include \
external/drm \
external/drm/include/drm
LOCAL_MODULE := libmesa_winsys_svga
include $(BUILD_STATIC_LIBRARY)
endif # MESA_BUILD_VMWGFX

View File

@@ -46,6 +46,24 @@
#include <errno.h>
#include <unistd.h>
#ifdef PIPE_OS_ANDROID
extern void* __mmap2(void*, size_t, int, int, int, size_t);
#define MMAP2_SHIFT 12
static INLINE void* vmw_mmap(void *addr, size_t size, int prot, int flags, int fd, unsigned long long offset)
{
if ( offset & ((1UL << MMAP2_SHIFT)-1) ) {
errno = EINVAL;
return MAP_FAILED;
}
return __mmap2(addr, size, prot, flags, fd, (size_t)(offset >> MMAP2_SHIFT));
}
#else
#define vmw_mmap(addr, size, prot, flags, fd, offset) mmap(addr, size, prot, flags, fd, offset)
#endif
struct vmw_region
{
SVGAGuestPtr ptr;
@@ -106,7 +124,7 @@ vmw_ioctl_fifo_map(struct vmw_winsys_screen *vws,
VMW_FUNC;
map = mmap(NULL, getpagesize(), PROT_READ, MAP_SHARED,
map = vmw_mmap(NULL, getpagesize(), PROT_READ, MAP_SHARED,
vws->ioctl.drm_fd, fifo_offset);
if (map == MAP_FAILED) {
@@ -388,7 +406,7 @@ vmw_ioctl_region_map(struct vmw_region *region)
region->ptr.gmrId, region->ptr.offset);
if (region->data == NULL) {
map = mmap(NULL, region->size, PROT_READ | PROT_WRITE, MAP_SHARED,
map = vmw_mmap(NULL, region->size, PROT_READ | PROT_WRITE, MAP_SHARED,
region->drm_fd, region->map_handle);
if (map == MAP_FAILED) {
debug_printf("%s: Map failed.\n", __FUNCTION__);

View File

@@ -0,0 +1,19 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
android/android_sw_winsys.cpp
LOCAL_CFLAGS := \
-fvisibility=hidden \
-Wno-sign-compare
LOCAL_C_INCLUDES := \
external/mesa/include \
external/mesa/src/gallium/include \
external/mesa/src/gallium/auxiliary
LOCAL_MODULE := libmesa_winsys_sw
include $(BUILD_STATIC_LIBRARY)

View File

@@ -0,0 +1,269 @@
/*
* Mesa 3-D graphics library
* Version: 7.9
*
* Copyright (C) 2010 LunarG 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.
*
* Authors:
* Chia-I Wu <olv@lunarg.com>
*/
#include "pipe/p_compiler.h"
#include "pipe/p_state.h"
#include "util/u_memory.h"
#include "util/u_format.h"
#include "state_tracker/sw_winsys.h"
#include <ui/PixelFormat.h>
#include <private/ui/sw_gralloc_handle.h>
#include <hardware/gralloc.h>
#include "android_sw_winsys.h"
struct android_sw_winsys
{
struct sw_winsys base;
const gralloc_module_t *grmod;
};
struct android_sw_displaytarget
{
buffer_handle_t handle;
int stride;
int width, height, usage;
void *mapped;
};
static INLINE struct android_sw_winsys *
android_sw_winsys(struct sw_winsys *ws)
{
return (struct android_sw_winsys *) ws;
}
static INLINE struct android_sw_displaytarget *
android_sw_displaytarget(struct sw_displaytarget *dt)
{
return (struct android_sw_displaytarget *) dt;
}
namespace android {
static void
android_displaytarget_display(struct sw_winsys *ws,
struct sw_displaytarget *dt,
void *context_private)
{
}
static struct sw_displaytarget *
android_displaytarget_create(struct sw_winsys *ws,
unsigned tex_usage,
enum pipe_format format,
unsigned width, unsigned height,
unsigned alignment,
unsigned *stride)
{
return NULL;
}
static void
android_displaytarget_destroy(struct sw_winsys *ws,
struct sw_displaytarget *dt)
{
struct android_sw_displaytarget *adt = android_sw_displaytarget(dt);
assert(!adt->mapped);
FREE(adt);
}
static void
android_displaytarget_unmap(struct sw_winsys *ws,
struct sw_displaytarget *dt)
{
struct android_sw_winsys *droid = android_sw_winsys(ws);
struct android_sw_displaytarget *adt = android_sw_displaytarget(dt);
if (adt->mapped) {
if (sw_gralloc_handle_t::validate(adt->handle) >= 0) {
adt->mapped = NULL;
}
else {
droid->grmod->unlock(droid->grmod, adt->handle);
adt->mapped = NULL;
}
}
}
static void *
android_displaytarget_map(struct sw_winsys *ws,
struct sw_displaytarget *dt,
unsigned flags)
{
struct android_sw_winsys *droid = android_sw_winsys(ws);
struct android_sw_displaytarget *adt = android_sw_displaytarget(dt);
if (!adt->mapped) {
if (sw_gralloc_handle_t::validate(adt->handle) >= 0) {
const sw_gralloc_handle_t *swhandle =
reinterpret_cast<const sw_gralloc_handle_t *>(adt->handle);
adt->mapped = reinterpret_cast<void *>(swhandle->base);
}
else {
droid->grmod->lock(droid->grmod, adt->handle,
adt->usage, 0, 0, adt->width, adt->height, &adt->mapped);
}
}
return adt->mapped;
}
static struct sw_displaytarget *
android_displaytarget_from_handle(struct sw_winsys *ws,
const struct pipe_resource *templ,
struct winsys_handle *whandle,
unsigned *stride)
{
struct android_winsys_handle *ahandle =
(struct android_winsys_handle *) whandle;
struct android_sw_displaytarget *adt;
adt = CALLOC_STRUCT(android_sw_displaytarget);
if (!adt)
return NULL;
adt->handle = ahandle->handle;
adt->stride = ahandle->stride;
adt->width = templ->width0;
adt->height = templ->height0;
if (templ->usage & PIPE_BIND_RENDER_TARGET)
adt->usage |= GRALLOC_USAGE_HW_RENDER;
if (templ->usage & PIPE_BIND_SAMPLER_VIEW)
adt->usage |= GRALLOC_USAGE_HW_TEXTURE;
if (templ->usage & PIPE_BIND_SCANOUT)
adt->usage |= GRALLOC_USAGE_HW_FB;
if (templ->usage & PIPE_BIND_TRANSFER_READ)
adt->usage |= GRALLOC_USAGE_SW_READ_OFTEN;
if (templ->usage & PIPE_BIND_TRANSFER_WRITE)
adt->usage |= GRALLOC_USAGE_SW_WRITE_OFTEN;
if (stride)
*stride = adt->stride;
return reinterpret_cast<struct sw_displaytarget *>(adt);
}
static boolean
android_displaytarget_get_handle(struct sw_winsys *ws,
struct sw_displaytarget *dt,
struct winsys_handle *whandle)
{
return FALSE;
}
static boolean
android_is_displaytarget_format_supported(struct sw_winsys *ws,
unsigned tex_usage,
enum pipe_format format)
{
struct android_sw_winsys *droid = android_sw_winsys(ws);
int fmt;
switch (format) {
case PIPE_FORMAT_R8G8B8A8_UNORM:
fmt = PIXEL_FORMAT_RGBA_8888;
break;
case PIPE_FORMAT_R8G8B8X8_UNORM:
fmt = PIXEL_FORMAT_RGBX_8888;
break;
case PIPE_FORMAT_R8G8B8_UNORM:
fmt = PIXEL_FORMAT_RGB_888;
break;
case PIPE_FORMAT_B5G6R5_UNORM:
fmt = PIXEL_FORMAT_RGB_565;
break;
case PIPE_FORMAT_B8G8R8A8_UNORM:
fmt = PIXEL_FORMAT_BGRA_8888;
break;
case PIPE_FORMAT_A8_UNORM:
fmt = PIXEL_FORMAT_A_8;
break;
case PIPE_FORMAT_L8_UNORM:
fmt = PIXEL_FORMAT_L_8;
break;
case PIPE_FORMAT_L8A8_UNORM:
fmt = PIXEL_FORMAT_LA_88;
break;
default:
fmt = PIXEL_FORMAT_NONE;
break;
}
return (fmt != PIXEL_FORMAT_NONE);
}
static void
android_destroy(struct sw_winsys *ws)
{
struct android_sw_winsys *droid = android_sw_winsys(ws);
FREE(droid);
}
}; /* namespace android */
using namespace android;
struct sw_winsys *
android_create_sw_winsys(void)
{
struct android_sw_winsys *droid;
const hw_module_t *mod;
droid = CALLOC_STRUCT(android_sw_winsys);
if (!droid)
return NULL;
if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &mod)) {
FREE(droid);
return NULL;
}
droid->grmod = (const gralloc_module_t *) mod;
droid->base.destroy = android_destroy;
droid->base.is_displaytarget_format_supported =
android_is_displaytarget_format_supported;
droid->base.displaytarget_create = android_displaytarget_create;
droid->base.displaytarget_destroy = android_displaytarget_destroy;
droid->base.displaytarget_from_handle = android_displaytarget_from_handle;
droid->base.displaytarget_get_handle = android_displaytarget_get_handle;
droid->base.displaytarget_map = android_displaytarget_map;
droid->base.displaytarget_unmap = android_displaytarget_unmap;
droid->base.displaytarget_display = android_displaytarget_display;
return &droid->base;
}

View File

@@ -0,0 +1,49 @@
/*
* Mesa 3-D graphics library
* Version: 7.9
*
* Copyright (C) 2010 LunarG 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.
*
* Authors:
* Chia-I Wu <olv@lunarg.com>
*/
#ifndef ANDROID_SW_WINSYS
#define ANDROID_SW_WINSYS
#include <sys/cdefs.h>
#include <hardware/gralloc.h>
__BEGIN_DECLS
struct sw_winsys;
struct android_winsys_handle {
buffer_handle_t handle;
int stride;
};
struct sw_winsys *
android_create_sw_winsys(void);
__END_DECLS
#endif /* ANDROID_SW_WINSYS */

100
src/glsl/Android.mk Normal file
View File

@@ -0,0 +1,100 @@
# Android.mk for glsl
LOCAL_PATH := $(call my-dir)
# from Makefile
LIBGLCPP_SOURCES = \
glcpp/glcpp-lex.c \
glcpp/glcpp-parse.c \
glcpp/pp.c
C_SOURCES = \
strtod.c \
ralloc.c \
$(LIBGLCPP_SOURCES)
CXX_SOURCES = \
ast_expr.cpp \
ast_function.cpp \
ast_to_hir.cpp \
ast_type.cpp \
glsl_lexer.cpp \
glsl_parser.cpp \
glsl_parser_extras.cpp \
glsl_types.cpp \
glsl_symbol_table.cpp \
hir_field_selection.cpp \
ir_basic_block.cpp \
ir_clone.cpp \
ir_constant_expression.cpp \
ir.cpp \
ir_expression_flattening.cpp \
ir_function_can_inline.cpp \
ir_function.cpp \
ir_hierarchical_visitor.cpp \
ir_hv_accept.cpp \
ir_import_prototypes.cpp \
ir_print_visitor.cpp \
ir_reader.cpp \
ir_rvalue_visitor.cpp \
ir_set_program_inouts.cpp \
ir_validate.cpp \
ir_variable.cpp \
ir_variable_refcount.cpp \
linker.cpp \
link_functions.cpp \
loop_analysis.cpp \
loop_controls.cpp \
loop_unroll.cpp \
lower_discard.cpp \
lower_if_to_cond_assign.cpp \
lower_instructions.cpp \
lower_jumps.cpp \
lower_mat_op_to_vec.cpp \
lower_noise.cpp \
lower_texture_projection.cpp \
lower_variable_index_to_cond_assign.cpp \
lower_vec_index_to_cond_assign.cpp \
lower_vec_index_to_swizzle.cpp \
lower_vector.cpp \
opt_algebraic.cpp \
opt_constant_folding.cpp \
opt_constant_propagation.cpp \
opt_constant_variable.cpp \
opt_copy_propagation.cpp \
opt_copy_propagation_elements.cpp \
opt_dead_code.cpp \
opt_dead_code_local.cpp \
opt_dead_functions.cpp \
opt_discard_simplification.cpp \
opt_function_inlining.cpp \
opt_if_simplification.cpp \
opt_noop_swizzle.cpp \
opt_redundant_jumps.cpp \
opt_structure_splitting.cpp \
opt_swizzle_swizzle.cpp \
opt_tree_grafting.cpp \
s_expression.cpp
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(C_SOURCES) \
$(CXX_SOURCES) \
builtin_function.cpp
LOCAL_CFLAGS := \
-DPTHREADS \
-fvisibility=hidden \
-Wno-sign-compare \
-Wno-error=non-virtual-dtor \
-Wno-non-virtual-dtor
LOCAL_C_INCLUDES := \
external/mesa/include \
external/mesa/src/mapi \
external/mesa/src/mesa
LOCAL_MODULE := libmesa_glsl
include $(BUILD_STATIC_LIBRARY)

15232
src/glsl/builtin_function.cpp Normal file

File diff suppressed because one or more lines are too long

2627
src/glsl/glcpp/glcpp-lex.c Normal file

File diff suppressed because it is too large Load Diff

4214
src/glsl/glcpp/glcpp-parse.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,101 @@
/* A Bison parser, made by GNU Bison 2.4.1. */
/* Skeleton interface for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
COMMA_FINAL = 258,
DEFINED = 259,
ELIF_EXPANDED = 260,
HASH = 261,
HASH_DEFINE_FUNC = 262,
HASH_DEFINE_OBJ = 263,
HASH_ELIF = 264,
HASH_ELSE = 265,
HASH_ENDIF = 266,
HASH_IF = 267,
HASH_IFDEF = 268,
HASH_IFNDEF = 269,
HASH_UNDEF = 270,
HASH_VERSION = 271,
IDENTIFIER = 272,
IF_EXPANDED = 273,
INTEGER = 274,
INTEGER_STRING = 275,
NEWLINE = 276,
OTHER = 277,
PLACEHOLDER = 278,
SPACE = 279,
PASTE = 280,
OR = 281,
AND = 282,
NOT_EQUAL = 283,
EQUAL = 284,
GREATER_OR_EQUAL = 285,
LESS_OR_EQUAL = 286,
RIGHT_SHIFT = 287,
LEFT_SHIFT = 288,
UNARY = 289
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE
{
int first_line;
int first_column;
int last_line;
int last_column;
} YYLTYPE;
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif

3740
src/glsl/glsl_lexer.cpp Normal file

File diff suppressed because it is too large Load Diff

5448
src/glsl/glsl_parser.cpp Normal file

File diff suppressed because it is too large Load Diff

301
src/glsl/glsl_parser.h Normal file
View File

@@ -0,0 +1,301 @@
/* A Bison parser, made by GNU Bison 2.4.1. */
/* Skeleton interface for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
ATTRIBUTE = 258,
CONST_TOK = 259,
BOOL_TOK = 260,
FLOAT_TOK = 261,
INT_TOK = 262,
UINT_TOK = 263,
BREAK = 264,
CONTINUE = 265,
DO = 266,
ELSE = 267,
FOR = 268,
IF = 269,
DISCARD = 270,
RETURN = 271,
SWITCH = 272,
CASE = 273,
DEFAULT = 274,
BVEC2 = 275,
BVEC3 = 276,
BVEC4 = 277,
IVEC2 = 278,
IVEC3 = 279,
IVEC4 = 280,
UVEC2 = 281,
UVEC3 = 282,
UVEC4 = 283,
VEC2 = 284,
VEC3 = 285,
VEC4 = 286,
CENTROID = 287,
IN_TOK = 288,
OUT_TOK = 289,
INOUT_TOK = 290,
UNIFORM = 291,
VARYING = 292,
NOPERSPECTIVE = 293,
FLAT = 294,
SMOOTH = 295,
MAT2X2 = 296,
MAT2X3 = 297,
MAT2X4 = 298,
MAT3X2 = 299,
MAT3X3 = 300,
MAT3X4 = 301,
MAT4X2 = 302,
MAT4X3 = 303,
MAT4X4 = 304,
SAMPLER1D = 305,
SAMPLER2D = 306,
SAMPLER3D = 307,
SAMPLERCUBE = 308,
SAMPLER1DSHADOW = 309,
SAMPLER2DSHADOW = 310,
SAMPLERCUBESHADOW = 311,
SAMPLER1DARRAY = 312,
SAMPLER2DARRAY = 313,
SAMPLER1DARRAYSHADOW = 314,
SAMPLER2DARRAYSHADOW = 315,
ISAMPLER1D = 316,
ISAMPLER2D = 317,
ISAMPLER3D = 318,
ISAMPLERCUBE = 319,
ISAMPLER1DARRAY = 320,
ISAMPLER2DARRAY = 321,
USAMPLER1D = 322,
USAMPLER2D = 323,
USAMPLER3D = 324,
USAMPLERCUBE = 325,
USAMPLER1DARRAY = 326,
USAMPLER2DARRAY = 327,
STRUCT = 328,
VOID_TOK = 329,
WHILE = 330,
IDENTIFIER = 331,
TYPE_IDENTIFIER = 332,
NEW_IDENTIFIER = 333,
FLOATCONSTANT = 334,
INTCONSTANT = 335,
UINTCONSTANT = 336,
BOOLCONSTANT = 337,
FIELD_SELECTION = 338,
LEFT_OP = 339,
RIGHT_OP = 340,
INC_OP = 341,
DEC_OP = 342,
LE_OP = 343,
GE_OP = 344,
EQ_OP = 345,
NE_OP = 346,
AND_OP = 347,
OR_OP = 348,
XOR_OP = 349,
MUL_ASSIGN = 350,
DIV_ASSIGN = 351,
ADD_ASSIGN = 352,
MOD_ASSIGN = 353,
LEFT_ASSIGN = 354,
RIGHT_ASSIGN = 355,
AND_ASSIGN = 356,
XOR_ASSIGN = 357,
OR_ASSIGN = 358,
SUB_ASSIGN = 359,
INVARIANT = 360,
LOWP = 361,
MEDIUMP = 362,
HIGHP = 363,
SUPERP = 364,
PRECISION = 365,
VERSION = 366,
EXTENSION = 367,
LINE = 368,
COLON = 369,
EOL = 370,
INTERFACE = 371,
OUTPUT = 372,
PRAGMA_DEBUG_ON = 373,
PRAGMA_DEBUG_OFF = 374,
PRAGMA_OPTIMIZE_ON = 375,
PRAGMA_OPTIMIZE_OFF = 376,
PRAGMA_INVARIANT_ALL = 377,
LAYOUT_TOK = 378,
ASM = 379,
CLASS = 380,
UNION = 381,
ENUM = 382,
TYPEDEF = 383,
TEMPLATE = 384,
THIS = 385,
PACKED_TOK = 386,
GOTO = 387,
INLINE_TOK = 388,
NOINLINE = 389,
VOLATILE = 390,
PUBLIC_TOK = 391,
STATIC = 392,
EXTERN = 393,
EXTERNAL = 394,
LONG_TOK = 395,
SHORT_TOK = 396,
DOUBLE_TOK = 397,
HALF = 398,
FIXED_TOK = 399,
UNSIGNED = 400,
INPUT_TOK = 401,
OUPTUT = 402,
HVEC2 = 403,
HVEC3 = 404,
HVEC4 = 405,
DVEC2 = 406,
DVEC3 = 407,
DVEC4 = 408,
FVEC2 = 409,
FVEC3 = 410,
FVEC4 = 411,
SAMPLER2DRECT = 412,
SAMPLER3DRECT = 413,
SAMPLER2DRECTSHADOW = 414,
SIZEOF = 415,
CAST = 416,
NAMESPACE = 417,
USING = 418,
ERROR_TOK = 419,
COMMON = 420,
PARTITION = 421,
ACTIVE = 422,
SAMPLERBUFFER = 423,
FILTER = 424,
IMAGE1D = 425,
IMAGE2D = 426,
IMAGE3D = 427,
IMAGECUBE = 428,
IMAGE1DARRAY = 429,
IMAGE2DARRAY = 430,
IIMAGE1D = 431,
IIMAGE2D = 432,
IIMAGE3D = 433,
IIMAGECUBE = 434,
IIMAGE1DARRAY = 435,
IIMAGE2DARRAY = 436,
UIMAGE1D = 437,
UIMAGE2D = 438,
UIMAGE3D = 439,
UIMAGECUBE = 440,
UIMAGE1DARRAY = 441,
UIMAGE2DARRAY = 442,
IMAGE1DSHADOW = 443,
IMAGE2DSHADOW = 444,
IMAGEBUFFER = 445,
IIMAGEBUFFER = 446,
UIMAGEBUFFER = 447,
IMAGE1DARRAYSHADOW = 448,
IMAGE2DARRAYSHADOW = 449,
ROW_MAJOR = 450
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
/* Line 1676 of yacc.c */
#line 52 "glsl_parser.yy"
int n;
float real;
char *identifier;
struct ast_type_qualifier type_qualifier;
ast_node *node;
ast_type_specifier *type_specifier;
ast_fully_specified_type *fully_specified_type;
ast_function *function;
ast_parameter_declarator *parameter_declarator;
ast_function_definition *function_definition;
ast_compound_statement *compound_statement;
ast_expression *expression;
ast_declarator_list *declarator_list;
ast_struct_specifier *struct_specifier;
ast_declaration *declaration;
struct {
ast_node *cond;
ast_expression *rest;
} for_rest_statement;
struct {
ast_node *then_statement;
ast_node *else_statement;
} selection_rest_statement;
/* Line 1676 of yacc.c */
#line 279 "glsl_parser.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE
{
int first_line;
int first_column;
int last_line;
int last_column;
} YYLTYPE;
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif

View File

@@ -46,6 +46,10 @@
#endif
#endif
#ifdef ANDROID
#define SIZE_MAX UINT32_MAX
#endif
#define CANARY 0x5A1106
struct ralloc_header

47
src/gralloc/Android.mk Normal file
View File

@@ -0,0 +1,47 @@
# Android.mk for gralloc
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
gralloc_gem.c \
gralloc_kms.c \
gralloc_mod.c
LOCAL_C_INCLUDES := \
external/drm \
external/drm/include/drm
LOCAL_SHARED_LIBRARIES := \
libdrm \
liblog \
libcutils \
libGLESv1_CM
ifeq ($(strip $(MESA_BUILD_INTEL)),true)
LOCAL_SRC_FILES += gralloc_gem_intel.c
LOCAL_C_INCLUDES += external/drm/intel
LOCAL_CFLAGS += -DENABLE_INTEL
LOCAL_SHARED_LIBRARIES += libdrm_intel
endif # MESA_BUILD_INTEL
ifeq ($(strip $(MESA_BUILD_RADEON)),true)
LOCAL_SRC_FILES += gralloc_gem_radeon.c
LOCAL_C_INCLUDES += external/drm/radeon
LOCAL_CFLAGS += -DENABLE_RADEON
LOCAL_SHARED_LIBRARIES += libdrm_radeon
endif # MESA_BUILD_INTEL
# this is broken
ifeq ($(strip $(MESA_BUILD_VMWGFX)),true)
LOCAL_SRC_FILES += gralloc_gem_pipe.c
LOCAL_C_INCLUDES += \
external/mesa/src/gallium/include \
external/mesa/src/gallium/auxiliary
LOCAL_CFLAGS += -DENABLE_VMWGFX
endif # MESA_BUILD_VMWGFX
LOCAL_MODULE := gralloc.mesa
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
include $(BUILD_SHARED_LIBRARY)

186
src/gralloc/gralloc_gem.c Normal file
View File

@@ -0,0 +1,186 @@
#define LOG_TAG "GRALLOC-GEM"
#include <cutils/log.h>
#include <cutils/atomic.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "gralloc_mod.h"
#include "gralloc_gem.h"
#define unlikely(x) __builtin_expect(!!(x), 0)
#define DRM_PATH "/dev/dri/card0"
static int32_t drm_gem_pid = 0;
static int
drm_gem_get_pid(void)
{
if (unlikely(!drm_gem_pid))
android_atomic_write((int32_t) getpid(), &drm_gem_pid);
return drm_gem_pid;
}
static int
drm_gem_init_locked(struct drm_module_t *drm)
{
int ret;
if (drm->fd >= 0)
return 0;
drm->fd = open(DRM_PATH, O_RDWR);
if (drm->fd < 0) {
LOGE("failed to open %s", DRM_PATH);
return -EINVAL;
}
return 0;
}
int
drm_gem_init(struct drm_module_t *drm)
{
int ret;
pthread_mutex_lock(&drm->mutex);
ret = drm_gem_init_locked(drm);
pthread_mutex_unlock(&drm->mutex);
return ret;
}
int
drm_gem_get_magic(struct drm_module_t *drm, int32_t *magic)
{
int ret;
ret = drm_gem_init(drm);
if (ret)
return ret;
return drmGetMagic(drm->fd, (drm_magic_t *) magic);
}
int
drm_gem_auth_magic(struct drm_module_t *drm, int32_t magic)
{
int ret;
ret = drm_gem_init(drm);
if (ret)
return ret;
return drmAuthMagic(drm->fd, (drm_magic_t) magic);
}
struct drm_bo_t *
drm_gem_create_bo(int width, int height, int format, int usage)
{
struct drm_bo_t *bo;
bo = calloc(1, sizeof(*bo));
if (!bo)
return NULL;
bo->base.version = sizeof(bo->base);
bo->base.numInts = DRM_HANDLE_NUM_INTS;
bo->base.numFds = DRM_HANDLE_NUM_FDS;
bo->magic = DRM_HANDLE_MAGIC;
bo->width = width;
bo->height = height;
bo->format = format;
bo->usage = usage;
bo->pid = drm_gem_get_pid();
return bo;
}
struct drm_bo_t *
drm_gem_validate(buffer_handle_t handle)
{
struct drm_bo_t *bo = drm_gem_get(handle);
if (bo && unlikely(bo->pid != drm_gem_pid)) {
bo->pid = drm_gem_get_pid();
bo->fb_handle = 0;
bo->fb_id = 0;
bo->data = 0;
}
return bo;
}
static const struct drm_gem_drv *
get_drv_from_fd(int fd)
{
const struct drm_gem_drv *drv = NULL;
drmVersionPtr version;
version = drmGetVersion(fd);
if (!version) {
LOGE("invalid DRM fd");
return NULL;
}
if (version->name) {
#ifdef ENABLE_INTEL
if (!drv && !strcmp(version->name, "i915"))
drv = &drm_gem_drv_intel;
#endif
#ifdef ENABLE_RADEON
if (!drv && !strcmp(version->name, "radeon"))
drv = &drm_gem_drv_radeon;
#endif
#ifdef ENABLE_VMWGFX
if (!drv && !strcmp(version->name, "vmwgfx"))
drv = &drm_gem_drv_pipe;
#endif
}
if (!drv)
LOGE("unknown driver: %s", (version->name) ? version->name : "NULL");
drmFreeVersion(version);
return drv;
}
static int
drm_gem_drv_init_locked(struct drm_module_t *drm)
{
const struct drm_gem_drv *drv;
int ret;
if (drm->gem)
return 0;
drv = get_drv_from_fd(drm->fd);
if (!drv)
return -EINVAL;
ret = drv->init(drm);
if (!ret)
drm->drv = (void *) drv;
return ret;
}
int
drm_gem_drv_init(struct drm_module_t *drm)
{
int ret;
pthread_mutex_lock(&drm->mutex);
ret = drm_gem_drv_init_locked(drm);
pthread_mutex_unlock(&drm->mutex);
return ret;
}

111
src/gralloc/gralloc_gem.h Normal file
View File

@@ -0,0 +1,111 @@
#ifndef _GRALLOC_GEM_H_
#define _GRALLOC_GEM_H_
#include <cutils/native_handle.h>
#include "gralloc_mod.h"
struct drm_bo_t {
native_handle_t base;
#define DRM_HANDLE_MAGIC 0x12345678
#define DRM_HANDLE_NUM_INTS 11
#define DRM_HANDLE_NUM_FDS 0
int magic;
int width;
int height;
int format;
int usage;
int name;
int stride;
/* these fields are undefined until validated */
int pid;
int fb_handle;
int fb_id;
int data; /* pointer as int? 32-bit only! */
};
int
drm_gem_init(struct drm_module_t *drm);
int
drm_gem_get_magic(struct drm_module_t *drm, int32_t *magic);
int
drm_gem_auth_magic(struct drm_module_t *drm, int32_t magic);
static inline struct drm_bo_t *
drm_gem_get(buffer_handle_t handle)
{
struct drm_bo_t *bo = (struct drm_bo_t *) handle;
if (bo->base.version != sizeof(bo->base) ||
bo->base.numInts != DRM_HANDLE_NUM_INTS ||
bo->base.numFds != DRM_HANDLE_NUM_FDS ||
bo->magic != DRM_HANDLE_MAGIC)
bo = NULL;
return bo;
}
struct drm_bo_t *
drm_gem_validate(buffer_handle_t handle);
struct drm_bo_t *
drm_gem_create_bo(int width, int height, int format, int usage);
int
drm_gem_drv_init(struct drm_module_t *drm);
struct drm_gem_drv {
int (*init)(struct drm_module_t *drm);
struct drm_bo_t *(*alloc)(struct drm_module_t *drm, int width, int height,
int format, int usage, int *stride);
void (*free)(struct drm_module_t *drm, struct drm_bo_t *bo);
int (*map)(struct drm_module_t *drm, struct drm_bo_t *bo,
int x, int y, int w, int h, int enable_write, void **addr);
void (*unmap)(struct drm_module_t *drm, struct drm_bo_t *bo);
};
extern const struct drm_gem_drv drm_gem_drv_intel;
extern const struct drm_gem_drv drm_gem_drv_radeon;
extern const struct drm_gem_drv drm_gem_drv_pipe;
static inline struct drm_bo_t *
drm_gem_drv_alloc(struct drm_module_t *drm, int width, int height,
int format, int usage, int *stride)
{
const struct drm_gem_drv *drv = (const struct drm_gem_drv *) drm->drv;
return drv->alloc(drm, width, height, format, usage, stride);
}
static inline void
drm_gem_drv_free(struct drm_module_t *drm, struct drm_bo_t *bo)
{
const struct drm_gem_drv *drv = (const struct drm_gem_drv *) drm->drv;
drv->free(drm, bo);
}
static inline int
drm_gem_drv_map(struct drm_module_t *drm, struct drm_bo_t *bo,
int x, int y, int w, int h, int enable_write, void **addr)
{
const struct drm_gem_drv *drv = (const struct drm_gem_drv *) drm->drv;
return drv->map(drm, bo, x, y, w, h, enable_write, addr);
}
static inline void
drm_gem_drv_unmap(struct drm_module_t *drm, struct drm_bo_t *bo)
{
const struct drm_gem_drv *drv = (const struct drm_gem_drv *) drm->drv;
drv->unmap(drm, bo);
}
#endif /* _GRALLOC_GEM_H_ */

View File

@@ -0,0 +1,205 @@
#define LOG_TAG "GRALLOC-I915"
#include <cutils/log.h>
#include <stdlib.h>
#include <errno.h>
#include <drm.h>
#include <intel_bufmgr.h>
#include <i915_drm.h>
#include "gralloc_mod.h"
#include "gralloc_gem.h"
static void
drm_gem_intel_init_features(struct drm_module_t *drm)
{
struct drm_i915_getparam gp;
drm_intel_bufmgr *bufmgr = (drm_intel_bufmgr *) drm->gem;
drm->mode_dirty_fb = 0;
memset(&gp, 0, sizeof(gp));
gp.param = I915_PARAM_HAS_PAGEFLIPPING;
gp.value = &drm->mode_page_flip;
if (!drmCommandWriteRead(drm->fd, DRM_I915_GETPARAM, &gp, sizeof(gp)))
drm->mode_page_flip = *gp.value;
else
drm->mode_page_flip = 0;
drm->mode_page_flip_blocking = 0;
if (drm->resources) {
int pipe;
pipe = drm_intel_get_pipe_from_crtc_id(bufmgr, drm->crtc_id);
drm->swap_interval = (pipe >= 0) ? 1 : 0;
drm->vblank_secondary = (pipe > 0);
}
else {
drm->swap_interval = 0;
}
/* XXX there is a bug in the kernel module */
drm->mode_page_flip = 0;
}
static int
drm_gem_intel_init(struct drm_module_t *drm)
{
drm->gem = (void *) drm_intel_bufmgr_gem_init(drm->fd, 16 * 1024);
if (!drm->gem) {
LOGE("failed to create buffer manager");
return -ENOMEM;
}
drm_gem_intel_init_features(drm);
return 0;
}
static uint32_t
drm_gem_get_tiling(struct drm_bo_t *bo)
{
uint32_t tiling = I915_TILING_NONE;
if (bo->usage & GRALLOC_USAGE_SW_READ_OFTEN)
return tiling;
if (bo->usage & GRALLOC_USAGE_HW_FB ||
bo->usage & GRALLOC_USAGE_HW_TEXTURE) {
if (bo->width >= 64)
tiling = I915_TILING_X;
}
return tiling;
}
static struct drm_bo_t *
drm_gem_intel_alloc(struct drm_module_t *drm, int width, int height,
int format, int usage, int *stride)
{
drm_intel_bufmgr *bufmgr = (drm_intel_bufmgr *) drm->gem;
struct drm_bo_t *bo;
drm_intel_bo *ibo;
int aligned_width, aligned_height, cpp;
unsigned long pitch, flags;
uint32_t tiling;
const char *name;
bo = drm_gem_create_bo(width, height, format, usage);
if (!bo)
return NULL;
cpp = drm_mod_get_bpp(format);
if (!cpp) {
LOGE("unrecognized format 0x%x", format);
free(bo);
return NULL;
}
if (usage & GRALLOC_USAGE_HW_FB) {
name = "gralloc-fb";
aligned_width = (width + 63) & ~63;
}
if (usage & GRALLOC_USAGE_HW_TEXTURE) {
name = "gralloc-texture";
aligned_width = (width + 3) & ~3;
aligned_height = (height + 1) & ~1;
}
else {
name = "gralloc-buf";
aligned_width = width;
aligned_height = height;
}
tiling = drm_gem_get_tiling(bo);
flags = 0x0;
if (bo->usage & (GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_FB))
flags |= BO_ALLOC_FOR_RENDER;
ibo = drm_intel_bo_alloc_tiled(bufmgr, name,
aligned_width, aligned_height, cpp, &tiling, &pitch, flags);
if (!ibo) {
LOGE("failed to allocate ibo %dx%dx%d", width, height, cpp);
free(bo);
return NULL;
}
if (bo->usage & GRALLOC_USAGE_HW_FB) {
drm_intel_bo_disable_reuse(ibo);
bo->stride = pitch;
bo->fb_handle = ibo->handle;
}
if (drm_intel_bo_flink(ibo, (uint32_t *) &bo->name)) {
LOGE("failed to flink ibo");
drm_intel_bo_unreference(ibo);
free(bo);
return NULL;
}
bo->data = (int) ibo;
*stride = pitch;
return bo;
}
static void
drm_gem_intel_free(struct drm_module_t *drm, struct drm_bo_t *bo)
{
drm_intel_bo_unreference((drm_intel_bo *) bo->data);
free(bo);
}
static int
drm_gem_intel_map(struct drm_module_t *drm, struct drm_bo_t *bo,
int x, int y, int w, int h, int enable_write, void **addr)
{
drm_intel_bo *ibo = (drm_intel_bo *) bo->data;
int err;
if (!ibo) {
drm_intel_bufmgr *bufmgr = (drm_intel_bufmgr *) drm->gem;
ibo = drm_intel_bo_gem_create_from_name(bufmgr, "gralloc-r", bo->name);
if (!ibo) {
LOGE("failed to create ibo from name %u", bo->name);
return -EINVAL;
}
bo->data = (int) ibo;
}
if ((bo->usage & GRALLOC_USAGE_HW_FB) ||
drm_gem_get_tiling(bo) != I915_TILING_NONE)
err = drm_intel_gem_bo_map_gtt(ibo);
else
err = drm_intel_bo_map(ibo, enable_write);
if (!err)
*addr = ibo->virtual;
return err;
}
static void
drm_gem_intel_unmap(struct drm_module_t *drm, struct drm_bo_t *bo)
{
drm_intel_bo *ibo = (drm_intel_bo *) bo->data;
if ((bo->usage & GRALLOC_USAGE_HW_FB) ||
drm_gem_get_tiling(bo) != I915_TILING_NONE)
drm_intel_gem_bo_unmap_gtt(ibo);
else
drm_intel_bo_unmap(ibo);
}
const struct drm_gem_drv drm_gem_drv_intel = {
.init = drm_gem_intel_init,
.alloc = drm_gem_intel_alloc,
.free = drm_gem_intel_free,
.map = drm_gem_intel_map,
.unmap = drm_gem_intel_unmap,
};

View File

@@ -0,0 +1,327 @@
#define LOG_TAG "GRALLOC-PIPE"
#include <cutils/log.h>
#include <errno.h>
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#include "state_tracker/drm_driver.h"
#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "gralloc_mod.h"
#include "gralloc_gem.h"
struct drm_pipe_manager {
pthread_mutex_t mutex;
struct pipe_screen *screen;
struct pipe_context *context;
};
struct drm_pipe_buffer {
struct winsys_handle winsys;
uint32_t fb_handle;
struct pipe_resource *resource;
struct pipe_transfer *transfer;
};
static void
drm_gem_pipe_init_features(struct drm_module_t *drm)
{
drm->mode_dirty_fb = 0;
drm->mode_page_flip = 0;
drm->mode_page_flip_blocking = 0;
if (strcmp(driver_descriptor.driver_name, "vmwgfx") == 0)
drm->mode_dirty_fb = 1;
drm->swap_interval = 0;
}
static int
drm_gem_pipe_init(struct drm_module_t *drm)
{
struct drm_pipe_manager *pm;
pm = CALLOC(1, sizeof(*pm));
if (!pm)
return -ENOMEM;
pthread_mutex_init(&pm->mutex, NULL);
pm->screen = driver_descriptor.create_screen(drm->fd);
if (!pm->screen) {
LOGE("failed to create pipe screen");
FREE(pm);
return -EINVAL;
}
drm->gem = (void *) pm;
drm_gem_pipe_init_features(drm);
return 0;
}
static enum pipe_format
get_pipe_format(int format)
{
enum pipe_format fmt;
switch (format) {
case HAL_PIXEL_FORMAT_RGBA_8888:
fmt = PIPE_FORMAT_R8G8B8A8_UNORM;
break;
case HAL_PIXEL_FORMAT_RGBX_8888:
fmt = PIPE_FORMAT_R8G8B8X8_UNORM;
break;
case HAL_PIXEL_FORMAT_RGB_888:
fmt = PIPE_FORMAT_R8G8B8_UNORM;
break;
case HAL_PIXEL_FORMAT_RGB_565:
fmt = PIPE_FORMAT_B5G6R5_UNORM;
break;
case HAL_PIXEL_FORMAT_BGRA_8888:
fmt = PIPE_FORMAT_B8G8R8A8_UNORM;
break;
case HAL_PIXEL_FORMAT_RGBA_5551:
case HAL_PIXEL_FORMAT_RGBA_4444:
default:
fmt = PIPE_FORMAT_NONE;
break;
}
return fmt;
}
static unsigned
get_pipe_bind(int usage)
{
unsigned bind = PIPE_BIND_SHARED;
if (usage & GRALLOC_USAGE_SW_READ_MASK)
bind |= PIPE_BIND_TRANSFER_READ;
if (usage & GRALLOC_USAGE_SW_WRITE_MASK)
bind |= PIPE_BIND_TRANSFER_WRITE;
if (usage & GRALLOC_USAGE_HW_TEXTURE)
bind |= PIPE_BIND_SAMPLER_VIEW;
if (usage & GRALLOC_USAGE_HW_RENDER)
bind |= PIPE_BIND_RENDER_TARGET;
if (usage & GRALLOC_USAGE_HW_FB) {
bind |= PIPE_BIND_RENDER_TARGET;
bind |= PIPE_BIND_SCANOUT;
}
return bind;
}
static struct drm_pipe_buffer *
get_pipe_buffer(struct drm_pipe_manager *pm, int width, int height,
int format, int usage, struct winsys_handle *winsys)
{
struct drm_pipe_buffer *buf;
struct pipe_resource templ;
memset(&templ, 0, sizeof(templ));
templ.format = get_pipe_format(format);
templ.bind = get_pipe_bind(usage);
templ.target = PIPE_TEXTURE_2D;
if (templ.format == PIPE_FORMAT_NONE ||
!pm->screen->is_format_supported(pm->screen, templ.format,
templ.target, 0, templ.bind)) {
LOGE("unsupported format 0x%x", format);
return NULL;
}
buf = CALLOC(1, sizeof(*buf));
if (!buf)
return NULL;
templ.width0 = width;
templ.height0 = height;
templ.depth0 = 1;
if (winsys) {
buf->resource = pm->screen->resource_from_handle(pm->screen,
&templ, winsys);
if (!buf->resource)
goto fail;
buf->winsys = *winsys;
}
else {
buf->resource = pm->screen->resource_create(pm->screen, &templ);
if (!buf->resource)
goto fail;
buf->winsys.type = DRM_API_HANDLE_TYPE_SHARED;
if (!pm->screen->resource_get_handle(pm->screen, buf->resource, &buf->winsys))
goto fail;
}
/* need the gem handle for fb */
if (usage & GRALLOC_USAGE_HW_FB) {
struct winsys_handle tmp;
memset(&tmp, 0, sizeof(tmp));
tmp.type = DRM_API_HANDLE_TYPE_KMS;
if (!pm->screen->resource_get_handle(pm->screen, buf->resource, &tmp))
goto fail;
buf->fb_handle = tmp.handle;
}
return buf;
fail:
LOGE("failed to allocate pipe buffer");
if (buf->resource)
pipe_resource_reference(&buf->resource, NULL);
FREE(buf);
return NULL;
}
static struct drm_bo_t *
drm_gem_pipe_alloc(struct drm_module_t *drm, int width, int height,
int format, int usage, int *stride)
{
struct drm_pipe_manager *pm = (struct drm_pipe_manager *) drm->gem;
struct drm_pipe_buffer *buf;
struct drm_bo_t *bo;
struct pipe_resource templ;
bo = drm_gem_create_bo(width, height, format, usage);
if (!bo)
return NULL;
pthread_mutex_lock(&pm->mutex);
buf = get_pipe_buffer(pm, width, height, format, usage, NULL);
pthread_mutex_unlock(&pm->mutex);
if (buf) {
bo->name = (int) buf->winsys.handle;
bo->stride = (int) buf->winsys.stride;
bo->fb_handle = buf->fb_handle;
bo->data = (int) buf;
*stride = bo->stride;
}
else {
free(bo);
bo = NULL;
}
return bo;
}
static void
drm_gem_pipe_free(struct drm_module_t *drm, struct drm_bo_t *bo)
{
struct drm_pipe_manager *pm = (struct drm_pipe_manager *) drm->gem;
struct drm_pipe_buffer *buf = (struct drm_pipe_buffer *) bo->data;
pthread_mutex_lock(&pm->mutex);
if (buf->transfer)
pipe_transfer_destroy(pm->context, buf->transfer);
pipe_resource_reference(&buf->resource, NULL);
pthread_mutex_unlock(&pm->mutex);
FREE(buf);
free(bo);
}
static int
drm_gem_pipe_map(struct drm_module_t *drm, struct drm_bo_t *bo,
int x, int y, int w, int h, int enable_write, void **addr)
{
struct drm_pipe_manager *pm = (struct drm_pipe_manager *) drm->gem;
struct drm_pipe_buffer *buf = (struct drm_pipe_buffer *) bo->data;
enum pipe_transfer_usage usage = 0;
int ret = 0;
pthread_mutex_lock(&pm->mutex);
/* need a context to get transfer */
if (!pm->context) {
pm->context = pm->screen->context_create(pm->screen, NULL);
if (!pm->context) {
LOGE("failed to create pipe context");
ret = -ENOMEM;
}
}
/* the bo was allocated by another process */
if (!buf && !ret) {
struct winsys_handle winsys;
memset(&winsys, 0, sizeof(winsys));
winsys.type = DRM_API_HANDLE_TYPE_SHARED;
winsys.handle = bo->name;
winsys.stride = bo->stride;
buf = get_pipe_buffer(pm, bo->width, bo->height,
bo->format, bo->usage, &winsys);
if (!buf) {
LOGE("failed to create pipe buffer from name %u", bo->name);
ret = -ENOMEM;
}
bo->data = (int) buf;
}
if (buf) {
usage = PIPE_TRANSFER_READ;
if (enable_write)
usage |= PIPE_TRANSFER_WRITE;
assert(!buf->transfer);
/*
* ignore x, y, w and h so that returned addr points at the start of the
* buffer
*/
buf->transfer = pipe_get_transfer(pm->context, buf->resource,
0, 0, usage, 0, 0, bo->width, bo->height);
if (buf->transfer)
*addr = pipe_transfer_map(pm->context, buf->transfer);
else
ret = -ENOMEM;
}
pthread_mutex_unlock(&pm->mutex);
return ret;
}
static void
drm_gem_pipe_unmap(struct drm_module_t *drm, struct drm_bo_t *bo)
{
struct drm_pipe_manager *pm = (struct drm_pipe_manager *) drm->gem;
struct drm_pipe_buffer *buf = (struct drm_pipe_buffer *) bo->data;
pthread_mutex_lock(&pm->mutex);
assert(buf && buf->transfer);
pipe_transfer_unmap(pm->context, buf->transfer);
pipe_transfer_destroy(pm->context, buf->transfer);
buf->transfer = NULL;
pm->context->flush(pm->context, NULL);
pthread_mutex_unlock(&pm->mutex);
}
const struct drm_gem_drv drm_gem_drv_pipe = {
.init = drm_gem_pipe_init,
.alloc = drm_gem_pipe_alloc,
.free = drm_gem_pipe_free,
.map = drm_gem_pipe_map,
.unmap = drm_gem_pipe_unmap,
};

View File

@@ -0,0 +1,362 @@
/*
* Based on xf86-video-ati, which is
*
* Copyright © 2009 Red Hat, 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 (including the next
* paragraph) 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.
*
* Authors:
* Dave Airlie <airlied@redhat.com>
*/
/*
* XXX This driver assumes evergreen. It works, but is slow and has sync
* issues.
*/
#define LOG_TAG "GRALLOC-RADEON"
#include <cutils/log.h>
#include <stdlib.h>
#include <errno.h>
#include <drm.h>
#include <radeon_drm.h>
#include <radeon_bo_gem.h>
#include <radeon_bo.h>
#include "gralloc_mod.h"
#include "gralloc_gem.h"
#define RADEON_GPU_PAGE_SIZE 4096
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define ALIGN(val, align) (((val) + (align) - 1) & ~((align) - 1))
struct radeon_info {
struct drm_module_t *drm;
struct radeon_bo_manager *bufmgr;
uint32_t tile_config;
int num_channels;
int num_banks;
int group_bytes;
/* r6xx+ tile config */
int have_tiling_info;
int allow_color_tiling;
};
static int
eg_init_tile_config(struct radeon_info *info)
{
struct drm_radeon_info ginfo;
uint32_t val;
int ret;
memset(&ginfo, 0, sizeof(ginfo));
ginfo.request = RADEON_INFO_TILING_CONFIG;
ginfo.value = (long) &val;
ret = drmCommandWriteRead(info->drm->fd, DRM_RADEON_INFO, &ginfo, sizeof(ginfo));
if (ret)
return ret;
info->tile_config = val;
switch (info->tile_config & 0xf) {
case 0:
info->num_channels = 1;
break;
case 1:
info->num_channels = 2;
break;
case 2:
info->num_channels = 4;
break;
case 3:
info->num_channels = 8;
break;
default:
return -EINVAL;
break;
}
info->num_banks = (info->tile_config & 0xf0) >> 4;
switch ((info->tile_config & 0xf00) >> 8) {
case 0:
info->group_bytes = 256;
break;
case 1:
info->group_bytes = 512;
break;
default:
return -EINVAL;
break;
}
info->have_tiling_info = 1;
info->allow_color_tiling = 0;
return 0;
}
/* returns pitch alignment in pixels */
static int
eg_get_pitch_align(struct radeon_info *info, int bpe, uint32_t tiling)
{
int pitch_align = 1;
if (tiling & RADEON_TILING_MACRO) {
/* general surface requirements */
pitch_align = MAX(info->num_banks,
(((info->group_bytes / 8) / bpe) * info->num_banks)) * 8;
/* further restrictions for scanout */
pitch_align = MAX(info->num_banks * 8, pitch_align);
} else if (tiling & RADEON_TILING_MICRO) {
/* general surface requirements */
pitch_align = MAX(8, (info->group_bytes / (8 * bpe)));
/* further restrictions for scanout */
pitch_align = MAX(info->group_bytes / bpe, pitch_align);
} else {
if (info->have_tiling_info)
/* linear aligned requirements */
pitch_align = MAX(64, info->group_bytes / bpe);
else
/* default to 512 elements if we don't know the real
* group size otherwise the kernel may reject the CS
* if the group sizes don't match as the pitch won't
* be aligned properly.
*/
pitch_align = 512;
}
return pitch_align;
}
/* returns height alignment in pixels */
static int
eg_get_height_align(struct radeon_info *info, uint32_t tiling)
{
int height_align = 1;
if (tiling & RADEON_TILING_MACRO)
height_align = info->num_channels * 8;
else if (tiling & RADEON_TILING_MICRO)
height_align = 8;
else
height_align = 8;
return height_align;
}
/* returns base alignment in bytes */
static int
eg_get_base_align(struct radeon_info *info, int bpe, uint32_t tiling)
{
int pixel_align = eg_get_pitch_align(info, bpe, tiling);
int height_align = eg_get_height_align(info, tiling);
int base_align = RADEON_GPU_PAGE_SIZE;
if (tiling & RADEON_TILING_MACRO) {
base_align = MAX(info->num_banks * info->num_channels * 8 * 8 * bpe,
pixel_align * bpe * height_align);
}
else {
if (info->have_tiling_info)
base_align = info->group_bytes;
else
/* default to 512 if we don't know the real
* group size otherwise the kernel may reject the CS
* if the group sizes don't match as the base won't
* be aligned properly.
*/
base_align = 512;
}
return base_align;
}
static void
drm_gem_radeon_init_features(struct drm_module_t *drm)
{
drm->mode_dirty_fb = 0;
drm->mode_page_flip = 1;
drm->mode_page_flip_blocking = 1;
drm->swap_interval = 1;
drm->vblank_secondary = 0;
}
static int
drm_gem_radeon_init(struct drm_module_t *drm)
{
struct radeon_info *info;
int ret;
info = calloc(1, sizeof(*info));
if (!info)
return -ENOMEM;
info->drm = drm;
info->bufmgr = radeon_bo_manager_gem_ctor(info->drm->fd);
if (!info->bufmgr) {
LOGE("failed to create buffer manager");
free(info);
return -ENOMEM;
}
drm->gem = (void *) info;
ret = eg_init_tile_config(info);
if (ret) {
radeon_bo_manager_gem_dtor(info->bufmgr);
free(info);
return ret;
}
drm_gem_radeon_init_features(drm);
return 0;
}
static uint32_t
drm_gem_get_tiling(struct drm_bo_t *bo)
{
return 0;
}
static struct drm_bo_t *
drm_gem_radeon_alloc(struct drm_module_t *drm, int width, int height,
int format, int usage, int *stride)
{
struct radeon_info *info = (struct radeon_info *) drm->gem;
struct drm_bo_t *bo;
struct radeon_bo *rbo;
int aligned_width, aligned_height, cpp;
int pitch, size, base_align;
uint32_t tiling, domain;
bo = drm_gem_create_bo(width, height, format, usage);
if (!bo)
return NULL;
cpp = drm_mod_get_bpp(format);
if (!cpp) {
LOGE("unrecognized format 0x%x", format);
free(bo);
return NULL;
}
tiling = drm_gem_get_tiling(bo);
domain = RADEON_GEM_DOMAIN_VRAM;
if (usage & (GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_HW_TEXTURE)) {
aligned_width = ALIGN(width, eg_get_pitch_align(info, cpp, tiling));
aligned_height = ALIGN(height, eg_get_height_align(info, tiling));
}
else {
aligned_width = width;
aligned_height = height;
}
if (!(usage & (GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_HW_RENDER)) &&
(usage & GRALLOC_USAGE_SW_READ_OFTEN))
domain = RADEON_GEM_DOMAIN_GTT;
pitch = aligned_width * cpp;
size = ALIGN(aligned_height * pitch, RADEON_GPU_PAGE_SIZE);
base_align = eg_get_base_align(info, cpp, tiling);
rbo = radeon_bo_open(info->bufmgr, 0, size, base_align, domain, 0);
if (!rbo) {
LOGE("failed to allocate rbo %dx%dx%d", width, height, cpp);
free(bo);
return NULL;
}
if (tiling)
radeon_bo_set_tiling(rbo, tiling, pitch);
if (bo->usage & GRALLOC_USAGE_HW_FB) {
bo->stride = pitch;
bo->fb_handle = rbo->handle;
}
if (radeon_gem_get_kernel_name(rbo, (uint32_t *) &bo->name)) {
LOGE("failed to flink rbo");
radeon_bo_unref(rbo);
free(bo);
return NULL;
}
bo->data = (int) rbo;
*stride = pitch;
return bo;
}
static void
drm_gem_radeon_free(struct drm_module_t *drm, struct drm_bo_t *bo)
{
radeon_bo_unref((struct radeon_bo *) bo->data);
free(bo);
}
static int
drm_gem_radeon_map(struct drm_module_t *drm, struct drm_bo_t *bo,
int x, int y, int w, int h, int enable_write, void **addr)
{
struct radeon_bo *rbo = (struct radeon_bo *) bo->data;
int err;
if (!rbo) {
struct radeon_info *info = (struct radeon_info *) drm->gem;
rbo = radeon_bo_open(info->bufmgr, bo->name, 0, 0, RADEON_GEM_DOMAIN_VRAM, 0);
if (!rbo) {
LOGE("failed to create rbo from name %u", bo->name);
return -EINVAL;
}
bo->data = (int) rbo;
}
err = radeon_bo_map(rbo, enable_write);
if (!err)
*addr = rbo->ptr;
return err;
}
static void
drm_gem_radeon_unmap(struct drm_module_t *drm, struct drm_bo_t *bo)
{
struct radeon_bo *rbo = (struct radeon_bo *) bo->data;
radeon_bo_unmap(rbo);
}
const struct drm_gem_drv drm_gem_drv_radeon = {
.init = drm_gem_radeon_init,
.alloc = drm_gem_radeon_alloc,
.free = drm_gem_radeon_free,
.map = drm_gem_radeon_map,
.unmap = drm_gem_radeon_unmap,
};

267
src/gralloc/gralloc_kms.c Normal file
View File

@@ -0,0 +1,267 @@
#define LOG_TAG "GRALLOC-KMS"
#include <cutils/log.h>
#include <errno.h>
#include <unistd.h>
#include "gralloc_kms.h"
int
drm_kms_add_fb(struct drm_module_t *drm, struct drm_bo_t *bo)
{
uint8_t bpp;
bpp = drm_mod_get_bpp(bo->format) * 8;
return drmModeAddFB(drm->fd, bo->width, bo->height, bpp, bpp,
bo->stride, bo->fb_handle, (uint32_t *) &bo->fb_id);
}
void
drm_kms_rm_fb(struct drm_module_t *drm, struct drm_bo_t *bo)
{
drmModeRmFB(drm->fd, bo->fb_id);
bo->fb_id = 0;
}
static void
drm_kms_wait_vblank(struct drm_module_t *drm, int num)
{
drmVBlank vbl;
int ret;
memset(&vbl, 0, sizeof(vbl));
vbl.request.type = DRM_VBLANK_RELATIVE;
if (drm->vblank_secondary)
vbl.request.type |= DRM_VBLANK_SECONDARY;
vbl.request.sequence = num;
ret = drmWaitVBlank(drm->fd, &vbl);
if (ret)
LOGW("failed to wait vblank");
}
static int
drm_kms_set_crtc(struct drm_module_t *drm, struct drm_bo_t *bo)
{
int ret;
if (drm->swap_interval)
drm_kms_wait_vblank(drm, drm->swap_interval);
ret = drmModeSetCrtc(drm->fd, drm->crtc_id, bo->fb_id,
0, 0, &drm->connector_id, 1, &drm->mode);
if (ret) {
LOGE("failed to set crtc");
return ret;
}
#ifdef DRM_MODE_FEATURE_DIRTYFB
if (drm->mode_dirty_fb)
ret = drmModeDirtyFB(drm->fd, bo->fb_id, &drm->clip, 1);
#endif
return ret;
}
static void page_flip_handler(int fd, unsigned int sequence,
unsigned int tv_sec, unsigned int tv_usec,
void *user_data)
{
struct drm_module_t *drm = (struct drm_module_t *) user_data;
drm->flip_pending = 0;
}
static int
drm_kms_page_flip(struct drm_module_t *drm, struct drm_bo_t *bo)
{
int retries = 3, ret;
if (drm->swap_interval > 1)
drm_kms_wait_vblank(drm, drm->swap_interval - 1);
/* TODO throttle page flip instead of retrying here */
while (retries) {
ret = drmModePageFlip(drm->fd, drm->crtc_id, bo->fb_id,
DRM_MODE_PAGE_FLIP_EVENT, (void *) drm);
if (ret && errno == EBUSY) {
if (drm->swap_interval)
drm_kms_wait_vblank(drm, 1);
else
usleep(5000);
retries--;
}
else {
if (!ret)
drm->flip_pending = 1;
break;
}
}
if (drm->mode_page_flip_blocking && drm->flip_pending) {
drmEventContext ctx;
memset(&ctx, 0, sizeof(ctx));
ctx.version = DRM_EVENT_CONTEXT_VERSION;
ctx.page_flip_handler = page_flip_handler;
while (drm->flip_pending)
drmHandleEvent(drm->fd, &ctx);
}
if (ret)
LOGE("failed to perform page flip");
return ret;
}
int
drm_kms_post(struct drm_module_t *drm, struct drm_bo_t *bo)
{
int ret;
if (!bo->fb_id) {
LOGE("unable to post bo %p without fb", bo);
return -EINVAL;
}
/* TODO spawn a thread to avoid waiting */
if (drm->first_post) {
pthread_mutex_lock(&drm->mutex);
if (drm->first_post) {
ret = drm_kms_set_crtc(drm, bo);
if (!ret)
drm->first_post = 0;
pthread_mutex_unlock(&drm->mutex);
return ret;
}
pthread_mutex_unlock(&drm->mutex);
}
if (drm->mode_page_flip && drm->swap_interval)
ret = drm_kms_page_flip(drm, bo);
else
ret = drm_kms_set_crtc(drm, bo);
return ret;
}
static int
drm_kms_init_with_connector_locked(struct drm_module_t *drm,
drmModeConnectorPtr connector)
{
drmModeEncoderPtr encoder;
drmModeModeInfoPtr mode;
int i;
if (!connector->count_modes)
return -EINVAL;
encoder = drmModeGetEncoder(drm->fd, connector->encoders[0]);
if (!encoder)
return -EINVAL;
for (i = 0; i < drm->resources->count_crtcs; i++) {
if (encoder->possible_crtcs & (1 << i))
break;
}
drmModeFreeEncoder(encoder);
if (i == drm->resources->count_crtcs)
return -EINVAL;
drm->crtc_id = drm->resources->crtcs[i];
drm->connector_id = connector->connector_id;
/* find the first preferred mode */
mode = NULL;
for (i = 0; i < connector->count_modes; i++) {
drmModeModeInfoPtr m = &connector->modes[i];
if (m->type & DRM_MODE_TYPE_PREFERRED) {
mode = m;
break;
}
}
/* no preference; use the first */
if (!mode)
mode = &connector->modes[0];
drm->mode = *mode;
if (connector->mmWidth && connector->mmHeight) {
drm->xdpi = (drm->mode.hdisplay * 25.4 / connector->mmWidth);
drm->ydpi = (drm->mode.vdisplay * 25.4 / connector->mmHeight);
}
else {
drm->xdpi = 75;
drm->ydpi = 75;
}
/* select between 32/16 bits */
#if 1
drm->format = HAL_PIXEL_FORMAT_BGRA_8888;
#else
drm->format = HAL_PIXEL_FORMAT_RGB_565;
#endif
#ifdef DRM_MODE_FEATURE_DIRTYFB
drm->clip.x1 = 0;
drm->clip.y1 = 0;
drm->clip.x2 = drm->mode.hdisplay;
drm->clip.y2 = drm->mode.vdisplay;
#endif
drm->first_post = 1;
return 0;
}
static int
drm_kms_init_locked(struct drm_module_t *drm)
{
int i, ret;
if (drm->resources)
return 0;
drm->resources = drmModeGetResources(drm->fd);
if (!drm->resources) {
LOGE("failed to get modeset resources");
return -EINVAL;
}
for (i = 0; i < drm->resources->count_connectors; i++) {
drmModeConnectorPtr connector;
connector = drmModeGetConnector(drm->fd, drm->resources->connectors[i]);
if (connector) {
if (connector->connection == DRM_MODE_CONNECTED) {
if (!drm_kms_init_with_connector_locked(drm, connector))
break;
}
drmModeFreeConnector(connector);
}
}
if (i == drm->resources->count_connectors) {
drmModeFreeResources(drm->resources);
drm->resources = NULL;
return -EINVAL;
}
return 0;
}
int
drm_kms_init(struct drm_module_t *drm)
{
int ret;
pthread_mutex_lock(&drm->mutex);
ret = drm_kms_init_locked(drm);
pthread_mutex_unlock(&drm->mutex);
return ret;
}

19
src/gralloc/gralloc_kms.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef _DRM_KMS_H_
#define _DRM_KMS_H_
#include "gralloc_mod.h"
#include "gralloc_gem.h"
int
drm_kms_init(struct drm_module_t *drm);
int
drm_kms_add_fb(struct drm_module_t *drm, struct drm_bo_t *bo);
void
drm_kms_rm_fb(struct drm_module_t *drm, struct drm_bo_t *bo);
int
drm_kms_post(struct drm_module_t *drm, struct drm_bo_t *bo);
#endif /* _DRM_KMS_H_ */

334
src/gralloc/gralloc_mod.c Normal file
View File

@@ -0,0 +1,334 @@
#define LOG_TAG "GRALLOC-MOD"
#include <cutils/log.h>
#include <stdlib.h>
#include <errno.h>
#include <stdarg.h>
#include "gralloc_mod.h"
#include "gralloc_gem.h"
#include "gralloc_kms.h"
static int
drm_mod_perform(const struct gralloc_module_t *mod, int op, ...)
{
struct drm_module_t *drm = (struct drm_module_t *) mod;
va_list args;
int ret;
va_start(args, op);
switch (op) {
case GRALLOC_MODULE_PERFORM_GET_DRM_FD:
{
int *fd = va_arg(args, int *);
ret = drm_gem_init(drm);
if (!ret)
*fd = drm->fd;
}
break;
case GRALLOC_MODULE_PERFORM_GET_DRM_MAGIC:
{
int32_t *magic = va_arg(args, int32_t *);
ret = drm_gem_init(drm);
if (!ret)
ret = drm_gem_get_magic(drm, magic);
}
break;
case GRALLOC_MODULE_PERFORM_AUTH_DRM_MAGIC:
{
int32_t magic = va_arg(args, int32_t);
ret = drm_gem_init(drm);
if (!ret)
ret = drm_gem_auth_magic(drm, magic);
}
break;
default:
ret = -EINVAL;
break;
}
va_end(args);
return ret;
}
static int
drm_mod_register_buffer(const gralloc_module_t *mod, buffer_handle_t handle)
{
return (drm_gem_get(handle)) ? 0 : -EINVAL;
}
static int
drm_mod_unregister_buffer(const gralloc_module_t *mod, buffer_handle_t handle)
{
return (drm_gem_get(handle)) ? 0 : -EINVAL;
}
static int
drm_mod_lock(const gralloc_module_t *mod, buffer_handle_t handle,
int usage, int x, int y, int w, int h, void **ptr)
{
struct drm_module_t *drm = (struct drm_module_t *) mod;
struct drm_bo_t *bo;
int ret;
ret = drm_gem_init(drm);
if (!ret)
ret = drm_gem_drv_init(drm);
if (ret)
return ret;
bo = drm_gem_validate(handle);
if (!bo)
return -EINVAL;
return drm_gem_drv_map(drm, bo, x, y, w, h, 1, ptr);
}
static int
drm_mod_unlock(const gralloc_module_t *mod, buffer_handle_t handle)
{
struct drm_module_t *drm = (struct drm_module_t *) mod;
struct drm_bo_t *bo;
bo = drm_gem_validate(handle);
if (!bo)
return -EINVAL;
drm_gem_drv_unmap(drm, bo);
return 0;
}
static int
drm_mod_close_gpu0(struct hw_device_t *dev)
{
struct alloc_device_t *alloc = (struct alloc_device_t *) dev;
free(alloc);
return 0;
}
static int
drm_mod_free_gpu0(alloc_device_t *dev, buffer_handle_t handle)
{
struct drm_module_t *drm = (struct drm_module_t *) dev->common.module;
struct drm_bo_t *bo;
bo = drm_gem_validate(handle);
if (!bo)
return -EINVAL;
if (bo->usage & GRALLOC_USAGE_HW_FB)
drm_kms_rm_fb(drm, bo);
drm_gem_drv_free(drm, bo);
return 0;
}
static int
drm_mod_alloc_gpu0(alloc_device_t *dev, int w, int h, int format, int usage,
buffer_handle_t *handle, int *stride)
{
struct drm_module_t *drm = (struct drm_module_t *) dev->common.module;
struct drm_bo_t *bo;
int size, bpp, ret;
ret = drm_gem_drv_init(drm);
if (ret)
return ret;
bpp = drm_mod_get_bpp(format);
if (!bpp)
return -EINVAL;
bo = drm_gem_drv_alloc(drm, w, h, format, usage, stride);
if (!bo)
return -EINVAL;
if (bo->usage & GRALLOC_USAGE_HW_FB) {
ret = drm_kms_add_fb(drm, bo);
if (ret) {
LOGE("failed to add fb");
drm_gem_drv_free(drm, bo);
return ret;
}
}
*stride /= bpp;
*handle = &bo->base;
return 0;
}
static int
drm_mod_open_gpu0(struct drm_module_t *drm, hw_device_t **dev)
{
struct alloc_device_t *alloc;
int ret;
ret = drm_gem_init(drm);
if (ret)
return ret;
alloc = calloc(1, sizeof(*alloc));
if (!alloc)
return -EINVAL;
alloc->common.tag = HARDWARE_DEVICE_TAG;
alloc->common.version = 0;
alloc->common.module = (hw_module_t *) drm;
alloc->common.close = drm_mod_close_gpu0;
alloc->alloc = drm_mod_alloc_gpu0;
alloc->free = drm_mod_free_gpu0;
*dev = &alloc->common;
return 0;
}
static int
drm_mod_close_fb0(struct hw_device_t *dev)
{
struct framebuffer_device_t *fb = (struct framebuffer_device_t *) dev;
free(fb);
return 0;
}
static int
drm_mod_set_swap_interval_fb0(struct framebuffer_device_t *fb, int interval)
{
if (interval < fb->minSwapInterval || interval > fb->maxSwapInterval)
return -EINVAL;
return 0;
}
static int
drm_mod_post_fb0(struct framebuffer_device_t *fb, buffer_handle_t handle)
{
struct drm_module_t *drm = (struct drm_module_t *) fb->common.module;
struct drm_bo_t *bo;
bo = drm_gem_validate(handle);
if (!bo)
return -EINVAL;
return drm_kms_post(drm, bo);
}
#include <GLES/gl.h>
static int
drm_mod_composition_complete_fb0(struct framebuffer_device_t *fb)
{
struct drm_module_t *drm = (struct drm_module_t *) fb->common.module;
if (drm->mode_page_flip)
glFlush();
else
glFinish();
return 0;
}
static int
drm_mod_open_fb0(struct drm_module_t *drm, struct hw_device_t **dev)
{
struct framebuffer_device_t *fb;
int ret;
fb = calloc(1, sizeof(*fb));
if (!fb)
return -ENOMEM;
ret = drm_gem_init(drm);
if (!ret)
ret = drm_kms_init(drm);
if (ret) {
free(fb);
return ret;
}
fb->common.tag = HARDWARE_DEVICE_TAG;
fb->common.version = 0;
fb->common.module = (hw_module_t *) drm;
fb->common.close = drm_mod_close_fb0;
fb->setSwapInterval = drm_mod_set_swap_interval_fb0;
fb->post = drm_mod_post_fb0;
fb->compositionComplete = drm_mod_composition_complete_fb0;
*((uint32_t *) &fb->flags) = 0x0;
*((uint32_t *) &fb->width) = drm->mode.hdisplay;
*((uint32_t *) &fb->height) = drm->mode.vdisplay;
*((int *) &fb->stride) = drm->mode.hdisplay;
*((float *) &fb->fps) = drm->mode.vrefresh;
*((int *) &fb->format) = drm->format;
*((float *) &fb->xdpi) = drm->xdpi;
*((float *) &fb->ydpi) = drm->ydpi;
*((int *) &fb->minSwapInterval) = drm->swap_interval;
*((int *) &fb->maxSwapInterval) = drm->swap_interval;
*dev = &fb->common;
LOGI("mode.hdisplay %d\n"
"mode.vdisplay %d\n"
"mode.vrefresh %d\n"
"format 0x%x\n"
"xdpi %d\n"
"ydpi %d\n",
drm->mode.hdisplay,
drm->mode.vdisplay,
drm->mode.vrefresh,
drm->format,
drm->xdpi, drm->ydpi);
return 0;
}
static int
drm_mod_open(const struct hw_module_t *mod, const char *name, struct hw_device_t **dev)
{
struct drm_module_t *drm = (struct drm_module_t *) mod;
int ret;
if (strcmp(name, GRALLOC_HARDWARE_GPU0) == 0)
ret = drm_mod_open_gpu0(drm, dev);
else if (strcmp(name, GRALLOC_HARDWARE_FB0) == 0)
ret = drm_mod_open_fb0(drm, dev);
else
ret = -EINVAL;
return ret;
}
static struct hw_module_methods_t drm_mod_methods = {
.open = drm_mod_open
};
struct drm_module_t HAL_MODULE_INFO_SYM = {
.base = {
.common = {
.tag = HARDWARE_MODULE_TAG,
.version_major = 1,
.version_minor = 0,
.id = GRALLOC_HARDWARE_MODULE_ID,
.name = "DRM Memory Allocator",
.author = "Chia-I Wu",
.methods = &drm_mod_methods
},
.registerBuffer = drm_mod_register_buffer,
.unregisterBuffer = drm_mod_unregister_buffer,
.lock = drm_mod_lock,
.unlock = drm_mod_unlock,
.perform = drm_mod_perform
},
.mutex = PTHREAD_MUTEX_INITIALIZER,
.fd = -1
};

68
src/gralloc/gralloc_mod.h Normal file
View File

@@ -0,0 +1,68 @@
#ifndef _GRALLOC_DRM_H
#define _GRALLOC_DRM_H
#include <hardware/gralloc.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <pthread.h>
struct drm_module_t {
gralloc_module_t base;
pthread_mutex_t mutex;
/* initialized by drm_gem_init */
int fd;
/* initialized by drm_kms_init */
drmModeResPtr resources;
uint32_t crtc_id;
uint32_t connector_id;
drmModeModeInfo mode;
int xdpi, ydpi;
int format;
#ifdef DRM_MODE_FEATURE_DIRTYFB
drmModeClip clip;
#endif
/* initialized by drm_gem_drv_init */
void *drv;
void *gem;
int mode_dirty_fb;
int mode_page_flip;
int mode_page_flip_blocking; /* page flip should block */
int swap_interval;
int vblank_secondary;
int first_post;
int flip_pending;
};
static inline int
drm_mod_get_bpp(int format)
{
int bpp;
switch (format) {
case HAL_PIXEL_FORMAT_RGBA_8888:
case HAL_PIXEL_FORMAT_RGBX_8888:
case HAL_PIXEL_FORMAT_BGRA_8888:
bpp = 4;
break;
case HAL_PIXEL_FORMAT_RGB_888:
bpp = 3;
break;
case HAL_PIXEL_FORMAT_RGB_565:
case HAL_PIXEL_FORMAT_RGBA_5551:
case HAL_PIXEL_FORMAT_RGBA_4444:
bpp = 2;
break;
default:
bpp = 0;
break;
}
return bpp;
}
#endif /* _GRALLOC_DRM_H */

23
src/mapi/Android.mk Normal file
View File

@@ -0,0 +1,23 @@
# Android.mk for glapi
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include $(LOCAL_PATH)/mapi/sources.mak
LOCAL_SRC_FILES := $(addprefix mapi/, $(MAPI_GLAPI_SOURCES))
LOCAL_CFLAGS := \
-DPTHREADS \
-DMAPI_MODE_GLAPI \
-DMAPI_ABI_HEADER=\"shared-glapi/glapi_mapi_tmp.h\" \
-fvisibility=hidden \
-Wno-sign-compare
LOCAL_C_INCLUDES := \
external/mesa/include \
external/mesa/src/mapi
LOCAL_MODULE := libglapi
include $(BUILD_SHARED_LIBRARY)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

55
src/mesa/Android.mk Normal file
View File

@@ -0,0 +1,55 @@
LOCAL_PATH := $(call my-dir)
include $(LOCAL_PATH)/sources.mak
common_CFLAGS := \
-DPTHREADS \
-DFEATURE_ES1=1 \
-DFEATURE_ES2=1 \
-fvisibility=hidden \
-Wno-sign-compare
ifeq ($(strip $(MESA_BUILD_CLASSIC)),true)
common_CFLAGS += -DFEATURE_GL=1
endif
common_C_INCLUDES := \
external/mesa/include \
external/mesa/src/mapi \
external/mesa/src/glsl
ifeq ($(strip $(MESA_BUILD_GALLIUM)),true)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(MESA_GALLIUM_SOURCES) \
$(MESA_GALLIUM_CXX_SOURCES)
LOCAL_CFLAGS := $(common_CFLAGS)
LOCAL_C_INCLUDES := \
$(common_C_INCLUDES) \
external/mesa/src/gallium/include \
external/mesa/src/gallium/auxiliary
LOCAL_MODULE := libmesa_st_mesa
include $(BUILD_STATIC_LIBRARY)
endif # MESA_BUILD_GALLIUM
ifeq ($(strip $(MESA_BUILD_CLASSIC)),true)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(MESA_SOURCES) \
$(MESA_CXX_SOURCES)
LOCAL_CFLAGS := $(common_CFLAGS)
LOCAL_C_INCLUDES := $(common_C_INCLUDES)
LOCAL_MODULE := libmesa_classic_mesa
include $(BUILD_STATIC_LIBRARY)
include $(call all-makefiles-under,$(LOCAL_PATH))
endif # MESA_BUILD_CLASSIC

258
src/mesa/drivers/Android.mk Normal file
View File

@@ -0,0 +1,258 @@
# Android.mk for DRI drivers
LOCAL_PATH := $(call my-dir)
# from dri/i915/Makefile
i915_DRIVER_SOURCES = \
i830_context.c \
i830_state.c \
i830_texblend.c \
i830_texstate.c \
i830_vtbl.c \
intel_render.c \
intel_regions.c \
intel_buffer_objects.c \
intel_batchbuffer.c \
intel_clear.c \
intel_extensions.c \
intel_extensions_es2.c \
intel_mipmap_tree.c \
intel_tex_layout.c \
intel_tex_image.c \
intel_tex_subimage.c \
intel_tex_copy.c \
intel_tex_validate.c \
intel_tex_format.c \
intel_tex.c \
intel_pixel.c \
intel_pixel_bitmap.c \
intel_pixel_copy.c \
intel_pixel_draw.c \
intel_pixel_read.c \
intel_buffers.c \
intel_blit.c \
i915_tex_layout.c \
i915_texstate.c \
i915_context.c \
i915_debug.c \
i915_debug_fp.c \
i915_fragprog.c \
i915_program.c \
i915_state.c \
i915_vtbl.c \
intel_context.c \
intel_decode.c \
intel_screen.c \
intel_span.c \
intel_state.c \
intel_syncobj.c \
intel_tris.c \
intel_fbo.c
i915_DRIVER_SOURCES := $(addprefix dri/i915/, $(i915_DRIVER_SOURCES))
# from dri/i965/Makefile
i965_DRIVER_SOURCES = \
intel_batchbuffer.c \
intel_blit.c \
intel_buffer_objects.c \
intel_buffers.c \
intel_clear.c \
intel_context.c \
intel_decode.c \
intel_extensions.c \
intel_extensions_es2.c \
intel_fbo.c \
intel_mipmap_tree.c \
intel_regions.c \
intel_screen.c \
intel_span.c \
intel_pixel.c \
intel_pixel_bitmap.c \
intel_pixel_copy.c \
intel_pixel_draw.c \
intel_pixel_read.c \
intel_state.c \
intel_syncobj.c \
intel_tex.c \
intel_tex_copy.c \
intel_tex_format.c \
intel_tex_image.c \
intel_tex_layout.c \
intel_tex_subimage.c \
intel_tex_validate.c \
brw_cc.c \
brw_clip.c \
brw_clip_line.c \
brw_clip_point.c \
brw_clip_state.c \
brw_clip_tri.c \
brw_clip_unfilled.c \
brw_clip_util.c \
brw_context.c \
brw_curbe.c \
brw_disasm.c \
brw_draw.c \
brw_draw_upload.c \
brw_eu.c \
brw_eu_debug.c \
brw_eu_emit.c \
brw_eu_util.c \
brw_fallback.c \
brw_gs.c \
brw_gs_emit.c \
brw_gs_state.c \
brw_misc_state.c \
brw_optimize.c \
brw_program.c \
brw_queryobj.c \
brw_sf.c \
brw_sf_emit.c \
brw_sf_state.c \
brw_state.c \
brw_state_batch.c \
brw_state_cache.c \
brw_state_dump.c \
brw_state_upload.c \
brw_tex.c \
brw_tex_layout.c \
brw_urb.c \
brw_util.c \
brw_vs.c \
brw_vs_constval.c \
brw_vs_emit.c \
brw_vs_state.c \
brw_vs_surface_state.c \
brw_vtbl.c \
brw_wm.c \
brw_wm_debug.c \
brw_wm_emit.c \
brw_wm_fp.c \
brw_wm_iz.c \
brw_wm_pass0.c \
brw_wm_pass1.c \
brw_wm_pass2.c \
brw_wm_sampler_state.c \
brw_wm_state.c \
brw_wm_surface_state.c \
gen6_cc.c \
gen6_clip_state.c \
gen6_depthstencil.c \
gen6_gs_state.c \
gen6_sampler_state.c \
gen6_scissor_state.c \
gen6_sf_state.c \
gen6_urb.c \
gen6_viewport_state.c \
gen6_vs_state.c \
gen6_wm_state.c
i965_CXX_SOURCES = \
brw_cubemap_normalize.cpp \
brw_fs.cpp \
brw_fs_channel_expressions.cpp \
brw_fs_reg_allocate.cpp \
brw_fs_schedule_instructions.cpp \
brw_fs_vector_splitting.cpp
i965_DRIVER_SOURCES := \
$(addprefix dri/i965/, $(i965_DRIVER_SOURCES)) \
$(addprefix dri/i965/, $(i965_CXX_SOURCES))
# from dri/Makefile.template
common_SOURCES = \
dri/common/utils.c \
dri/common/vblank.c \
dri/common/dri_util.c \
dri/common/xmlconfig.c \
dri/common/texmem.c \
dri/common/drirenderbuffer.c \
common/driverfuncs.c
common_CFLAGS := \
-DPTHREADS \
-DFEATURE_GL=1 \
-DFEATURE_ES1=1 \
-DFEATURE_ES2=1 \
-fvisibility=hidden \
-Wno-sign-compare
common_C_INCLUDES := \
external/mesa/include \
external/mesa/src/mapi \
external/mesa/src/glsl \
external/mesa/src/mesa \
external/mesa/src/mesa/drivers/dri/common \
external/drm/ \
external/drm/include/drm \
external/expat/lib
common_STATIC_LIBRARIES := \
libmesa_classic_mesa \
libmesa_glsl \
libmesa_classic_mesa
common_SHARED_LIBRARIES := \
libglapi \
libdl \
libdrm \
libexpat \
liblog \
libcutils
common_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/dri
ifeq ($(strip $(MESA_BUILD_I915C)),true)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(common_SOURCES) \
$(i915_DRIVER_SOURCES)
LOCAL_CFLAGS := \
$(common_CFLAGS) \
-DI915
LOCAL_C_INCLUDES := \
$(common_C_INCLUDES) \
external/mesa/src/mesa/drivers/dri/intel \
external/drm/intel
LOCAL_STATIC_LIBRARIES := \
$(common_STATIC_LIBRARIES)
LOCAL_SHARED_LIBRARIES := \
$(common_SHARED_LIBRARIES) \
libdrm_intel
LOCAL_MODULE := i915_dri
LOCAL_MODULE_PATH := $(common_MODULE_PATH)
include $(BUILD_SHARED_LIBRARY)
endif # MESA_BUILD_I915C
ifeq ($(strip $(MESA_BUILD_I965C)),true)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(common_SOURCES) \
$(i965_DRIVER_SOURCES)
LOCAL_CFLAGS := \
$(common_CFLAGS) \
-DI965
LOCAL_C_INCLUDES := \
$(common_C_INCLUDES) \
external/mesa/src/mesa/drivers/dri/intel \
external/drm/intel
LOCAL_STATIC_LIBRARIES := \
$(common_STATIC_LIBRARIES)
LOCAL_SHARED_LIBRARIES := \
$(common_SHARED_LIBRARIES) \
libdrm_intel
LOCAL_MODULE := i965_dri
LOCAL_MODULE_PATH := $(common_MODULE_PATH)
include $(BUILD_SHARED_LIBRARY)
endif # MESA_BUILD_I965C

View File

@@ -268,6 +268,16 @@ struct gen_mipmap_state
};
#define MAX_META_OPS_DEPTH 2
/**
* State for glDrawTex()
*/
struct drawtex_state
{
GLuint ArrayObj;
GLuint VBO;
};
/**
* All per-context meta state.
*/
@@ -286,6 +296,7 @@ struct gl_meta_state
struct drawpix_state DrawPix; /**< For _mesa_meta_DrawPixels() */
struct bitmap_state Bitmap; /**< For _mesa_meta_Bitmap() */
struct gen_mipmap_state Mipmap; /**< For _mesa_meta_GenerateMipmap() */
struct drawtex_state DrawTex; /**< For _mesa_meta_DrawTex() */
};
@@ -2850,3 +2861,135 @@ _mesa_meta_CopyColorSubTable(struct gl_context *ctx,GLenum target, GLsizei start
free(buf);
}
#if FEATURE_OES_draw_texture
/**
* Meta implementation of ctx->Driver.DrawTex() in terms
* of polygon rendering.
*/
void
_mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
GLfloat width, GLfloat height)
{
struct drawtex_state *drawtex = &ctx->Meta->DrawTex;
struct vertex {
GLfloat x, y, z, st[MAX_TEXTURE_UNITS][2];
};
struct vertex verts[4];
GLuint i;
_mesa_meta_begin(ctx, (META_RASTERIZATION |
META_SHADER |
META_TRANSFORM |
META_VERTEX |
META_VIEWPORT));
if (drawtex->ArrayObj == 0) {
/* one-time setup */
GLint active_texture;
/* create vertex array object */
_mesa_GenVertexArrays(1, &drawtex->ArrayObj);
_mesa_BindVertexArray(drawtex->ArrayObj);
/* create vertex array buffer */
_mesa_GenBuffersARB(1, &drawtex->VBO);
_mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, drawtex->VBO);
_mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts),
NULL, GL_DYNAMIC_DRAW_ARB);
/* client active texture is not part of the array object */
active_texture = ctx->Array.ActiveTexture;
/* setup vertex arrays */
_mesa_VertexPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
_mesa_EnableClientState(GL_VERTEX_ARRAY);
for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
_mesa_ClientActiveTextureARB(GL_TEXTURE0 + i);
_mesa_TexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(st[i]));
_mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY);
}
/* restore client active texture */
_mesa_ClientActiveTextureARB(GL_TEXTURE0 + active_texture);
}
else {
_mesa_BindVertexArray(drawtex->ArrayObj);
_mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, drawtex->VBO);
}
/* vertex positions, texcoords */
{
const GLfloat x1 = x + width;
const GLfloat y1 = y + height;
z = CLAMP(z, 0.0, 1.0);
z = invert_z(z);
verts[0].x = x;
verts[0].y = y;
verts[0].z = z;
verts[1].x = x1;
verts[1].y = y;
verts[1].z = z;
verts[2].x = x1;
verts[2].y = y1;
verts[2].z = z;
verts[3].x = x;
verts[3].y = y1;
verts[3].z = z;
for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
const struct gl_texture_object *texObj;
const struct gl_texture_image *texImage;
GLfloat s, t, s1, t1;
GLuint tw, th;
if (!ctx->Texture.Unit[i]._ReallyEnabled) {
GLuint j;
for (j = 0; j < 4; j++) {
verts[j].st[i][0] = 0.0f;
verts[j].st[i][1] = 0.0f;
}
continue;
}
texObj = ctx->Texture.Unit[i]._Current;
texImage = texObj->Image[0][texObj->BaseLevel];
tw = texImage->Width2;
th = texImage->Height2;
s = (GLfloat) texObj->CropRect[0] / tw;
t = (GLfloat) texObj->CropRect[1] / th;
s1 = (GLfloat) (texObj->CropRect[0] + texObj->CropRect[2]) / tw;
t1 = (GLfloat) (texObj->CropRect[1] + texObj->CropRect[3]) / th;
verts[0].st[i][0] = s;
verts[0].st[i][1] = t;
verts[1].st[i][0] = s1;
verts[1].st[i][1] = t;
verts[2].st[i][0] = s1;
verts[2].st[i][1] = t1;
verts[3].st[i][0] = s;
verts[3].st[i][1] = t1;
}
_mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
}
_mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
_mesa_meta_end(ctx);
}
#endif /* FEATURE_OES_draw_texture */

View File

@@ -114,5 +114,8 @@ _mesa_meta_CopyConvolutionFilter2D(struct gl_context *ctx, GLenum target,
GLenum internalFormat, GLint x, GLint y,
GLsizei width, GLsizei height);
extern void
_mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
GLfloat width, GLfloat height);
#endif /* META_H */

View File

@@ -60,6 +60,8 @@ translate_texture_format(gl_format mesa_format, GLuint internal_format,
return MAPSURF_32BIT | MT_32BIT_ARGB8888;
case MESA_FORMAT_XRGB8888:
return MAPSURF_32BIT | MT_32BIT_XRGB8888;
case MESA_FORMAT_RGBA8888_REV:
return MAPSURF_32BIT | MT_32BIT_ABGR8888;
case MESA_FORMAT_YCBCR_REV:
return (MAPSURF_422 | MT_422_YCRCB_NORMAL);
case MESA_FORMAT_YCBCR:

View File

@@ -192,6 +192,7 @@ static GLuint get_surface_type( GLenum type, GLuint size,
else {
return ubyte_types_norm[size];
}
case GL_FIXED: return float_types[size]; /* was uploaded as floats */
default: assert(0); return 0;
}
}
@@ -207,6 +208,7 @@ static GLuint get_surface_type( GLenum type, GLuint size,
case GL_UNSIGNED_INT: return uint_types_scale[size];
case GL_UNSIGNED_SHORT: return ushort_types_scale[size];
case GL_UNSIGNED_BYTE: return ubyte_types_scale[size];
case GL_FIXED: return float_types[size]; /* was uploaded as floats */
default: assert(0); return 0;
}
}
@@ -225,6 +227,7 @@ static GLuint get_size( GLenum type )
case GL_UNSIGNED_INT: return sizeof(GLuint);
case GL_UNSIGNED_SHORT: return sizeof(GLushort);
case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
case GL_FIXED: return sizeof(GLfloat); /* will be uploaded as floats */
default: assert(0); return 0;
}
}
@@ -251,6 +254,45 @@ copy_array_to_vbo_array(struct brw_context *brw,
int count = max - min + 1;
GLuint size = count * dst_stride;
/* upload as floats */
if (element->glarray->Type == GL_FIXED) {
char * const map = intel_upload_map(&brw->intel, size, dst_stride);
char *dst = map;
drm_intel_bo *src_bo = NULL;
GLint i, j;
/* map source bo */
if (_mesa_is_bufferobj(element->glarray->BufferObj)) {
struct intel_buffer_object *intel_buffer =
intel_buffer_object(element->glarray->BufferObj);
src_bo = intel_bufferobj_buffer(&brw->intel, intel_buffer, INTEL_READ);
drm_intel_gem_bo_map_gtt(src_bo);
src = (const unsigned char *) src_bo->virtual + (unsigned long) src;
}
while (count--) {
const GLint *s = (GLint *) src;
GLfloat *d = (GLfloat *) dst;
int i;
for (i = 0; i < element->glarray->Size; i++)
d[i] = s[i] / 65536.0f;
src += src_stride;
dst += dst_stride;
}
intel_upload_unmap(&brw->intel, map, size, dst_stride,
&buffer->bo, &buffer->offset);
if (src_bo)
drm_intel_gem_bo_unmap_gtt(src_bo);
return;
}
if (dst_stride == src_stride) {
intel_upload_data(&brw->intel, src, size, dst_stride,
&buffer->bo, &buffer->offset);
@@ -323,7 +365,8 @@ static void brw_prepare_vertices(struct brw_context *brw)
input->element_size = type_size * glarray->Size;
if (_mesa_is_bufferobj(glarray->BufferObj)) {
if (_mesa_is_bufferobj(glarray->BufferObj) &&
glarray->Type != GL_FIXED) {
struct intel_buffer_object *intel_buffer =
intel_buffer_object(glarray->BufferObj);
int k;
@@ -452,11 +495,27 @@ static void brw_prepare_vertices(struct brw_context *brw)
dst = map + offset;
src += min_index * stride;
for (n = 0; n < count; n++) {
memcpy(dst, src, size);
src += stride;
dst += total_size;
}
if (upload[i]->glarray->Type == GL_FIXED) {
for (n = 0; n < count; n++) {
const GLint *s = (GLint *) src;
GLfloat *d = (GLfloat *) dst;
int k;
for (k = 0; k < upload[i]->glarray->Size; k++) {
d[k] = s[k] / 65536.0f;
}
src += stride;
dst += total_size;
}
}
else {
for (n = 0; n < count; n++) {
memcpy(dst, src, size);
src += stride;
dst += total_size;
}
}
upload[i]->offset = offset;
upload[i]->buffer = j;

View File

@@ -85,7 +85,7 @@ static void init_registers( struct brw_wm_compile *c )
prealloc_reg(c, &c->creg[j], i++);
if (intel->gen >= 6) {
for (unsigned int j = 0; j < FRAG_ATTRIB_MAX; j++) {
for (j = 0; j < FRAG_ATTRIB_MAX; j++) {
if (brw->fragment_program->Base.InputsRead & BITFIELD64_BIT(j)) {
nr_interp_regs++;
prealloc_reg(c, &c->payload.input_interp[j], i++);

View File

@@ -101,6 +101,7 @@ static uint32_t brw_format_for_mesa_format[MESA_FORMAT_COUNT] =
[MESA_FORMAT_SL8] = BRW_SURFACEFORMAT_L8_UNORM_SRGB,
[MESA_FORMAT_DUDV8] = BRW_SURFACEFORMAT_R8G8_SNORM,
[MESA_FORMAT_SIGNED_RGBA8888_REV] = BRW_SURFACEFORMAT_R8G8B8A8_SNORM,
[MESA_FORMAT_RGBA8888_REV] = BRW_SURFACEFORMAT_R8G8B8A8_UNORM,
};
bool

View File

@@ -420,6 +420,32 @@ intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
}
}
#ifdef ANDROID
depth_rb = intel_get_renderbuffer(fb, BUFFER_DEPTH);
stencil_rb = intel_get_renderbuffer(fb, BUFFER_STENCIL);
rb = NULL;
if (depth_rb && !depth_rb->region)
rb = depth_rb;
else if (stencil_rb && !stencil_rb->region)
rb = stencil_rb;
if (rb) {
uint32_t tiling = I915_TILING_NONE;
/* Gen6 requires depth must be tiling */
if (intel->gen >= 6 && rb->Base.Format == MESA_FORMAT_S8_Z24)
tiling = I915_TILING_Y;
region = intel_region_alloc(intel->intelScreen, tiling,
_mesa_get_format_bytes(rb->Base.Format),
drawable->w, drawable->h, GL_TRUE);
intel_renderbuffer_set_region(intel, rb, region);
intel_region_release(&region);
}
if (stencil_rb && !stencil_rb->region)
intel_renderbuffer_set_region(intel, stencil_rb, depth_rb->region);
#endif
driUpdateFramebufferSize(&intel->ctx, drawable);
}
@@ -851,6 +877,7 @@ intelInitContext(struct intel_context *intel,
intelInitExtensions(ctx);
break;
case API_OPENGLES:
intelInitExtensionsES1(ctx);
break;
case API_OPENGLES2:
intelInitExtensionsES2(ctx);

View File

@@ -32,6 +32,9 @@
extern void
intelInitExtensions(struct gl_context *ctx);
extern void
intelInitExtensionsES1(struct gl_context *ctx);
extern void
intelInitExtensionsES2(struct gl_context *ctx);

View File

@@ -80,6 +80,27 @@ static const char *es2_extensions[] = {
NULL,
};
void
intelInitExtensionsES1(struct gl_context *ctx)
{
int i;
/* Can't use driInitExtensions() since it uses extensions from
* main/remap_helper.h when called the first time. */
for (i = 0; es2_extensions[i]; i++)
_mesa_enable_extension(ctx, es2_extensions[i]);
_mesa_enable_extension(ctx, "GL_ARB_texture_env_add");
_mesa_enable_extension(ctx, "GL_ARB_texture_env_combine");
_mesa_enable_extension(ctx, "GL_ARB_texture_env_dot3");
_mesa_enable_extension(ctx, "GL_ARB_point_parameters");
_mesa_enable_extension(ctx, "GL_OES_draw_texture");
_mesa_enable_extension(ctx, "GL_OES_point_sprite");
}
/**
* \brief Extensions to disable.
*

View File

@@ -152,6 +152,11 @@ intel_create_image_from_name(__DRIscreen *screen,
image->internal_format = GL_RGBA;
image->data_type = GL_UNSIGNED_BYTE;
break;
case __DRI_IMAGE_FORMAT_RGBA8888_REV:
image->format = MESA_FORMAT_RGBA8888_REV;
image->internal_format = GL_RGBA;
image->data_type = GL_UNSIGNED_BYTE;
break;
default:
free(image);
return NULL;
@@ -238,6 +243,11 @@ intel_create_image(__DRIscreen *screen,
image->internal_format = GL_RGBA;
image->data_type = GL_UNSIGNED_BYTE;
break;
case __DRI_IMAGE_FORMAT_RGBA8888_REV:
image->format = MESA_FORMAT_RGBA8888_REV;
image->internal_format = GL_RGBA;
image->data_type = GL_UNSIGNED_BYTE;
break;
default:
free(image);
return NULL;

View File

@@ -119,4 +119,6 @@ intelInitTextureFuncs(struct dd_function_table *functions)
functions->NewTextureImage = intelNewTextureImage;
functions->DeleteTexture = intelDeleteTextureObject;
functions->FreeTexImageData = intelFreeTextureImageData;
functions->DrawTex = _mesa_meta_DrawTex;
}

4867
src/mesa/main/api_exec_es1.c Normal file

File diff suppressed because it is too large Load Diff

2548
src/mesa/main/api_exec_es2.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -45,11 +45,15 @@ draw_texture(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
return;
}
_mesa_set_vp_override(ctx, GL_TRUE);
if (ctx->NewState)
_mesa_update_state(ctx);
ASSERT(ctx->Driver.DrawTex);
ctx->Driver.DrawTex(ctx, x, y, z, width, height);
_mesa_set_vp_override(ctx, GL_FALSE);
}

View File

@@ -121,7 +121,7 @@ static const struct extension extension_table[] = {
{ "GL_ARB_texture_env_dot3", o(ARB_texture_env_dot3), GL },
{ "GL_ARB_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), GL },
{ "GL_ARB_texture_multisample", o(ARB_texture_multisample), GL },
{ "GL_ARB_texture_non_power_of_two", o(ARB_texture_non_power_of_two), GL },
{ "GL_ARB_texture_non_power_of_two", o(ARB_texture_non_power_of_two), GL | ES1 | ES2 },
{ "GL_ARB_texture_rectangle", o(NV_texture_rectangle), GL },
{ "GL_ARB_texture_rgb10_a2ui", o(ARB_texture_rgb10_a2ui), GL },
{ "GL_ARB_texture_rg", o(ARB_texture_rg), GL },

View File

@@ -753,7 +753,7 @@ _mesa_strdup( const char *s )
float
_mesa_strtof( const char *s, char **end )
{
#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__)
#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) && !defined(ANDROID)
static locale_t loc = NULL;
if (!loc) {
loc = newlocale(LC_CTYPE_MASK, "C", NULL);

View File

@@ -116,6 +116,7 @@ typedef union { GLfloat f; GLint i; } fi_type;
#endif
/**
* \name Work-arounds for platforms that lack C99 math functions
*/
@@ -134,7 +135,13 @@ typedef union { GLfloat f; GLint i; } fi_type;
#define exp2f(f) ((float) exp2(f))
#define floorf(f) ((float) floor(f))
#define logf(f) ((float) log(f))
#ifdef ANDROID
#define log2f(f) ((float) (log(f) / M_LN2))
#else
#define log2f(f) ((float) log2(f))
#endif
#define powf(x,y) ((float) pow(x,y))
#define sinf(f) ((float) sin(f))
#define sinhf(f) ((float) sinh(f))

View File

@@ -73,7 +73,8 @@ fpclassify(double x)
#elif defined(__APPLE__) || defined(__CYGWIN__) || defined(__FreeBSD__) || \
defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \
(defined(__sun) && defined(__C99FEATURES__)) || defined(__MINGW32__) || \
(defined(__sun) && defined(__GNUC__))
(defined(__sun) && defined(__GNUC__)) || \
defined(ANDROID)
/* fpclassify is available. */

3667
src/mesa/program/lex.yy.c Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,310 @@
/* A Bison parser, made by GNU Bison 2.3. */
/* Skeleton interface for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
ARBvp_10 = 258,
ARBfp_10 = 259,
ADDRESS = 260,
ALIAS = 261,
ATTRIB = 262,
OPTION = 263,
OUTPUT = 264,
PARAM = 265,
TEMP = 266,
END = 267,
BIN_OP = 268,
BINSC_OP = 269,
SAMPLE_OP = 270,
SCALAR_OP = 271,
TRI_OP = 272,
VECTOR_OP = 273,
ARL = 274,
KIL = 275,
SWZ = 276,
TXD_OP = 277,
INTEGER = 278,
REAL = 279,
AMBIENT = 280,
ATTENUATION = 281,
BACK = 282,
CLIP = 283,
COLOR = 284,
DEPTH = 285,
DIFFUSE = 286,
DIRECTION = 287,
EMISSION = 288,
ENV = 289,
EYE = 290,
FOG = 291,
FOGCOORD = 292,
FRAGMENT = 293,
FRONT = 294,
HALF = 295,
INVERSE = 296,
INVTRANS = 297,
LIGHT = 298,
LIGHTMODEL = 299,
LIGHTPROD = 300,
LOCAL = 301,
MATERIAL = 302,
MAT_PROGRAM = 303,
MATRIX = 304,
MATRIXINDEX = 305,
MODELVIEW = 306,
MVP = 307,
NORMAL = 308,
OBJECT = 309,
PALETTE = 310,
PARAMS = 311,
PLANE = 312,
POINT_TOK = 313,
POINTSIZE = 314,
POSITION = 315,
PRIMARY = 316,
PROGRAM = 317,
PROJECTION = 318,
RANGE = 319,
RESULT = 320,
ROW = 321,
SCENECOLOR = 322,
SECONDARY = 323,
SHININESS = 324,
SIZE_TOK = 325,
SPECULAR = 326,
SPOT = 327,
STATE = 328,
TEXCOORD = 329,
TEXENV = 330,
TEXGEN = 331,
TEXGEN_Q = 332,
TEXGEN_R = 333,
TEXGEN_S = 334,
TEXGEN_T = 335,
TEXTURE = 336,
TRANSPOSE = 337,
TEXTURE_UNIT = 338,
TEX_1D = 339,
TEX_2D = 340,
TEX_3D = 341,
TEX_CUBE = 342,
TEX_RECT = 343,
TEX_SHADOW1D = 344,
TEX_SHADOW2D = 345,
TEX_SHADOWRECT = 346,
TEX_ARRAY1D = 347,
TEX_ARRAY2D = 348,
TEX_ARRAYSHADOW1D = 349,
TEX_ARRAYSHADOW2D = 350,
VERTEX = 351,
VTXATTRIB = 352,
WEIGHT = 353,
IDENTIFIER = 354,
USED_IDENTIFIER = 355,
MASK4 = 356,
MASK3 = 357,
MASK2 = 358,
MASK1 = 359,
SWIZZLE = 360,
DOT_DOT = 361,
DOT = 362
};
#endif
/* Tokens. */
#define ARBvp_10 258
#define ARBfp_10 259
#define ADDRESS 260
#define ALIAS 261
#define ATTRIB 262
#define OPTION 263
#define OUTPUT 264
#define PARAM 265
#define TEMP 266
#define END 267
#define BIN_OP 268
#define BINSC_OP 269
#define SAMPLE_OP 270
#define SCALAR_OP 271
#define TRI_OP 272
#define VECTOR_OP 273
#define ARL 274
#define KIL 275
#define SWZ 276
#define TXD_OP 277
#define INTEGER 278
#define REAL 279
#define AMBIENT 280
#define ATTENUATION 281
#define BACK 282
#define CLIP 283
#define COLOR 284
#define DEPTH 285
#define DIFFUSE 286
#define DIRECTION 287
#define EMISSION 288
#define ENV 289
#define EYE 290
#define FOG 291
#define FOGCOORD 292
#define FRAGMENT 293
#define FRONT 294
#define HALF 295
#define INVERSE 296
#define INVTRANS 297
#define LIGHT 298
#define LIGHTMODEL 299
#define LIGHTPROD 300
#define LOCAL 301
#define MATERIAL 302
#define MAT_PROGRAM 303
#define MATRIX 304
#define MATRIXINDEX 305
#define MODELVIEW 306
#define MVP 307
#define NORMAL 308
#define OBJECT 309
#define PALETTE 310
#define PARAMS 311
#define PLANE 312
#define POINT_TOK 313
#define POINTSIZE 314
#define POSITION 315
#define PRIMARY 316
#define PROGRAM 317
#define PROJECTION 318
#define RANGE 319
#define RESULT 320
#define ROW 321
#define SCENECOLOR 322
#define SECONDARY 323
#define SHININESS 324
#define SIZE_TOK 325
#define SPECULAR 326
#define SPOT 327
#define STATE 328
#define TEXCOORD 329
#define TEXENV 330
#define TEXGEN 331
#define TEXGEN_Q 332
#define TEXGEN_R 333
#define TEXGEN_S 334
#define TEXGEN_T 335
#define TEXTURE 336
#define TRANSPOSE 337
#define TEXTURE_UNIT 338
#define TEX_1D 339
#define TEX_2D 340
#define TEX_3D 341
#define TEX_CUBE 342
#define TEX_RECT 343
#define TEX_SHADOW1D 344
#define TEX_SHADOW2D 345
#define TEX_SHADOWRECT 346
#define TEX_ARRAY1D 347
#define TEX_ARRAY2D 348
#define TEX_ARRAYSHADOW1D 349
#define TEX_ARRAYSHADOW2D 350
#define VERTEX 351
#define VTXATTRIB 352
#define WEIGHT 353
#define IDENTIFIER 354
#define USED_IDENTIFIER 355
#define MASK4 356
#define MASK3 357
#define MASK2 358
#define MASK1 359
#define SWIZZLE 360
#define DOT_DOT 361
#define DOT 362
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
#line 126 "program/program_parse.y"
{
struct asm_instruction *inst;
struct asm_symbol *sym;
struct asm_symbol temp_sym;
struct asm_swizzle_mask swiz_mask;
struct asm_src_register src_reg;
struct prog_dst_register dst_reg;
struct prog_instruction temp_inst;
char *string;
unsigned result;
unsigned attrib;
int integer;
float real;
gl_state_index state[STATE_LENGTH];
int negate;
struct asm_vector vector;
gl_inst_opcode opcode;
struct {
unsigned swz;
unsigned rgba_valid:1;
unsigned xyzw_valid:1;
unsigned negate:1;
} ext_swizzle;
}
/* Line 1529 of yacc.c. */
#line 289 "program/program_parse.tab.h"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE
{
int first_line;
int first_column;
int last_line;
int last_column;
} YYLTYPE;
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif