• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 Google Inc.
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 GrAAFillRRectOp_DEFINED
9 #define GrAAFillRRectOp_DEFINED
10 
11 #include "GrDrawOp.h"
12 
13 class GrAAFillRRectOp : public GrDrawOp {
14 public:
15     DEFINE_OP_CLASS_ID
16 
17     static std::unique_ptr<GrAAFillRRectOp> Make(GrContext*, const SkMatrix&, const SkRRect&,
18                                                  const GrCaps&, GrPaint&&);
19 
name()20     const char* name() const override { return "GrAAFillRRectOp"; }
fixedFunctionFlags()21     FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
22     GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*) override;
23     CombineResult onCombineIfPossible(GrOp*, const GrCaps&) override;
visitProxies(const VisitProxyFunc & fn,VisitorType)24     void visitProxies(const VisitProxyFunc& fn, VisitorType) const override {
25         fProcessors.visitProxies(fn);
26     }
27     void onPrepare(GrOpFlushState*) override;
28 
29     void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
30 
31 private:
32     enum class Flags {
33         kNone = 0,
34         kUseHWDerivatives = 1 << 0,
35         kHasLocalCoords = 1 << 1
36     };
37 
38     GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags)
39 
40     class Processor;
41 
42     GrAAFillRRectOp(const GrShaderCaps&, const SkMatrix&, const SkRRect&, GrPaint&&);
43 
44     // These methods are used to append data of various POD types to our internal array of instance
45     // data. The actual layout of the instance buffer can vary from Op to Op.
appendInstanceData(int count)46     template <typename T> inline void* appendInstanceData(int count) {
47         static_assert(std::is_pod<T>::value, "");
48         static_assert(4 == alignof(T), "");
49         return fInstanceData.push_back_n(sizeof(T) * count);
50     }
51 
52     template <typename T, typename... Args>
writeInstanceData(const T & val,const Args &...remainder)53     inline void writeInstanceData(const T& val, const Args&... remainder) {
54         memcpy(this->appendInstanceData<T>(1), &val, sizeof(T));
55         this->writeInstanceData(remainder...);
56     }
57 
writeInstanceData()58     void writeInstanceData() {}  // Halt condition.
59 
60     const SkPMColor4f fOriginalColor;
61     const SkRect fLocalRect;
62     Flags fFlags = Flags::kNone;
63     GrProcessorSet fProcessors;
64 
65     SkSTArray<sizeof(float) * 16 * 4, char, /*MEM_MOVE=*/ true> fInstanceData;
66     int fInstanceCount = 1;
67     int fInstanceStride = 0;
68 
69     sk_sp<const GrBuffer> fInstanceBuffer;
70     int fBaseInstance;
71 
72     friend class GrOpMemoryPool;
73 };
74 
75 GR_MAKE_BITFIELD_CLASS_OPS(GrAAFillRRectOp::Flags)
76 
77 #endif
78