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

Side by Side Diff: src/gpu/GrDrawTarget.cpp

Issue 1437843002: Move GrBatchFlushState from GrDrawTarget to GrDrawingManager (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: readd white space Created 5 years, 1 month 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/GrDrawTarget.h ('k') | src/gpu/GrDrawingManager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 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 #include "GrDrawTarget.h" 9 #include "GrDrawTarget.h"
10 10
(...skipping 14 matching lines...) Expand all
25 #include "batches/GrDiscardBatch.h" 25 #include "batches/GrDiscardBatch.h"
26 #include "batches/GrDrawBatch.h" 26 #include "batches/GrDrawBatch.h"
27 #include "batches/GrDrawPathBatch.h" 27 #include "batches/GrDrawPathBatch.h"
28 #include "batches/GrRectBatchFactory.h" 28 #include "batches/GrRectBatchFactory.h"
29 #include "batches/GrStencilPathBatch.h" 29 #include "batches/GrStencilPathBatch.h"
30 30
31 #include "SkStrokeRec.h" 31 #include "SkStrokeRec.h"
32 32
33 //////////////////////////////////////////////////////////////////////////////// 33 ////////////////////////////////////////////////////////////////////////////////
34 34
35 GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r esourceProvider, 35 GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r esourceProvider)
36 const Options& options)
37 : fGpu(SkRef(gpu)) 36 : fGpu(SkRef(gpu))
38 , fResourceProvider(resourceProvider) 37 , fResourceProvider(resourceProvider)
39 , fFlushState(fGpu, fResourceProvider)
40 , fFlushing(false) 38 , fFlushing(false)
41 , fFlags(0) 39 , fFlags(0)
42 , fOptions(options)
43 , fRenderTarget(rt) { 40 , fRenderTarget(rt) {
44 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) 41 // TODO: Stop extracting the context (currently needed by GrClipMaskManager)
45 fContext = fGpu->getContext(); 42 fContext = fGpu->getContext();
46 fClipMaskManager.reset(new GrClipMaskManager(this)); 43 fClipMaskManager.reset(new GrClipMaskManager(this));
47 44
48 #ifdef SK_DEBUG 45 #ifdef SK_DEBUG
49 static int debugID = 0; 46 static int debugID = 0;
50 fDebugID = debugID++; 47 fDebugID = debugID++;
51 #endif 48 #endif
52 } 49 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 SkDebugf("Failed to create temporary copy of destination texture.\n"); 166 SkDebugf("Failed to create temporary copy of destination texture.\n");
170 return false; 167 return false;
171 } 168 }
172 SkIPoint dstPoint = {0, 0}; 169 SkIPoint dstPoint = {0, 0};
173 this->copySurface(copy, rt, copyRect, dstPoint); 170 this->copySurface(copy, rt, copyRect, dstPoint);
174 dstTexture->setTexture(copy); 171 dstTexture->setTexture(copy);
175 dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); 172 dstTexture->setOffset(copyRect.fLeft, copyRect.fTop);
176 return true; 173 return true;
177 } 174 }
178 175
179 void GrDrawTarget::flush() { 176 void GrDrawTarget::prepareBatches(GrBatchFlushState* flushState) {
180 if (fFlushing) { 177 if (fFlushing) {
181 return; 178 return;
182 } 179 }
183 fFlushing = true; 180 fFlushing = true;
184 181
185 // Semi-usually the drawTargets are already closed at this point, but someti mes Ganesh 182 // Semi-usually the drawTargets are already closed at this point, but someti mes Ganesh
186 // needs to flush mid-draw. In that case, the SkGpuDevice's drawTargets won' t be closed 183 // needs to flush mid-draw. In that case, the SkGpuDevice's drawTargets won' t be closed
187 // but need to be flushed anyway. Closing such drawTargets here will mean ne w 184 // but need to be flushed anyway. Closing such drawTargets here will mean ne w
188 // drawTargets will be created to replace them if the SkGpuDevice(s) write t o them again. 185 // drawTargets will be created to replace them if the SkGpuDevice(s) write t o them again.
189 this->makeClosed(); 186 this->makeClosed();
190 187
191 // Loop over the batches that haven't yet generated their geometry 188 // Loop over the batches that haven't yet generated their geometry
192 for (int i = 0; i < fBatches.count(); ++i) { 189 for (int i = 0; i < fBatches.count(); ++i) {
193 fBatches[i]->prepare(&fFlushState); 190 fBatches[i]->prepare(flushState);
194 } 191 }
192 }
195 193
196 // Upload all data to the GPU 194 void GrDrawTarget::drawBatches(GrBatchFlushState* flushState) {
197 fFlushState.preIssueDraws();
198
199 // Draw all the generated geometry. 195 // Draw all the generated geometry.
200 for (int i = 0; i < fBatches.count(); ++i) { 196 for (int i = 0; i < fBatches.count(); ++i) {
201 fBatches[i]->draw(&fFlushState); 197 fBatches[i]->draw(flushState);
202 } 198 }
203 199
204 SkASSERT(fFlushState.lastFlushedToken() == fFlushState.currentToken());
205 this->reset();
206
207 fFlushing = false; 200 fFlushing = false;
208 } 201 }
209 202
210 void GrDrawTarget::reset() { 203 void GrDrawTarget::reset() {
211 fBatches.reset(); 204 fBatches.reset();
212 fFlushState.reset();
213 } 205 }
214 206
215 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat ch* batch) { 207 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat ch* batch) {
216 // Setup clip 208 // Setup clip
217 GrPipelineBuilder::AutoRestoreStencil ars; 209 GrPipelineBuilder::AutoRestoreStencil ars;
218 GrAppliedClip clip; 210 GrAppliedClip clip;
219 if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, &batch->bounds() , &clip)) { 211 if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, &batch->bounds() , &clip)) {
220 return; 212 return;
221 } 213 }
222 214
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 455
464 template <class Left, class Right> static bool intersect(const Left& a, const Ri ght& b) { 456 template <class Left, class Right> static bool intersect(const Left& a, const Ri ght& b) {
465 SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && 457 SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom &&
466 b.fLeft <= b.fRight && b.fTop <= b.fBottom); 458 b.fLeft <= b.fRight && b.fTop <= b.fBottom);
467 return a.fLeft < b.fRight && b.fLeft < a.fRight && a.fTop < b.fBottom && b.f Top < a.fBottom; 459 return a.fLeft < b.fRight && b.fLeft < a.fRight && a.fTop < b.fBottom && b.f Top < a.fBottom;
468 } 460 }
469 461
470 void GrDrawTarget::recordBatch(GrBatch* batch) { 462 void GrDrawTarget::recordBatch(GrBatch* batch) {
471 // A closed drawTarget should never receive new/more batches 463 // A closed drawTarget should never receive new/more batches
472 SkASSERT(!this->isClosed()); 464 SkASSERT(!this->isClosed());
473 // Should never have batches queued up when in immediate mode.
474 SkASSERT(!fOptions.fImmediateMode || !fBatches.count());
475 465
476 // Check if there is a Batch Draw we can batch with by linearly searching ba ck until we either 466 // Check if there is a Batch Draw we can batch with by linearly searching ba ck until we either
477 // 1) check every draw 467 // 1) check every draw
478 // 2) intersect with something 468 // 2) intersect with something
479 // 3) find a 'blocker' 469 // 3) find a 'blocker'
480 // Experimentally we have found that most batching occurs within the first 1 0 comparisons. 470 // Experimentally we have found that most batching occurs within the first 1 0 comparisons.
481 static const int kMaxLookback = 10; 471 static const int kMaxLookback = 10;
482 472
483 GrBATCH_INFO("Re-Recording (%s, B%u)\n" 473 GrBATCH_INFO("Re-Recording (%s, B%u)\n"
484 "\tBounds LRTB (%f, %f, %f, %f)\n", 474 "\tBounds LRTB (%f, %f, %f, %f)\n",
(...skipping 28 matching lines...) Expand all
513 ++i; 503 ++i;
514 if (i == maxCandidates) { 504 if (i == maxCandidates) {
515 GrBATCH_INFO("\t\tReached max lookback or beginning of batch arr ay %d\n", i); 505 GrBATCH_INFO("\t\tReached max lookback or beginning of batch arr ay %d\n", i);
516 break; 506 break;
517 } 507 }
518 } 508 }
519 } else { 509 } else {
520 GrBATCH_INFO("\t\tFirstBatch\n"); 510 GrBATCH_INFO("\t\tFirstBatch\n");
521 } 511 }
522 fBatches.push_back().reset(SkRef(batch)); 512 fBatches.push_back().reset(SkRef(batch));
523 if (fOptions.fImmediateMode) {
524 this->flush();
525 }
526 } 513 }
527 514
528 /////////////////////////////////////////////////////////////////////////////// 515 ///////////////////////////////////////////////////////////////////////////////
529 516
530 bool GrDrawTarget::installPipelineInDrawBatch(const GrPipelineBuilder* pipelineB uilder, 517 bool GrDrawTarget::installPipelineInDrawBatch(const GrPipelineBuilder* pipelineB uilder,
531 const GrAppliedClip* clip, GrDrawB atch* batch) { 518 const GrAppliedClip* clip, GrDrawB atch* batch) {
532 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; 519 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps;
533 if (clip->clipCoverageFragmentProcessor()) { 520 if (clip->clipCoverageFragmentProcessor()) {
534 arfps.set(pipelineBuilder); 521 arfps.set(pipelineBuilder);
535 arfps.addCoverageFragmentProcessor(clip->clipCoverageFragmentProcessor() ); 522 arfps.addCoverageFragmentProcessor(clip->clipCoverageFragmentProcessor() );
(...skipping 16 matching lines...) Expand all
552 } 539 }
553 540
554 return true; 541 return true;
555 } 542 }
556 543
557 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend erTarget* rt) { 544 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend erTarget* rt) {
558 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); 545 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt);
559 this->recordBatch(batch); 546 this->recordBatch(batch);
560 batch->unref(); 547 batch->unref();
561 } 548 }
OLDNEW
« no previous file with comments | « src/gpu/GrDrawTarget.h ('k') | src/gpu/GrDrawingManager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698