Loading core/java/android/view/View.java +9 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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 graphics/java/android/graphics/RenderNode.java +33 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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); Loading libs/hwui/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -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", Loading libs/hwui/RenderProperties.h +6 −0 Original line number Diff line number Diff line Loading @@ -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" Loading Loading @@ -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); Loading @@ -124,6 +129,7 @@ private: SkBlendMode mMode; sk_sp<SkColorFilter> mColorFilter; sk_sp<SkImageFilter> mImageFilter; StretchEffect mStretchEffect; }; /* Loading libs/hwui/effects/StretchEffect.cpp 0 → 100644 +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
core/java/android/view/View.java +9 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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
graphics/java/android/graphics/RenderNode.java +33 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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); Loading
libs/hwui/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -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", Loading
libs/hwui/RenderProperties.h +6 −0 Original line number Diff line number Diff line Loading @@ -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" Loading Loading @@ -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); Loading @@ -124,6 +129,7 @@ private: SkBlendMode mMode; sk_sp<SkColorFilter> mColorFilter; sk_sp<SkImageFilter> mImageFilter; StretchEffect mStretchEffect; }; /* Loading
libs/hwui/effects/StretchEffect.cpp 0 → 100644 +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