OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrDrawTarget.h" | 8 #include "GrDrawTarget.h" |
9 | 9 |
10 #include "GrAuditTrail.h" | 10 #include "GrAuditTrail.h" |
11 #include "GrCaps.h" | 11 #include "GrCaps.h" |
12 #include "GrDrawContext.h" | 12 #include "GrDrawContext.h" |
13 #include "GrGpu.h" | 13 #include "GrGpu.h" |
| 14 #include "GrGpuCommandBuffer.h" |
14 #include "GrPath.h" | 15 #include "GrPath.h" |
15 #include "GrPipeline.h" | 16 #include "GrPipeline.h" |
16 #include "GrMemoryPool.h" | 17 #include "GrMemoryPool.h" |
17 #include "GrRenderTarget.h" | 18 #include "GrRenderTarget.h" |
18 #include "GrResourceProvider.h" | 19 #include "GrResourceProvider.h" |
19 #include "GrRenderTargetPriv.h" | 20 #include "GrRenderTargetPriv.h" |
20 #include "GrStencilAttachment.h" | 21 #include "GrStencilAttachment.h" |
21 #include "GrSurfacePriv.h" | 22 #include "GrSurfacePriv.h" |
22 #include "GrTexture.h" | 23 #include "GrTexture.h" |
23 #include "gl/GrGLRenderTarget.h" | 24 #include "gl/GrGLRenderTarget.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 for (int i = 0; i < fBatches.count(); ++i) { | 203 for (int i = 0; i < fBatches.count(); ++i) { |
203 if (fBatches[i]) { | 204 if (fBatches[i]) { |
204 fBatches[i]->prepare(flushState); | 205 fBatches[i]->prepare(flushState); |
205 } | 206 } |
206 } | 207 } |
207 } | 208 } |
208 | 209 |
209 void GrDrawTarget::drawBatches(GrBatchFlushState* flushState) { | 210 void GrDrawTarget::drawBatches(GrBatchFlushState* flushState) { |
210 // Draw all the generated geometry. | 211 // Draw all the generated geometry. |
211 SkRandom random; | 212 SkRandom random; |
| 213 GrRenderTarget* currentRT = nullptr; |
| 214 SkAutoTDelete<GrGpuCommandBuffer> commandBuffer; |
212 for (int i = 0; i < fBatches.count(); ++i) { | 215 for (int i = 0; i < fBatches.count(); ++i) { |
213 if (!fBatches[i]) { | 216 if (!fBatches[i]) { |
214 continue; | 217 continue; |
215 } | 218 } |
| 219 if (fBatches[i]->renderTarget() != currentRT) { |
| 220 if (commandBuffer) { |
| 221 commandBuffer->end(); |
| 222 // For now just use size of whole render target, but this should
be updated to |
| 223 // only be the actual bounds of the various draws. |
| 224 SkIRect bounds = SkIRect::MakeWH(currentRT->width(), currentRT->
height()); |
| 225 commandBuffer->submit(bounds); |
| 226 commandBuffer.reset(); |
| 227 } |
| 228 currentRT = fBatches[i]->renderTarget(); |
| 229 if (currentRT) { |
| 230 static const GrGpuCommandBuffer::LoadAndStoreOp kBasicLoadStoreO
p = |
| 231 GrGpuCommandBuffer::kLoadAndStore_LoadAndStoreOp; |
| 232 static const GrColor kClearValue = GrColor_ILLEGAL; |
| 233 commandBuffer.reset(fGpu->createCommandBuffer(currentRT, |
| 234 kBasicLoadStoreOp,
// Color |
| 235 kClearValue,
// Color clear |
| 236 kBasicLoadStoreOp,
// Stencil |
| 237 kClearValue));
// Stencil clear |
| 238 } |
| 239 flushState->setCommandBuffer(commandBuffer); |
| 240 } |
216 if (fDrawBatchBounds) { | 241 if (fDrawBatchBounds) { |
217 const SkRect& bounds = fBatches[i]->bounds(); | 242 const SkRect& bounds = fBatches[i]->bounds(); |
218 SkIRect ibounds; | 243 SkIRect ibounds; |
219 bounds.roundOut(&ibounds); | 244 bounds.roundOut(&ibounds); |
220 // In multi-draw buffer all the batches use the same render target a
nd we won't need to | 245 // In multi-draw buffer all the batches use the same render target a
nd we won't need to |
221 // get the batchs bounds. | 246 // get the batchs bounds. |
222 if (GrRenderTarget* rt = fBatches[i]->renderTarget()) { | 247 if (GrRenderTarget* rt = fBatches[i]->renderTarget()) { |
223 fGpu->drawDebugWireRect(rt, ibounds, 0xFF000000 | random.nextU()
); | 248 fGpu->drawDebugWireRect(rt, ibounds, 0xFF000000 | random.nextU()
); |
224 } | 249 } |
225 } | 250 } |
226 fBatches[i]->draw(flushState); | 251 fBatches[i]->draw(flushState); |
227 } | 252 } |
| 253 if (commandBuffer) { |
| 254 commandBuffer->end(); |
| 255 // For now just use size of whole render target, but this should be upda
ted to |
| 256 // only be the actual bounds of the various draws. |
| 257 SkIRect bounds = SkIRect::MakeWH(currentRT->width(), currentRT->height()
); |
| 258 commandBuffer->submit(bounds); |
| 259 flushState->setCommandBuffer(nullptr); |
| 260 } |
228 | 261 |
229 fGpu->finishDrawTarget(); | 262 fGpu->finishDrawTarget(); |
230 } | 263 } |
231 | 264 |
232 void GrDrawTarget::reset() { | 265 void GrDrawTarget::reset() { |
233 fBatches.reset(); | 266 fBatches.reset(); |
234 } | 267 } |
235 | 268 |
236 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, | 269 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, |
237 GrDrawContext* drawContext, | 270 GrDrawContext* drawContext, |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 } | 557 } |
525 } | 558 } |
526 | 559 |
527 /////////////////////////////////////////////////////////////////////////////// | 560 /////////////////////////////////////////////////////////////////////////////// |
528 | 561 |
529 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { | 562 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { |
530 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); | 563 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
531 this->recordBatch(batch); | 564 this->recordBatch(batch); |
532 batch->unref(); | 565 batch->unref(); |
533 } | 566 } |
OLD | NEW |