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

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

Issue 1225923010: Refugee from Dead Machine 4: MDB Monster Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Last update from dead machine Created 4 years, 7 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/GrSurface.cpp ('k') | src/gpu/GrTargetCommands.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 GrTargetCommands_DEFINED
9 #define GrTargetCommands_DEFINED
10
11 #include "GrDrawTarget.h"
12 #include "GrPath.h"
13 #include "GrPendingProgramElement.h"
14 #include "GrPrimitiveProcessor.h"
15 #include "GrRenderTarget.h"
16 #include "GrTRecorder.h"
17
18 #include "batches/GrBatch.h"
19
20 #include "SkRect.h"
21
22 class GrResourceProvider;
23 class GrBatchFlushState;
24
25 // TODO: Convert all commands into GrBatch and remove this class.
26 class GrTargetCommands : ::SkNoncopyable {
27 public:
28 bool empty() const { return fCmdBuffer.empty(); }
29
30 GrTargetCommands(GrFoo* foo, GrGpu* gpu, GrRenderTarget* dst)
31 : fCmdBuffer(kCmdBufferInitialSizeInBytes)
32 , fFoo(foo)
33 // , fBatchTarget(foo, gpu, dst)
34 , fLastFlushToken(0) {
35 }
36
37 class Cmd : ::SkNoncopyable {
38 public:
39 enum CmdType {
40 kDrawPath_CmdType = 2,
41 kDrawPaths_CmdType = 3,
42 kDrawBatch_CmdType = 4,
43 };
44
45 Cmd(CmdType type)
46 : fType(type)
47 #if GR_BATCH_SPEW
48 , fUniqueID(GenID(&gUniqueID))
49 #endif
50 {}
51 virtual ~Cmd() {}
52
53 virtual void execute(GrBatchFlushState*) = 0;
54
55 CmdType type() const { return fType; }
56
57 GrBATCH_SPEW(uint32_t uniqueID() const { return fUniqueID;} )
58
59 private:
60 // TODO move this to a common header so it can be shared with GrBatch
61 static uint32_t GenID(int32_t* idCounter) {
62 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1;
63 if (!id) {
64 SkFAIL("This should never wrap\n");
65 }
66 return id;
67 }
68 CmdType fType;
69 GrBATCH_SPEW(uint32_t fUniqueID);
70 GrBATCH_SPEW(static int32_t gUniqueID;)
71 };
72
73 void reset();
74 void flush(GrGpu*, GrResourceProvider*);
75
76 private:
77 friend class GrCommandBuilder;
78 friend class GrBufferedDrawTarget; // This goes away when State becomes just a pipeline
79 friend class GrReorderCommandBuilder;
80
81 typedef GrGpu::DrawArgs DrawArgs;
82
83 // TODO: This can be just a pipeline once paths are in batch, and it should live elsewhere
84 struct StateForPathDraw : public SkNVRefCnt<StateForPathDraw> {
85 // TODO get rid of the prim proc parameter when we use batch everywhere
86 StateForPathDraw(const GrPrimitiveProcessor* primProc = nullptr)
87 : fPrimitiveProcessor(primProc)
88 , fCompiled(false) {}
89
90 ~StateForPathDraw() { reinterpret_cast<GrPipeline*>(fPipeline.get())->~G rPipeline(); }
91
92 // This function is only for getting the location in memory where we wil l create our
93 // pipeline object.
94 void* pipelineLocation() { return fPipeline.get(); }
95
96 const GrPipeline* getPipeline() const {
97 return reinterpret_cast<const GrPipeline*>(fPipeline.get());
98 }
99 GrRenderTarget* getRenderTarget1() const {
100 return this->getPipeline()->getRenderTarget1();
101 }
102 const GrXferProcessor* getXferProcessor() const {
103 return this->getPipeline()->getXferProcessor();
104 }
105
106 void operator delete(void* p) {}
107 void* operator new(size_t) {
108 SkFAIL("All States are created by placement new.");
109 return sk_malloc_throw(0);
110 }
111
112 void* operator new(size_t, void* p) { return p; }
113 void operator delete(void* target, void* placement) {
114 ::operator delete(target, placement);
115 }
116
117 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi tiveProcessor;
118 ProgramPrimitiveProcessor fPrimitiveProcessor;
119 SkAlignedSStorage<sizeof(GrPipeline)> fPipeline;
120 GrProgramDesc fDesc;
121 GrBatchTracker fBatchTracker;
122 bool fCompiled;
123 };
124 // TODO remove this when State is just a pipeline
125 friend SkNVRefCnt<StateForPathDraw>;
126
127 struct DrawPath : public Cmd {
128 DrawPath(StateForPathDraw* state, const GrPath* path)
129 : Cmd(kDrawPath_CmdType)
130 , fState(SkRef(state))
131 , fPath(path) {}
132
133 const GrPath* path() const { return fPath.get(); }
134
135 void execute(GrBatchFlushState*) override;
136
137 SkAutoTUnref<StateForPathDraw> fState;
138 GrStencilSettings fStencilSettings;
139 private:
140 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath;
141 };
142
143 struct DrawPaths : public Cmd {
144 DrawPaths(StateForPathDraw* state, const GrPathRange* pathRange)
145 : Cmd(kDrawPaths_CmdType)
146 , fState(SkRef(state))
147 , fPathRange(pathRange) {}
148
149 const GrPathRange* pathRange() const { return fPathRange.get(); }
150
151 void execute(GrBatchFlushState*) override;
152
153 SkAutoTUnref<StateForPathDraw> fState;
154 char* fIndices;
155 GrDrawTarget::PathIndexType fIndexType;
156 float* fTransforms;
157 GrDrawTarget::PathTransformType fTransformType;
158 int fCount;
159 GrStencilSettings fStencilSettings;
160
161 private:
162 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange;
163 };
164
165 struct DrawBatch : public Cmd {
166 DrawBatch(GrBatch* batch)
167 : Cmd(kDrawBatch_CmdType)
168 , fBatch(SkRef(batch)){
169 SkASSERT(!batch->isUsed());
170 }
171
172 GrBatch* batch() { return fBatch; }
173 void execute(GrBatchFlushState*) override;
174
175 private:
176 SkAutoTUnref<GrBatch> fBatch;
177 };
178
179 static const int kCmdBufferInitialSizeInBytes = 8 * 1024;
180
181 typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double.
182 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer;
183
184 CmdBuffer* cmdBuffer() { return &fCmdBuffer; }
185
186 CmdBuffer fCmdBuffer;
187 GrFoo* fFoo;
188 GrBatchToken fLastFlushToken;
189 };
190
191 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrSurface.cpp ('k') | src/gpu/GrTargetCommands.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698