| 1 |
/* |
| 2 |
* Copyright 2022 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "src/gpu/graphite/KeyContext.h" |
| 9 |
|
| 10 |
#include "include/effects/SkRuntimeEffect.h" |
| 11 |
#include "src/core/SkRuntimeEffectPriv.h" |
| 12 |
#include "src/gpu/graphite/DrawContext.h" |
| 13 |
#include "src/gpu/graphite/PaintParams.h" |
| 14 |
#include "src/gpu/graphite/RecorderPriv.h" |
| 15 |
#include "src/gpu/graphite/RuntimeEffectDictionary.h" |
| 16 |
|
| 17 |
namespace skgpu::graphite { |
| 18 |
|
| 19 |
KeyContext::KeyContext(const Caps* caps, |
| 20 |
FloatStorageManager* floatStorageManager, |
| 21 |
PaintParamsKeyBuilder* paintParamsKeyBuilder, |
| 22 |
PipelineDataGatherer* pipelineDataGatherer, |
| 23 |
ShaderCodeDictionary* dict, |
| 24 |
sk_sp<RuntimeEffectDictionary> rtEffectDict, |
| 25 |
const SkColorInfo& dstColorInfo) |
| 26 |
: fCaps(caps) |
| 27 |
, fRecorder(nullptr) |
| 28 |
, fFloatStorageManager(floatStorageManager) |
| 29 |
, fPaintParamsKeyBuilder(paintParamsKeyBuilder) |
| 30 |
, fPipelineDataGatherer(pipelineDataGatherer) |
| 31 |
, fDictionary(dict) |
| 32 |
, fRTEffectDict(std::move(rtEffectDict)) |
| 33 |
, fDstColorInfo(dstColorInfo) {} |
| 34 |
|
| 35 |
KeyContext::KeyContext(skgpu::graphite::Recorder* recorder, |
| 36 |
DrawContext* drawContext, |
| 37 |
FloatStorageManager* floatStorageManager, |
| 38 |
PaintParamsKeyBuilder* paintParamsKeyBuilder, |
| 39 |
PipelineDataGatherer* pipelineDataGatherer, |
| 40 |
const SkM44& local2Dev, |
| 41 |
const SkColorInfo& dstColorInfo, |
| 42 |
SkEnumBitMask<KeyGenFlags> initialFlags, |
| 43 |
const SkColor4f& paintColor) |
| 44 |
: fCaps(recorder->priv().caps()) |
| 45 |
, fRecorder(recorder) |
| 46 |
, fDC(drawContext) |
| 47 |
, fFloatStorageManager(floatStorageManager) |
| 48 |
, fPaintParamsKeyBuilder(paintParamsKeyBuilder) |
| 49 |
, fPipelineDataGatherer(pipelineDataGatherer) |
| 50 |
, fDictionary(recorder->priv().shaderCodeDictionary()) |
| 51 |
, fRTEffectDict(recorder->priv().runtimeEffectDictionary()) |
| 52 |
, fLocal2Dev(local2Dev) |
| 53 |
, fLocalMatrix(nullptr) |
| 54 |
, fDstColorInfo(dstColorInfo) |
| 55 |
, fKeyGenFlags(initialFlags) {\ |
| 56 |
fPaintColor = PaintParams::Color4fPrepForDst(paintColor, fDstColorInfo).makeOpaque().premul(); |
| 57 |
fPaintColor.fA = paintColor.fA; |
| 58 |
} |
| 59 |
|
| 60 |
KeyContext::KeyContext(const KeyContext& other, |
| 61 |
SkEnumBitMask<KeyGenFlags> xtraFlags) |
| 62 |
: fCaps(other.fCaps) |
| 63 |
, fRecorder(other.fRecorder) |
| 64 |
, fDC(other.fDC) |
| 65 |
, fFloatStorageManager(other.fFloatStorageManager) |
| 66 |
, fPaintParamsKeyBuilder(other.fPaintParamsKeyBuilder) |
| 67 |
, fPipelineDataGatherer(other.fPipelineDataGatherer) |
| 68 |
, fDictionary(other.fDictionary) |
| 69 |
, fRTEffectDict(other.fRTEffectDict) |
| 70 |
, fLocal2Dev(other.fLocal2Dev) |
| 71 |
, fLocalMatrix(other.fLocalMatrix) |
| 72 |
, fDstColorInfo(other.fDstColorInfo) |
| 73 |
, fPaintColor(other.fPaintColor) |
| 74 |
, fKeyGenFlags(other.fKeyGenFlags | xtraFlags) {} |
| 75 |
|
| 76 |
KeyContext::~KeyContext() {} |
| 77 |
|
| 78 |
sk_sp<RuntimeEffectDictionary> KeyContext::rtEffectDict() const { return fRTEffectDict; } |
| 79 |
|
| 80 |
KeyContext KeyContext::forRuntimeEffect(const SkRuntimeEffect* effect, int child) const { |
| 81 |
// Runtime effects always disable paint-color colorization of alpha-only image shaders |
| 82 |
SkEnumBitMask<KeyGenFlags> xtraFlags = KeyGenFlags::kDisableAlphaOnlyImageColorization; |
| 83 |
|
| 84 |
if (SkRuntimeEffectPriv::ChildSampleUsage(effect, child).isExplicit()) { |
| 85 |
// Assume explicit sampling as a proxy for either a likely data lookup (e.g. raw shader) |
| 86 |
// or an effect that might sample the child many times. This means it's worth using |
| 87 |
// eliding colorspace conversions, and we have to disable sampling optimization. |
| 88 |
xtraFlags |= KeyGenFlags::kEnableIdentityColorSpaceXform | |
| 89 |
KeyGenFlags::kDisableSamplingOptimization; |
| 90 |
} |
| 91 |
|
| 92 |
return this->withExtraFlags(xtraFlags); |
| 93 |
} |
| 94 |
|
| 95 |
} // namespace skgpu::graphite |