From 1473f46cbc82aa6f0ba744cc896a36923823d55b Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 10 Apr 2009 14:24:30 -0700 Subject: Integrate from //sandbox/mathias/donut/...@145728 SurfaceFlinger rework for new EGL driver model support. --- opengl/libagl/state.cpp | 82 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 22 deletions(-) (limited to 'opengl/libagl/state.cpp') diff --git a/opengl/libagl/state.cpp b/opengl/libagl/state.cpp index 5cbabea1f8a8..a00f779d6d35 100644 --- a/opengl/libagl/state.cpp +++ b/opengl/libagl/state.cpp @@ -2,16 +2,16 @@ ** ** Copyright 2006, The Android Open Source Project ** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at ** -** http://www.apache.org/licenses/LICENSE-2.0 +** http://www.apache.org/licenses/LICENSE-2.0 ** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and ** limitations under the License. */ @@ -28,12 +28,16 @@ #include "BufferObjectManager.h" #include "TextureObjectManager.h" +#ifdef LIBAGL_USE_GRALLOC_COPYBITS +#include +#endif // LIBAGL_USE_GRALLOC_COPYBITS + namespace android { // ---------------------------------------------------------------------------- static char const * const gVendorString = "Android"; -static char const * const gRendererString = "Android PixelFlinger 1.0"; +static char const * const gRendererString = "Android PixelFlinger 1.1"; static char const * const gVersionString = "OpenGL ES-CM 1.0"; static char const * const gExtensionsString = "GL_OES_byte_coordinates " // OK @@ -46,9 +50,9 @@ static char const * const gExtensionsString = "GL_OES_query_matrix " // OK // "GL_OES_point_size_array " // TODO // "GL_OES_point_sprite " // TODO + "GL_OES_EGL_image " // OK "GL_ARB_texture_compression " // OK "GL_ARB_texture_non_power_of_two " // OK - "GL_ANDROID_direct_texture " // OK "GL_ANDROID_user_clip_plane " // OK "GL_ANDROID_vertex_buffer_object " // OK "GL_ANDROID_generate_mipmap " // OK @@ -62,13 +66,13 @@ static char const * const gExtensionsString = ogles_context_t *ogles_init(size_t extra) { void* const base = malloc(extra + sizeof(ogles_context_t) + 32); - if (!base) return 0; + if (!base) return 0; ogles_context_t *c = (ogles_context_t *)((ptrdiff_t(base) + extra + 31) & ~0x1FL); memset(c, 0, sizeof(ogles_context_t)); ggl_init_context(&(c->rasterizer)); - + // XXX: this should be passed as an argument sp smgr(new EGLSurfaceManager()); c->surfaceManager = smgr.get(); @@ -87,13 +91,42 @@ ogles_context_t *ogles_init(size_t extra) c->rasterizer.base = base; c->point.size = TRI_ONE; c->line.width = TRI_ONE; - + // in OpenGL, writing to the depth buffer is enabled by default. c->rasterizer.procs.depthMask(c, 1); - + // OpenGL enables dithering by default c->rasterizer.procs.enable(c, GL_DITHER); + c->copybits.blitEngine = NULL; + c->copybits.minScale = 0; + c->copybits.maxScale = 0; + c->copybits.drawSurfaceFd = -1; + +#ifdef LIBAGL_USE_GRALLOC_COPYBITS + hw_module_t const* module; + if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) { + struct copybit_device_t* copyBits; + if (copybit_open(module, ©Bits) == 0) { + c->copybits.blitEngine = copyBits; + { + int minLim = copyBits->get(copyBits, + COPYBIT_MINIFICATION_LIMIT); + if (minLim != -EINVAL && minLim > 0) { + c->copybits.minScale = (1 << 16) / minLim; + } + } + { + int magLim = copyBits->get(copyBits, + COPYBIT_MAGNIFICATION_LIMIT); + if (magLim != -EINVAL && magLim > 0) { + c->copybits.maxScale = min(32*1024-1, magLim) << 16; + } + } + } + } +#endif // LIBAGL_USE_GRALLOC_COPYBITS + return c; } @@ -107,7 +140,12 @@ void ogles_uninit(ogles_context_t* c) c->surfaceManager->decStrong(c); c->bufferObjectManager->decStrong(c); ggl_uninit_context(&(c->rasterizer)); - free(c->rasterizer.base); + free(c->rasterizer.base); +#ifdef LIBAGL_USE_GRALLOC_COPYBITS + if (c->copybits.blitEngine != NULL) { + copybit_close((struct copybit_device_t*) c->copybits.blitEngine); + } +#endif // LIBAGL_USE_GRALLOC_COPYBITS } void _ogles_error(ogles_context_t* c, GLenum error) @@ -188,7 +226,7 @@ static void enable_disable(ogles_context_t* c, GLenum cap, int enabled) // these need to fall through into the rasterizer c->rasterizer.procs.enableDisable(c, cap, enabled); break; - + case GL_MULTISAMPLE: case GL_SAMPLE_ALPHA_TO_COVERAGE: case GL_SAMPLE_ALPHA_TO_ONE: @@ -281,7 +319,7 @@ void glHint(GLenum target, GLenum mode) case GL_LINE_SMOOTH_HINT: break; case GL_POINT_SMOOTH_HINT: - c->rasterizer.procs.enableDisable(c, + c->rasterizer.procs.enableDisable(c, GGL_POINT_SMOOTH_NICE, mode==GL_NICEST); break; case GL_PERSPECTIVE_CORRECTION_HINT: @@ -323,7 +361,7 @@ GLenum glGetError() c->error = 0; return ret; } - + if (c->rasterizer.error) { const GLenum ret(c->rasterizer.error); c->rasterizer.error = 0; @@ -362,25 +400,25 @@ void glGetIntegerv(GLenum pname, GLint *params) int index = c->rasterizer.state.buffers.color.format; GGLFormat const * formats = gglGetPixelFormatTable(); params[0] = formats[index].ah - formats[index].al; - break; + break; } case GL_RED_BITS: { int index = c->rasterizer.state.buffers.color.format; GGLFormat const * formats = gglGetPixelFormatTable(); params[0] = formats[index].rh - formats[index].rl; - break; + break; } case GL_GREEN_BITS: { int index = c->rasterizer.state.buffers.color.format; GGLFormat const * formats = gglGetPixelFormatTable(); params[0] = formats[index].gh - formats[index].gl; - break; + break; } case GL_BLUE_BITS: { int index = c->rasterizer.state.buffers.color.format; GGLFormat const * formats = gglGetPixelFormatTable(); params[0] = formats[index].bh - formats[index].bl; - break; + break; } case GL_COMPRESSED_TEXTURE_FORMATS: params[ 0] = GL_PALETTE4_RGB8_OES; -- cgit v1.2.3-59-g8ed1b From 350d651706d8f484d9aeb539d491526f822fa84a Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 10 Jun 2009 16:01:54 -0700 Subject: fix a bug where copybit only renders in the first buffer when used with s/w GL --- include/private/opengles/gl_context.h | 5 ++--- opengl/libagl/TextureObjectManager.cpp | 2 +- opengl/libagl/TextureObjectManager.h | 2 +- opengl/libagl/copybit.cpp | 27 +++++++++++++++++---------- opengl/libagl/copybit.h | 4 ++-- opengl/libagl/egl.cpp | 10 +++++----- opengl/libagl/state.cpp | 2 +- opengl/libagl/texture.cpp | 10 ++++------ opengl/tests/copybits/copybits.cpp | 16 +++++++--------- 9 files changed, 40 insertions(+), 38 deletions(-) (limited to 'opengl/libagl/state.cpp') diff --git a/include/private/opengles/gl_context.h b/include/private/opengles/gl_context.h index 641961f3a822..3b406779af5a 100644 --- a/include/private/opengles/gl_context.h +++ b/include/private/opengles/gl_context.h @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -600,9 +601,7 @@ struct copybits_context_t { copybit_device_t* blitEngine; int32_t minScale; int32_t maxScale; - // File descriptor of current drawing surface, if it's suitable for use as - // a copybits destination, else -1. - int drawSurfaceFd; + buffer_handle_t drawSurfaceBuffer; }; struct ogles_context_t { diff --git a/opengl/libagl/TextureObjectManager.cpp b/opengl/libagl/TextureObjectManager.cpp index 9deb2cf9eea4..255ccac3565b 100644 --- a/opengl/libagl/TextureObjectManager.cpp +++ b/opengl/libagl/TextureObjectManager.cpp @@ -56,7 +56,7 @@ void EGLTextureObject::init() generate_mipmap = GL_FALSE; direct = GL_FALSE; #ifdef LIBAGL_USE_GRALLOC_COPYBITS - copybits_fd = -1; + try_copybit = false; #endif // LIBAGL_USE_GRALLOC_COPYBITS buffer = 0; } diff --git a/opengl/libagl/TextureObjectManager.h b/opengl/libagl/TextureObjectManager.h index e0eadf147959..496e6947d737 100644 --- a/opengl/libagl/TextureObjectManager.h +++ b/opengl/libagl/TextureObjectManager.h @@ -80,7 +80,7 @@ public: GLint generate_mipmap; GLint direct; #ifdef LIBAGL_USE_GRALLOC_COPYBITS - int copybits_fd; + bool try_copybit; #endif // LIBAGL_USE_GRALLOC_COPYBITS android_native_buffer_t* buffer; }; diff --git a/opengl/libagl/copybit.cpp b/opengl/libagl/copybit.cpp index 427e42aaf292..a539a2bdd5d7 100644 --- a/opengl/libagl/copybit.cpp +++ b/opengl/libagl/copybit.cpp @@ -27,23 +27,28 @@ #include "primitives.h" #include "texture.h" #include "BufferObjectManager.h" - #include "TextureObjectManager.h" + #include #include +#include #include "gralloc_priv.h" // ---------------------------------------------------------------------------- namespace android { -static void textureToCopyBitImage(const GGLSurface* surface, int fd, copybit_image_t* img) { +static void textureToCopyBitImage( + const GGLSurface* surface, buffer_handle_t buffer, copybit_image_t* img) +{ + // we know private_handle_t is good here + private_handle_t* hnd = (private_handle_t*)buffer; img->w = surface->stride; img->h = surface->height; img->format = surface->format; - img->offset = 0; + img->offset = hnd->offset; img->base = surface->data; - img->fd = fd; + img->fd = hnd->fd; } struct clipRectRegion : public copybit_region_t { @@ -109,7 +114,7 @@ static inline int fixedToByte(GGLfixed val) { static bool checkContext(ogles_context_t* c) { - // By convenction copybitQuickCheckContext() has already returned true. + // By convention copybitQuickCheckContext() has already returned true. // avoid checking the same information again. if (c->copybits.blitEngine == NULL @@ -118,7 +123,7 @@ static bool checkContext(ogles_context_t* c) { return false; } - // Note: The drawSurfaceFd is only set for destination + // Note: The drawSurfaceBuffer is only set for destination // surfaces types that are supported by the hardware and // do not have an alpha channel. So we don't have to re-check that here. @@ -237,18 +242,20 @@ static bool copybit(GLint x, GLint y, // LOGW("calling copybits"); copybit_device_t* copybit = c->copybits.blitEngine; + copybit_image_t dst; - textureToCopyBitImage(&cbSurface, c->copybits.drawSurfaceFd, &dst); + buffer_handle_t target_hnd = c->copybits.drawSurfaceBuffer; + textureToCopyBitImage(&cbSurface, target_hnd, &dst); copybit_rect_t drect = {x, y, x+w, y+h}; + // we know private_handle_t is good here copybit_image_t src; - textureToCopyBitImage(&textureObject->surface, textureObject->copybits_fd, - &src); + buffer_handle_t source_hnd = textureObject->buffer->handle; + textureToCopyBitImage(&textureObject->surface, source_hnd, &src); copybit_rect_t srect = { Ucr, Vcr + Hcr, Ucr + Wcr, Vcr }; copybit->set_parameter(copybit, COPYBIT_TRANSFORM, transform); copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, planeAlpha); - copybit->set_parameter(copybit, COPYBIT_DITHER, (enables & GGL_ENABLE_DITHER) ? COPYBIT_ENABLE : COPYBIT_DISABLE); diff --git a/opengl/libagl/copybit.h b/opengl/libagl/copybit.h index 1888aee1929e..401b68c2914a 100644 --- a/opengl/libagl/copybit.h +++ b/opengl/libagl/copybit.h @@ -32,9 +32,9 @@ bool drawTrangleFanWithCopybit_impl(ogles_context_t* c, GLint first, GLsizei count); inline bool copybitQuickCheckContext(ogles_context_t* c) { - return c->copybits.drawSurfaceFd >= 0 + return c->copybits.drawSurfaceBuffer != 0 && c->rasterizer.state.enabled_tmu == 1 - && c->textures.tmu[0].texture->copybits_fd >= 0; + && c->textures.tmu[0].texture->try_copybit; } /* diff --git a/opengl/libagl/egl.cpp b/opengl/libagl/egl.cpp index 0df2bbaa584f..c6d50578869a 100644 --- a/opengl/libagl/egl.cpp +++ b/opengl/libagl/egl.cpp @@ -551,20 +551,20 @@ EGLBoolean egl_window_surface_v2_t::bindDrawSurface(ogles_context_t* gl) gl->rasterizer.procs.colorBuffer(gl, &buffer); if (depth.data != gl->rasterizer.state.buffers.depth.data) gl->rasterizer.procs.depthBuffer(gl, &depth); + #ifdef LIBAGL_USE_GRALLOC_COPYBITS - gl->copybits.drawSurfaceFd = -1; + gl->copybits.drawSurfaceBuffer = 0; if (supportedCopybitsDestinationFormat(buffer.format)) { buffer_handle_t handle = this->buffer->handle; if (handle != NULL) { private_handle_t* hand = private_handle_t::dynamicCast(handle); - if (hand != NULL) { - if (hand->usesPhysicallyContiguousMemory()) { - gl->copybits.drawSurfaceFd = hand->fd; - } + if (hand != NULL && hand->usesPhysicallyContiguousMemory()) { + gl->copybits.drawSurfaceBuffer = handle; } } } #endif // LIBAGL_USE_GRALLOC_COPYBITS + return EGL_TRUE; } EGLBoolean egl_window_surface_v2_t::bindReadSurface(ogles_context_t* gl) diff --git a/opengl/libagl/state.cpp b/opengl/libagl/state.cpp index a00f779d6d35..a59b3b046e3f 100644 --- a/opengl/libagl/state.cpp +++ b/opengl/libagl/state.cpp @@ -101,7 +101,7 @@ ogles_context_t *ogles_init(size_t extra) c->copybits.blitEngine = NULL; c->copybits.minScale = 0; c->copybits.maxScale = 0; - c->copybits.drawSurfaceFd = -1; + c->copybits.drawSurfaceBuffer = 0; #ifdef LIBAGL_USE_GRALLOC_COPYBITS hw_module_t const* module; diff --git a/opengl/libagl/texture.cpp b/opengl/libagl/texture.cpp index d675107ca0b1..05fd46e5a2b0 100644 --- a/opengl/libagl/texture.cpp +++ b/opengl/libagl/texture.cpp @@ -1544,12 +1544,10 @@ void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) * */ #ifdef LIBAGL_USE_GRALLOC_COPYBITS - tex->copybits_fd = -1; - private_handle_t* hand; - if ((hand = private_handle_t::dynamicCast(native_buffer->handle)) != NULL) { - if (hand->usesPhysicallyContiguousMemory()) { - tex->copybits_fd = hand->fd; - } + tex->try_copybit = false; + private_handle_t* hnd = private_handle_t::dynamicCast(native_buffer->handle); + if (hnd && hnd->usesPhysicallyContiguousMemory()) { + tex->try_copybit = true; } #endif // LIBAGL_USE_GRALLOC_COPYBITS } diff --git a/opengl/tests/copybits/copybits.cpp b/opengl/tests/copybits/copybits.cpp index d15526c65e94..f8ca9b2e0eee 100644 --- a/opengl/tests/copybits/copybits.cpp +++ b/opengl/tests/copybits/copybits.cpp @@ -96,13 +96,11 @@ private: status_t initSize(uint32_t w, uint32_t h); ssize_t mInitCheck; - uint32_t mFlags; - uint32_t mVStride; void* mData; }; Buffer::Buffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage) - : SurfaceBuffer(), mInitCheck(NO_INIT), mVStride(0) + : SurfaceBuffer(), mInitCheck(NO_INIT) { this->usage = usage; this->format = format; @@ -137,7 +135,6 @@ status_t Buffer::initSize(uint32_t w, uint32_t h) if (err == NO_ERROR) { width = w; height = h; - mVStride = 0; } } @@ -154,7 +151,6 @@ status_t Buffer::lock(GGLSurface* sur, uint32_t usage) sur->height = height; sur->stride = stride; sur->format = format; - sur->vstride = mVStride; sur->data = static_cast(vaddr); } return res; @@ -355,7 +351,7 @@ void init_scene(void) // #define USE_ALPHA_COLOR #define USE_GL_REPLACE -// #define USE_GL_MODULATE +//#define USE_GL_MODULATE // #define USE_BLEND @@ -479,7 +475,7 @@ static const int SCALE_COUNT = 12; int scale(int base, int factor) { static const float kTable[SCALE_COUNT] = { - 0.1f, 0.25f, 0.5f, 0.75f, 1.0f, + 0.24f, 0.25f, 0.5f, 0.75f, 1.0f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 5.0f }; return base * kTable[factor]; @@ -570,10 +566,10 @@ int testStretch() return -1; } // Need to do a dummy eglSwapBuffers first. Don't know why. - glClearColor(0.4, 1.0, 0.4, 0.4); + glClearColor(0.4, 1.0, 0.4, 1.0); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); eglSwapBuffers(eglDisplay, eglSurface); - + int cropRect[4] = {0,HEIGHT,WIDTH,-HEIGHT}; // Left bottom width height. Width and Height can be neg to flip. glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect); @@ -592,6 +588,8 @@ int testStretch() } eglSwapBuffers(eglDisplay, eglSurface); + LOGD("wait 1s"); + usleep(1000000); } return 0; } -- cgit v1.2.3-59-g8ed1b