Better encapsulate Blend, Color and Empty shaders
Bug: skia:13438 Change-Id: Id1b7e6759144820f200040616deb3a120d809765 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/554405 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
This commit is contained in:
parent
a43654ec7e
commit
fc49c18ca2
@ -13,7 +13,6 @@
|
|||||||
#include "include/core/SkTime.h"
|
#include "include/core/SkTime.h"
|
||||||
#include "samplecode/Sample.h"
|
#include "samplecode/Sample.h"
|
||||||
#include "src/core/SkOSFile.h"
|
#include "src/core/SkOSFile.h"
|
||||||
#include "src/shaders/SkColorShader.h"
|
|
||||||
#include "src/utils/SkOSPath.h"
|
#include "src/utils/SkOSPath.h"
|
||||||
#include "src/utils/SkUTF.h"
|
#include "src/utils/SkUTF.h"
|
||||||
#include "tools/Resources.h"
|
#include "tools/Resources.h"
|
||||||
|
@ -469,10 +469,8 @@ skia_core_sources = [
|
|||||||
"$_src/shaders/SkColorFilterShader.cpp",
|
"$_src/shaders/SkColorFilterShader.cpp",
|
||||||
"$_src/shaders/SkColorFilterShader.h",
|
"$_src/shaders/SkColorFilterShader.h",
|
||||||
"$_src/shaders/SkColorShader.cpp",
|
"$_src/shaders/SkColorShader.cpp",
|
||||||
"$_src/shaders/SkColorShader.h",
|
|
||||||
"$_src/shaders/SkComposeShader.cpp",
|
"$_src/shaders/SkComposeShader.cpp",
|
||||||
"$_src/shaders/SkComposeShader.h",
|
"$_src/shaders/SkEmptyShader.cpp",
|
||||||
"$_src/shaders/SkEmptyShader.h",
|
|
||||||
"$_src/shaders/SkImageShader.cpp",
|
"$_src/shaders/SkImageShader.cpp",
|
||||||
"$_src/shaders/SkImageShader.h",
|
"$_src/shaders/SkImageShader.h",
|
||||||
"$_src/shaders/SkLocalMatrixShader.cpp",
|
"$_src/shaders/SkLocalMatrixShader.cpp",
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include "modules/skparagraph/utils/TestFontCollection.h"
|
#include "modules/skparagraph/utils/TestFontCollection.h"
|
||||||
#include "samplecode/Sample.h"
|
#include "samplecode/Sample.h"
|
||||||
#include "src/core/SkOSFile.h"
|
#include "src/core/SkOSFile.h"
|
||||||
#include "src/shaders/SkColorShader.h"
|
|
||||||
#include "src/utils/SkOSPath.h"
|
#include "src/utils/SkOSPath.h"
|
||||||
#include "src/utils/SkUTF.h"
|
#include "src/utils/SkUTF.h"
|
||||||
#include "tools/Resources.h"
|
#include "tools/Resources.h"
|
||||||
|
@ -1410,10 +1410,8 @@ BASE_SRCS_ALL = [
|
|||||||
"src/shaders/SkColorFilterShader.cpp",
|
"src/shaders/SkColorFilterShader.cpp",
|
||||||
"src/shaders/SkColorFilterShader.h",
|
"src/shaders/SkColorFilterShader.h",
|
||||||
"src/shaders/SkColorShader.cpp",
|
"src/shaders/SkColorShader.cpp",
|
||||||
"src/shaders/SkColorShader.h",
|
|
||||||
"src/shaders/SkComposeShader.cpp",
|
"src/shaders/SkComposeShader.cpp",
|
||||||
"src/shaders/SkComposeShader.h",
|
"src/shaders/SkEmptyShader.cpp",
|
||||||
"src/shaders/SkEmptyShader.h",
|
|
||||||
"src/shaders/SkImageShader.cpp",
|
"src/shaders/SkImageShader.cpp",
|
||||||
"src/shaders/SkImageShader.h",
|
"src/shaders/SkImageShader.h",
|
||||||
"src/shaders/SkLocalMatrixShader.cpp",
|
"src/shaders/SkLocalMatrixShader.cpp",
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include "include/utils/SkRandom.h"
|
#include "include/utils/SkRandom.h"
|
||||||
#include "modules/skshaper/include/SkShaper.h"
|
#include "modules/skshaper/include/SkShaper.h"
|
||||||
#include "src/core/SkOSFile.h"
|
#include "src/core/SkOSFile.h"
|
||||||
#include "src/shaders/SkColorShader.h"
|
|
||||||
#include "src/utils/SkUTF.h"
|
#include "src/utils/SkUTF.h"
|
||||||
|
|
||||||
typedef std::unique_ptr<SkShaper> (*ShaperFactory)();
|
typedef std::unique_ptr<SkShaper> (*ShaperFactory)();
|
||||||
|
@ -183,7 +183,7 @@ void SkDraw::drawAtlas(const SkRSXform xform[],
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (gUseSkVMBlitter || !rpblit()) {
|
if (gUseSkVMBlitter || !rpblit()) {
|
||||||
auto updateShader = as_SB(atlasShader)->updatableShader(&alloc);
|
SkUpdatableShader* updateShader = as_SB(atlasShader)->updatableShader(&alloc);
|
||||||
UpdatableColorShader* colorShader = nullptr;
|
UpdatableColorShader* colorShader = nullptr;
|
||||||
sk_sp<SkShader> shader;
|
sk_sp<SkShader> shader;
|
||||||
if (colors) {
|
if (colors) {
|
||||||
|
@ -548,7 +548,7 @@ void SkDraw::drawVertices(const SkVertices* vertices,
|
|||||||
|
|
||||||
constexpr size_t kDefVertexCount = 16;
|
constexpr size_t kDefVertexCount = 16;
|
||||||
constexpr size_t kOuterSize = sizeof(SkTriColorShader) +
|
constexpr size_t kOuterSize = sizeof(SkTriColorShader) +
|
||||||
(2 * sizeof(SkPoint) + sizeof(SkColor4f)) * kDefVertexCount;
|
(2 * sizeof(SkPoint) + sizeof(SkColor4f)) * kDefVertexCount;
|
||||||
SkSTArenaAlloc<kOuterSize> outerAlloc;
|
SkSTArenaAlloc<kOuterSize> outerAlloc;
|
||||||
|
|
||||||
SkPoint* dev2 = nullptr;
|
SkPoint* dev2 = nullptr;
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include "src/core/SkVM.h"
|
#include "src/core/SkVM.h"
|
||||||
#include "src/core/SkVMBlitter.h"
|
#include "src/core/SkVMBlitter.h"
|
||||||
#include "src/shaders/SkColorFilterShader.h"
|
#include "src/shaders/SkColorFilterShader.h"
|
||||||
#include "src/shaders/SkColorShader.h"
|
|
||||||
|
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
|
||||||
@ -228,7 +227,7 @@ SkVMBlitter::Params SkVMBlitter::EffectiveParams(const SkPixmap& device,
|
|||||||
// but if there is a shader, it's modulated by the paint alpha.
|
// but if there is a shader, it's modulated by the paint alpha.
|
||||||
sk_sp<SkShader> shader = paint.refShader();
|
sk_sp<SkShader> shader = paint.refShader();
|
||||||
if (!shader) {
|
if (!shader) {
|
||||||
shader = sk_make_sp<SkColor4Shader>(paint.getColor4f(), nullptr);
|
shader = SkShaders::Color(paint.getColor4f(), nullptr);
|
||||||
} else if (paint.getAlphaf() < 1.0f) {
|
} else if (paint.getAlphaf() < 1.0f) {
|
||||||
shader = sk_make_sp<SkColorFilterShader>(std::move(shader),
|
shader = sk_make_sp<SkColorFilterShader>(std::move(shader),
|
||||||
paint.getAlphaf(),
|
paint.getAlphaf(),
|
||||||
|
@ -36,9 +36,6 @@
|
|||||||
#include "src/effects/SkTrimPE.h"
|
#include "src/effects/SkTrimPE.h"
|
||||||
#include "src/shaders/SkBitmapProcShader.h"
|
#include "src/shaders/SkBitmapProcShader.h"
|
||||||
#include "src/shaders/SkColorFilterShader.h"
|
#include "src/shaders/SkColorFilterShader.h"
|
||||||
#include "src/shaders/SkColorShader.h"
|
|
||||||
#include "src/shaders/SkComposeShader.h"
|
|
||||||
#include "src/shaders/SkEmptyShader.h"
|
|
||||||
#include "src/shaders/SkImageShader.h"
|
#include "src/shaders/SkImageShader.h"
|
||||||
#include "src/shaders/SkLocalMatrixShader.h"
|
#include "src/shaders/SkLocalMatrixShader.h"
|
||||||
#include "src/shaders/SkPictureShader.h"
|
#include "src/shaders/SkPictureShader.h"
|
||||||
@ -65,11 +62,11 @@
|
|||||||
*/
|
*/
|
||||||
void SkFlattenable::PrivateInitializer::InitEffects() {
|
void SkFlattenable::PrivateInitializer::InitEffects() {
|
||||||
// Shaders.
|
// Shaders.
|
||||||
SK_REGISTER_FLATTENABLE(SkColor4Shader);
|
SkRegisterColor4ShaderFlattenable();
|
||||||
SK_REGISTER_FLATTENABLE(SkColorFilterShader);
|
SK_REGISTER_FLATTENABLE(SkColorFilterShader);
|
||||||
SK_REGISTER_FLATTENABLE(SkColorShader);
|
SkRegisterColorShaderFlattenable();
|
||||||
SK_REGISTER_FLATTENABLE(SkShader_Blend);
|
SkRegisterComposeShaderFlattenable();
|
||||||
SK_REGISTER_FLATTENABLE(SkEmptyShader);
|
SkRegisterEmptyShaderFlattenable();
|
||||||
SK_REGISTER_FLATTENABLE(SkLocalMatrixShader);
|
SK_REGISTER_FLATTENABLE(SkLocalMatrixShader);
|
||||||
SK_REGISTER_FLATTENABLE(SkPictureShader);
|
SK_REGISTER_FLATTENABLE(SkPictureShader);
|
||||||
SkGradientShader::RegisterFlattenables();
|
SkGradientShader::RegisterFlattenables();
|
||||||
|
@ -10,10 +10,8 @@ SHADER_FILES = [
|
|||||||
"SkColorFilterShader.cpp",
|
"SkColorFilterShader.cpp",
|
||||||
"SkColorFilterShader.h",
|
"SkColorFilterShader.h",
|
||||||
"SkColorShader.cpp",
|
"SkColorShader.cpp",
|
||||||
"SkColorShader.h",
|
|
||||||
"SkComposeShader.cpp",
|
"SkComposeShader.cpp",
|
||||||
"SkComposeShader.h",
|
"SkEmptyShader.cpp",
|
||||||
"SkEmptyShader.h",
|
|
||||||
"SkImageShader.cpp",
|
"SkImageShader.cpp",
|
||||||
"SkImageShader.h",
|
"SkImageShader.h",
|
||||||
"SkLocalMatrixShader.cpp",
|
"SkLocalMatrixShader.cpp",
|
||||||
|
@ -5,9 +5,8 @@
|
|||||||
* found in the LICENSE file.
|
* found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "src/shaders/SkColorShader.h"
|
|
||||||
|
|
||||||
#include "include/core/SkColorSpace.h"
|
#include "include/core/SkColorSpace.h"
|
||||||
|
#include "include/core/SkFlattenable.h"
|
||||||
#include "src/core/SkArenaAlloc.h"
|
#include "src/core/SkArenaAlloc.h"
|
||||||
#include "src/core/SkColorSpacePriv.h"
|
#include "src/core/SkColorSpacePriv.h"
|
||||||
#include "src/core/SkColorSpaceXformSteps.h"
|
#include "src/core/SkColorSpaceXformSteps.h"
|
||||||
@ -21,6 +20,89 @@
|
|||||||
#include "src/core/SkPaintParamsKey.h"
|
#include "src/core/SkPaintParamsKey.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "src/shaders/SkShaderBase.h"
|
||||||
|
|
||||||
|
class SkShaderCodeDictionary;
|
||||||
|
|
||||||
|
/** \class SkColorShader
|
||||||
|
A Shader that represents a single color. In general, this effect can be
|
||||||
|
accomplished by just using the color field on the paint, but if an
|
||||||
|
actual shader object is needed, this provides that feature.
|
||||||
|
*/
|
||||||
|
class SkColorShader : public SkShaderBase {
|
||||||
|
public:
|
||||||
|
/** Create a ColorShader that ignores the color in the paint, and uses the
|
||||||
|
specified color. Note: like all shaders, at draw time the paint's alpha
|
||||||
|
will be respected, and is applied to the specified color.
|
||||||
|
*/
|
||||||
|
explicit SkColorShader(SkColor c);
|
||||||
|
|
||||||
|
bool isOpaque() const override;
|
||||||
|
bool isConstant() const override { return true; }
|
||||||
|
|
||||||
|
GradientType asAGradient(GradientInfo* info) const override;
|
||||||
|
|
||||||
|
#if SK_SUPPORT_GPU
|
||||||
|
std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SK_ENABLE_SKSL
|
||||||
|
void addToKey(const SkKeyContext&,
|
||||||
|
SkPaintParamsKeyBuilder*,
|
||||||
|
SkPipelineDataGatherer*) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend void ::SkRegisterColorShaderFlattenable();
|
||||||
|
SK_FLATTENABLE_HOOKS(SkColorShader)
|
||||||
|
|
||||||
|
void flatten(SkWriteBuffer&) const override;
|
||||||
|
|
||||||
|
bool onAsLuminanceColor(SkColor* lum) const override {
|
||||||
|
*lum = fColor;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool onAppendStages(const SkStageRec&) const override;
|
||||||
|
|
||||||
|
skvm::Color onProgram(skvm::Builder*, skvm::Coord device, skvm::Coord local, skvm::Color paint,
|
||||||
|
const SkMatrixProvider&, const SkMatrix* localM, const SkColorInfo& dst,
|
||||||
|
skvm::Uniforms* uniforms, SkArenaAlloc*) const override;
|
||||||
|
|
||||||
|
SkColor fColor;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SkColor4Shader : public SkShaderBase {
|
||||||
|
public:
|
||||||
|
SkColor4Shader(const SkColor4f&, sk_sp<SkColorSpace>);
|
||||||
|
|
||||||
|
bool isOpaque() const override { return fColor.isOpaque(); }
|
||||||
|
bool isConstant() const override { return true; }
|
||||||
|
|
||||||
|
#if SK_SUPPORT_GPU
|
||||||
|
std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
|
||||||
|
#endif
|
||||||
|
#ifdef SK_ENABLE_SKSL
|
||||||
|
void addToKey(const SkKeyContext&,
|
||||||
|
SkPaintParamsKeyBuilder*,
|
||||||
|
SkPipelineDataGatherer*) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend void ::SkRegisterColor4ShaderFlattenable();
|
||||||
|
SK_FLATTENABLE_HOOKS(SkColor4Shader)
|
||||||
|
|
||||||
|
void flatten(SkWriteBuffer&) const override;
|
||||||
|
bool onAppendStages(const SkStageRec&) const override;
|
||||||
|
|
||||||
|
skvm::Color onProgram(skvm::Builder*, skvm::Coord device, skvm::Coord local, skvm::Color paint,
|
||||||
|
const SkMatrixProvider&, const SkMatrix* localM, const SkColorInfo& dst,
|
||||||
|
skvm::Uniforms* uniforms, SkArenaAlloc*) const override;
|
||||||
|
|
||||||
|
sk_sp<SkColorSpace> fColorSpace;
|
||||||
|
const SkColor4f fColor;
|
||||||
|
};
|
||||||
|
|
||||||
SkColorShader::SkColorShader(SkColor c) : fColor(c) {}
|
SkColorShader::SkColorShader(SkColor c) : fColor(c) {}
|
||||||
|
|
||||||
bool SkColorShader::isOpaque() const {
|
bool SkColorShader::isOpaque() const {
|
||||||
@ -73,14 +155,6 @@ void SkColor4Shader::flatten(SkWriteBuffer& buffer) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sk_sp<SkShader> SkShaders::Color(const SkColor4f& color, sk_sp<SkColorSpace> space) {
|
|
||||||
if (!SkScalarsAreFinite(color.vec(), 4)) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return sk_make_sp<SkColor4Shader>(color, std::move(space));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SkColorShader::onAppendStages(const SkStageRec& rec) const {
|
bool SkColorShader::onAppendStages(const SkStageRec& rec) const {
|
||||||
SkColor4f color = SkColor4f::FromColor(fColor);
|
SkColor4f color = SkColor4f::FromColor(fColor);
|
||||||
SkColorSpaceXformSteps(sk_srgb_singleton(), kUnpremul_SkAlphaType,
|
SkColorSpaceXformSteps(sk_srgb_singleton(), kUnpremul_SkAlphaType,
|
||||||
@ -157,3 +231,20 @@ void SkColor4Shader::addToKey(const SkKeyContext& keyContext,
|
|||||||
builder->endBlock();
|
builder->endBlock();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
sk_sp<SkShader> SkShaders::Color(SkColor color) { return sk_make_sp<SkColorShader>(color); }
|
||||||
|
|
||||||
|
sk_sp<SkShader> SkShaders::Color(const SkColor4f& color, sk_sp<SkColorSpace> space) {
|
||||||
|
if (!SkScalarsAreFinite(color.vec(), 4)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return sk_make_sp<SkColor4Shader>(color, std::move(space));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkRegisterColor4ShaderFlattenable() {
|
||||||
|
SK_REGISTER_FLATTENABLE(SkColor4Shader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkRegisterColorShaderFlattenable() {
|
||||||
|
SK_REGISTER_FLATTENABLE(SkColorShader);
|
||||||
|
}
|
||||||
|
@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2007 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by a BSD-style license that can be
|
|
||||||
* found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SkColorShader_DEFINED
|
|
||||||
#define SkColorShader_DEFINED
|
|
||||||
|
|
||||||
#include "src/shaders/SkShaderBase.h"
|
|
||||||
|
|
||||||
class SkShaderCodeDictionary;
|
|
||||||
|
|
||||||
/** \class SkColorShader
|
|
||||||
A Shader that represents a single color. In general, this effect can be
|
|
||||||
accomplished by just using the color field on the paint, but if an
|
|
||||||
actual shader object is needed, this provides that feature.
|
|
||||||
*/
|
|
||||||
class SkColorShader : public SkShaderBase {
|
|
||||||
public:
|
|
||||||
/** Create a ColorShader that ignores the color in the paint, and uses the
|
|
||||||
specified color. Note: like all shaders, at draw time the paint's alpha
|
|
||||||
will be respected, and is applied to the specified color.
|
|
||||||
*/
|
|
||||||
explicit SkColorShader(SkColor c);
|
|
||||||
|
|
||||||
bool isOpaque() const override;
|
|
||||||
bool isConstant() const override { return true; }
|
|
||||||
|
|
||||||
GradientType asAGradient(GradientInfo* info) const override;
|
|
||||||
|
|
||||||
#if SK_SUPPORT_GPU
|
|
||||||
std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SK_ENABLE_SKSL
|
|
||||||
void addToKey(const SkKeyContext&,
|
|
||||||
SkPaintParamsKeyBuilder*,
|
|
||||||
SkPipelineDataGatherer*) const override;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
|
||||||
SK_FLATTENABLE_HOOKS(SkColorShader)
|
|
||||||
|
|
||||||
void flatten(SkWriteBuffer&) const override;
|
|
||||||
|
|
||||||
bool onAsLuminanceColor(SkColor* lum) const override {
|
|
||||||
*lum = fColor;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool onAppendStages(const SkStageRec&) const override;
|
|
||||||
|
|
||||||
skvm::Color onProgram(skvm::Builder*, skvm::Coord device, skvm::Coord local, skvm::Color paint,
|
|
||||||
const SkMatrixProvider&, const SkMatrix* localM, const SkColorInfo& dst,
|
|
||||||
skvm::Uniforms* uniforms, SkArenaAlloc*) const override;
|
|
||||||
|
|
||||||
SkColor fColor;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SkColor4Shader : public SkShaderBase {
|
|
||||||
public:
|
|
||||||
SkColor4Shader(const SkColor4f&, sk_sp<SkColorSpace>);
|
|
||||||
|
|
||||||
bool isOpaque() const override { return fColor.isOpaque(); }
|
|
||||||
bool isConstant() const override { return true; }
|
|
||||||
|
|
||||||
#if SK_SUPPORT_GPU
|
|
||||||
std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
|
|
||||||
#endif
|
|
||||||
#ifdef SK_ENABLE_SKSL
|
|
||||||
void addToKey(const SkKeyContext&,
|
|
||||||
SkPaintParamsKeyBuilder*,
|
|
||||||
SkPipelineDataGatherer*) const override;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
|
||||||
SK_FLATTENABLE_HOOKS(SkColor4Shader)
|
|
||||||
|
|
||||||
void flatten(SkWriteBuffer&) const override;
|
|
||||||
bool onAppendStages(const SkStageRec&) const override;
|
|
||||||
|
|
||||||
skvm::Color onProgram(skvm::Builder*, skvm::Coord device, skvm::Coord local, skvm::Color paint,
|
|
||||||
const SkMatrixProvider&, const SkMatrix* localM, const SkColorInfo& dst,
|
|
||||||
skvm::Uniforms* uniforms, SkArenaAlloc*) const override;
|
|
||||||
|
|
||||||
sk_sp<SkColorSpace> fColorSpace;
|
|
||||||
const SkColor4f fColor;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "include/core/SkColorFilter.h"
|
#include "include/core/SkColorFilter.h"
|
||||||
|
#include "include/core/SkFlattenable.h"
|
||||||
#include "include/core/SkString.h"
|
#include "include/core/SkString.h"
|
||||||
#include "include/private/SkColorData.h"
|
#include "include/private/SkColorData.h"
|
||||||
#include "src/core/SkArenaAlloc.h"
|
#include "src/core/SkArenaAlloc.h"
|
||||||
@ -16,8 +17,6 @@
|
|||||||
#include "src/core/SkRuntimeEffectPriv.h"
|
#include "src/core/SkRuntimeEffectPriv.h"
|
||||||
#include "src/core/SkVM.h"
|
#include "src/core/SkVM.h"
|
||||||
#include "src/core/SkWriteBuffer.h"
|
#include "src/core/SkWriteBuffer.h"
|
||||||
#include "src/shaders/SkColorShader.h"
|
|
||||||
#include "src/shaders/SkComposeShader.h"
|
|
||||||
|
|
||||||
#ifdef SK_ENABLE_SKSL
|
#ifdef SK_ENABLE_SKSL
|
||||||
#include "src/core/SkKeyHelpers.h"
|
#include "src/core/SkKeyHelpers.h"
|
||||||
@ -47,31 +46,49 @@ private:
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
sk_sp<SkShader> SkShaders::Blend(SkBlendMode mode, sk_sp<SkShader> dst, sk_sp<SkShader> src) {
|
|
||||||
if (!src || !dst) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
switch (mode) {
|
|
||||||
case SkBlendMode::kClear: return Color(0);
|
|
||||||
case SkBlendMode::kDst: return dst;
|
|
||||||
case SkBlendMode::kSrc: return src;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
return sk_sp<SkShader>(new SkShader_Blend(mode, std::move(dst), std::move(src)));
|
|
||||||
}
|
|
||||||
|
|
||||||
sk_sp<SkShader> SkShaders::Blend(sk_sp<SkBlender> blender, sk_sp<SkShader> dst, sk_sp<SkShader> src) {
|
|
||||||
if (!src || !dst) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
if (!blender) {
|
|
||||||
return SkShaders::Blend(SkBlendMode::kSrcOver, std::move(dst), std::move(src));
|
|
||||||
}
|
|
||||||
return sk_sp<SkShader>(new SkShader_Blend(std::move(blender), std::move(dst), std::move(src)));
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class SkShader_Blend final : public SkShaderBase {
|
||||||
|
public:
|
||||||
|
SkShader_Blend(SkBlendMode mode, sk_sp<SkShader> dst, sk_sp<SkShader> src)
|
||||||
|
: fDst(std::move(dst))
|
||||||
|
, fSrc(std::move(src))
|
||||||
|
, fBlender(nullptr)
|
||||||
|
, fMode(mode)
|
||||||
|
{}
|
||||||
|
|
||||||
|
SkShader_Blend(sk_sp<SkBlender> blender, sk_sp<SkShader> dst, sk_sp<SkShader> src);
|
||||||
|
|
||||||
|
#if SK_SUPPORT_GPU
|
||||||
|
std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SK_ENABLE_SKSL
|
||||||
|
void addToKey(const SkKeyContext&,
|
||||||
|
SkPaintParamsKeyBuilder*,
|
||||||
|
SkPipelineDataGatherer*) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
SkShader_Blend(SkReadBuffer&);
|
||||||
|
void flatten(SkWriteBuffer&) const override;
|
||||||
|
bool onAppendStages(const SkStageRec&) const override;
|
||||||
|
skvm::Color onProgram(skvm::Builder*, skvm::Coord device, skvm::Coord local, skvm::Color paint,
|
||||||
|
const SkMatrixProvider&, const SkMatrix* localM, const SkColorInfo& dst,
|
||||||
|
skvm::Uniforms*, SkArenaAlloc*) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend void ::SkRegisterComposeShaderFlattenable();
|
||||||
|
SK_FLATTENABLE_HOOKS(SkShader_Blend)
|
||||||
|
|
||||||
|
sk_sp<SkShader> fDst;
|
||||||
|
sk_sp<SkShader> fSrc;
|
||||||
|
sk_sp<SkBlender> fBlender; // if null, use fMode
|
||||||
|
SkBlendMode fMode; // only use if fBlender is null
|
||||||
|
|
||||||
|
using INHERITED = SkShaderBase;
|
||||||
|
};
|
||||||
|
|
||||||
SkShader_Blend::SkShader_Blend(sk_sp<SkBlender> blender, sk_sp<SkShader> dst, sk_sp<SkShader> src)
|
SkShader_Blend::SkShader_Blend(sk_sp<SkBlender> blender, sk_sp<SkShader> dst, sk_sp<SkShader> src)
|
||||||
: fDst(std::move(dst))
|
: fDst(std::move(dst))
|
||||||
, fSrc(std::move(src))
|
, fSrc(std::move(src))
|
||||||
@ -209,3 +226,32 @@ void SkShader_Blend::addToKey(const SkKeyContext& keyContext,
|
|||||||
builder->endBlock();
|
builder->endBlock();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
sk_sp<SkShader> SkShaders::Blend(SkBlendMode mode, sk_sp<SkShader> dst, sk_sp<SkShader> src) {
|
||||||
|
if (!src || !dst) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
switch (mode) {
|
||||||
|
case SkBlendMode::kClear: return Color(0);
|
||||||
|
case SkBlendMode::kDst: return dst;
|
||||||
|
case SkBlendMode::kSrc: return src;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return sk_sp<SkShader>(new SkShader_Blend(mode, std::move(dst), std::move(src)));
|
||||||
|
}
|
||||||
|
|
||||||
|
sk_sp<SkShader> SkShaders::Blend(sk_sp<SkBlender> blender,
|
||||||
|
sk_sp<SkShader> dst,
|
||||||
|
sk_sp<SkShader> src) {
|
||||||
|
if (!src || !dst) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
if (!blender) {
|
||||||
|
return SkShaders::Blend(SkBlendMode::kSrcOver, std::move(dst), std::move(src));
|
||||||
|
}
|
||||||
|
return sk_sp<SkShader>(new SkShader_Blend(std::move(blender), std::move(dst), std::move(src)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkRegisterComposeShaderFlattenable() {
|
||||||
|
SK_REGISTER_FLATTENABLE(SkShader_Blend);
|
||||||
|
}
|
||||||
|
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2006 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by a BSD-style license that can be
|
|
||||||
* found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SkComposeShader_DEFINED
|
|
||||||
#define SkComposeShader_DEFINED
|
|
||||||
|
|
||||||
#include "include/core/SkBlendMode.h"
|
|
||||||
#include "src/core/SkBlendModePriv.h"
|
|
||||||
#include "src/core/SkBlenderBase.h"
|
|
||||||
#include "src/shaders/SkShaderBase.h"
|
|
||||||
|
|
||||||
class SkShaderCodeDictionary;
|
|
||||||
|
|
||||||
class SkShader_Blend final : public SkShaderBase {
|
|
||||||
public:
|
|
||||||
SkShader_Blend(SkBlendMode mode, sk_sp<SkShader> dst, sk_sp<SkShader> src)
|
|
||||||
: fDst(std::move(dst))
|
|
||||||
, fSrc(std::move(src))
|
|
||||||
, fBlender(nullptr)
|
|
||||||
, fMode(mode)
|
|
||||||
{}
|
|
||||||
|
|
||||||
SkShader_Blend(sk_sp<SkBlender> blender, sk_sp<SkShader> dst, sk_sp<SkShader> src);
|
|
||||||
|
|
||||||
#if SK_SUPPORT_GPU
|
|
||||||
std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SK_ENABLE_SKSL
|
|
||||||
void addToKey(const SkKeyContext&,
|
|
||||||
SkPaintParamsKeyBuilder*,
|
|
||||||
SkPipelineDataGatherer*) const override;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
|
||||||
SkShader_Blend(SkReadBuffer&);
|
|
||||||
void flatten(SkWriteBuffer&) const override;
|
|
||||||
bool onAppendStages(const SkStageRec&) const override;
|
|
||||||
skvm::Color onProgram(skvm::Builder*, skvm::Coord device, skvm::Coord local, skvm::Color paint,
|
|
||||||
const SkMatrixProvider&, const SkMatrix* localM, const SkColorInfo& dst,
|
|
||||||
skvm::Uniforms*, SkArenaAlloc*) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
SK_FLATTENABLE_HOOKS(SkShader_Blend)
|
|
||||||
|
|
||||||
sk_sp<SkShader> fDst;
|
|
||||||
sk_sp<SkShader> fSrc;
|
|
||||||
sk_sp<SkBlender> fBlender; // if null, use fMode
|
|
||||||
SkBlendMode fMode; // only use if fBlender is null
|
|
||||||
|
|
||||||
using INHERITED = SkShaderBase;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,16 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011 Google Inc.
|
* Copyright 2022 Google LLC
|
||||||
*
|
*
|
||||||
* Use of this source code is governed by a BSD-style license that can be
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
* found in the LICENSE file.
|
* found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SkEmptyShader_DEFINED
|
|
||||||
#define SkEmptyShader_DEFINED
|
|
||||||
|
|
||||||
#include "src/shaders/SkShaderBase.h"
|
#include "src/shaders/SkShaderBase.h"
|
||||||
|
|
||||||
// TODO: move this to private, as there is a public factory on SkShader
|
#include "include/core/SkFlattenable.h"
|
||||||
|
#include "src/core/SkVM.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \class SkEmptyShader
|
* \class SkEmptyShader
|
||||||
@ -42,9 +40,24 @@ protected:
|
|||||||
skvm::Uniforms*, SkArenaAlloc*) const override;
|
skvm::Uniforms*, SkArenaAlloc*) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend void ::SkRegisterEmptyShaderFlattenable();
|
||||||
SK_FLATTENABLE_HOOKS(SkEmptyShader)
|
SK_FLATTENABLE_HOOKS(SkEmptyShader)
|
||||||
|
|
||||||
using INHERITED = SkShaderBase;
|
using INHERITED = SkShaderBase;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
skvm::Color SkEmptyShader::onProgram(skvm::Builder*, skvm::Coord, skvm::Coord, skvm::Color,
|
||||||
|
const SkMatrixProvider&, const SkMatrix*, const SkColorInfo&,
|
||||||
|
skvm::Uniforms*, SkArenaAlloc*) const {
|
||||||
|
return {}; // signal failure
|
||||||
|
}
|
||||||
|
|
||||||
|
sk_sp<SkFlattenable> SkEmptyShader::CreateProc(SkReadBuffer&) {
|
||||||
|
return SkShaders::Empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
sk_sp<SkShader> SkShaders::Empty() { return sk_make_sp<SkEmptyShader>(); }
|
||||||
|
|
||||||
|
void SkRegisterEmptyShaderFlattenable() {
|
||||||
|
SK_REGISTER_FLATTENABLE(SkEmptyShader);
|
||||||
|
}
|
@ -21,7 +21,6 @@
|
|||||||
#include "src/core/SkWriteBuffer.h"
|
#include "src/core/SkWriteBuffer.h"
|
||||||
#include "src/image/SkImage_Base.h"
|
#include "src/image/SkImage_Base.h"
|
||||||
#include "src/shaders/SkBitmapProcShader.h"
|
#include "src/shaders/SkBitmapProcShader.h"
|
||||||
#include "src/shaders/SkEmptyShader.h"
|
|
||||||
#include "src/shaders/SkTransformShader.h"
|
#include "src/shaders/SkTransformShader.h"
|
||||||
|
|
||||||
#ifdef SK_ENABLE_SKSL
|
#ifdef SK_ENABLE_SKSL
|
||||||
@ -301,7 +300,7 @@ sk_sp<SkShader> SkImageShader::MakeRaw(sk_sp<SkImage> image,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (!image) {
|
if (!image) {
|
||||||
return sk_make_sp<SkEmptyShader>();
|
return SkShaders::Empty();
|
||||||
}
|
}
|
||||||
return sk_sp<SkShader>{new SkImageShader(
|
return sk_sp<SkShader>{new SkImageShader(
|
||||||
image, SkRect::Make(image->dimensions()), tmx, tmy, options, localMatrix,
|
image, SkRect::Make(image->dimensions()), tmx, tmy, options, localMatrix,
|
||||||
@ -323,7 +322,7 @@ sk_sp<SkShader> SkImageShader::MakeSubset(sk_sp<SkImage> image,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!image || subset.isEmpty()) {
|
if (!image || subset.isEmpty()) {
|
||||||
return sk_make_sp<SkEmptyShader>();
|
return SkShaders::Empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate subset and check if we can drop it
|
// Validate subset and check if we can drop it
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#include "include/core/SkMallocPixelRef.h"
|
#include "include/core/SkMallocPixelRef.h"
|
||||||
#include "include/core/SkPaint.h"
|
#include "include/core/SkPaint.h"
|
||||||
#include "include/core/SkPicture.h"
|
|
||||||
#include "include/core/SkScalar.h"
|
#include "include/core/SkScalar.h"
|
||||||
#include "src/core/SkArenaAlloc.h"
|
#include "src/core/SkArenaAlloc.h"
|
||||||
#include "src/core/SkColorSpacePriv.h"
|
#include "src/core/SkColorSpacePriv.h"
|
||||||
@ -16,13 +15,9 @@
|
|||||||
#include "src/core/SkRasterPipeline.h"
|
#include "src/core/SkRasterPipeline.h"
|
||||||
#include "src/core/SkReadBuffer.h"
|
#include "src/core/SkReadBuffer.h"
|
||||||
#include "src/core/SkTLazy.h"
|
#include "src/core/SkTLazy.h"
|
||||||
#include "src/core/SkVM.h"
|
|
||||||
#include "src/core/SkWriteBuffer.h"
|
#include "src/core/SkWriteBuffer.h"
|
||||||
#include "src/shaders/SkBitmapProcShader.h"
|
#include "src/shaders/SkBitmapProcShader.h"
|
||||||
#include "src/shaders/SkColorShader.h"
|
|
||||||
#include "src/shaders/SkEmptyShader.h"
|
|
||||||
#include "src/shaders/SkImageShader.h"
|
#include "src/shaders/SkImageShader.h"
|
||||||
#include "src/shaders/SkPictureShader.h"
|
|
||||||
#include "src/shaders/SkShaderBase.h"
|
#include "src/shaders/SkShaderBase.h"
|
||||||
#include "src/shaders/SkTransformShader.h"
|
#include "src/shaders/SkTransformShader.h"
|
||||||
|
|
||||||
@ -163,9 +158,6 @@ void SkShaderBase::addToKey(const SkKeyContext& keyContext,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sk_sp<SkShader> SkShaders::Empty() { return sk_make_sp<SkEmptyShader>(); }
|
|
||||||
sk_sp<SkShader> SkShaders::Color(SkColor color) { return sk_make_sp<SkColorShader>(color); }
|
|
||||||
|
|
||||||
sk_sp<SkShader> SkBitmap::makeShader(SkTileMode tmx, SkTileMode tmy,
|
sk_sp<SkShader> SkBitmap::makeShader(SkTileMode tmx, SkTileMode tmy,
|
||||||
const SkSamplingOptions& sampling,
|
const SkSamplingOptions& sampling,
|
||||||
const SkMatrix* lm) const {
|
const SkMatrix* lm) const {
|
||||||
@ -289,15 +281,3 @@ skvm::Coord SkShaderBase::ApplyMatrix(skvm::Builder* p, const SkMatrix& m,
|
|||||||
}
|
}
|
||||||
return {x,y};
|
return {x,y};
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
skvm::Color SkEmptyShader::onProgram(skvm::Builder*, skvm::Coord, skvm::Coord, skvm::Color,
|
|
||||||
const SkMatrixProvider&, const SkMatrix*, const SkColorInfo&,
|
|
||||||
skvm::Uniforms*, SkArenaAlloc*) const {
|
|
||||||
return {}; // signal failure
|
|
||||||
}
|
|
||||||
|
|
||||||
sk_sp<SkFlattenable> SkEmptyShader::CreateProc(SkReadBuffer&) {
|
|
||||||
return SkShaders::Empty();
|
|
||||||
}
|
|
||||||
|
@ -304,4 +304,9 @@ inline const SkShaderBase* as_SB(const sk_sp<SkShader>& shader) {
|
|||||||
return static_cast<SkShaderBase*>(shader.get());
|
return static_cast<SkShaderBase*>(shader.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SkRegisterColor4ShaderFlattenable();
|
||||||
|
void SkRegisterColorShaderFlattenable();
|
||||||
|
void SkRegisterComposeShaderFlattenable();
|
||||||
|
void SkRegisterEmptyShaderFlattenable();
|
||||||
|
|
||||||
#endif // SkShaderBase_DEFINED
|
#endif // SkShaderBase_DEFINED
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "src/core/SkMatrixProvider.h"
|
#include "src/core/SkMatrixProvider.h"
|
||||||
#include "src/core/SkTLazy.h"
|
#include "src/core/SkTLazy.h"
|
||||||
#include "src/gpu/ganesh/GrColorInfo.h"
|
#include "src/gpu/ganesh/GrColorInfo.h"
|
||||||
#include "src/shaders/SkColorShader.h"
|
|
||||||
#include "tests/Test.h"
|
#include "tests/Test.h"
|
||||||
|
|
||||||
// https://code.google.com/p/chromium/issues/detail?id=448299
|
// https://code.google.com/p/chromium/issues/detail?id=448299
|
||||||
@ -77,7 +76,7 @@ static void none_gradproc(skiatest::Reporter* reporter, const GradRec&, const Gr
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void color_gradproc(skiatest::Reporter* reporter, const GradRec& rec, const GradRec&) {
|
static void color_gradproc(skiatest::Reporter* reporter, const GradRec& rec, const GradRec&) {
|
||||||
sk_sp<SkShader> s(new SkColorShader(rec.fColors[0]));
|
sk_sp<SkShader> s(SkShaders::Color(rec.fColors[0]));
|
||||||
REPORTER_ASSERT(reporter, SkShader::kColor_GradientType == s->asAGradient(nullptr));
|
REPORTER_ASSERT(reporter, SkShader::kColor_GradientType == s->asAGradient(nullptr));
|
||||||
|
|
||||||
SkShader::GradientInfo info;
|
SkShader::GradientInfo info;
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include "include/core/SkShader.h"
|
#include "include/core/SkShader.h"
|
||||||
#include "include/core/SkSurface.h"
|
#include "include/core/SkSurface.h"
|
||||||
#include "include/effects/SkGradientShader.h"
|
#include "include/effects/SkGradientShader.h"
|
||||||
#include "src/shaders/SkColorShader.h"
|
|
||||||
#include "tests/Test.h"
|
#include "tests/Test.h"
|
||||||
#include "tools/ToolUtils.h"
|
#include "tools/ToolUtils.h"
|
||||||
|
|
||||||
@ -85,12 +84,12 @@ static void test_gradient(skiatest::Reporter* reporter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_color(skiatest::Reporter* reporter) {
|
static void test_color(skiatest::Reporter* reporter) {
|
||||||
SkColorShader colorShader1(SkColorSetARGB(0,0,0,0));
|
sk_sp<SkShader> colorShader1 = SkShaders::Color(SkColorSetARGB(0,0,0,0));
|
||||||
REPORTER_ASSERT(reporter, !colorShader1.isOpaque());
|
REPORTER_ASSERT(reporter, !colorShader1->isOpaque());
|
||||||
SkColorShader colorShader2(SkColorSetARGB(0xFF,0,0,0));
|
sk_sp<SkShader> colorShader2 = SkShaders::Color(SkColorSetARGB(0xFF,0,0,0));
|
||||||
REPORTER_ASSERT(reporter, colorShader2.isOpaque());
|
REPORTER_ASSERT(reporter, colorShader2->isOpaque());
|
||||||
SkColorShader colorShader3(SkColorSetARGB(0x7F,0,0,0));
|
sk_sp<SkShader> colorShader3 = SkShaders::Color(SkColorSetARGB(0x7F,0,0,0));
|
||||||
REPORTER_ASSERT(reporter, !colorShader3.isOpaque());
|
REPORTER_ASSERT(reporter, !colorShader3->isOpaque());
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_TEST(ShaderOpacity, reporter) {
|
DEF_TEST(ShaderOpacity, reporter) {
|
||||||
|
Loading…
Reference in New Issue
Block a user