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 | 9 |
10 | 10 |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 | 400 |
401 GrAssert(drawState.validateVertexAttribs()); | 401 GrAssert(drawState.validateVertexAttribs()); |
402 #endif | 402 #endif |
403 if (NULL == drawState.getRenderTarget()) { | 403 if (NULL == drawState.getRenderTarget()) { |
404 return false; | 404 return false; |
405 } | 405 } |
406 return true; | 406 return true; |
407 } | 407 } |
408 | 408 |
409 bool GrDrawTarget::setupDstReadIfNecessary(DrawInfo* info) { | 409 bool GrDrawTarget::setupDstReadIfNecessary(DrawInfo* info) { |
410 bool willReadDst = false; | 410 if (!this->getDrawState().willEffectReadDst()) { |
411 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | |
412 const GrEffectRef* effect = this->drawState()->getStage(s).getEffect(); | |
413 if (NULL != effect && (*effect)->willReadDst()) { | |
414 willReadDst = true; | |
415 break; | |
416 } | |
417 } | |
418 if (!willReadDst) { | |
419 return true; | 411 return true; |
420 } | 412 } |
421 GrRenderTarget* rt = this->drawState()->getRenderTarget(); | 413 GrRenderTarget* rt = this->drawState()->getRenderTarget(); |
422 // If the dst is not a texture then we don't currently have a way of copying
the | 414 // If the dst is not a texture then we don't currently have a way of copying
the |
423 // texture. TODO: make copying RT->Tex (or Surface->Surface) a GrDrawTarget
operation that can | 415 // texture. TODO: make copying RT->Tex (or Surface->Surface) a GrDrawTarget
operation that can |
424 // be built on top of GL/D3D APIs. | 416 // be built on top of GL/D3D APIs. |
425 if (NULL == rt->asTexture()) { | 417 if (NULL == rt->asTexture()) { |
426 GrPrintf("Reading Dst of non-texture render target is not currently supp
orted.\n"); | 418 GrPrintf("Reading Dst of non-texture render target is not currently supp
orted.\n"); |
427 return false; | 419 return false; |
428 } | 420 } |
429 // TODO: Consider bounds of draw and bounds of clip | |
430 | 421 |
| 422 const GrClipData* clip = this->getClip(); |
| 423 GrIRect copyRect; |
| 424 clip->getConservativeBounds(this->getDrawState().getRenderTarget(), ©Rec
t); |
| 425 SkIRect drawIBounds; |
| 426 if (info->getDevIBounds(&drawIBounds)) { |
| 427 if (!copyRect.intersect(drawIBounds)) { |
| 428 #if GR_DEBUG |
| 429 GrPrintf("Missed an early reject. Bailing on draw from setupDstReadI
fNecessary.\n"); |
| 430 #endif |
| 431 return false; |
| 432 } |
| 433 } else { |
| 434 #if GR_DEBUG |
| 435 //GrPrintf("No dev bounds when dst copy is made.\n"); |
| 436 #endif |
| 437 } |
| 438 |
431 GrDrawTarget::AutoGeometryAndStatePush agasp(this, kReset_ASRInit); | 439 GrDrawTarget::AutoGeometryAndStatePush agasp(this, kReset_ASRInit); |
432 | 440 |
433 // The draw will resolve dst if it has MSAA. Two things to consider in the f
uture: | 441 // The draw will resolve dst if it has MSAA. Two things to consider in the f
uture: |
434 // 1) to make the dst values be pre-resolve we'd need to be able to copy to
MSAA | 442 // 1) to make the dst values be pre-resolve we'd need to be able to copy to
MSAA |
435 // texture and sample it correctly in the shader. 2) If 1 isn't available th
en we | 443 // texture and sample it correctly in the shader. 2) If 1 isn't available th
en we |
436 // should just resolve and use the resolved texture directly rather than mak
ing a | 444 // should just resolve and use the resolved texture directly rather than mak
ing a |
437 // copy of it. | 445 // copy of it. |
438 GrTextureDesc desc; | 446 GrTextureDesc desc; |
439 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 447 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
440 desc.fWidth = rt->width(); | 448 desc.fWidth = copyRect.width(); |
441 desc.fHeight = rt->height(); | 449 desc.fHeight = copyRect.height(); |
442 desc.fSampleCnt = 0; | 450 desc.fSampleCnt = 0; |
443 desc.fConfig = rt->config(); | 451 desc.fConfig = rt->config(); |
444 | 452 |
445 GrAutoScratchTexture ast(fContext, desc, GrContext::kApprox_ScratchTexMatch)
; | 453 GrAutoScratchTexture ast(fContext, desc, GrContext::kApprox_ScratchTexMatch)
; |
446 | 454 |
447 if (NULL == ast.texture()) { | 455 if (NULL == ast.texture()) { |
448 GrPrintf("Failed to create temporary copy of destination texture.\n"); | 456 GrPrintf("Failed to create temporary copy of destination texture.\n"); |
449 return false; | 457 return false; |
450 } | 458 } |
451 this->drawState()->disableState(GrDrawState::kClip_StateBit); | 459 this->drawState()->disableState(GrDrawState::kClip_StateBit); |
452 this->drawState()->setRenderTarget(ast.texture()->asRenderTarget()); | 460 this->drawState()->setRenderTarget(ast.texture()->asRenderTarget()); |
453 static const int kTextureStage = 0; | 461 static const int kTextureStage = 0; |
454 SkMatrix matrix; | 462 SkMatrix matrix; |
455 matrix.setIDiv(rt->width(), rt->height()); | 463 matrix.setIDiv(rt->width(), rt->height()); |
456 this->drawState()->createTextureEffect(kTextureStage, rt->asTexture(), matri
x); | 464 this->drawState()->createTextureEffect(kTextureStage, rt->asTexture(), matri
x); |
457 SkRect copyRect = SkRect::MakeWH(SkIntToScalar(desc.fWidth), | 465 |
458 SkIntToScalar(desc.fHeight)); | 466 SkRect srcRect = SkRect::MakeFromIRect(copyRect); |
459 this->drawRect(copyRect, NULL, ©Rect, NULL); | 467 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(copyRect.width()), |
| 468 SkIntToScalar(copyRect.height())); |
| 469 this->drawRect(dstRect, NULL, &srcRect, NULL); |
| 470 |
460 info->fDstCopy.setTexture(ast.texture()); | 471 info->fDstCopy.setTexture(ast.texture()); |
461 info->fDstCopy.setOffset(0, 0); | 472 info->fDstCopy.setOffset(copyRect.fLeft, copyRect.fTop); |
462 return true; | 473 return true; |
463 } | 474 } |
464 | 475 |
465 void GrDrawTarget::drawIndexed(GrPrimitiveType type, | 476 void GrDrawTarget::drawIndexed(GrPrimitiveType type, |
466 int startVertex, | 477 int startVertex, |
467 int startIndex, | 478 int startIndex, |
468 int vertexCount, | 479 int vertexCount, |
469 int indexCount, | 480 int indexCount, |
470 const SkRect* devBounds) { | 481 const SkRect* devBounds) { |
471 if (indexCount > 0 && this->checkDraw(type, startVertex, startIndex, vertexC
ount, indexCount)) { | 482 if (indexCount > 0 && this->checkDraw(type, startVertex, startIndex, vertexC
ount, indexCount)) { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 GrAssert(attribCount == 2); | 649 GrAssert(attribCount == 2); |
639 GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + | 650 GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + |
640 kAttribs[1].fOffset); | 651 kAttribs[1].fOffset); |
641 coords->setRectFan(localRect->fLeft, localRect->fTop, | 652 coords->setRectFan(localRect->fLeft, localRect->fTop, |
642 localRect->fRight, localRect->fBottom, | 653 localRect->fRight, localRect->fBottom, |
643 vsize); | 654 vsize); |
644 if (NULL != localMatrix) { | 655 if (NULL != localMatrix) { |
645 localMatrix->mapPointsWithStride(coords, vsize, 4); | 656 localMatrix->mapPointsWithStride(coords, vsize, 4); |
646 } | 657 } |
647 } | 658 } |
| 659 SkTLazy<SkRect> bounds; |
| 660 if (this->getDrawState().willEffectReadDst()) { |
| 661 bounds.init(); |
| 662 this->getDrawState().getViewMatrix().mapRect(bounds.get(), rect); |
| 663 } |
648 | 664 |
649 this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); | 665 this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4, bounds.getMaybeNull
()); |
650 } | 666 } |
651 | 667 |
652 void GrDrawTarget::clipWillBeSet(const GrClipData* clipData) { | 668 void GrDrawTarget::clipWillBeSet(const GrClipData* clipData) { |
653 } | 669 } |
654 | 670 |
655 //////////////////////////////////////////////////////////////////////////////// | 671 //////////////////////////////////////////////////////////////////////////////// |
656 | 672 |
657 GrDrawTarget::AutoStateRestore::AutoStateRestore() { | 673 GrDrawTarget::AutoStateRestore::AutoStateRestore() { |
658 fDrawTarget = NULL; | 674 fDrawTarget = NULL; |
659 } | 675 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 GrPrintf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]); | 815 GrPrintf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]); |
800 GrPrintf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]
); | 816 GrPrintf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]
); |
801 GrPrintf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); | 817 GrPrintf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); |
802 GrPrintf("Dual Source Blending Support: %s\n", gNY[fDualSourceBlendingSuppor
t]); | 818 GrPrintf("Dual Source Blending Support: %s\n", gNY[fDualSourceBlendingSuppor
t]); |
803 GrPrintf("Buffer Lock Support : %s\n", gNY[fBufferLockSupport]); | 819 GrPrintf("Buffer Lock Support : %s\n", gNY[fBufferLockSupport]); |
804 GrPrintf("Path Stenciling Support : %s\n", gNY[fPathStencilingSupport]); | 820 GrPrintf("Path Stenciling Support : %s\n", gNY[fPathStencilingSupport]); |
805 GrPrintf("Max Texture Size : %d\n", fMaxTextureSize); | 821 GrPrintf("Max Texture Size : %d\n", fMaxTextureSize); |
806 GrPrintf("Max Render Target Size : %d\n", fMaxRenderTargetSize); | 822 GrPrintf("Max Render Target Size : %d\n", fMaxRenderTargetSize); |
807 GrPrintf("Max Sample Count : %d\n", fMaxSampleCount); | 823 GrPrintf("Max Sample Count : %d\n", fMaxSampleCount); |
808 } | 824 } |
OLD | NEW |