OLD | NEW |
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 fGpu->unref(); | 44 fGpu->unref(); |
45 fCaps->unref(); | 45 fCaps->unref(); |
46 } | 46 } |
47 | 47 |
48 //////////////////////////////////////////////////////////////////////////////// | 48 //////////////////////////////////////////////////////////////////////////////// |
49 | 49 |
50 bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuil
der, | 50 bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuil
der, |
51 const GrProcOptInfo& colorPOI, | 51 const GrProcOptInfo& colorPOI, |
52 const GrProcOptInfo& coveragePOI, | 52 const GrProcOptInfo& coveragePOI, |
53 GrXferProcessor::DstTexture* dstTextu
re, | 53 GrXferProcessor::DstTexture* dstTextu
re, |
54 const SkRect* drawBounds) { | 54 const SkRect& batchBounds) { |
| 55 SkRect bounds = batchBounds; |
| 56 bounds.outset(0.5f, 0.5f); |
| 57 |
55 if (!pipelineBuilder.willXPNeedDstTexture(*this->caps(), colorPOI, coverageP
OI)) { | 58 if (!pipelineBuilder.willXPNeedDstTexture(*this->caps(), colorPOI, coverageP
OI)) { |
56 return true; | 59 return true; |
57 } | 60 } |
58 | 61 |
59 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); | 62 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
60 | 63 |
61 if (this->caps()->textureBarrierSupport()) { | 64 if (this->caps()->textureBarrierSupport()) { |
62 if (GrTexture* rtTex = rt->asTexture()) { | 65 if (GrTexture* rtTex = rt->asTexture()) { |
63 // The render target is a texture, so we can read from it directly i
n the shader. The XP | 66 // The render target is a texture, so we can read from it directly i
n the shader. The XP |
64 // will be responsible to detect this situation and request a textur
e barrier. | 67 // will be responsible to detect this situation and request a textur
e barrier. |
65 dstTexture->setTexture(rtTex); | 68 dstTexture->setTexture(rtTex); |
66 dstTexture->setOffset(0, 0); | 69 dstTexture->setOffset(0, 0); |
67 return true; | 70 return true; |
68 } | 71 } |
69 } | 72 } |
70 | 73 |
71 SkIRect copyRect; | 74 SkIRect copyRect; |
72 pipelineBuilder.clip().getConservativeBounds(rt, ©Rect); | 75 pipelineBuilder.clip().getConservativeBounds(rt, ©Rect); |
73 | 76 |
74 if (drawBounds) { | 77 SkIRect drawIBounds; |
75 SkIRect drawIBounds; | 78 bounds.roundOut(&drawIBounds); |
76 drawBounds->roundOut(&drawIBounds); | 79 if (!copyRect.intersect(drawIBounds)) { |
77 if (!copyRect.intersect(drawIBounds)) { | |
78 #ifdef SK_DEBUG | 80 #ifdef SK_DEBUG |
79 GrCapsDebugf(fCaps, "Missed an early reject. " | 81 GrCapsDebugf(fCaps, "Missed an early reject. " |
80 "Bailing on draw from setupDstReadIfNecessary.\n"); | 82 "Bailing on draw from setupDstReadIfNecessary.\n"); |
81 #endif | 83 #endif |
82 return false; | 84 return false; |
83 } | |
84 } else { | |
85 #ifdef SK_DEBUG | |
86 //SkDebugf("No dev bounds when dst copy is made.\n"); | |
87 #endif | |
88 } | 85 } |
89 | 86 |
90 // MSAA consideration: When there is support for reading MSAA samples in the
shader we could | 87 // MSAA consideration: When there is support for reading MSAA samples in the
shader we could |
91 // have per-sample dst values by making the copy multisampled. | 88 // have per-sample dst values by making the copy multisampled. |
92 GrSurfaceDesc desc; | 89 GrSurfaceDesc desc; |
93 if (!this->getGpu()->initCopySurfaceDstDesc(rt, &desc)) { | 90 if (!this->getGpu()->initCopySurfaceDstDesc(rt, &desc)) { |
94 desc.fOrigin = kDefault_GrSurfaceOrigin; | 91 desc.fOrigin = kDefault_GrSurfaceOrigin; |
95 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 92 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
96 desc.fConfig = rt->config(); | 93 desc.fConfig = rt->config(); |
97 } | 94 } |
98 | 95 |
99 | |
100 desc.fWidth = copyRect.width(); | 96 desc.fWidth = copyRect.width(); |
101 desc.fHeight = copyRect.height(); | 97 desc.fHeight = copyRect.height(); |
102 | 98 |
103 static const uint32_t kFlags = 0; | 99 static const uint32_t kFlags = 0; |
104 SkAutoTUnref<GrTexture> copy(fResourceProvider->createApproxTexture(desc, kF
lags)); | 100 SkAutoTUnref<GrTexture> copy(fResourceProvider->createApproxTexture(desc, kF
lags)); |
105 | 101 |
106 if (!copy) { | 102 if (!copy) { |
107 SkDebugf("Failed to create temporary copy of destination texture.\n"); | 103 SkDebugf("Failed to create temporary copy of destination texture.\n"); |
108 return false; | 104 return false; |
109 } | 105 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 143 |
148 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat
ch* batch) { | 144 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat
ch* batch) { |
149 // Setup clip | 145 // Setup clip |
150 GrScissorState scissorState; | 146 GrScissorState scissorState; |
151 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; | 147 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
152 GrPipelineBuilder::AutoRestoreStencil ars; | 148 GrPipelineBuilder::AutoRestoreStencil ars; |
153 if (!this->setupClip(pipelineBuilder, &arfps, &ars, &scissorState, &batch->b
ounds())) { | 149 if (!this->setupClip(pipelineBuilder, &arfps, &ars, &scissorState, &batch->b
ounds())) { |
154 return; | 150 return; |
155 } | 151 } |
156 | 152 |
157 // Batch bounds are tight, so for dev copies | 153 GrPipeline::CreateArgs args; |
158 // TODO move this into setupDstReadIfNecessary when paths are in batch | 154 if (!this->installPipelineInDrawBatch(&pipelineBuilder, &scissorState, batch
)) { |
159 SkRect bounds = batch->bounds(); | |
160 bounds.outset(0.5f, 0.5f); | |
161 | |
162 GrDrawTarget::PipelineInfo pipelineInfo(&pipelineBuilder, &scissorState, bat
ch, &bounds, | |
163 this); | |
164 | |
165 if (!pipelineInfo.valid()) { | |
166 return; | 155 return; |
167 } | 156 } |
168 if (!batch->installPipeline(pipelineInfo.pipelineCreateArgs())) { | 157 |
169 return; | |
170 } | |
171 this->recordBatch(batch); | 158 this->recordBatch(batch); |
172 } | 159 } |
173 | 160 |
174 static const GrStencilSettings& winding_path_stencil_settings() { | 161 static const GrStencilSettings& winding_path_stencil_settings() { |
175 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, | 162 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
176 kIncClamp_StencilOp, | 163 kIncClamp_StencilOp, |
177 kIncClamp_StencilOp, | 164 kIncClamp_StencilOp, |
178 kAlwaysIfInClip_StencilFunc, | 165 kAlwaysIfInClip_StencilFunc, |
179 0xFFFF, 0xFFFF, 0xFFFF); | 166 0xFFFF, 0xFFFF, 0xFFFF); |
180 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); | 167 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 return; | 262 return; |
276 } | 263 } |
277 | 264 |
278 // Ensure the render target has a stencil buffer and get the stencil setting
s. | 265 // Ensure the render target has a stencil buffer and get the stencil setting
s. |
279 GrStencilSettings stencilSettings; | 266 GrStencilSettings stencilSettings; |
280 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); | 267 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
281 GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment(); | 268 GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment(); |
282 this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); | 269 this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
283 batch->setStencilSettings(stencilSettings); | 270 batch->setStencilSettings(stencilSettings); |
284 | 271 |
285 GrDrawTarget::PipelineInfo pipelineInfo(&pipelineBuilder, &scissorState, bat
ch, | 272 GrPipeline::CreateArgs args; |
286 &batch->bounds(), this); | 273 if (!this->installPipelineInDrawBatch(&pipelineBuilder, &scissorState, batch
)) { |
287 | |
288 if (!pipelineInfo.valid()) { | |
289 return; | |
290 } | |
291 if (!batch->installPipeline(pipelineInfo.pipelineCreateArgs())) { | |
292 return; | 274 return; |
293 } | 275 } |
294 | 276 |
295 this->recordBatch(batch); | 277 this->recordBatch(batch); |
296 } | 278 } |
297 | 279 |
298 void GrDrawTarget::drawNonAARect(const GrPipelineBuilder& pipelineBuilder, | 280 void GrDrawTarget::drawNonAARect(const GrPipelineBuilder& pipelineBuilder, |
299 GrColor color, | 281 GrColor color, |
300 const SkMatrix& viewMatrix, | 282 const SkMatrix& viewMatrix, |
301 const SkRect& rect) { | 283 const SkRect& rect) { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 } | 426 } |
445 } | 427 } |
446 } else { | 428 } else { |
447 GrBATCH_INFO("\t\tFirstBatch\n"); | 429 GrBATCH_INFO("\t\tFirstBatch\n"); |
448 } | 430 } |
449 fBatches.push_back().reset(SkRef(batch)); | 431 fBatches.push_back().reset(SkRef(batch)); |
450 } | 432 } |
451 | 433 |
452 /////////////////////////////////////////////////////////////////////////////// | 434 /////////////////////////////////////////////////////////////////////////////// |
453 | 435 |
454 GrDrawTarget::PipelineInfo::PipelineInfo(const GrPipelineBuilder* pipelineBuilde
r, | 436 bool GrDrawTarget::installPipelineInDrawBatch(const GrPipelineBuilder* pipelineB
uilder, |
455 const GrScissorState* scissor, | 437 const GrScissorState* scissor, |
456 const GrDrawBatch* batch, | 438 GrDrawBatch* batch) { |
457 const SkRect* devBounds, | 439 GrPipeline::CreateArgs args; |
458 GrDrawTarget* target) { | 440 args.fPipelineBuilder = pipelineBuilder; |
459 fArgs.fPipelineBuilder = pipelineBuilder; | 441 args.fCaps = this->caps(); |
460 fArgs.fCaps = target->caps(); | 442 args.fScissor = scissor; |
461 fArgs.fScissor = scissor; | 443 args.fColorPOI = pipelineBuilder->colorProcInfo(batch); |
462 fArgs.fColorPOI = fArgs.fPipelineBuilder->colorProcInfo(batch); | 444 args.fCoveragePOI = pipelineBuilder->coverageProcInfo(batch); |
463 fArgs.fCoveragePOI = fArgs.fPipelineBuilder->coverageProcInfo(batch); | 445 if (!this->setupDstReadIfNecessary(*pipelineBuilder, args.fColorPOI, |
464 if (!target->setupDstReadIfNecessary(*fArgs.fPipelineBuilder, fArgs.fColorPO
I, | 446 args.fCoveragePOI, &args.fDstTexture, |
465 fArgs.fCoveragePOI, &fArgs.fDstTexture,
devBounds)) { | 447 batch->bounds())) { |
466 fArgs.fPipelineBuilder = nullptr; | 448 return false; |
467 } | 449 } |
| 450 |
| 451 if (!batch->installPipeline(args)) { |
| 452 return false; |
| 453 } |
| 454 |
| 455 return true; |
468 } | 456 } |
469 | 457 |
470 /////////////////////////////////////////////////////////////////////////////// | 458 /////////////////////////////////////////////////////////////////////////////// |
471 GrClipTarget::GrClipTarget(GrContext* context) | 459 GrClipTarget::GrClipTarget(GrContext* context) |
472 : INHERITED(context->getGpu(), context->resourceProvider()) | 460 : INHERITED(context->getGpu(), context->resourceProvider()) |
473 , fContext(context) { | 461 , fContext(context) { |
474 fClipMaskManager.reset(new GrClipMaskManager(this)); | 462 fClipMaskManager.reset(new GrClipMaskManager(this)); |
475 } | 463 } |
476 | 464 |
477 | 465 |
(...skipping 13 matching lines...) Expand all Loading... |
491 // The clip mask manager can rebuild all its clip masks so just | 479 // The clip mask manager can rebuild all its clip masks so just |
492 // get rid of them all. | 480 // get rid of them all. |
493 fClipMaskManager->purgeResources(); | 481 fClipMaskManager->purgeResources(); |
494 }; | 482 }; |
495 | 483 |
496 void GrClipTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { | 484 void GrClipTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { |
497 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); | 485 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
498 this->recordBatch(batch); | 486 this->recordBatch(batch); |
499 batch->unref(); | 487 batch->unref(); |
500 } | 488 } |
OLD | NEW |