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

Commit e65e6c0d authored by Derek Sollenberger's avatar Derek Sollenberger Committed by Android (Google) Code Review
Browse files

Merge "Remove unused classes from HWUI."

parents 760d8b1e 72903272
Loading
Loading
Loading
Loading
+1 −8
Original line number Diff line number Diff line
@@ -23,8 +23,6 @@
#include <hwui/Paint.h>
#include <utils/Log.h>

#include <ResourceCache.h>

#include "SkCanvas.h"
#include "SkLatticeIter.h"
#include "SkRegion.h"
@@ -83,13 +81,8 @@ public:

    static void finalize(JNIEnv* env, jobject, jlong patchHandle) {
        int8_t* patch = reinterpret_cast<int8_t*>(patchHandle);
        if (android::uirenderer::ResourceCache::hasInstance()) {
            Res_png_9patch* p = (Res_png_9patch*) patch;
            android::uirenderer::ResourceCache::getInstance().destructor(p);
        } else {
        delete[] patch;
    }
    }

    static jlong getTransparentRegion(JNIEnv* env, jobject, jobject jbitmap,
            jlong chunkHandle, jobject dstRect) {
+0 −7
Original line number Diff line number Diff line
@@ -202,9 +202,7 @@ cc_defaults {
        "AnimationContext.cpp",
        "Animator.cpp",
        "AnimatorManager.cpp",
        "CanvasState.cpp",
        "CanvasTransform.cpp",
        "ClipArea.cpp",
        "DamageAccumulator.cpp",
        "DeferredLayerUpdater.cpp",
        "DeviceInfo.cpp",
@@ -227,9 +225,7 @@ cc_defaults {
        "RecordingCanvas.cpp",
        "RenderNode.cpp",
        "RenderProperties.cpp",
        "ResourceCache.cpp",
        "SkiaCanvas.cpp",
        "Snapshot.cpp",
        "TreeInfo.cpp",
        "VectorDrawable.cpp",
        "protos/graphicsstats.proto",
@@ -308,8 +304,6 @@ cc_test {
        "tests/unit/main.cpp",
        "tests/unit/CacheManagerTests.cpp",
        "tests/unit/CanvasContextTests.cpp",
        "tests/unit/CanvasStateTests.cpp",
        "tests/unit/ClipAreaTests.cpp",
        "tests/unit/DamageAccumulatorTests.cpp",
        "tests/unit/DeferredLayerUpdaterTests.cpp",
        "tests/unit/FatVectorTests.cpp",
@@ -328,7 +322,6 @@ cc_test {
        "tests/unit/SkiaPipelineTests.cpp",
        "tests/unit/SkiaRenderPropertiesTests.cpp",
        "tests/unit/SkiaCanvasTests.cpp",
        "tests/unit/SnapshotTests.cpp",
        "tests/unit/StringUtilsTests.cpp",
        "tests/unit/TestUtilsTests.cpp",
        "tests/unit/ThreadBaseTests.cpp",

libs/hwui/CanvasState.cpp

deleted100644 → 0
+0 −284
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "CanvasState.h"
#include "hwui/Canvas.h"
#include "utils/MathUtils.h"

namespace android {
namespace uirenderer {

CanvasState::CanvasState(CanvasStateClient& renderer)
        : mWidth(-1), mHeight(-1), mSaveCount(1), mCanvas(renderer), mSnapshot(&mFirstSnapshot) {}

CanvasState::~CanvasState() {
    // First call freeSnapshot on all but mFirstSnapshot
    // to invoke all the dtors
    freeAllSnapshots();

    // Now actually release the memory
    while (mSnapshotPool) {
        void* temp = mSnapshotPool;
        mSnapshotPool = mSnapshotPool->previous;
        free(temp);
    }
}

void CanvasState::initializeRecordingSaveStack(int viewportWidth, int viewportHeight) {
    if (mWidth != viewportWidth || mHeight != viewportHeight) {
        mWidth = viewportWidth;
        mHeight = viewportHeight;
        mFirstSnapshot.initializeViewport(viewportWidth, viewportHeight);
        mCanvas.onViewportInitialized();
    }

    freeAllSnapshots();
    mSnapshot = allocSnapshot(&mFirstSnapshot, SaveFlags::MatrixClip);
    mSnapshot->setRelativeLightCenter(Vector3());
    mSaveCount = 1;
}

void CanvasState::initializeSaveStack(int viewportWidth, int viewportHeight, float clipLeft,
                                      float clipTop, float clipRight, float clipBottom,
                                      const Vector3& lightCenter) {
    if (mWidth != viewportWidth || mHeight != viewportHeight) {
        mWidth = viewportWidth;
        mHeight = viewportHeight;
        mFirstSnapshot.initializeViewport(viewportWidth, viewportHeight);
        mCanvas.onViewportInitialized();
    }

    freeAllSnapshots();
    mSnapshot = allocSnapshot(&mFirstSnapshot, SaveFlags::MatrixClip);
    mSnapshot->setClip(clipLeft, clipTop, clipRight, clipBottom);
    mSnapshot->fbo = mCanvas.getTargetFbo();
    mSnapshot->setRelativeLightCenter(lightCenter);
    mSaveCount = 1;
}

Snapshot* CanvasState::allocSnapshot(Snapshot* previous, int savecount) {
    void* memory;
    if (mSnapshotPool) {
        memory = mSnapshotPool;
        mSnapshotPool = mSnapshotPool->previous;
        mSnapshotPoolCount--;
    } else {
        memory = malloc(sizeof(Snapshot));
    }
    return new (memory) Snapshot(previous, savecount);
}

void CanvasState::freeSnapshot(Snapshot* snapshot) {
    snapshot->~Snapshot();
    // Arbitrary number, just don't let this grown unbounded
    if (mSnapshotPoolCount > 10) {
        free((void*)snapshot);
    } else {
        snapshot->previous = mSnapshotPool;
        mSnapshotPool = snapshot;
        mSnapshotPoolCount++;
    }
}

void CanvasState::freeAllSnapshots() {
    while (mSnapshot != &mFirstSnapshot) {
        Snapshot* temp = mSnapshot;
        mSnapshot = mSnapshot->previous;
        freeSnapshot(temp);
    }
}

///////////////////////////////////////////////////////////////////////////////
// Save (layer)
///////////////////////////////////////////////////////////////////////////////

/**
 * Guaranteed to save without side-effects
 *
 * This approach, here and in restoreSnapshot(), allows subclasses to directly manipulate the save
 * stack, and ensures restoreToCount() doesn't call back into subclass overrides.
 */
int CanvasState::saveSnapshot(int flags) {
    mSnapshot = allocSnapshot(mSnapshot, flags);
    return mSaveCount++;
}

int CanvasState::save(int flags) {
    return saveSnapshot(flags);
}

/**
 * Guaranteed to restore without side-effects.
 */
void CanvasState::restoreSnapshot() {
    Snapshot* toRemove = mSnapshot;
    Snapshot* toRestore = mSnapshot->previous;

    mSaveCount--;
    mSnapshot = toRestore;

    // subclass handles restore implementation
    mCanvas.onSnapshotRestored(*toRemove, *toRestore);

    freeSnapshot(toRemove);
}

void CanvasState::restore() {
    if (mSaveCount > 1) {
        restoreSnapshot();
    }
}

void CanvasState::restoreToCount(int saveCount) {
    if (saveCount < 1) saveCount = 1;

    while (mSaveCount > saveCount) {
        restoreSnapshot();
    }
}

///////////////////////////////////////////////////////////////////////////////
// Matrix
///////////////////////////////////////////////////////////////////////////////

void CanvasState::getMatrix(SkMatrix* matrix) const {
    mSnapshot->transform->copyTo(*matrix);
}

void CanvasState::translate(float dx, float dy, float dz) {
    mSnapshot->transform->translate(dx, dy, dz);
}

void CanvasState::rotate(float degrees) {
    mSnapshot->transform->rotate(degrees, 0.0f, 0.0f, 1.0f);
}

void CanvasState::scale(float sx, float sy) {
    mSnapshot->transform->scale(sx, sy, 1.0f);
}

void CanvasState::skew(float sx, float sy) {
    mSnapshot->transform->skew(sx, sy);
}

void CanvasState::setMatrix(const SkMatrix& matrix) {
    mSnapshot->transform->load(matrix);
}

void CanvasState::setMatrix(const Matrix4& matrix) {
    *(mSnapshot->transform) = matrix;
}

void CanvasState::concatMatrix(const SkMatrix& matrix) {
    mat4 transform(matrix);
    mSnapshot->transform->multiply(transform);
}

void CanvasState::concatMatrix(const Matrix4& matrix) {
    mSnapshot->transform->multiply(matrix);
}

///////////////////////////////////////////////////////////////////////////////
// Clip
///////////////////////////////////////////////////////////////////////////////

bool CanvasState::clipRect(float left, float top, float right, float bottom, SkClipOp op) {
    mSnapshot->clip(Rect(left, top, right, bottom), op);
    return !mSnapshot->clipIsEmpty();
}

bool CanvasState::clipPath(const SkPath* path, SkClipOp op) {
    mSnapshot->clipPath(*path, op);
    return !mSnapshot->clipIsEmpty();
}

void CanvasState::setClippingOutline(LinearAllocator& allocator, const Outline* outline) {
    Rect bounds;
    float radius;
    if (!outline->getAsRoundRect(&bounds, &radius)) return;  // only RR supported

    bool outlineIsRounded = MathUtils::isPositive(radius);
    if (!outlineIsRounded || currentTransform()->isSimple()) {
        // TODO: consider storing this rect separately, so that this can't be replaced with clip ops
        clipRect(bounds.left, bounds.top, bounds.right, bounds.bottom, SkClipOp::kIntersect);
    }
    if (outlineIsRounded) {
        setClippingRoundRect(allocator, bounds, radius, false);
    }
}

///////////////////////////////////////////////////////////////////////////////
// Quick Rejection
///////////////////////////////////////////////////////////////////////////////

/**
 * Calculates whether content drawn within the passed bounds would be outside of, or intersect with
 * the clipRect. Does not modify the scissor.
 *
 * @param clipRequired if not null, will be set to true if element intersects clip
 *         (and wasn't rejected)
 *
 * @param snapOut if set, the geometry will be treated as having an AA ramp.
 *         See Rect::snapGeometryToPixelBoundaries()
 */
bool CanvasState::calculateQuickRejectForScissor(float left, float top, float right, float bottom,
                                                 bool* clipRequired, bool* roundRectClipRequired,
                                                 bool snapOut) const {
    if (bottom <= top || right <= left) {
        return true;
    }

    Rect r(left, top, right, bottom);
    currentTransform()->mapRect(r);
    r.snapGeometryToPixelBoundaries(snapOut);

    Rect clipRect(currentRenderTargetClip());
    clipRect.snapToPixelBoundaries();

    if (!clipRect.intersects(r)) return true;

    // clip is required if geometry intersects clip rect
    if (clipRequired) {
        *clipRequired = !clipRect.contains(r);
    }

    // round rect clip is required if RR clip exists, and geometry intersects its corners
    if (roundRectClipRequired) {
        *roundRectClipRequired = mSnapshot->roundRectClipState != nullptr &&
                                 mSnapshot->roundRectClipState->areaRequiresRoundRectClip(r);
    }
    return false;
}

bool CanvasState::quickRejectConservative(float left, float top, float right, float bottom) const {
    if (bottom <= top || right <= left) {
        return true;
    }

    Rect r(left, top, right, bottom);
    currentTransform()->mapRect(r);
    r.roundOut();  // rounded out to be conservative

    Rect clipRect(currentRenderTargetClip());
    clipRect.snapToPixelBoundaries();

    if (!clipRect.intersects(r)) return true;

    return false;
}

}  // namespace uirenderer
}  // namespace android

libs/hwui/CanvasState.h

deleted100644 → 0
+0 −195
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "Snapshot.h"

#include <SkClipOp.h>
#include <SkMatrix.h>
#include <SkPath.h>
#include <SkRegion.h>

namespace android {
namespace uirenderer {

/**
 * Abstract base class for any class containing CanvasState.
 * Defines three mandatory callbacks.
 */
class CanvasStateClient {
public:
    CanvasStateClient() {}
    virtual ~CanvasStateClient() {}

    /**
     * Callback allowing embedder to take actions in the middle of a
     * setViewport() call.
     */
    virtual void onViewportInitialized() = 0;

    /**
     * Callback allowing embedder to take actions in the middle of a
     * restore() call.  May be called several times sequentially.
     */
    virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) = 0;

    /**
     * Allows subclasses to control what value is stored in snapshot's
     * fbo field in * initializeSaveStack.
     */
    virtual GLuint getTargetFbo() const = 0;

};  // class CanvasStateClient

/**
 * Implements Canvas state methods on behalf of Renderers.
 *
 * Manages the Snapshot stack, implementing matrix, save/restore, and clipping methods in the
 * Renderer interface. Drawing and recording classes that include a CanvasState will have
 * different use cases:
 *
 * Drawing code maintaining canvas state (e.g. FrameBuilder) can query attributes (such as
 * transform) or hook into changes (e.g. save/restore) with minimal surface area for manipulating
 * the stack itself.
 *
 * Recording code maintaining canvas state (e.g. RecordingCanvas) can both record and pass
 * through state operations to CanvasState, so that not only will querying operations work
 * (getClip/Matrix), but so that quickRejection can also be used.
 */

class CanvasState {
public:
    explicit CanvasState(CanvasStateClient& renderer);
    ~CanvasState();

    /**
     * Initializes the first snapshot, computing the projection matrix,
     * and stores the dimensions of the render target.
     */
    void initializeRecordingSaveStack(int viewportWidth, int viewportHeight);

    /**
     * Initializes the first snapshot, computing the projection matrix,
     * and stores the dimensions of the render target.
     */
    void initializeSaveStack(int viewportWidth, int viewportHeight, float clipLeft, float clipTop,
                             float clipRight, float clipBottom, const Vector3& lightCenter);

    bool hasRectToRectTransform() const { return CC_LIKELY(currentTransform()->rectToRect()); }

    // Save (layer)
    int getSaveCount() const { return mSaveCount; }
    int save(int flags);
    void restore();
    void restoreToCount(int saveCount);

    // Save/Restore without side-effects
    int saveSnapshot(int flags);
    void restoreSnapshot();

    // Matrix
    void getMatrix(SkMatrix* outMatrix) const;
    void translate(float dx, float dy, float dz = 0.0f);
    void rotate(float degrees);
    void scale(float sx, float sy);
    void skew(float sx, float sy);

    void setMatrix(const SkMatrix& matrix);
    void setMatrix(const Matrix4& matrix);  // internal only convenience method
    void concatMatrix(const SkMatrix& matrix);
    void concatMatrix(const Matrix4& matrix);  // internal only convenience method

    // Clip
    const Rect& getLocalClipBounds() const { return mSnapshot->getLocalClip(); }
    const Rect& getRenderTargetClipBounds() const { return mSnapshot->getRenderTargetClip(); }

    bool quickRejectConservative(float left, float top, float right, float bottom) const;

    bool clipRect(float left, float top, float right, float bottom, SkClipOp op);
    bool clipPath(const SkPath* path, SkClipOp op);

    /**
     * Sets a "clipping outline", which is independent from the regular clip.
     * Currently only supports rectangles or rounded rectangles; passing in a
     * more complicated outline fails silently. Replaces any previous clipping
     * outline.
     */
    void setClippingOutline(LinearAllocator& allocator, const Outline* outline);
    void setClippingRoundRect(LinearAllocator& allocator, const Rect& rect, float radius,
                              bool highPriority = true) {
        mSnapshot->setClippingRoundRect(allocator, rect, radius, highPriority);
    }
    void setProjectionPathMask(const SkPath* path) { mSnapshot->setProjectionPathMask(path); }

    /**
     * Returns true if drawing in the rectangle (left, top, right, bottom)
     * will be clipped out. Is conservative: might return false when subpixel-
     * perfect tests would return true.
     */
    bool calculateQuickRejectForScissor(float left, float top, float right, float bottom,
                                        bool* clipRequired, bool* roundRectClipRequired,
                                        bool snapOut) const;

    void scaleAlpha(float alpha) { mSnapshot->alpha *= alpha; }

    inline const mat4* currentTransform() const { return currentSnapshot()->transform; }
    inline const Rect& currentRenderTargetClip() const {
        return currentSnapshot()->getRenderTargetClip();
    }
    inline int currentFlags() const { return currentSnapshot()->flags; }
    const Vector3& currentLightCenter() const {
        return currentSnapshot()->getRelativeLightCenter();
    }
    int getViewportWidth() const { return currentSnapshot()->getViewportWidth(); }
    int getViewportHeight() const { return currentSnapshot()->getViewportHeight(); }
    int getWidth() const { return mWidth; }
    int getHeight() const { return mHeight; }
    bool clipIsSimple() const { return currentSnapshot()->clipIsSimple(); }

    inline const Snapshot* currentSnapshot() const { return mSnapshot; }
    inline Snapshot* writableSnapshot() { return mSnapshot; }
    inline const Snapshot* firstSnapshot() const { return &mFirstSnapshot; }

private:
    Snapshot* allocSnapshot(Snapshot* previous, int savecount);
    void freeSnapshot(Snapshot* snapshot);
    void freeAllSnapshots();

    /// Dimensions of the drawing surface
    int mWidth, mHeight;

    /// Number of saved states
    int mSaveCount;

    /// Base state
    Snapshot mFirstSnapshot;

    /// Host providing callbacks
    CanvasStateClient& mCanvas;

    /// Current state
    Snapshot* mSnapshot;

    // Pool of allocated snapshots to re-use
    // NOTE: The dtors have already been invoked!
    Snapshot* mSnapshotPool = nullptr;
    int mSnapshotPoolCount = 0;

};  // class CanvasState

};  // namespace uirenderer
};  // namespace android

libs/hwui/ClipArea.cpp

deleted100644 → 0
+0 −534

File deleted.

Preview size limit exceeded, changes collapsed.

Loading