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

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

Issue 1988923002: Remove GrRenderTarget from GrPipelineBuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to ToT 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
« no previous file with comments | « src/gpu/GrDrawTarget.h ('k') | src/gpu/GrPipeline.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 * 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"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 #if 0 123 #if 0
124 SkString str = fBatches[i]->dumpInfo(); 124 SkString str = fBatches[i]->dumpInfo();
125 SkDebugf("%s\n", str.c_str()); 125 SkDebugf("%s\n", str.c_str());
126 #endif 126 #endif
127 } 127 }
128 } 128 }
129 } 129 }
130 #endif 130 #endif
131 131
132 bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuil der, 132 bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuil der,
133 GrRenderTarget* rt,
133 const GrClip& clip, 134 const GrClip& clip,
134 const GrPipelineOptimizations& optimi zations, 135 const GrPipelineOptimizations& optimi zations,
135 GrXferProcessor::DstTexture* dstTextu re, 136 GrXferProcessor::DstTexture* dstTextu re,
136 const SkRect& batchBounds) { 137 const SkRect& batchBounds) {
137 SkRect bounds = batchBounds; 138 SkRect bounds = batchBounds;
138 bounds.outset(0.5f, 0.5f); 139 bounds.outset(0.5f, 0.5f);
139 140
140 if (!pipelineBuilder.willXPNeedDstTexture(*this->caps(), optimizations)) { 141 if (!pipelineBuilder.willXPNeedDstTexture(*this->caps(), optimizations)) {
141 return true; 142 return true;
142 } 143 }
143 144
144 GrRenderTarget* rt = pipelineBuilder.getRenderTarget();
145
146 if (this->caps()->textureBarrierSupport()) { 145 if (this->caps()->textureBarrierSupport()) {
147 if (GrTexture* rtTex = rt->asTexture()) { 146 if (GrTexture* rtTex = rt->asTexture()) {
148 // The render target is a texture, so we can read from it directly i n the shader. The XP 147 // The render target is a texture, so we can read from it directly i n the shader. The XP
149 // will be responsible to detect this situation and request a textur e barrier. 148 // will be responsible to detect this situation and request a textur e barrier.
150 dstTexture->setTexture(rtTex); 149 dstTexture->setTexture(rtTex);
151 dstTexture->setOffset(0, 0); 150 dstTexture->setOffset(0, 0);
152 return true; 151 return true;
153 } 152 }
154 } 153 }
155 154
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, 236 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder,
238 GrDrawContext* drawContext, 237 GrDrawContext* drawContext,
239 const GrClip& clip, 238 const GrClip& clip,
240 GrDrawBatch* batch) { 239 GrDrawBatch* batch) {
241 // Setup clip 240 // Setup clip
242 GrAppliedClip appliedClip; 241 GrAppliedClip appliedClip;
243 if (!clip.apply(fContext, pipelineBuilder, drawContext, &batch->bounds(), &a ppliedClip)) { 242 if (!clip.apply(fContext, pipelineBuilder, drawContext, &batch->bounds(), &a ppliedClip)) {
244 return; 243 return;
245 } 244 }
246 245
246 // TODO: this is the only remaining usage of the AutoRestoreFragmentProcesso rState - remove it
247 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; 247 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps;
248 if (appliedClip.clipCoverageFragmentProcessor()) { 248 if (appliedClip.clipCoverageFragmentProcessor()) {
249 arfps.set(&pipelineBuilder); 249 arfps.set(&pipelineBuilder);
250 arfps.addCoverageFragmentProcessor(appliedClip.clipCoverageFragmentProce ssor()); 250 arfps.addCoverageFragmentProcessor(appliedClip.clipCoverageFragmentProce ssor());
251 } 251 }
252 252
253 GrPipeline::CreateArgs args; 253 GrPipeline::CreateArgs args;
254 args.fPipelineBuilder = &pipelineBuilder; 254 args.fPipelineBuilder = &pipelineBuilder;
255 args.fDrawContext = drawContext;
255 args.fCaps = this->caps(); 256 args.fCaps = this->caps();
256 args.fScissor = &appliedClip.scissorState(); 257 args.fScissor = &appliedClip.scissorState();
257 args.fHasStencilClip = appliedClip.hasStencilClip(); 258 args.fHasStencilClip = appliedClip.hasStencilClip();
258 if (pipelineBuilder.hasUserStencilSettings() || appliedClip.hasStencilClip() ) { 259 if (pipelineBuilder.hasUserStencilSettings() || appliedClip.hasStencilClip() ) {
259 if (!fResourceProvider->attachStencilAttachment(pipelineBuilder.getRende rTarget())) { 260 if (!fResourceProvider->attachStencilAttachment(drawContext->accessRende rTarget())) {
260 SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); 261 SkDebugf("ERROR creating stencil attachment. Draw skipped.\n");
261 return; 262 return;
262 } 263 }
263 } 264 }
264 batch->getPipelineOptimizations(&args.fOpts); 265 batch->getPipelineOptimizations(&args.fOpts);
265 GrScissorState finalScissor; 266 GrScissorState finalScissor;
266 if (args.fOpts.fOverrides.fUsePLSDstRead || fClipBatchToBounds) { 267 if (args.fOpts.fOverrides.fUsePLSDstRead || fClipBatchToBounds) {
267 GrRenderTarget* rt = pipelineBuilder.getRenderTarget();
268 GrGLIRect viewport; 268 GrGLIRect viewport;
269 viewport.fLeft = 0; 269 viewport.fLeft = 0;
270 viewport.fBottom = 0; 270 viewport.fBottom = 0;
271 viewport.fWidth = rt->width(); 271 viewport.fWidth = drawContext->width();
272 viewport.fHeight = rt->height(); 272 viewport.fHeight = drawContext->height();
273 SkIRect ibounds; 273 SkIRect ibounds;
274 ibounds.fLeft = SkTPin(SkScalarFloorToInt(batch->bounds().fLeft), viewpo rt.fLeft, 274 ibounds.fLeft = SkTPin(SkScalarFloorToInt(batch->bounds().fLeft), viewpo rt.fLeft,
275 viewport.fWidth); 275 viewport.fWidth);
276 ibounds.fTop = SkTPin(SkScalarFloorToInt(batch->bounds().fTop), viewport .fBottom, 276 ibounds.fTop = SkTPin(SkScalarFloorToInt(batch->bounds().fTop), viewport .fBottom,
277 viewport.fHeight); 277 viewport.fHeight);
278 ibounds.fRight = SkTPin(SkScalarCeilToInt(batch->bounds().fRight), viewp ort.fLeft, 278 ibounds.fRight = SkTPin(SkScalarCeilToInt(batch->bounds().fRight), viewp ort.fLeft,
279 viewport.fWidth); 279 viewport.fWidth);
280 ibounds.fBottom = SkTPin(SkScalarCeilToInt(batch->bounds().fBottom), vie wport.fBottom, 280 ibounds.fBottom = SkTPin(SkScalarCeilToInt(batch->bounds().fBottom), vie wport.fBottom,
281 viewport.fHeight); 281 viewport.fHeight);
282 if (appliedClip.scissorState().enabled()) { 282 if (appliedClip.scissorState().enabled()) {
283 const SkIRect& scissorRect = appliedClip.scissorState().rect(); 283 const SkIRect& scissorRect = appliedClip.scissorState().rect();
284 if (!ibounds.intersect(scissorRect)) { 284 if (!ibounds.intersect(scissorRect)) {
285 return; 285 return;
286 } 286 }
287 } 287 }
288 finalScissor.set(ibounds); 288 finalScissor.set(ibounds);
289 args.fScissor = &finalScissor; 289 args.fScissor = &finalScissor;
290 } 290 }
291 args.fOpts.fColorPOI.completeCalculations(pipelineBuilder.fColorFragmentProc essors.begin(), 291 args.fOpts.fColorPOI.completeCalculations(pipelineBuilder.fColorFragmentProc essors.begin(),
292 pipelineBuilder.numColorFragmentPr ocessors()); 292 pipelineBuilder.numColorFragmentPr ocessors());
293 args.fOpts.fCoveragePOI.completeCalculations( 293 args.fOpts.fCoveragePOI.completeCalculations(
294 pipelineBuilder.fCoverageFragment Processors.begin(), 294 pipelineBuilder.fCoverageFragment Processors.begin(),
295 pipelineBuilder.numCoverageFragme ntProcessors()); 295 pipelineBuilder.numCoverageFragme ntProcessors());
296 if (!this->setupDstReadIfNecessary(pipelineBuilder, clip, args.fOpts, &args. fDstTexture, 296 if (!this->setupDstReadIfNecessary(pipelineBuilder, drawContext->accessRende rTarget(),
297 batch->bounds())) { 297 clip, args.fOpts,
298 &args.fDstTexture, batch->bounds())) {
298 return; 299 return;
299 } 300 }
300 301
301 if (!batch->installPipeline(args)) { 302 if (!batch->installPipeline(args)) {
302 return; 303 return;
303 } 304 }
304 305
305 #ifdef ENABLE_MDB 306 #ifdef ENABLE_MDB
306 SkASSERT(fRenderTarget); 307 SkASSERT(fRenderTarget);
307 batch->pipeline()->addDependenciesTo(fRenderTarget); 308 batch->pipeline()->addDependenciesTo(fRenderTarget);
(...skipping 16 matching lines...) Expand all
324 GrAppliedClip appliedClip; 325 GrAppliedClip appliedClip;
325 if (!clip.apply(fContext, pipelineBuilder, drawContext, nullptr, &appliedCli p)) { 326 if (!clip.apply(fContext, pipelineBuilder, drawContext, nullptr, &appliedCli p)) {
326 return; 327 return;
327 } 328 }
328 // TODO: respect fClipBatchToBounds if we ever start computing bounds here. 329 // TODO: respect fClipBatchToBounds if we ever start computing bounds here.
329 330
330 // Coverage AA does not make sense when rendering to the stencil buffer. The caller should never 331 // Coverage AA does not make sense when rendering to the stencil buffer. The caller should never
331 // attempt this in a situation that would require coverage AA. 332 // attempt this in a situation that would require coverage AA.
332 SkASSERT(!appliedClip.clipCoverageFragmentProcessor()); 333 SkASSERT(!appliedClip.clipCoverageFragmentProcessor());
333 334
334 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); 335 GrStencilAttachment* stencilAttachment = fResourceProvider->attachStencilAtt achment(
335 GrStencilAttachment* stencilAttachment = fResourceProvider->attachStencilAtt achment(rt); 336 drawContext->accessRenderTarget( ));
336 if (!stencilAttachment) { 337 if (!stencilAttachment) {
337 SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); 338 SkDebugf("ERROR creating stencil attachment. Draw skipped.\n");
338 return; 339 return;
339 } 340 }
340 341
341 GrBatch* batch = GrStencilPathBatch::Create(viewMatrix, 342 GrBatch* batch = GrStencilPathBatch::Create(viewMatrix,
342 pipelineBuilder.isHWAntialias(), 343 pipelineBuilder.isHWAntialias(),
343 fill, 344 fill,
344 appliedClip.hasStencilClip(), 345 appliedClip.hasStencilClip(),
345 stencilAttachment->bits(), 346 stencilAttachment->bits(),
346 appliedClip.scissorState(), 347 appliedClip.scissorState(),
347 pipelineBuilder.getRenderTarget( ), 348 drawContext->accessRenderTarget( ),
348 path); 349 path);
349 this->recordBatch(batch); 350 this->recordBatch(batch);
350 batch->unref(); 351 batch->unref();
351 } 352 }
352 353
353 void GrDrawTarget::clear(const SkIRect* rect, 354 void GrDrawTarget::clear(const SkIRect* rect,
354 GrColor color, 355 GrColor color,
355 bool canIgnoreRect, 356 bool canIgnoreRect,
356 GrDrawContext* drawContext) { 357 GrDrawContext* drawContext) {
357 SkIRect rtRect = SkIRect::MakeWH(drawContext->width(), drawContext->height() ); 358 SkIRect rtRect = SkIRect::MakeWH(drawContext->width(), drawContext->height() );
(...skipping 11 matching lines...) Expand all
369 } 370 }
370 371
371 if (this->caps()->useDrawInsteadOfClear()) { 372 if (this->caps()->useDrawInsteadOfClear()) {
372 // This works around a driver bug with clear by drawing a rect instead. 373 // This works around a driver bug with clear by drawing a rect instead.
373 // The driver will ignore a clear if it is the only thing rendered to a 374 // The driver will ignore a clear if it is the only thing rendered to a
374 // target before the target is read. 375 // target before the target is read.
375 if (rect == &rtRect) { 376 if (rect == &rtRect) {
376 drawContext->discard(); 377 drawContext->discard();
377 } 378 }
378 379
380 // TODO: flip this into real draw!
379 GrPipelineBuilder pipelineBuilder; 381 GrPipelineBuilder pipelineBuilder;
380 pipelineBuilder.setXPFactory( 382 pipelineBuilder.setXPFactory(
381 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref(); 383 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref();
382 pipelineBuilder.setRenderTarget(drawContext->accessRenderTarget());
383 384
384 SkRect scalarRect = SkRect::Make(*rect); 385 SkRect scalarRect = SkRect::Make(*rect);
385 SkAutoTUnref<GrDrawBatch> batch( 386 SkAutoTUnref<GrDrawBatch> batch(
386 GrRectBatchFactory::CreateNonAAFill(color, SkMatrix::I(), scalar Rect, 387 GrRectBatchFactory::CreateNonAAFill(color, SkMatrix::I(), scalar Rect,
387 nullptr, nullptr)); 388 nullptr, nullptr));
388 this->drawBatch(pipelineBuilder, drawContext, GrNoClip(), batch); 389 this->drawBatch(pipelineBuilder, drawContext, GrNoClip(), batch);
389 } else { 390 } else {
390 GrBatch* batch = new GrClearBatch(*rect, color, drawContext->accessRende rTarget()); 391 GrBatch* batch = new GrClearBatch(*rect, color, drawContext->accessRende rTarget());
391 this->recordBatch(batch); 392 this->recordBatch(batch);
392 batch->unref(); 393 batch->unref();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 } 524 }
524 } 525 }
525 526
526 /////////////////////////////////////////////////////////////////////////////// 527 ///////////////////////////////////////////////////////////////////////////////
527 528
528 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend erTarget* rt) { 529 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend erTarget* rt) {
529 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); 530 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt);
530 this->recordBatch(batch); 531 this->recordBatch(batch);
531 batch->unref(); 532 batch->unref();
532 } 533 }
OLDNEW
« no previous file with comments | « src/gpu/GrDrawTarget.h ('k') | src/gpu/GrPipeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698