From 5a4690bf26932c0d6940e4af8516d920e09ae81a Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Tue, 14 Jul 2015 12:13:03 -0700 Subject: Clean up unncessary defines LOG_TAG and TRACE_TAG are already defined in the makefile Change-Id: I9e53e3dacbe018441edd74cb7c8c90846defee74 --- libs/hwui/ProgramCache.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'libs/hwui/ProgramCache.cpp') diff --git a/libs/hwui/ProgramCache.cpp b/libs/hwui/ProgramCache.cpp index 41adda15f367..7f16deb41813 100644 --- a/libs/hwui/ProgramCache.cpp +++ b/libs/hwui/ProgramCache.cpp @@ -14,8 +14,6 @@ * limitations under the License. */ -#define LOG_TAG "OpenGLRenderer" - #include #include "Caches.h" -- cgit v1.2.3-59-g8ed1b From 8bd68c6b7d4d6d3137edf1cbdc0e0de266c5b9ee Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Wed, 19 Aug 2015 15:29:05 -0700 Subject: Define GLSL version bug:21923805 Change-Id: Ie44fb9cf38ef5f19df957e4a639d9c7d47da391e --- libs/hwui/ProgramCache.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'libs/hwui/ProgramCache.cpp') diff --git a/libs/hwui/ProgramCache.cpp b/libs/hwui/ProgramCache.cpp index 7f16deb41813..29cca36c9ce4 100644 --- a/libs/hwui/ProgramCache.cpp +++ b/libs/hwui/ProgramCache.cpp @@ -38,7 +38,8 @@ namespace uirenderer { // Vertex shaders snippets /////////////////////////////////////////////////////////////////////////////// -const char* gVS_Header_Attributes = +const char* gVS_Header_Start = + "#version 100\n" "attribute vec4 position;\n"; const char* gVS_Header_Attributes_TexCoords = "attribute vec2 texCoords;\n"; @@ -132,6 +133,8 @@ const char* gVS_Footer = // Fragment shaders snippets /////////////////////////////////////////////////////////////////////////////// +const char* gFS_Header_Start = + "#version 100\n"; const char* gFS_Header_Extension_FramebufferFetch = "#extension GL_NV_shader_framebuffer_fetch : enable\n\n"; const char* gFS_Header_Extension_ExternalTexture = @@ -457,7 +460,7 @@ static inline size_t gradientIndex(const ProgramDescription& description) { String8 ProgramCache::generateVertexShader(const ProgramDescription& description) { // Add attributes - String8 shader(gVS_Header_Attributes); + String8 shader(gVS_Header_Start); if (description.hasTexture || description.hasExternalTexture) { shader.append(gVS_Header_Attributes_TexCoords); } @@ -543,7 +546,7 @@ static bool shaderOp(const ProgramDescription& description, String8& shader, } String8 ProgramCache::generateFragmentShader(const ProgramDescription& description) { - String8 shader; + String8 shader(gFS_Header_Start); const bool blendFramebuffer = description.framebufferMode >= SkXfermode::kPlus_Mode; if (blendFramebuffer) { -- cgit v1.2.3-59-g8ed1b From b9ce116dac378b4cf4490f265dcbd5704a1dd43c Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Thu, 20 Aug 2015 15:14:06 -0700 Subject: Switch several enums to enum classes Change-Id: I00ecd0b61657196b51704f70ca31a9d1c1ac254e --- libs/hwui/Animator.cpp | 28 ++++++++++++++-------------- libs/hwui/Animator.h | 20 ++++++++++---------- libs/hwui/Caches.cpp | 6 +++--- libs/hwui/Caches.h | 10 +++++----- libs/hwui/GlopBuilder.cpp | 6 +++--- libs/hwui/Layer.cpp | 2 +- libs/hwui/Layer.h | 22 +++++++++++----------- libs/hwui/LayerCache.cpp | 10 +++++----- libs/hwui/LayerRenderer.cpp | 2 +- libs/hwui/Outline.h | 32 ++++++++++++++++---------------- libs/hwui/Program.h | 16 ++++++++-------- libs/hwui/ProgramCache.cpp | 8 ++++---- libs/hwui/RenderNode.cpp | 10 +++++----- libs/hwui/RenderNode.h | 6 +++--- libs/hwui/renderstate/RenderState.cpp | 4 ++-- libs/hwui/renderstate/Stencil.cpp | 24 ++++++++++-------------- libs/hwui/renderstate/Stencil.h | 21 +++++++++------------ libs/hwui/renderthread/CanvasContext.cpp | 6 +++--- 18 files changed, 113 insertions(+), 120 deletions(-) (limited to 'libs/hwui/ProgramCache.cpp') diff --git a/libs/hwui/Animator.cpp b/libs/hwui/Animator.cpp index 512e0e24aa93..5ca2a2fa37ab 100644 --- a/libs/hwui/Animator.cpp +++ b/libs/hwui/Animator.cpp @@ -36,8 +36,8 @@ BaseRenderNodeAnimator::BaseRenderNodeAnimator(float finalValue) , mFinalValue(finalValue) , mDeltaValue(0) , mFromValue(0) - , mStagingPlayState(NOT_STARTED) - , mPlayState(NOT_STARTED) + , mStagingPlayState(PlayState::NotStarted) + , mPlayState(PlayState::NotStarted) , mHasStartValue(false) , mStartTime(0) , mDuration(300) @@ -50,7 +50,7 @@ BaseRenderNodeAnimator::~BaseRenderNodeAnimator() { void BaseRenderNodeAnimator::checkMutable() { // Should be impossible to hit as the Java-side also has guards for this - LOG_ALWAYS_FATAL_IF(mStagingPlayState != NOT_STARTED, + LOG_ALWAYS_FATAL_IF(mStagingPlayState != PlayState::NotStarted, "Animator has already been started!"); } @@ -92,9 +92,9 @@ void BaseRenderNodeAnimator::pushStaging(AnimationContext& context) { if (mStagingPlayState > mPlayState) { mPlayState = mStagingPlayState; // Oh boy, we're starting! Man the battle stations! - if (mPlayState == RUNNING) { + if (mPlayState == PlayState::Running) { transitionToRunning(context); - } else if (mPlayState == FINISHED) { + } else if (mPlayState == PlayState::Finished) { callOnFinishedListener(context); } } @@ -124,10 +124,10 @@ void BaseRenderNodeAnimator::transitionToRunning(AnimationContext& context) { } bool BaseRenderNodeAnimator::animate(AnimationContext& context) { - if (mPlayState < RUNNING) { + if (mPlayState < PlayState::Running) { return false; } - if (mPlayState == FINISHED) { + if (mPlayState == PlayState::Finished) { return true; } @@ -141,18 +141,18 @@ bool BaseRenderNodeAnimator::animate(AnimationContext& context) { } float fraction = 1.0f; - if (mPlayState == RUNNING && mDuration > 0) { + if (mPlayState == PlayState::Running && mDuration > 0) { fraction = (float)(context.frameTimeMs() - mStartTime) / mDuration; } if (fraction >= 1.0f) { fraction = 1.0f; - mPlayState = FINISHED; + mPlayState = PlayState::Finished; } fraction = mInterpolator->interpolate(fraction); setValue(mTarget, mFromValue + (mDeltaValue * fraction)); - if (mPlayState == FINISHED) { + if (mPlayState == PlayState::Finished) { callOnFinishedListener(context); return true; } @@ -161,8 +161,8 @@ bool BaseRenderNodeAnimator::animate(AnimationContext& context) { } void BaseRenderNodeAnimator::forceEndNow(AnimationContext& context) { - if (mPlayState < FINISHED) { - mPlayState = FINISHED; + if (mPlayState < PlayState::Finished) { + mPlayState = PlayState::Finished; callOnFinishedListener(context); } } @@ -212,9 +212,9 @@ void RenderPropertyAnimator::onAttached() { } void RenderPropertyAnimator::onStagingPlayStateChanged() { - if (mStagingPlayState == RUNNING) { + if (mStagingPlayState == PlayState::Running) { (mTarget->mutateStagingProperties().*mPropertyAccess->setter)(finalValue()); - } else if (mStagingPlayState == FINISHED) { + } else if (mStagingPlayState == PlayState::Finished) { // We're being canceled, so make sure that whatever values the UI thread // is observing for us is pushed over mTarget->setPropertyFieldsDirty(dirtyMask()); diff --git a/libs/hwui/Animator.h b/libs/hwui/Animator.h index 1b3d8e7f4842..aea95bfc1c0e 100644 --- a/libs/hwui/Animator.h +++ b/libs/hwui/Animator.h @@ -59,8 +59,8 @@ public: mMayRunAsync = mayRunAsync; } bool mayRunAsync() { return mMayRunAsync; } - ANDROID_API void start() { mStagingPlayState = RUNNING; onStagingPlayStateChanged(); } - ANDROID_API void end() { mStagingPlayState = FINISHED; onStagingPlayStateChanged(); } + ANDROID_API void start() { mStagingPlayState = PlayState::Running; onStagingPlayStateChanged(); } + ANDROID_API void end() { mStagingPlayState = PlayState::Finished; onStagingPlayStateChanged(); } void attach(RenderNode* target); virtual void onAttached() {} @@ -68,8 +68,8 @@ public: void pushStaging(AnimationContext& context); bool animate(AnimationContext& context); - bool isRunning() { return mPlayState == RUNNING; } - bool isFinished() { return mPlayState == FINISHED; } + bool isRunning() { return mPlayState == PlayState::Running; } + bool isFinished() { return mPlayState == PlayState::Finished; } float finalValue() { return mFinalValue; } ANDROID_API virtual uint32_t dirtyMask() = 0; @@ -77,6 +77,12 @@ public: void forceEndNow(AnimationContext& context); protected: + enum class PlayState { + NotStarted, + Running, + Finished, + }; + BaseRenderNodeAnimator(float finalValue); virtual ~BaseRenderNodeAnimator(); @@ -88,12 +94,6 @@ protected: virtual void onStagingPlayStateChanged() {} - enum PlayState { - NOT_STARTED, - RUNNING, - FINISHED, - }; - RenderNode* mTarget; float mFinalValue; diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp index f663f07269d7..ff713133e389 100644 --- a/libs/hwui/Caches.cpp +++ b/libs/hwui/Caches.cpp @@ -245,7 +245,7 @@ void Caches::flush(FlushMode mode) { FLUSH_LOGD("Flushing caches (mode %d)", mode); switch (mode) { - case kFlushMode_Full: + case FlushMode::Full: textureCache.clear(); patchCache.clear(); dropShadowCache.clear(); @@ -254,13 +254,13 @@ void Caches::flush(FlushMode mode) { fboCache.clear(); dither.clear(); // fall through - case kFlushMode_Moderate: + case FlushMode::Moderate: fontRenderer->flush(); textureCache.flush(); pathCache.clear(); tessellationCache.clear(); // fall through - case kFlushMode_Layers: + case FlushMode::Layers: layerCache.clear(); renderBufferCache.clear(); break; diff --git a/libs/hwui/Caches.h b/libs/hwui/Caches.h index a02e15de7fb0..929db17a22a8 100644 --- a/libs/hwui/Caches.h +++ b/libs/hwui/Caches.h @@ -83,10 +83,10 @@ private: static Caches* sInstance; public: - enum FlushMode { - kFlushMode_Layers = 0, - kFlushMode_Moderate, - kFlushMode_Full + enum class FlushMode { + Layers = 0, + Moderate, + Full }; /** @@ -103,7 +103,7 @@ public: /** * Destroys all resources associated with this cache. This should - * be called after a flush(kFlushMode_Full). + * be called after a flush(FlushMode::Full). */ void terminate(); diff --git a/libs/hwui/GlopBuilder.cpp b/libs/hwui/GlopBuilder.cpp index c9e388021558..e27b26b1d091 100644 --- a/libs/hwui/GlopBuilder.cpp +++ b/libs/hwui/GlopBuilder.cpp @@ -274,7 +274,7 @@ void GlopBuilder::setFill(int color, float alphaScale, SkXfermode::Mode mode; SkScalar srcColorMatrix[20]; if (colorFilter->asColorMode(&color, &mode)) { - mOutGlop->fill.filterMode = mDescription.colorOp = ProgramDescription::kColorBlend; + mOutGlop->fill.filterMode = mDescription.colorOp = ProgramDescription::ColorFilterMode::Blend; mDescription.colorMode = mode; const float alpha = SkColorGetA(color) / 255.0f; @@ -286,7 +286,7 @@ void GlopBuilder::setFill(int color, float alphaScale, alpha, }; } else if (colorFilter->asColorMatrix(srcColorMatrix)) { - mOutGlop->fill.filterMode = mDescription.colorOp = ProgramDescription::kColorMatrix; + mOutGlop->fill.filterMode = mDescription.colorOp = ProgramDescription::ColorFilterMode::Matrix; float* colorMatrix = mOutGlop->fill.filter.matrix.matrix; memcpy(colorMatrix, srcColorMatrix, 4 * sizeof(float)); @@ -305,7 +305,7 @@ void GlopBuilder::setFill(int color, float alphaScale, LOG_ALWAYS_FATAL("unsupported ColorFilter"); } } else { - mOutGlop->fill.filterMode = ProgramDescription::kColorNone; + mOutGlop->fill.filterMode = ProgramDescription::ColorFilterMode::None; } } diff --git a/libs/hwui/Layer.cpp b/libs/hwui/Layer.cpp index 928f91bdd4d9..e7482211b399 100644 --- a/libs/hwui/Layer.cpp +++ b/libs/hwui/Layer.cpp @@ -36,7 +36,7 @@ namespace android { namespace uirenderer { Layer::Layer(Type layerType, RenderState& renderState, uint32_t layerWidth, uint32_t layerHeight) - : state(kState_Uncached) + : state(State::Uncached) , caches(Caches::getInstance()) , renderState(renderState) , texture(caches) diff --git a/libs/hwui/Layer.h b/libs/hwui/Layer.h index b670870ca55f..e90f055b667b 100644 --- a/libs/hwui/Layer.h +++ b/libs/hwui/Layer.h @@ -56,19 +56,19 @@ struct DeferStateStruct; */ class Layer : public VirtualLightRefBase { public: - enum Type { - kType_Texture, - kType_DisplayList, + enum class Type { + Texture, + DisplayList, }; // layer lifecycle, controlled from outside - enum State { - kState_Uncached = 0, - kState_InCache = 1, - kState_FailedToCache = 2, - kState_RemovedFromCache = 3, - kState_DeletedFromCache = 4, - kState_InGarbageList = 5, + enum class State { + Uncached = 0, + InCache = 1, + FailedToCache = 2, + RemovedFromCache = 3, + DeletedFromCache = 4, + InGarbageList = 5, }; State state; // public for logging/debugging purposes @@ -241,7 +241,7 @@ public: } inline bool isTextureLayer() const { - return type == kType_Texture; + return type == Type::Texture; } inline SkColorFilter* getColorFilter() const { diff --git a/libs/hwui/LayerCache.cpp b/libs/hwui/LayerCache.cpp index 33f40b006092..39cadd198c83 100644 --- a/libs/hwui/LayerCache.cpp +++ b/libs/hwui/LayerCache.cpp @@ -81,7 +81,7 @@ void LayerCache::deleteLayer(Layer* layer) { LAYER_LOGD("Destroying layer %dx%d, fbo %d", layer->getWidth(), layer->getHeight(), layer->getFbo()); mSize -= layer->getWidth() * layer->getHeight() * 4; - layer->state = Layer::kState_DeletedFromCache; + layer->state = Layer::State::DeletedFromCache; layer->decStrong(nullptr); } } @@ -104,14 +104,14 @@ Layer* LayerCache::get(RenderState& renderState, const uint32_t width, const uin mCache.erase(iter); layer = entry.mLayer; - layer->state = Layer::kState_RemovedFromCache; + layer->state = Layer::State::RemovedFromCache; mSize -= layer->getWidth() * layer->getHeight() * 4; LAYER_LOGD("Reusing layer %dx%d", layer->getWidth(), layer->getHeight()); } else { LAYER_LOGD("Creating new layer %dx%d", entry.mWidth, entry.mHeight); - layer = new Layer(Layer::kType_DisplayList, renderState, entry.mWidth, entry.mHeight); + layer = new Layer(Layer::Type::DisplayList, renderState, entry.mWidth, entry.mHeight); layer->setBlend(true); layer->generateTexture(); layer->bindTexture(); @@ -156,11 +156,11 @@ bool LayerCache::put(Layer* layer) { mCache.insert(entry); mSize += size; - layer->state = Layer::kState_InCache; + layer->state = Layer::State::InCache; return true; } - layer->state = Layer::kState_FailedToCache; + layer->state = Layer::State::FailedToCache; return false; } diff --git a/libs/hwui/LayerRenderer.cpp b/libs/hwui/LayerRenderer.cpp index 00add2903371..d8e6392bd07e 100644 --- a/libs/hwui/LayerRenderer.cpp +++ b/libs/hwui/LayerRenderer.cpp @@ -272,7 +272,7 @@ bool LayerRenderer::resizeLayer(Layer* layer, uint32_t width, uint32_t height) { Layer* LayerRenderer::createTextureLayer(RenderState& renderState) { LAYER_RENDERER_LOGD("Creating new texture layer"); - Layer* layer = new Layer(Layer::kType_Texture, renderState, 0, 0); + Layer* layer = new Layer(Layer::Type::Texture, renderState, 0, 0); layer->setCacheable(false); layer->layer.set(0.0f, 0.0f, 0.0f, 0.0f); layer->texCoords.set(0.0f, 1.0f, 1.0f, 0.0f); diff --git a/libs/hwui/Outline.h b/libs/hwui/Outline.h index 8d4d4f085f98..4bd4ae1d48c9 100644 --- a/libs/hwui/Outline.h +++ b/libs/hwui/Outline.h @@ -28,13 +28,13 @@ class Outline { public: Outline() : mShouldClip(false) - , mType(kOutlineType_None) + , mType(Type::None) , mRadius(0) , mAlpha(0.0f) {} void setRoundRect(int left, int top, int right, int bottom, float radius, float alpha) { mAlpha = alpha; - if (mType == kOutlineType_RoundRect + if (mType == Type::RoundRect && left == mBounds.left && right == mBounds.right && top == mBounds.top @@ -44,7 +44,7 @@ public: return; } - mType = kOutlineType_RoundRect; + mType = Type::RoundRect; mBounds.set(left, top, right, bottom); mRadius = radius; @@ -63,26 +63,26 @@ public: setEmpty(); return; } - mType = kOutlineType_ConvexPath; + mType = Type::ConvexPath; mPath = *outline; mBounds.set(outline->getBounds()); mAlpha = alpha; } void setEmpty() { - mType = kOutlineType_Empty; + mType = Type::Empty; mPath.reset(); mAlpha = 0.0f; } void setNone() { - mType = kOutlineType_None; + mType = Type::None; mPath.reset(); mAlpha = 0.0f; } bool isEmpty() const { - return mType == kOutlineType_Empty; + return mType == Type::Empty; } float getAlpha() const { @@ -99,7 +99,7 @@ public: bool willClip() const { // only round rect outlines can be used for clipping - return mShouldClip && (mType == kOutlineType_RoundRect); + return mShouldClip && (mType == Type::RoundRect); } bool willRoundRectClip() const { @@ -108,7 +108,7 @@ public: } bool getAsRoundRect(Rect* outRect, float* outRadius) const { - if (mType == kOutlineType_RoundRect) { + if (mType == Type::RoundRect) { outRect->set(mBounds); *outRadius = mRadius; return true; @@ -117,21 +117,21 @@ public: } const SkPath* getPath() const { - if (mType == kOutlineType_None || mType == kOutlineType_Empty) return nullptr; + if (mType == Type::None || mType == Type::Empty) return nullptr; return &mPath; } private: - enum OutlineType { - kOutlineType_None = 0, - kOutlineType_Empty = 1, - kOutlineType_ConvexPath = 2, - kOutlineType_RoundRect = 3 + enum class Type { + None = 0, + Empty = 1, + ConvexPath = 2, + RoundRect = 3 }; bool mShouldClip; - OutlineType mType; + Type mType; Rect mBounds; float mRadius; float mAlpha; diff --git a/libs/hwui/Program.h b/libs/hwui/Program.h index af1e4a74d46e..b09c207f6e45 100644 --- a/libs/hwui/Program.h +++ b/libs/hwui/Program.h @@ -103,10 +103,10 @@ typedef uint64_t programid; * A ProgramDescription must be used in conjunction with a ProgramCache. */ struct ProgramDescription { - enum ColorFilterMode { - kColorNone = 0, - kColorMatrix, - kColorBlend + enum class ColorFilterMode { + None = 0, + Matrix, + Blend }; enum Gradient { @@ -193,7 +193,7 @@ struct ProgramDescription { bitmapWrapS = GL_CLAMP_TO_EDGE; bitmapWrapT = GL_CLAMP_TO_EDGE; - colorOp = kColorNone; + colorOp = ColorFilterMode::None; colorMode = SkXfermode::kClear_Mode; framebufferMode = SkXfermode::kClear_Mode; @@ -249,14 +249,14 @@ struct ProgramDescription { key |= (shadersMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_SHADER_SHIFT; } switch (colorOp) { - case kColorMatrix: + case ColorFilterMode::Matrix: key |= PROGRAM_KEY_COLOR_MATRIX; break; - case kColorBlend: + case ColorFilterMode::Blend: key |= PROGRAM_KEY_COLOR_BLEND; key |= (colorMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_COLOR_OP_SHIFT; break; - case kColorNone: + case ColorFilterMode::None: break; } key |= (framebufferMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_FRAMEBUFFER_SHIFT; diff --git a/libs/hwui/ProgramCache.cpp b/libs/hwui/ProgramCache.cpp index 7f16deb41813..1ac368f423b8 100644 --- a/libs/hwui/ProgramCache.cpp +++ b/libs/hwui/ProgramCache.cpp @@ -604,7 +604,7 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti if (!description.hasVertexAlpha && !blendFramebuffer && !description.hasColors - && description.colorOp == ProgramDescription::kColorNone + && description.colorOp == ProgramDescription::ColorFilterMode::None && !description.hasDebugHighlight && !description.hasRoundRectClip) { bool fast = false; @@ -668,13 +668,13 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti if (description.hasBitmap) { shader.append(gFS_Uniforms_BitmapSampler); } - shader.append(gFS_Uniforms_ColorOp[description.colorOp]); + shader.append(gFS_Uniforms_ColorOp[static_cast(description.colorOp)]); // Generate required functions if (description.hasGradient && description.hasBitmap) { generateBlend(shader, "blendShaders", description.shadersMode); } - if (description.colorOp == ProgramDescription::kColorBlend) { + if (description.colorOp == ProgramDescription::ColorFilterMode::Blend) { generateBlend(shader, "blendColors", description.colorMode); } if (blendFramebuffer) { @@ -737,7 +737,7 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti } // Apply the color op if needed - shader.append(gFS_Main_ApplyColorOp[description.colorOp]); + shader.append(gFS_Main_ApplyColorOp[static_cast(description.colorOp)]); if (description.hasVertexAlpha) { if (description.useShadowAlphaInterp) { diff --git a/libs/hwui/RenderNode.cpp b/libs/hwui/RenderNode.cpp index 73c01075e842..1414fd541909 100644 --- a/libs/hwui/RenderNode.cpp +++ b/libs/hwui/RenderNode.cpp @@ -710,8 +710,8 @@ void RenderNode::issueOperationsOf3dChildren(ChildrenSelectMode mode, OpenGLRenderer& renderer, T& handler) { const int size = zTranslatedNodes.size(); if (size == 0 - || (mode == kNegativeZChildren && zTranslatedNodes[0].key > 0.0f) - || (mode == kPositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) { + || (mode == ChildrenSelectMode::NegativeZChildren && zTranslatedNodes[0].key > 0.0f) + || (mode == ChildrenSelectMode::PositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) { // no 3d children to draw return; } @@ -730,7 +730,7 @@ void RenderNode::issueOperationsOf3dChildren(ChildrenSelectMode mode, */ const size_t nonNegativeIndex = findNonNegativeIndex(zTranslatedNodes); size_t drawIndex, shadowIndex, endIndex; - if (mode == kNegativeZChildren) { + if (mode == ChildrenSelectMode::NegativeZChildren) { drawIndex = 0; endIndex = nonNegativeIndex; shadowIndex = endIndex; // draw no shadows @@ -886,7 +886,7 @@ void RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) { std::vector zTranslatedNodes; buildZSortedChildList(chunk, zTranslatedNodes); - issueOperationsOf3dChildren(kNegativeZChildren, + issueOperationsOf3dChildren(ChildrenSelectMode::NegativeZChildren, initialTransform, zTranslatedNodes, renderer, handler); @@ -903,7 +903,7 @@ void RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) { } } - issueOperationsOf3dChildren(kPositiveZChildren, + issueOperationsOf3dChildren(ChildrenSelectMode::PositiveZChildren, initialTransform, zTranslatedNodes, renderer, handler); } } diff --git a/libs/hwui/RenderNode.h b/libs/hwui/RenderNode.h index 6d1a2b7be1f9..3bff2b393f74 100644 --- a/libs/hwui/RenderNode.h +++ b/libs/hwui/RenderNode.h @@ -184,9 +184,9 @@ private: return nodes.size(); } - enum ChildrenSelectMode { - kNegativeZChildren, - kPositiveZChildren + enum class ChildrenSelectMode { + NegativeZChildren, + PositiveZChildren }; void computeOrderingImpl(DrawRenderNodeOp* opState, diff --git a/libs/hwui/renderstate/RenderState.cpp b/libs/hwui/renderstate/RenderState.cpp index b5ed9e6558a7..c5126def683c 100644 --- a/libs/hwui/renderstate/RenderState.cpp +++ b/libs/hwui/renderstate/RenderState.cpp @@ -229,11 +229,11 @@ void RenderState::render(const Glop& glop) { glop.transform.transformFlags & TransformFlags::OffsetByFudgeFactor); // Color filter uniforms - if (fill.filterMode == ProgramDescription::kColorBlend) { + if (fill.filterMode == ProgramDescription::ColorFilterMode::Blend) { const FloatColor& color = fill.filter.color; glUniform4f(mCaches->program().getUniform("colorBlend"), color.r, color.g, color.b, color.a); - } else if (fill.filterMode == ProgramDescription::kColorMatrix) { + } else if (fill.filterMode == ProgramDescription::ColorFilterMode::Matrix) { glUniformMatrix4fv(mCaches->program().getUniform("colorMatrix"), 1, GL_FALSE, fill.filter.matrix.matrix); glUniform4fv(mCaches->program().getUniform("colorMatrixVector"), 1, diff --git a/libs/hwui/renderstate/Stencil.cpp b/libs/hwui/renderstate/Stencil.cpp index 319cfe4ba0d0..d25ad514e892 100644 --- a/libs/hwui/renderstate/Stencil.cpp +++ b/libs/hwui/renderstate/Stencil.cpp @@ -34,10 +34,6 @@ namespace uirenderer { #define STENCIL_MASK_VALUE 0x1 #endif -Stencil::Stencil() - : mState(kDisabled) { -} - uint8_t Stencil::getStencilSize() { return STENCIL_BUFFER_SIZE; } @@ -64,14 +60,14 @@ void Stencil::clear() { glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT); - if (mState == kTest) { + if (mState == StencilState::Test) { // reset to test state, with immutable stencil glStencilMask(0); } } void Stencil::enableTest(int incrementThreshold) { - if (mState != kTest) { + if (mState != StencilState::Test) { enable(); if (incrementThreshold > 0) { glStencilFunc(GL_EQUAL, incrementThreshold, 0xff); @@ -82,12 +78,12 @@ void Stencil::enableTest(int incrementThreshold) { glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glStencilMask(0); - mState = kTest; + mState = StencilState::Test; } } void Stencil::enableWrite(int incrementThreshold) { - if (mState != kWrite) { + if (mState != StencilState::Write) { enable(); if (incrementThreshold > 0) { glStencilFunc(GL_ALWAYS, 1, 0xff); @@ -100,7 +96,7 @@ void Stencil::enableWrite(int incrementThreshold) { } glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glStencilMask(0xff); - mState = kWrite; + mState = StencilState::Write; } } @@ -109,7 +105,7 @@ void Stencil::enableDebugTest(GLint value, bool greater) { glStencilFunc(greater ? GL_LESS : GL_EQUAL, value, 0xffffffff); // We only want to test, let's keep everything glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - mState = kTest; + mState = StencilState::Test; glStencilMask(0); } @@ -119,20 +115,20 @@ void Stencil::enableDebugWrite() { // The test always passes so the first two values are meaningless glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - mState = kWrite; + mState = StencilState::Write; glStencilMask(0xff); } void Stencil::enable() { - if (mState == kDisabled) { + if (mState == StencilState::Disabled) { glEnable(GL_STENCIL_TEST); } } void Stencil::disable() { - if (mState != kDisabled) { + if (mState != StencilState::Disabled) { glDisable(GL_STENCIL_TEST); - mState = kDisabled; + mState = StencilState::Disabled; } } diff --git a/libs/hwui/renderstate/Stencil.h b/libs/hwui/renderstate/Stencil.h index 32618230bbf6..5f7d4056b51d 100644 --- a/libs/hwui/renderstate/Stencil.h +++ b/libs/hwui/renderstate/Stencil.h @@ -30,8 +30,6 @@ namespace uirenderer { class ANDROID_API Stencil { public: - Stencil(); - /** * Returns the desired size for the stencil buffer. If the returned value * is 0, then no stencil buffer is required. @@ -81,32 +79,31 @@ public: * Indicates whether either test or write is enabled. */ bool isEnabled() { - return mState != kDisabled; + return mState != StencilState::Disabled; } /** * Indicates whether testing only is enabled. */ bool isTestEnabled() { - return mState == kTest; + return mState == StencilState::Test; } bool isWriteEnabled() { - return mState == kWrite; + return mState == StencilState::Write; } void dump(); private: - void enable(); - - enum StencilState { - kDisabled, - kTest, - kWrite + enum class StencilState { + Disabled, + Test, + Write }; - StencilState mState; + void enable(); + StencilState mState = StencilState::Disabled; }; // class Stencil diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp index 67c42f3c9977..7cb773805c21 100644 --- a/libs/hwui/renderthread/CanvasContext.cpp +++ b/libs/hwui/renderthread/CanvasContext.cpp @@ -421,7 +421,7 @@ void CanvasContext::destroyHardwareResources() { // Make sure to release all the textures we were owning as there won't // be another draw caches.textureCache.resetMarkInUse(this); - caches.flush(Caches::kFlushMode_Layers); + caches.flush(Caches::FlushMode::Layers); } } @@ -431,10 +431,10 @@ void CanvasContext::trimMemory(RenderThread& thread, int level) { ATRACE_CALL(); if (level >= TRIM_MEMORY_COMPLETE) { - Caches::getInstance().flush(Caches::kFlushMode_Full); + Caches::getInstance().flush(Caches::FlushMode::Full); thread.eglManager().destroy(); } else if (level >= TRIM_MEMORY_UI_HIDDEN) { - Caches::getInstance().flush(Caches::kFlushMode_Moderate); + Caches::getInstance().flush(Caches::FlushMode::Moderate); } } -- cgit v1.2.3-59-g8ed1b From 11718bc17bcfc56dfb9f4362eebf640b025c4415 Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Tue, 22 Sep 2015 11:50:13 -0700 Subject: Remove shader based gamma approach Also fixes some INIT_LOGD logs Change-Id: I212a71a1e7b366aea41f7c3c8cc169d509d6e4a2 --- libs/hwui/GammaFontRenderer.cpp | 48 -------------------------------- libs/hwui/GammaFontRenderer.h | 61 ----------------------------------------- libs/hwui/PathCache.cpp | 4 +-- libs/hwui/Program.h | 17 +++--------- libs/hwui/ProgramCache.cpp | 48 +++++--------------------------- libs/hwui/Properties.h | 2 +- libs/hwui/TessellationCache.cpp | 4 +-- 7 files changed, 16 insertions(+), 168 deletions(-) (limited to 'libs/hwui/ProgramCache.cpp') diff --git a/libs/hwui/GammaFontRenderer.cpp b/libs/hwui/GammaFontRenderer.cpp index 0bcd83a1a050..6c3d04e7400e 100644 --- a/libs/hwui/GammaFontRenderer.cpp +++ b/libs/hwui/GammaFontRenderer.cpp @@ -43,10 +43,6 @@ GammaFontRenderer* GammaFontRenderer::createRenderer() { if (property_get(PROPERTY_TEXT_GAMMA_METHOD, property, DEFAULT_TEXT_GAMMA_METHOD) > 0) { if (!strcasecmp(property, "lookup")) { return new LookupGammaFontRenderer(); - } else if (!strcasecmp(property, "shader")) { - return new ShaderGammaFontRenderer(false); - } else if (!strcasecmp(property, "shader3")) { - return new ShaderGammaFontRenderer(true); } } @@ -90,50 +86,6 @@ GammaFontRenderer::GammaFontRenderer() { GammaFontRenderer::~GammaFontRenderer() { } -/////////////////////////////////////////////////////////////////////////////// -// Shader-based renderer -/////////////////////////////////////////////////////////////////////////////// - -ShaderGammaFontRenderer::ShaderGammaFontRenderer(bool multiGamma) - : GammaFontRenderer() { - INIT_LOGD("Creating shader gamma font renderer"); - mRenderer = nullptr; - mMultiGamma = multiGamma; -} - -void ShaderGammaFontRenderer::describe(ProgramDescription& description, - const SkPaint* paint) const { - if (paint->getShader() == nullptr) { - if (mMultiGamma) { - const int l = luminance(paint); - - if (l <= mBlackThreshold) { - description.hasGammaCorrection = true; - description.gamma = mGamma; - } else if (l >= mWhiteThreshold) { - description.hasGammaCorrection = true; - description.gamma = 1.0f / mGamma; - } - } else { - description.hasGammaCorrection = true; - description.gamma = 1.0f / mGamma; - } - } -} - -void ShaderGammaFontRenderer::setupProgram(ProgramDescription& description, - Program& program) const { - if (description.hasGammaCorrection) { - glUniform1f(program.getUniform("gamma"), description.gamma); - } -} - -void ShaderGammaFontRenderer::endPrecaching() { - if (mRenderer) { - mRenderer->endPrecaching(); - } -} - /////////////////////////////////////////////////////////////////////////////// // Lookup-based renderer /////////////////////////////////////////////////////////////////////////////// diff --git a/libs/hwui/GammaFontRenderer.h b/libs/hwui/GammaFontRenderer.h index ca55bf1e74e0..03f25106de38 100644 --- a/libs/hwui/GammaFontRenderer.h +++ b/libs/hwui/GammaFontRenderer.h @@ -37,9 +37,6 @@ public: virtual uint32_t getFontRendererCount() const = 0; virtual uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const = 0; - virtual void describe(ProgramDescription& description, const SkPaint* paint) const = 0; - virtual void setupProgram(ProgramDescription& description, Program& program) const = 0; - virtual void endPrecaching() = 0; static GammaFontRenderer* createRenderer(); @@ -53,52 +50,6 @@ protected: float mGamma; }; -class ShaderGammaFontRenderer: public GammaFontRenderer { -public: - ~ShaderGammaFontRenderer() { - delete mRenderer; - } - - void clear() override { - delete mRenderer; - mRenderer = nullptr; - } - - void flush() override { - if (mRenderer) { - mRenderer->flushLargeCaches(); - } - } - - FontRenderer& getFontRenderer(const SkPaint* paint) override { - if (!mRenderer) { - mRenderer = new FontRenderer; - } - return *mRenderer; - } - - uint32_t getFontRendererCount() const override { - return 1; - } - - uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const override { - return mRenderer ? mRenderer->getCacheSize(format) : 0; - } - - void describe(ProgramDescription& description, const SkPaint* paint) const override; - void setupProgram(ProgramDescription& description, Program& program) const override; - - void endPrecaching() override; - -private: - ShaderGammaFontRenderer(bool multiGamma); - - FontRenderer* mRenderer; - bool mMultiGamma; - - friend class GammaFontRenderer; -}; - class LookupGammaFontRenderer: public GammaFontRenderer { public: ~LookupGammaFontRenderer() { @@ -132,12 +83,6 @@ public: return mRenderer ? mRenderer->getCacheSize(format) : 0; } - void describe(ProgramDescription& description, const SkPaint* paint) const override { - } - - void setupProgram(ProgramDescription& description, Program& program) const override { - } - void endPrecaching() override; private: @@ -168,12 +113,6 @@ public: return mRenderers[fontRenderer]->getCacheSize(format); } - void describe(ProgramDescription& description, const SkPaint* paint) const override { - } - - void setupProgram(ProgramDescription& description, Program& program) const override { - } - void endPrecaching() override; private: diff --git a/libs/hwui/PathCache.cpp b/libs/hwui/PathCache.cpp index f503e5d6e8ba..4031f2e13f39 100644 --- a/libs/hwui/PathCache.cpp +++ b/libs/hwui/PathCache.cpp @@ -138,10 +138,10 @@ PathCache::PathCache(): mSize(0), mMaxSize(MB(DEFAULT_PATH_CACHE_SIZE)) { char property[PROPERTY_VALUE_MAX]; if (property_get(PROPERTY_PATH_CACHE_SIZE, property, nullptr) > 0) { - INIT_LOGD(" Setting %s cache size to %sMB", name, property); + INIT_LOGD(" Setting path cache size to %sMB", property); mMaxSize = MB(atof(property)); } else { - INIT_LOGD(" Using default %s cache size of %.2fMB", name, DEFAULT_PATH_CACHE_SIZE); + INIT_LOGD(" Using default path cache size of %.2fMB", DEFAULT_PATH_CACHE_SIZE); } mCache.setOnEntryRemovedListener(this); diff --git a/libs/hwui/Program.h b/libs/hwui/Program.h index b09c207f6e45..e5200a516777 100644 --- a/libs/hwui/Program.h +++ b/libs/hwui/Program.h @@ -78,14 +78,12 @@ namespace uirenderer { #define PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT 38 #define PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT 39 -#define PROGRAM_HAS_GAMMA_CORRECTION 40 +#define PROGRAM_IS_SIMPLE_GRADIENT 40 -#define PROGRAM_IS_SIMPLE_GRADIENT 41 +#define PROGRAM_HAS_COLORS 41 -#define PROGRAM_HAS_COLORS 42 - -#define PROGRAM_HAS_DEBUG_HIGHLIGHT 43 -#define PROGRAM_HAS_ROUND_RECT_CLIP 44 +#define PROGRAM_HAS_DEBUG_HIGHLIGHT 42 +#define PROGRAM_HAS_ROUND_RECT_CLIP 43 /////////////////////////////////////////////////////////////////////////////// // Types @@ -157,9 +155,6 @@ struct ProgramDescription { SkXfermode::Mode framebufferMode; bool swapSrcDst; - bool hasGammaCorrection; - float gamma; - bool hasDebugHighlight; bool hasRoundRectClip; @@ -199,9 +194,6 @@ struct ProgramDescription { framebufferMode = SkXfermode::kClear_Mode; swapSrcDst = false; - hasGammaCorrection = false; - gamma = 2.2f; - hasDebugHighlight = false; hasRoundRectClip = false; } @@ -266,7 +258,6 @@ struct ProgramDescription { if (useShadowAlphaInterp) key |= programid(0x1) << PROGRAM_USE_SHADOW_ALPHA_INTERP_SHIFT; if (hasExternalTexture) key |= programid(0x1) << PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT; if (hasTextureTransform) key |= programid(0x1) << PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT; - if (hasGammaCorrection) key |= programid(0x1) << PROGRAM_HAS_GAMMA_CORRECTION; if (isSimpleGradient) key |= programid(0x1) << PROGRAM_IS_SIMPLE_GRADIENT; if (hasColors) key |= programid(0x1) << PROGRAM_HAS_COLORS; if (hasDebugHighlight) key |= programid(0x1) << PROGRAM_HAS_DEBUG_HIGHLIGHT; diff --git a/libs/hwui/ProgramCache.cpp b/libs/hwui/ProgramCache.cpp index b25a4ac9558d..05be48822fb2 100644 --- a/libs/hwui/ProgramCache.cpp +++ b/libs/hwui/ProgramCache.cpp @@ -167,8 +167,6 @@ const char* gFS_Uniforms_ColorOp[3] = { // PorterDuff "uniform vec4 colorBlend;\n" }; -const char* gFS_Uniforms_Gamma = - "uniform float gamma;\n"; const char* gFS_Uniforms_HasRoundRectClip = "uniform vec4 roundRectInnerRectLTRB;\n" @@ -204,18 +202,10 @@ const char* gFS_Fast_SingleA8Texture = "\nvoid main(void) {\n" " gl_FragColor = texture2D(baseSampler, outTexCoords);\n" "}\n\n"; -const char* gFS_Fast_SingleA8Texture_ApplyGamma = - "\nvoid main(void) {\n" - " gl_FragColor = vec4(0.0, 0.0, 0.0, pow(texture2D(baseSampler, outTexCoords).a, gamma));\n" - "}\n\n"; const char* gFS_Fast_SingleModulateA8Texture = "\nvoid main(void) {\n" " gl_FragColor = color * texture2D(baseSampler, outTexCoords).a;\n" "}\n\n"; -const char* gFS_Fast_SingleModulateA8Texture_ApplyGamma = - "\nvoid main(void) {\n" - " gl_FragColor = color * pow(texture2D(baseSampler, outTexCoords).a, gamma);\n" - "}\n\n"; const char* gFS_Fast_SingleGradient[2] = { "\nvoid main(void) {\n" " gl_FragColor = %s + texture2D(gradientSampler, linear);\n" @@ -250,13 +240,11 @@ const char* gFS_Main_FetchTexture[2] = { // Modulate " fragColor = color * texture2D(baseSampler, outTexCoords);\n" }; -const char* gFS_Main_FetchA8Texture[4] = { +const char* gFS_Main_FetchA8Texture[2] = { // Don't modulate " fragColor = texture2D(baseSampler, outTexCoords);\n", - " fragColor = texture2D(baseSampler, outTexCoords);\n", // Modulate " fragColor = color * texture2D(baseSampler, outTexCoords).a;\n", - " fragColor = color * pow(texture2D(baseSampler, outTexCoords).a, gamma);\n" }; const char* gFS_Main_FetchGradient[6] = { // Linear @@ -284,38 +272,29 @@ const char* gFS_Main_BlendShadersBG = " fragColor = blendShaders(gradientColor, bitmapColor)"; const char* gFS_Main_BlendShadersGB = " fragColor = blendShaders(bitmapColor, gradientColor)"; -const char* gFS_Main_BlendShaders_Modulate[6] = { +const char* gFS_Main_BlendShaders_Modulate[3] = { // Don't modulate ";\n", - ";\n", // Modulate " * color.a;\n", - " * color.a;\n", // Modulate with alpha 8 texture " * texture2D(baseSampler, outTexCoords).a;\n", - " * pow(texture2D(baseSampler, outTexCoords).a, gamma);\n" }; -const char* gFS_Main_GradientShader_Modulate[6] = { +const char* gFS_Main_GradientShader_Modulate[3] = { // Don't modulate " fragColor = gradientColor;\n", - " fragColor = gradientColor;\n", // Modulate " fragColor = gradientColor * color.a;\n", - " fragColor = gradientColor * color.a;\n", // Modulate with alpha 8 texture " fragColor = gradientColor * texture2D(baseSampler, outTexCoords).a;\n", - " fragColor = gradientColor * pow(texture2D(baseSampler, outTexCoords).a, gamma);\n" }; -const char* gFS_Main_BitmapShader_Modulate[6] = { +const char* gFS_Main_BitmapShader_Modulate[3] = { // Don't modulate " fragColor = bitmapColor;\n", - " fragColor = bitmapColor;\n", // Modulate " fragColor = bitmapColor * color.a;\n", - " fragColor = bitmapColor * color.a;\n", // Modulate with alpha 8 texture " fragColor = bitmapColor * texture2D(baseSampler, outTexCoords).a;\n", - " fragColor = bitmapColor * pow(texture2D(baseSampler, outTexCoords).a, gamma);\n" }; const char* gFS_Main_FragColor = " gl_FragColor = fragColor;\n"; @@ -540,7 +519,6 @@ String8 ProgramCache::generateVertexShader(const ProgramDescription& description static bool shaderOp(const ProgramDescription& description, String8& shader, const int modulateOp, const char** snippets) { int op = description.hasAlpha8Texture ? MODULATE_OP_MODULATE_A8 : modulateOp; - op = op * 2 + description.hasGammaCorrection; shader.append(snippets[op]); return description.hasAlpha8Texture; } @@ -596,9 +574,6 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti shader.appendFormat(gFS_Uniforms_GradientSampler[description.isSimpleGradient], gFS_Uniforms_Dither); } - if (description.hasGammaCorrection) { - shader.append(gFS_Uniforms_Gamma); - } if (description.hasRoundRectClip) { shader.append(gFS_Uniforms_HasRoundRectClip); } @@ -633,17 +608,9 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti fast = true; } else if (singleA8Texture) { if (!description.modulate) { - if (description.hasGammaCorrection) { - shader.append(gFS_Fast_SingleA8Texture_ApplyGamma); - } else { - shader.append(gFS_Fast_SingleA8Texture); - } + shader.append(gFS_Fast_SingleA8Texture); } else { - if (description.hasGammaCorrection) { - shader.append(gFS_Fast_SingleModulateA8Texture_ApplyGamma); - } else { - shader.append(gFS_Fast_SingleModulateA8Texture); - } + shader.append(gFS_Fast_SingleModulateA8Texture); } fast = true; } else if (singleGradient) { @@ -693,8 +660,7 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti if (description.hasTexture || description.hasExternalTexture) { if (description.hasAlpha8Texture) { if (!description.hasGradient && !description.hasBitmap) { - shader.append(gFS_Main_FetchA8Texture[modulateOp * 2 + - description.hasGammaCorrection]); + shader.append(gFS_Main_FetchA8Texture[modulateOp]); } } else { shader.append(gFS_Main_FetchTexture[modulateOp]); diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h index 76028482ba86..98834b8f561d 100644 --- a/libs/hwui/Properties.h +++ b/libs/hwui/Properties.h @@ -242,7 +242,7 @@ enum DebugLevel { #define DEFAULT_RENDER_BUFFER_CACHE_SIZE 2.0f #define DEFAULT_PATH_CACHE_SIZE 4.0f #define DEFAULT_VERTEX_CACHE_SIZE 1.0f -#define DEFAULT_PATCH_CACHE_SIZE 128 // in kB +#define DEFAULT_PATCH_CACHE_SIZE 128.0f // in kB #define DEFAULT_GRADIENT_CACHE_SIZE 0.5f #define DEFAULT_DROP_SHADOW_CACHE_SIZE 2.0f #define DEFAULT_FBO_CACHE_SIZE 0 diff --git a/libs/hwui/TessellationCache.cpp b/libs/hwui/TessellationCache.cpp index 01f5e2dba214..12a3e76c9387 100644 --- a/libs/hwui/TessellationCache.cpp +++ b/libs/hwui/TessellationCache.cpp @@ -312,10 +312,10 @@ TessellationCache::TessellationCache() , mShadowCache(LruCache*>::kUnlimitedCapacity) { char property[PROPERTY_VALUE_MAX]; if (property_get(PROPERTY_VERTEX_CACHE_SIZE, property, nullptr) > 0) { - INIT_LOGD(" Setting %s cache size to %sMB", name, property); + INIT_LOGD(" Setting tessellation cache size to %sMB", property); setMaxSize(MB(atof(property))); } else { - INIT_LOGD(" Using default %s cache size of %.2fMB", name, DEFAULT_VERTEX_CACHE_SIZE); + INIT_LOGD(" Using default tessellation cache size of %.2fMB", DEFAULT_VERTEX_CACHE_SIZE); } mCache.setOnEntryRemovedListener(&mBufferRemovedListener); -- cgit v1.2.3-59-g8ed1b From 138c21fbec12bead3c7ca1f181c3fd35542ccb00 Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Thu, 28 Apr 2016 16:59:42 -0700 Subject: Use LUT for computing final shadow alpha bug:27415250 Significantly reduces shadow fragment shader computation. Change-Id: Ie9b3c712700754b3734d0ae9cda8751c298fc59e --- libs/hwui/AmbientShadow.cpp | 29 +++++++------------------- libs/hwui/BakedOpDispatcher.cpp | 5 +++-- libs/hwui/Caches.cpp | 1 + libs/hwui/Glop.h | 5 +++++ libs/hwui/GlopBuilder.cpp | 23 +++++++++++++------- libs/hwui/GlopBuilder.h | 4 ++-- libs/hwui/OpenGLRenderer.cpp | 4 ++-- libs/hwui/ProgramCache.cpp | 7 +++---- libs/hwui/SpotShadow.cpp | 13 ++++++------ libs/hwui/renderstate/RenderState.cpp | 12 +++++++---- libs/hwui/renderstate/TextureState.cpp | 38 ++++++++++++++++++++++++++++++++++ libs/hwui/renderstate/TextureState.h | 12 ++++++++--- 12 files changed, 101 insertions(+), 52 deletions(-) (limited to 'libs/hwui/ProgramCache.cpp') diff --git a/libs/hwui/AmbientShadow.cpp b/libs/hwui/AmbientShadow.cpp index 20ecda28b22a..3982fa0938bf 100644 --- a/libs/hwui/AmbientShadow.cpp +++ b/libs/hwui/AmbientShadow.cpp @@ -43,9 +43,7 @@ /** * Other constants: */ -// For the edge of the penumbra, the opacity is 0. After transform (1 - alpha), -// it is 1. -#define TRANSFORMED_OUTER_OPACITY (1.0f) +#define OUTER_ALPHA (0.0f) // Once the alpha difference is greater than this threshold, we will allocate extra // edge vertices. @@ -81,17 +79,6 @@ inline float getAlphaFromFactoredZ(float factoredZ) { return 1.0 / (1 + std::max(factoredZ, 0.0f)); } -// The shader is using gaussian function e^-(1-x)*(1-x)*4, therefore, we transform -// the alpha value to (1 - alpha) -inline float getTransformedAlphaFromAlpha(float alpha) { - return 1.0f - alpha; -} - -// The output is ranged from 0 to 1. -inline float getTransformedAlphaFromFactoredZ(float factoredZ) { - return getTransformedAlphaFromAlpha(getAlphaFromFactoredZ(factoredZ)); -} - inline int getEdgeExtraAndUpdateSpike(Vector2* currentSpike, const Vector3& secondVertex, const Vector3& centroid) { Vector2 secondSpike = {secondVertex.x - centroid.x, secondVertex.y - centroid.y}; @@ -225,9 +212,9 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, if (!isCasterOpaque) { umbraVertices[umbraIndex++] = vertexBufferIndex; } - AlphaVertex::set(&shadowVertices[vertexBufferIndex++], casterVertices[i].x, - casterVertices[i].y, - getTransformedAlphaFromAlpha(currentAlpha)); + AlphaVertex::set(&shadowVertices[vertexBufferIndex++], + casterVertices[i].x, casterVertices[i].y, + currentAlpha); const Vector3& innerStart = casterVertices[i]; @@ -249,7 +236,7 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, indexBuffer[indexBufferIndex++] = vertexBufferIndex; indexBuffer[indexBufferIndex++] = currentInnerVertexIndex; AlphaVertex::set(&shadowVertices[vertexBufferIndex++], outerVertex.x, - outerVertex.y, TRANSFORMED_OUTER_OPACITY); + outerVertex.y, OUTER_ALPHA); if (j == 0) { outerStart = outerVertex; @@ -285,7 +272,7 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, (outerLast * startWeight + outerNext * k) / extraVerticesNumber; indexBuffer[indexBufferIndex++] = vertexBufferIndex; AlphaVertex::set(&shadowVertices[vertexBufferIndex++], currentOuter.x, - currentOuter.y, TRANSFORMED_OUTER_OPACITY); + currentOuter.y, OUTER_ALPHA); if (!isCasterOpaque) { umbraVertices[umbraIndex++] = vertexBufferIndex; @@ -295,7 +282,7 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, indexBuffer[indexBufferIndex++] = vertexBufferIndex; AlphaVertex::set(&shadowVertices[vertexBufferIndex++], currentInner.x, currentInner.y, - getTransformedAlphaFromFactoredZ(currentInner.z * heightFactor)); + getAlphaFromFactoredZ(currentInner.z * heightFactor)); } } currentAlpha = nextAlpha; @@ -307,7 +294,7 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, if (!isCasterOpaque) { // Add the centroid as the last one in the vertex buffer. float centroidOpacity = - getTransformedAlphaFromFactoredZ(centroid3d.z * heightFactor); + getAlphaFromFactoredZ(centroid3d.z * heightFactor); int centroidIndex = vertexBufferIndex; AlphaVertex::set(&shadowVertices[vertexBufferIndex++], centroid3d.x, centroid3d.y, centroidOpacity); diff --git a/libs/hwui/BakedOpDispatcher.cpp b/libs/hwui/BakedOpDispatcher.cpp index 8251ee6698c1..19df68ec98e6 100644 --- a/libs/hwui/BakedOpDispatcher.cpp +++ b/libs/hwui/BakedOpDispatcher.cpp @@ -346,11 +346,12 @@ static void renderVertexBuffer(BakedOpRenderer& renderer, const BakedOpState& st bool shadowInterp = vertexBufferRenderFlags & VertexBufferRenderFlags::ShadowInterp; const int transformFlags = vertexBufferRenderFlags & VertexBufferRenderFlags::Offset ? TransformFlags::OffsetByFudgeFactor : 0; + Glop glop; GlopBuilder(renderer.renderState(), renderer.caches(), &glop) .setRoundRectClipState(state.roundRectClipState) - .setMeshVertexBuffer(vertexBuffer, shadowInterp) - .setFillPaint(paint, state.alpha) + .setMeshVertexBuffer(vertexBuffer) + .setFillPaint(paint, state.alpha, shadowInterp) .setTransform(state.computedState.transform, transformFlags) .setModelViewOffsetRect(translateX, translateY, vertexBuffer.getBounds()) .build(); diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp index eaa1c330d5dd..949ad450d5f7 100644 --- a/libs/hwui/Caches.cpp +++ b/libs/hwui/Caches.cpp @@ -74,6 +74,7 @@ bool Caches::init() { mPixelBufferState = new PixelBufferState(); mTextureState = new TextureState(); + mTextureState->constructTexture(*this); return true; } diff --git a/libs/hwui/Glop.h b/libs/hwui/Glop.h index 6a9663412a00..6433c86908e7 100644 --- a/libs/hwui/Glop.h +++ b/libs/hwui/Glop.h @@ -44,9 +44,14 @@ class Texture; namespace VertexAttribFlags { enum { + // Mesh is pure x,y vertex pairs None = 0, + // Mesh has texture coordinates embedded. Note that texture can exist without this flag + // being set, if coordinates passed to sampler are determined another way. TextureCoord = 1 << 0, + // Mesh has color embedded (to export to varying) Color = 1 << 1, + // Mesh has alpha embedded (to export to varying) Alpha = 1 << 2, }; }; diff --git a/libs/hwui/GlopBuilder.cpp b/libs/hwui/GlopBuilder.cpp index fdbe76a5e459..910300d3f4f6 100644 --- a/libs/hwui/GlopBuilder.cpp +++ b/libs/hwui/GlopBuilder.cpp @@ -193,7 +193,7 @@ GlopBuilder& GlopBuilder::setMeshColoredTexturedMesh(ColorTextureVertex* vertexD return *this; } -GlopBuilder& GlopBuilder::setMeshVertexBuffer(const VertexBuffer& vertexBuffer, bool shadowInterp) { +GlopBuilder& GlopBuilder::setMeshVertexBuffer(const VertexBuffer& vertexBuffer) { TRIGGER_STAGE(kMeshStage); const VertexBuffer::MeshFeatureFlags flags = vertexBuffer.getMeshFeatureFlags(); @@ -210,8 +210,6 @@ GlopBuilder& GlopBuilder::setMeshVertexBuffer(const VertexBuffer& vertexBuffer, alphaVertex ? kAlphaVertexStride : kVertexStride }; mOutGlop->mesh.elementCount = indices ? vertexBuffer.getIndexCount() : vertexBuffer.getVertexCount(); - - mDescription.useShadowAlphaInterp = shadowInterp; return *this; } @@ -368,15 +366,23 @@ GlopBuilder& GlopBuilder::setFillTexturePaint(Texture& texture, return *this; } -GlopBuilder& GlopBuilder::setFillPaint(const SkPaint& paint, float alphaScale) { +GlopBuilder& GlopBuilder::setFillPaint(const SkPaint& paint, float alphaScale, bool shadowInterp) { TRIGGER_STAGE(kFillStage); REQUIRE_STAGES(kMeshStage | kRoundRectClipStage); - mOutGlop->fill.texture = { nullptr, GL_INVALID_ENUM, GL_INVALID_ENUM, GL_INVALID_ENUM, nullptr }; + if (CC_LIKELY(!shadowInterp)) { + mOutGlop->fill.texture = { + nullptr, GL_INVALID_ENUM, GL_INVALID_ENUM, GL_INVALID_ENUM, nullptr }; + } else { + mOutGlop->fill.texture = { + mCaches.textureState().getShadowLutTexture(), GL_TEXTURE_2D, + GL_INVALID_ENUM, GL_INVALID_ENUM, nullptr }; + } setFill(paint.getColor(), alphaScale, PaintUtils::getXfermode(paint.getXfermode()), Blend::ModeOrderSwap::NoSwap, paint.getShader(), paint.getColorFilter()); + mDescription.useShadowAlphaInterp = shadowInterp; mDescription.modulate = mOutGlop->fill.color.a < 1.0f; return *this; } @@ -592,8 +598,11 @@ GlopBuilder& GlopBuilder::setRoundRectClipState(const RoundRectClipState* roundR void verify(const ProgramDescription& description, const Glop& glop) { if (glop.fill.texture.texture != nullptr) { LOG_ALWAYS_FATAL_IF(((description.hasTexture && description.hasExternalTexture) - || (!description.hasTexture && !description.hasExternalTexture) - || ((glop.mesh.vertices.attribFlags & VertexAttribFlags::TextureCoord) == 0)), + || (!description.hasTexture + && !description.hasExternalTexture + && !description.useShadowAlphaInterp) + || ((glop.mesh.vertices.attribFlags & VertexAttribFlags::TextureCoord) == 0 + && !description.useShadowAlphaInterp)), "Texture %p, hT%d, hET %d, attribFlags %x", glop.fill.texture.texture, description.hasTexture, description.hasExternalTexture, diff --git a/libs/hwui/GlopBuilder.h b/libs/hwui/GlopBuilder.h index b6c186d85e76..4f5f0d83becb 100644 --- a/libs/hwui/GlopBuilder.h +++ b/libs/hwui/GlopBuilder.h @@ -51,14 +51,14 @@ public: GlopBuilder& setMeshUnitQuad(); GlopBuilder& setMeshTexturedUnitQuad(const UvMapper* uvMapper); GlopBuilder& setMeshTexturedUvQuad(const UvMapper* uvMapper, const Rect uvs); - GlopBuilder& setMeshVertexBuffer(const VertexBuffer& vertexBuffer, bool shadowInterp); + GlopBuilder& setMeshVertexBuffer(const VertexBuffer& vertexBuffer); GlopBuilder& setMeshIndexedQuads(Vertex* vertexData, int quadCount); GlopBuilder& setMeshTexturedMesh(TextureVertex* vertexData, int elementCount); // TODO: delete GlopBuilder& setMeshColoredTexturedMesh(ColorTextureVertex* vertexData, int elementCount); // TODO: use indexed quads GlopBuilder& setMeshTexturedIndexedQuads(TextureVertex* vertexData, int elementCount); // TODO: take quadCount GlopBuilder& setMeshPatchQuads(const Patch& patch); - GlopBuilder& setFillPaint(const SkPaint& paint, float alphaScale); + GlopBuilder& setFillPaint(const SkPaint& paint, float alphaScale, bool shadowInterp = false); // TODO: avoid boolean with default GlopBuilder& setFillTexturePaint(Texture& texture, const int textureFillFlags, const SkPaint* paint, float alphaScale); GlopBuilder& setFillPathTexturePaint(PathTexture& texture, diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 53ea7fa6f77d..b68240ac7519 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -1697,8 +1697,8 @@ void OpenGLRenderer::drawVertexBuffer(float translateX, float translateY, Glop glop; GlopBuilder(mRenderState, mCaches, &glop) .setRoundRectClipState(currentSnapshot()->roundRectClipState) - .setMeshVertexBuffer(vertexBuffer, shadowInterp) - .setFillPaint(*paint, currentSnapshot()->alpha) + .setMeshVertexBuffer(vertexBuffer) + .setFillPaint(*paint, currentSnapshot()->alpha, shadowInterp) .setTransform(*currentSnapshot(), transformFlags) .setModelViewOffsetRect(translateX, translateY, vertexBuffer.getBounds()) .build(); diff --git a/libs/hwui/ProgramCache.cpp b/libs/hwui/ProgramCache.cpp index 05be48822fb2..59225e108ac7 100644 --- a/libs/hwui/ProgramCache.cpp +++ b/libs/hwui/ProgramCache.cpp @@ -231,9 +231,8 @@ const char* gFS_Main_ModulateColor = const char* gFS_Main_ApplyVertexAlphaLinearInterp = " fragColor *= alpha;\n"; const char* gFS_Main_ApplyVertexAlphaShadowInterp = - // Use a gaussian function for the shadow fall off. Note that alpha here - // is actually (1.0 - alpha) for saving computation. - " fragColor *= exp(- alpha * alpha * 4.0) - 0.018;\n"; + // map alpha through shadow alpha sampler + " fragColor *= texture2D(baseSampler, vec2(alpha, 0.5)).a;\n"; const char* gFS_Main_FetchTexture[2] = { // Don't modulate " fragColor = texture2D(baseSampler, outTexCoords);\n", @@ -565,7 +564,7 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti shader.append(gFS_Uniforms_Color); if (!singleColor) modulateOp = MODULATE_OP_MODULATE; } - if (description.hasTexture) { + if (description.hasTexture || description.useShadowAlphaInterp) { shader.append(gFS_Uniforms_TextureSampler); } else if (description.hasExternalTexture) { shader.append(gFS_Uniforms_ExternalTextureSampler); diff --git a/libs/hwui/SpotShadow.cpp b/libs/hwui/SpotShadow.cpp index 759e39b2e4e2..760d814f27a8 100644 --- a/libs/hwui/SpotShadow.cpp +++ b/libs/hwui/SpotShadow.cpp @@ -42,9 +42,8 @@ // For each RADIANS_DIVISOR, we would allocate one more vertex b/t the normals. #define SPOT_CORNER_RADIANS_DIVISOR (M_PI / SPOT_EXTRA_CORNER_VERTEX_PER_PI) -// For performance, we use (1 - alpha) value for the shader input. -#define TRANSFORMED_PENUMBRA_ALPHA 1.0f -#define TRANSFORMED_UMBRA_ALPHA 0.0f +#define PENUMBRA_ALPHA 0.0f +#define UMBRA_ALPHA 1.0f #include "SpotShadow.h" @@ -941,11 +940,11 @@ void SpotShadow::generateTriangleStrip(bool isCasterOpaque, float shadowStrength // Fill the IB and VB for the penumbra area. for (int i = 0; i < newPenumbraLength; i++) { AlphaVertex::set(&shadowVertices[vertexBufferIndex++], newPenumbra[i].x, - newPenumbra[i].y, TRANSFORMED_PENUMBRA_ALPHA); + newPenumbra[i].y, PENUMBRA_ALPHA); } for (int i = 0; i < umbraLength; i++) { AlphaVertex::set(&shadowVertices[vertexBufferIndex++], umbra[i].x, umbra[i].y, - TRANSFORMED_UMBRA_ALPHA); + UMBRA_ALPHA); } for (int i = 0; i < verticesPairIndex; i++) { @@ -985,14 +984,14 @@ void SpotShadow::generateTriangleStrip(bool isCasterOpaque, float shadowStrength indexBuffer[indexBufferIndex++] = newPenumbraLength + i; indexBuffer[indexBufferIndex++] = vertexBufferIndex; AlphaVertex::set(&shadowVertices[vertexBufferIndex++], - closerVertex.x, closerVertex.y, TRANSFORMED_UMBRA_ALPHA); + closerVertex.x, closerVertex.y, UMBRA_ALPHA); } } else { // If there is no occluded umbra at all, then draw the triangle fan // starting from the centroid to all umbra vertices. int lastCentroidIndex = vertexBufferIndex; AlphaVertex::set(&shadowVertices[vertexBufferIndex++], centroid.x, - centroid.y, TRANSFORMED_UMBRA_ALPHA); + centroid.y, UMBRA_ALPHA); for (int i = 0; i < umbraLength; i++) { indexBuffer[indexBufferIndex++] = newPenumbraLength + i; indexBuffer[indexBufferIndex++] = lastCentroidIndex; diff --git a/libs/hwui/renderstate/RenderState.cpp b/libs/hwui/renderstate/RenderState.cpp index ea4391b87006..e78cd7296f42 100644 --- a/libs/hwui/renderstate/RenderState.cpp +++ b/libs/hwui/renderstate/RenderState.cpp @@ -298,7 +298,8 @@ void RenderState::render(const Glop& glop, const Matrix4& orthoMatrix) { // indices meshState().bindIndicesBuffer(indices.bufferObject); - if (vertices.attribFlags & VertexAttribFlags::TextureCoord) { + // texture + if (fill.texture.texture != nullptr) { const Glop::Fill::TextureData& texture = fill.texture; // texture always takes slot 0, shader samplers increment from there mCaches->textureState().activateTexture(0); @@ -311,13 +312,16 @@ void RenderState::render(const Glop& glop, const Matrix4& orthoMatrix) { texture.texture->setFilter(texture.filter, false, false, texture.target); } - meshState().enableTexCoordsVertexArray(); - meshState().bindTexCoordsVertexPointer(vertices.texCoord, vertices.stride); - if (texture.textureTransform) { glUniformMatrix4fv(fill.program->getUniform("mainTextureTransform"), 1, GL_FALSE, &texture.textureTransform->data[0]); } + } + + // vertex attributes (tex coord, color, alpha) + if (vertices.attribFlags & VertexAttribFlags::TextureCoord) { + meshState().enableTexCoordsVertexArray(); + meshState().bindTexCoordsVertexPointer(vertices.texCoord, vertices.stride); } else { meshState().disableTexCoordsVertexArray(); } diff --git a/libs/hwui/renderstate/TextureState.cpp b/libs/hwui/renderstate/TextureState.cpp index 78b8edae2eed..f9a1f8c38895 100644 --- a/libs/hwui/renderstate/TextureState.cpp +++ b/libs/hwui/renderstate/TextureState.cpp @@ -26,6 +26,9 @@ namespace android { namespace uirenderer { +// Width of mShadowLutTexture, defines how accurate the shadow alpha lookup table is +static const int SHADOW_LUT_SIZE = 128; + // Must define as many texture units as specified by kTextureUnitsCount const GLenum kTextureUnits[] = { GL_TEXTURE0, @@ -46,6 +49,41 @@ TextureState::TextureState() glPixelStorei(GL_UNPACK_ALIGNMENT, 1); } +TextureState::~TextureState() { + if (mShadowLutTexture != nullptr) { + mShadowLutTexture->deleteTexture(); + } +} + +/** + * Maps shadow geometry 'alpha' varying (1 for darkest, 0 for transparent) to + * darkness at that spot. Input values of 0->1 should be mapped within the same + * range, but can affect the curve for a different visual falloff. + * + * This is used to populate the shadow LUT texture for quick lookup in the + * shadow shader. + */ +static float computeShadowOpacity(float ratio) { + // exponential falloff function provided by UX + float val = 1 - ratio; + return exp(-val * val * 4.0) - 0.018; +} + +void TextureState::constructTexture(Caches& caches) { + if (mShadowLutTexture == nullptr) { + mShadowLutTexture.reset(new Texture(caches)); + + unsigned char bytes[SHADOW_LUT_SIZE]; + for (int i = 0; i < SHADOW_LUT_SIZE; i++) { + float inputRatio = i / (SHADOW_LUT_SIZE - 1.0f); + bytes[i] = computeShadowOpacity(inputRatio) * 255; + } + mShadowLutTexture->upload(GL_ALPHA, SHADOW_LUT_SIZE, 1, GL_ALPHA, GL_UNSIGNED_BYTE, &bytes); + mShadowLutTexture->setFilter(GL_LINEAR); + mShadowLutTexture->setWrap(GL_CLAMP_TO_EDGE); + } +} + void TextureState::activateTexture(GLuint textureUnit) { LOG_ALWAYS_FATAL_IF(textureUnit >= kTextureUnitsCount, "Tried to use texture unit index %d, only %d exist", diff --git a/libs/hwui/renderstate/TextureState.h b/libs/hwui/renderstate/TextureState.h index ec94d7e9e267..7296fd39a705 100644 --- a/libs/hwui/renderstate/TextureState.h +++ b/libs/hwui/renderstate/TextureState.h @@ -17,14 +17,12 @@ #define RENDERSTATE_TEXTURESTATE_H #include "Vertex.h" +#include "Texture.h" #include #include -#include #include -class SkBitmap; - namespace android { namespace uirenderer { @@ -33,6 +31,9 @@ class Texture; class TextureState { friend class Caches; // TODO: move to RenderState public: + + void constructTexture(Caches& caches); + /** * Activate the specified texture unit. The texture unit must * be specified using an integer number (0 for GL_TEXTURE0 etc.) @@ -76,15 +77,20 @@ public: */ void unbindTexture(GLuint texture); + Texture* getShadowLutTexture() { return mShadowLutTexture.get(); } + private: // total number of texture units available for use static const int kTextureUnitsCount = 4; TextureState(); + ~TextureState(); GLuint mTextureUnit; // Caches texture bindings for the GL_TEXTURE_2D target GLuint mBoundTextures[kTextureUnitsCount]; + + std::unique_ptr mShadowLutTexture; }; } /* namespace uirenderer */ -- cgit v1.2.3-59-g8ed1b