diff options
author | Romain Guy <romainguy@google.com> | 2011-05-02 17:24:22 -0700 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2011-05-02 18:32:29 -0700 |
commit | 8f0095cd33558e9cc8a440047908e53b68906f5f (patch) | |
tree | 2f55d779bf102e0c134357d89c7de69d0444634a /libs | |
parent | 3a5c227279011f850036c29e7c0bc96023298d5c (diff) | |
download | frameworks_base-8f0095cd33558e9cc8a440047908e53b68906f5f.zip frameworks_base-8f0095cd33558e9cc8a440047908e53b68906f5f.tar.gz frameworks_base-8f0095cd33558e9cc8a440047908e53b68906f5f.tar.bz2 |
Allows to render with an OpenGL context inside a TextureView.
Change-Id: I59453f7fc3997f0502a1c5d325d37fed376fabc7
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/Layer.h | 6 | ||||
-rw-r--r-- | libs/hwui/LayerRenderer.cpp | 21 | ||||
-rw-r--r-- | libs/hwui/LayerRenderer.h | 2 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 21 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.h | 3 | ||||
-rw-r--r-- | libs/hwui/ProgramCache.cpp | 12 | ||||
-rw-r--r-- | libs/hwui/ProgramCache.h | 4 |
7 files changed, 45 insertions, 24 deletions
diff --git a/libs/hwui/Layer.h b/libs/hwui/Layer.h index 16566b8..0310bc3 100644 --- a/libs/hwui/Layer.h +++ b/libs/hwui/Layer.h @@ -47,6 +47,7 @@ struct Layer { meshElementCount = 0; isCacheable = true; isTextureLayer = false; + renderTarget = GL_TEXTURE_2D; } ~Layer() { @@ -155,6 +156,11 @@ struct Layer { * Optional texture coordinates transform. */ mat4 texTransform; + + /** + * Indicates the render target. + */ + GLenum renderTarget; }; // struct Layer }; // namespace uirenderer diff --git a/libs/hwui/LayerRenderer.cpp b/libs/hwui/LayerRenderer.cpp index e167336..f316ba7 100644 --- a/libs/hwui/LayerRenderer.cpp +++ b/libs/hwui/LayerRenderer.cpp @@ -185,17 +185,7 @@ Layer* LayerRenderer::createTextureLayer() { layer->region.clear(); glActiveTexture(GL_TEXTURE0); - glGenTextures(1, &layer->texture); - glBindTexture(GL_TEXTURE_EXTERNAL_OES, layer->texture); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - - glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); return layer; } @@ -280,7 +270,7 @@ bool LayerRenderer::resizeLayer(Layer* layer, uint32_t width, uint32_t height) { } void LayerRenderer::updateTextureLayer(Layer* layer, uint32_t width, uint32_t height, - float* transform) { + GLenum renderTarget, float* transform) { if (layer) { layer->width = width; layer->height = height; @@ -288,6 +278,15 @@ void LayerRenderer::updateTextureLayer(Layer* layer, uint32_t width, uint32_t he layer->region.set(width, height); layer->regionRect.set(0.0f, 0.0f, width, height); layer->texTransform.load(transform); + layer->renderTarget = renderTarget; + + glBindTexture(layer->renderTarget, layer->texture); + + glTexParameteri(layer->renderTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(layer->renderTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexParameteri(layer->renderTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(layer->renderTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } } diff --git a/libs/hwui/LayerRenderer.h b/libs/hwui/LayerRenderer.h index b3cd5db..59cab96 100644 --- a/libs/hwui/LayerRenderer.h +++ b/libs/hwui/LayerRenderer.h @@ -57,7 +57,7 @@ public: static Layer* createLayer(uint32_t width, uint32_t height, bool isOpaque = false); static bool resizeLayer(Layer* layer, uint32_t width, uint32_t height); static void updateTextureLayer(Layer* layer, uint32_t width, uint32_t height, - float* transform); + GLenum renderTarget, float* transform); static void destroyLayer(Layer* layer); static void destroyLayerDeferred(Layer* layer); diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 34d8fd3..71976cd 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -637,7 +637,12 @@ void OpenGLRenderer::drawTextureLayer(Layer* layer, const Rect& rect) { float alpha = layer->alpha / 255.0f; setupDraw(); - setupDrawWithExternalTexture(); + if (layer->renderTarget == GL_TEXTURE_2D) { + setupDrawWithTexture(); + } else { + setupDrawWithExternalTexture(); + } + setupDrawTextureTransform(); setupDrawColor(alpha, alpha, alpha, alpha); setupDrawColorFilter(); setupDrawBlending(layer->blend, layer->mode); @@ -645,8 +650,12 @@ void OpenGLRenderer::drawTextureLayer(Layer* layer, const Rect& rect) { setupDrawModelView(rect.left, rect.top, rect.right, rect.bottom); setupDrawPureColorUniforms(); setupDrawColorFilterUniforms(); - setupDrawExternalTexture(layer->texture); - setupDrawTextureTransform(layer->texTransform); + if (layer->renderTarget == GL_TEXTURE_2D) { + setupDrawTexture(layer->texture); + } else { + setupDrawExternalTexture(layer->texture); + } + setupDrawTextureTransformUniforms(layer->texTransform); setupDrawMesh(&mMeshVertices[0].position[0], &mMeshVertices[0].texture[0]); glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount); @@ -1095,7 +1104,11 @@ void OpenGLRenderer::setupDrawExternalTexture(GLuint texture) { glEnableVertexAttribArray(mTexCoordsSlot); } -void OpenGLRenderer::setupDrawTextureTransform(mat4& transform) { +void OpenGLRenderer::setupDrawTextureTransform() { + mDescription.hasTextureTransform = true; +} + +void OpenGLRenderer::setupDrawTextureTransformUniforms(mat4& transform) { glUniformMatrix4fv(mCaches.currentProgram->getUniform("mainTextureTransform"), 1, GL_FALSE, &transform.data[0]); } diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h index 0ffd70b..22309f8 100644 --- a/libs/hwui/OpenGLRenderer.h +++ b/libs/hwui/OpenGLRenderer.h @@ -465,7 +465,8 @@ private: void setupDrawSimpleMesh(); void setupDrawTexture(GLuint texture); void setupDrawExternalTexture(GLuint texture); - void setupDrawTextureTransform(mat4& transform); + void setupDrawTextureTransform(); + void setupDrawTextureTransformUniforms(mat4& transform); void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords = NULL, GLuint vbo = 0); void setupDrawVertices(GLvoid* vertices); void setupDrawAALine(GLvoid* vertices, GLvoid* distanceCoords, float strokeWidth); diff --git a/libs/hwui/ProgramCache.cpp b/libs/hwui/ProgramCache.cpp index 62ac2ba..297f5a9 100644 --- a/libs/hwui/ProgramCache.cpp +++ b/libs/hwui/ProgramCache.cpp @@ -385,7 +385,7 @@ String8 ProgramCache::generateVertexShader(const ProgramDescription& description } // Uniforms shader.append(gVS_Header_Uniforms); - if (description.hasExternalTexture) { + if (description.hasTextureTransform) { shader.append(gVS_Header_Uniforms_TextureTransform); } if (description.hasGradient) { @@ -415,11 +415,10 @@ String8 ProgramCache::generateVertexShader(const ProgramDescription& description // Begin the shader shader.append(gVS_Main); { - if (description.hasTexture) { - shader.append(gVS_Main_OutTexCoords); - } - if (description.hasExternalTexture) { + if (description.hasTextureTransform) { shader.append(gVS_Main_OutTransformedTexCoords); + } else if (description.hasTexture || description.hasExternalTexture) { + shader.append(gVS_Main_OutTexCoords); } if (description.hasWidth) { shader.append(gVS_Main_Width); @@ -487,8 +486,7 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti } if (description.hasTexture) { shader.append(gFS_Uniforms_TextureSampler); - } - if (description.hasExternalTexture) { + } else if (description.hasExternalTexture) { shader.append(gFS_Uniforms_ExternalTextureSampler); } if (description.hasWidth) { diff --git a/libs/hwui/ProgramCache.h b/libs/hwui/ProgramCache.h index 70909fd..21eb099 100644 --- a/libs/hwui/ProgramCache.h +++ b/libs/hwui/ProgramCache.h @@ -78,6 +78,7 @@ namespace uirenderer { #define PROGRAM_HAS_WIDTH_SHIFT 37 #define PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT 38 +#define PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT 39 /////////////////////////////////////////////////////////////////////////////// // Types @@ -116,6 +117,7 @@ struct ProgramDescription { bool hasTexture; bool hasAlpha8Texture; bool hasExternalTexture; + bool hasTextureTransform; // Modulate, this should only be set when setColor() return true bool modulate; @@ -155,6 +157,7 @@ struct ProgramDescription { hasTexture = false; hasAlpha8Texture = false; hasExternalTexture = false; + hasTextureTransform = false; hasWidth = false; @@ -245,6 +248,7 @@ struct ProgramDescription { if (isPoint) key |= programid(0x1) << PROGRAM_IS_POINT_SHIFT; if (hasWidth) key |= programid(0x1) << PROGRAM_HAS_WIDTH_SHIFT; if (hasExternalTexture) key |= programid(0x1) << PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT; + if (hasTextureTransform) key |= programid(0x1) << PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT; return key; } |