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

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

Issue 2035823002: Make GrClipMaskManager stateless and push GrPipelineBuilder construction downstack (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address code review comments Created 4 years, 6 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
OLDNEW
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 "GrGpu.h" 13 #include "GrGpu.h"
13 #include "GrPath.h" 14 #include "GrPath.h"
14 #include "GrPipeline.h" 15 #include "GrPipeline.h"
15 #include "GrMemoryPool.h" 16 #include "GrMemoryPool.h"
16 #include "GrRenderTarget.h" 17 #include "GrRenderTarget.h"
17 #include "GrResourceProvider.h" 18 #include "GrResourceProvider.h"
18 #include "GrRenderTargetPriv.h" 19 #include "GrRenderTargetPriv.h"
19 #include "GrStencilAttachment.h" 20 #include "GrStencilAttachment.h"
20 #include "GrSurfacePriv.h" 21 #include "GrSurfacePriv.h"
21 #include "GrTexture.h" 22 #include "GrTexture.h"
(...skipping 17 matching lines...) Expand all
39 40
40 GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r esourceProvider, 41 GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r esourceProvider,
41 GrAuditTrail* auditTrail, const Options& options) 42 GrAuditTrail* auditTrail, const Options& options)
42 : fGpu(SkRef(gpu)) 43 : fGpu(SkRef(gpu))
43 , fResourceProvider(resourceProvider) 44 , fResourceProvider(resourceProvider)
44 , fAuditTrail(auditTrail) 45 , fAuditTrail(auditTrail)
45 , fFlags(0) 46 , fFlags(0)
46 , fRenderTarget(rt) { 47 , fRenderTarget(rt) {
47 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) 48 // TODO: Stop extracting the context (currently needed by GrClipMaskManager)
48 fContext = fGpu->getContext(); 49 fContext = fGpu->getContext();
49 fClipMaskManager.reset(new GrClipMaskManager(this));
50 50
51 fClipBatchToBounds = options.fClipBatchToBounds; 51 fClipBatchToBounds = options.fClipBatchToBounds;
52 fDrawBatchBounds = options.fDrawBatchBounds; 52 fDrawBatchBounds = options.fDrawBatchBounds;
53 fMaxBatchLookback = (options.fMaxBatchLookback < 0) ? kDefaultMaxBatchLookba ck : 53 fMaxBatchLookback = (options.fMaxBatchLookback < 0) ? kDefaultMaxBatchLookba ck :
54 options.fMaxBatchLookb ack; 54 options.fMaxBatchLookb ack;
55 fMaxBatchLookahead = (options.fMaxBatchLookahead < 0) ? kDefaultMaxBatchLook ahead : 55 fMaxBatchLookahead = (options.fMaxBatchLookahead < 0) ? kDefaultMaxBatchLook ahead :
56 options.fMaxBatchLook ahead; 56 options.fMaxBatchLook ahead;
57 57
58 rt->setLastDrawTarget(this); 58 rt->setLastDrawTarget(this);
59 59
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 228 }
229 229
230 fGpu->finishDrawTarget(); 230 fGpu->finishDrawTarget();
231 } 231 }
232 232
233 void GrDrawTarget::reset() { 233 void GrDrawTarget::reset() {
234 fBatches.reset(); 234 fBatches.reset();
235 } 235 }
236 236
237 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, 237 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder,
238 GrDrawContext* drawContext,
238 const GrClip& clip, 239 const GrClip& clip,
239 GrDrawBatch* batch) { 240 GrDrawBatch* batch) {
240 // Setup clip 241 // Setup clip
241 GrAppliedClip appliedClip; 242 GrAppliedClip appliedClip;
242 if (!clip.apply(fClipMaskManager, pipelineBuilder, &batch->bounds(), &applie dClip)) { 243 if (!clip.apply(fContext, pipelineBuilder, drawContext, &batch->bounds(), &a ppliedClip)) {
243 return; 244 return;
244 } 245 }
245 246
246 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; 247 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps;
247 if (appliedClip.clipCoverageFragmentProcessor()) { 248 if (appliedClip.clipCoverageFragmentProcessor()) {
248 arfps.set(&pipelineBuilder); 249 arfps.set(&pipelineBuilder);
249 arfps.addCoverageFragmentProcessor(appliedClip.clipCoverageFragmentProce ssor()); 250 arfps.addCoverageFragmentProcessor(appliedClip.clipCoverageFragmentProce ssor());
250 } 251 }
251 252
252 GrPipeline::CreateArgs args; 253 GrPipeline::CreateArgs args;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 304
304 #ifdef ENABLE_MDB 305 #ifdef ENABLE_MDB
305 SkASSERT(fRenderTarget); 306 SkASSERT(fRenderTarget);
306 batch->pipeline()->addDependenciesTo(fRenderTarget); 307 batch->pipeline()->addDependenciesTo(fRenderTarget);
307 #endif 308 #endif
308 309
309 this->recordBatch(batch); 310 this->recordBatch(batch);
310 } 311 }
311 312
312 void GrDrawTarget::stencilPath(const GrPipelineBuilder& pipelineBuilder, 313 void GrDrawTarget::stencilPath(const GrPipelineBuilder& pipelineBuilder,
314 GrDrawContext* drawContext,
313 const GrClip& clip, 315 const GrClip& clip,
314 const SkMatrix& viewMatrix, 316 const SkMatrix& viewMatrix,
315 const GrPath* path, 317 const GrPath* path,
316 GrPathRendering::FillType fill) { 318 GrPathRendering::FillType fill) {
317 // TODO: extract portions of checkDraw that are relevant to path stenciling. 319 // TODO: extract portions of checkDraw that are relevant to path stenciling.
318 SkASSERT(path); 320 SkASSERT(path);
319 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); 321 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport());
320 322
321 // Setup clip 323 // Setup clip
322 GrAppliedClip appliedClip; 324 GrAppliedClip appliedClip;
323 if (!clip.apply(fClipMaskManager, pipelineBuilder, nullptr, &appliedClip)) { 325 if (!clip.apply(fContext, pipelineBuilder, drawContext, nullptr, &appliedCli p)) {
324 return; 326 return;
325 } 327 }
326 // TODO: respect fClipBatchToBounds if we ever start computing bounds here. 328 // TODO: respect fClipBatchToBounds if we ever start computing bounds here.
327 329
328 // Coverage AA does not make sense when rendering to the stencil buffer. The caller should never 330 // Coverage AA does not make sense when rendering to the stencil buffer. The caller should never
329 // attempt this in a situation that would require coverage AA. 331 // attempt this in a situation that would require coverage AA.
330 SkASSERT(!appliedClip.clipCoverageFragmentProcessor()); 332 SkASSERT(!appliedClip.clipCoverageFragmentProcessor());
331 333
332 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); 334 GrRenderTarget* rt = pipelineBuilder.getRenderTarget();
333 GrStencilAttachment* stencilAttachment = fResourceProvider->attachStencilAtt achment(rt); 335 GrStencilAttachment* stencilAttachment = fResourceProvider->attachStencilAtt achment(rt);
(...skipping 10 matching lines...) Expand all
344 appliedClip.scissorState(), 346 appliedClip.scissorState(),
345 pipelineBuilder.getRenderTarget( ), 347 pipelineBuilder.getRenderTarget( ),
346 path); 348 path);
347 this->recordBatch(batch); 349 this->recordBatch(batch);
348 batch->unref(); 350 batch->unref();
349 } 351 }
350 352
351 void GrDrawTarget::clear(const SkIRect* rect, 353 void GrDrawTarget::clear(const SkIRect* rect,
352 GrColor color, 354 GrColor color,
353 bool canIgnoreRect, 355 bool canIgnoreRect,
354 GrRenderTarget* renderTarget) { 356 GrDrawContext* drawContext) {
355 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height ()); 357 SkIRect rtRect = SkIRect::MakeWH(drawContext->width(), drawContext->height() );
356 SkIRect clippedRect; 358 SkIRect clippedRect;
357 if (!rect || 359 if (!rect ||
358 (canIgnoreRect && this->caps()->fullClearIsFree()) || 360 (canIgnoreRect && this->caps()->fullClearIsFree()) ||
359 rect->contains(rtRect)) { 361 rect->contains(rtRect)) {
360 rect = &rtRect; 362 rect = &rtRect;
361 } else { 363 } else {
362 clippedRect = *rect; 364 clippedRect = *rect;
363 if (!clippedRect.intersect(rtRect)) { 365 if (!clippedRect.intersect(rtRect)) {
364 return; 366 return;
365 } 367 }
366 rect = &clippedRect; 368 rect = &clippedRect;
367 } 369 }
368 370
369 if (this->caps()->useDrawInsteadOfClear()) { 371 if (this->caps()->useDrawInsteadOfClear()) {
370 // This works around a driver bug with clear by drawing a rect instead. 372 // This works around a driver bug with clear by drawing a rect instead.
371 // The driver will ignore a clear if it is the only thing rendered to a 373 // The driver will ignore a clear if it is the only thing rendered to a
372 // target before the target is read. 374 // target before the target is read.
373 if (rect == &rtRect) { 375 if (rect == &rtRect) {
374 this->discard(renderTarget); 376 drawContext->discard();
375 } 377 }
376 378
377 GrPipelineBuilder pipelineBuilder; 379 GrPipelineBuilder pipelineBuilder;
378 pipelineBuilder.setXPFactory( 380 pipelineBuilder.setXPFactory(
379 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref(); 381 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref();
380 pipelineBuilder.setRenderTarget(renderTarget); 382 pipelineBuilder.setRenderTarget(drawContext->accessRenderTarget());
381 383
382 SkRect scalarRect = SkRect::Make(*rect); 384 SkRect scalarRect = SkRect::Make(*rect);
383 SkAutoTUnref<GrDrawBatch> batch( 385 SkAutoTUnref<GrDrawBatch> batch(
384 GrRectBatchFactory::CreateNonAAFill(color, SkMatrix::I(), scalar Rect, 386 GrRectBatchFactory::CreateNonAAFill(color, SkMatrix::I(), scalar Rect,
385 nullptr, nullptr)); 387 nullptr, nullptr));
386 this->drawBatch(pipelineBuilder, GrNoClip(), batch); 388 this->drawBatch(pipelineBuilder, drawContext, GrNoClip(), batch);
387 } else { 389 } else {
388 GrBatch* batch = new GrClearBatch(*rect, color, renderTarget); 390 GrBatch* batch = new GrClearBatch(*rect, color, drawContext->accessRende rTarget());
389 this->recordBatch(batch); 391 this->recordBatch(batch);
390 batch->unref(); 392 batch->unref();
391 } 393 }
392 } 394 }
393 395
394 void GrDrawTarget::discard(GrRenderTarget* renderTarget) { 396 void GrDrawTarget::discard(GrRenderTarget* renderTarget) {
395 if (this->caps()->discardRenderTargetSupport()) { 397 if (this->caps()->discardRenderTargetSupport()) {
396 GrBatch* batch = new GrDiscardBatch(renderTarget); 398 GrBatch* batch = new GrDiscardBatch(renderTarget);
397 this->recordBatch(batch); 399 this->recordBatch(batch);
398 batch->unref(); 400 batch->unref();
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } 523 }
522 } 524 }
523 525
524 /////////////////////////////////////////////////////////////////////////////// 526 ///////////////////////////////////////////////////////////////////////////////
525 527
526 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend erTarget* rt) { 528 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend erTarget* rt) {
527 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); 529 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt);
528 this->recordBatch(batch); 530 this->recordBatch(batch);
529 batch->unref(); 531 batch->unref();
530 } 532 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698