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 #ifndef skgpu_graphite_PaintOptionsPriv_DEFINED
9 #define skgpu_graphite_PaintOptionsPriv_DEFINED
10
11 #include "include/gpu/graphite/precompile/PaintOptions.h"
12
13 namespace skgpu::graphite {
14
15 class ShaderCodeDictionary;
16
17 /** Class that exposes methods in PaintOptions that are only intended for use internal to Skia.
18 This class is purely a privileged window into PaintOptions. It should never have additional
19 data members or virtual methods. */
20 class PaintOptionsPriv {
21 public:
22 using ProcessCombination = PaintOptions::ProcessCombination;
23
24 void addColorFilter(sk_sp<PrecompileColorFilter> cf);
25
setClipShaders(SkSpan<const sk_sp<PrecompileShader>> clipShaders)26 void setClipShaders(SkSpan<const sk_sp<PrecompileShader>> clipShaders) {
27 fPaintOptions->setClipShaders(std::move(clipShaders));
28 }
29
numCombinations()30 int numCombinations() const {
31 return fPaintOptions->numCombinations();
32 }
33
buildCombinations(const KeyContext & keyContext,PipelineDataGatherer * gatherer,DrawTypeFlags drawTypes,bool withPrimitiveBlender,Coverage coverage,const RenderPassDesc & renderPassDesc,const ProcessCombination & processCombination)34 void buildCombinations(
35 const KeyContext& keyContext,
36 PipelineDataGatherer* gatherer,
37 DrawTypeFlags drawTypes,
38 bool withPrimitiveBlender,
39 Coverage coverage,
40 const RenderPassDesc& renderPassDesc,
41 const ProcessCombination& processCombination) const {
42 fPaintOptions->buildCombinations(
43 keyContext, gatherer, drawTypes, withPrimitiveBlender, coverage,
44 renderPassDesc, processCombination);
45 }
46
47 private:
48 friend class PaintOptions; // to construct/copy this type.
49
PaintOptionsPriv(PaintOptions * paintOptions)50 explicit PaintOptionsPriv(PaintOptions* paintOptions) : fPaintOptions(paintOptions) {}
51
52 PaintOptionsPriv& operator=(const PaintOptionsPriv&) = delete;
53
54 // No taking addresses of this type.
55 const PaintOptionsPriv* operator&() const;
56 PaintOptionsPriv *operator&();
57
58 PaintOptions* fPaintOptions;
59 };
60
priv()61 inline PaintOptionsPriv PaintOptions::priv() { return PaintOptionsPriv(this); }
62
63 // NOLINTNEXTLINE(readability-const-return-type)
priv()64 inline const PaintOptionsPriv PaintOptions::priv() const {
65 return PaintOptionsPriv(const_cast<PaintOptions *>(this));
66 }
67
68 } // namespace skgpu::graphite
69
70 #endif // skgpu_graphite_PaintOptionsPriv_DEFINED
71