| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 | 770 |
| 771 GrRect devRect; | 771 GrRect devRect; |
| 772 SkMatrix combinedMatrix; | 772 SkMatrix combinedMatrix; |
| 773 bool useVertexCoverage; | 773 bool useVertexCoverage; |
| 774 bool needAA = paint.isAntiAlias() && | 774 bool needAA = paint.isAntiAlias() && |
| 775 !target->getDrawState().getRenderTarget()->isMultisampled(); | 775 !target->getDrawState().getRenderTarget()->isMultisampled(); |
| 776 bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix, | 776 bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix, |
| 777 &combinedMatrix, &devRect, | 777 &combinedMatrix, &devRect, |
| 778 &useVertexCoverage); | 778 &useVertexCoverage); |
| 779 if (doAA) { | 779 if (doAA) { |
| 780 GrDrawState::AutoDeviceCoordDraw adcd(target->drawState()); | 780 GrDrawState::AutoViewMatrixRestore avmr; |
| 781 if (!adcd.succeeded()) { | 781 if (!avmr.setIdentity(target->drawState())) { |
| 782 return; | 782 return; |
| 783 } | 783 } |
| 784 if (width >= 0) { | 784 if (width >= 0) { |
| 785 fAARectRenderer->strokeAARect(this->getGpu(), target, | 785 fAARectRenderer->strokeAARect(this->getGpu(), target, |
| 786 rect, combinedMatrix, devRect, | 786 rect, combinedMatrix, devRect, |
| 787 width, useVertexCoverage); | 787 width, useVertexCoverage); |
| 788 } else { | 788 } else { |
| 789 // filled AA rect | 789 // filled AA rect |
| 790 fAARectRenderer->fillAARect(this->getGpu(), target, | 790 fAARectRenderer->fillAARect(this->getGpu(), target, |
| 791 rect, combinedMatrix, devRect, | 791 rect, combinedMatrix, devRect, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 target->drawSimpleRect(rect, matrix); | 839 target->drawSimpleRect(rect, matrix); |
| 840 } | 840 } |
| 841 } | 841 } |
| 842 | 842 |
| 843 void GrContext::drawRectToRect(const GrPaint& paint, | 843 void GrContext::drawRectToRect(const GrPaint& paint, |
| 844 const GrRect& dstRect, | 844 const GrRect& dstRect, |
| 845 const GrRect& localRect, | 845 const GrRect& localRect, |
| 846 const SkMatrix* dstMatrix, | 846 const SkMatrix* dstMatrix, |
| 847 const SkMatrix* localMatrix) { | 847 const SkMatrix* localMatrix) { |
| 848 SK_TRACE_EVENT0("GrContext::drawRectToRect"); | 848 SK_TRACE_EVENT0("GrContext::drawRectToRect"); |
| 849 | |
| 850 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); | 849 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); |
| 851 GrDrawState::AutoStageDisable atr(fDrawState); | 850 GrDrawState::AutoStageDisable atr(fDrawState); |
| 852 | 851 |
| 853 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); | 852 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); |
| 854 } | 853 } |
| 855 | 854 |
| 856 namespace { | 855 namespace { |
| 857 | 856 |
| 858 extern const GrVertexAttrib gPosUVColorAttribs[] = { | 857 extern const GrVertexAttrib gPosUVColorAttribs[] = { |
| 859 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, | 858 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 } | 1041 } |
| 1043 | 1042 |
| 1044 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. | 1043 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. |
| 1045 // Scratch textures can be recycled after they are returned to the texture | 1044 // Scratch textures can be recycled after they are returned to the texture |
| 1046 // cache. This presents a potential hazard for buffered drawing. However, | 1045 // cache. This presents a potential hazard for buffered drawing. However, |
| 1047 // the writePixels that uploads to the scratch will perform a flush so we're | 1046 // the writePixels that uploads to the scratch will perform a flush so we're |
| 1048 // OK. | 1047 // OK. |
| 1049 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); | 1048 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); |
| 1050 GrDrawState::AutoStageDisable atr(fDrawState); | 1049 GrDrawState::AutoStageDisable atr(fDrawState); |
| 1051 | 1050 |
| 1052 bool useAA = paint.isAntiAlias() && !this->getRenderTarget()->isMultisampled
(); | 1051 bool useAA = paint.isAntiAlias() && !target->getDrawState().getRenderTarget(
)->isMultisampled(); |
| 1053 if (useAA && stroke.getWidth() < 0 && !path.isConvex()) { | 1052 if (useAA && stroke.getWidth() < 0 && !path.isConvex()) { |
| 1054 // Concave AA paths are expensive - try to avoid them for special cases | 1053 // Concave AA paths are expensive - try to avoid them for special cases |
| 1055 bool useVertexCoverage; | 1054 bool useVertexCoverage; |
| 1056 SkRect rects[2]; | 1055 SkRect rects[2]; |
| 1057 | 1056 |
| 1058 if (is_nested_rects(target, path, stroke, rects, &useVertexCoverage)) { | 1057 if (is_nested_rects(target, path, stroke, rects, &useVertexCoverage)) { |
| 1059 GrDrawState::AutoDeviceCoordDraw adcd(target->drawState()); | 1058 SkMatrix origViewMatrix = target->getDrawState().getViewMatrix(); |
| 1060 if (!adcd.succeeded()) { | 1059 GrDrawState::AutoViewMatrixRestore avmr; |
| 1060 if (!avmr.setIdentity(target->drawState())) { |
| 1061 return; | 1061 return; |
| 1062 } | 1062 } |
| 1063 | 1063 |
| 1064 fAARectRenderer->fillAANestedRects(this->getGpu(), target, | 1064 fAARectRenderer->fillAANestedRects(this->getGpu(), target, |
| 1065 rects, | 1065 rects, |
| 1066 adcd.getOriginalMatrix(), | 1066 origViewMatrix, |
| 1067 useVertexCoverage); | 1067 useVertexCoverage); |
| 1068 return; | 1068 return; |
| 1069 } | 1069 } |
| 1070 } | 1070 } |
| 1071 | 1071 |
| 1072 SkRect ovalRect; | 1072 SkRect ovalRect; |
| 1073 bool isOval = path.isOval(&ovalRect); | 1073 bool isOval = path.isOval(&ovalRect); |
| 1074 | 1074 |
| 1075 if (!isOval || path.isInverseFillType() | 1075 if (!isOval || path.isInverseFillType() |
| 1076 || !fOvalRenderer->drawOval(target, this, useAA, ovalRect, stroke)) { | 1076 || !fOvalRenderer->drawOval(target, this, useAA, ovalRect, stroke)) { |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1527 if (!this->writeTexturePixels(texture, | 1527 if (!this->writeTexturePixels(texture, |
| 1528 0, 0, width, height, | 1528 0, 0, width, height, |
| 1529 writeConfig, buffer, rowBytes, | 1529 writeConfig, buffer, rowBytes, |
| 1530 flags & ~kUnpremul_PixelOpsFlag)) { | 1530 flags & ~kUnpremul_PixelOpsFlag)) { |
| 1531 return false; | 1531 return false; |
| 1532 } | 1532 } |
| 1533 | 1533 |
| 1534 // writeRenderTargetPixels can be called in the midst of drawing another | 1534 // writeRenderTargetPixels can be called in the midst of drawing another |
| 1535 // object (e.g., when uploading a SW path rendering to the gpu while | 1535 // object (e.g., when uploading a SW path rendering to the gpu while |
| 1536 // drawing a rect) so preserve the current geometry. | 1536 // drawing a rect) so preserve the current geometry. |
| 1537 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRI
nit); | 1537 SkMatrix matrix; |
| 1538 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 1539 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRI
nit, &matrix); |
| 1538 GrDrawState* drawState = fGpu->drawState(); | 1540 GrDrawState* drawState = fGpu->drawState(); |
| 1539 GrAssert(effect); | 1541 GrAssert(effect); |
| 1540 drawState->setEffect(0, effect); | 1542 drawState->setEffect(0, effect); |
| 1541 | 1543 |
| 1542 SkMatrix matrix; | |
| 1543 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | |
| 1544 drawState->setViewMatrix(matrix); | |
| 1545 drawState->setRenderTarget(target); | 1544 drawState->setRenderTarget(target); |
| 1546 | 1545 |
| 1547 fGpu->drawSimpleRect(GrRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heig
ht)), NULL); | 1546 fGpu->drawSimpleRect(GrRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heig
ht)), NULL); |
| 1548 return true; | 1547 return true; |
| 1549 } | 1548 } |
| 1550 //////////////////////////////////////////////////////////////////////////////// | 1549 //////////////////////////////////////////////////////////////////////////////// |
| 1551 | 1550 |
| 1552 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, BufferedDraw buffer
ed) { | 1551 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, BufferedDraw buffer
ed) { |
| 1553 if (kNo_BufferedDraw == buffered && kYes_BufferedDraw == fLastDrawWasBuffere
d) { | 1552 if (kNo_BufferedDraw == buffered && kYes_BufferedDraw == fLastDrawWasBuffere
d) { |
| 1554 this->flushDrawBuffer(); | 1553 this->flushDrawBuffer(); |
| 1555 fLastDrawWasBuffered = kNo_BufferedDraw; | 1554 fLastDrawWasBuffered = kNo_BufferedDraw; |
| 1556 } | 1555 } |
| 1557 ASSERT_OWNED_RESOURCE(fRenderTarget.get()); | 1556 ASSERT_OWNED_RESOURCE(fRenderTarget.get()); |
| 1558 if (NULL != paint) { | 1557 if (NULL != paint) { |
| 1559 GrAssert(fDrawState->stagesDisabled()); | 1558 GrAssert(fDrawState->stagesDisabled()); |
| 1560 fDrawState->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); | 1559 fDrawState->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); |
| 1561 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK | 1560 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK |
| 1562 if ((paint->hasMask() || 0xff != paint->fCoverage) && | 1561 if ((paint->hasMask() || 0xff != paint->fCoverage) && |
| 1563 !fGpu->canApplyCoverage()) { | 1562 !fGpu->canApplyCoverage()) { |
| 1564 GrPrintf("Partial pixel coverage will be incorrectly blended.\n"); | 1563 GrPrintf("Partial pixel coverage will be incorrectly blended.\n"); |
| 1565 } | 1564 } |
| 1566 #endif | 1565 #endif |
| 1567 } else { | 1566 } else { |
| 1568 fDrawState->reset(); | 1567 fDrawState->reset(fViewMatrix); |
| 1569 *fDrawState->viewMatrix() = fViewMatrix; | |
| 1570 fDrawState->setRenderTarget(fRenderTarget.get()); | 1568 fDrawState->setRenderTarget(fRenderTarget.get()); |
| 1571 } | 1569 } |
| 1572 GrDrawTarget* target; | 1570 GrDrawTarget* target; |
| 1573 if (kYes_BufferedDraw == buffered) { | 1571 if (kYes_BufferedDraw == buffered) { |
| 1574 fLastDrawWasBuffered = kYes_BufferedDraw; | 1572 fLastDrawWasBuffered = kYes_BufferedDraw; |
| 1575 target = fDrawBuffer; | 1573 target = fDrawBuffer; |
| 1576 } else { | 1574 } else { |
| 1577 GrAssert(kNo_BufferedDraw == buffered); | 1575 GrAssert(kNo_BufferedDraw == buffered); |
| 1578 fLastDrawWasBuffered = kNo_BufferedDraw; | 1576 fLastDrawWasBuffered = kNo_BufferedDraw; |
| 1579 target = fGpu; | 1577 target = fGpu; |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1837 return srcTexture; | 1835 return srcTexture; |
| 1838 } | 1836 } |
| 1839 } | 1837 } |
| 1840 | 1838 |
| 1841 /////////////////////////////////////////////////////////////////////////////// | 1839 /////////////////////////////////////////////////////////////////////////////// |
| 1842 #if GR_CACHE_STATS | 1840 #if GR_CACHE_STATS |
| 1843 void GrContext::printCacheStats() const { | 1841 void GrContext::printCacheStats() const { |
| 1844 fTextureCache->printStats(); | 1842 fTextureCache->printStats(); |
| 1845 } | 1843 } |
| 1846 #endif | 1844 #endif |
| OLD | NEW |