Revert "Create wrapper around Shader native implementation"
This reverts commit fc42a99ea5712883c9872d34a523d972c26c9d6f.
Because we are moving away from a wrapper class to delegate
between SkImageFilter and SkShader and instead adding
RenderEffect on RenderNode, this wrapper implementation
is no longer necessary. There are some behavioral
differences between SkShader and SkImageFilter that
would lead to additional complexity in conversions
between these objects and potential bugs.
To simplify this, RenderEffect will be added
directly to RenderNode to support better
caching of rasterization layers that is necessary
for various visual effects like blur.
Test: N/A
Change-Id: I65dc9f8bd26aed8761af13491ae3f6d583208377
diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp
index 975265e..155bb6b 100644
--- a/libs/hwui/Android.bp
+++ b/libs/hwui/Android.bp
@@ -464,14 +464,6 @@
"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 a690840..1dbce58 100644
--- a/libs/hwui/SkiaCanvas.cpp
+++ b/libs/hwui/SkiaCanvas.cpp
@@ -42,8 +42,6 @@
#include <SkTextBlob.h>
#include <SkVertices.h>
-#include <shader/BitmapShader.h>
-
#include <memory>
#include <optional>
#include <utility>
@@ -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 @@
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 0f566e4..cd908354 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 @@
// 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<Shader>(SkSafeRef(properties.getFillGradient())));
+ paint.setShader(sk_sp<SkShader>(SkSafeRef(properties.getFillGradient())));
needsFill = true;
} else if (properties.getFillColor() != SK_ColorTRANSPARENT) {
paint.setColor(applyAlpha(properties.getFillColor(), properties.getFillAlpha()));
@@ -178,7 +179,7 @@
bool needsStroke = false;
if (properties.getStrokeGradient() != nullptr) {
paint.setColor(applyAlpha(SK_ColorBLACK, properties.getStrokeAlpha()));
- paint.setShader(sk_sp<Shader>(SkSafeRef(properties.getStrokeGradient())));
+ paint.setShader(sk_sp<SkShader>(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 d4086f1..ac7d41e 100644
--- a/libs/hwui/VectorDrawable.h
+++ b/libs/hwui/VectorDrawable.h
@@ -31,8 +31,8 @@
#include <SkPath.h>
#include <SkPathMeasure.h>
#include <SkRect.h>
+#include <SkShader.h>
#include <SkSurface.h>
-#include <shader/Shader.h>
#include <cutils/compiler.h>
#include <stddef.h>
@@ -227,20 +227,20 @@
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 @@
count,
};
PrimitiveFields mPrimitiveFields;
- sk_sp<Shader> fillGradient;
- sk_sp<Shader> strokeGradient;
+ sk_sp<SkShader> fillGradient;
+ sk_sp<SkShader> strokeGradient;
};
// Called from UI thread
diff --git a/libs/hwui/hwui/Canvas.cpp b/libs/hwui/hwui/Canvas.cpp
index 2001b56..8df2770b 100644
--- a/libs/hwui/hwui/Canvas.cpp
+++ b/libs/hwui/hwui/Canvas.cpp
@@ -73,7 +73,7 @@
static void simplifyPaint(int color, Paint* paint) {
paint->setColor(color);
- paint->setShader((sk_sp<uirenderer::Shader>)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 4e2016a..e75e9e7 100644
--- a/libs/hwui/hwui/Paint.h
+++ b/libs/hwui/hwui/Paint.h
@@ -30,8 +30,6 @@
#include <minikin/FamilyVariant.h>
#include <minikin/Hyphenator.h>
-#include <shader/Shader.h>
-
namespace android {
class Paint : public SkPaint {
@@ -151,13 +149,8 @@
// 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<uirenderer::Shader> shader);
private:
-
- using SkPaint::setShader;
-
SkFont mFont;
sk_sp<SkDrawLooper> mLooper;
@@ -176,7 +169,6 @@
bool mStrikeThru = false;
bool mUnderline = false;
bool mDevKern = false;
- sk_sp<uirenderer::Shader> mShader;
};
} // namespace android
diff --git a/libs/hwui/hwui/PaintImpl.cpp b/libs/hwui/hwui/PaintImpl.cpp
index 21f60fd..fa2674f 100644
--- a/libs/hwui/hwui/PaintImpl.cpp
+++ b/libs/hwui/hwui/PaintImpl.cpp
@@ -24,8 +24,7 @@
, 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 @@
, mAlign(paint.mAlign)
, mStrikeThru(paint.mStrikeThru)
, mUnderline(paint.mUnderline)
- , mDevKern(paint.mDevKern)
- , mShader(paint.mShader){}
+ , mDevKern(paint.mDevKern) {}
Paint::~Paint() {}
@@ -67,30 +65,9 @@
mStrikeThru = other.mStrikeThru;
mUnderline = other.mUnderline;
mDevKern = other.mDevKern;
- mShader = other.mShader;
return *this;
}
-void Paint::setShader(sk_sp<uirenderer::Shader> shader) {
- if (shader) {
- // If there is an SkShader compatible shader, apply it
- sk_sp<SkShader> 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<const SkPaint&>(a) == static_cast<const SkPaint&>(b) &&
a.mFont == b.mFont &&
diff --git a/libs/hwui/jni/Paint.cpp b/libs/hwui/jni/Paint.cpp
index f6c8496..3c86b28 100644
--- a/libs/hwui/jni/Paint.cpp
+++ b/libs/hwui/jni/Paint.cpp
@@ -47,7 +47,6 @@
#include <minikin/LocaleList.h>
#include <minikin/Measurement.h>
#include <minikin/MinikinPaint.h>
-#include <shader/Shader.h>
#include <unicode/utf16.h>
#include <cassert>
@@ -55,8 +54,6 @@
#include <memory>
#include <vector>
-using namespace android::uirenderer;
-
namespace android {
static void getPosTextPath(const SkFont& font, const uint16_t glyphs[], int count,
@@ -745,10 +742,11 @@
return obj->getFillPath(*src, dst) ? JNI_TRUE : JNI_FALSE;
}
- static void setShader(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jlong shaderHandle) {
- auto* paint = reinterpret_cast<Paint*>(objHandle);
- auto* shader = reinterpret_cast<Shader*>(shaderHandle);
- paint->setShader(sk_ref_sp(shader));
+ static jlong setShader(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jlong shaderHandle) {
+ Paint* obj = reinterpret_cast<Paint*>(objHandle);
+ SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
+ obj->setShader(sk_ref_sp(shader));
+ return reinterpret_cast<jlong>(obj->getShader());
}
static jlong setColorFilter(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jlong filterHandle) {
@@ -1059,7 +1057,7 @@
{"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 0a194f9..e76aace 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 <vector>
@@ -58,7 +50,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////
-static void Shader_safeUnref(Shader* shader) {
+static void Shader_safeUnref(SkShader* shader) {
SkSafeUnref(shader);
}
@@ -82,15 +74,15 @@
SkBitmap bitmap;
image = SkMakeImageFromRasterBitmap(bitmap, kNever_SkCopyPixelsMode);
}
+ sk_sp<SkShader> shader = image->makeShader(
+ (SkTileMode)tileModeX, (SkTileMode)tileModeY);
+ ThrowIAE_IfNull(env, shader.get());
- auto* shader = new BitmapShader(
- image,
- static_cast<SkTileMode>(tileModeX),
- static_cast<SkTileMode>(tileModeY),
- matrix
- );
+ if (matrix) {
+ shader = shader->makeWithLocalMatrix(*matrix);
+ }
- return reinterpret_cast<jlong>(shader);
+ return reinterpret_cast<jlong>(shader.release());
}
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -126,18 +118,17 @@
#error Need to convert float array to SkScalar array before calling the following function.
#endif
- auto* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
- auto* shader = new LinearGradientShader(
- pts,
- colors,
- GraphicsJNI::getNativeColorSpace(colorSpaceHandle),
- pos,
- static_cast<SkTileMode>(tileMode),
- sGradientShaderFlags,
- matrix
- );
+ sk_sp<SkShader> shader(SkGradientShader::MakeLinear(pts, &colors[0],
+ GraphicsJNI::getNativeColorSpace(colorSpaceHandle), pos, colors.size(),
+ static_cast<SkTileMode>(tileMode), sGradientShaderFlags, nullptr));
+ ThrowIAE_IfNull(env, shader);
- return reinterpret_cast<jlong>(shader);
+ const SkMatrix* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
+ if (matrix) {
+ shader = shader->makeWithLocalMatrix(*matrix);
+ }
+
+ return reinterpret_cast<jlong>(shader.release());
}
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -157,20 +148,17 @@
#error Need to convert float array to SkScalar array before calling the following function.
#endif
- auto* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
+ sk_sp<SkShader> shader = SkGradientShader::MakeRadial(center, radius, &colors[0],
+ GraphicsJNI::getNativeColorSpace(colorSpaceHandle), pos, colors.size(),
+ static_cast<SkTileMode>(tileMode), sGradientShaderFlags, nullptr);
+ ThrowIAE_IfNull(env, shader);
- auto* shader = new RadialGradientShader(
- center,
- radius,
- colors,
- GraphicsJNI::getNativeColorSpace(colorSpaceHandle),
- pos,
- static_cast<SkTileMode>(tileMode),
- sGradientShaderFlags,
- matrix
- );
+ const SkMatrix* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
+ if (matrix) {
+ shader = shader->makeWithLocalMatrix(*matrix);
+ }
- return reinterpret_cast<jlong>(shader);
+ return reinterpret_cast<jlong>(shader.release());
}
///////////////////////////////////////////////////////////////////////////////
@@ -186,75 +174,54 @@
#error Need to convert float array to SkScalar array before calling the following function.
#endif
- auto* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
+ sk_sp<SkShader> 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<const SkMatrix*>(matrixPtr);
+ if (matrix) {
+ shader = shader->makeWithLocalMatrix(*matrix);
+ }
- return reinterpret_cast<jlong>(shader);
+ return reinterpret_cast<jlong>(shader.release());
}
///////////////////////////////////////////////////////////////////////////////////////////////
static jlong ComposeShader_create(JNIEnv* env, jobject o, jlong matrixPtr,
jlong shaderAHandle, jlong shaderBHandle, jint xfermodeHandle) {
- auto* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
- auto* shaderA = reinterpret_cast<Shader*>(shaderAHandle);
- auto* shaderB = reinterpret_cast<Shader*>(shaderBHandle);
+ const SkMatrix* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
+ SkShader* shaderA = reinterpret_cast<SkShader *>(shaderAHandle);
+ SkShader* shaderB = reinterpret_cast<SkShader *>(shaderBHandle);
+ SkBlendMode mode = static_cast<SkBlendMode>(xfermodeHandle);
+ sk_sp<SkShader> baseShader(SkShaders::Blend(mode,
+ sk_ref_sp(shaderA), sk_ref_sp(shaderB)));
- auto mode = static_cast<SkBlendMode>(xfermodeHandle);
+ SkShader* shader;
- auto* composeShader = new ComposeShader(
- *shaderA,
- *shaderB,
- mode,
- matrix
- );
-
- return reinterpret_cast<jlong>(composeShader);
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////
-
-static jlong BlurShader_create(JNIEnv* env , jobject o, jlong matrixPtr, jfloat sigmaX,
- jfloat sigmaY, jlong shaderHandle, jint edgeTreatment) {
- auto* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
- auto* inputShader = reinterpret_cast<Shader*>(shaderHandle);
-
- auto* blurShader = new BlurShader(
- sigmaX,
- sigmaY,
- inputShader,
- static_cast<SkTileMode>(edgeTreatment),
- matrix
- );
- return reinterpret_cast<jlong>(blurShader);
+ if (matrix) {
+ shader = baseShader->makeWithLocalMatrix(*matrix).release();
+ } else {
+ shader = baseShader.release();
+ }
+ return reinterpret_cast<jlong>(shader);
}
///////////////////////////////////////////////////////////////////////////////////////////////
static jlong RuntimeShader_create(JNIEnv* env, jobject, jlong shaderFactory, jlong matrixPtr,
jbyteArray inputs, jlong colorSpaceHandle, jboolean isOpaque) {
- auto* effect = reinterpret_cast<SkRuntimeEffect*>(shaderFactory);
+ SkRuntimeEffect* effect = reinterpret_cast<SkRuntimeEffect*>(shaderFactory);
AutoJavaByteArray arInputs(env, inputs);
- auto data = SkData::MakeWithCopy(arInputs.ptr(), arInputs.length());
- auto* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
+ sk_sp<SkData> fData;
+ fData = SkData::MakeWithCopy(arInputs.ptr(), arInputs.length());
+ const SkMatrix* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
+ sk_sp<SkShader> 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<jlong>(shader);
+ return reinterpret_cast<jlong>(shader.release());
}
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -272,8 +239,12 @@
///////////////////////////////////////////////////////////////////////////////////////////////
+static void Effect_safeUnref(SkRuntimeEffect* effect) {
+ SkSafeUnref(effect);
+}
+
static jlong RuntimeShader_getNativeFinalizer(JNIEnv*, jobject) {
- return static_cast<jlong>(reinterpret_cast<uintptr_t>(&Shader_safeUnref));
+ return static_cast<jlong>(reinterpret_cast<uintptr_t>(&Effect_safeUnref));
}
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -291,10 +262,6 @@
{ "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 @@
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 a1adcb3..9cffceb 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 updateFullPathFillGradient(JNIEnv*, jobject, jlong pathPtr, jlong fillGradientPtr) {
VectorDrawable::FullPath* path = reinterpret_cast<VectorDrawable::FullPath*>(pathPtr);
- auto* fillShader = reinterpret_cast<Shader*>(fillGradientPtr);
+ SkShader* fillShader = reinterpret_cast<SkShader*>(fillGradientPtr);
path->mutateStagingProperties()->setFillGradient(fillShader);
}
static void updateFullPathStrokeGradient(JNIEnv*, jobject, jlong pathPtr, jlong strokeGradientPtr) {
VectorDrawable::FullPath* path = reinterpret_cast<VectorDrawable::FullPath*>(pathPtr);
- auto* strokeShader = reinterpret_cast<Shader*>(strokeGradientPtr);
+ SkShader* strokeShader = reinterpret_cast<SkShader*>(strokeGradientPtr);
path->mutateStagingProperties()->setStrokeGradient(strokeShader);
}
diff --git a/libs/hwui/shader/BitmapShader.cpp b/libs/hwui/shader/BitmapShader.cpp
deleted file mode 100644
index fe653e8..0000000
--- 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<SkImage>& image, const SkTileMode tileModeX,
- const SkTileMode tileModeY, const SkMatrix* matrix)
- : Shader(matrix), skShader(image->makeShader(tileModeX, tileModeY)) {}
-
-sk_sp<SkShader> 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 ed6a6e6..0000000
--- 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<SkImage>& image, const SkTileMode tileModeX,
- const SkTileMode tileModeY, const SkMatrix* matrix);
- ~BitmapShader() override;
-
-protected:
- sk_sp<SkShader> makeSkShader() override;
-
-private:
- sk_sp<SkShader> 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 3765489..0000000
--- 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<SkShader> skShaderA = shaderA.asSkShader();
- sk_sp<SkShader> skShaderB = shaderB.asSkShader();
- if (skShaderA.get() && skShaderB.get()) {
- skShader = SkShaders::Blend(blendMode, skShaderA, skShaderB);
- skImageFilter = nullptr;
- } else {
- sk_sp<SkImageFilter> skImageFilterA = shaderA.asSkImageFilter();
- sk_sp<SkImageFilter> skImageFilterB = shaderB.asSkImageFilter();
- skShader = nullptr;
- skImageFilter = SkImageFilters::Xfermode(blendMode, skImageFilterA, skImageFilterB);
- }
-}
-
-sk_sp<SkShader> ComposeShader::makeSkShader() {
- return skShader;
-}
-
-sk_sp<SkImageFilter> 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 a246b52..0000000
--- 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<SkShader> makeSkShader() override;
- sk_sp<SkImageFilter> makeSkImageFilter() override;
-
-private:
- sk_sp<SkShader> skShader;
- sk_sp<SkImageFilter> skImageFilter;
-};
-} // namespace android::uirenderer
diff --git a/libs/hwui/shader/LinearGradientShader.cpp b/libs/hwui/shader/LinearGradientShader.cpp
deleted file mode 100644
index 868fa44..0000000
--- 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 <vector>
-
-#include "SkGradientShader.h"
-
-namespace android::uirenderer {
-
-LinearGradientShader::LinearGradientShader(const SkPoint pts[2],
- const std::vector<SkColor4f>& colors,
- sk_sp<SkColorSpace> 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<SkShader> 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 596f4e0..0000000
--- 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<SkColor4f>& colors,
- sk_sp<SkColorSpace> colorspace, const SkScalar pos[],
- const SkTileMode tileMode, const uint32_t shaderFlags,
- const SkMatrix* matrix);
- ~LinearGradientShader() override;
-
-protected:
- sk_sp<SkShader> makeSkShader() override;
-
-private:
- sk_sp<SkShader> skShader;
-};
-} // namespace android::uirenderer
diff --git a/libs/hwui/shader/RadialGradientShader.cpp b/libs/hwui/shader/RadialGradientShader.cpp
deleted file mode 100644
index 21ff56f..0000000
--- 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 <vector>
-
-#include "SkGradientShader.h"
-
-namespace android::uirenderer {
-
-RadialGradientShader::RadialGradientShader(const SkPoint& center, const float radius,
- const std::vector<SkColor4f>& colors,
- sk_sp<SkColorSpace> 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<SkShader> 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 9a2ff13..0000000
--- 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<SkColor4f>& colors, sk_sp<SkColorSpace> colorSpace,
- const SkScalar pos[], const SkTileMode tileMode, const uint32_t shaderFlags,
- const SkMatrix* matrix);
- ~RadialGradientShader() override;
-
-protected:
- sk_sp<SkShader> makeSkShader() override;
-
-private:
- sk_sp<SkShader> 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 dd0b698..0000000
--- 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<SkData> 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<SkShader> 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 7fe0b02..0000000
--- 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<SkData> data, bool isOpaque,
- const SkMatrix* matrix);
- ~RuntimeShader() override;
-
-protected:
- sk_sp<SkShader> makeSkShader() override;
-
-private:
- sk_sp<SkShader> skShader;
-};
-} // namespace android::uirenderer
diff --git a/libs/hwui/shader/Shader.cpp b/libs/hwui/shader/Shader.cpp
deleted file mode 100644
index 45123dd..0000000
--- 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<SkShader> 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<SkShader> Shader::makeSkShader() {
- return nullptr;
-}
-
-sk_sp<SkImageFilter> 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<SkImageFilter> 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<SkImageFilter> 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 6403e11..0000000
--- 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<SkShader> asSkShader();
-
- /**
- * Create an SkImageFilter from the current Shader instance or return a previously
- * created instance. Unlike asSkShader, this method cannot return null.
- */
- sk_sp<SkImageFilter> asSkImageFilter();
-
-protected:
- /**
- * Create a new SkShader instance based on this Shader instance
- */
- virtual sk_sp<SkShader> makeSkShader();
-
- /**
- * Create a new SkImageFilter instance based on this Shader instance. If no SkImageFilter
- * can be created then return nullptr
- */
- virtual sk_sp<SkImageFilter> makeSkImageFilter();
-
-private:
- /**
- * Optional matrix transform
- */
- const SkMatrix localMatrix;
-
- /**
- * Cached SkShader instance to be returned on subsequent queries
- */
- sk_sp<SkShader> skShader;
-
- /**
- * Cached SkImageFilter instance to be returned on subsequent queries
- */
- sk_sp<SkImageFilter> skImageFilter;
-};
-} // namespace android::uirenderer
diff --git a/libs/hwui/shader/SweepGradientShader.cpp b/libs/hwui/shader/SweepGradientShader.cpp
deleted file mode 100644
index 3b1f37f..0000000
--- 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 <vector>
-
-#include "SkGradientShader.h"
-#include "SkImageFilters.h"
-
-namespace android::uirenderer {
-
-SweepGradientShader::SweepGradientShader(float x, float y, const std::vector<SkColor4f>& colors,
- const sk_sp<SkColorSpace>& 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<SkShader> 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 dad3ef0..0000000
--- 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<SkColor4f>& colors,
- const sk_sp<SkColorSpace>& colorspace, const SkScalar pos[],
- const uint32_t shaderFlags, const SkMatrix* matrix);
- virtual ~SweepGradientShader() override;
-
-protected:
- virtual sk_sp<SkShader> makeSkShader() override;
-
-private:
- sk_sp<SkShader> skShader;
-};
-} // namespace android::uirenderer
diff --git a/libs/hwui/tests/common/scenes/BitmapShaders.cpp b/libs/hwui/tests/common/scenes/BitmapShaders.cpp
index e2c1651..c4067af 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 <shader/BitmapShader.h>
#include "utils/Color.h"
class BitmapShaders;
@@ -46,24 +45,15 @@
});
Paint paint;
- sk_sp<BitmapShader> bitmapShader = sk_make_sp<BitmapShader>(
- hwuiBitmap->makeImage(),
- SkTileMode::kRepeat,
- SkTileMode::kRepeat,
- nullptr
- );
-
sk_sp<SkImage> image = hwuiBitmap->makeImage();
- paint.setShader(std::move(bitmapShader));
+ sk_sp<SkShader> 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<BitmapShader> mirrorBitmapShader = sk_make_sp<BitmapShader>(
- image,
- SkTileMode::kMirror,
- SkTileMode::kMirror,
- nullptr
- );
- paint.setShader(std::move(mirrorBitmapShader));
+ sk_sp<SkShader> 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 d37bc3c..5886ea3 100644
--- a/libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp
+++ b/libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp
@@ -20,10 +20,6 @@
#include <SkGradientShader.h>
#include <SkImagePriv.h>
#include <ui/PixelFormat.h>
-#include <shader/BitmapShader.h>
-#include <shader/LinearGradientShader.h>
-#include <shader/RadialGradientShader.h>
-#include <shader/ComposeShader.h>
class HwBitmapInCompositeShader;
@@ -54,41 +50,20 @@
pixels[4000 + 4 * i + 3] = 255;
}
buffer->unlock();
-
- sk_sp<BitmapShader> bitmapShader = sk_make_sp<BitmapShader>(
- Bitmap::createFrom(
- buffer->toAHardwareBuffer(),
- SkColorSpace::MakeSRGB()
- )->makeImage(),
- SkTileMode::kClamp,
- SkTileMode::kClamp,
- nullptr
- );
+ sk_sp<Bitmap> hardwareBitmap(Bitmap::createFrom(buffer->toAHardwareBuffer(),
+ SkColorSpace::MakeSRGB()));
+ sk_sp<SkShader> hardwareShader(createBitmapShader(*hardwareBitmap));
SkPoint center;
center.set(50, 50);
+ SkColor colors[2];
+ colors[0] = Color::Black;
+ colors[1] = Color::White;
+ sk_sp<SkShader> gradientShader = SkGradientShader::MakeRadial(
+ center, 50, colors, nullptr, 2, SkTileMode::kRepeat);
- std::vector<SkColor4f> vColors(2);
- vColors[0] = SkColors::kBlack;
- vColors[1] = SkColors::kWhite;
-
- sk_sp<RadialGradientShader> radialShader = sk_make_sp<RadialGradientShader>(
- center,
- 50,
- vColors,
- SkColorSpace::MakeSRGB(),
- nullptr,
- SkTileMode::kRepeat,
- 0,
- nullptr
- );
-
- sk_sp<ComposeShader> compositeShader = sk_make_sp<ComposeShader>(
- *bitmapShader.get(),
- *radialShader.get(),
- SkBlendMode::kDstATop,
- nullptr
- );
+ sk_sp<SkShader> 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 76e39de..a9449b6 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 <shader/LinearGradientShader.h>
+#include <SkGradientShader.h>
class ListOfFadedTextAnimation;
@@ -43,26 +42,15 @@
pts[0].set(0, 0);
pts[1].set(0, 1);
+ SkColor colors[2] = {Color::Black, Color::Transparent};
+ sk_sp<SkShader> s(
+ SkGradientShader::MakeLinear(pts, colors, NULL, 2, SkTileMode::kClamp));
+
SkMatrix matrix;
matrix.setScale(1, length);
matrix.postRotate(-90);
-
- std::vector<SkColor4f> vColors(2);
- vColors[0] = SkColors::kBlack;
- vColors[1] = SkColors::kTransparent;
-
- sk_sp<LinearGradientShader> linearGradientShader = sk_make_sp<LinearGradientShader>(
- 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 bdc157f..a0bc5aa 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 <SkColorMatrixFilter.h>
-#include <shader/LinearGradientShader.h>
+#include <SkGradientShader.h>
class SimpleColorMatrixAnimation;
@@ -65,12 +65,9 @@
// 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<SkColor4f> colors(2);
- colors[0] = SkColor4f::FromColor(Color::DeepPurple_500);
- colors[1] = SkColor4f::FromColor(Color::DeepOrange_500);
- paint.setShader(sk_make_sp<LinearGradientShader>(
- 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 9a15c9d..57a260c 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 <SkGradientShader.h>
-#include <shader/LinearGradientShader.h>
class SimpleGradientAnimation;
@@ -56,24 +55,9 @@
// 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<SkColor4f> 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<LinearGradientShader> gradient = sk_make_sp<LinearGradientShader>(
- 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 5e56b26..6d4c574 100644
--- a/libs/hwui/tests/unit/VectorDrawableTests.cpp
+++ b/libs/hwui/tests/unit/VectorDrawableTests.cpp
@@ -17,14 +17,9 @@
#include <gtest/gtest.h>
#include "PathParser.h"
-#include "GraphicsJNI.h"
-#include "SkGradientShader.h"
-#include "SkShader.h"
#include "VectorDrawable.h"
#include "utils/MathUtils.h"
#include "utils/VectorDrawableUtils.h"
-#include <shader/Shader.h>
-#include <shader/LinearGradientShader.h>
#include <functional>
@@ -400,21 +395,7 @@
bitmap.allocN32Pixels(5, 5, false);
SkCanvas canvas(bitmap);
- SkPoint pts[2];
- pts[0].set(0, 0);
- pts[1].set(0, 0);
-
- std::vector<SkColor4f> colors(2);
- colors[0] = SkColors::kBlack;
- colors[1] = SkColors::kBlack;
-
- sk_sp<LinearGradientShader> shader = sk_sp(new LinearGradientShader(pts,
- colors,
- SkColorSpace::MakeSRGB(),
- nullptr,
- SkTileMode::kClamp,
- SkGradientShader::kInterpolateColorsInPremul_Flag,
- nullptr));
+ sk_sp<SkShader> shader = SkShaders::Color(SK_ColorBLACK);
// Initial ref count is 1
EXPECT_TRUE(shader->unique());