• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 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 GrDrawOp_DEFINED
9 #define GrDrawOp_DEFINED
10 
11 #include <functional>
12 #include "GrOp.h"
13 #include "GrPipeline.h"
14 
15 class GrAppliedClip;
16 
17 /**
18  * GrDrawOps are flushed in two phases (preDraw, and draw). In preDraw uploads to GrGpuResources
19  * and draws are determined and scheduled. They are issued in the draw phase. GrDrawOpUploadToken is
20  * used to sequence the uploads relative to each other and to draws.
21  **/
22 
23 class GrDrawOpUploadToken {
24 public:
AlreadyFlushedToken()25     static GrDrawOpUploadToken AlreadyFlushedToken() { return GrDrawOpUploadToken(0); }
26 
GrDrawOpUploadToken(const GrDrawOpUploadToken & that)27     GrDrawOpUploadToken(const GrDrawOpUploadToken& that) : fSequenceNumber(that.fSequenceNumber) {}
28     GrDrawOpUploadToken& operator =(const GrDrawOpUploadToken& that) {
29         fSequenceNumber = that.fSequenceNumber;
30         return *this;
31     }
32     bool operator==(const GrDrawOpUploadToken& that) const {
33         return fSequenceNumber == that.fSequenceNumber;
34     }
35     bool operator!=(const GrDrawOpUploadToken& that) const { return !(*this == that); }
36 
37 private:
38     GrDrawOpUploadToken();
GrDrawOpUploadToken(uint64_t sequenceNumber)39     explicit GrDrawOpUploadToken(uint64_t sequenceNumber) : fSequenceNumber(sequenceNumber) {}
40     friend class GrOpFlushState;
41     uint64_t fSequenceNumber;
42 };
43 
44 /**
45  * Base class for GrOps that draw. These ops have a GrPipeline installed by GrOpList.
46  */
47 class GrDrawOp : public GrOp {
48 public:
49     /** Method that performs an upload on behalf of a DeferredUploadFn. */
50     using WritePixelsFn = std::function<bool(GrSurface* texture,
51                                              int left, int top, int width, int height,
52                                              GrPixelConfig config, const void* buffer,
53                                              size_t rowBytes)>;
54     /** See comments before GrDrawOp::Target definition on how deferred uploaders work. */
55     using DeferredUploadFn = std::function<void(WritePixelsFn&)>;
56 
57     class Target;
58 
GrDrawOp(uint32_t classID)59     GrDrawOp(uint32_t classID) : INHERITED(classID) {}
60 
61     /**
62      * This information is required to determine how to compute a GrAppliedClip from a GrClip for
63      * this op.
64      */
65     enum class FixedFunctionFlags : uint32_t {
66         kNone = 0x0,
67         /** Indices that the op will enable MSAA or mixed samples rendering. */
68         kUsesHWAA = 0x1,
69         /** Indices that the op reads and/or writes the stencil buffer */
70         kUsesStencil = 0x2,
71     };
72     GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(FixedFunctionFlags);
73     virtual FixedFunctionFlags fixedFunctionFlags() const = 0;
74 
75     enum class RequiresDstTexture : bool { kNo = false, kYes = true };
76     /**
77      * This is called after the GrAppliedClip has been computed and just prior to recording the op
78      * or combining it with a previously recorded op. The op should convert any proxies or resources
79      * it owns to "pending io" status so that resource allocation can be more optimal. Additionally,
80      * at this time the op must report whether a copy of the destination (or destination texture
81      * itself) needs to be provided to the GrXferProcessor when this op executes.
82      */
83     virtual RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) = 0;
84 
85 protected:
86     static SkString DumpPipelineInfo(const GrPipeline& pipeline);
87 
88     struct QueuedUpload {
QueuedUploadQueuedUpload89         QueuedUpload(DeferredUploadFn&& upload, GrDrawOpUploadToken token)
90             : fUpload(std::move(upload))
91             , fUploadBeforeToken(token) {}
92         DeferredUploadFn fUpload;
93         GrDrawOpUploadToken fUploadBeforeToken;
94     };
95 
96     SkTArray<QueuedUpload> fInlineUploads;
97 
98 private:
99     typedef GrOp INHERITED;
100 };
101 
102 GR_MAKE_BITFIELD_CLASS_OPS(GrDrawOp::FixedFunctionFlags);
103 
104 #endif
105