diff options
author | Chris Craik <ccraik@google.com> | 2015-02-03 00:00:57 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-02-03 00:00:58 +0000 |
commit | 9dfd7bd520ee598b3033a0c47b8b649bd3988c7c (patch) | |
tree | 73de6cf28c9296701cb202addfbf51cea6833d62 /libs/hwui/OpenGLRenderer.cpp | |
parent | d8f32ea2dffd3f6a080b4eb55a11c0f1c6d7a3a6 (diff) | |
parent | 6c15ffa196fc9b7724c189d833c3435d8db12266 (diff) | |
download | frameworks_base-9dfd7bd520ee598b3033a0c47b8b649bd3988c7c.zip frameworks_base-9dfd7bd520ee598b3033a0c47b8b649bd3988c7c.tar.gz frameworks_base-9dfd7bd520ee598b3033a0c47b8b649bd3988c7c.tar.bz2 |
Merge "Refactoring of Program ownership/lifecycle, and WIP Glop rendering path"
Diffstat (limited to 'libs/hwui/OpenGLRenderer.cpp')
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 75 |
1 files changed, 29 insertions, 46 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 3ee9808..b56ce4f 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -14,8 +14,6 @@ * limitations under the License. */ -#define LOG_TAG "OpenGLRenderer" - #include "OpenGLRenderer.h" #include "DeferredDisplayList.h" @@ -136,8 +134,6 @@ void OpenGLRenderer::initLight(const Vector3& lightCenter, float lightRadius, void OpenGLRenderer::onViewportInitialized() { glDisable(GL_DITHER); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - - glEnableVertexAttribArray(Program::kBindingPosition); mFirstFrameAfterResize = true; } @@ -1714,20 +1710,20 @@ void OpenGLRenderer::setupDrawBlending(const SkPaint* paint, bool blend, bool sw } void OpenGLRenderer::setupDrawProgram() { - useProgram(mCaches.programCache.get(mDescription)); + mCaches.setProgram(mDescription); if (mDescription.hasRoundRectClip) { // TODO: avoid doing this repeatedly, stashing state pointer in program const RoundRectClipState* state = writableSnapshot()->roundRectClipState; const Rect& innerRect = state->innerRect; - glUniform4f(mCaches.currentProgram->getUniform("roundRectInnerRectLTRB"), + glUniform4f(mCaches.program().getUniform("roundRectInnerRectLTRB"), innerRect.left, innerRect.top, innerRect.right, innerRect.bottom); - glUniformMatrix4fv(mCaches.currentProgram->getUniform("roundRectInvTransform"), + glUniformMatrix4fv(mCaches.program().getUniform("roundRectInvTransform"), 1, GL_FALSE, &state->matrix.data[0]); // add half pixel to round out integer rect space to cover pixel centers float roundedOutRadius = state->radius + 0.5f; - glUniform1f(mCaches.currentProgram->getUniform("roundRectRadius"), + glUniform1f(mCaches.program().getUniform("roundRectRadius"), roundedOutRadius); } } @@ -1745,7 +1741,8 @@ void OpenGLRenderer::setupDrawModelView(ModelViewMode mode, bool offset, bool dirty = right - left > 0.0f && bottom - top > 0.0f; const Matrix4& transformMatrix = ignoreTransform ? Matrix4::identity() : *currentTransform(); - mCaches.currentProgram->set(writableSnapshot()->getOrthoMatrix(), + + mCaches.program().set(currentSnapshot()->getOrthoMatrix(), mModelViewMatrix, transformMatrix, offset); if (dirty && mTrackDirtyRegions) { if (!ignoreTransform) { @@ -1758,13 +1755,13 @@ void OpenGLRenderer::setupDrawModelView(ModelViewMode mode, bool offset, void OpenGLRenderer::setupDrawColorUniforms(bool hasShader) { if ((mColorSet && !hasShader) || (hasShader && mSetShaderColor)) { - mCaches.currentProgram->setColor(mColorR, mColorG, mColorB, mColorA); + mCaches.program().setColor(mColorR, mColorG, mColorB, mColorA); } } void OpenGLRenderer::setupDrawPureColorUniforms() { if (mSetShaderColor) { - mCaches.currentProgram->setColor(mColorR, mColorG, mColorB, mColorA); + mCaches.program().setColor(mColorR, mColorG, mColorB, mColorA); } } @@ -1799,7 +1796,7 @@ void OpenGLRenderer::setupDrawColorFilterUniforms(const SkColorFilter* filter) { const GLfloat r = a * SkColorGetR(color) / 255.0f; const GLfloat g = a * SkColorGetG(color) / 255.0f; const GLfloat b = a * SkColorGetB(color) / 255.0f; - glUniform4f(mCaches.currentProgram->getUniform("colorBlend"), r, g, b, a); + glUniform4f(mCaches.program().getUniform("colorBlend"), r, g, b, a); return; } @@ -1820,9 +1817,9 @@ void OpenGLRenderer::setupDrawColorFilterUniforms(const SkColorFilter* filter) { colorVector[2] = srcColorMatrix[14] / 255.0f; colorVector[3] = srcColorMatrix[19] / 255.0f; - glUniformMatrix4fv(mCaches.currentProgram->getUniform("colorMatrix"), 1, + glUniformMatrix4fv(mCaches.program().getUniform("colorMatrix"), 1, GL_FALSE, colorMatrix); - glUniform4fv(mCaches.currentProgram->getUniform("colorMatrixVector"), 1, colorVector); + glUniform4fv(mCaches.program().getUniform("colorMatrixVector"), 1, colorVector); return; } @@ -1830,12 +1827,12 @@ void OpenGLRenderer::setupDrawColorFilterUniforms(const SkColorFilter* filter) { } void OpenGLRenderer::setupDrawTextGammaUniforms() { - mCaches.fontRenderer->setupProgram(mDescription, mCaches.currentProgram); + mCaches.fontRenderer->setupProgram(mDescription, mCaches.program()); } void OpenGLRenderer::setupDrawSimpleMesh() { bool force = mRenderState.meshState().bindMeshBuffer(); - mRenderState.meshState().bindPositionVertexPointer(mCaches.currentProgram, force, nullptr); + mRenderState.meshState().bindPositionVertexPointer(force, nullptr); mRenderState.meshState().unbindIndicesBuffer(); } @@ -1856,7 +1853,7 @@ void OpenGLRenderer::setupDrawTextureTransform() { } void OpenGLRenderer::setupDrawTextureTransformUniforms(mat4& transform) { - glUniformMatrix4fv(mCaches.currentProgram->getUniform("mainTextureTransform"), 1, + glUniformMatrix4fv(mCaches.program().getUniform("mainTextureTransform"), 1, GL_FALSE, &transform.data[0]); } @@ -1869,9 +1866,9 @@ void OpenGLRenderer::setupDrawMesh(const GLvoid* vertices, force = mRenderState.meshState().unbindMeshBuffer(); } - mRenderState.meshState().bindPositionVertexPointer(mCaches.currentProgram, force, vertices); - if (mCaches.currentProgram->texCoords >= 0) { - mRenderState.meshState().bindTexCoordsVertexPointer(mCaches.currentProgram, force, texCoords); + mRenderState.meshState().bindPositionVertexPointer(force, vertices); + if (mCaches.program().texCoords >= 0) { + mRenderState.meshState().bindTexCoordsVertexPointer(force, texCoords); } mRenderState.meshState().unbindIndicesBuffer(); @@ -1882,13 +1879,11 @@ void OpenGLRenderer::setupDrawMesh(const GLvoid* vertices, bool force = mRenderState.meshState().unbindMeshBuffer(); GLsizei stride = sizeof(ColorTextureVertex); - mRenderState.meshState().bindPositionVertexPointer(mCaches.currentProgram, force, - vertices, stride); - if (mCaches.currentProgram->texCoords >= 0) { - mRenderState.meshState().bindTexCoordsVertexPointer(mCaches.currentProgram, force, - texCoords, stride); + mRenderState.meshState().bindPositionVertexPointer(force, vertices, stride); + if (mCaches.program().texCoords >= 0) { + mRenderState.meshState().bindTexCoordsVertexPointer(force, texCoords, stride); } - int slot = mCaches.currentProgram->getAttrib("colors"); + int slot = mCaches.program().getAttrib("colors"); if (slot >= 0) { glEnableVertexAttribArray(slot); glVertexAttribPointer(slot, 4, GL_FLOAT, GL_FALSE, stride, colors); @@ -1910,18 +1905,16 @@ void OpenGLRenderer::setupDrawMeshIndices(const GLvoid* vertices, } mRenderState.meshState().bindQuadIndicesBuffer(); - mRenderState.meshState().bindPositionVertexPointer(mCaches.currentProgram, force, vertices); - if (mCaches.currentProgram->texCoords >= 0) { - mRenderState.meshState().bindTexCoordsVertexPointer(mCaches.currentProgram, - force, texCoords); + mRenderState.meshState().bindPositionVertexPointer(force, vertices); + if (mCaches.program().texCoords >= 0) { + mRenderState.meshState().bindTexCoordsVertexPointer(force, texCoords); } } void OpenGLRenderer::setupDrawIndexedVertices(GLvoid* vertices) { bool force = mRenderState.meshState().unbindMeshBuffer(); mRenderState.meshState().bindQuadIndicesBuffer(); - mRenderState.meshState().bindPositionVertexPointer(mCaches.currentProgram, force, - vertices, kVertexStride); + mRenderState.meshState().bindPositionVertexPointer(force, vertices, kVertexStride); } /////////////////////////////////////////////////////////////////////////////// @@ -2143,7 +2136,7 @@ void OpenGLRenderer::drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int m glDrawArrays(GL_TRIANGLES, 0, count); - int slot = mCaches.currentProgram->getAttrib("colors"); + int slot = mCaches.program().getAttrib("colors"); if (slot >= 0) { glDisableVertexAttribArray(slot); } @@ -2359,14 +2352,14 @@ void OpenGLRenderer::drawVertexBuffer(float translateX, float translateY, const void* vertices = vertexBuffer.getBuffer(); mRenderState.meshState().unbindMeshBuffer(); - mRenderState.meshState().bindPositionVertexPointer(mCaches.currentProgram, - true, vertices, isAA ? kAlphaVertexStride : kVertexStride); + mRenderState.meshState().bindPositionVertexPointer(true, vertices, + isAA ? kAlphaVertexStride : kVertexStride); mRenderState.meshState().resetTexCoordsVertexPointer(); int alphaSlot = -1; if (isAA) { void* alphaCoords = ((GLbyte*) vertices) + kVertexAlphaOffset; - alphaSlot = mCaches.currentProgram->getAttrib("vtxAlpha"); + alphaSlot = mCaches.program().getAttrib("vtxAlpha"); // TODO: avoid enable/disable in back to back uses of the alpha attribute glEnableVertexAttribArray(alphaSlot); glVertexAttribPointer(alphaSlot, 1, GL_FLOAT, GL_FALSE, kAlphaVertexStride, alphaCoords); @@ -3439,16 +3432,6 @@ void OpenGLRenderer::chooseBlending(bool blend, SkXfermode::Mode mode, } } -bool OpenGLRenderer::useProgram(Program* program) { - if (!program->isInUse()) { - if (mCaches.currentProgram != nullptr) mCaches.currentProgram->remove(); - program->use(); - mCaches.currentProgram = program; - return false; - } - return true; -} - void OpenGLRenderer::resetDrawTextureTexCoords(float u1, float v1, float u2, float v2) { TextureVertex* v = &mMeshVertices[0]; TextureVertex::setUV(v++, u1, v1); |