Loading libs/hwui/AmbientShadow.cpp +47 −52 Original line number Original line Diff line number Diff line Loading @@ -56,8 +56,8 @@ #include "Vertex.h" #include "Vertex.h" #include "VertexBuffer.h" #include "VertexBuffer.h" #include <algorithm> #include <utils/Log.h> #include <utils/Log.h> #include <algorithm> namespace android { namespace android { namespace uirenderer { namespace uirenderer { Loading @@ -79,8 +79,8 @@ inline float getAlphaFromFactoredZ(float factoredZ) { return 1.0 / (1 + std::max(factoredZ, 0.0f)); return 1.0 / (1 + std::max(factoredZ, 0.0f)); } } inline int getEdgeExtraAndUpdateSpike(Vector2* currentSpike, inline int getEdgeExtraAndUpdateSpike(Vector2* currentSpike, const Vector3& secondVertex, const Vector3& secondVertex, const Vector3& centroid) { const Vector3& centroid) { Vector2 secondSpike = {secondVertex.x - centroid.x, secondVertex.y - centroid.y}; Vector2 secondSpike = {secondVertex.x - centroid.x, secondVertex.y - centroid.y}; secondSpike.normalize(); secondSpike.normalize(); Loading @@ -92,11 +92,11 @@ inline int getEdgeExtraAndUpdateSpike(Vector2* currentSpike, // Given the caster's vertex count, compute all the buffers size depending on // Given the caster's vertex count, compute all the buffers size depending on // whether or not the caster is opaque. // whether or not the caster is opaque. inline void computeBufferSize(int* totalVertexCount, int* totalIndexCount, inline void computeBufferSize(int* totalVertexCount, int* totalIndexCount, int* totalUmbraCount, int* totalUmbraCount, int casterVertexCount, bool isCasterOpaque) { int casterVertexCount, bool isCasterOpaque) { // Compute the size of the vertex buffer. // Compute the size of the vertex buffer. int outerVertexCount = casterVertexCount * 2 + MAX_EXTRA_CORNER_VERTEX_NUMBER + int outerVertexCount = MAX_EXTRA_EDGE_VERTEX_NUMBER; casterVertexCount * 2 + MAX_EXTRA_CORNER_VERTEX_NUMBER + MAX_EXTRA_EDGE_VERTEX_NUMBER; int innerVertexCount = casterVertexCount + MAX_EXTRA_EDGE_VERTEX_NUMBER; int innerVertexCount = casterVertexCount + MAX_EXTRA_EDGE_VERTEX_NUMBER; *totalVertexCount = outerVertexCount + innerVertexCount; *totalVertexCount = outerVertexCount + innerVertexCount; Loading Loading @@ -163,27 +163,25 @@ inline bool needsExtraForEdge(float firstAlpha, float secondAlpha) { * | | * | | * (V3)-----------------------------------(V2) * (V3)-----------------------------------(V2) */ */ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, void AmbientShadow::createAmbientShadow(bool isCasterOpaque, const Vector3* casterVertices, const Vector3* casterVertices, int casterVertexCount, const Vector3& centroid3d, int casterVertexCount, const Vector3& centroid3d, float heightFactor, float geomFactor, VertexBuffer& shadowVertexBuffer) { float heightFactor, float geomFactor, VertexBuffer& shadowVertexBuffer) { shadowVertexBuffer.setMeshFeatureFlags(VertexBuffer::kAlpha | VertexBuffer::kIndices); shadowVertexBuffer.setMeshFeatureFlags(VertexBuffer::kAlpha | VertexBuffer::kIndices); // In order to computer the outer vertices in one loop, we need pre-compute // In order to computer the outer vertices in one loop, we need pre-compute // the normal by the vertex (n - 1) to vertex 0, and the spike and alpha value // the normal by the vertex (n - 1) to vertex 0, and the spike and alpha value // for vertex 0. // for vertex 0. Vector2 previousNormal = getNormalFromVertices(casterVertices, Vector2 previousNormal = getNormalFromVertices(casterVertices, casterVertexCount - 1, 0); casterVertexCount - 1 , 0); Vector2 currentSpike = {casterVertices[0].x - centroid3d.x, casterVertices[0].y - centroid3d.y}; Vector2 currentSpike = {casterVertices[0].x - centroid3d.x, casterVertices[0].y - centroid3d.y}; currentSpike.normalize(); currentSpike.normalize(); float currentAlpha = getAlphaFromFactoredZ(casterVertices[0].z * heightFactor); float currentAlpha = getAlphaFromFactoredZ(casterVertices[0].z * heightFactor); // Preparing all the output data. // Preparing all the output data. int totalVertexCount, totalIndexCount, totalUmbraCount; int totalVertexCount, totalIndexCount, totalUmbraCount; computeBufferSize(&totalVertexCount, &totalIndexCount, &totalUmbraCount, computeBufferSize(&totalVertexCount, &totalIndexCount, &totalUmbraCount, casterVertexCount, casterVertexCount, isCasterOpaque); isCasterOpaque); AlphaVertex* shadowVertices = AlphaVertex* shadowVertices = shadowVertexBuffer.alloc<AlphaVertex>(totalVertexCount); shadowVertexBuffer.alloc<AlphaVertex>(totalVertexCount); int vertexBufferIndex = 0; int vertexBufferIndex = 0; uint16_t* indexBuffer = shadowVertexBuffer.allocIndices<uint16_t>(totalIndexCount); uint16_t* indexBuffer = shadowVertexBuffer.allocIndices<uint16_t>(totalIndexCount); int indexBufferIndex = 0; int indexBufferIndex = 0; Loading @@ -193,11 +191,11 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, for (int i = 0; i < casterVertexCount; i++) { for (int i = 0; i < casterVertexCount; i++) { // Corner: first figure out the extra vertices we need for the corner. // Corner: first figure out the extra vertices we need for the corner. const Vector3& innerVertex = casterVertices[i]; const Vector3& innerVertex = casterVertices[i]; Vector2 currentNormal = getNormalFromVertices(casterVertices, i, Vector2 currentNormal = (i + 1) % casterVertexCount); getNormalFromVertices(casterVertices, i, (i + 1) % casterVertexCount); int extraVerticesNumber = ShadowTessellator::getExtraVertexNumber(currentNormal, int extraVerticesNumber = ShadowTessellator::getExtraVertexNumber( previousNormal, CORNER_RADIANS_DIVISOR); currentNormal, previousNormal, CORNER_RADIANS_DIVISOR); float expansionDist = innerVertex.z * heightFactor * geomFactor; float expansionDist = innerVertex.z * heightFactor * geomFactor; const int cornerSlicesNumber = extraVerticesNumber + 1; // Minimal as 1. const int cornerSlicesNumber = extraVerticesNumber + 1; // Minimal as 1. Loading @@ -212,9 +210,8 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, if (!isCasterOpaque) { if (!isCasterOpaque) { umbraVertices[umbraIndex++] = vertexBufferIndex; umbraVertices[umbraIndex++] = vertexBufferIndex; } } AlphaVertex::set(&shadowVertices[vertexBufferIndex++], AlphaVertex::set(&shadowVertices[vertexBufferIndex++], casterVertices[i].x, casterVertices[i].x, casterVertices[i].y, casterVertices[i].y, currentAlpha); currentAlpha); const Vector3& innerStart = casterVertices[i]; const Vector3& innerStart = casterVertices[i]; Loading @@ -225,8 +222,7 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, // This will create vertices from [0, cornerSlicesNumber] inclusively, // This will create vertices from [0, cornerSlicesNumber] inclusively, // which means minimally 2 vertices even without the extra ones. // which means minimally 2 vertices even without the extra ones. for (int j = 0; j <= cornerSlicesNumber; j++) { for (int j = 0; j <= cornerSlicesNumber; j++) { Vector2 averageNormal = Vector2 averageNormal = previousNormal * (cornerSlicesNumber - j) + currentNormal * j; previousNormal * (cornerSlicesNumber - j) + currentNormal * j; averageNormal /= cornerSlicesNumber; averageNormal /= cornerSlicesNumber; averageNormal.normalize(); averageNormal.normalize(); Vector2 outerVertex; Vector2 outerVertex; Loading @@ -235,8 +231,8 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, indexBuffer[indexBufferIndex++] = vertexBufferIndex; indexBuffer[indexBufferIndex++] = vertexBufferIndex; indexBuffer[indexBufferIndex++] = currentInnerVertexIndex; indexBuffer[indexBufferIndex++] = currentInnerVertexIndex; AlphaVertex::set(&shadowVertices[vertexBufferIndex++], outerVertex.x, AlphaVertex::set(&shadowVertices[vertexBufferIndex++], outerVertex.x, outerVertex.y, outerVertex.y, OUTER_ALPHA); OUTER_ALPHA); if (j == 0) { if (j == 0) { outerStart = outerVertex; outerStart = outerVertex; Loading @@ -257,8 +253,8 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, outerNext.y = innerNext.y + currentNormal.y * expansionDist; outerNext.y = innerNext.y + currentNormal.y * expansionDist; // Compute the angle and see how many extra points we need. // Compute the angle and see how many extra points we need. int extraVerticesNumber = getEdgeExtraAndUpdateSpike(¤tSpike, int extraVerticesNumber = innerNext, centroid3d); getEdgeExtraAndUpdateSpike(¤tSpike, innerNext, centroid3d); #if DEBUG_SHADOW #if DEBUG_SHADOW ALOGD("extraVerticesNumber %d for edge %d", extraVerticesNumber, i); ALOGD("extraVerticesNumber %d for edge %d", extraVerticesNumber, i); #endif #endif Loading Loading @@ -293,11 +289,10 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, if (!isCasterOpaque) { if (!isCasterOpaque) { // Add the centroid as the last one in the vertex buffer. // Add the centroid as the last one in the vertex buffer. float centroidOpacity = float centroidOpacity = getAlphaFromFactoredZ(centroid3d.z * heightFactor); getAlphaFromFactoredZ(centroid3d.z * heightFactor); int centroidIndex = vertexBufferIndex; int centroidIndex = vertexBufferIndex; AlphaVertex::set(&shadowVertices[vertexBufferIndex++], centroid3d.x, AlphaVertex::set(&shadowVertices[vertexBufferIndex++], centroid3d.x, centroid3d.y, centroid3d.y, centroidOpacity); centroidOpacity); for (int i = 0; i < umbraIndex; i++) { for (int i = 0; i < umbraIndex; i++) { // Note that umbraVertices[0] is always 0. // Note that umbraVertices[0] is always 0. Loading libs/hwui/AmbientShadow.h +7 −7 Original line number Original line Diff line number Diff line Loading @@ -31,9 +31,9 @@ class VertexBuffer; */ */ class AmbientShadow { class AmbientShadow { public: public: static void createAmbientShadow(bool isCasterOpaque, const Vector3* poly, static void createAmbientShadow(bool isCasterOpaque, const Vector3* poly, int polyLength, int polyLength, const Vector3& centroid3d, float heightFactor, const Vector3& centroid3d, float heightFactor, float geomFactor, float geomFactor, VertexBuffer& shadowVertexBuffer); VertexBuffer& shadowVertexBuffer); }; // AmbientShadow }; // AmbientShadow }; // namespace uirenderer }; // namespace uirenderer Loading libs/hwui/AnimationContext.cpp +9 −14 Original line number Original line Diff line number Diff line Loading @@ -26,11 +26,9 @@ AnimationContext::AnimationContext(renderthread::TimeLord& clock) : mClock(clock) : mClock(clock) , mCurrentFrameAnimations(*this) , mCurrentFrameAnimations(*this) , mNextFrameAnimations(*this) , mNextFrameAnimations(*this) , mFrameTimeMs(0) { , mFrameTimeMs(0) {} } AnimationContext::~AnimationContext() { AnimationContext::~AnimationContext() {} } void AnimationContext::destroy() { void AnimationContext::destroy() { startFrame(TreeInfo::MODE_RT_ONLY); startFrame(TreeInfo::MODE_RT_ONLY); Loading Loading @@ -83,10 +81,7 @@ void AnimationContext::callOnFinished(BaseRenderNodeAnimator* animator, } } AnimationHandle::AnimationHandle(AnimationContext& context) AnimationHandle::AnimationHandle(AnimationContext& context) : mContext(context) : mContext(context), mPreviousHandle(nullptr), mNextHandle(nullptr) {} , mPreviousHandle(nullptr) , mNextHandle(nullptr) { } AnimationHandle::AnimationHandle(RenderNode& animatingNode, AnimationContext& context) AnimationHandle::AnimationHandle(RenderNode& animatingNode, AnimationContext& context) : mRenderNode(&animatingNode) : mRenderNode(&animatingNode) Loading libs/hwui/AnimationContext.h +5 −3 Original line number Original line Diff line number Diff line Loading @@ -43,6 +43,7 @@ class RenderNode; */ */ class AnimationHandle { class AnimationHandle { PREVENT_COPY_AND_ASSIGN(AnimationHandle); PREVENT_COPY_AND_ASSIGN(AnimationHandle); public: public: AnimationContext& context() { return mContext; } AnimationContext& context() { return mContext; } Loading Loading @@ -74,14 +75,14 @@ private: class AnimationContext { class AnimationContext { PREVENT_COPY_AND_ASSIGN(AnimationContext); PREVENT_COPY_AND_ASSIGN(AnimationContext); public: public: ANDROID_API explicit AnimationContext(renderthread::TimeLord& clock); ANDROID_API explicit AnimationContext(renderthread::TimeLord& clock); ANDROID_API virtual ~AnimationContext(); ANDROID_API virtual ~AnimationContext(); nsecs_t frameTimeMs() { return mFrameTimeMs; } nsecs_t frameTimeMs() { return mFrameTimeMs; } bool hasAnimations() { bool hasAnimations() { return mCurrentFrameAnimations.mNextHandle return mCurrentFrameAnimations.mNextHandle || mNextFrameAnimations.mNextHandle; || mNextFrameAnimations.mNextHandle; } } // Will always add to the next frame list, which is swapped when // Will always add to the next frame list, which is swapped when Loading @@ -96,7 +97,8 @@ public: // as part of the standard RenderNode:prepareTree pass. // as part of the standard RenderNode:prepareTree pass. ANDROID_API virtual void runRemainingAnimations(TreeInfo& info); ANDROID_API virtual void runRemainingAnimations(TreeInfo& info); ANDROID_API virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener); ANDROID_API virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener); ANDROID_API virtual void destroy(); ANDROID_API virtual void destroy(); Loading libs/hwui/Animator.cpp +84 −93 Original line number Original line Diff line number Diff line Loading @@ -44,11 +44,9 @@ BaseRenderNodeAnimator::BaseRenderNodeAnimator(float finalValue) , mDuration(300) , mDuration(300) , mStartDelay(0) , mStartDelay(0) , mMayRunAsync(true) , mMayRunAsync(true) , mPlayTime(0) { , mPlayTime(0) {} } BaseRenderNodeAnimator::~BaseRenderNodeAnimator() { BaseRenderNodeAnimator::~BaseRenderNodeAnimator() {} } void BaseRenderNodeAnimator::checkMutable() { void BaseRenderNodeAnimator::checkMutable() { // Should be impossible to hit as the Java-side also has guards for this // Should be impossible to hit as the Java-side also has guards for this Loading Loading @@ -120,14 +118,16 @@ void BaseRenderNodeAnimator::end() { void BaseRenderNodeAnimator::resolveStagingRequest(Request request) { void BaseRenderNodeAnimator::resolveStagingRequest(Request request) { switch (request) { switch (request) { case Request::Start: case Request::Start: mPlayTime = (mPlayState == PlayState::Running || mPlayState == PlayState::Reversing) ? mPlayTime = (mPlayState == PlayState::Running || mPlayState == PlayState::Reversing) mPlayTime : 0; ? mPlayTime : 0; mPlayState = PlayState::Running; mPlayState = PlayState::Running; mPendingActionUponFinish = Action::None; mPendingActionUponFinish = Action::None; break; break; case Request::Reverse: case Request::Reverse: mPlayTime = (mPlayState == PlayState::Running || mPlayState == PlayState::Reversing) ? mPlayTime = (mPlayState == PlayState::Running || mPlayState == PlayState::Reversing) mPlayTime : mDuration; ? mPlayTime : mDuration; mPlayState = PlayState::Reversing; mPlayState = PlayState::Reversing; mPendingActionUponFinish = Action::None; mPendingActionUponFinish = Action::None; break; break; Loading Loading @@ -182,8 +182,8 @@ void BaseRenderNodeAnimator::pushStaging(AnimationContext& context) { if (mStagingPlayState == PlayState::Finished) { if (mStagingPlayState == PlayState::Finished) { callOnFinishedListener(context); callOnFinishedListener(context); } else if (mStagingPlayState == PlayState::Running } else if (mStagingPlayState == PlayState::Running || || mStagingPlayState == PlayState::Reversing) { mStagingPlayState == PlayState::Reversing) { bool changed = currentPlayTime != mPlayTime || prevFramePlayState != mStagingPlayState; bool changed = currentPlayTime != mPlayTime || prevFramePlayState != mStagingPlayState; if (prevFramePlayState != mStagingPlayState) { if (prevFramePlayState != mStagingPlayState) { transitionToRunning(context); transitionToRunning(context); Loading Loading @@ -223,8 +223,8 @@ void BaseRenderNodeAnimator::transitionToRunning(AnimationContext& context) { } } mStartTime = frameTimeMs + mStartDelay; mStartTime = frameTimeMs + mStartDelay; if (mStartTime < 0) { if (mStartTime < 0) { ALOGW("Ended up with a really weird start time of %" PRId64 ALOGW("Ended up with a really weird start time of %" PRId64 " with frame time %" PRId64 " with frame time %" PRId64 " and start delay %" PRId64, " and start delay %" PRId64, mStartTime, frameTimeMs, mStartDelay); mStartTime, frameTimeMs, mStartDelay); // Set to 0 so that the animate() basically instantly finishes // Set to 0 so that the animate() basically instantly finishes mStartTime = 0; mStartTime = 0; Loading Loading @@ -315,9 +315,12 @@ struct RenderPropertyAnimator::PropertyAccessors { // Maps RenderProperty enum to accessors // Maps RenderProperty enum to accessors const RenderPropertyAnimator::PropertyAccessors RenderPropertyAnimator::PROPERTY_ACCESSOR_LUT[] = { const RenderPropertyAnimator::PropertyAccessors RenderPropertyAnimator::PROPERTY_ACCESSOR_LUT[] = { {RenderNode::TRANSLATION_X, &RenderProperties::getTranslationX, &RenderProperties::setTranslationX }, {RenderNode::TRANSLATION_X, &RenderProperties::getTranslationX, {RenderNode::TRANSLATION_Y, &RenderProperties::getTranslationY, &RenderProperties::setTranslationY }, &RenderProperties::setTranslationX}, {RenderNode::TRANSLATION_Z, &RenderProperties::getTranslationZ, &RenderProperties::setTranslationZ }, {RenderNode::TRANSLATION_Y, &RenderProperties::getTranslationY, &RenderProperties::setTranslationY}, {RenderNode::TRANSLATION_Z, &RenderProperties::getTranslationZ, &RenderProperties::setTranslationZ}, {RenderNode::SCALE_X, &RenderProperties::getScaleX, &RenderProperties::setScaleX}, {RenderNode::SCALE_X, &RenderProperties::getScaleX, &RenderProperties::setScaleX}, {RenderNode::SCALE_Y, &RenderProperties::getScaleY, &RenderProperties::setScaleY}, {RenderNode::SCALE_Y, &RenderProperties::getScaleY, &RenderProperties::setScaleY}, {RenderNode::ROTATION, &RenderProperties::getRotation, &RenderProperties::setRotation}, {RenderNode::ROTATION, &RenderProperties::getRotation, &RenderProperties::setRotation}, Loading @@ -330,13 +333,10 @@ const RenderPropertyAnimator::PropertyAccessors RenderPropertyAnimator::PROPERTY }; }; RenderPropertyAnimator::RenderPropertyAnimator(RenderProperty property, float finalValue) RenderPropertyAnimator::RenderPropertyAnimator(RenderProperty property, float finalValue) : BaseRenderNodeAnimator(finalValue) : BaseRenderNodeAnimator(finalValue), mPropertyAccess(&(PROPERTY_ACCESSOR_LUT[property])) {} , mPropertyAccess(&(PROPERTY_ACCESSOR_LUT[property])) { } void RenderPropertyAnimator::onAttached() { void RenderPropertyAnimator::onAttached() { if (!mHasStartValue if (!mHasStartValue && mStagingTarget->isPropertyFieldDirty(mPropertyAccess->dirtyMask)) { && mStagingTarget->isPropertyFieldDirty(mPropertyAccess->dirtyMask)) { setStartValue((mStagingTarget->stagingProperties().*mPropertyAccess->getter)()); setStartValue((mStagingTarget->stagingProperties().*mPropertyAccess->getter)()); } } } } Loading Loading @@ -385,11 +385,9 @@ void RenderPropertyAnimator::setValue(RenderNode* target, float value) { * CanvasPropertyPrimitiveAnimator * CanvasPropertyPrimitiveAnimator ************************************************************/ ************************************************************/ CanvasPropertyPrimitiveAnimator::CanvasPropertyPrimitiveAnimator( CanvasPropertyPrimitiveAnimator::CanvasPropertyPrimitiveAnimator(CanvasPropertyPrimitive* property, CanvasPropertyPrimitive* property, float finalValue) float finalValue) : BaseRenderNodeAnimator(finalValue) : BaseRenderNodeAnimator(finalValue), mProperty(property) {} , mProperty(property) { } float CanvasPropertyPrimitiveAnimator::getValue(RenderNode* target) const { float CanvasPropertyPrimitiveAnimator::getValue(RenderNode* target) const { return mProperty->value; return mProperty->value; Loading @@ -407,12 +405,9 @@ uint32_t CanvasPropertyPrimitiveAnimator::dirtyMask() { * CanvasPropertySkPaintAnimator * CanvasPropertySkPaintAnimator ************************************************************/ ************************************************************/ CanvasPropertyPaintAnimator::CanvasPropertyPaintAnimator( CanvasPropertyPaintAnimator::CanvasPropertyPaintAnimator(CanvasPropertyPaint* property, CanvasPropertyPaint* property, PaintField field, float finalValue) PaintField field, float finalValue) : BaseRenderNodeAnimator(finalValue) : BaseRenderNodeAnimator(finalValue), mProperty(property), mField(field) {} , mProperty(property) , mField(field) { } float CanvasPropertyPaintAnimator::getValue(RenderNode* target) const { float CanvasPropertyPaintAnimator::getValue(RenderNode* target) const { switch (mField) { switch (mField) { Loading Loading @@ -446,11 +441,8 @@ uint32_t CanvasPropertyPaintAnimator::dirtyMask() { return RenderNode::DISPLAY_LIST; return RenderNode::DISPLAY_LIST; } } RevealAnimator::RevealAnimator(int centerX, int centerY, RevealAnimator::RevealAnimator(int centerX, int centerY, float startValue, float finalValue) float startValue, float finalValue) : BaseRenderNodeAnimator(finalValue), mCenterX(centerX), mCenterY(centerY) { : BaseRenderNodeAnimator(finalValue) , mCenterX(centerX) , mCenterY(centerY) { setStartValue(startValue); setStartValue(startValue); } } Loading @@ -459,8 +451,7 @@ float RevealAnimator::getValue(RenderNode* target) const { } } void RevealAnimator::setValue(RenderNode* target, float value) { void RevealAnimator::setValue(RenderNode* target, float value) { target->animatorProperties().mutableRevealClip().set(true, target->animatorProperties().mutableRevealClip().set(true, mCenterX, mCenterY, value); mCenterX, mCenterY, value); } } uint32_t RevealAnimator::dirtyMask() { uint32_t RevealAnimator::dirtyMask() { Loading Loading
libs/hwui/AmbientShadow.cpp +47 −52 Original line number Original line Diff line number Diff line Loading @@ -56,8 +56,8 @@ #include "Vertex.h" #include "Vertex.h" #include "VertexBuffer.h" #include "VertexBuffer.h" #include <algorithm> #include <utils/Log.h> #include <utils/Log.h> #include <algorithm> namespace android { namespace android { namespace uirenderer { namespace uirenderer { Loading @@ -79,8 +79,8 @@ inline float getAlphaFromFactoredZ(float factoredZ) { return 1.0 / (1 + std::max(factoredZ, 0.0f)); return 1.0 / (1 + std::max(factoredZ, 0.0f)); } } inline int getEdgeExtraAndUpdateSpike(Vector2* currentSpike, inline int getEdgeExtraAndUpdateSpike(Vector2* currentSpike, const Vector3& secondVertex, const Vector3& secondVertex, const Vector3& centroid) { const Vector3& centroid) { Vector2 secondSpike = {secondVertex.x - centroid.x, secondVertex.y - centroid.y}; Vector2 secondSpike = {secondVertex.x - centroid.x, secondVertex.y - centroid.y}; secondSpike.normalize(); secondSpike.normalize(); Loading @@ -92,11 +92,11 @@ inline int getEdgeExtraAndUpdateSpike(Vector2* currentSpike, // Given the caster's vertex count, compute all the buffers size depending on // Given the caster's vertex count, compute all the buffers size depending on // whether or not the caster is opaque. // whether or not the caster is opaque. inline void computeBufferSize(int* totalVertexCount, int* totalIndexCount, inline void computeBufferSize(int* totalVertexCount, int* totalIndexCount, int* totalUmbraCount, int* totalUmbraCount, int casterVertexCount, bool isCasterOpaque) { int casterVertexCount, bool isCasterOpaque) { // Compute the size of the vertex buffer. // Compute the size of the vertex buffer. int outerVertexCount = casterVertexCount * 2 + MAX_EXTRA_CORNER_VERTEX_NUMBER + int outerVertexCount = MAX_EXTRA_EDGE_VERTEX_NUMBER; casterVertexCount * 2 + MAX_EXTRA_CORNER_VERTEX_NUMBER + MAX_EXTRA_EDGE_VERTEX_NUMBER; int innerVertexCount = casterVertexCount + MAX_EXTRA_EDGE_VERTEX_NUMBER; int innerVertexCount = casterVertexCount + MAX_EXTRA_EDGE_VERTEX_NUMBER; *totalVertexCount = outerVertexCount + innerVertexCount; *totalVertexCount = outerVertexCount + innerVertexCount; Loading Loading @@ -163,27 +163,25 @@ inline bool needsExtraForEdge(float firstAlpha, float secondAlpha) { * | | * | | * (V3)-----------------------------------(V2) * (V3)-----------------------------------(V2) */ */ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, void AmbientShadow::createAmbientShadow(bool isCasterOpaque, const Vector3* casterVertices, const Vector3* casterVertices, int casterVertexCount, const Vector3& centroid3d, int casterVertexCount, const Vector3& centroid3d, float heightFactor, float geomFactor, VertexBuffer& shadowVertexBuffer) { float heightFactor, float geomFactor, VertexBuffer& shadowVertexBuffer) { shadowVertexBuffer.setMeshFeatureFlags(VertexBuffer::kAlpha | VertexBuffer::kIndices); shadowVertexBuffer.setMeshFeatureFlags(VertexBuffer::kAlpha | VertexBuffer::kIndices); // In order to computer the outer vertices in one loop, we need pre-compute // In order to computer the outer vertices in one loop, we need pre-compute // the normal by the vertex (n - 1) to vertex 0, and the spike and alpha value // the normal by the vertex (n - 1) to vertex 0, and the spike and alpha value // for vertex 0. // for vertex 0. Vector2 previousNormal = getNormalFromVertices(casterVertices, Vector2 previousNormal = getNormalFromVertices(casterVertices, casterVertexCount - 1, 0); casterVertexCount - 1 , 0); Vector2 currentSpike = {casterVertices[0].x - centroid3d.x, casterVertices[0].y - centroid3d.y}; Vector2 currentSpike = {casterVertices[0].x - centroid3d.x, casterVertices[0].y - centroid3d.y}; currentSpike.normalize(); currentSpike.normalize(); float currentAlpha = getAlphaFromFactoredZ(casterVertices[0].z * heightFactor); float currentAlpha = getAlphaFromFactoredZ(casterVertices[0].z * heightFactor); // Preparing all the output data. // Preparing all the output data. int totalVertexCount, totalIndexCount, totalUmbraCount; int totalVertexCount, totalIndexCount, totalUmbraCount; computeBufferSize(&totalVertexCount, &totalIndexCount, &totalUmbraCount, computeBufferSize(&totalVertexCount, &totalIndexCount, &totalUmbraCount, casterVertexCount, casterVertexCount, isCasterOpaque); isCasterOpaque); AlphaVertex* shadowVertices = AlphaVertex* shadowVertices = shadowVertexBuffer.alloc<AlphaVertex>(totalVertexCount); shadowVertexBuffer.alloc<AlphaVertex>(totalVertexCount); int vertexBufferIndex = 0; int vertexBufferIndex = 0; uint16_t* indexBuffer = shadowVertexBuffer.allocIndices<uint16_t>(totalIndexCount); uint16_t* indexBuffer = shadowVertexBuffer.allocIndices<uint16_t>(totalIndexCount); int indexBufferIndex = 0; int indexBufferIndex = 0; Loading @@ -193,11 +191,11 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, for (int i = 0; i < casterVertexCount; i++) { for (int i = 0; i < casterVertexCount; i++) { // Corner: first figure out the extra vertices we need for the corner. // Corner: first figure out the extra vertices we need for the corner. const Vector3& innerVertex = casterVertices[i]; const Vector3& innerVertex = casterVertices[i]; Vector2 currentNormal = getNormalFromVertices(casterVertices, i, Vector2 currentNormal = (i + 1) % casterVertexCount); getNormalFromVertices(casterVertices, i, (i + 1) % casterVertexCount); int extraVerticesNumber = ShadowTessellator::getExtraVertexNumber(currentNormal, int extraVerticesNumber = ShadowTessellator::getExtraVertexNumber( previousNormal, CORNER_RADIANS_DIVISOR); currentNormal, previousNormal, CORNER_RADIANS_DIVISOR); float expansionDist = innerVertex.z * heightFactor * geomFactor; float expansionDist = innerVertex.z * heightFactor * geomFactor; const int cornerSlicesNumber = extraVerticesNumber + 1; // Minimal as 1. const int cornerSlicesNumber = extraVerticesNumber + 1; // Minimal as 1. Loading @@ -212,9 +210,8 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, if (!isCasterOpaque) { if (!isCasterOpaque) { umbraVertices[umbraIndex++] = vertexBufferIndex; umbraVertices[umbraIndex++] = vertexBufferIndex; } } AlphaVertex::set(&shadowVertices[vertexBufferIndex++], AlphaVertex::set(&shadowVertices[vertexBufferIndex++], casterVertices[i].x, casterVertices[i].x, casterVertices[i].y, casterVertices[i].y, currentAlpha); currentAlpha); const Vector3& innerStart = casterVertices[i]; const Vector3& innerStart = casterVertices[i]; Loading @@ -225,8 +222,7 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, // This will create vertices from [0, cornerSlicesNumber] inclusively, // This will create vertices from [0, cornerSlicesNumber] inclusively, // which means minimally 2 vertices even without the extra ones. // which means minimally 2 vertices even without the extra ones. for (int j = 0; j <= cornerSlicesNumber; j++) { for (int j = 0; j <= cornerSlicesNumber; j++) { Vector2 averageNormal = Vector2 averageNormal = previousNormal * (cornerSlicesNumber - j) + currentNormal * j; previousNormal * (cornerSlicesNumber - j) + currentNormal * j; averageNormal /= cornerSlicesNumber; averageNormal /= cornerSlicesNumber; averageNormal.normalize(); averageNormal.normalize(); Vector2 outerVertex; Vector2 outerVertex; Loading @@ -235,8 +231,8 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, indexBuffer[indexBufferIndex++] = vertexBufferIndex; indexBuffer[indexBufferIndex++] = vertexBufferIndex; indexBuffer[indexBufferIndex++] = currentInnerVertexIndex; indexBuffer[indexBufferIndex++] = currentInnerVertexIndex; AlphaVertex::set(&shadowVertices[vertexBufferIndex++], outerVertex.x, AlphaVertex::set(&shadowVertices[vertexBufferIndex++], outerVertex.x, outerVertex.y, outerVertex.y, OUTER_ALPHA); OUTER_ALPHA); if (j == 0) { if (j == 0) { outerStart = outerVertex; outerStart = outerVertex; Loading @@ -257,8 +253,8 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, outerNext.y = innerNext.y + currentNormal.y * expansionDist; outerNext.y = innerNext.y + currentNormal.y * expansionDist; // Compute the angle and see how many extra points we need. // Compute the angle and see how many extra points we need. int extraVerticesNumber = getEdgeExtraAndUpdateSpike(¤tSpike, int extraVerticesNumber = innerNext, centroid3d); getEdgeExtraAndUpdateSpike(¤tSpike, innerNext, centroid3d); #if DEBUG_SHADOW #if DEBUG_SHADOW ALOGD("extraVerticesNumber %d for edge %d", extraVerticesNumber, i); ALOGD("extraVerticesNumber %d for edge %d", extraVerticesNumber, i); #endif #endif Loading Loading @@ -293,11 +289,10 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque, if (!isCasterOpaque) { if (!isCasterOpaque) { // Add the centroid as the last one in the vertex buffer. // Add the centroid as the last one in the vertex buffer. float centroidOpacity = float centroidOpacity = getAlphaFromFactoredZ(centroid3d.z * heightFactor); getAlphaFromFactoredZ(centroid3d.z * heightFactor); int centroidIndex = vertexBufferIndex; int centroidIndex = vertexBufferIndex; AlphaVertex::set(&shadowVertices[vertexBufferIndex++], centroid3d.x, AlphaVertex::set(&shadowVertices[vertexBufferIndex++], centroid3d.x, centroid3d.y, centroid3d.y, centroidOpacity); centroidOpacity); for (int i = 0; i < umbraIndex; i++) { for (int i = 0; i < umbraIndex; i++) { // Note that umbraVertices[0] is always 0. // Note that umbraVertices[0] is always 0. Loading
libs/hwui/AmbientShadow.h +7 −7 Original line number Original line Diff line number Diff line Loading @@ -31,9 +31,9 @@ class VertexBuffer; */ */ class AmbientShadow { class AmbientShadow { public: public: static void createAmbientShadow(bool isCasterOpaque, const Vector3* poly, static void createAmbientShadow(bool isCasterOpaque, const Vector3* poly, int polyLength, int polyLength, const Vector3& centroid3d, float heightFactor, const Vector3& centroid3d, float heightFactor, float geomFactor, float geomFactor, VertexBuffer& shadowVertexBuffer); VertexBuffer& shadowVertexBuffer); }; // AmbientShadow }; // AmbientShadow }; // namespace uirenderer }; // namespace uirenderer Loading
libs/hwui/AnimationContext.cpp +9 −14 Original line number Original line Diff line number Diff line Loading @@ -26,11 +26,9 @@ AnimationContext::AnimationContext(renderthread::TimeLord& clock) : mClock(clock) : mClock(clock) , mCurrentFrameAnimations(*this) , mCurrentFrameAnimations(*this) , mNextFrameAnimations(*this) , mNextFrameAnimations(*this) , mFrameTimeMs(0) { , mFrameTimeMs(0) {} } AnimationContext::~AnimationContext() { AnimationContext::~AnimationContext() {} } void AnimationContext::destroy() { void AnimationContext::destroy() { startFrame(TreeInfo::MODE_RT_ONLY); startFrame(TreeInfo::MODE_RT_ONLY); Loading Loading @@ -83,10 +81,7 @@ void AnimationContext::callOnFinished(BaseRenderNodeAnimator* animator, } } AnimationHandle::AnimationHandle(AnimationContext& context) AnimationHandle::AnimationHandle(AnimationContext& context) : mContext(context) : mContext(context), mPreviousHandle(nullptr), mNextHandle(nullptr) {} , mPreviousHandle(nullptr) , mNextHandle(nullptr) { } AnimationHandle::AnimationHandle(RenderNode& animatingNode, AnimationContext& context) AnimationHandle::AnimationHandle(RenderNode& animatingNode, AnimationContext& context) : mRenderNode(&animatingNode) : mRenderNode(&animatingNode) Loading
libs/hwui/AnimationContext.h +5 −3 Original line number Original line Diff line number Diff line Loading @@ -43,6 +43,7 @@ class RenderNode; */ */ class AnimationHandle { class AnimationHandle { PREVENT_COPY_AND_ASSIGN(AnimationHandle); PREVENT_COPY_AND_ASSIGN(AnimationHandle); public: public: AnimationContext& context() { return mContext; } AnimationContext& context() { return mContext; } Loading Loading @@ -74,14 +75,14 @@ private: class AnimationContext { class AnimationContext { PREVENT_COPY_AND_ASSIGN(AnimationContext); PREVENT_COPY_AND_ASSIGN(AnimationContext); public: public: ANDROID_API explicit AnimationContext(renderthread::TimeLord& clock); ANDROID_API explicit AnimationContext(renderthread::TimeLord& clock); ANDROID_API virtual ~AnimationContext(); ANDROID_API virtual ~AnimationContext(); nsecs_t frameTimeMs() { return mFrameTimeMs; } nsecs_t frameTimeMs() { return mFrameTimeMs; } bool hasAnimations() { bool hasAnimations() { return mCurrentFrameAnimations.mNextHandle return mCurrentFrameAnimations.mNextHandle || mNextFrameAnimations.mNextHandle; || mNextFrameAnimations.mNextHandle; } } // Will always add to the next frame list, which is swapped when // Will always add to the next frame list, which is swapped when Loading @@ -96,7 +97,8 @@ public: // as part of the standard RenderNode:prepareTree pass. // as part of the standard RenderNode:prepareTree pass. ANDROID_API virtual void runRemainingAnimations(TreeInfo& info); ANDROID_API virtual void runRemainingAnimations(TreeInfo& info); ANDROID_API virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener); ANDROID_API virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener); ANDROID_API virtual void destroy(); ANDROID_API virtual void destroy(); Loading
libs/hwui/Animator.cpp +84 −93 Original line number Original line Diff line number Diff line Loading @@ -44,11 +44,9 @@ BaseRenderNodeAnimator::BaseRenderNodeAnimator(float finalValue) , mDuration(300) , mDuration(300) , mStartDelay(0) , mStartDelay(0) , mMayRunAsync(true) , mMayRunAsync(true) , mPlayTime(0) { , mPlayTime(0) {} } BaseRenderNodeAnimator::~BaseRenderNodeAnimator() { BaseRenderNodeAnimator::~BaseRenderNodeAnimator() {} } void BaseRenderNodeAnimator::checkMutable() { void BaseRenderNodeAnimator::checkMutable() { // Should be impossible to hit as the Java-side also has guards for this // Should be impossible to hit as the Java-side also has guards for this Loading Loading @@ -120,14 +118,16 @@ void BaseRenderNodeAnimator::end() { void BaseRenderNodeAnimator::resolveStagingRequest(Request request) { void BaseRenderNodeAnimator::resolveStagingRequest(Request request) { switch (request) { switch (request) { case Request::Start: case Request::Start: mPlayTime = (mPlayState == PlayState::Running || mPlayState == PlayState::Reversing) ? mPlayTime = (mPlayState == PlayState::Running || mPlayState == PlayState::Reversing) mPlayTime : 0; ? mPlayTime : 0; mPlayState = PlayState::Running; mPlayState = PlayState::Running; mPendingActionUponFinish = Action::None; mPendingActionUponFinish = Action::None; break; break; case Request::Reverse: case Request::Reverse: mPlayTime = (mPlayState == PlayState::Running || mPlayState == PlayState::Reversing) ? mPlayTime = (mPlayState == PlayState::Running || mPlayState == PlayState::Reversing) mPlayTime : mDuration; ? mPlayTime : mDuration; mPlayState = PlayState::Reversing; mPlayState = PlayState::Reversing; mPendingActionUponFinish = Action::None; mPendingActionUponFinish = Action::None; break; break; Loading Loading @@ -182,8 +182,8 @@ void BaseRenderNodeAnimator::pushStaging(AnimationContext& context) { if (mStagingPlayState == PlayState::Finished) { if (mStagingPlayState == PlayState::Finished) { callOnFinishedListener(context); callOnFinishedListener(context); } else if (mStagingPlayState == PlayState::Running } else if (mStagingPlayState == PlayState::Running || || mStagingPlayState == PlayState::Reversing) { mStagingPlayState == PlayState::Reversing) { bool changed = currentPlayTime != mPlayTime || prevFramePlayState != mStagingPlayState; bool changed = currentPlayTime != mPlayTime || prevFramePlayState != mStagingPlayState; if (prevFramePlayState != mStagingPlayState) { if (prevFramePlayState != mStagingPlayState) { transitionToRunning(context); transitionToRunning(context); Loading Loading @@ -223,8 +223,8 @@ void BaseRenderNodeAnimator::transitionToRunning(AnimationContext& context) { } } mStartTime = frameTimeMs + mStartDelay; mStartTime = frameTimeMs + mStartDelay; if (mStartTime < 0) { if (mStartTime < 0) { ALOGW("Ended up with a really weird start time of %" PRId64 ALOGW("Ended up with a really weird start time of %" PRId64 " with frame time %" PRId64 " with frame time %" PRId64 " and start delay %" PRId64, " and start delay %" PRId64, mStartTime, frameTimeMs, mStartDelay); mStartTime, frameTimeMs, mStartDelay); // Set to 0 so that the animate() basically instantly finishes // Set to 0 so that the animate() basically instantly finishes mStartTime = 0; mStartTime = 0; Loading Loading @@ -315,9 +315,12 @@ struct RenderPropertyAnimator::PropertyAccessors { // Maps RenderProperty enum to accessors // Maps RenderProperty enum to accessors const RenderPropertyAnimator::PropertyAccessors RenderPropertyAnimator::PROPERTY_ACCESSOR_LUT[] = { const RenderPropertyAnimator::PropertyAccessors RenderPropertyAnimator::PROPERTY_ACCESSOR_LUT[] = { {RenderNode::TRANSLATION_X, &RenderProperties::getTranslationX, &RenderProperties::setTranslationX }, {RenderNode::TRANSLATION_X, &RenderProperties::getTranslationX, {RenderNode::TRANSLATION_Y, &RenderProperties::getTranslationY, &RenderProperties::setTranslationY }, &RenderProperties::setTranslationX}, {RenderNode::TRANSLATION_Z, &RenderProperties::getTranslationZ, &RenderProperties::setTranslationZ }, {RenderNode::TRANSLATION_Y, &RenderProperties::getTranslationY, &RenderProperties::setTranslationY}, {RenderNode::TRANSLATION_Z, &RenderProperties::getTranslationZ, &RenderProperties::setTranslationZ}, {RenderNode::SCALE_X, &RenderProperties::getScaleX, &RenderProperties::setScaleX}, {RenderNode::SCALE_X, &RenderProperties::getScaleX, &RenderProperties::setScaleX}, {RenderNode::SCALE_Y, &RenderProperties::getScaleY, &RenderProperties::setScaleY}, {RenderNode::SCALE_Y, &RenderProperties::getScaleY, &RenderProperties::setScaleY}, {RenderNode::ROTATION, &RenderProperties::getRotation, &RenderProperties::setRotation}, {RenderNode::ROTATION, &RenderProperties::getRotation, &RenderProperties::setRotation}, Loading @@ -330,13 +333,10 @@ const RenderPropertyAnimator::PropertyAccessors RenderPropertyAnimator::PROPERTY }; }; RenderPropertyAnimator::RenderPropertyAnimator(RenderProperty property, float finalValue) RenderPropertyAnimator::RenderPropertyAnimator(RenderProperty property, float finalValue) : BaseRenderNodeAnimator(finalValue) : BaseRenderNodeAnimator(finalValue), mPropertyAccess(&(PROPERTY_ACCESSOR_LUT[property])) {} , mPropertyAccess(&(PROPERTY_ACCESSOR_LUT[property])) { } void RenderPropertyAnimator::onAttached() { void RenderPropertyAnimator::onAttached() { if (!mHasStartValue if (!mHasStartValue && mStagingTarget->isPropertyFieldDirty(mPropertyAccess->dirtyMask)) { && mStagingTarget->isPropertyFieldDirty(mPropertyAccess->dirtyMask)) { setStartValue((mStagingTarget->stagingProperties().*mPropertyAccess->getter)()); setStartValue((mStagingTarget->stagingProperties().*mPropertyAccess->getter)()); } } } } Loading Loading @@ -385,11 +385,9 @@ void RenderPropertyAnimator::setValue(RenderNode* target, float value) { * CanvasPropertyPrimitiveAnimator * CanvasPropertyPrimitiveAnimator ************************************************************/ ************************************************************/ CanvasPropertyPrimitiveAnimator::CanvasPropertyPrimitiveAnimator( CanvasPropertyPrimitiveAnimator::CanvasPropertyPrimitiveAnimator(CanvasPropertyPrimitive* property, CanvasPropertyPrimitive* property, float finalValue) float finalValue) : BaseRenderNodeAnimator(finalValue) : BaseRenderNodeAnimator(finalValue), mProperty(property) {} , mProperty(property) { } float CanvasPropertyPrimitiveAnimator::getValue(RenderNode* target) const { float CanvasPropertyPrimitiveAnimator::getValue(RenderNode* target) const { return mProperty->value; return mProperty->value; Loading @@ -407,12 +405,9 @@ uint32_t CanvasPropertyPrimitiveAnimator::dirtyMask() { * CanvasPropertySkPaintAnimator * CanvasPropertySkPaintAnimator ************************************************************/ ************************************************************/ CanvasPropertyPaintAnimator::CanvasPropertyPaintAnimator( CanvasPropertyPaintAnimator::CanvasPropertyPaintAnimator(CanvasPropertyPaint* property, CanvasPropertyPaint* property, PaintField field, float finalValue) PaintField field, float finalValue) : BaseRenderNodeAnimator(finalValue) : BaseRenderNodeAnimator(finalValue), mProperty(property), mField(field) {} , mProperty(property) , mField(field) { } float CanvasPropertyPaintAnimator::getValue(RenderNode* target) const { float CanvasPropertyPaintAnimator::getValue(RenderNode* target) const { switch (mField) { switch (mField) { Loading Loading @@ -446,11 +441,8 @@ uint32_t CanvasPropertyPaintAnimator::dirtyMask() { return RenderNode::DISPLAY_LIST; return RenderNode::DISPLAY_LIST; } } RevealAnimator::RevealAnimator(int centerX, int centerY, RevealAnimator::RevealAnimator(int centerX, int centerY, float startValue, float finalValue) float startValue, float finalValue) : BaseRenderNodeAnimator(finalValue), mCenterX(centerX), mCenterY(centerY) { : BaseRenderNodeAnimator(finalValue) , mCenterX(centerX) , mCenterY(centerY) { setStartValue(startValue); setStartValue(startValue); } } Loading @@ -459,8 +451,7 @@ float RevealAnimator::getValue(RenderNode* target) const { } } void RevealAnimator::setValue(RenderNode* target, float value) { void RevealAnimator::setValue(RenderNode* target, float value) { target->animatorProperties().mutableRevealClip().set(true, target->animatorProperties().mutableRevealClip().set(true, mCenterX, mCenterY, value); mCenterX, mCenterY, value); } } uint32_t RevealAnimator::dirtyMask() { uint32_t RevealAnimator::dirtyMask() { Loading