diff options
Diffstat (limited to 'libs/hwui/OpenGLRenderer.cpp')
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 165 |
1 files changed, 101 insertions, 64 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 61cd16f..a00a2bc 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -57,16 +57,11 @@ #define EVENT_LOGD(...) #endif +#define USE_GLOPS true + namespace android { namespace uirenderer { -static GLenum getFilter(const SkPaint* paint) { - if (!paint || paint->getFilterLevel() != SkPaint::kNone_FilterLevel) { - return GL_LINEAR; - } - return GL_NEAREST; -} - /////////////////////////////////////////////////////////////////////////////// // Globals /////////////////////////////////////////////////////////////////////////////// @@ -1586,6 +1581,7 @@ void OpenGLRenderer::renderGlop(const Glop& glop) { // TODO: specify more clearly when a draw should dirty the layer. // is writing to the stencil the only time we should ignore this? dirtyLayer(glop.bounds.left, glop.bounds.top, glop.bounds.right, glop.bounds.bottom); + mDirty = true; } } @@ -1611,7 +1607,7 @@ void OpenGLRenderer::setupDraw(bool clearLayer) { mSetShaderColor = false; mColorSet = false; - mColorA = mColorR = mColorG = mColorB = 0.0f; + mColor.a = mColor.r = mColor.g = mColor.b = 0.0f; mTextureUnit = 0; mTrackDirtyRegions = true; @@ -1647,21 +1643,21 @@ void OpenGLRenderer::setupDrawVertexAlpha(bool useShadowAlphaInterp) { } void OpenGLRenderer::setupDrawColor(int color, int alpha) { - mColorA = alpha / 255.0f; - mColorR = mColorA * ((color >> 16) & 0xFF) / 255.0f; - mColorG = mColorA * ((color >> 8) & 0xFF) / 255.0f; - mColorB = mColorA * ((color ) & 0xFF) / 255.0f; + mColor.a = alpha / 255.0f; + mColor.r = mColor.a * ((color >> 16) & 0xFF) / 255.0f; + mColor.g = mColor.a * ((color >> 8) & 0xFF) / 255.0f; + mColor.b = mColor.a * ((color ) & 0xFF) / 255.0f; mColorSet = true; - mSetShaderColor = mDescription.setColorModulate(mColorA); + mSetShaderColor = mDescription.setColorModulate(mColor.a); } void OpenGLRenderer::setupDrawAlpha8Color(int color, int alpha) { - mColorA = alpha / 255.0f; - mColorR = mColorA * ((color >> 16) & 0xFF) / 255.0f; - mColorG = mColorA * ((color >> 8) & 0xFF) / 255.0f; - mColorB = mColorA * ((color ) & 0xFF) / 255.0f; + mColor.a = alpha / 255.0f; + mColor.r = mColor.a * ((color >> 16) & 0xFF) / 255.0f; + mColor.g = mColor.a * ((color >> 8) & 0xFF) / 255.0f; + mColor.b = mColor.a * ((color ) & 0xFF) / 255.0f; mColorSet = true; - mSetShaderColor = mDescription.setAlpha8ColorModulate(mColorR, mColorG, mColorB, mColorA); + mSetShaderColor = mDescription.setAlpha8ColorModulate(mColor.r, mColor.g, mColor.b, mColor.a); } void OpenGLRenderer::setupDrawTextGamma(const SkPaint* paint) { @@ -1669,10 +1665,10 @@ void OpenGLRenderer::setupDrawTextGamma(const SkPaint* paint) { } void OpenGLRenderer::setupDrawColor(float r, float g, float b, float a) { - mColorA = a; - mColorR = r; - mColorG = g; - mColorB = b; + mColor.a = a; + mColor.r = r; + mColor.g = g; + mColor.b = b; mColorSet = true; mSetShaderColor = mDescription.setColorModulate(a); } @@ -1699,8 +1695,8 @@ void OpenGLRenderer::setupDrawColorFilter(const SkColorFilter* filter) { void OpenGLRenderer::accountForClear(SkXfermode::Mode mode) { if (mColorSet && mode == SkXfermode::kClear_Mode) { - mColorA = 1.0f; - mColorR = mColorG = mColorB = 0.0f; + mColor.a = 1.0f; + mColor.r = mColor.g = mColor.b = 0.0f; mSetShaderColor = mDescription.modulate = true; } } @@ -1713,7 +1709,7 @@ void OpenGLRenderer::setupDrawBlending(const Layer* layer, bool swapSrcDst) { // TODO: check shader blending, once we have shader drawing support for layers. bool blend = layer->isBlend() || getLayerAlpha(layer) < 1.0f - || (mColorSet && mColorA < 1.0f) + || (mColorSet && mColor.a < 1.0f) || PaintUtils::isBlendedColorFilter(layer->getColorFilter()); chooseBlending(blend, mode, mDescription, swapSrcDst); } @@ -1723,7 +1719,7 @@ void OpenGLRenderer::setupDrawBlending(const SkPaint* paint, bool blend, bool sw // When the blending mode is kClear_Mode, we need to use a modulate color // argb=1,0,0,0 accountForClear(mode); - blend |= (mColorSet && mColorA < 1.0f) + blend |= (mColorSet && mColor.a < 1.0f) || (getShader(paint) && !getShader(paint)->isOpaque()) || PaintUtils::isBlendedColorFilter(getColorFilter(paint)); chooseBlending(blend, mode, mDescription, swapSrcDst); @@ -1775,13 +1771,13 @@ void OpenGLRenderer::setupDrawModelView(ModelViewMode mode, bool offset, void OpenGLRenderer::setupDrawColorUniforms(bool hasShader) { if ((mColorSet && !hasShader) || (hasShader && mSetShaderColor)) { - mCaches.program().setColor(mColorR, mColorG, mColorB, mColorA); + mCaches.program().setColor(mColor); } } void OpenGLRenderer::setupDrawPureColorUniforms() { if (mSetShaderColor) { - mCaches.program().setColor(mColorR, mColorG, mColorB, mColorA); + mCaches.program().setColor(mColor); } } @@ -1973,22 +1969,34 @@ void OpenGLRenderer::drawRenderNode(RenderNode* renderNode, Rect& dirty, int32_t } } -void OpenGLRenderer::drawAlphaBitmap(Texture* texture, float left, float top, - const SkPaint* paint) { - float x = left; - float y = top; +void OpenGLRenderer::drawAlphaBitmap(Texture* texture, const SkPaint* paint) { + if (USE_GLOPS && (!paint || !paint->getShader())) { + 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; texture->setWrap(GL_CLAMP_TO_EDGE, true); bool ignoreTransform = false; if (currentTransform()->isPureTranslate()) { - x = (int) floorf(left + currentTransform()->getTranslateX() + 0.5f); - y = (int) floorf(top + currentTransform()->getTranslateY() + 0.5f); + x = (int) floorf(currentTransform()->getTranslateX() + 0.5f); + y = (int) floorf(currentTransform()->getTranslateY() + 0.5f); ignoreTransform = true; texture->setFilter(GL_NEAREST, true); } else { - texture->setFilter(getFilter(paint), true); + texture->setFilter(PaintUtils::getFilter(paint), true); } // No need to check for a UV mapper on the texture object, only ARGB_8888 @@ -2013,7 +2021,7 @@ void OpenGLRenderer::drawBitmaps(const SkBitmap* bitmap, AssetAtlas::Entry* entr const AutoTexture autoCleanup(texture); texture->setWrap(GL_CLAMP_TO_EDGE, true); - texture->setFilter(pureTranslate ? GL_NEAREST : getFilter(paint), true); + texture->setFilter(pureTranslate ? GL_NEAREST : PaintUtils::getFilter(paint), true); const float x = (int) floorf(bounds.left + 0.5f); const float y = (int) floorf(bounds.top + 0.5f); @@ -2043,9 +2051,9 @@ void OpenGLRenderer::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) { const AutoTexture autoCleanup(texture); if (CC_UNLIKELY(bitmap->colorType() == kAlpha_8_SkColorType)) { - drawAlphaBitmap(texture, 0, 0, paint); + drawAlphaBitmap(texture, paint); } else { - drawTextureRect(0, 0, bitmap->width(), bitmap->height(), texture, paint); + drawTextureRect(texture, paint); } mDirty = true; @@ -2130,7 +2138,7 @@ void OpenGLRenderer::drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int m const AutoTexture autoCleanup(texture); texture->setWrap(GL_CLAMP_TO_EDGE, true); - texture->setFilter(getFilter(paint), true); + texture->setFilter(PaintUtils::getFilter(paint), true); int alpha; SkXfermode::Mode mode; @@ -2213,10 +2221,10 @@ void OpenGLRenderer::drawBitmap(const SkBitmap* bitmap, dstLeft = x; dstTop = y; - texture->setFilter(scaled ? getFilter(paint) : GL_NEAREST, true); + texture->setFilter(scaled ? PaintUtils::getFilter(paint) : GL_NEAREST, true); ignoreTransform = true; } else { - texture->setFilter(getFilter(paint), true); + texture->setFilter(PaintUtils::getFilter(paint), true); } if (CC_UNLIKELY(useScaleTransform)) { @@ -2350,15 +2358,16 @@ void OpenGLRenderer::drawVertexBuffer(float translateX, float translateY, return; } - if (!paint->getShader() && !currentSnapshot()->roundRectClipState) { + if (USE_GLOPS && !paint->getShader()) { Glop glop; GlopBuilder aBuilder(mRenderState, mCaches, &glop); bool fudgeOffset = displayFlags & kVertexBuffer_Offset; bool shadowInterp = displayFlags & kVertexBuffer_ShadowInterp; aBuilder.setMeshVertexBuffer(vertexBuffer, shadowInterp) - .setTransform(currentSnapshot()->getOrthoMatrix(), *currentTransform(), fudgeOffset) + .setFillPaint(*paint, currentSnapshot()->alpha) + .setTransformClip(currentSnapshot()->getOrthoMatrix(), *currentTransform(), fudgeOffset) .setModelViewOffsetRect(translateX, translateY, vertexBuffer.getBounds()) - .setPaint(*paint, currentSnapshot()->alpha) + .setRoundRectClipState(currentSnapshot()->roundRectClipState) .build(); renderGlop(glop); return; @@ -2496,7 +2505,7 @@ void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) { mDirty = true; } -void OpenGLRenderer::drawShape(float left, float top, const PathTexture* texture, +void OpenGLRenderer::drawShape(float left, float top, PathTexture* texture, const SkPaint* paint) { if (!texture) return; const AutoTexture autoCleanup(texture); @@ -2519,7 +2528,7 @@ void OpenGLRenderer::drawRoundRect(float left, float top, float right, float bot if (p->getPathEffect() != nullptr) { mCaches.textureState().activateTexture(0); - const PathTexture* texture = mCaches.pathCache.getRoundRect( + PathTexture* texture = mCaches.pathCache.getRoundRect( right - left, bottom - top, rx, ry, p); drawShape(left, top, texture, p); } else { @@ -2537,7 +2546,7 @@ void OpenGLRenderer::drawCircle(float x, float y, float radius, const SkPaint* p } if (p->getPathEffect() != nullptr) { mCaches.textureState().activateTexture(0); - const PathTexture* texture = mCaches.pathCache.getCircle(radius, p); + PathTexture* texture = mCaches.pathCache.getCircle(radius, p); drawShape(x - radius, y - radius, texture, p); } else { SkPath path; @@ -2560,7 +2569,7 @@ void OpenGLRenderer::drawOval(float left, float top, float right, float bottom, if (p->getPathEffect() != nullptr) { mCaches.textureState().activateTexture(0); - const PathTexture* texture = mCaches.pathCache.getOval(right - left, bottom - top, p); + PathTexture* texture = mCaches.pathCache.getOval(right - left, bottom - top, p); drawShape(left, top, texture, p); } else { SkPath path; @@ -2584,7 +2593,7 @@ void OpenGLRenderer::drawArc(float left, float top, float right, float bottom, // TODO: support fills (accounting for concavity if useCenter && sweepAngle > 180) if (p->getStyle() != SkPaint::kStroke_Style || p->getPathEffect() != nullptr || useCenter) { mCaches.textureState().activateTexture(0); - const PathTexture* texture = mCaches.pathCache.getArc(right - left, bottom - top, + PathTexture* texture = mCaches.pathCache.getArc(right - left, bottom - top, startAngle, sweepAngle, useCenter, p); drawShape(left, top, texture, p); return; @@ -2621,7 +2630,7 @@ void OpenGLRenderer::drawRect(float left, float top, float right, float bottom, if (p->getPathEffect() != nullptr || p->getStrokeJoin() != SkPaint::kMiter_Join || p->getStrokeMiter() != SkPaintDefaults_MiterLimit) { mCaches.textureState().activateTexture(0); - const PathTexture* texture = + PathTexture* texture = mCaches.pathCache.getRect(right - left, bottom - top, p); drawShape(left, top, texture, p); } else { @@ -2965,7 +2974,7 @@ void OpenGLRenderer::drawPath(const SkPath* path, const SkPaint* paint) { mCaches.textureState().activateTexture(0); - const PathTexture* texture = mCaches.pathCache.get(path, paint); + PathTexture* texture = mCaches.pathCache.get(path, paint); if (!texture) return; const AutoTexture autoCleanup(texture); @@ -3098,12 +3107,26 @@ Texture* OpenGLRenderer::getTexture(const SkBitmap* bitmap) { return texture; } -void OpenGLRenderer::drawPathTexture(const PathTexture* texture, +void OpenGLRenderer::drawPathTexture(PathTexture* texture, float x, float y, const SkPaint* paint) { if (quickRejectSetupScissor(x, y, x + texture->width, y + texture->height)) { return; } + if (USE_GLOPS && !paint->getShader()) { + Glop glop; + GlopBuilder aBuilder(mRenderState, mCaches, &glop); + aBuilder.setMeshTexturedUnitQuad(nullptr, true) + .setFillPathTexturePaint(*texture, *paint, currentSnapshot()->alpha) + .setTransformClip(currentSnapshot()->getOrthoMatrix(), *currentTransform(), false) + .setModelViewMapUnitToRect(Rect(x, y, x + texture->width, y + texture->height)) + .setRoundRectClipState(currentSnapshot()->roundRectClipState) + .build(); + renderGlop(glop); + return; + } + + int alpha; SkXfermode::Mode mode; getAlphaAndMode(paint, &alpha, &mode); @@ -3251,14 +3274,15 @@ void OpenGLRenderer::drawColorRects(const float* rects, int count, const SkPaint return; } - if (!paint->getShader() && !currentSnapshot()->roundRectClipState) { + if (USE_GLOPS && !paint->getShader()) { const Matrix4& transform = ignoreTransform ? Matrix4::identity() : *currentTransform(); Glop glop; GlopBuilder aBuilder(mRenderState, mCaches, &glop); aBuilder.setMeshIndexedQuads(&mesh[0], count / 4) - .setTransform(currentSnapshot()->getOrthoMatrix(), transform, false) + .setFillPaint(*paint, currentSnapshot()->alpha) + .setTransformClip(currentSnapshot()->getOrthoMatrix(), transform, false) .setModelViewOffsetRect(0, 0, Rect(left, top, right, bottom)) - .setPaint(*paint, currentSnapshot()->alpha) + .setRoundRectClipState(currentSnapshot()->roundRectClipState) .build(); renderGlop(glop); return; @@ -3296,14 +3320,15 @@ void OpenGLRenderer::drawColorRects(const float* rects, int count, const SkPaint void OpenGLRenderer::drawColorRect(float left, float top, float right, float bottom, const SkPaint* paint, bool ignoreTransform) { - if (!paint->getShader() && !currentSnapshot()->roundRectClipState) { + if (USE_GLOPS && !paint->getShader()) { const Matrix4& transform = ignoreTransform ? Matrix4::identity() : *currentTransform(); Glop glop; GlopBuilder aBuilder(mRenderState, mCaches, &glop); aBuilder.setMeshUnitQuad() - .setTransform(currentSnapshot()->getOrthoMatrix(), transform, false) + .setFillPaint(*paint, currentSnapshot()->alpha) + .setTransformClip(currentSnapshot()->getOrthoMatrix(), transform, false) .setModelViewMapUnitToRect(Rect(left, top, right, bottom)) - .setPaint(*paint, currentSnapshot()->alpha) + .setRoundRectClipState(currentSnapshot()->roundRectClipState) .build(); renderGlop(glop); return; @@ -3332,8 +3357,20 @@ void OpenGLRenderer::drawColorRect(float left, float top, float right, float bot glDrawArrays(GL_TRIANGLE_STRIP, 0, kUnitQuadCount); } -void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom, - Texture* texture, const SkPaint* paint) { +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; @@ -3350,16 +3387,16 @@ void OpenGLRenderer::drawTextureRect(float left, float top, float right, float b } if (CC_LIKELY(currentTransform()->isPureTranslate())) { - const float x = (int) floorf(left + currentTransform()->getTranslateX() + 0.5f); - const float y = (int) floorf(top + currentTransform()->getTranslateY() + 0.5f); + const float x = (int) floorf(currentTransform()->getTranslateX() + 0.5f); + const float y = (int) floorf(currentTransform()->getTranslateY() + 0.5f); texture->setFilter(GL_NEAREST, true); drawTextureMesh(x, y, x + texture->width, y + texture->height, texture->id, paint, texture->blend, vertices, texCoords, GL_TRIANGLE_STRIP, kUnitQuadCount, false, true); } else { - texture->setFilter(getFilter(paint), true); - drawTextureMesh(left, top, right, bottom, texture->id, paint, + texture->setFilter(PaintUtils::getFilter(paint), true); + drawTextureMesh(0, 0, texture->width, texture->height, texture->id, paint, texture->blend, vertices, texCoords, GL_TRIANGLE_STRIP, kUnitQuadCount); } |