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" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 | 39 |
40 GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r esourceProvider, | 40 GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r esourceProvider, |
41 GrAuditTrail* auditTrail, const Options& options) | 41 GrAuditTrail* auditTrail, const Options& options) |
42 : fGpu(SkRef(gpu)) | 42 : fGpu(SkRef(gpu)) |
43 , fResourceProvider(resourceProvider) | 43 , fResourceProvider(resourceProvider) |
44 , fAuditTrail(auditTrail) | 44 , fAuditTrail(auditTrail) |
45 , fFlags(0) | 45 , fFlags(0) |
46 , fRenderTarget(rt) { | 46 , fRenderTarget(rt) { |
47 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) | 47 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) |
48 fContext = fGpu->getContext(); | 48 fContext = fGpu->getContext(); |
49 fClipMaskManager.reset(new GrClipMaskManager(this, options.fClipBatchToBound s)); | 49 fClipMaskManager.reset(new GrClipMaskManager(this)); |
50 | 50 |
51 fClipBatchToBounds = options.fClipBatchToBounds; | |
51 fDrawBatchBounds = options.fDrawBatchBounds; | 52 fDrawBatchBounds = options.fDrawBatchBounds; |
52 fMaxBatchLookback = (options.fMaxBatchLookback < 0) ? kDefaultMaxBatchLookba ck : | 53 fMaxBatchLookback = (options.fMaxBatchLookback < 0) ? kDefaultMaxBatchLookba ck : |
53 options.fMaxBatchLookb ack; | 54 options.fMaxBatchLookb ack; |
54 fMaxBatchLookahead = (options.fMaxBatchLookahead < 0) ? kDefaultMaxBatchLook ahead : | 55 fMaxBatchLookahead = (options.fMaxBatchLookahead < 0) ? kDefaultMaxBatchLook ahead : |
55 options.fMaxBatchLook ahead; | 56 options.fMaxBatchLook ahead; |
56 | 57 |
57 rt->setLastDrawTarget(this); | 58 rt->setLastDrawTarget(this); |
58 | 59 |
59 #ifdef SK_DEBUG | 60 #ifdef SK_DEBUG |
60 static int debugID = 0; | 61 static int debugID = 0; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 #if 0 | 123 #if 0 |
123 SkString str = fBatches[i]->dumpInfo(); | 124 SkString str = fBatches[i]->dumpInfo(); |
124 SkDebugf("%s\n", str.c_str()); | 125 SkDebugf("%s\n", str.c_str()); |
125 #endif | 126 #endif |
126 } | 127 } |
127 } | 128 } |
128 } | 129 } |
129 #endif | 130 #endif |
130 | 131 |
131 bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuil der, | 132 bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuil der, |
133 const GrClip& clip, | |
132 const GrPipelineOptimizations& optimi zations, | 134 const GrPipelineOptimizations& optimi zations, |
133 GrXferProcessor::DstTexture* dstTextu re, | 135 GrXferProcessor::DstTexture* dstTextu re, |
134 const SkRect& batchBounds) { | 136 const SkRect& batchBounds) { |
135 SkRect bounds = batchBounds; | 137 SkRect bounds = batchBounds; |
136 bounds.outset(0.5f, 0.5f); | 138 bounds.outset(0.5f, 0.5f); |
137 | 139 |
138 if (!pipelineBuilder.willXPNeedDstTexture(*this->caps(), optimizations)) { | 140 if (!pipelineBuilder.willXPNeedDstTexture(*this->caps(), optimizations)) { |
139 return true; | 141 return true; |
140 } | 142 } |
141 | 143 |
142 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); | 144 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
143 | 145 |
144 if (this->caps()->textureBarrierSupport()) { | 146 if (this->caps()->textureBarrierSupport()) { |
145 if (GrTexture* rtTex = rt->asTexture()) { | 147 if (GrTexture* rtTex = rt->asTexture()) { |
146 // The render target is a texture, so we can read from it directly i n the shader. The XP | 148 // The render target is a texture, so we can read from it directly i n the shader. The XP |
147 // will be responsible to detect this situation and request a textur e barrier. | 149 // will be responsible to detect this situation and request a textur e barrier. |
148 dstTexture->setTexture(rtTex); | 150 dstTexture->setTexture(rtTex); |
149 dstTexture->setOffset(0, 0); | 151 dstTexture->setOffset(0, 0); |
150 return true; | 152 return true; |
151 } | 153 } |
152 } | 154 } |
153 | 155 |
154 SkIRect copyRect; | 156 SkIRect copyRect; |
155 pipelineBuilder.clip().getConservativeBounds(rt->width(), rt->height(), &cop yRect); | 157 clip.getConservativeBounds(rt->width(), rt->height(), ©Rect); |
156 | 158 |
157 SkIRect drawIBounds; | 159 SkIRect drawIBounds; |
158 bounds.roundOut(&drawIBounds); | 160 bounds.roundOut(&drawIBounds); |
159 if (!copyRect.intersect(drawIBounds)) { | 161 if (!copyRect.intersect(drawIBounds)) { |
160 #ifdef SK_DEBUG | 162 #ifdef SK_DEBUG |
161 GrCapsDebugf(this->caps(), "Missed an early reject. " | 163 GrCapsDebugf(this->caps(), "Missed an early reject. " |
162 "Bailing on draw from setupDstReadIfNecessary .\n"); | 164 "Bailing on draw from setupDstReadIfNecessary .\n"); |
163 #endif | 165 #endif |
164 return false; | 166 return false; |
165 } | 167 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 } | 228 } |
227 | 229 |
228 fGpu->finishDrawTarget(); | 230 fGpu->finishDrawTarget(); |
229 } | 231 } |
230 | 232 |
231 void GrDrawTarget::reset() { | 233 void GrDrawTarget::reset() { |
232 fBatches.reset(); | 234 fBatches.reset(); |
233 } | 235 } |
234 | 236 |
235 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, | 237 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, |
236 GrDrawBatch* batch, | 238 const GrClip& clip, |
237 const SkIRect* scissorRect) { | 239 GrDrawBatch* batch) { |
238 // Setup clip | 240 // Setup clip |
239 GrAppliedClip clip; | 241 GrAppliedClip appliedClip; |
240 | 242 if (!fClipMaskManager->setupClipping(pipelineBuilder, clip, &batch->bounds() , &appliedClip)) { |
241 if (scissorRect) { | 243 return; |
242 SkASSERT(GrClip::kWideOpen_ClipType == pipelineBuilder.clip().clipType() ); | |
243 if (!fClipMaskManager->setupScissorClip(pipelineBuilder, *scissorRect, | |
244 &batch->bounds(), &clip)) { | |
245 return; | |
246 } | |
247 } else { | |
248 if (!fClipMaskManager->setupClipping(pipelineBuilder, &batch->bounds(), &clip)) { | |
249 return; | |
250 } | |
251 } | 244 } |
252 | 245 |
253 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; | 246 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
254 if (clip.clipCoverageFragmentProcessor()) { | 247 if (appliedClip.clipCoverageFragmentProcessor()) { |
255 arfps.set(&pipelineBuilder); | 248 arfps.set(&pipelineBuilder); |
256 arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor()) ; | 249 arfps.addCoverageFragmentProcessor(appliedClip.clipCoverageFragmentProce ssor()); |
257 } | 250 } |
258 | 251 |
259 GrPipeline::CreateArgs args; | 252 GrPipeline::CreateArgs args; |
260 args.fPipelineBuilder = &pipelineBuilder; | 253 args.fPipelineBuilder = &pipelineBuilder; |
261 args.fCaps = this->caps(); | 254 args.fCaps = this->caps(); |
262 args.fScissor = &clip.scissorState(); | 255 args.fScissor = &appliedClip.scissorState(); |
263 args.fHasStencilClip = clip.hasStencilClip(); | 256 args.fHasStencilClip = appliedClip.hasStencilClip(); |
264 if (pipelineBuilder.hasUserStencilSettings() || clip.hasStencilClip()) { | 257 if (pipelineBuilder.hasUserStencilSettings() || appliedClip.hasStencilClip() ) { |
265 fResourceProvider->attachStencilAttachment(pipelineBuilder.getRenderTarg et()); | 258 fResourceProvider->attachStencilAttachment(pipelineBuilder.getRenderTarg et()); |
266 } | 259 } |
267 batch->getPipelineOptimizations(&args.fOpts); | 260 batch->getPipelineOptimizations(&args.fOpts); |
268 GrScissorState finalScissor; | 261 GrScissorState finalScissor; |
269 if (args.fOpts.fOverrides.fUsePLSDstRead) { | 262 if (args.fOpts.fOverrides.fUsePLSDstRead || fClipBatchToBounds) { |
270 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); | 263 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
271 GrGLIRect viewport; | 264 GrGLIRect viewport; |
272 viewport.fLeft = 0; | 265 viewport.fLeft = 0; |
273 viewport.fBottom = 0; | 266 viewport.fBottom = 0; |
274 viewport.fWidth = rt->width(); | 267 viewport.fWidth = rt->width(); |
275 viewport.fHeight = rt->height(); | 268 viewport.fHeight = rt->height(); |
276 SkIRect ibounds; | 269 SkIRect ibounds; |
277 ibounds.fLeft = SkTPin(SkScalarFloorToInt(batch->bounds().fLeft), viewpo rt.fLeft, | 270 ibounds.fLeft = SkTPin(SkScalarFloorToInt(batch->bounds().fLeft), viewpo rt.fLeft, |
278 viewport.fWidth); | 271 viewport.fWidth); |
279 ibounds.fTop = SkTPin(SkScalarFloorToInt(batch->bounds().fTop), viewport .fBottom, | 272 ibounds.fTop = SkTPin(SkScalarFloorToInt(batch->bounds().fTop), viewport .fBottom, |
280 viewport.fHeight); | 273 viewport.fHeight); |
281 ibounds.fRight = SkTPin(SkScalarCeilToInt(batch->bounds().fRight), viewp ort.fLeft, | 274 ibounds.fRight = SkTPin(SkScalarCeilToInt(batch->bounds().fRight), viewp ort.fLeft, |
282 viewport.fWidth); | 275 viewport.fWidth); |
283 ibounds.fBottom = SkTPin(SkScalarCeilToInt(batch->bounds().fBottom), vie wport.fBottom, | 276 ibounds.fBottom = SkTPin(SkScalarCeilToInt(batch->bounds().fBottom), vie wport.fBottom, |
284 viewport.fHeight); | 277 viewport.fHeight); |
285 if (clip.scissorState().enabled()) { | 278 if (appliedClip.scissorState().enabled()) { |
286 const SkIRect& scissorRect = clip.scissorState().rect(); | 279 const SkIRect& scissorRect = appliedClip.scissorState().rect(); |
287 if (!ibounds.intersect(scissorRect)) { | 280 if (!ibounds.intersect(scissorRect)) { |
288 ibounds = scissorRect; | 281 return; |
289 } | 282 } |
290 } | 283 } |
291 finalScissor.set(ibounds); | 284 finalScissor.set(ibounds); |
292 args.fScissor = &finalScissor; | 285 args.fScissor = &finalScissor; |
293 } | 286 } |
294 args.fOpts.fColorPOI.completeCalculations(pipelineBuilder.fColorFragmentProc essors.begin(), | 287 args.fOpts.fColorPOI.completeCalculations(pipelineBuilder.fColorFragmentProc essors.begin(), |
295 pipelineBuilder.numColorFragmentPr ocessors()); | 288 pipelineBuilder.numColorFragmentPr ocessors()); |
296 args.fOpts.fCoveragePOI.completeCalculations( | 289 args.fOpts.fCoveragePOI.completeCalculations( |
297 pipelineBuilder.fCoverageFragment Processors.begin(), | 290 pipelineBuilder.fCoverageFragment Processors.begin(), |
298 pipelineBuilder.numCoverageFragme ntProcessors()); | 291 pipelineBuilder.numCoverageFragme ntProcessors()); |
299 if (!this->setupDstReadIfNecessary(pipelineBuilder, args.fOpts, &args.fDstTe xture, | 292 if (!this->setupDstReadIfNecessary(pipelineBuilder, clip, args.fOpts, &args. fDstTexture, |
300 batch->bounds())) { | 293 batch->bounds())) { |
301 return; | 294 return; |
302 } | 295 } |
303 | 296 |
304 if (!batch->installPipeline(args)) { | 297 if (!batch->installPipeline(args)) { |
305 return; | 298 return; |
306 } | 299 } |
307 | 300 |
308 #ifdef ENABLE_MDB | 301 #ifdef ENABLE_MDB |
309 SkASSERT(fRenderTarget); | 302 SkASSERT(fRenderTarget); |
310 batch->pipeline()->addDependenciesTo(fRenderTarget); | 303 batch->pipeline()->addDependenciesTo(fRenderTarget); |
311 #endif | 304 #endif |
312 | 305 |
313 this->recordBatch(batch); | 306 this->recordBatch(batch); |
314 } | 307 } |
315 | 308 |
316 void GrDrawTarget::stencilPath(const GrPipelineBuilder& pipelineBuilder, | 309 void GrDrawTarget::stencilPath(const GrPipelineBuilder& pipelineBuilder, |
bsalomon
2016/05/12 21:25:35
Curious why we have this function anymore.. Can th
Chris Dalton
2016/05/12 21:29:19
The (current) reason is that GrStencilPathBatch do
| |
310 const GrClip& clip, | |
317 const SkMatrix& viewMatrix, | 311 const SkMatrix& viewMatrix, |
318 const GrPath* path, | 312 const GrPath* path, |
319 GrPathRendering::FillType fill) { | 313 GrPathRendering::FillType fill) { |
320 // TODO: extract portions of checkDraw that are relevant to path stenciling. | 314 // TODO: extract portions of checkDraw that are relevant to path stenciling. |
321 SkASSERT(path); | 315 SkASSERT(path); |
322 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); | 316 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
323 | 317 |
324 // Setup clip | 318 // Setup clip |
325 GrAppliedClip clip; | 319 GrAppliedClip appliedClip; |
326 if (!fClipMaskManager->setupClipping(pipelineBuilder, nullptr, &clip)) { | 320 if (!fClipMaskManager->setupClipping(pipelineBuilder, clip, nullptr, &applie dClip)) { |
327 return; | 321 return; |
328 } | 322 } |
323 // TODO: respect fClipBatchToBounds if we ever start computing bounds here. | |
329 | 324 |
330 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; | 325 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
331 if (clip.clipCoverageFragmentProcessor()) { | 326 if (appliedClip.clipCoverageFragmentProcessor()) { |
332 arfps.set(&pipelineBuilder); | 327 arfps.set(&pipelineBuilder); |
333 arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor()) ; | 328 arfps.addCoverageFragmentProcessor(appliedClip.clipCoverageFragmentProce ssor()); |
334 } | 329 } |
335 | 330 |
336 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); | 331 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
337 GrStencilAttachment* stencilAttachment = fResourceProvider->attachStencilAtt achment(rt); | 332 GrStencilAttachment* stencilAttachment = fResourceProvider->attachStencilAtt achment(rt); |
338 | 333 |
339 GrBatch* batch = GrStencilPathBatch::Create(viewMatrix, | 334 GrBatch* batch = GrStencilPathBatch::Create(viewMatrix, |
340 pipelineBuilder.isHWAntialias(), | 335 pipelineBuilder.isHWAntialias(), |
341 fill, | 336 fill, |
342 clip.hasStencilClip(), | 337 appliedClip.hasStencilClip(), |
343 stencilAttachment->bits(), | 338 stencilAttachment->bits(), |
344 clip.scissorState(), | 339 appliedClip.scissorState(), |
345 pipelineBuilder.getRenderTarget( ), | 340 pipelineBuilder.getRenderTarget( ), |
346 path); | 341 path); |
347 this->recordBatch(batch); | 342 this->recordBatch(batch); |
348 batch->unref(); | 343 batch->unref(); |
349 } | 344 } |
350 | 345 |
351 void GrDrawTarget::clear(const SkIRect* rect, | 346 void GrDrawTarget::clear(const SkIRect* rect, |
352 GrColor color, | 347 GrColor color, |
353 bool canIgnoreRect, | 348 bool canIgnoreRect, |
354 GrRenderTarget* renderTarget) { | 349 GrRenderTarget* renderTarget) { |
(...skipping 21 matching lines...) Expand all Loading... | |
376 | 371 |
377 GrPipelineBuilder pipelineBuilder; | 372 GrPipelineBuilder pipelineBuilder; |
378 pipelineBuilder.setXPFactory( | 373 pipelineBuilder.setXPFactory( |
379 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref(); | 374 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref(); |
380 pipelineBuilder.setRenderTarget(renderTarget); | 375 pipelineBuilder.setRenderTarget(renderTarget); |
381 | 376 |
382 SkRect scalarRect = SkRect::Make(*rect); | 377 SkRect scalarRect = SkRect::Make(*rect); |
383 SkAutoTUnref<GrDrawBatch> batch( | 378 SkAutoTUnref<GrDrawBatch> batch( |
384 GrRectBatchFactory::CreateNonAAFill(color, SkMatrix::I(), scalar Rect, | 379 GrRectBatchFactory::CreateNonAAFill(color, SkMatrix::I(), scalar Rect, |
385 nullptr, nullptr)); | 380 nullptr, nullptr)); |
386 this->drawBatch(pipelineBuilder, batch); | 381 this->drawBatch(pipelineBuilder, GrClip::WideOpen(), batch); |
387 } else { | 382 } else { |
388 GrBatch* batch = new GrClearBatch(*rect, color, renderTarget); | 383 GrBatch* batch = new GrClearBatch(*rect, color, renderTarget); |
389 this->recordBatch(batch); | 384 this->recordBatch(batch); |
390 batch->unref(); | 385 batch->unref(); |
391 } | 386 } |
392 } | 387 } |
393 | 388 |
394 void GrDrawTarget::discard(GrRenderTarget* renderTarget) { | 389 void GrDrawTarget::discard(GrRenderTarget* renderTarget) { |
395 if (this->caps()->discardRenderTargetSupport()) { | 390 if (this->caps()->discardRenderTargetSupport()) { |
396 GrBatch* batch = new GrDiscardBatch(renderTarget); | 391 GrBatch* batch = new GrDiscardBatch(renderTarget); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
521 } | 516 } |
522 } | 517 } |
523 | 518 |
524 /////////////////////////////////////////////////////////////////////////////// | 519 /////////////////////////////////////////////////////////////////////////////// |
525 | 520 |
526 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend erTarget* rt) { | 521 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend erTarget* rt) { |
527 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); | 522 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
528 this->recordBatch(batch); | 523 this->recordBatch(batch); |
529 batch->unref(); | 524 batch->unref(); |
530 } | 525 } |
OLD | NEW |