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

Commit 7cf75f0b authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge "Add stretch plumbing" into sc-dev

parents fa00d329 5cb290bf
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -21370,6 +21370,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            int height = mBottom - mTop;
            int layerType = getLayerType();
            // Hacky hack: Reset any stretch effects as those are applied during the draw pass
            // instead of being "stateful" like other RenderNode properties
            renderNode.clearStretch();
            final RecordingCanvas canvas = renderNode.beginRecording(width, height);
            try {
@@ -22796,6 +22800,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        final Rect bounds = drawable.getBounds();
        final int width = bounds.width();
        final int height = bounds.height();
        // Hacky hack: Reset any stretch effects as those are applied during the draw pass
        // instead of being "stateful" like other RenderNode properties
        renderNode.clearStretch();
        final RecordingCanvas canvas = renderNode.beginRecording(width, height);
        // Reverse left/top translation done by drawable canvas, which will
+33 −0
Original line number Diff line number Diff line
@@ -693,6 +693,32 @@ public final class RenderNode {
        throw new IllegalArgumentException("Unrecognized outline?");
    }

    /** @hide */
    public boolean clearStretch() {
        return nClearStretch(mNativeRenderNode);
    }

    /** @hide */
    public boolean stretch(float left, float top, float right, float bottom,
            float vecX, float vecY, float maxStretchAmount) {
        if (1.0 < vecX || vecX < -1.0) {
            throw new IllegalArgumentException("vecX must be in the range [-1, 1], was " + vecX);
        }
        if (1.0 < vecY || vecY < -1.0) {
            throw new IllegalArgumentException("vecY must be in the range [-1, 1], was " + vecY);
        }
        if (top <= bottom || right <= left) {
            throw new IllegalArgumentException(
                    "Stretch region must not be empty, got "
                            + new RectF(left, top, right, bottom).toString());
        }
        if (maxStretchAmount <= 0.0f) {
            throw new IllegalArgumentException(
                    "The max stretch amount must be >0, got " + maxStretchAmount);
        }
        return nStretch(mNativeRenderNode, left, top, right, bottom, vecX, vecY, maxStretchAmount);
    }

    /**
     * Checks if the RenderNode has a shadow. That is, if the combination of {@link #getElevation()}
     * and {@link #getTranslationZ()} is greater than zero, there is an {@link Outline} set with
@@ -1637,6 +1663,13 @@ public final class RenderNode {
    @CriticalNative
    private static native boolean nSetOutlineNone(long renderNode);

    @CriticalNative
    private static native boolean nClearStretch(long renderNode);

    @CriticalNative
    private static native boolean nStretch(long renderNode, float left, float top, float right,
            float bottom, float vecX, float vecY, float maxStretch);

    @CriticalNative
    private static native boolean nHasShadow(long renderNode);

+1 −0
Original line number Diff line number Diff line
@@ -435,6 +435,7 @@ cc_defaults {
        "canvas/CanvasFrontend.cpp",
        "canvas/CanvasOpBuffer.cpp",
        "canvas/CanvasOpRasterizer.cpp",
        "effects/StretchEffect.cpp",
        "pipeline/skia/SkiaDisplayList.cpp",
        "pipeline/skia/SkiaRecordingCanvas.cpp",
        "pipeline/skia/RenderNodeDrawable.cpp",
+6 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include "Outline.h"
#include "Rect.h"
#include "RevealClip.h"
#include "effects/StretchEffect.h"
#include "utils/MathUtils.h"
#include "utils/PaintUtils.h"

@@ -98,6 +99,10 @@ public:

    SkImageFilter* getImageFilter() const { return mImageFilter.get(); }

    const StretchEffect& getStretchEffect() const { return mStretchEffect; }

    StretchEffect& mutableStretchEffect() { return mStretchEffect; }

    // Sets alpha, xfermode, and colorfilter from an SkPaint
    // paint may be NULL, in which case defaults will be set
    bool setFromPaint(const SkPaint* paint);
@@ -124,6 +129,7 @@ private:
    SkBlendMode mMode;
    sk_sp<SkColorFilter> mColorFilter;
    sk_sp<SkImageFilter> mImageFilter;
    StretchEffect mStretchEffect;
};

/*
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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 "StretchEffect.h"

namespace android::uirenderer {

sk_sp<SkImageFilter> StretchEffect::getImageFilter() const {
    // TODO: Implement & Cache
    // Probably need to use mutable to achieve caching
    return nullptr;
}

} // namespace android::uirenderer
 No newline at end of file
Loading