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 |
11 #include "GrDrawTarget.h" | 11 #include "GrDrawTarget.h" |
12 #include "GrContext.h" | 12 #include "GrContext.h" |
13 #include "GrDrawTargetCaps.h" | 13 #include "GrDrawTargetCaps.h" |
| 14 #include "GrPath.h" |
14 #include "GrRenderTarget.h" | 15 #include "GrRenderTarget.h" |
15 #include "GrTexture.h" | 16 #include "GrTexture.h" |
16 #include "GrVertexBuffer.h" | 17 #include "GrVertexBuffer.h" |
17 | 18 |
18 #include "SkStrokeRec.h" | 19 #include "SkStrokeRec.h" |
19 | 20 |
20 SK_DEFINE_INST_COUNT(GrDrawTarget) | 21 SK_DEFINE_INST_COUNT(GrDrawTarget) |
21 | 22 |
22 //////////////////////////////////////////////////////////////////////////////// | 23 //////////////////////////////////////////////////////////////////////////////// |
23 | 24 |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 } | 407 } |
407 | 408 |
408 SkASSERT(drawState.validateVertexAttribs()); | 409 SkASSERT(drawState.validateVertexAttribs()); |
409 #endif | 410 #endif |
410 if (NULL == drawState.getRenderTarget()) { | 411 if (NULL == drawState.getRenderTarget()) { |
411 return false; | 412 return false; |
412 } | 413 } |
413 return true; | 414 return true; |
414 } | 415 } |
415 | 416 |
416 bool GrDrawTarget::setupDstReadIfNecessary(DrawInfo* info) { | 417 bool GrDrawTarget::setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const
SkRect* drawBounds) { |
417 if (this->caps()->dstReadInShaderSupport() || !this->getDrawState().willEffe
ctReadDstColor()) { | 418 if (this->caps()->dstReadInShaderSupport() || !this->getDrawState().willEffe
ctReadDstColor()) { |
418 return true; | 419 return true; |
419 } | 420 } |
420 GrRenderTarget* rt = this->drawState()->getRenderTarget(); | 421 GrRenderTarget* rt = this->drawState()->getRenderTarget(); |
| 422 SkIRect copyRect; |
| 423 const GrClipData* clip = this->getClip(); |
| 424 clip->getConservativeBounds(rt, ©Rect); |
421 | 425 |
422 const GrClipData* clip = this->getClip(); | 426 if (NULL != drawBounds) { |
423 SkIRect copyRect; | 427 SkIRect drawIBounds; |
424 clip->getConservativeBounds(this->getDrawState().getRenderTarget(), ©Rec
t); | 428 drawBounds->roundOut(&drawIBounds); |
425 SkIRect drawIBounds; | |
426 if (info->getDevIBounds(&drawIBounds)) { | |
427 if (!copyRect.intersect(drawIBounds)) { | 429 if (!copyRect.intersect(drawIBounds)) { |
428 #ifdef SK_DEBUG | 430 #ifdef SK_DEBUG |
429 GrPrintf("Missed an early reject. Bailing on draw from setupDstReadI
fNecessary.\n"); | 431 GrPrintf("Missed an early reject. Bailing on draw from setupDstReadI
fNecessary.\n"); |
430 #endif | 432 #endif |
431 return false; | 433 return false; |
432 } | 434 } |
433 } else { | 435 } else { |
434 #ifdef SK_DEBUG | 436 #ifdef SK_DEBUG |
435 //GrPrintf("No dev bounds when dst copy is made.\n"); | 437 //GrPrintf("No dev bounds when dst copy is made.\n"); |
436 #endif | 438 #endif |
437 } | 439 } |
438 | 440 |
439 // MSAA consideration: When there is support for reading MSAA samples in the
shader we could | 441 // MSAA consideration: When there is support for reading MSAA samples in the
shader we could |
440 // have per-sample dst values by making the copy multisampled. | 442 // have per-sample dst values by making the copy multisampled. |
441 GrTextureDesc desc; | 443 GrTextureDesc desc; |
442 this->initCopySurfaceDstDesc(rt, &desc); | 444 this->initCopySurfaceDstDesc(rt, &desc); |
443 desc.fWidth = copyRect.width(); | 445 desc.fWidth = copyRect.width(); |
444 desc.fHeight = copyRect.height(); | 446 desc.fHeight = copyRect.height(); |
445 | 447 |
446 GrAutoScratchTexture ast(fContext, desc, GrContext::kApprox_ScratchTexMatch)
; | 448 GrAutoScratchTexture ast(fContext, desc, GrContext::kApprox_ScratchTexMatch)
; |
447 | 449 |
448 if (NULL == ast.texture()) { | 450 if (NULL == ast.texture()) { |
449 GrPrintf("Failed to create temporary copy of destination texture.\n"); | 451 GrPrintf("Failed to create temporary copy of destination texture.\n"); |
450 return false; | 452 return false; |
451 } | 453 } |
452 SkIPoint dstPoint = {0, 0}; | 454 SkIPoint dstPoint = {0, 0}; |
453 if (this->copySurface(ast.texture(), rt, copyRect, dstPoint)) { | 455 if (this->copySurface(ast.texture(), rt, copyRect, dstPoint)) { |
454 info->fDstCopy.setTexture(ast.texture()); | 456 dstCopy->setTexture(ast.texture()); |
455 info->fDstCopy.setOffset(copyRect.fLeft, copyRect.fTop); | 457 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); |
456 return true; | 458 return true; |
457 } else { | 459 } else { |
458 return false; | 460 return false; |
459 } | 461 } |
460 } | 462 } |
461 | 463 |
462 void GrDrawTarget::drawIndexed(GrPrimitiveType type, | 464 void GrDrawTarget::drawIndexed(GrPrimitiveType type, |
463 int startVertex, | 465 int startVertex, |
464 int startIndex, | 466 int startIndex, |
465 int vertexCount, | 467 int vertexCount, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 if (!this->setupDstReadIfNecessary(&info)) { | 513 if (!this->setupDstReadIfNecessary(&info)) { |
512 return; | 514 return; |
513 } | 515 } |
514 this->onDraw(info); | 516 this->onDraw(info); |
515 } | 517 } |
516 } | 518 } |
517 | 519 |
518 void GrDrawTarget::stencilPath(const GrPath* path, const SkStrokeRec& stroke, Sk
Path::FillType fill) { | 520 void GrDrawTarget::stencilPath(const GrPath* path, const SkStrokeRec& stroke, Sk
Path::FillType fill) { |
519 // TODO: extract portions of checkDraw that are relevant to path stenciling. | 521 // TODO: extract portions of checkDraw that are relevant to path stenciling. |
520 SkASSERT(NULL != path); | 522 SkASSERT(NULL != path); |
521 SkASSERT(this->caps()->pathStencilingSupport()); | 523 SkASSERT(this->caps()->pathRenderingSupport()); |
522 SkASSERT(!stroke.isHairlineStyle()); | 524 SkASSERT(!stroke.isHairlineStyle()); |
523 SkASSERT(!SkPath::IsInverseFillType(fill)); | 525 SkASSERT(!SkPath::IsInverseFillType(fill)); |
524 this->onStencilPath(path, stroke, fill); | 526 this->onStencilPath(path, stroke, fill); |
525 } | 527 } |
526 | 528 |
| 529 void GrDrawTarget::fillPath(const GrPath* path, const SkStrokeRec& stroke, SkPat
h::FillType fill) { |
| 530 // TODO: extract portions of checkDraw that are relevant to path rendering. |
| 531 SkASSERT(NULL != path); |
| 532 SkASSERT(this->caps()->pathRenderingSupport()); |
| 533 SkASSERT(!stroke.isHairlineStyle()); |
| 534 const GrDrawState* drawState = &getDrawState(); |
| 535 |
| 536 SkRect devBounds; |
| 537 if (SkPath::IsInverseFillType(fill)) { |
| 538 devBounds = SkRect::MakeWH(SkIntToScalar(drawState->getRenderTarget()->w
idth()), |
| 539 SkIntToScalar(drawState->getRenderTarget()->h
eight())); |
| 540 } else { |
| 541 devBounds = path->getBounds(); |
| 542 } |
| 543 SkMatrix viewM = drawState->getViewMatrix(); |
| 544 viewM.mapRect(&devBounds); |
| 545 |
| 546 GrDeviceCoordTexture dstCopy; |
| 547 if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) { |
| 548 return; |
| 549 } |
| 550 |
| 551 this->onFillPath(path, stroke, fill, dstCopy.texture() ? &dstCopy : NULL); |
| 552 } |
| 553 |
527 //////////////////////////////////////////////////////////////////////////////// | 554 //////////////////////////////////////////////////////////////////////////////// |
528 | 555 |
529 bool GrDrawTarget::willUseHWAALines() const { | 556 bool GrDrawTarget::willUseHWAALines() const { |
530 // There is a conflict between using smooth lines and our use of premultipli
ed alpha. Smooth | 557 // There is a conflict between using smooth lines and our use of premultipli
ed alpha. Smooth |
531 // lines tweak the incoming alpha value but not in a premul-alpha way. So we
only use them when | 558 // lines tweak the incoming alpha value but not in a premul-alpha way. So we
only use them when |
532 // our alpha is 0xff and tweaking the color for partial coverage is OK | 559 // our alpha is 0xff and tweaking the color for partial coverage is OK |
533 if (!this->caps()->hwAALineSupport() || | 560 if (!this->caps()->hwAALineSupport() || |
534 !this->getDrawState().isHWAntialiasState()) { | 561 !this->getDrawState().isHWAntialiasState()) { |
535 return false; | 562 return false; |
536 } | 563 } |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 void GrDrawTargetCaps::reset() { | 969 void GrDrawTargetCaps::reset() { |
943 f8BitPaletteSupport = false; | 970 f8BitPaletteSupport = false; |
944 fNPOTTextureTileSupport = false; | 971 fNPOTTextureTileSupport = false; |
945 fTwoSidedStencilSupport = false; | 972 fTwoSidedStencilSupport = false; |
946 fStencilWrapOpsSupport = false; | 973 fStencilWrapOpsSupport = false; |
947 fHWAALineSupport = false; | 974 fHWAALineSupport = false; |
948 fShaderDerivativeSupport = false; | 975 fShaderDerivativeSupport = false; |
949 fGeometryShaderSupport = false; | 976 fGeometryShaderSupport = false; |
950 fDualSourceBlendingSupport = false; | 977 fDualSourceBlendingSupport = false; |
951 fBufferLockSupport = false; | 978 fBufferLockSupport = false; |
952 fPathStencilingSupport = false; | 979 fPathRenderingSupport = false; |
953 fDstReadInShaderSupport = false; | 980 fDstReadInShaderSupport = false; |
954 fReuseScratchTextures = true; | 981 fReuseScratchTextures = true; |
955 | 982 |
956 fMaxRenderTargetSize = 0; | 983 fMaxRenderTargetSize = 0; |
957 fMaxTextureSize = 0; | 984 fMaxTextureSize = 0; |
958 fMaxSampleCount = 0; | 985 fMaxSampleCount = 0; |
959 } | 986 } |
960 | 987 |
961 GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) { | 988 GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) { |
962 f8BitPaletteSupport = other.f8BitPaletteSupport; | 989 f8BitPaletteSupport = other.f8BitPaletteSupport; |
963 fNPOTTextureTileSupport = other.fNPOTTextureTileSupport; | 990 fNPOTTextureTileSupport = other.fNPOTTextureTileSupport; |
964 fTwoSidedStencilSupport = other.fTwoSidedStencilSupport; | 991 fTwoSidedStencilSupport = other.fTwoSidedStencilSupport; |
965 fStencilWrapOpsSupport = other.fStencilWrapOpsSupport; | 992 fStencilWrapOpsSupport = other.fStencilWrapOpsSupport; |
966 fHWAALineSupport = other.fHWAALineSupport; | 993 fHWAALineSupport = other.fHWAALineSupport; |
967 fShaderDerivativeSupport = other.fShaderDerivativeSupport; | 994 fShaderDerivativeSupport = other.fShaderDerivativeSupport; |
968 fGeometryShaderSupport = other.fGeometryShaderSupport; | 995 fGeometryShaderSupport = other.fGeometryShaderSupport; |
969 fDualSourceBlendingSupport = other.fDualSourceBlendingSupport; | 996 fDualSourceBlendingSupport = other.fDualSourceBlendingSupport; |
970 fBufferLockSupport = other.fBufferLockSupport; | 997 fBufferLockSupport = other.fBufferLockSupport; |
971 fPathStencilingSupport = other.fPathStencilingSupport; | 998 fPathRenderingSupport = other.fPathRenderingSupport; |
972 fDstReadInShaderSupport = other.fDstReadInShaderSupport; | 999 fDstReadInShaderSupport = other.fDstReadInShaderSupport; |
973 fReuseScratchTextures = other.fReuseScratchTextures; | 1000 fReuseScratchTextures = other.fReuseScratchTextures; |
974 | 1001 |
975 fMaxRenderTargetSize = other.fMaxRenderTargetSize; | 1002 fMaxRenderTargetSize = other.fMaxRenderTargetSize; |
976 fMaxTextureSize = other.fMaxTextureSize; | 1003 fMaxTextureSize = other.fMaxTextureSize; |
977 fMaxSampleCount = other.fMaxSampleCount; | 1004 fMaxSampleCount = other.fMaxSampleCount; |
978 | 1005 |
979 return *this; | 1006 return *this; |
980 } | 1007 } |
981 | 1008 |
982 void GrDrawTargetCaps::print() const { | 1009 void GrDrawTargetCaps::print() const { |
983 static const char* gNY[] = {"NO", "YES"}; | 1010 static const char* gNY[] = {"NO", "YES"}; |
984 GrPrintf("8 Bit Palette Support : %s\n", gNY[f8BitPaletteSupport]); | 1011 GrPrintf("8 Bit Palette Support : %s\n", gNY[f8BitPaletteSupport]); |
985 GrPrintf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport])
; | 1012 GrPrintf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport])
; |
986 GrPrintf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport])
; | 1013 GrPrintf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport])
; |
987 GrPrintf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]); | 1014 GrPrintf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]); |
988 GrPrintf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]); | 1015 GrPrintf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]); |
989 GrPrintf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]
); | 1016 GrPrintf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]
); |
990 GrPrintf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); | 1017 GrPrintf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); |
991 GrPrintf("Dual Source Blending Support: %s\n", gNY[fDualSourceBlendingSuppor
t]); | 1018 GrPrintf("Dual Source Blending Support: %s\n", gNY[fDualSourceBlendingSuppor
t]); |
992 GrPrintf("Buffer Lock Support : %s\n", gNY[fBufferLockSupport]); | 1019 GrPrintf("Buffer Lock Support : %s\n", gNY[fBufferLockSupport]); |
993 GrPrintf("Path Stenciling Support : %s\n", gNY[fPathStencilingSupport]); | 1020 GrPrintf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]); |
994 GrPrintf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport])
; | 1021 GrPrintf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport])
; |
995 GrPrintf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]); | 1022 GrPrintf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]); |
996 GrPrintf("Max Texture Size : %d\n", fMaxTextureSize); | 1023 GrPrintf("Max Texture Size : %d\n", fMaxTextureSize); |
997 GrPrintf("Max Render Target Size : %d\n", fMaxRenderTargetSize); | 1024 GrPrintf("Max Render Target Size : %d\n", fMaxRenderTargetSize); |
998 GrPrintf("Max Sample Count : %d\n", fMaxSampleCount); | 1025 GrPrintf("Max Sample Count : %d\n", fMaxSampleCount); |
999 } | 1026 } |
OLD | NEW |