diff options
author | Chris Craik <ccraik@google.com> | 2015-02-05 00:25:03 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-02-05 00:25:04 +0000 |
commit | ecad24b49d20f7fb4b75950e9444787967acd347 (patch) | |
tree | 74c55efb6736b3b142a299f2c1feae32abf06b7a /libs/hwui/renderstate | |
parent | e8d05b5bab49f2becb1762b70275d3914de23be2 (diff) | |
parent | 031888744e24b5c7243ac99ec98b78aff5db1c78 (diff) | |
download | frameworks_base-ecad24b49d20f7fb4b75950e9444787967acd347.zip frameworks_base-ecad24b49d20f7fb4b75950e9444787967acd347.tar.gz frameworks_base-ecad24b49d20f7fb4b75950e9444787967acd347.tar.bz2 |
Merge "GlopBuilder, and test app refactor"
Diffstat (limited to 'libs/hwui/renderstate')
-rw-r--r-- | libs/hwui/renderstate/Blend.cpp | 41 | ||||
-rw-r--r-- | libs/hwui/renderstate/Blend.h | 3 | ||||
-rw-r--r-- | libs/hwui/renderstate/MeshState.cpp | 14 | ||||
-rw-r--r-- | libs/hwui/renderstate/MeshState.h | 8 | ||||
-rw-r--r-- | libs/hwui/renderstate/RenderState.cpp | 11 |
5 files changed, 47 insertions, 30 deletions
diff --git a/libs/hwui/renderstate/Blend.cpp b/libs/hwui/renderstate/Blend.cpp index 3e7b721..93088e4 100644 --- a/libs/hwui/renderstate/Blend.cpp +++ b/libs/hwui/renderstate/Blend.cpp @@ -79,21 +79,10 @@ Blend::Blend() } void Blend::enable(SkXfermode::Mode mode, bool swapSrcDst) { - // enable - if (!mEnabled) { - glEnable(GL_BLEND); - mEnabled = true; - } - - // select blend mode - GLenum sourceMode = swapSrcDst ? kBlendsSwap[mode].src : kBlends[mode].src; - GLenum destMode = swapSrcDst ? kBlendsSwap[mode].dst : kBlends[mode].dst; - - if (sourceMode != mSrcMode || destMode != mSrcMode) { - glBlendFunc(sourceMode, destMode); - mSrcMode = sourceMode; - mDstMode = destMode; - } + GLenum srcMode; + GLenum dstMode; + getFactors(mode, swapSrcDst, &srcMode, &dstMode); + setFactors(srcMode, dstMode); } void Blend::disable() { @@ -116,6 +105,28 @@ void Blend::syncEnabled() { } } +void Blend::getFactors(SkXfermode::Mode mode, bool swapSrcDst, GLenum* outSrc, GLenum* outDst) { + *outSrc = swapSrcDst ? kBlendsSwap[mode].src : kBlends[mode].src; + *outDst = swapSrcDst ? kBlendsSwap[mode].dst : kBlends[mode].dst; +} + +void Blend::setFactors(GLenum srcMode, GLenum dstMode) { + if (srcMode == GL_ZERO && dstMode == GL_ZERO) { + disable(); + } else { + if (!mEnabled) { + glEnable(GL_BLEND); + mEnabled = true; + } + + if (srcMode != mSrcMode || dstMode != mSrcMode) { + glBlendFunc(srcMode, dstMode); + mSrcMode = srcMode; + mDstMode = dstMode; + } + } +} + } /* namespace uirenderer */ } /* namespace android */ diff --git a/libs/hwui/renderstate/Blend.h b/libs/hwui/renderstate/Blend.h index b82b477..31d7dde 100644 --- a/libs/hwui/renderstate/Blend.h +++ b/libs/hwui/renderstate/Blend.h @@ -32,6 +32,9 @@ public: void enable(SkXfermode::Mode mode, bool swapSrcDst); void disable(); void syncEnabled(); + + static void getFactors(SkXfermode::Mode mode, bool swapSrcDst, GLenum* outSrc, GLenum* outDst); + void setFactors(GLenum src, GLenum dst); private: Blend(); void invalidate(); diff --git a/libs/hwui/renderstate/MeshState.cpp b/libs/hwui/renderstate/MeshState.cpp index 022faf7..50c09c8 100644 --- a/libs/hwui/renderstate/MeshState.cpp +++ b/libs/hwui/renderstate/MeshState.cpp @@ -29,11 +29,11 @@ MeshState::MeshState() , mCurrentTexCoordsStride(0) , mTexCoordsArrayEnabled(false) { - glGenBuffers(1, &meshBuffer); - glBindBuffer(GL_ARRAY_BUFFER, meshBuffer); - glBufferData(GL_ARRAY_BUFFER, sizeof(kMeshVertices), kMeshVertices, GL_STATIC_DRAW); + glGenBuffers(1, &mUnitQuadBuffer); + glBindBuffer(GL_ARRAY_BUFFER, mUnitQuadBuffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(kUnitQuadVertices), kUnitQuadVertices, GL_STATIC_DRAW); - mCurrentBuffer = meshBuffer; + mCurrentBuffer = mUnitQuadBuffer; mCurrentIndicesBuffer = 0; mCurrentPixelBuffer = 0; @@ -45,7 +45,7 @@ MeshState::MeshState() } MeshState::~MeshState() { - glDeleteBuffers(1, &meshBuffer); + glDeleteBuffers(1, &mUnitQuadBuffer); mCurrentBuffer = 0; glDeleteBuffers(1, &mQuadListIndices); @@ -60,11 +60,11 @@ MeshState::~MeshState() { /////////////////////////////////////////////////////////////////////////////// bool MeshState::bindMeshBuffer() { - return bindMeshBuffer(meshBuffer); + return bindMeshBuffer(mUnitQuadBuffer); } bool MeshState::bindMeshBuffer(GLuint buffer) { - if (!buffer) buffer = meshBuffer; + if (!buffer) buffer = mUnitQuadBuffer; if (mCurrentBuffer != buffer) { glBindBuffer(GL_ARRAY_BUFFER, buffer); mCurrentBuffer = buffer; diff --git a/libs/hwui/renderstate/MeshState.h b/libs/hwui/renderstate/MeshState.h index 9b1021d..5cb1143 100644 --- a/libs/hwui/renderstate/MeshState.h +++ b/libs/hwui/renderstate/MeshState.h @@ -32,7 +32,7 @@ const uint32_t kMaxNumberOfQuads = 2048; // This array is never used directly but used as a memcpy source in the // OpenGLRenderer constructor -const TextureVertex kMeshVertices[] = { +const TextureVertex kUnitQuadVertices[] = { { 0, 0, 0, 0 }, { 1, 0, 1, 0 }, { 0, 1, 0, 1 }, @@ -110,12 +110,16 @@ public: bool bindShadowIndicesBuffer(); bool unbindIndicesBuffer(); + /////////////////////////////////////////////////////////////////////////////// + // Getters - for use in Glop building + /////////////////////////////////////////////////////////////////////////////// + GLuint getUnitQuadVBO() { return mUnitQuadBuffer; } private: MeshState(); bool bindIndicesBufferInternal(const GLuint buffer); // VBO to draw with - GLuint meshBuffer; + GLuint mUnitQuadBuffer; GLuint mCurrentBuffer; GLuint mCurrentIndicesBuffer; diff --git a/libs/hwui/renderstate/RenderState.cpp b/libs/hwui/renderstate/RenderState.cpp index 5e02844..0cb3ddb 100644 --- a/libs/hwui/renderstate/RenderState.cpp +++ b/libs/hwui/renderstate/RenderState.cpp @@ -219,7 +219,7 @@ void RenderState::render(const Glop& glop) { mCaches->setProgram(shader.program); Glop::Fill::Color color = shader.color; - shader.program->setColor(color.a, color.r, color.g, color.b); + shader.program->setColor(color.r, color.g, color.b, color.a); shader.program->set(glop.transform.ortho, glop.transform.modelView, @@ -261,14 +261,13 @@ void RenderState::render(const Glop& glop) { meshState().bindIndicesBufferInternal(mesh.indexBufferObject); // ---------- GL state setup ---------- + blend().setFactors(glop.blend.src, glop.blend.dst); - if (glop.blend.mode != Glop::Blend::kDisable) { - blend().enable(glop.blend.mode, glop.blend.swapSrcDst); + if (mesh.indexBufferObject) { + glDrawElements(glop.mesh.primitiveMode, glop.mesh.vertexCount, GL_UNSIGNED_BYTE, nullptr); } else { - blend().disable(); + glDrawArrays(GL_TRIANGLE_STRIP, 0, glop.mesh.vertexCount); } - - glDrawElements(glop.mesh.primitiveMode, glop.mesh.vertexCount, GL_UNSIGNED_BYTE, nullptr); } } /* namespace uirenderer */ |