• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 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 "include/gpu/graphite/precompile/PrecompileBlender.h"
9 
10 #include "src/core/SkKnownRuntimeEffects.h"
11 #include "src/gpu/graphite/FactoryFunctions.h"
12 #include "src/gpu/graphite/PaintParams.h"
13 
14 namespace skgpu::graphite {
15 
16 PrecompileBlender::~PrecompileBlender() = default;
17 
18 //--------------------------------------------------------------------------------------------------
19 class PrecompileBlendModeBlender final : public PrecompileBlender {
20 public:
PrecompileBlendModeBlender(SkBlendMode blendMode)21     PrecompileBlendModeBlender(SkBlendMode blendMode) : fBlendMode(blendMode) {}
22 
23 protected:
asBlendMode() const24     std::optional<SkBlendMode> asBlendMode() const final { return fBlendMode; }
25 
addToKey(const KeyContext & keyContext,PaintParamsKeyBuilder * builder,PipelineDataGatherer * gatherer,int desiredCombination) const26     void addToKey(const KeyContext& keyContext,
27                   PaintParamsKeyBuilder* builder,
28                   PipelineDataGatherer* gatherer,
29                   int desiredCombination) const final {
30         SkASSERT(desiredCombination == 0); // The blend mode blender only ever has one combination
31 
32         AddModeBlend(keyContext, builder, gatherer, fBlendMode);
33     }
34 
35 private:
36     SkBlendMode fBlendMode;
37 };
38 
Mode(SkBlendMode blendMode)39 sk_sp<PrecompileBlender> PrecompileBlenders::Mode(SkBlendMode blendMode) {
40     return sk_make_sp<PrecompileBlendModeBlender>(blendMode);
41 }
42 
43 //--------------------------------------------------------------------------------------------------
Arithmetic()44 sk_sp<PrecompileBlender> PrecompileBlenders::Arithmetic() {
45     const SkRuntimeEffect* arithmeticEffect =
46             GetKnownRuntimeEffect(SkKnownRuntimeEffects::StableKey::kArithmetic);
47 
48     return MakePrecompileBlender(sk_ref_sp(arithmeticEffect));
49 }
50 
51 } // namespace skgpu::graphite
52