| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrInOrderDrawBuffer.h" | 8 #include "GrInOrderDrawBuffer.h" |
| 9 | 9 |
| 10 #include "GrBufferAllocPool.h" | 10 #include "GrBufferAllocPool.h" |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 343 |
| 344 if (drawState.isClipState() && | 344 if (drawState.isClipState() && |
| 345 NULL != info.getDevBounds() && | 345 NULL != info.getDevBounds() && |
| 346 this->quickInsideClip(*info.getDevBounds())) { | 346 this->quickInsideClip(*info.getDevBounds())) { |
| 347 acr.set(this->drawState()); | 347 acr.set(this->drawState()); |
| 348 } | 348 } |
| 349 | 349 |
| 350 if (this->needsNewClip()) { | 350 if (this->needsNewClip()) { |
| 351 this->recordClip(); | 351 this->recordClip(); |
| 352 } | 352 } |
| 353 if (this->needsNewState()) { | 353 this->recordStateIfNecessary(); |
| 354 this->recordState(); | |
| 355 } | |
| 356 | 354 |
| 357 DrawRecord* draw; | 355 DrawRecord* draw; |
| 358 if (info.isInstanced()) { | 356 if (info.isInstanced()) { |
| 359 int instancesConcated = this->concatInstancedDraw(info); | 357 int instancesConcated = this->concatInstancedDraw(info); |
| 360 if (info.instanceCount() > instancesConcated) { | 358 if (info.instanceCount() > instancesConcated) { |
| 361 draw = this->recordDraw(info); | 359 draw = this->recordDraw(info); |
| 362 draw->adjustInstanceCount(-instancesConcated); | 360 draw->adjustInstanceCount(-instancesConcated); |
| 363 } else { | 361 } else { |
| 364 return; | 362 return; |
| 365 } | 363 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 if (fIndices) { | 415 if (fIndices) { |
| 418 SkDELETE_ARRAY(fIndices); | 416 SkDELETE_ARRAY(fIndices); |
| 419 } | 417 } |
| 420 } | 418 } |
| 421 | 419 |
| 422 void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, SkPath::FillType fil
l) { | 420 void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, SkPath::FillType fil
l) { |
| 423 if (this->needsNewClip()) { | 421 if (this->needsNewClip()) { |
| 424 this->recordClip(); | 422 this->recordClip(); |
| 425 } | 423 } |
| 426 // Only compare the subset of GrDrawState relevant to path stenciling? | 424 // Only compare the subset of GrDrawState relevant to path stenciling? |
| 427 if (this->needsNewState()) { | 425 this->recordStateIfNecessary(); |
| 428 this->recordState(); | |
| 429 } | |
| 430 StencilPath* sp = this->recordStencilPath(); | 426 StencilPath* sp = this->recordStencilPath(); |
| 431 sp->fPath.reset(path); | 427 sp->fPath.reset(path); |
| 432 path->ref(); | 428 path->ref(); |
| 433 sp->fFill = fill; | 429 sp->fFill = fill; |
| 434 } | 430 } |
| 435 | 431 |
| 436 void GrInOrderDrawBuffer::onDrawPath(const GrPath* path, | 432 void GrInOrderDrawBuffer::onDrawPath(const GrPath* path, |
| 437 SkPath::FillType fill, const GrDeviceCoordT
exture* dstCopy) { | 433 SkPath::FillType fill, const GrDeviceCoordT
exture* dstCopy) { |
| 438 if (this->needsNewClip()) { | 434 if (this->needsNewClip()) { |
| 439 this->recordClip(); | 435 this->recordClip(); |
| 440 } | 436 } |
| 441 // TODO: Only compare the subset of GrDrawState relevant to path covering? | 437 // TODO: Only compare the subset of GrDrawState relevant to path covering? |
| 442 if (this->needsNewState()) { | 438 this->recordStateIfNecessary(); |
| 443 this->recordState(); | |
| 444 } | |
| 445 DrawPath* cp = this->recordDrawPath(); | 439 DrawPath* cp = this->recordDrawPath(); |
| 446 cp->fPath.reset(path); | 440 cp->fPath.reset(path); |
| 447 path->ref(); | 441 path->ref(); |
| 448 cp->fFill = fill; | 442 cp->fFill = fill; |
| 449 if (NULL != dstCopy) { | 443 if (NULL != dstCopy) { |
| 450 cp->fDstCopy = *dstCopy; | 444 cp->fDstCopy = *dstCopy; |
| 451 } | 445 } |
| 452 } | 446 } |
| 453 | 447 |
| 454 void GrInOrderDrawBuffer::onDrawPaths(const GrPathRange* pathRange, | 448 void GrInOrderDrawBuffer::onDrawPaths(const GrPathRange* pathRange, |
| 455 const uint32_t indices[], int count, | 449 const uint32_t indices[], int count, |
| 456 const float transforms[], PathTransformTyp
e transformsType, | 450 const float transforms[], PathTransformTyp
e transformsType, |
| 457 SkPath::FillType fill, const GrDeviceCoord
Texture* dstCopy) { | 451 SkPath::FillType fill, const GrDeviceCoord
Texture* dstCopy) { |
| 458 SkASSERT(NULL != pathRange); | 452 SkASSERT(NULL != pathRange); |
| 459 SkASSERT(NULL != indices); | 453 SkASSERT(NULL != indices); |
| 460 SkASSERT(NULL != transforms); | 454 SkASSERT(NULL != transforms); |
| 461 | 455 |
| 462 if (this->needsNewClip()) { | 456 if (this->needsNewClip()) { |
| 463 this->recordClip(); | 457 this->recordClip(); |
| 464 } | 458 } |
| 465 if (this->needsNewState()) { | 459 this->recordStateIfNecessary(); |
| 466 this->recordState(); | |
| 467 } | |
| 468 DrawPaths* dp = this->recordDrawPaths(); | 460 DrawPaths* dp = this->recordDrawPaths(); |
| 469 dp->fPathRange.reset(SkRef(pathRange)); | 461 dp->fPathRange.reset(SkRef(pathRange)); |
| 470 dp->fIndices = SkNEW_ARRAY(uint32_t, count); // TODO: Accomplish this withou
t a malloc | 462 dp->fIndices = SkNEW_ARRAY(uint32_t, count); // TODO: Accomplish this withou
t a malloc |
| 471 memcpy(dp->fIndices, indices, sizeof(uint32_t) * count); | 463 memcpy(dp->fIndices, indices, sizeof(uint32_t) * count); |
| 472 dp->fCount = count; | 464 dp->fCount = count; |
| 473 | 465 |
| 474 const int transformsLength = PathTransformSize(transformsType) * count; | 466 const int transformsLength = PathTransformSize(transformsType) * count; |
| 475 dp->fTransforms = SkNEW_ARRAY(float, transformsLength); | 467 dp->fTransforms = SkNEW_ARRAY(float, transformsLength); |
| 476 memcpy(dp->fTransforms, transforms, sizeof(float) * transformsLength); | 468 memcpy(dp->fTransforms, transforms, sizeof(float) * transformsLength); |
| 477 dp->fTransformsType = transformsType; | 469 dp->fTransformsType = transformsType; |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 kArray_GeometrySrcType == restoredState.fVertexSrc) { | 904 kArray_GeometrySrcType == restoredState.fVertexSrc) { |
| 913 poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredSta
te.fVertexCount; | 905 poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredSta
te.fVertexCount; |
| 914 } | 906 } |
| 915 if (kReserved_GeometrySrcType == restoredState.fIndexSrc || | 907 if (kReserved_GeometrySrcType == restoredState.fIndexSrc || |
| 916 kArray_GeometrySrcType == restoredState.fIndexSrc) { | 908 kArray_GeometrySrcType == restoredState.fIndexSrc) { |
| 917 poolState.fUsedPoolIndexBytes = sizeof(uint16_t) * | 909 poolState.fUsedPoolIndexBytes = sizeof(uint16_t) * |
| 918 restoredState.fIndexCount; | 910 restoredState.fIndexCount; |
| 919 } | 911 } |
| 920 } | 912 } |
| 921 | 913 |
| 922 bool GrInOrderDrawBuffer::needsNewState() const { | 914 void GrInOrderDrawBuffer::recordStateIfNecessary() { |
| 923 return fStates.empty() || fStates.back() != this->getDrawState(); | 915 if (fStates.empty()) { |
| 916 fStates.push_back() = this->getDrawState(); |
| 917 this->addToCmdBuffer(kSetState_Cmd); |
| 918 return; |
| 919 } |
| 920 const GrDrawState& curr = this->getDrawState(); |
| 921 GrDrawState& prev = fStates.back(); |
| 922 switch (GrDrawState::CombineIfPossible(prev, curr)) { |
| 923 case GrDrawState::kIncompatible_CombinedState: |
| 924 fStates.push_back() = this->getDrawState(); |
| 925 this->addToCmdBuffer(kSetState_Cmd); |
| 926 break; |
| 927 case GrDrawState::kA_CombinedState: |
| 928 case GrDrawState::kAOrB_CombinedState: // Treat the same as kA. |
| 929 break; |
| 930 case GrDrawState::kB_CombinedState: |
| 931 prev = curr; |
| 932 break; |
| 933 } |
| 924 } | 934 } |
| 925 | 935 |
| 926 bool GrInOrderDrawBuffer::needsNewClip() const { | 936 bool GrInOrderDrawBuffer::needsNewClip() const { |
| 927 if (this->getDrawState().isClipState()) { | 937 if (this->getDrawState().isClipState()) { |
| 928 if (fClipSet && | 938 if (fClipSet && |
| 929 (fClips.empty() || | 939 (fClips.empty() || |
| 930 fClips.back().fStack != *this->getClip()->fClipStack || | 940 fClips.back().fStack != *this->getClip()->fClipStack || |
| 931 fClips.back().fOrigin != this->getClip()->fOrigin)) { | 941 fClips.back().fOrigin != this->getClip()->fOrigin)) { |
| 932 return true; | 942 return true; |
| 933 } | 943 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 946 } | 956 } |
| 947 } | 957 } |
| 948 | 958 |
| 949 void GrInOrderDrawBuffer::recordClip() { | 959 void GrInOrderDrawBuffer::recordClip() { |
| 950 fClips.push_back().fStack = *this->getClip()->fClipStack; | 960 fClips.push_back().fStack = *this->getClip()->fClipStack; |
| 951 fClips.back().fOrigin = this->getClip()->fOrigin; | 961 fClips.back().fOrigin = this->getClip()->fOrigin; |
| 952 fClipSet = false; | 962 fClipSet = false; |
| 953 this->addToCmdBuffer(kSetClip_Cmd); | 963 this->addToCmdBuffer(kSetClip_Cmd); |
| 954 } | 964 } |
| 955 | 965 |
| 956 void GrInOrderDrawBuffer::recordState() { | |
| 957 fStates.push_back() = this->getDrawState(); | |
| 958 this->addToCmdBuffer(kSetState_Cmd); | |
| 959 } | |
| 960 | |
| 961 GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo&
info) { | 966 GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo&
info) { |
| 962 this->addToCmdBuffer(kDraw_Cmd); | 967 this->addToCmdBuffer(kDraw_Cmd); |
| 963 return &fDraws.push_back(info); | 968 return &fDraws.push_back(info); |
| 964 } | 969 } |
| 965 | 970 |
| 966 GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { | 971 GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { |
| 967 this->addToCmdBuffer(kStencilPath_Cmd); | 972 this->addToCmdBuffer(kStencilPath_Cmd); |
| 968 return &fStencilPaths.push_back(); | 973 return &fStencilPaths.push_back(); |
| 969 } | 974 } |
| 970 | 975 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 986 GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() { | 991 GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() { |
| 987 this->addToCmdBuffer(kCopySurface_Cmd); | 992 this->addToCmdBuffer(kCopySurface_Cmd); |
| 988 return &fCopySurfaces.push_back(); | 993 return &fCopySurfaces.push_back(); |
| 989 } | 994 } |
| 990 | 995 |
| 991 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { | 996 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { |
| 992 INHERITED::clipWillBeSet(newClipData); | 997 INHERITED::clipWillBeSet(newClipData); |
| 993 fClipSet = true; | 998 fClipSet = true; |
| 994 fClipProxyState = kUnknown_ClipProxyState; | 999 fClipProxyState = kUnknown_ClipProxyState; |
| 995 } | 1000 } |
| OLD | NEW |