diff options
-rw-r--r-- | core/jni/android_view_HardwareLayer.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/Caches.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/DeferredLayerUpdater.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/Glop.h | 10 | ||||
-rw-r--r-- | libs/hwui/GlopBuilder.cpp | 118 | ||||
-rw-r--r-- | libs/hwui/GlopBuilder.h | 8 | ||||
-rw-r--r-- | libs/hwui/Layer.h | 6 | ||||
-rw-r--r-- | libs/hwui/LayerRenderer.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 147 | ||||
-rw-r--r-- | libs/hwui/renderstate/MeshState.cpp | 1 | ||||
-rw-r--r-- | libs/hwui/renderstate/RenderState.cpp | 22 | ||||
-rw-r--r-- | libs/hwui/renderstate/TextureState.cpp | 2 |
12 files changed, 193 insertions, 129 deletions
diff --git a/core/jni/android_view_HardwareLayer.cpp b/core/jni/android_view_HardwareLayer.cpp index f539127..9e49afb 100644 --- a/core/jni/android_view_HardwareLayer.cpp +++ b/core/jni/android_view_HardwareLayer.cpp @@ -82,7 +82,7 @@ static void android_view_HardwareLayer_updateSurfaceTexture(JNIEnv* env, jobject static jint android_view_HardwareLayer_getTexName(JNIEnv* env, jobject clazz, jlong layerUpdaterPtr) { DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr); - return layer->backingLayer()->getTexture(); + return layer->backingLayer()->getTextureId(); } // ---------------------------------------------------------------------------- diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp index f4fc068..a0a2bed 100644 --- a/libs/hwui/Caches.cpp +++ b/libs/hwui/Caches.cpp @@ -263,7 +263,7 @@ void Caches::dumpMemoryUsage(String8 &log) { const Layer* layer = *it; log.appendFormat(" Layer size %dx%d; isTextureLayer()=%d; texid=%u fbo=%u; refs=%d\n", layer->getWidth(), layer->getHeight(), - layer->isTextureLayer(), layer->getTexture(), + layer->isTextureLayer(), layer->getTextureId(), layer->getFbo(), layer->getStrongCount()); memused += layer->getWidth() * layer->getHeight() * 4; } diff --git a/libs/hwui/DeferredLayerUpdater.cpp b/libs/hwui/DeferredLayerUpdater.cpp index 0792120..6a59a13 100644 --- a/libs/hwui/DeferredLayerUpdater.cpp +++ b/libs/hwui/DeferredLayerUpdater.cpp @@ -62,7 +62,7 @@ bool DeferredLayerUpdater::apply() { if (mSurfaceTexture.get()) { if (mNeedsGLContextAttach) { mNeedsGLContextAttach = false; - mSurfaceTexture->attachToContext(mLayer->getTexture()); + mSurfaceTexture->attachToContext(mLayer->getTextureId()); } if (mUpdateTexImage) { mUpdateTexImage = false; diff --git a/libs/hwui/Glop.h b/libs/hwui/Glop.h index 6eca468..e500546 100644 --- a/libs/hwui/Glop.h +++ b/libs/hwui/Glop.h @@ -76,18 +76,20 @@ struct Glop { GLuint indexBufferObject; const void* vertices; const void* indices; + GLvoid* texCoordOffset; int elementCount; GLsizei stride; - GLvoid* texCoordOffset; TextureVertex mappedVertices[4]; } mesh; struct Fill { Program* program; - Texture* texture; - GLenum textureFilter; - GLenum textureClamp; + struct TextureData { + Texture* texture; + GLenum filter; + GLenum clamp; + } texture; bool colorEnabled; FloatColor color; diff --git a/libs/hwui/GlopBuilder.cpp b/libs/hwui/GlopBuilder.cpp index f133d42..4617588 100644 --- a/libs/hwui/GlopBuilder.cpp +++ b/libs/hwui/GlopBuilder.cpp @@ -73,8 +73,7 @@ GlopBuilder& GlopBuilder::setMeshUnitQuad() { return *this; } -GlopBuilder& GlopBuilder::setMeshTexturedUnitQuad(const UvMapper* uvMapper, - bool isAlphaMaskTexture) { +GlopBuilder& GlopBuilder::setMeshTexturedUnitQuad(const UvMapper* uvMapper) { TRIGGER_STAGE(kMeshStage); mOutGlop->mesh.vertexFlags = kTextureCoord_Attrib; @@ -87,19 +86,18 @@ GlopBuilder& GlopBuilder::setMeshTexturedUnitQuad(const UvMapper* uvMapper, mOutGlop->mesh.vertexBufferObject = 0; mOutGlop->mesh.vertices = &mOutGlop->mesh.mappedVertices[0]; + mOutGlop->mesh.texCoordOffset = &mOutGlop->mesh.mappedVertices[0].u; } else { // standard UV coordinates, use regular unit quad VBO mOutGlop->mesh.vertexBufferObject = mRenderState.meshState().getUnitQuadVBO(); mOutGlop->mesh.vertices = nullptr; + mOutGlop->mesh.texCoordOffset = (GLvoid*) kMeshTextureOffset; } mOutGlop->mesh.indexBufferObject = 0; mOutGlop->mesh.indices = nullptr; mOutGlop->mesh.elementCount = 4; mOutGlop->mesh.stride = kTextureVertexStride; - mOutGlop->mesh.texCoordOffset = (GLvoid*) kMeshTextureOffset; - mDescription.hasTexture = true; - mDescription.hasAlpha8Texture = isAlphaMaskTexture; return *this; } @@ -112,13 +110,29 @@ GlopBuilder& GlopBuilder::setMeshIndexedQuads(void* vertexData, int quadCount) { mOutGlop->mesh.vertices = vertexData; mOutGlop->mesh.indexBufferObject = mRenderState.meshState().getQuadListIBO(); mOutGlop->mesh.indices = nullptr; + mOutGlop->mesh.texCoordOffset = nullptr; mOutGlop->mesh.elementCount = 6 * quadCount; mOutGlop->mesh.stride = kVertexStride; - mOutGlop->mesh.texCoordOffset = nullptr; return *this; } +GlopBuilder& GlopBuilder::setMeshTexturedIndexedQuads(TextureVertex* vertexData, int elementCount) { + TRIGGER_STAGE(kMeshStage); + + mOutGlop->mesh.vertexFlags = kTextureCoord_Attrib; + mOutGlop->mesh.primitiveMode = GL_TRIANGLES; + mOutGlop->mesh.vertexBufferObject = 0; + mOutGlop->mesh.vertices = &vertexData[0].x; + mOutGlop->mesh.indexBufferObject = mRenderState.meshState().getQuadListIBO(); + mOutGlop->mesh.indices = nullptr; + mOutGlop->mesh.texCoordOffset = &vertexData[0].u; + mOutGlop->mesh.elementCount = elementCount; + mOutGlop->mesh.stride = kTextureVertexStride; + mDescription.hasTexture = true; + return *this; +} + GlopBuilder& GlopBuilder::setMeshVertexBuffer(const VertexBuffer& vertexBuffer, bool shadowInterp) { TRIGGER_STAGE(kMeshStage); @@ -132,6 +146,7 @@ GlopBuilder& GlopBuilder::setMeshVertexBuffer(const VertexBuffer& vertexBuffer, mOutGlop->mesh.vertices = vertexBuffer.getBuffer(); mOutGlop->mesh.indexBufferObject = 0; mOutGlop->mesh.indices = vertexBuffer.getIndices(); + mOutGlop->mesh.texCoordOffset = nullptr; mOutGlop->mesh.elementCount = indices ? vertexBuffer.getIndexCount() : vertexBuffer.getVertexCount(); mOutGlop->mesh.stride = alphaVertex ? kAlphaVertexStride : kVertexStride; @@ -168,7 +183,7 @@ void GlopBuilder::setFill(int color, float alphaScale, SkXfermode::Mode mode, mOutGlop->blend = { GL_ZERO, GL_ZERO }; if (mOutGlop->fill.color.a < 1.0f || (mOutGlop->mesh.vertexFlags & kAlpha_Attrib) - || (mOutGlop->fill.texture && mOutGlop->fill.texture->blend) + || (mOutGlop->fill.texture.texture && mOutGlop->fill.texture.texture->blend) || mOutGlop->roundRectClipState || PaintUtils::isBlendedShader(shader) || PaintUtils::isBlendedColorFilter(colorFilter) @@ -240,9 +255,7 @@ GlopBuilder& GlopBuilder::setFillTexturePaint(Texture& texture, bool isAlphaMask TRIGGER_STAGE(kFillStage); REQUIRE_STAGES(kMeshStage); - mOutGlop->fill.texture = &texture; - mOutGlop->fill.textureFilter = PaintUtils::getFilter(paint); - mOutGlop->fill.textureClamp = GL_CLAMP_TO_EDGE; + mOutGlop->fill.texture = { &texture, PaintUtils::getFilter(paint), GL_CLAMP_TO_EDGE }; if (paint) { int color = paint->getColor(); @@ -270,6 +283,7 @@ GlopBuilder& GlopBuilder::setFillTexturePaint(Texture& texture, bool isAlphaMask } } + mDescription.hasAlpha8Texture = isAlphaMaskTexture; if (isAlphaMaskTexture) { mDescription.modulate = mOutGlop->fill.color.isNotBlack(); } else { @@ -282,9 +296,7 @@ GlopBuilder& GlopBuilder::setFillPaint(const SkPaint& paint, float alphaScale) { TRIGGER_STAGE(kFillStage); REQUIRE_STAGES(kMeshStage); - mOutGlop->fill.texture = nullptr; - mOutGlop->fill.textureFilter = GL_INVALID_ENUM; - mOutGlop->fill.textureClamp = GL_INVALID_ENUM; + mOutGlop->fill.texture = { nullptr, GL_INVALID_ENUM, GL_INVALID_ENUM }; setFill(paint.getColor(), alphaScale, PaintUtils::getXfermode(paint.getXfermode()), paint.getShader(), paint.getColorFilter()); @@ -297,15 +309,13 @@ GlopBuilder& GlopBuilder::setFillPathTexturePaint(PathTexture& texture, TRIGGER_STAGE(kFillStage); REQUIRE_STAGES(kMeshStage); - mOutGlop->fill.texture = &texture; - - //specify invalid, since these are always static for PathTextures - mOutGlop->fill.textureFilter = GL_INVALID_ENUM; - mOutGlop->fill.textureClamp = GL_INVALID_ENUM; + //specify invalid filter/clamp, since these are always static for PathTextures + mOutGlop->fill.texture = { &texture, GL_INVALID_ENUM, GL_INVALID_ENUM }; setFill(paint.getColor(), alphaScale, PaintUtils::getXfermode(paint.getXfermode()), paint.getShader(), paint.getColorFilter()); + mDescription.hasAlpha8Texture = true; mDescription.modulate = mOutGlop->fill.color.isNotBlack(); return *this; } @@ -315,11 +325,8 @@ GlopBuilder& GlopBuilder::setFillShadowTexturePaint(ShadowTexture& texture, int TRIGGER_STAGE(kFillStage); REQUIRE_STAGES(kMeshStage); - mOutGlop->fill.texture = &texture; - - //specify invalid, since these are always static for ShadowTextures - mOutGlop->fill.textureFilter = GL_INVALID_ENUM; - mOutGlop->fill.textureClamp = GL_INVALID_ENUM; + //specify invalid filter/clamp, since these are always static for ShadowTextures + mOutGlop->fill.texture = { &texture, GL_INVALID_ENUM, GL_INVALID_ENUM }; const int ALPHA_BITMASK = SK_ColorBLACK; const int COLOR_BITMASK = ~ALPHA_BITMASK; @@ -331,6 +338,7 @@ GlopBuilder& GlopBuilder::setFillShadowTexturePaint(ShadowTexture& texture, int setFill(shadowColor, alphaScale, PaintUtils::getXfermode(paint.getXfermode()), paint.getShader(), paint.getColorFilter()); + mDescription.hasAlpha8Texture = true; mDescription.modulate = mOutGlop->fill.color.isNotBlack(); return *this; } @@ -339,12 +347,8 @@ GlopBuilder& GlopBuilder::setFillBlack() { TRIGGER_STAGE(kFillStage); REQUIRE_STAGES(kMeshStage); - mOutGlop->fill.texture = nullptr; - mOutGlop->fill.textureFilter = GL_INVALID_ENUM; - mOutGlop->fill.textureClamp = GL_INVALID_ENUM; - + mOutGlop->fill.texture = { nullptr, GL_INVALID_ENUM, GL_INVALID_ENUM }; setFill(SK_ColorBLACK, 1.0f, SkXfermode::kSrcOver_Mode, nullptr, nullptr); - return *this; } @@ -352,19 +356,30 @@ GlopBuilder& GlopBuilder::setFillClear() { TRIGGER_STAGE(kFillStage); REQUIRE_STAGES(kMeshStage); - mOutGlop->fill.texture = nullptr; - mOutGlop->fill.textureFilter = GL_INVALID_ENUM; - mOutGlop->fill.textureClamp = GL_INVALID_ENUM; - + mOutGlop->fill.texture = { nullptr, GL_INVALID_ENUM, GL_INVALID_ENUM }; setFill(SK_ColorBLACK, 1.0f, SkXfermode::kClear_Mode, nullptr, nullptr); + return *this; +} +GlopBuilder& GlopBuilder::setFillLayer(Texture& texture, const SkColorFilter* colorFilter, + float alpha, SkXfermode::Mode mode) { + TRIGGER_STAGE(kFillStage); + REQUIRE_STAGES(kMeshStage); + + mOutGlop->fill.texture = { &texture, GL_LINEAR, GL_CLAMP_TO_EDGE }; + mOutGlop->fill.color = { alpha, alpha, alpha, alpha }; + + setFill(SK_ColorWHITE, alpha, mode, nullptr, colorFilter); + + mDescription.modulate = mOutGlop->fill.color.a < 1.0f; return *this; } + //////////////////////////////////////////////////////////////////////////////// // Transform //////////////////////////////////////////////////////////////////////////////// -GlopBuilder& GlopBuilder::setTransformClip(const Matrix4& ortho, +GlopBuilder& GlopBuilder::setTransform(const Matrix4& ortho, const Matrix4& transform, bool fudgingOffset) { TRIGGER_STAGE(kTransformStage); @@ -396,12 +411,13 @@ GlopBuilder& GlopBuilder::setModelViewMapUnitToRectSnap(const Rect destination) const Matrix4& canvasTransform = mOutGlop->transform.canvas; if (CC_LIKELY(canvasTransform.isPureTranslate())) { + // snap by adjusting the model view matrix const float translateX = canvasTransform.getTranslateX(); const float translateY = canvasTransform.getTranslateY(); left = (int) floorf(left + translateX + 0.5f) - translateX; top = (int) floorf(top + translateY + 0.5f) - translateY; - mOutGlop->fill.textureFilter = GL_NEAREST; + mOutGlop->fill.texture.filter = GL_NEAREST; } mOutGlop->transform.modelView.loadTranslate(left, top, 0.0f); @@ -419,6 +435,30 @@ GlopBuilder& GlopBuilder::setModelViewOffsetRect(float offsetX, float offsetY, c return *this; } +GlopBuilder& GlopBuilder::setModelViewOffsetRectSnap(float offsetX, float offsetY, const Rect source) { + TRIGGER_STAGE(kModelViewStage); + REQUIRE_STAGES(kTransformStage | kFillStage); + + const Matrix4& canvasTransform = mOutGlop->transform.canvas; + if (CC_LIKELY(canvasTransform.isPureTranslate())) { + // snap by adjusting the model view matrix + const float translateX = canvasTransform.getTranslateX(); + const float translateY = canvasTransform.getTranslateY(); + + offsetX = (int) floorf(offsetX + translateX + source.left + 0.5f) - translateX - source.left; + offsetY = (int) floorf(offsetY + translateY + source.top + 0.5f) - translateY - source.top; + mOutGlop->fill.texture.filter = GL_NEAREST; + } + + mOutGlop->transform.modelView.loadTranslate(offsetX, offsetY, 0.0f); + mOutGlop->bounds.translate(offsetX, offsetY); + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +// RoundRectClip +//////////////////////////////////////////////////////////////////////////////// + GlopBuilder& GlopBuilder::setRoundRectClipState(const RoundRectClipState* roundRectClipState) { TRIGGER_STAGE(kRoundRectClipStage); @@ -431,11 +471,17 @@ GlopBuilder& GlopBuilder::setRoundRectClipState(const RoundRectClipState* roundR // Build //////////////////////////////////////////////////////////////////////////////// +void verify(const ProgramDescription& description, const Glop& glop) { + bool hasTexture = glop.fill.texture.texture != nullptr; + LOG_ALWAYS_FATAL_IF(description.hasTexture != hasTexture); + LOG_ALWAYS_FATAL_IF((glop.mesh.vertexFlags & kTextureCoord_Attrib) != hasTexture); +} + void GlopBuilder::build() { REQUIRE_STAGES(kAllStages); // serialize shader info into ShaderData - GLuint textureUnit = mOutGlop->fill.texture ? 1 : 0; + GLuint textureUnit = mOutGlop->fill.texture.texture ? 1 : 0; SkiaShader::store(mCaches, mShader, mOutGlop->transform.modelView, &textureUnit, &mDescription, &(mOutGlop->fill.skiaShaderData)); @@ -448,6 +494,8 @@ void GlopBuilder::build() { && !mDescription.hasGradient && !mDescription.hasBitmap; mOutGlop->fill.colorEnabled = mDescription.modulate || singleColor; + + verify(mDescription, *mOutGlop); } } /* namespace uirenderer */ diff --git a/libs/hwui/GlopBuilder.h b/libs/hwui/GlopBuilder.h index 546e6c5..cbdd0cd 100644 --- a/libs/hwui/GlopBuilder.h +++ b/libs/hwui/GlopBuilder.h @@ -39,9 +39,10 @@ public: GlopBuilder(RenderState& renderState, Caches& caches, Glop* outGlop); GlopBuilder& setMeshUnitQuad(); - GlopBuilder& setMeshTexturedUnitQuad(const UvMapper* uvMapper, bool isAlphaMaskTexture); + GlopBuilder& setMeshTexturedUnitQuad(const UvMapper* uvMapper); GlopBuilder& setMeshVertexBuffer(const VertexBuffer& vertexBuffer, bool shadowInterp); GlopBuilder& setMeshIndexedQuads(void* vertexData, int quadCount); + GlopBuilder& setMeshTexturedIndexedQuads(TextureVertex* vertexData, int elementCount); // TODO: take quadCount GlopBuilder& setFillPaint(const SkPaint& paint, float alphaScale); GlopBuilder& setFillTexturePaint(Texture& texture, bool isAlphaMaskTexture, @@ -52,12 +53,15 @@ public: const SkPaint& paint, float alphaScale); GlopBuilder& setFillBlack(); GlopBuilder& setFillClear(); + GlopBuilder& setFillLayer(Texture& texture, const SkColorFilter* colorFilter, + float alpha, SkXfermode::Mode mode); - GlopBuilder& setTransformClip(const Matrix4& ortho, const Matrix4& transform, bool fudgingOffset); + GlopBuilder& setTransform(const Matrix4& ortho, const Matrix4& transform, bool fudgingOffset); GlopBuilder& setModelViewMapUnitToRect(const Rect destination); GlopBuilder& setModelViewMapUnitToRectSnap(const Rect destination); GlopBuilder& setModelViewOffsetRect(float offsetX, float offsetY, const Rect source); + GlopBuilder& setModelViewOffsetRectSnap(float offsetX, float offsetY, const Rect source); GlopBuilder& setRoundRectClipState(const RoundRectClipState* roundRectClipState); diff --git a/libs/hwui/Layer.h b/libs/hwui/Layer.h index 84ff021..3c1f1d1 100644 --- a/libs/hwui/Layer.h +++ b/libs/hwui/Layer.h @@ -200,10 +200,14 @@ public: return stencil; } - inline GLuint getTexture() const { + inline GLuint getTextureId() const { return texture.id; } + inline Texture& getTexture() { + return texture; + } + inline GLenum getRenderTarget() const { return renderTarget; } diff --git a/libs/hwui/LayerRenderer.cpp b/libs/hwui/LayerRenderer.cpp index b4b14e8..f598664 100644 --- a/libs/hwui/LayerRenderer.cpp +++ b/libs/hwui/LayerRenderer.cpp @@ -247,7 +247,7 @@ Layer* LayerRenderer::createRenderLayer(RenderState& renderState, uint32_t width } glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, - layer->getTexture(), 0); + layer->getTextureId(), 0); renderState.bindFramebuffer(previousFbo); diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 3f79cef..b62af3b 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -753,7 +753,7 @@ bool OpenGLRenderer::createFboLayer(Layer* layer, Rect& bounds, Rect& clip) { } glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, - layer->getTexture(), 0); + layer->getTextureId(), 0); // Expand the startTiling region by 1 startTilingCurrentClip(true, true); @@ -862,9 +862,9 @@ void OpenGLRenderer::drawTextureLayer(Layer* layer, const Rect& rect) { setupDrawPureColorUniforms(); setupDrawColorFilterUniforms(layer->getColorFilter()); if (layer->getRenderTarget() == GL_TEXTURE_2D) { - setupDrawTexture(layer->getTexture()); + setupDrawTexture(layer->getTextureId()); } else { - setupDrawExternalTexture(layer->getTexture()); + setupDrawExternalTexture(layer->getTextureId()); } if (currentTransform()->isPureTranslate() && !layer->getForceFilter() && @@ -924,7 +924,7 @@ void OpenGLRenderer::composeLayerRect(Layer* layer, const Rect& rect, bool swap) bool blend = layer->isBlend() || getLayerAlpha(layer) < 1.0f; drawTextureMesh(x, y, x + rect.getWidth(), y + rect.getHeight(), - layer->getTexture(), &layerPaint, blend, + layer->getTextureId(), &layerPaint, blend, &mMeshVertices[0].x, &mMeshVertices[0].u, GL_TRIANGLE_STRIP, kUnitQuadCount, swap, swap || simpleTransform); @@ -1061,7 +1061,7 @@ void OpenGLRenderer::composeLayerRegion(Layer* layer, const Rect& rect) { setupDrawDirtyRegionsDisabled(); setupDrawPureColorUniforms(); setupDrawColorFilterUniforms(layer->getColorFilter()); - setupDrawTexture(layer->getTexture()); + setupDrawTexture(layer->getTextureId()); if (currentTransform()->isPureTranslate()) { const float x = (int) floorf(rect.left + currentTransform()->getTranslateX() + 0.5f); const float y = (int) floorf(rect.top + currentTransform()->getTranslateY() + 0.5f); @@ -1233,7 +1233,7 @@ void OpenGLRenderer::clearLayerRegions() { GlopBuilder aBuilder(mRenderState, mCaches, &glop); aBuilder.setMeshIndexedQuads(&mesh[0], quadCount) .setFillClear() - .setTransformClip(currentSnapshot()->getOrthoMatrix(), Matrix4::identity(), false) + .setTransform(currentSnapshot()->getOrthoMatrix(), Matrix4::identity(), false) .setModelViewOffsetRect(0, 0, currentSnapshot()->getClipRect()) .setRoundRectClipState(currentSnapshot()->roundRectClipState) .build(); @@ -1437,7 +1437,7 @@ void OpenGLRenderer::drawRectangleList(const RectangleList& rectangleList) { GlopBuilder aBuilder(mRenderState, mCaches, &glop); aBuilder.setMeshIndexedQuads(&rectangleVertices[0], rectangleVertices.size() / 4) .setFillBlack() - .setTransformClip(currentSnapshot()->getOrthoMatrix(), Matrix4::identity(), false) + .setTransform(currentSnapshot()->getOrthoMatrix(), Matrix4::identity(), false) .setModelViewOffsetRect(0, 0, scissorBox) .setRoundRectClipState(currentSnapshot()->roundRectClipState) .build(); @@ -1981,19 +1981,6 @@ void OpenGLRenderer::drawRenderNode(RenderNode* renderNode, Rect& dirty, int32_t } void OpenGLRenderer::drawAlphaBitmap(Texture* texture, const SkPaint* paint) { - if (USE_GLOPS) { - Glop glop; - GlopBuilder aBuilder(mRenderState, mCaches, &glop); - aBuilder.setMeshTexturedUnitQuad(texture->uvMapper, true) - .setFillTexturePaint(*texture, true, paint, currentSnapshot()->alpha) - .setTransformClip(currentSnapshot()->getOrthoMatrix(), *currentTransform(), false) - .setModelViewMapUnitToRectSnap(Rect(0, 0, texture->width, texture->height)) - .setRoundRectClipState(currentSnapshot()->roundRectClipState) - .build(); - renderGlop(glop); - return; - } - float x = 0; float y = 0; @@ -2061,6 +2048,20 @@ void OpenGLRenderer::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) { if (!texture) return; const AutoTexture autoCleanup(texture); + if (USE_GLOPS) { + bool isAlpha8Texture = bitmap->colorType() == kAlpha_8_SkColorType; + Glop glop; + GlopBuilder aBuilder(mRenderState, mCaches, &glop); + aBuilder.setMeshTexturedUnitQuad(texture->uvMapper) + .setFillTexturePaint(*texture, isAlpha8Texture, paint, currentSnapshot()->alpha) + .setTransform(currentSnapshot()->getOrthoMatrix(), *currentTransform(), false) + .setModelViewMapUnitToRectSnap(Rect(0, 0, texture->width, texture->height)) + .setRoundRectClipState(currentSnapshot()->roundRectClipState) + .build(); + renderGlop(glop); + return; + } + if (CC_UNLIKELY(bitmap->colorType() == kAlpha_8_SkColorType)) { drawAlphaBitmap(texture, paint); } else { @@ -2376,7 +2377,7 @@ void OpenGLRenderer::drawVertexBuffer(float translateX, float translateY, bool shadowInterp = displayFlags & kVertexBuffer_ShadowInterp; aBuilder.setMeshVertexBuffer(vertexBuffer, shadowInterp) .setFillPaint(*paint, currentSnapshot()->alpha) - .setTransformClip(currentSnapshot()->getOrthoMatrix(), *currentTransform(), fudgeOffset) + .setTransform(currentSnapshot()->getOrthoMatrix(), *currentTransform(), fudgeOffset) .setModelViewOffsetRect(translateX, translateY, vertexBuffer.getBounds()) .setRoundRectClipState(currentSnapshot()->roundRectClipState) .build(); @@ -2692,9 +2693,9 @@ void OpenGLRenderer::drawTextShadow(const SkPaint* paint, const char* text, if (USE_GLOPS) { Glop glop; GlopBuilder aBuilder(mRenderState, mCaches, &glop); - aBuilder.setMeshTexturedUnitQuad(nullptr, true) + aBuilder.setMeshTexturedUnitQuad(nullptr) .setFillShadowTexturePaint(*texture, textShadow.color, *paint, currentSnapshot()->alpha) - .setTransformClip(currentSnapshot()->getOrthoMatrix(), *currentTransform(), false) + .setTransform(currentSnapshot()->getOrthoMatrix(), *currentTransform(), false) .setModelViewMapUnitToRect(Rect(sx, sy, sx + texture->width, sy + texture->height)) .setRoundRectClipState(currentSnapshot()->roundRectClipState) .build(); @@ -3048,45 +3049,58 @@ void OpenGLRenderer::drawLayer(Layer* layer, float x, float y) { DRAW_DOUBLE_STENCIL_IF(!layer->hasDrawnSinceUpdate, composeLayerRect(layer, layer->regionRect)); } else if (layer->mesh) { - const float a = getLayerAlpha(layer); - setupDraw(); - setupDrawWithTexture(); - setupDrawColor(a, a, a, a); - setupDrawColorFilter(layer->getColorFilter()); - setupDrawBlending(layer); - setupDrawProgram(); - setupDrawPureColorUniforms(); - setupDrawColorFilterUniforms(layer->getColorFilter()); - setupDrawTexture(layer->getTexture()); - if (CC_LIKELY(currentTransform()->isPureTranslate())) { - int tx = (int) floorf(x + currentTransform()->getTranslateX() + 0.5f); - int ty = (int) floorf(y + currentTransform()->getTranslateY() + 0.5f); - - layer->setFilter(GL_NEAREST); - setupDrawModelView(kModelViewMode_Translate, false, tx, ty, - tx + layer->layer.getWidth(), ty + layer->layer.getHeight(), true); + if (USE_GLOPS) { + Glop glop; + GlopBuilder aBuilder(mRenderState, mCaches, &glop); + aBuilder.setMeshTexturedIndexedQuads(layer->mesh, layer->meshElementCount) + .setFillLayer(layer->getTexture(), layer->getColorFilter(), getLayerAlpha(layer), layer->getMode()) + .setTransform(currentSnapshot()->getOrthoMatrix(), *currentTransform(), false) + .setModelViewOffsetRectSnap(x, y, Rect(0, 0, layer->layer.getWidth(), layer->layer.getHeight())) + .setRoundRectClipState(currentSnapshot()->roundRectClipState) + .build(); + DRAW_DOUBLE_STENCIL_IF(!layer->hasDrawnSinceUpdate, renderGlop(glop)); } else { - layer->setFilter(GL_LINEAR); - setupDrawModelView(kModelViewMode_Translate, false, x, y, - x + layer->layer.getWidth(), y + layer->layer.getHeight()); - } + const float a = getLayerAlpha(layer); + setupDraw(); + setupDrawWithTexture(); + setupDrawColor(a, a, a, a); + setupDrawColorFilter(layer->getColorFilter()); + setupDrawBlending(layer); + setupDrawProgram(); + setupDrawPureColorUniforms(); + setupDrawColorFilterUniforms(layer->getColorFilter()); + setupDrawTexture(layer->getTextureId()); + if (CC_LIKELY(currentTransform()->isPureTranslate())) { + int tx = (int) floorf(x + currentTransform()->getTranslateX() + 0.5f); + int ty = (int) floorf(y + currentTransform()->getTranslateY() + 0.5f); + + layer->setFilter(GL_NEAREST); + setupDrawModelView(kModelViewMode_Translate, false, tx, ty, + tx + layer->layer.getWidth(), ty + layer->layer.getHeight(), true); + } else { + layer->setFilter(GL_LINEAR); + setupDrawModelView(kModelViewMode_Translate, false, x, y, + x + layer->layer.getWidth(), y + layer->layer.getHeight()); + } - TextureVertex* mesh = &layer->mesh[0]; - GLsizei elementsCount = layer->meshElementCount; - while (elementsCount > 0) { - GLsizei drawCount = MathUtils::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6); + TextureVertex* mesh = &layer->mesh[0]; + GLsizei elementsCount = layer->meshElementCount; - setupDrawMeshIndices(&mesh[0].x, &mesh[0].u); - DRAW_DOUBLE_STENCIL_IF(!layer->hasDrawnSinceUpdate, - glDrawElements(GL_TRIANGLES, drawCount, GL_UNSIGNED_SHORT, nullptr)); - elementsCount -= drawCount; - // Though there are 4 vertices in a quad, we use 6 indices per - // quad to draw with GL_TRIANGLES - mesh += (drawCount / 6) * 4; - } + while (elementsCount > 0) { + GLsizei drawCount = MathUtils::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6); + + setupDrawMeshIndices(&mesh[0].x, &mesh[0].u); + DRAW_DOUBLE_STENCIL_IF(!layer->hasDrawnSinceUpdate, + glDrawElements(GL_TRIANGLES, drawCount, GL_UNSIGNED_SHORT, nullptr)); + elementsCount -= drawCount; + // Though there are 4 vertices in a quad, we use 6 indices per + // quad to draw with GL_TRIANGLES + mesh += (drawCount / 6) * 4; + } + } #if DEBUG_LAYERS_AS_REGIONS drawRegionRectsDebug(layer->region); #endif @@ -3139,9 +3153,9 @@ void OpenGLRenderer::drawPathTexture(PathTexture* texture, float x, float y, if (USE_GLOPS) { Glop glop; GlopBuilder aBuilder(mRenderState, mCaches, &glop); - aBuilder.setMeshTexturedUnitQuad(nullptr, true) + aBuilder.setMeshTexturedUnitQuad(nullptr) .setFillPathTexturePaint(*texture, *paint, currentSnapshot()->alpha) - .setTransformClip(currentSnapshot()->getOrthoMatrix(), *currentTransform(), false) + .setTransform(currentSnapshot()->getOrthoMatrix(), *currentTransform(), false) .setModelViewMapUnitToRect(Rect(x, y, x + texture->width, y + texture->height)) .setRoundRectClipState(currentSnapshot()->roundRectClipState) .build(); @@ -3303,7 +3317,7 @@ void OpenGLRenderer::drawColorRects(const float* rects, int count, const SkPaint GlopBuilder aBuilder(mRenderState, mCaches, &glop); aBuilder.setMeshIndexedQuads(&mesh[0], count / 4) .setFillPaint(*paint, currentSnapshot()->alpha) - .setTransformClip(currentSnapshot()->getOrthoMatrix(), transform, false) + .setTransform(currentSnapshot()->getOrthoMatrix(), transform, false) .setModelViewOffsetRect(0, 0, Rect(left, top, right, bottom)) .setRoundRectClipState(currentSnapshot()->roundRectClipState) .build(); @@ -3349,7 +3363,7 @@ void OpenGLRenderer::drawColorRect(float left, float top, float right, float bot GlopBuilder aBuilder(mRenderState, mCaches, &glop); aBuilder.setMeshUnitQuad() .setFillPaint(*paint, currentSnapshot()->alpha) - .setTransformClip(currentSnapshot()->getOrthoMatrix(), transform, false) + .setTransform(currentSnapshot()->getOrthoMatrix(), transform, false) .setModelViewMapUnitToRect(Rect(left, top, right, bottom)) .setRoundRectClipState(currentSnapshot()->roundRectClipState) .build(); @@ -3381,19 +3395,6 @@ void OpenGLRenderer::drawColorRect(float left, float top, float right, float bot } void OpenGLRenderer::drawTextureRect(Texture* texture, const SkPaint* paint) { - if (USE_GLOPS) { - Glop glop; - GlopBuilder aBuilder(mRenderState, mCaches, &glop); - aBuilder.setMeshTexturedUnitQuad(texture->uvMapper, false) - .setFillTexturePaint(*texture, false, paint, currentSnapshot()->alpha) - .setTransformClip(currentSnapshot()->getOrthoMatrix(), *currentTransform(), false) - .setModelViewMapUnitToRectSnap(Rect(0, 0, texture->width, texture->height)) - .setRoundRectClipState(currentSnapshot()->roundRectClipState) - .build(); - renderGlop(glop); - return; - } - texture->setWrap(GL_CLAMP_TO_EDGE, true); GLvoid* vertices = (GLvoid*) nullptr; diff --git a/libs/hwui/renderstate/MeshState.cpp b/libs/hwui/renderstate/MeshState.cpp index 585fb86..6b00020 100644 --- a/libs/hwui/renderstate/MeshState.cpp +++ b/libs/hwui/renderstate/MeshState.cpp @@ -68,6 +68,7 @@ MeshState::~MeshState() { void MeshState::dump() { ALOGD("MeshState VBOs: unitQuad %d, current %d", mUnitQuadBuffer, mCurrentBuffer); + ALOGD("MeshState IBOs: quadList %d, current %d", mQuadListIndices, mCurrentIndicesBuffer); ALOGD("MeshState vertices: vertex data %p, stride %d", mCurrentPositionPointer, mCurrentPositionStride); ALOGD("MeshState texCoord: data %p, stride %d", diff --git a/libs/hwui/renderstate/RenderState.cpp b/libs/hwui/renderstate/RenderState.cpp index b64dbdc..192bf81 100644 --- a/libs/hwui/renderstate/RenderState.cpp +++ b/libs/hwui/renderstate/RenderState.cpp @@ -253,7 +253,6 @@ void RenderState::render(const Glop& glop) { glUniform1f(fill.program->getUniform("roundRectRadius"), roundedOutRadius); } - // -------------------------------- // ---------- Mesh setup ---------- // -------------------------------- @@ -269,16 +268,16 @@ void RenderState::render(const Glop& glop) { // glop.fill.texture always takes slot 0, shader samplers increment from there mCaches->textureState().activateTexture(0); - if (glop.fill.textureClamp != GL_INVALID_ENUM) { - glop.fill.texture->setWrap(glop.fill.textureClamp, true); + if (glop.fill.texture.clamp != GL_INVALID_ENUM) { + glop.fill.texture.texture->setWrap(glop.fill.texture.clamp, true); } - if (glop.fill.textureFilter != GL_INVALID_ENUM) { - glop.fill.texture->setFilter(glop.fill.textureFilter, true); + if (glop.fill.texture.filter != GL_INVALID_ENUM) { + glop.fill.texture.texture->setFilter(glop.fill.texture.filter, true); } - mCaches->textureState().bindTexture(fill.texture->id); + mCaches->textureState().bindTexture(fill.texture.texture->id); meshState().enableTexCoordsVertexArray(); - meshState().bindTexCoordsVertexPointer(force, mesh.texCoordOffset); + meshState().bindTexCoordsVertexPointer(force, mesh.texCoordOffset, mesh.stride); } else { meshState().disableTexCoordsVertexArray(); } @@ -313,8 +312,13 @@ void RenderState::render(const Glop& glop) { while (elementsCount > 0) { GLsizei drawCount = MathUtils::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6); - // TODO: this double binds on first pass - meshState().bindPositionVertexPointer(true, vertices, mesh.stride); + // rebind pointers without forcing, since initial bind handled above + meshState().bindPositionVertexPointer(false, vertices, mesh.stride); + if (mesh.vertexFlags & kTextureCoord_Attrib) { + meshState().bindTexCoordsVertexPointer(false, + vertices + kMeshTextureOffset, mesh.stride); + } + glDrawElements(mesh.primitiveMode, drawCount, GL_UNSIGNED_SHORT, nullptr); elementsCount -= drawCount; vertices += (drawCount / 6) * 4 * mesh.stride; diff --git a/libs/hwui/renderstate/TextureState.cpp b/libs/hwui/renderstate/TextureState.cpp index 1a638d2..a211de7 100644 --- a/libs/hwui/renderstate/TextureState.cpp +++ b/libs/hwui/renderstate/TextureState.cpp @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <renderstate/TextureState.h> +#include "renderstate/TextureState.h" namespace android { namespace uirenderer { |