[graphite] Add addToKey entry points
Bug: skia:12701 Change-Id: Id6ce588c28413b32b864f22cec73a5e90a9ec376 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/494756 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
466df1e697
commit
abd6cf13f4
@ -8,6 +8,9 @@
|
||||
#include "experimental/graphite/src/PaintParams.h"
|
||||
|
||||
#include "include/core/SkShader.h"
|
||||
#include "include/private/SkPaintParamsKey.h"
|
||||
#include "src/core/SkKeyHelpers.h"
|
||||
#include "src/shaders/SkShaderBase.h"
|
||||
|
||||
namespace skgpu {
|
||||
|
||||
@ -29,4 +32,22 @@ PaintParams& PaintParams::operator=(const PaintParams& other) = default;
|
||||
|
||||
sk_sp<SkShader> PaintParams::refShader() const { return fShader; }
|
||||
|
||||
void PaintParams::toKey(SkShaderCodeDictionary* dict,
|
||||
SkBackend backend,
|
||||
SkPaintParamsKey* key) const {
|
||||
|
||||
if (fShader) {
|
||||
as_SB(fShader)->addToKey(dict, backend, key);
|
||||
} else {
|
||||
SolidColorShaderBlock::AddToKey(key);
|
||||
}
|
||||
|
||||
// TODO: add blender support to PaintParams
|
||||
{
|
||||
BlendModeBlock::AddToKey(key, fBlendMode);
|
||||
}
|
||||
|
||||
SkASSERT(key->sizeInBytes() > 0);
|
||||
}
|
||||
|
||||
} // namespace skgpu
|
||||
|
@ -11,7 +11,10 @@
|
||||
#include "include/core/SkColor.h"
|
||||
#include "include/core/SkPaint.h"
|
||||
|
||||
enum class SkBackend : uint8_t;
|
||||
class SkPaintParamsKey;
|
||||
class SkShader;
|
||||
class SkShaderCodeDictionary;
|
||||
|
||||
namespace skgpu {
|
||||
|
||||
@ -36,6 +39,10 @@ public:
|
||||
SkShader* shader() const { return fShader.get(); }
|
||||
sk_sp<SkShader> refShader() const;
|
||||
|
||||
void toKey(SkShaderCodeDictionary*,
|
||||
SkBackend,
|
||||
SkPaintParamsKey*) const;
|
||||
|
||||
private:
|
||||
SkColor4f fColor;
|
||||
SkBlendMode fBlendMode;
|
||||
|
@ -12,6 +12,12 @@
|
||||
#include <limits>
|
||||
#include "include/core/SkTypes.h"
|
||||
|
||||
enum class SkBackend : uint8_t {
|
||||
kGanesh,
|
||||
kGraphite,
|
||||
kSkVM
|
||||
};
|
||||
|
||||
// TODO: this needs to be expanded into a more flexible dictionary (esp. for user-supplied SkSL)
|
||||
// TODO: should this enum actually be in ShaderCodeDictionary.h?
|
||||
enum class CodeSnippetID : uint8_t {
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "src/core/SkBlendModeBlender.h"
|
||||
#include "src/core/SkKeyHelpers.h"
|
||||
#include "src/core/SkReadBuffer.h"
|
||||
#include "src/core/SkWriteBuffer.h"
|
||||
|
||||
@ -59,6 +60,17 @@ sk_sp<SkBlender> SkBlender::Mode(SkBlendMode mode) {
|
||||
#undef RETURN_SINGLETON_BLENDER
|
||||
}
|
||||
|
||||
void SkBlenderBase::addToKey(SkShaderCodeDictionary* dict,
|
||||
SkBackend backend,
|
||||
SkPaintParamsKey* key) const {
|
||||
|
||||
if (skstd::optional<SkBlendMode> bm = as_BB(this)->asBlendMode(); bm.has_value()) {
|
||||
BlendModeBlock::AddToKey(key, bm.value());
|
||||
} else {
|
||||
BlendModeBlock::AddToKey(key, SkBlendMode::kSrcOver);
|
||||
}
|
||||
}
|
||||
|
||||
sk_sp<SkFlattenable> SkBlendModeBlender::CreateProc(SkReadBuffer& buffer) {
|
||||
SkBlendMode mode = buffer.read32LE(SkBlendMode::kLastMode);
|
||||
return SkBlender::Mode(mode);
|
||||
|
@ -14,9 +14,12 @@
|
||||
#include "src/core/SkArenaAlloc.h"
|
||||
#include "src/core/SkVM.h"
|
||||
|
||||
enum class SkBackend : uint8_t;
|
||||
struct GrFPArgs;
|
||||
class GrFragmentProcessor;
|
||||
class SkPaintParamsKey;
|
||||
class SkRuntimeEffect;
|
||||
class SkShaderCodeDictionary;
|
||||
|
||||
/**
|
||||
* Encapsulates a blend function, including non-public APIs.
|
||||
@ -52,6 +55,11 @@ public:
|
||||
|
||||
virtual SkRuntimeEffect* asRuntimeEffect() const { return nullptr; }
|
||||
|
||||
// TODO: make pure virtual
|
||||
virtual void addToKey(SkShaderCodeDictionary*,
|
||||
SkBackend,
|
||||
SkPaintParamsKey*) const;
|
||||
|
||||
static SkFlattenable::Type GetFlattenableType() { return kSkBlender_Type; }
|
||||
Type getFlattenableType() const override { return GetFlattenableType(); }
|
||||
|
||||
|
@ -6,8 +6,11 @@
|
||||
*/
|
||||
|
||||
#include "include/core/SkPaint.h"
|
||||
#include "include/private/SkPaintParamsKey.h"
|
||||
#include "src/core/SkBlenderBase.h"
|
||||
#include "src/core/SkColorFilterBase.h"
|
||||
#include "src/core/SkColorSpacePriv.h"
|
||||
#include "src/core/SkKeyHelpers.h"
|
||||
#include "src/core/SkPaintPriv.h"
|
||||
#include "src/core/SkXfermodePriv.h"
|
||||
#include "src/shaders/SkColorFilterShader.h"
|
||||
@ -119,3 +122,33 @@ SkScalar SkPaintPriv::ComputeResScaleForStroking(const SkMatrix& matrix) {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::vector<SkPaintParamsKey> SkPaintPriv::ToKeys(const SkPaint& paint,
|
||||
SkShaderCodeDictionary* dict,
|
||||
SkBackend backend) {
|
||||
std::vector<SkPaintParamsKey> keys;
|
||||
|
||||
// TODO: actually split the SkPaint into multiple PaintParams and generate the keys
|
||||
// for them separately.
|
||||
{
|
||||
SkPaintParamsKey key;
|
||||
|
||||
if (paint.getShader()) {
|
||||
as_SB(paint.getShader())->addToKey(dict, backend, &key);
|
||||
} else {
|
||||
SolidColorShaderBlock::AddToKey(&key);
|
||||
}
|
||||
|
||||
if (paint.getBlender()) {
|
||||
as_BB(paint.getBlender())->addToKey(dict, backend, &key);
|
||||
} else {
|
||||
BlendModeBlock::AddToKey(&key, SkBlendMode::kSrcOver);
|
||||
}
|
||||
|
||||
SkASSERT(key.sizeInBytes() > 0);
|
||||
|
||||
keys.push_back(key);
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
@ -10,7 +10,12 @@
|
||||
|
||||
#include "include/core/SkPaint.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
enum class SkBackend : uint8_t;
|
||||
class SkPaintParamsKey;
|
||||
class SkReadBuffer;
|
||||
class SkShaderCodeDictionary;
|
||||
class SkWriteBuffer;
|
||||
|
||||
class SkPaintPriv {
|
||||
@ -58,6 +63,18 @@ public:
|
||||
static void RemoveColorFilter(SkPaint*, SkColorSpace* dstCS);
|
||||
|
||||
static SkScalar ComputeResScaleForStroking(const SkMatrix&);
|
||||
|
||||
/**
|
||||
Return the SkPaintParamsKeys that would be needed to draw the provided paint.
|
||||
|
||||
@param paint the paint to be decomposed
|
||||
@param dictionary dictionary of code fragments available to be used in the SkPaintParamKeys
|
||||
@param backend the backend that would be carrying out the drawing
|
||||
@return the SkPaintParamsKeys that would be needed to draw this paint
|
||||
*/
|
||||
static std::vector<SkPaintParamsKey> ToKeys(const SkPaint& paint,
|
||||
SkShaderCodeDictionary* dictionary,
|
||||
SkBackend backend);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "src/core/SkArenaAlloc.h"
|
||||
#include "src/core/SkColorSpacePriv.h"
|
||||
#include "src/core/SkColorSpaceXformSteps.h"
|
||||
#include "src/core/SkKeyHelpers.h"
|
||||
#include "src/core/SkMatrixProvider.h"
|
||||
#include "src/core/SkRasterPipeline.h"
|
||||
#include "src/core/SkReadBuffer.h"
|
||||
@ -148,6 +149,13 @@ SkUpdatableShader* SkShaderBase::onUpdatableShader(SkArenaAlloc* alloc) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// TODO: add implementations for derived classes
|
||||
void SkShaderBase::addToKey(SkShaderCodeDictionary* dictionary,
|
||||
SkBackend backend,
|
||||
SkPaintParamsKey* key) const {
|
||||
SolidColorShaderBlock::AddToKey(key);
|
||||
}
|
||||
|
||||
sk_sp<SkShader> SkShaders::Empty() { return sk_make_sp<SkEmptyShader>(); }
|
||||
sk_sp<SkShader> SkShaders::Color(SkColor color) { return sk_make_sp<SkColorShader>(color); }
|
||||
|
||||
|
@ -24,12 +24,15 @@
|
||||
|
||||
class GrFragmentProcessor;
|
||||
class SkArenaAlloc;
|
||||
enum class SkBackend : uint8_t;
|
||||
class SkColorSpace;
|
||||
class SkImage;
|
||||
struct SkImageInfo;
|
||||
class SkPaint;
|
||||
class SkPaintParamsKey;
|
||||
class SkRasterPipeline;
|
||||
class SkRuntimeEffect;
|
||||
class SkShaderCodeDictionary;
|
||||
class SkStageUpdater;
|
||||
|
||||
class SkUpdatableShader;
|
||||
@ -209,6 +212,19 @@ public:
|
||||
const SkMatrixProvider&, const SkMatrix* localM, const SkColorInfo& dst,
|
||||
skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const;
|
||||
|
||||
|
||||
/**
|
||||
Add implementation details, for the specified backend, of this SkShader to the
|
||||
provided key.
|
||||
|
||||
@param dictionary dictionary of code fragments available to be used in the key
|
||||
@param backend the backend that would be carrying out the drawing
|
||||
@param key destination for implementation details of this SkShader
|
||||
*/
|
||||
virtual void addToKey(SkShaderCodeDictionary* dictionary,
|
||||
SkBackend backend,
|
||||
SkPaintParamsKey* key) const;
|
||||
|
||||
protected:
|
||||
SkShaderBase(const SkMatrix* localMatrix = nullptr);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user