diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index 964640b106b97..28d7911c771ff 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -3111,7 +3111,7 @@ public class Paint { @CriticalNative private static native boolean nGetFillPath(long paintPtr, long src, long dst); @CriticalNative - private static native void nSetShader(long paintPtr, long shader); + private static native long nSetShader(long paintPtr, long shader); @CriticalNative private static native long nSetColorFilter(long paintPtr, long filter); @CriticalNative diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp index 975265e4add54..155bb6ba8f75f 100644 --- a/libs/hwui/Android.bp +++ b/libs/hwui/Android.bp @@ -464,14 +464,6 @@ cc_defaults { "RenderNode.cpp", "RenderProperties.cpp", "RootRenderNode.cpp", - "shader/Shader.cpp", - "shader/BitmapShader.cpp", - "shader/BlurShader.cpp", - "shader/ComposeShader.cpp", - "shader/LinearGradientShader.cpp", - "shader/RadialGradientShader.cpp", - "shader/RuntimeShader.cpp", - "shader/SweepGradientShader.cpp", "SkiaCanvas.cpp", "VectorDrawable.cpp", ], diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index a690840e91a92..1dbce58fb7c98 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -42,8 +42,6 @@ #include #include -#include - #include #include #include @@ -51,7 +49,6 @@ namespace android { using uirenderer::PaintUtils; -using uirenderer::BitmapShader; Canvas* Canvas::create_canvas(const SkBitmap& bitmap) { return new SkiaCanvas(bitmap); @@ -684,9 +681,7 @@ void SkiaCanvas::drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight, if (paint) { pnt = *paint; } - - pnt.setShader(sk_ref_sp(new BitmapShader( - bitmap.makeImage(), SkTileMode::kClamp, SkTileMode::kClamp, nullptr))); + pnt.setShader(bitmap.makeImage()->makeShader()); auto v = builder.detach(); apply_looper(&pnt, [&](const SkPaint& p) { mCanvas->drawVertices(v, SkBlendMode::kModulate, p); diff --git a/libs/hwui/VectorDrawable.cpp b/libs/hwui/VectorDrawable.cpp index 0f566e4b494a4..cd908354aea5f 100644 --- a/libs/hwui/VectorDrawable.cpp +++ b/libs/hwui/VectorDrawable.cpp @@ -23,6 +23,7 @@ #include "PathParser.h" #include "SkColorFilter.h" #include "SkImageInfo.h" +#include "SkShader.h" #include "hwui/Paint.h" #ifdef __ANDROID__ @@ -158,10 +159,10 @@ void FullPath::draw(SkCanvas* outCanvas, bool useStagingData) { // Draw path's fill, if fill color or gradient is valid bool needsFill = false; - Paint paint; + SkPaint paint; if (properties.getFillGradient() != nullptr) { paint.setColor(applyAlpha(SK_ColorBLACK, properties.getFillAlpha())); - paint.setShader(sk_sp(SkSafeRef(properties.getFillGradient()))); + paint.setShader(sk_sp(SkSafeRef(properties.getFillGradient()))); needsFill = true; } else if (properties.getFillColor() != SK_ColorTRANSPARENT) { paint.setColor(applyAlpha(properties.getFillColor(), properties.getFillAlpha())); @@ -178,7 +179,7 @@ void FullPath::draw(SkCanvas* outCanvas, bool useStagingData) { bool needsStroke = false; if (properties.getStrokeGradient() != nullptr) { paint.setColor(applyAlpha(SK_ColorBLACK, properties.getStrokeAlpha())); - paint.setShader(sk_sp(SkSafeRef(properties.getStrokeGradient()))); + paint.setShader(sk_sp(SkSafeRef(properties.getStrokeGradient()))); needsStroke = true; } else if (properties.getStrokeColor() != SK_ColorTRANSPARENT) { paint.setColor(applyAlpha(properties.getStrokeColor(), properties.getStrokeAlpha())); diff --git a/libs/hwui/VectorDrawable.h b/libs/hwui/VectorDrawable.h index d4086f1aa6229..ac7d41e0d600a 100644 --- a/libs/hwui/VectorDrawable.h +++ b/libs/hwui/VectorDrawable.h @@ -31,8 +31,8 @@ #include #include #include +#include #include -#include #include #include @@ -227,20 +227,20 @@ public: strokeGradient = prop.strokeGradient; onPropertyChanged(); } - void setFillGradient(Shader* gradient) { + void setFillGradient(SkShader* gradient) { if (fillGradient.get() != gradient) { fillGradient = sk_ref_sp(gradient); onPropertyChanged(); } } - void setStrokeGradient(Shader* gradient) { + void setStrokeGradient(SkShader* gradient) { if (strokeGradient.get() != gradient) { strokeGradient = sk_ref_sp(gradient); onPropertyChanged(); } } - Shader* getFillGradient() const { return fillGradient.get(); } - Shader* getStrokeGradient() const { return strokeGradient.get(); } + SkShader* getFillGradient() const { return fillGradient.get(); } + SkShader* getStrokeGradient() const { return strokeGradient.get(); } float getStrokeWidth() const { return mPrimitiveFields.strokeWidth; } void setStrokeWidth(float strokeWidth) { VD_SET_PRIMITIVE_FIELD_AND_NOTIFY(strokeWidth, strokeWidth); @@ -320,8 +320,8 @@ public: count, }; PrimitiveFields mPrimitiveFields; - sk_sp fillGradient; - sk_sp strokeGradient; + sk_sp fillGradient; + sk_sp strokeGradient; }; // Called from UI thread diff --git a/libs/hwui/hwui/Canvas.cpp b/libs/hwui/hwui/Canvas.cpp index 2001b5620f840..8df2770b01576 100644 --- a/libs/hwui/hwui/Canvas.cpp +++ b/libs/hwui/hwui/Canvas.cpp @@ -73,7 +73,7 @@ void Canvas::drawTextDecorations(float x, float y, float length, const Paint& pa static void simplifyPaint(int color, Paint* paint) { paint->setColor(color); - paint->setShader((sk_sp)nullptr); + paint->setShader(nullptr); paint->setColorFilter(nullptr); paint->setLooper(nullptr); paint->setStrokeWidth(4 + 0.04 * paint->getSkFont().getSize()); diff --git a/libs/hwui/hwui/Paint.h b/libs/hwui/hwui/Paint.h index 4e2016a41f5e6..e75e9e7c69334 100644 --- a/libs/hwui/hwui/Paint.h +++ b/libs/hwui/hwui/Paint.h @@ -30,8 +30,6 @@ #include #include -#include - namespace android { class Paint : public SkPaint { @@ -151,13 +149,8 @@ public: // The only respected flags are : [ antialias, dither, filterBitmap ] static uint32_t GetSkPaintJavaFlags(const SkPaint&); static void SetSkPaintJavaFlags(SkPaint*, uint32_t flags); - - void setShader(sk_sp shader); private: - - using SkPaint::setShader; - SkFont mFont; sk_sp mLooper; @@ -176,7 +169,6 @@ private: bool mStrikeThru = false; bool mUnderline = false; bool mDevKern = false; - sk_sp mShader; }; } // namespace android diff --git a/libs/hwui/hwui/PaintImpl.cpp b/libs/hwui/hwui/PaintImpl.cpp index 21f60fd7b671d..fa2674fc2f5e4 100644 --- a/libs/hwui/hwui/PaintImpl.cpp +++ b/libs/hwui/hwui/PaintImpl.cpp @@ -24,8 +24,7 @@ Paint::Paint() , mWordSpacing(0) , mFontFeatureSettings() , mMinikinLocaleListId(0) - , mFamilyVariant(minikin::FamilyVariant::DEFAULT) - , mShader(nullptr) { + , mFamilyVariant(minikin::FamilyVariant::DEFAULT) { // SkPaint::antialiasing defaults to false, but // SkFont::edging defaults to kAntiAlias. To keep them // insync, we manually set the font to kAilas. @@ -46,8 +45,7 @@ Paint::Paint(const Paint& paint) , mAlign(paint.mAlign) , mStrikeThru(paint.mStrikeThru) , mUnderline(paint.mUnderline) - , mDevKern(paint.mDevKern) - , mShader(paint.mShader){} + , mDevKern(paint.mDevKern) {} Paint::~Paint() {} @@ -67,30 +65,9 @@ Paint& Paint::operator=(const Paint& other) { mStrikeThru = other.mStrikeThru; mUnderline = other.mUnderline; mDevKern = other.mDevKern; - mShader = other.mShader; return *this; } -void Paint::setShader(sk_sp shader) { - if (shader) { - // If there is an SkShader compatible shader, apply it - sk_sp skShader = shader->asSkShader(); - if (skShader.get()) { - SkPaint::setShader(skShader); - SkPaint::setImageFilter(nullptr); - } else { - // ... otherwise the specified shader can only be represented as an ImageFilter - SkPaint::setShader(nullptr); - SkPaint::setImageFilter(shader->asSkImageFilter()); - } - } else { - // No shader is provided at all, clear out both the SkShader and SkImageFilter slots - SkPaint::setShader(nullptr); - SkPaint::setImageFilter(nullptr); - } - mShader = shader; -} - bool operator==(const Paint& a, const Paint& b) { return static_cast(a) == static_cast(b) && a.mFont == b.mFont && diff --git a/libs/hwui/jni/Paint.cpp b/libs/hwui/jni/Paint.cpp index f6c8496d84ca6..3c86b28262b03 100644 --- a/libs/hwui/jni/Paint.cpp +++ b/libs/hwui/jni/Paint.cpp @@ -47,7 +47,6 @@ #include #include #include -#include #include #include @@ -55,8 +54,6 @@ #include #include -using namespace android::uirenderer; - namespace android { static void getPosTextPath(const SkFont& font, const uint16_t glyphs[], int count, @@ -745,10 +742,11 @@ namespace PaintGlue { return obj->getFillPath(*src, dst) ? JNI_TRUE : JNI_FALSE; } - static void setShader(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jlong shaderHandle) { - auto* paint = reinterpret_cast(objHandle); - auto* shader = reinterpret_cast(shaderHandle); - paint->setShader(sk_ref_sp(shader)); + static jlong setShader(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jlong shaderHandle) { + Paint* obj = reinterpret_cast(objHandle); + SkShader* shader = reinterpret_cast(shaderHandle); + obj->setShader(sk_ref_sp(shader)); + return reinterpret_cast(obj->getShader()); } static jlong setColorFilter(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jlong filterHandle) { @@ -1059,7 +1057,7 @@ static const JNINativeMethod methods[] = { {"nGetStrokeJoin","(J)I", (void*) PaintGlue::getStrokeJoin}, {"nSetStrokeJoin","(JI)V", (void*) PaintGlue::setStrokeJoin}, {"nGetFillPath","(JJJ)Z", (void*) PaintGlue::getFillPath}, - {"nSetShader","(JJ)V", (void*) PaintGlue::setShader}, + {"nSetShader","(JJ)J", (void*) PaintGlue::setShader}, {"nSetColorFilter","(JJ)J", (void*) PaintGlue::setColorFilter}, {"nSetXfermode","(JI)V", (void*) PaintGlue::setXfermode}, {"nSetPathEffect","(JJ)J", (void*) PaintGlue::setPathEffect}, diff --git a/libs/hwui/jni/Shader.cpp b/libs/hwui/jni/Shader.cpp index 0a194f9dd666e..e76aace601be3 100644 --- a/libs/hwui/jni/Shader.cpp +++ b/libs/hwui/jni/Shader.cpp @@ -5,14 +5,6 @@ #include "SkShader.h" #include "SkBlendMode.h" #include "include/effects/SkRuntimeEffect.h" -#include "shader/Shader.h" -#include "shader/BitmapShader.h" -#include "shader/BlurShader.h" -#include "shader/ComposeShader.h" -#include "shader/LinearGradientShader.h" -#include "shader/RadialGradientShader.h" -#include "shader/RuntimeShader.h" -#include "shader/SweepGradientShader.h" #include @@ -58,7 +50,7 @@ static jint Color_HSVToColor(JNIEnv* env, jobject, jint alpha, jfloatArray hsvAr /////////////////////////////////////////////////////////////////////////////////////////////// -static void Shader_safeUnref(Shader* shader) { +static void Shader_safeUnref(SkShader* shader) { SkSafeUnref(shader); } @@ -82,15 +74,15 @@ static jlong BitmapShader_constructor(JNIEnv* env, jobject o, jlong matrixPtr, j SkBitmap bitmap; image = SkMakeImageFromRasterBitmap(bitmap, kNever_SkCopyPixelsMode); } + sk_sp shader = image->makeShader( + (SkTileMode)tileModeX, (SkTileMode)tileModeY); + ThrowIAE_IfNull(env, shader.get()); - auto* shader = new BitmapShader( - image, - static_cast(tileModeX), - static_cast(tileModeY), - matrix - ); + if (matrix) { + shader = shader->makeWithLocalMatrix(*matrix); + } - return reinterpret_cast(shader); + return reinterpret_cast(shader.release()); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -126,18 +118,17 @@ static jlong LinearGradient_create(JNIEnv* env, jobject, jlong matrixPtr, #error Need to convert float array to SkScalar array before calling the following function. #endif - auto* matrix = reinterpret_cast(matrixPtr); - auto* shader = new LinearGradientShader( - pts, - colors, - GraphicsJNI::getNativeColorSpace(colorSpaceHandle), - pos, - static_cast(tileMode), - sGradientShaderFlags, - matrix - ); + sk_sp shader(SkGradientShader::MakeLinear(pts, &colors[0], + GraphicsJNI::getNativeColorSpace(colorSpaceHandle), pos, colors.size(), + static_cast(tileMode), sGradientShaderFlags, nullptr)); + ThrowIAE_IfNull(env, shader); - return reinterpret_cast(shader); + const SkMatrix* matrix = reinterpret_cast(matrixPtr); + if (matrix) { + shader = shader->makeWithLocalMatrix(*matrix); + } + + return reinterpret_cast(shader.release()); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -157,20 +148,17 @@ static jlong RadialGradient_create(JNIEnv* env, jobject, jlong matrixPtr, jfloat #error Need to convert float array to SkScalar array before calling the following function. #endif - auto* matrix = reinterpret_cast(matrixPtr); + sk_sp shader = SkGradientShader::MakeRadial(center, radius, &colors[0], + GraphicsJNI::getNativeColorSpace(colorSpaceHandle), pos, colors.size(), + static_cast(tileMode), sGradientShaderFlags, nullptr); + ThrowIAE_IfNull(env, shader); - auto* shader = new RadialGradientShader( - center, - radius, - colors, - GraphicsJNI::getNativeColorSpace(colorSpaceHandle), - pos, - static_cast(tileMode), - sGradientShaderFlags, - matrix - ); + const SkMatrix* matrix = reinterpret_cast(matrixPtr); + if (matrix) { + shader = shader->makeWithLocalMatrix(*matrix); + } - return reinterpret_cast(shader); + return reinterpret_cast(shader.release()); } /////////////////////////////////////////////////////////////////////////////// @@ -186,75 +174,54 @@ static jlong SweepGradient_create(JNIEnv* env, jobject, jlong matrixPtr, jfloat #error Need to convert float array to SkScalar array before calling the following function. #endif - auto* matrix = reinterpret_cast(matrixPtr); + sk_sp shader = SkGradientShader::MakeSweep(x, y, &colors[0], + GraphicsJNI::getNativeColorSpace(colorSpaceHandle), pos, colors.size(), + sGradientShaderFlags, nullptr); + ThrowIAE_IfNull(env, shader); - auto* shader = new SweepGradientShader( - x, - y, - colors, - GraphicsJNI::getNativeColorSpace(colorSpaceHandle), - pos, - sGradientShaderFlags, - matrix - ); + const SkMatrix* matrix = reinterpret_cast(matrixPtr); + if (matrix) { + shader = shader->makeWithLocalMatrix(*matrix); + } - return reinterpret_cast(shader); + return reinterpret_cast(shader.release()); } /////////////////////////////////////////////////////////////////////////////////////////////// static jlong ComposeShader_create(JNIEnv* env, jobject o, jlong matrixPtr, jlong shaderAHandle, jlong shaderBHandle, jint xfermodeHandle) { - auto* matrix = reinterpret_cast(matrixPtr); - auto* shaderA = reinterpret_cast(shaderAHandle); - auto* shaderB = reinterpret_cast(shaderBHandle); + const SkMatrix* matrix = reinterpret_cast(matrixPtr); + SkShader* shaderA = reinterpret_cast(shaderAHandle); + SkShader* shaderB = reinterpret_cast(shaderBHandle); + SkBlendMode mode = static_cast(xfermodeHandle); + sk_sp baseShader(SkShaders::Blend(mode, + sk_ref_sp(shaderA), sk_ref_sp(shaderB))); - auto mode = static_cast(xfermodeHandle); + SkShader* shader; - auto* composeShader = new ComposeShader( - *shaderA, - *shaderB, - mode, - matrix - ); - - return reinterpret_cast(composeShader); -} - -/////////////////////////////////////////////////////////////////////////////////////////////// - -static jlong BlurShader_create(JNIEnv* env , jobject o, jlong matrixPtr, jfloat sigmaX, - jfloat sigmaY, jlong shaderHandle, jint edgeTreatment) { - auto* matrix = reinterpret_cast(matrixPtr); - auto* inputShader = reinterpret_cast(shaderHandle); - - auto* blurShader = new BlurShader( - sigmaX, - sigmaY, - inputShader, - static_cast(edgeTreatment), - matrix - ); - return reinterpret_cast(blurShader); + if (matrix) { + shader = baseShader->makeWithLocalMatrix(*matrix).release(); + } else { + shader = baseShader.release(); + } + return reinterpret_cast(shader); } /////////////////////////////////////////////////////////////////////////////////////////////// static jlong RuntimeShader_create(JNIEnv* env, jobject, jlong shaderFactory, jlong matrixPtr, jbyteArray inputs, jlong colorSpaceHandle, jboolean isOpaque) { - auto* effect = reinterpret_cast(shaderFactory); + SkRuntimeEffect* effect = reinterpret_cast(shaderFactory); AutoJavaByteArray arInputs(env, inputs); - auto data = SkData::MakeWithCopy(arInputs.ptr(), arInputs.length()); - auto* matrix = reinterpret_cast(matrixPtr); + sk_sp fData; + fData = SkData::MakeWithCopy(arInputs.ptr(), arInputs.length()); + const SkMatrix* matrix = reinterpret_cast(matrixPtr); + sk_sp shader = effect->makeShader(fData, nullptr, 0, matrix, isOpaque == JNI_TRUE); + ThrowIAE_IfNull(env, shader); - auto* shader = new RuntimeShader( - *effect, - std::move(data), - isOpaque == JNI_TRUE, - matrix - ); - return reinterpret_cast(shader); + return reinterpret_cast(shader.release()); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -272,8 +239,12 @@ static jlong RuntimeShader_createShaderFactory(JNIEnv* env, jobject, jstring sks /////////////////////////////////////////////////////////////////////////////////////////////// +static void Effect_safeUnref(SkRuntimeEffect* effect) { + SkSafeUnref(effect); +} + static jlong RuntimeShader_getNativeFinalizer(JNIEnv*, jobject) { - return static_cast(reinterpret_cast(&Shader_safeUnref)); + return static_cast(reinterpret_cast(&Effect_safeUnref)); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -291,10 +262,6 @@ static const JNINativeMethod gBitmapShaderMethods[] = { { "nativeCreate", "(JJII)J", (void*)BitmapShader_constructor }, }; -static const JNINativeMethod gBlurShaderMethods[] = { - { "nativeCreate", "(JFFJI)J", (void*)BlurShader_create } -}; - static const JNINativeMethod gLinearGradientMethods[] = { { "nativeCreate", "(JFFFF[J[FIJ)J", (void*)LinearGradient_create }, }; @@ -326,8 +293,6 @@ int register_android_graphics_Shader(JNIEnv* env) NELEM(gShaderMethods)); android::RegisterMethodsOrDie(env, "android/graphics/BitmapShader", gBitmapShaderMethods, NELEM(gBitmapShaderMethods)); - android::RegisterMethodsOrDie(env, "android/graphics/BlurShader", gBlurShaderMethods, - NELEM(gBlurShaderMethods)); android::RegisterMethodsOrDie(env, "android/graphics/LinearGradient", gLinearGradientMethods, NELEM(gLinearGradientMethods)); android::RegisterMethodsOrDie(env, "android/graphics/RadialGradient", gRadialGradientMethods, diff --git a/libs/hwui/jni/android_graphics_drawable_VectorDrawable.cpp b/libs/hwui/jni/android_graphics_drawable_VectorDrawable.cpp index a1adcb30e80d9..9cffceb308c84 100644 --- a/libs/hwui/jni/android_graphics_drawable_VectorDrawable.cpp +++ b/libs/hwui/jni/android_graphics_drawable_VectorDrawable.cpp @@ -143,13 +143,13 @@ static void updateFullPathPropertiesAndStrokeStyles(JNIEnv*, jobject, jlong full static void updateFullPathFillGradient(JNIEnv*, jobject, jlong pathPtr, jlong fillGradientPtr) { VectorDrawable::FullPath* path = reinterpret_cast(pathPtr); - auto* fillShader = reinterpret_cast(fillGradientPtr); + SkShader* fillShader = reinterpret_cast(fillGradientPtr); path->mutateStagingProperties()->setFillGradient(fillShader); } static void updateFullPathStrokeGradient(JNIEnv*, jobject, jlong pathPtr, jlong strokeGradientPtr) { VectorDrawable::FullPath* path = reinterpret_cast(pathPtr); - auto* strokeShader = reinterpret_cast(strokeGradientPtr); + SkShader* strokeShader = reinterpret_cast(strokeGradientPtr); path->mutateStagingProperties()->setStrokeGradient(strokeShader); } diff --git a/libs/hwui/shader/BitmapShader.cpp b/libs/hwui/shader/BitmapShader.cpp deleted file mode 100644 index fe653e85a0218..0000000000000 --- a/libs/hwui/shader/BitmapShader.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2020 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 "BitmapShader.h" - -#include "SkImagePriv.h" - -namespace android::uirenderer { -BitmapShader::BitmapShader(const sk_sp& image, const SkTileMode tileModeX, - const SkTileMode tileModeY, const SkMatrix* matrix) - : Shader(matrix), skShader(image->makeShader(tileModeX, tileModeY)) {} - -sk_sp BitmapShader::makeSkShader() { - return skShader; -} - -BitmapShader::~BitmapShader() {} -} // namespace android::uirenderer \ No newline at end of file diff --git a/libs/hwui/shader/BitmapShader.h b/libs/hwui/shader/BitmapShader.h deleted file mode 100644 index ed6a6e6802d1c..0000000000000 --- a/libs/hwui/shader/BitmapShader.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2020 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 "Shader.h" -#include "SkShader.h" - -namespace android::uirenderer { - -/** - * Shader implementation that renders a Bitmap as either a SkShader or SkImageFilter - */ -class BitmapShader : public Shader { -public: - BitmapShader(const sk_sp& image, const SkTileMode tileModeX, - const SkTileMode tileModeY, const SkMatrix* matrix); - ~BitmapShader() override; - -protected: - sk_sp makeSkShader() override; - -private: - sk_sp skShader; -}; -} // namespace android::uirenderer \ No newline at end of file diff --git a/libs/hwui/shader/ComposeShader.cpp b/libs/hwui/shader/ComposeShader.cpp deleted file mode 100644 index 3765489e74313..0000000000000 --- a/libs/hwui/shader/ComposeShader.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2020 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 "ComposeShader.h" - -#include "SkImageFilters.h" -#include "SkShader.h" - -namespace android::uirenderer { - -ComposeShader::ComposeShader(Shader& shaderA, Shader& shaderB, const SkBlendMode blendMode, - const SkMatrix* matrix) - : Shader(matrix) { - // If both Shaders can be represented as SkShaders then use those, if not - // create an SkImageFilter from both Shaders and create the equivalent SkImageFilter - sk_sp skShaderA = shaderA.asSkShader(); - sk_sp skShaderB = shaderB.asSkShader(); - if (skShaderA.get() && skShaderB.get()) { - skShader = SkShaders::Blend(blendMode, skShaderA, skShaderB); - skImageFilter = nullptr; - } else { - sk_sp skImageFilterA = shaderA.asSkImageFilter(); - sk_sp skImageFilterB = shaderB.asSkImageFilter(); - skShader = nullptr; - skImageFilter = SkImageFilters::Xfermode(blendMode, skImageFilterA, skImageFilterB); - } -} - -sk_sp ComposeShader::makeSkShader() { - return skShader; -} - -sk_sp ComposeShader::makeSkImageFilter() { - return skImageFilter; -} - -ComposeShader::~ComposeShader() {} -} // namespace android::uirenderer diff --git a/libs/hwui/shader/ComposeShader.h b/libs/hwui/shader/ComposeShader.h deleted file mode 100644 index a246b520d46a3..0000000000000 --- a/libs/hwui/shader/ComposeShader.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2020 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 "Shader.h" -#include "SkShader.h" - -namespace android::uirenderer { - -/** - * Shader implementation that can composite 2 Shaders together with the specified blend mode. - * This implementation can appropriately convert the composed result to either an SkShader or - * SkImageFilter depending on the inputs - */ -class ComposeShader : public Shader { -public: - ComposeShader(Shader& shaderA, Shader& shaderB, const SkBlendMode blendMode, - const SkMatrix* matrix); - ~ComposeShader() override; - -protected: - sk_sp makeSkShader() override; - sk_sp makeSkImageFilter() override; - -private: - sk_sp skShader; - sk_sp skImageFilter; -}; -} // namespace android::uirenderer diff --git a/libs/hwui/shader/LinearGradientShader.cpp b/libs/hwui/shader/LinearGradientShader.cpp deleted file mode 100644 index 868fa44fb4b7f..0000000000000 --- a/libs/hwui/shader/LinearGradientShader.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2020 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 "LinearGradientShader.h" - -#include - -#include "SkGradientShader.h" - -namespace android::uirenderer { - -LinearGradientShader::LinearGradientShader(const SkPoint pts[2], - const std::vector& colors, - sk_sp colorspace, const SkScalar pos[], - const SkTileMode tileMode, const uint32_t shaderFlags, - const SkMatrix* matrix) - : Shader(matrix) - , skShader(SkGradientShader::MakeLinear(pts, colors.data(), colorspace, pos, colors.size(), - tileMode, shaderFlags, nullptr)) {} - -sk_sp LinearGradientShader::makeSkShader() { - return skShader; -} - -LinearGradientShader::~LinearGradientShader() {} -} // namespace android::uirenderer \ No newline at end of file diff --git a/libs/hwui/shader/LinearGradientShader.h b/libs/hwui/shader/LinearGradientShader.h deleted file mode 100644 index 596f4e009448f..0000000000000 --- a/libs/hwui/shader/LinearGradientShader.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2020 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 "Shader.h" -#include "SkShader.h" - -namespace android::uirenderer { - -/** - * Shader implementation that renders a color ramp of colors to either as either SkShader or - * SkImageFilter - */ -class LinearGradientShader : public Shader { -public: - LinearGradientShader(const SkPoint pts[2], const std::vector& colors, - sk_sp colorspace, const SkScalar pos[], - const SkTileMode tileMode, const uint32_t shaderFlags, - const SkMatrix* matrix); - ~LinearGradientShader() override; - -protected: - sk_sp makeSkShader() override; - -private: - sk_sp skShader; -}; -} // namespace android::uirenderer diff --git a/libs/hwui/shader/RadialGradientShader.cpp b/libs/hwui/shader/RadialGradientShader.cpp deleted file mode 100644 index 21ff56fee2f8f..0000000000000 --- a/libs/hwui/shader/RadialGradientShader.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2020 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 "RadialGradientShader.h" - -#include - -#include "SkGradientShader.h" - -namespace android::uirenderer { - -RadialGradientShader::RadialGradientShader(const SkPoint& center, const float radius, - const std::vector& colors, - sk_sp colorspace, const SkScalar pos[], - const SkTileMode tileMode, const uint32_t shaderFlags, - const SkMatrix* matrix) - : Shader(matrix) - , skShader(SkGradientShader::MakeRadial(center, radius, colors.data(), colorspace, pos, - colors.size(), tileMode, shaderFlags, nullptr)) {} - -sk_sp RadialGradientShader::makeSkShader() { - return skShader; -} - -RadialGradientShader::~RadialGradientShader() {} -} // namespace android::uirenderer \ No newline at end of file diff --git a/libs/hwui/shader/RadialGradientShader.h b/libs/hwui/shader/RadialGradientShader.h deleted file mode 100644 index 9a2ff139aedb2..0000000000000 --- a/libs/hwui/shader/RadialGradientShader.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2020 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 "Shader.h" -#include "SkShader.h" - -namespace android::uirenderer { - -/** - * Shader implementation that renders a color ramp from the center outward to either as either - * a SkShader or SkImageFilter - */ -class RadialGradientShader : public Shader { -public: - RadialGradientShader(const SkPoint& center, const float radius, - const std::vector& colors, sk_sp colorSpace, - const SkScalar pos[], const SkTileMode tileMode, const uint32_t shaderFlags, - const SkMatrix* matrix); - ~RadialGradientShader() override; - -protected: - sk_sp makeSkShader() override; - -private: - sk_sp skShader; -}; -} // namespace android::uirenderer \ No newline at end of file diff --git a/libs/hwui/shader/RuntimeShader.cpp b/libs/hwui/shader/RuntimeShader.cpp deleted file mode 100644 index dd0b6980841a0..0000000000000 --- a/libs/hwui/shader/RuntimeShader.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2020 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 "RuntimeShader.h" - -#include "SkShader.h" -#include "include/effects/SkRuntimeEffect.h" - -namespace android::uirenderer { - -RuntimeShader::RuntimeShader(SkRuntimeEffect& effect, sk_sp data, bool isOpaque, - const SkMatrix* matrix) - : Shader(nullptr) - , // Explicitly passing null as RuntimeShader is created with the - // matrix directly - skShader(effect.makeShader(std::move(data), nullptr, 0, matrix, isOpaque)) {} - -sk_sp RuntimeShader::makeSkShader() { - return skShader; -} - -RuntimeShader::~RuntimeShader() {} -} // namespace android::uirenderer \ No newline at end of file diff --git a/libs/hwui/shader/RuntimeShader.h b/libs/hwui/shader/RuntimeShader.h deleted file mode 100644 index 7fe0b02064676..0000000000000 --- a/libs/hwui/shader/RuntimeShader.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2020 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 "Shader.h" -#include "SkShader.h" -#include "include/effects/SkRuntimeEffect.h" - -namespace android::uirenderer { - -/** - * RuntimeShader implementation that can map to either a SkShader or SkImageFilter - */ -class RuntimeShader : public Shader { -public: - RuntimeShader(SkRuntimeEffect& effect, sk_sp data, bool isOpaque, - const SkMatrix* matrix); - ~RuntimeShader() override; - -protected: - sk_sp makeSkShader() override; - -private: - sk_sp skShader; -}; -} // namespace android::uirenderer diff --git a/libs/hwui/shader/Shader.cpp b/libs/hwui/shader/Shader.cpp deleted file mode 100644 index 45123dd55002d..0000000000000 --- a/libs/hwui/shader/Shader.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2020 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 "Shader.h" - -#include "SkImageFilters.h" -#include "SkPaint.h" -#include "SkRefCnt.h" - -namespace android::uirenderer { - -Shader::Shader(const SkMatrix* matrix) - : localMatrix(matrix ? *matrix : SkMatrix::I()) - , skShader(nullptr) - , skImageFilter(nullptr) {} - -Shader::~Shader() {} - -sk_sp Shader::asSkShader() { - // If we already have created a shader with these parameters just return the existing - // shader we have already created - if (!this->skShader.get()) { - this->skShader = makeSkShader(); - if (this->skShader.get()) { - if (!localMatrix.isIdentity()) { - this->skShader = this->skShader->makeWithLocalMatrix(localMatrix); - } - } - } - return this->skShader; -} - -/** - * By default return null as we cannot convert all visual effects to SkShader instances - */ -sk_sp Shader::makeSkShader() { - return nullptr; -} - -sk_sp Shader::asSkImageFilter() { - // If we already have created an ImageFilter with these parameters just return the existing - // ImageFilter we have already created - if (!this->skImageFilter.get()) { - // Attempt to create an SkImageFilter from the current Shader implementation - this->skImageFilter = makeSkImageFilter(); - if (this->skImageFilter) { - if (!localMatrix.isIdentity()) { - // If we have created an SkImageFilter and we have a transformation, wrap - // the created SkImageFilter to apply the given matrix - this->skImageFilter = SkImageFilters::MatrixTransform( - localMatrix, kMedium_SkFilterQuality, this->skImageFilter); - } - } else { - // Otherwise if no SkImageFilter implementation is provided, create one from - // the result of asSkShader. Note the matrix is already applied to the shader in - // this case so just convert it to an SkImageFilter using SkImageFilters::Paint - SkPaint paint; - paint.setShader(asSkShader()); - sk_sp paintFilter = SkImageFilters::Paint(paint); - this->skImageFilter = SkImageFilters::Xfermode(SkBlendMode::kDstIn, - std::move(paintFilter)); - } - } - return this->skImageFilter; -} - -/** - * By default return null for subclasses to implement. If there is not a direct SkImageFilter - * conversion - */ -sk_sp Shader::makeSkImageFilter() { - return nullptr; -} -} // namespace android::uirenderer \ No newline at end of file diff --git a/libs/hwui/shader/Shader.h b/libs/hwui/shader/Shader.h deleted file mode 100644 index 6403e1147ded8..0000000000000 --- a/libs/hwui/shader/Shader.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2020 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 "SkImageFilter.h" -#include "SkShader.h" -#include "SkPaint.h" -#include "SkRefCnt.h" - -class SkMatrix; - -namespace android::uirenderer { - -/** - * Shader class that can optionally wrap an SkShader or SkImageFilter depending - * on the implementation - */ -class Shader: public SkRefCnt { -public: - /** - * Creates a Shader instance with an optional transformation matrix. The transformation matrix - * is copied internally and ownership is unchanged. It is the responsibility of the caller to - * deallocate it appropriately. - * @param matrix Optional matrix to transform the underlying SkShader or SkImageFilter - */ - Shader(const SkMatrix* matrix); - virtual ~Shader(); - - /** - * Create an SkShader from the current Shader instance or return a previously - * created instance. This can be null if no SkShader could be created from this - * Shader instance. - */ - sk_sp asSkShader(); - - /** - * Create an SkImageFilter from the current Shader instance or return a previously - * created instance. Unlike asSkShader, this method cannot return null. - */ - sk_sp asSkImageFilter(); - -protected: - /** - * Create a new SkShader instance based on this Shader instance - */ - virtual sk_sp makeSkShader(); - - /** - * Create a new SkImageFilter instance based on this Shader instance. If no SkImageFilter - * can be created then return nullptr - */ - virtual sk_sp makeSkImageFilter(); - -private: - /** - * Optional matrix transform - */ - const SkMatrix localMatrix; - - /** - * Cached SkShader instance to be returned on subsequent queries - */ - sk_sp skShader; - - /** - * Cached SkImageFilter instance to be returned on subsequent queries - */ - sk_sp skImageFilter; -}; -} // namespace android::uirenderer diff --git a/libs/hwui/shader/SweepGradientShader.cpp b/libs/hwui/shader/SweepGradientShader.cpp deleted file mode 100644 index 3b1f37f8b0513..0000000000000 --- a/libs/hwui/shader/SweepGradientShader.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2020 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 "SweepGradientShader.h" - -#include - -#include "SkGradientShader.h" -#include "SkImageFilters.h" - -namespace android::uirenderer { - -SweepGradientShader::SweepGradientShader(float x, float y, const std::vector& colors, - const sk_sp& colorspace, const SkScalar pos[], - const uint32_t shaderFlags, const SkMatrix* matrix) - : Shader(matrix) - , skShader(SkGradientShader::MakeSweep(x, y, colors.data(), colorspace, pos, colors.size(), - shaderFlags, nullptr)) {} - -sk_sp SweepGradientShader::makeSkShader() { - return skShader; -} - -SweepGradientShader::~SweepGradientShader() {} -} // namespace android::uirenderer \ No newline at end of file diff --git a/libs/hwui/shader/SweepGradientShader.h b/libs/hwui/shader/SweepGradientShader.h deleted file mode 100644 index dad3ef0ffad43..0000000000000 --- a/libs/hwui/shader/SweepGradientShader.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2020 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 "Shader.h" -#include "SkShader.h" - -namespace android::uirenderer { - -/** - * Shader implementation that renders a color ramp clockwise such that the start and end colors - * are visible at 3 o'clock. This handles converting to either an SkShader or SkImageFilter - */ -class SweepGradientShader : public Shader { -public: - SweepGradientShader(float x, float y, const std::vector& colors, - const sk_sp& colorspace, const SkScalar pos[], - const uint32_t shaderFlags, const SkMatrix* matrix); - virtual ~SweepGradientShader() override; - -protected: - virtual sk_sp makeSkShader() override; - -private: - sk_sp skShader; -}; -} // namespace android::uirenderer diff --git a/libs/hwui/tests/common/scenes/BitmapShaders.cpp b/libs/hwui/tests/common/scenes/BitmapShaders.cpp index e2c1651d823a5..c4067af388e38 100644 --- a/libs/hwui/tests/common/scenes/BitmapShaders.cpp +++ b/libs/hwui/tests/common/scenes/BitmapShaders.cpp @@ -18,7 +18,6 @@ #include "hwui/Paint.h" #include "TestSceneBase.h" #include "tests/common/BitmapAllocationTestUtils.h" -#include #include "utils/Color.h" class BitmapShaders; @@ -46,24 +45,15 @@ public: }); Paint paint; - sk_sp bitmapShader = sk_make_sp( - hwuiBitmap->makeImage(), - SkTileMode::kRepeat, - SkTileMode::kRepeat, - nullptr - ); - sk_sp image = hwuiBitmap->makeImage(); - paint.setShader(std::move(bitmapShader)); + sk_sp repeatShader = + image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat); + paint.setShader(std::move(repeatShader)); canvas.drawRoundRect(0, 0, 500, 500, 50.0f, 50.0f, paint); - sk_sp mirrorBitmapShader = sk_make_sp( - image, - SkTileMode::kMirror, - SkTileMode::kMirror, - nullptr - ); - paint.setShader(std::move(mirrorBitmapShader)); + sk_sp mirrorShader = + image->makeShader(SkTileMode::kMirror, SkTileMode::kMirror); + paint.setShader(std::move(mirrorShader)); canvas.drawRoundRect(0, 600, 500, 1100, 50.0f, 50.0f, paint); } diff --git a/libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp b/libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp index d37bc3c7d37c4..5886ea39acce0 100644 --- a/libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp +++ b/libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp @@ -20,10 +20,6 @@ #include #include #include -#include -#include -#include -#include class HwBitmapInCompositeShader; @@ -54,41 +50,20 @@ public: pixels[4000 + 4 * i + 3] = 255; } buffer->unlock(); - - sk_sp bitmapShader = sk_make_sp( - Bitmap::createFrom( - buffer->toAHardwareBuffer(), - SkColorSpace::MakeSRGB() - )->makeImage(), - SkTileMode::kClamp, - SkTileMode::kClamp, - nullptr - ); + sk_sp hardwareBitmap(Bitmap::createFrom(buffer->toAHardwareBuffer(), + SkColorSpace::MakeSRGB())); + sk_sp hardwareShader(createBitmapShader(*hardwareBitmap)); SkPoint center; center.set(50, 50); + SkColor colors[2]; + colors[0] = Color::Black; + colors[1] = Color::White; + sk_sp gradientShader = SkGradientShader::MakeRadial( + center, 50, colors, nullptr, 2, SkTileMode::kRepeat); - std::vector vColors(2); - vColors[0] = SkColors::kBlack; - vColors[1] = SkColors::kWhite; - - sk_sp radialShader = sk_make_sp( - center, - 50, - vColors, - SkColorSpace::MakeSRGB(), - nullptr, - SkTileMode::kRepeat, - 0, - nullptr - ); - - sk_sp compositeShader = sk_make_sp( - *bitmapShader.get(), - *radialShader.get(), - SkBlendMode::kDstATop, - nullptr - ); + sk_sp compositeShader( + SkShaders::Blend(SkBlendMode::kDstATop, hardwareShader, gradientShader)); Paint paint; paint.setShader(std::move(compositeShader)); diff --git a/libs/hwui/tests/common/scenes/ListOfFadedTextAnimation.cpp b/libs/hwui/tests/common/scenes/ListOfFadedTextAnimation.cpp index 76e39deedd9a6..a9449b62a1f8c 100644 --- a/libs/hwui/tests/common/scenes/ListOfFadedTextAnimation.cpp +++ b/libs/hwui/tests/common/scenes/ListOfFadedTextAnimation.cpp @@ -17,8 +17,7 @@ #include "TestSceneBase.h" #include "tests/common/TestListViewSceneBase.h" #include "hwui/Paint.h" -#include "SkColor.h" -#include +#include class ListOfFadedTextAnimation; @@ -43,26 +42,15 @@ class ListOfFadedTextAnimation : public TestListViewSceneBase { pts[0].set(0, 0); pts[1].set(0, 1); + SkColor colors[2] = {Color::Black, Color::Transparent}; + sk_sp s( + SkGradientShader::MakeLinear(pts, colors, NULL, 2, SkTileMode::kClamp)); + SkMatrix matrix; matrix.setScale(1, length); matrix.postRotate(-90); - - std::vector vColors(2); - vColors[0] = SkColors::kBlack; - vColors[1] = SkColors::kTransparent; - - sk_sp linearGradientShader = sk_make_sp( - pts, - vColors, - SkColorSpace::MakeSRGB(), - nullptr, - SkTileMode::kClamp, - 0, - &matrix - ); - Paint fadingPaint; - fadingPaint.setShader(linearGradientShader); + fadingPaint.setShader(s->makeWithLocalMatrix(matrix)); fadingPaint.setBlendMode(SkBlendMode::kDstOut); canvas.drawRect(0, 0, length, itemHeight, fadingPaint); canvas.restore(); diff --git a/libs/hwui/tests/common/scenes/SimpleColorMatrixAnimation.cpp b/libs/hwui/tests/common/scenes/SimpleColorMatrixAnimation.cpp index bdc157f852646..a0bc5aa245d52 100644 --- a/libs/hwui/tests/common/scenes/SimpleColorMatrixAnimation.cpp +++ b/libs/hwui/tests/common/scenes/SimpleColorMatrixAnimation.cpp @@ -17,7 +17,7 @@ #include "TestSceneBase.h" #include -#include +#include class SimpleColorMatrixAnimation; @@ -65,12 +65,9 @@ private: // enough renderer might apply it directly to the paint color) float pos[] = {0, 1}; SkPoint pts[] = {SkPoint::Make(0, 0), SkPoint::Make(width, height)}; - std::vector colors(2); - colors[0] = SkColor4f::FromColor(Color::DeepPurple_500); - colors[1] = SkColor4f::FromColor(Color::DeepOrange_500); - paint.setShader(sk_make_sp( - pts, colors, SkColorSpace::MakeSRGB(), pos, SkTileMode::kClamp, - 0, nullptr)); + SkColor colors[2] = {Color::DeepPurple_500, Color::DeepOrange_500}; + paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 2, + SkTileMode::kClamp)); // overdraw several times to emphasize shader cost for (int i = 0; i < 10; i++) { diff --git a/libs/hwui/tests/common/scenes/SimpleGradientAnimation.cpp b/libs/hwui/tests/common/scenes/SimpleGradientAnimation.cpp index 9a15c9d370a40..57a260c8d2340 100644 --- a/libs/hwui/tests/common/scenes/SimpleGradientAnimation.cpp +++ b/libs/hwui/tests/common/scenes/SimpleGradientAnimation.cpp @@ -17,7 +17,6 @@ #include "TestSceneBase.h" #include -#include class SimpleGradientAnimation; @@ -56,24 +55,9 @@ private: // overdraw several times to emphasize shader cost for (int i = 0; i < 10; i++) { // use i%2 start position to pick 2 color combo with black in it - std::vector vColors(2); - vColors[0] = ((i % 2) == 0) ? - SkColor4f::FromColor(Color::Transparent) : - SkColor4f::FromColor(Color::Black); - vColors[1] = (((i + 1) % 2) == 0) ? - SkColor4f::FromColor(Color::Black) : - SkColor4f::FromColor(Color::Cyan_500); - - sk_sp gradient = sk_make_sp( - pts, - vColors, - SkColorSpace::MakeSRGB(), - pos, - SkTileMode::kClamp, - 0, - nullptr - ); - paint.setShader(gradient); + SkColor colors[3] = {Color::Transparent, Color::Black, Color::Cyan_500}; + paint.setShader(SkGradientShader::MakeLinear(pts, colors + (i % 2), pos, 2, + SkTileMode::kClamp)); canvas.drawRect(i, i, width, height, paint); } }); diff --git a/libs/hwui/tests/unit/VectorDrawableTests.cpp b/libs/hwui/tests/unit/VectorDrawableTests.cpp index 5e56b26f46f05..6d4c57413f00c 100644 --- a/libs/hwui/tests/unit/VectorDrawableTests.cpp +++ b/libs/hwui/tests/unit/VectorDrawableTests.cpp @@ -17,14 +17,9 @@ #include #include "PathParser.h" -#include "GraphicsJNI.h" -#include "SkGradientShader.h" -#include "SkShader.h" #include "VectorDrawable.h" #include "utils/MathUtils.h" #include "utils/VectorDrawableUtils.h" -#include -#include #include @@ -400,21 +395,7 @@ TEST(VectorDrawable, drawPathWithoutIncrementingShaderRefCount) { bitmap.allocN32Pixels(5, 5, false); SkCanvas canvas(bitmap); - SkPoint pts[2]; - pts[0].set(0, 0); - pts[1].set(0, 0); - - std::vector colors(2); - colors[0] = SkColors::kBlack; - colors[1] = SkColors::kBlack; - - sk_sp shader = sk_sp(new LinearGradientShader(pts, - colors, - SkColorSpace::MakeSRGB(), - nullptr, - SkTileMode::kClamp, - SkGradientShader::kInterpolateColorsInPremul_Flag, - nullptr)); + sk_sp shader = SkShaders::Color(SK_ColorBLACK); // Initial ref count is 1 EXPECT_TRUE(shader->unique());