OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 /** | 27 /** |
28 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws
for eventual | 28 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws
for eventual |
29 * playback into a GrGpu. In theory one draw buffer could playback into another.
When index or | 29 * playback into a GrGpu. In theory one draw buffer could playback into another.
When index or |
30 * vertex buffers are used as geometry sources it is the callers the draw buffer
only holds | 30 * vertex buffers are used as geometry sources it is the callers the draw buffer
only holds |
31 * references to the buffers. It is the callers responsibility to ensure that th
e data is still | 31 * references to the buffers. It is the callers responsibility to ensure that th
e data is still |
32 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the
caller's | 32 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the
caller's |
33 * responsibility to ensure that all referenced textures, buffers, and render-ta
rgets are associated | 33 * responsibility to ensure that all referenced textures, buffers, and render-ta
rgets are associated |
34 * in the GrGpu object that the buffer is played back into. The buffer requires
VB and IB pools to | 34 * in the GrGpu object that the buffer is played back into. The buffer requires
VB and IB pools to |
35 * store geometry. | 35 * store geometry. |
36 */ | 36 */ |
37 class GrInOrderDrawBuffer : public GrDrawTarget { | 37 class GrInOrderDrawBuffer : public GrDrawTarget { |
38 public: | 38 public: |
39 | 39 |
40 /** | 40 /** |
41 * Creates a GrInOrderDrawBuffer | 41 * Creates a GrInOrderDrawBuffer |
42 * | 42 * |
43 * @param gpu the gpu object that this draw buffer flushes to. | 43 * @param gpu the gpu object that this draw buffer flushes to. |
44 * @param vertexPool pool where vertices for queued draws will be saved when | 44 * @param vertexPool pool where vertices for queued draws will be saved when |
45 * the vertex source is either reserved or array. | 45 * the vertex source is either reserved or array. |
46 * @param indexPool pool where indices for queued draws will be saved when | 46 * @param indexPool pool where indices for queued draws will be saved when |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 protected: | 80 protected: |
81 virtual void clipWillBeSet(const GrClipData* newClip) SK_OVERRIDE; | 81 virtual void clipWillBeSet(const GrClipData* newClip) SK_OVERRIDE; |
82 | 82 |
83 private: | 83 private: |
84 enum Cmd { | 84 enum Cmd { |
85 kDraw_Cmd = 1, | 85 kDraw_Cmd = 1, |
86 kStencilPath_Cmd = 2, | 86 kStencilPath_Cmd = 2, |
87 kSetState_Cmd = 3, | 87 kSetState_Cmd = 3, |
88 kSetClip_Cmd = 4, | 88 kSetClip_Cmd = 4, |
89 kClear_Cmd = 5, | 89 kClear_Cmd = 5, |
| 90 kCopySurface_Cmd = 6, |
90 }; | 91 }; |
91 | 92 |
92 class DrawRecord : public DrawInfo { | 93 class DrawRecord : public DrawInfo { |
93 public: | 94 public: |
94 DrawRecord(const DrawInfo& info) : DrawInfo(info) {} | 95 DrawRecord(const DrawInfo& info) : DrawInfo(info) {} |
95 const GrVertexBuffer* fVertexBuffer; | 96 const GrVertexBuffer* fVertexBuffer; |
96 const GrIndexBuffer* fIndexBuffer; | 97 const GrIndexBuffer* fIndexBuffer; |
97 }; | 98 }; |
98 | 99 |
99 struct StencilPath { | 100 struct StencilPath : GrNoncopyable { |
100 StencilPath(); | 101 StencilPath(); |
101 | 102 |
102 SkAutoTUnref<const GrPath> fPath; | 103 SkAutoTUnref<const GrPath> fPath; |
103 SkStrokeRec fStroke; | 104 SkStrokeRec fStroke; |
104 SkPath::FillType fFill; | 105 SkPath::FillType fFill; |
105 }; | 106 }; |
106 | 107 |
107 struct Clear { | 108 struct Clear : GrNoncopyable { |
108 Clear() : fRenderTarget(NULL) {} | 109 Clear() : fRenderTarget(NULL) {} |
109 ~Clear() { GrSafeUnref(fRenderTarget); } | 110 ~Clear() { GrSafeUnref(fRenderTarget); } |
110 | 111 |
111 GrIRect fRect; | 112 GrIRect fRect; |
112 GrColor fColor; | 113 GrColor fColor; |
113 GrRenderTarget* fRenderTarget; | 114 GrRenderTarget* fRenderTarget; |
114 }; | 115 }; |
115 | 116 |
| 117 struct CopySurface : GrNoncopyable { |
| 118 SkAutoTUnref<GrSurface> fDst; |
| 119 SkAutoTUnref<GrSurface> fSrc; |
| 120 SkIRect fSrcRect; |
| 121 SkIPoint fDstPoint; |
| 122 }; |
| 123 |
116 // overrides from GrDrawTarget | 124 // overrides from GrDrawTarget |
117 virtual void onDraw(const DrawInfo&) SK_OVERRIDE; | 125 virtual void onDraw(const DrawInfo&) SK_OVERRIDE; |
118 virtual void onDrawRect(const GrRect& rect, | 126 virtual void onDrawRect(const GrRect& rect, |
119 const SkMatrix* matrix, | 127 const SkMatrix* matrix, |
120 const GrRect* localRect, | 128 const GrRect* localRect, |
121 const SkMatrix* localMatrix) SK_OVERRIDE; | 129 const SkMatrix* localMatrix) SK_OVERRIDE; |
122 virtual void onStencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath:
:FillType) SK_OVERRIDE; | 130 virtual void onStencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath:
:FillType) SK_OVERRIDE; |
123 virtual bool onReserveVertexSpace(size_t vertexSize, | 131 virtual bool onReserveVertexSpace(size_t vertexSize, |
124 int vertexCount, | 132 int vertexCount, |
125 void** vertices) SK_OVERRIDE; | 133 void** vertices) SK_OVERRIDE; |
126 virtual bool onReserveIndexSpace(int indexCount, | 134 virtual bool onReserveIndexSpace(int indexCount, |
127 void** indices) SK_OVERRIDE; | 135 void** indices) SK_OVERRIDE; |
128 virtual void releaseReservedVertexSpace() SK_OVERRIDE; | 136 virtual void releaseReservedVertexSpace() SK_OVERRIDE; |
129 virtual void releaseReservedIndexSpace() SK_OVERRIDE; | 137 virtual void releaseReservedIndexSpace() SK_OVERRIDE; |
130 virtual void onSetVertexSourceToArray(const void* vertexArray, | 138 virtual void onSetVertexSourceToArray(const void* vertexArray, |
131 int vertexCount) SK_OVERRIDE; | 139 int vertexCount) SK_OVERRIDE; |
132 virtual void onSetIndexSourceToArray(const void* indexArray, | 140 virtual void onSetIndexSourceToArray(const void* indexArray, |
133 int indexCount) SK_OVERRIDE; | 141 int indexCount) SK_OVERRIDE; |
134 virtual void releaseVertexArray() SK_OVERRIDE; | 142 virtual void releaseVertexArray() SK_OVERRIDE; |
135 virtual void releaseIndexArray() SK_OVERRIDE; | 143 virtual void releaseIndexArray() SK_OVERRIDE; |
136 virtual void geometrySourceWillPush() SK_OVERRIDE; | 144 virtual void geometrySourceWillPush() SK_OVERRIDE; |
137 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK
_OVERRIDE; | 145 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK
_OVERRIDE; |
138 virtual void willReserveVertexAndIndexSpace(int vertexCount, | 146 virtual void willReserveVertexAndIndexSpace(int vertexCount, |
139 int indexCount) SK_OVERRIDE; | 147 int indexCount) SK_OVERRIDE; |
| 148 virtual bool onCopySurface(GrSurface* dst, |
| 149 GrSurface* src, |
| 150 const SkIRect& srcRect, |
| 151 const SkIPoint& dstPoint) SK_OVERRIDE; |
| 152 virtual bool onCanCopySurface(GrSurface* dst, |
| 153 GrSurface* src, |
| 154 const SkIRect& srcRect, |
| 155 const SkIPoint& dstPoint) SK_OVERRIDE; |
| 156 |
140 bool quickInsideClip(const SkRect& devBounds); | 157 bool quickInsideClip(const SkRect& devBounds); |
141 | 158 |
142 // Attempts to concat instances from info onto the previous draw. info must
represent an | 159 // Attempts to concat instances from info onto the previous draw. info must
represent an |
143 // instanced draw. The caller must have already recorded a new draw state an
d clip if necessary. | 160 // instanced draw. The caller must have already recorded a new draw state an
d clip if necessary. |
144 int concatInstancedDraw(const DrawInfo& info); | 161 int concatInstancedDraw(const DrawInfo& info); |
145 | 162 |
146 // we lazily record state and clip changes in order to skip clips and states
that have no | 163 // we lazily record state and clip changes in order to skip clips and states
that have no |
147 // effect. | 164 // effect. |
148 bool needsNewState() const; | 165 bool needsNewState() const; |
149 bool needsNewClip() const; | 166 bool needsNewClip() const; |
150 | 167 |
151 // these functions record a command | 168 // these functions record a command |
152 void recordState(); | 169 void recordState(); |
153 void recordClip(); | 170 void recordClip(); |
154 DrawRecord* recordDraw(const DrawInfo&); | 171 DrawRecord* recordDraw(const DrawInfo&); |
155 StencilPath* recordStencilPath(); | 172 StencilPath* recordStencilPath(); |
156 Clear* recordClear(); | 173 Clear* recordClear(); |
| 174 CopySurface* recordCopySurface(); |
157 | 175 |
| 176 // TODO: Use a single allocator for commands and records |
158 enum { | 177 enum { |
159 kCmdPreallocCnt = 32, | 178 kCmdPreallocCnt = 32, |
160 kDrawPreallocCnt = 8, | 179 kDrawPreallocCnt = 8, |
161 kStencilPathPreallocCnt = 8, | 180 kStencilPathPreallocCnt = 8, |
162 kStatePreallocCnt = 8, | 181 kStatePreallocCnt = 8, |
163 kClipPreallocCnt = 8, | 182 kClipPreallocCnt = 8, |
164 kClearPreallocCnt = 4, | 183 kClearPreallocCnt = 4, |
165 kGeoPoolStatePreAllocCnt = 4, | 184 kGeoPoolStatePreAllocCnt = 4, |
| 185 kCopySurfacePreallocCnt = 4, |
166 }; | 186 }; |
167 | 187 |
168 SkSTArray<kCmdPreallocCnt, uint8_t, true> fCmds; | 188 SkSTArray<kCmdPreallocCnt, uint8_t, true> fCmds; |
169 GrSTAllocator<kDrawPreallocCnt, DrawRecord> fDraws; | 189 GrSTAllocator<kDrawPreallocCnt, DrawRecord> fDraws; |
170 GrSTAllocator<kStatePreallocCnt, StencilPath> fStencilP
aths; | 190 GrSTAllocator<kStatePreallocCnt, StencilPath> fStencilP
aths; |
171 GrSTAllocator<kStatePreallocCnt, GrDrawState::DeferredState> fStates; | 191 GrSTAllocator<kStatePreallocCnt, GrDrawState::DeferredState> fStates; |
172 GrSTAllocator<kClearPreallocCnt, Clear> fClears; | 192 GrSTAllocator<kClearPreallocCnt, Clear> fClears; |
173 | 193 GrSTAllocator<kCopySurfacePreallocCnt, CopySurface> fCopySurf
aces; |
174 GrSTAllocator<kClipPreallocCnt, SkClipStack> fClips; | 194 GrSTAllocator<kClipPreallocCnt, SkClipStack> fClips; |
175 GrSTAllocator<kClipPreallocCnt, SkIPoint> fClipOrigins; | 195 GrSTAllocator<kClipPreallocCnt, SkIPoint> fClipOrig
ins; |
176 | 196 |
177 GrDrawTarget* fDstGpu; | 197 GrDrawTarget* fDstGpu; |
178 | 198 |
179 bool fClipSet; | 199 bool fClipSet; |
180 | 200 |
181 enum ClipProxyState { | 201 enum ClipProxyState { |
182 kUnknown_ClipProxyState, | 202 kUnknown_ClipProxyState, |
183 kValid_ClipProxyState, | 203 kValid_ClipProxyState, |
184 kInvalid_ClipProxyState | 204 kInvalid_ClipProxyState |
185 }; | 205 }; |
(...skipping 16 matching lines...) Expand all Loading... |
202 size_t fUsedPoolIndexBytes; | 222 size_t fUsedPoolIndexBytes; |
203 }; | 223 }; |
204 SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> fGeoPoolStateStack; | 224 SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> fGeoPoolStateStack; |
205 | 225 |
206 bool fFlushing; | 226 bool fFlushing; |
207 | 227 |
208 typedef GrDrawTarget INHERITED; | 228 typedef GrDrawTarget INHERITED; |
209 }; | 229 }; |
210 | 230 |
211 #endif | 231 #endif |
OLD | NEW |