Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1bcacfdc authored by John Reck's avatar John Reck
Browse files

Format the world (or just HWUI)

Test: No code changes, just ran through clang-format
Change-Id: Id23aa4ec7eebc0446fe3a30260f33e7fd455bb8c
parent 30ec71c0
Loading
Loading
Loading
Loading
+47 −52
Original line number Diff line number Diff line
@@ -56,8 +56,8 @@
#include "Vertex.h"
#include "VertexBuffer.h"

#include <algorithm>
#include <utils/Log.h>
#include <algorithm>

namespace android {
namespace uirenderer {
@@ -79,8 +79,8 @@ inline float getAlphaFromFactoredZ(float factoredZ) {
    return 1.0 / (1 + std::max(factoredZ, 0.0f));
}

inline int getEdgeExtraAndUpdateSpike(Vector2* currentSpike,
        const Vector3& secondVertex, const Vector3& centroid) {
inline int getEdgeExtraAndUpdateSpike(Vector2* currentSpike, const Vector3& secondVertex,
                                      const Vector3& centroid) {
    Vector2 secondSpike = {secondVertex.x - centroid.x, secondVertex.y - centroid.y};
    secondSpike.normalize();

@@ -92,11 +92,11 @@ inline int getEdgeExtraAndUpdateSpike(Vector2* currentSpike,

// Given the caster's vertex count, compute all the buffers size depending on
// whether or not the caster is opaque.
inline void computeBufferSize(int* totalVertexCount, int* totalIndexCount,
        int* totalUmbraCount, int casterVertexCount, bool isCasterOpaque) {
inline void computeBufferSize(int* totalVertexCount, int* totalIndexCount, int* totalUmbraCount,
                              int casterVertexCount, bool isCasterOpaque) {
    // Compute the size of the vertex buffer.
    int outerVertexCount = casterVertexCount * 2 + MAX_EXTRA_CORNER_VERTEX_NUMBER +
        MAX_EXTRA_EDGE_VERTEX_NUMBER;
    int outerVertexCount =
            casterVertexCount * 2 + MAX_EXTRA_CORNER_VERTEX_NUMBER + MAX_EXTRA_EDGE_VERTEX_NUMBER;
    int innerVertexCount = casterVertexCount + MAX_EXTRA_EDGE_VERTEX_NUMBER;
    *totalVertexCount = outerVertexCount + innerVertexCount;

@@ -163,27 +163,25 @@ inline bool needsExtraForEdge(float firstAlpha, float secondAlpha) {
 *           |                                 |
 *        (V3)-----------------------------------(V2)
 */
void AmbientShadow::createAmbientShadow(bool isCasterOpaque,
        const Vector3* casterVertices, int casterVertexCount, const Vector3& centroid3d,
        float heightFactor, float geomFactor, VertexBuffer& shadowVertexBuffer) {
void AmbientShadow::createAmbientShadow(bool isCasterOpaque, const Vector3* casterVertices,
                                        int casterVertexCount, const Vector3& centroid3d,
                                        float heightFactor, float geomFactor,
                                        VertexBuffer& shadowVertexBuffer) {
    shadowVertexBuffer.setMeshFeatureFlags(VertexBuffer::kAlpha | VertexBuffer::kIndices);

    // 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
    // for vertex 0.
    Vector2 previousNormal = getNormalFromVertices(casterVertices,
            casterVertexCount - 1 , 0);
    Vector2 currentSpike = {casterVertices[0].x - centroid3d.x,
        casterVertices[0].y - centroid3d.y};
    Vector2 previousNormal = getNormalFromVertices(casterVertices, casterVertexCount - 1, 0);
    Vector2 currentSpike = {casterVertices[0].x - centroid3d.x, casterVertices[0].y - centroid3d.y};
    currentSpike.normalize();
    float currentAlpha = getAlphaFromFactoredZ(casterVertices[0].z * heightFactor);

    // Preparing all the output data.
    int totalVertexCount, totalIndexCount, totalUmbraCount;
    computeBufferSize(&totalVertexCount, &totalIndexCount, &totalUmbraCount,
            casterVertexCount, isCasterOpaque);
    AlphaVertex* shadowVertices =
            shadowVertexBuffer.alloc<AlphaVertex>(totalVertexCount);
    computeBufferSize(&totalVertexCount, &totalIndexCount, &totalUmbraCount, casterVertexCount,
                      isCasterOpaque);
    AlphaVertex* shadowVertices = shadowVertexBuffer.alloc<AlphaVertex>(totalVertexCount);
    int vertexBufferIndex = 0;
    uint16_t* indexBuffer = shadowVertexBuffer.allocIndices<uint16_t>(totalIndexCount);
    int indexBufferIndex = 0;
@@ -193,11 +191,11 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque,
    for (int i = 0; i < casterVertexCount; i++) {
        // Corner: first figure out the extra vertices we need for the corner.
        const Vector3& innerVertex = casterVertices[i];
        Vector2 currentNormal = getNormalFromVertices(casterVertices, i,
                (i + 1) % casterVertexCount);
        Vector2 currentNormal =
                getNormalFromVertices(casterVertices, i, (i + 1) % casterVertexCount);

        int extraVerticesNumber = ShadowTessellator::getExtraVertexNumber(currentNormal,
                previousNormal, CORNER_RADIANS_DIVISOR);
        int extraVerticesNumber = ShadowTessellator::getExtraVertexNumber(
                currentNormal, previousNormal, CORNER_RADIANS_DIVISOR);

        float expansionDist = innerVertex.z * heightFactor * geomFactor;
        const int cornerSlicesNumber = extraVerticesNumber + 1;  // Minimal as 1.
@@ -212,9 +210,8 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque,
        if (!isCasterOpaque) {
            umbraVertices[umbraIndex++] = vertexBufferIndex;
        }
        AlphaVertex::set(&shadowVertices[vertexBufferIndex++],
                casterVertices[i].x, casterVertices[i].y,
                currentAlpha);
        AlphaVertex::set(&shadowVertices[vertexBufferIndex++], casterVertices[i].x,
                         casterVertices[i].y, currentAlpha);

        const Vector3& innerStart = casterVertices[i];

@@ -225,8 +222,7 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque,
        // This will create vertices from [0, cornerSlicesNumber] inclusively,
        // which means minimally 2 vertices even without the extra ones.
        for (int j = 0; j <= cornerSlicesNumber; j++) {
            Vector2 averageNormal =
                previousNormal * (cornerSlicesNumber - j) + currentNormal * j;
            Vector2 averageNormal = previousNormal * (cornerSlicesNumber - j) + currentNormal * j;
            averageNormal /= cornerSlicesNumber;
            averageNormal.normalize();
            Vector2 outerVertex;
@@ -235,8 +231,8 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque,

            indexBuffer[indexBufferIndex++] = vertexBufferIndex;
            indexBuffer[indexBufferIndex++] = currentInnerVertexIndex;
            AlphaVertex::set(&shadowVertices[vertexBufferIndex++], outerVertex.x,
                    outerVertex.y, OUTER_ALPHA);
            AlphaVertex::set(&shadowVertices[vertexBufferIndex++], outerVertex.x, outerVertex.y,
                             OUTER_ALPHA);

            if (j == 0) {
                outerStart = outerVertex;
@@ -257,8 +253,8 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque,
            outerNext.y = innerNext.y + currentNormal.y * expansionDist;

            // Compute the angle and see how many extra points we need.
            int extraVerticesNumber = getEdgeExtraAndUpdateSpike(&currentSpike,
                    innerNext, centroid3d);
            int extraVerticesNumber =
                    getEdgeExtraAndUpdateSpike(&currentSpike, innerNext, centroid3d);
#if DEBUG_SHADOW
            ALOGD("extraVerticesNumber %d for edge %d", extraVerticesNumber, i);
#endif
@@ -293,11 +289,10 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque,

    if (!isCasterOpaque) {
        // Add the centroid as the last one in the vertex buffer.
        float centroidOpacity =
            getAlphaFromFactoredZ(centroid3d.z * heightFactor);
        float centroidOpacity = getAlphaFromFactoredZ(centroid3d.z * heightFactor);
        int centroidIndex = vertexBufferIndex;
        AlphaVertex::set(&shadowVertices[vertexBufferIndex++], centroid3d.x,
                centroid3d.y, centroidOpacity);
        AlphaVertex::set(&shadowVertices[vertexBufferIndex++], centroid3d.x, centroid3d.y,
                         centroidOpacity);

        for (int i = 0; i < umbraIndex; i++) {
            // Note that umbraVertices[0] is always 0.
+7 −7
Original line number Diff line number Diff line
@@ -31,9 +31,9 @@ class VertexBuffer;
 */
class AmbientShadow {
public:
    static void createAmbientShadow(bool isCasterOpaque, const Vector3* poly,
            int polyLength, const Vector3& centroid3d, float heightFactor,
            float geomFactor, VertexBuffer& shadowVertexBuffer);
    static void createAmbientShadow(bool isCasterOpaque, const Vector3* poly, int polyLength,
                                    const Vector3& centroid3d, float heightFactor, float geomFactor,
                                    VertexBuffer& shadowVertexBuffer);
};  // AmbientShadow

};  // namespace uirenderer
+9 −14
Original line number Diff line number Diff line
@@ -26,11 +26,9 @@ AnimationContext::AnimationContext(renderthread::TimeLord& clock)
        : mClock(clock)
        , mCurrentFrameAnimations(*this)
        , mNextFrameAnimations(*this)
        , mFrameTimeMs(0) {
}
        , mFrameTimeMs(0) {}

AnimationContext::~AnimationContext() {
}
AnimationContext::~AnimationContext() {}

void AnimationContext::destroy() {
    startFrame(TreeInfo::MODE_RT_ONLY);
@@ -83,10 +81,7 @@ void AnimationContext::callOnFinished(BaseRenderNodeAnimator* animator,
}

AnimationHandle::AnimationHandle(AnimationContext& context)
        : mContext(context)
        , mPreviousHandle(nullptr)
        , mNextHandle(nullptr) {
}
        : mContext(context), mPreviousHandle(nullptr), mNextHandle(nullptr) {}

AnimationHandle::AnimationHandle(RenderNode& animatingNode, AnimationContext& context)
        : mRenderNode(&animatingNode)
+5 −3
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ class RenderNode;
 */
class AnimationHandle {
    PREVENT_COPY_AND_ASSIGN(AnimationHandle);

public:
    AnimationContext& context() { return mContext; }

@@ -74,14 +75,14 @@ private:

class AnimationContext {
    PREVENT_COPY_AND_ASSIGN(AnimationContext);

public:
    ANDROID_API explicit AnimationContext(renderthread::TimeLord& clock);
    ANDROID_API virtual ~AnimationContext();

    nsecs_t frameTimeMs() { return mFrameTimeMs; }
    bool hasAnimations() {
        return mCurrentFrameAnimations.mNextHandle
                || mNextFrameAnimations.mNextHandle;
        return mCurrentFrameAnimations.mNextHandle || mNextFrameAnimations.mNextHandle;
    }

    // Will always add to the next frame list, which is swapped when
@@ -96,7 +97,8 @@ public:
    // as part of the standard RenderNode:prepareTree pass.
    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();

+84 −93
Original line number Diff line number Diff line
@@ -44,11 +44,9 @@ BaseRenderNodeAnimator::BaseRenderNodeAnimator(float finalValue)
        , mDuration(300)
        , mStartDelay(0)
        , mMayRunAsync(true)
        , mPlayTime(0) {
}
        , mPlayTime(0) {}

BaseRenderNodeAnimator::~BaseRenderNodeAnimator() {
}
BaseRenderNodeAnimator::~BaseRenderNodeAnimator() {}

void BaseRenderNodeAnimator::checkMutable() {
    // Should be impossible to hit as the Java-side also has guards for this
@@ -120,14 +118,16 @@ void BaseRenderNodeAnimator::end() {
void BaseRenderNodeAnimator::resolveStagingRequest(Request request) {
    switch (request) {
        case Request::Start:
        mPlayTime = (mPlayState == PlayState::Running || mPlayState == PlayState::Reversing) ?
                        mPlayTime : 0;
            mPlayTime = (mPlayState == PlayState::Running || mPlayState == PlayState::Reversing)
                                ? mPlayTime
                                : 0;
            mPlayState = PlayState::Running;
            mPendingActionUponFinish = Action::None;
            break;
        case Request::Reverse:
        mPlayTime = (mPlayState == PlayState::Running || mPlayState == PlayState::Reversing) ?
                        mPlayTime : mDuration;
            mPlayTime = (mPlayState == PlayState::Running || mPlayState == PlayState::Reversing)
                                ? mPlayTime
                                : mDuration;
            mPlayState = PlayState::Reversing;
            mPendingActionUponFinish = Action::None;
            break;
@@ -182,8 +182,8 @@ void BaseRenderNodeAnimator::pushStaging(AnimationContext& context) {

        if (mStagingPlayState == PlayState::Finished) {
            callOnFinishedListener(context);
        } else if (mStagingPlayState == PlayState::Running
                || mStagingPlayState == PlayState::Reversing) {
        } else if (mStagingPlayState == PlayState::Running ||
                   mStagingPlayState == PlayState::Reversing) {
            bool changed = currentPlayTime != mPlayTime || prevFramePlayState != mStagingPlayState;
            if (prevFramePlayState != mStagingPlayState) {
                transitionToRunning(context);
@@ -223,8 +223,8 @@ void BaseRenderNodeAnimator::transitionToRunning(AnimationContext& context) {
    }
    mStartTime = frameTimeMs + mStartDelay;
    if (mStartTime < 0) {
        ALOGW("Ended up with a really weird start time of %" PRId64
                " with frame time %" PRId64 " and start delay %" PRId64,
        ALOGW("Ended up with a really weird start time of %" PRId64 " with frame time %" PRId64
              " and start delay %" PRId64,
              mStartTime, frameTimeMs, mStartDelay);
        // Set to 0 so that the animate() basically instantly finishes
        mStartTime = 0;
@@ -315,9 +315,12 @@ struct RenderPropertyAnimator::PropertyAccessors {

// Maps RenderProperty enum to accessors
const RenderPropertyAnimator::PropertyAccessors RenderPropertyAnimator::PROPERTY_ACCESSOR_LUT[] = {
    {RenderNode::TRANSLATION_X, &RenderProperties::getTranslationX, &RenderProperties::setTranslationX },
    {RenderNode::TRANSLATION_Y, &RenderProperties::getTranslationY, &RenderProperties::setTranslationY },
    {RenderNode::TRANSLATION_Z, &RenderProperties::getTranslationZ, &RenderProperties::setTranslationZ },
        {RenderNode::TRANSLATION_X, &RenderProperties::getTranslationX,
         &RenderProperties::setTranslationX},
        {RenderNode::TRANSLATION_Y, &RenderProperties::getTranslationY,
         &RenderProperties::setTranslationY},
        {RenderNode::TRANSLATION_Z, &RenderProperties::getTranslationZ,
         &RenderProperties::setTranslationZ},
        {RenderNode::SCALE_X, &RenderProperties::getScaleX, &RenderProperties::setScaleX},
        {RenderNode::SCALE_Y, &RenderProperties::getScaleY, &RenderProperties::setScaleY},
        {RenderNode::ROTATION, &RenderProperties::getRotation, &RenderProperties::setRotation},
@@ -330,13 +333,10 @@ const RenderPropertyAnimator::PropertyAccessors RenderPropertyAnimator::PROPERTY
};

RenderPropertyAnimator::RenderPropertyAnimator(RenderProperty property, float finalValue)
        : BaseRenderNodeAnimator(finalValue)
        , mPropertyAccess(&(PROPERTY_ACCESSOR_LUT[property])) {
}
        : BaseRenderNodeAnimator(finalValue), mPropertyAccess(&(PROPERTY_ACCESSOR_LUT[property])) {}

void RenderPropertyAnimator::onAttached() {
    if (!mHasStartValue
            && mStagingTarget->isPropertyFieldDirty(mPropertyAccess->dirtyMask)) {
    if (!mHasStartValue && mStagingTarget->isPropertyFieldDirty(mPropertyAccess->dirtyMask)) {
        setStartValue((mStagingTarget->stagingProperties().*mPropertyAccess->getter)());
    }
}
@@ -385,11 +385,9 @@ void RenderPropertyAnimator::setValue(RenderNode* target, float value) {
 *  CanvasPropertyPrimitiveAnimator
 ************************************************************/

CanvasPropertyPrimitiveAnimator::CanvasPropertyPrimitiveAnimator(
                CanvasPropertyPrimitive* property, float finalValue)
        : BaseRenderNodeAnimator(finalValue)
        , mProperty(property) {
}
CanvasPropertyPrimitiveAnimator::CanvasPropertyPrimitiveAnimator(CanvasPropertyPrimitive* property,
                                                                 float finalValue)
        : BaseRenderNodeAnimator(finalValue), mProperty(property) {}

float CanvasPropertyPrimitiveAnimator::getValue(RenderNode* target) const {
    return mProperty->value;
@@ -407,12 +405,9 @@ uint32_t CanvasPropertyPrimitiveAnimator::dirtyMask() {
 *  CanvasPropertySkPaintAnimator
 ************************************************************/

CanvasPropertyPaintAnimator::CanvasPropertyPaintAnimator(
                CanvasPropertyPaint* property, PaintField field, float finalValue)
        : BaseRenderNodeAnimator(finalValue)
        , mProperty(property)
        , mField(field) {
}
CanvasPropertyPaintAnimator::CanvasPropertyPaintAnimator(CanvasPropertyPaint* property,
                                                         PaintField field, float finalValue)
        : BaseRenderNodeAnimator(finalValue), mProperty(property), mField(field) {}

float CanvasPropertyPaintAnimator::getValue(RenderNode* target) const {
    switch (mField) {
@@ -446,11 +441,8 @@ uint32_t CanvasPropertyPaintAnimator::dirtyMask() {
    return RenderNode::DISPLAY_LIST;
}

RevealAnimator::RevealAnimator(int centerX, int centerY,
        float startValue, float finalValue)
        : BaseRenderNodeAnimator(finalValue)
        , mCenterX(centerX)
        , mCenterY(centerY) {
RevealAnimator::RevealAnimator(int centerX, int centerY, float startValue, float finalValue)
        : BaseRenderNodeAnimator(finalValue), mCenterX(centerX), mCenterY(centerY) {
    setStartValue(startValue);
}

@@ -459,8 +451,7 @@ float RevealAnimator::getValue(RenderNode* target) const {
}

void RevealAnimator::setValue(RenderNode* target, float value) {
    target->animatorProperties().mutableRevealClip().set(true,
            mCenterX, mCenterY, value);
    target->animatorProperties().mutableRevealClip().set(true, mCenterX, mCenterY, value);
}

uint32_t RevealAnimator::dirtyMask() {
Loading