Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: src/gpu/GrBatch.h

Issue 845103005: GrBatchPrototype (Closed) Base URL: https://skia.googlesource.com/skia.git@lc2
Patch Set: tidying Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrAARectRenderer.cpp ('k') | src/gpu/GrBatch.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 GrBatch_DEFINED
9 #define GrBatch_DEFINED
10
11 #include <new>
12 // TODO remove this header when we move entirely to batch
13 #include "GrGeometryProcessor.h"
14 #include "SkRefCnt.h"
15 #include "SkThread.h"
16 #include "SkTypes.h"
17
18 class GrBatchTarget;
19 class GrGpu;
20 class GrIndexBufferAllocPool;
21 class GrInitInvariantOutput;
22 class GrOptDrawState;
23 class GrVertexBufferAllocPool;
24
25 /*
26 * GrBatch is the base class for all Ganesh deferred geometry generators. To fa cilitate
27 * reorderable batching, Ganesh does not generate geometry inline with draw call s. Instead, it
28 * captures the arguments to the draw and then generates the geometry on demand. This gives GrBatch
29 * subclasses complete freedom to decide how / what they can batch.
30 *
31 * Batches are created when GrContext processes a draw call. Batches of the same subclass may be
32 * merged using combineIfPossible. When two batches merge, one takes on the unio n of the data
33 * and the other is left empty. The merged batch becomes responsible for drawing the data from both
34 * the original batches.
35 *
36 * If there are any possible optimizations which might require knowing more abou t the full state of
37 * the draw, ie whether or not the GrBatch is allowed to tweak alpha for coverag e, then this
38 * information will be communicated to the GrBatch prior to geometry generation.
39 */
40
41 struct GrBatchOpt {
42 bool fCanTweakAlphaForCoverage;
43 };
44
45 class GrBatch : public SkRefCnt {
46 public:
47 SK_DECLARE_INST_COUNT(GrBatch)
48 GrBatch() { SkDEBUGCODE(fUsed = false;) }
49 virtual ~GrBatch() {}
50 virtual const char* name() const = 0;
51 virtual void getInvariantOutputColor(GrInitInvariantOutput* out,
52 const GrBatchOpt&) const = 0;
53 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out,
54 const GrBatchOpt&) const = 0;
55
56 virtual void initBatchOpt(const GrBatchOpt&) = 0;
bsalomon 2015/01/22 16:00:59 The virtuals that the client overrides could use s
57 virtual void initBatchTracker(const GrGeometryProcessor::InitBT& init) = 0;
58
59 bool combineIfPossible(GrBatch* that) {
60 if (this->classID() != that->classID()) {
61 return false;
62 }
63
64 return onCombineIfPossible(that);
65 }
66
67 virtual bool onCombineIfPossible(GrBatch*) = 0;
68
69 virtual void generateGeometry(GrBatchTarget*, const GrOptDrawState*) = 0;
70
71 void* operator new(size_t size);
72 void operator delete(void* target);
73
74 void* operator new(size_t size, void* placement) {
75 return ::operator new(size, placement);
76 }
77 void operator delete(void* target, void* placement) {
78 ::operator delete(target, placement);
79 }
80
81 /**
82 * Helper for down-casting to a GrBatch subclass
83 */
84 template <typename T> const T& cast() const { return *static_cast<const T*>( this); }
85 template <typename T> T* cast() { return static_cast<T*>(this); }
86
87 uint32_t classID() const { SkASSERT(kIllegalBatchClassID != fClassID); retur n fClassID; }
88
89 // TODO no GrPrimitiveProcessors yet read fragment position
90 bool willReadFragmentPosition() const { return false; }
91
92 SkDEBUGCODE(bool isUsed() const { return fUsed; })
93
94 protected:
95 template <typename PROC_SUBCLASS> void initClassID() {
96 static uint32_t kClassID = GenClassID();
97 fClassID = kClassID;
98 }
99
100 uint32_t fClassID;
101
102 private:
103 static uint32_t GenClassID() {
104 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI D. The
105 // atomic inc returns the old value not the incremented value. So we add
106 // 1 to the returned value.
107 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrBatchClassID)) + 1;
108 if (!id) {
109 SkFAIL("This should never wrap as it should only be called once for each GrBatch "
110 "subclass.");
111 }
112 return id;
113 }
114
115 enum {
116 kIllegalBatchClassID = 0,
117 };
118 static int32_t gCurrBatchClassID;
119
120 SkDEBUGCODE(bool fUsed;)
121
122 typedef SkRefCnt INHERITED;
123 };
124
125 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAARectRenderer.cpp ('k') | src/gpu/GrBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698