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

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

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

Powered by Google App Engine
This is Rietveld 408576698