diff options
author | Chris Craik <ccraik@google.com> | 2013-03-29 10:59:59 -0700 |
---|---|---|
committer | Chris Craik <ccraik@google.com> | 2013-04-01 17:21:35 -0700 |
commit | 16ecda5317c40fc3da284952d9b3add34d6763ae (patch) | |
tree | 1b1a5c9a2bd631a4e0878d7c6de6759e8e8e5909 /libs | |
parent | 0102443c4f52f2e15fd731c452f0c4745312d448 (diff) | |
download | frameworks_base-16ecda5317c40fc3da284952d9b3add34d6763ae.zip frameworks_base-16ecda5317c40fc3da284952d9b3add34d6763ae.tar.gz frameworks_base-16ecda5317c40fc3da284952d9b3add34d6763ae.tar.bz2 |
Update view's alpha and layer docs
bug:8501661
Makes the performance issues and interaction with layer type/paint
more clear.
Additionally, corrects change from 47ab7d6612e2b5b8b66fb261dafef7c91264e173
to still allow displayList alpha to override layer paint
Change-Id: Ic94d75865700820489370461cd8ac9f9077a8d90
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/DisplayList.cpp | 9 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 25 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.h | 20 |
3 files changed, 43 insertions, 11 deletions
diff --git a/libs/hwui/DisplayList.cpp b/libs/hwui/DisplayList.cpp index d985ad0..36c95f9 100644 --- a/libs/hwui/DisplayList.cpp +++ b/libs/hwui/DisplayList.cpp @@ -352,7 +352,9 @@ void DisplayList::outputViewProperties(const int level) { } } if (mAlpha < 1) { - if (mCaching || !mHasOverlappingRendering) { + if (mCaching) { + ALOGD("%*sSetOverrideLayerAlpha %.2f", level * 2, "", mAlpha); + } else if (!mHasOverlappingRendering) { ALOGD("%*sScaleAlpha %.2f", level * 2, "", mAlpha); } else { int flags = SkCanvas::kHasAlphaLayer_SaveFlag; @@ -400,7 +402,9 @@ void DisplayList::setViewProperties(OpenGLRenderer& renderer, T& handler, } } if (mAlpha < 1) { - if (mCaching || !mHasOverlappingRendering) { + if (mCaching) { + renderer.setOverrideLayerAlpha(mAlpha); + } else if (!mHasOverlappingRendering) { renderer.scaleAlpha(mAlpha); } else { // TODO: should be able to store the size of a DL at record time and not @@ -513,6 +517,7 @@ void DisplayList::iterate(OpenGLRenderer& renderer, T& handler, const int level) DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (level + 1) * 2, "", restoreTo); handler(mRestoreToCountOp->reinit(restoreTo), PROPERTY_SAVECOUNT); renderer.restoreToCount(restoreTo); + renderer.setOverrideLayerAlpha(1.0f); } }; // namespace uirenderer diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 4a5785c..1138998 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -114,6 +114,7 @@ OpenGLRenderer::OpenGLRenderer(): mCaches(Caches::getInstance()), mExtensions(Extensions::getInstance()) { mDrawModifiers.mShader = NULL; mDrawModifiers.mColorFilter = NULL; + mDrawModifiers.mOverrideLayerAlpha = 1.0f; mDrawModifiers.mHasShadow = false; mDrawModifiers.mHasDrawFilter = false; @@ -1074,7 +1075,7 @@ void OpenGLRenderer::composeLayerRect(Layer* layer, const Rect& rect, bool swap) layer->setFilter(GL_LINEAR, true); } - float alpha = layer->getAlpha() / 255.0f * mSnapshot->alpha; + float alpha = getLayerAlpha(layer); bool blend = layer->isBlend() || alpha < 1.0f; drawTextureMesh(x, y, x + rect.getWidth(), y + rect.getHeight(), layer->getTexture(), alpha, layer->getMode(), blend, @@ -1112,7 +1113,7 @@ void OpenGLRenderer::composeLayerRegion(Layer* layer, const Rect& rect) { rects = safeRegion.getArray(&count); } - const float alpha = layer->getAlpha() / 255.0f * mSnapshot->alpha; + const float alpha = getLayerAlpha(layer); const float texX = 1.0f / float(layer->getWidth()); const float texY = 1.0f / float(layer->getHeight()); const float height = rect.getHeight(); @@ -2237,7 +2238,7 @@ status_t OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const float left, float top, float right, float bottom, SkPaint* paint) { int alpha; SkXfermode::Mode mode; - getAlphaAndModeDirect(paint, &alpha, &mode); + getAlphaAndMode(paint, &alpha, &mode); return drawPatch(bitmap, xDivs, yDivs, colors, width, height, numColors, left, top, right, bottom, alpha, mode); @@ -2990,7 +2991,7 @@ status_t OpenGLRenderer::drawLayer(Layer* layer, float x, float y) { if (layer->region.isRect()) { composeLayerRect(layer, layer->regionRect); } else if (layer->mesh) { - const float a = layer->getAlpha() / 255.0f * mSnapshot->alpha; + const float a = getLayerAlpha(layer); setupDraw(); setupDrawWithTexture(); setupDrawColor(a, a, a, a); @@ -3446,10 +3447,24 @@ void OpenGLRenderer::resetDrawTextureTexCoords(float u1, float v1, float u2, flo TextureVertex::setUV(v++, u2, v2); } -void OpenGLRenderer::getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode) { +void OpenGLRenderer::getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode) const { getAlphaAndModeDirect(paint, alpha, mode); + if (mDrawModifiers.mOverrideLayerAlpha < 1.0f) { + // if drawing a layer, ignore the paint's alpha + *alpha = mDrawModifiers.mOverrideLayerAlpha; + } *alpha *= mSnapshot->alpha; } +float OpenGLRenderer::getLayerAlpha(Layer* layer) const { + float alpha; + if (mDrawModifiers.mOverrideLayerAlpha < 1.0f) { + alpha = mDrawModifiers.mOverrideLayerAlpha; + } else { + alpha = layer->getAlpha() / 255.0f; + } + return alpha * mSnapshot->alpha; +} + }; // namespace uirenderer }; // namespace android diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h index 04a47fc..dd7a5a2 100644 --- a/libs/hwui/OpenGLRenderer.h +++ b/libs/hwui/OpenGLRenderer.h @@ -51,6 +51,7 @@ namespace uirenderer { struct DrawModifiers { SkiaShader* mShader; SkiaColorFilter* mColorFilter; + float mOverrideLayerAlpha; // Drop shadow bool mHasShadow; @@ -275,6 +276,9 @@ public: virtual void resetPaintFilter(); virtual void setupPaintFilter(int clearBits, int setBits); + // If this value is set to < 1.0, it overrides alpha set on layer (see drawBitmap, drawLayer) + void setOverrideLayerAlpha(float alpha) { mDrawModifiers.mOverrideLayerAlpha = alpha; } + SkPaint* filterPaint(SkPaint* paint); bool storeDisplayState(DeferredDisplayState& state, int stateDeferFlags); @@ -283,7 +287,6 @@ public: const DrawModifiers& getDrawModifiers() { return mDrawModifiers; } void setDrawModifiers(const DrawModifiers& drawModifiers) { mDrawModifiers = drawModifiers; } - // TODO: what does this mean? no perspective? no rotate? ANDROID_API bool isCurrentTransformSimple() { return mSnapshot->transform->isSimple(); } @@ -325,7 +328,8 @@ public: /** * Gets the alpha and xfermode out of a paint object. If the paint is null * alpha will be 255 and the xfermode will be SRC_OVER. This method does - * not multiply the paint's alpha by the current snapshot's alpha. + * not multiply the paint's alpha by the current snapshot's alpha, and does + * not replace the alpha with the overrideLayerAlpha * * @param paint The paint to extract values from * @param alpha Where to store the resulting alpha @@ -450,13 +454,21 @@ protected: /** * Gets the alpha and xfermode out of a paint object. If the paint is null - * alpha will be 255 and the xfermode will be SRC_OVER. + * alpha will be 255 and the xfermode will be SRC_OVER. Accounts for both + * snapshot alpha, and overrideLayerAlpha * * @param paint The paint to extract values from * @param alpha Where to store the resulting alpha * @param mode Where to store the resulting xfermode */ - inline void getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode); + inline void getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode) const; + + /** + * Gets the alpha from a layer, accounting for snapshot alpha and overrideLayerAlpha + * + * @param layer The layer from which the alpha is extracted + */ + inline float getLayerAlpha(Layer* layer) const; /** * Safely retrieves the mode from the specified xfermode. If the specified |