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 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1546 return srcPI.convertPixelsTo(&dstPI, width, height); | 1546 return srcPI.convertPixelsTo(&dstPI, width, height); |
1547 } | 1547 } |
1548 return true; | 1548 return true; |
1549 } | 1549 } |
1550 | 1550 |
1551 void GrContext::resolveRenderTarget(GrRenderTarget* target) { | 1551 void GrContext::resolveRenderTarget(GrRenderTarget* target) { |
1552 SkASSERT(target); | 1552 SkASSERT(target); |
1553 ASSERT_OWNED_RESOURCE(target); | 1553 ASSERT_OWNED_RESOURCE(target); |
1554 // In the future we may track whether there are any pending draws to this | 1554 // In the future we may track whether there are any pending draws to this |
1555 // target. We don't today so we always perform a flush. We don't promise | 1555 // target. We don't today so we always perform a flush. We don't promise |
1556 // this to our clients, though. | 1556 // this to our clients, though. |
robertphillips
2014/09/23 13:21:53
Is this flush on your radar?
bsalomon
2014/09/23 15:08:57
Yes, I think this whole function can be deleted.
| |
1557 this->flush(); | 1557 this->flush(); |
1558 if (fGpu) { | 1558 if (fGpu) { |
1559 fGpu->resolveRenderTarget(target); | 1559 fGpu->resolveRenderTarget(target); |
1560 } | 1560 } |
1561 } | 1561 } |
1562 | 1562 |
1563 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { | 1563 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { |
1564 SkASSERT(renderTarget); | 1564 SkASSERT(renderTarget); |
1565 ASSERT_OWNED_RESOURCE(renderTarget); | 1565 ASSERT_OWNED_RESOURCE(renderTarget); |
1566 AutoRestoreEffects are; | 1566 AutoRestoreEffects are; |
1567 AutoCheckFlush acf(this); | 1567 AutoCheckFlush acf(this); |
1568 GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW, &are, &acf); | 1568 GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW, &are, &acf); |
1569 if (NULL == target) { | 1569 if (NULL == target) { |
1570 return; | 1570 return; |
1571 } | 1571 } |
1572 target->discard(renderTarget); | 1572 target->discard(renderTarget); |
1573 } | 1573 } |
1574 | 1574 |
1575 void GrContext::copyTexture(GrTexture* src, GrRenderTarget* dst, const SkIPoint* topLeft) { | 1575 void GrContext::copyTexture(GrTexture* src, GrRenderTarget* dst, const SkIPoint* topLeft) { |
1576 if (NULL == src || NULL == dst) { | 1576 if (NULL == src || NULL == dst) { |
1577 return; | 1577 return; |
1578 } | 1578 } |
robertphillips
2014/09/23 13:21:53
ASSERT_OWNED_RESOURCE(dst); ?
bsalomon
2014/09/23 15:08:57
Done.
| |
1579 ASSERT_OWNED_RESOURCE(src); | 1579 ASSERT_OWNED_RESOURCE(src); |
1580 | 1580 |
1581 | 1581 |
1582 if (src->hasPendingWrite() || dst->hasPendingIO()) { | 1582 if (src->hasPendingWrite() || dst->hasPendingIO()) { |
1583 this->flush(); | 1583 this->flush(); |
1584 } | 1584 } |
1585 | 1585 |
robertphillips
2014/09/23 13:21:53
So this prepareToDraw call does a bit of work on t
bsalomon
2014/09/23 15:08:57
I think there is a larger change coming related to
| |
1586 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit); | 1586 GrDrawTarget* target = this->prepareToDraw(NULL, kYes_BufferedDraw, NULL, NU LL); |
1587 GrDrawState* drawState = fGpu->drawState(); | 1587 GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kReset_ASRInit); |
1588 GrDrawState* drawState = target->drawState(); | |
1588 drawState->setRenderTarget(dst); | 1589 drawState->setRenderTarget(dst); |
1589 SkMatrix sampleM; | 1590 SkMatrix sampleM; |
1590 sampleM.setIDiv(src->width(), src->height()); | 1591 sampleM.setIDiv(src->width(), src->height()); |
1591 SkIRect srcRect = SkIRect::MakeWH(dst->width(), dst->height()); | 1592 SkIRect srcRect = SkIRect::MakeWH(dst->width(), dst->height()); |
1592 if (topLeft) { | 1593 if (topLeft) { |
1593 srcRect.offset(*topLeft); | 1594 srcRect.offset(*topLeft); |
1594 } | 1595 } |
1595 SkIRect srcBounds = SkIRect::MakeWH(src->width(), src->height()); | 1596 SkIRect srcBounds = SkIRect::MakeWH(src->width(), src->height()); |
1596 if (!srcRect.intersect(srcBounds)) { | 1597 if (!srcRect.intersect(srcBounds)) { |
1597 return; | 1598 return; |
1598 } | 1599 } |
1599 sampleM.preTranslate(SkIntToScalar(srcRect.fLeft), SkIntToScalar(srcRect.fTo p)); | 1600 sampleM.preTranslate(SkIntToScalar(srcRect.fLeft), SkIntToScalar(srcRect.fTo p)); |
1600 drawState->addColorTextureEffect(src, sampleM); | 1601 drawState->addColorTextureEffect(src, sampleM); |
1601 SkRect dstR = SkRect::MakeWH(SkIntToScalar(srcRect.width()), SkIntToScalar(s rcRect.height())); | 1602 SkRect dstR = SkRect::MakeWH(SkIntToScalar(srcRect.width()), SkIntToScalar(s rcRect.height())); |
1602 fGpu->drawSimpleRect(dstR); | 1603 target->drawSimpleRect(dstR); |
1603 } | 1604 } |
1604 | 1605 |
1605 bool GrContext::writeRenderTargetPixels(GrRenderTarget* target, | 1606 bool GrContext::writeRenderTargetPixels(GrRenderTarget* target, |
1606 int left, int top, int width, int height , | 1607 int left, int top, int width, int height , |
1607 GrPixelConfig srcConfig, | 1608 GrPixelConfig srcConfig, |
1608 const void* buffer, | 1609 const void* buffer, |
1609 size_t rowBytes, | 1610 size_t rowBytes, |
1610 uint32_t flags) { | 1611 uint32_t flags) { |
1611 ASSERT_OWNED_RESOURCE(target); | 1612 ASSERT_OWNED_RESOURCE(target); |
1612 | 1613 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1732 | 1733 |
1733 drawState->setRenderTarget(target); | 1734 drawState->setRenderTarget(target); |
1734 | 1735 |
1735 fGpu->drawSimpleRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heig ht))); | 1736 fGpu->drawSimpleRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heig ht))); |
1736 return true; | 1737 return true; |
1737 } | 1738 } |
1738 //////////////////////////////////////////////////////////////////////////////// | 1739 //////////////////////////////////////////////////////////////////////////////// |
1739 | 1740 |
1740 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, | 1741 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, |
1741 BufferedDraw buffered, | 1742 BufferedDraw buffered, |
1742 AutoRestoreEffects* are, | 1743 AutoRestoreEffects* are, |
robertphillips
2014/09/23 13:21:53
Does it still make sense to pass the acf?
bsalomon
2014/09/23 15:08:57
I'm not totally sure. I want to revisit this once
| |
1743 AutoCheckFlush* acf) { | 1744 AutoCheckFlush* acf) { |
1744 // All users of this draw state should be freeing up all effects when they'r e done. | 1745 // All users of this draw state should be freeing up all effects when they'r e done. |
1745 // Otherwise effects that own resources may keep those resources alive indef initely. | 1746 // Otherwise effects that own resources may keep those resources alive indef initely. |
1746 SkASSERT(0 == fDrawState->numColorStages() && 0 == fDrawState->numCoverageSt ages() && | 1747 SkASSERT(0 == fDrawState->numColorStages() && 0 == fDrawState->numCoverageSt ages() && |
1747 !fDrawState->hasGeometryProcessor()); | 1748 !fDrawState->hasGeometryProcessor()); |
1748 | 1749 |
1749 if (NULL == fGpu) { | 1750 if (NULL == fGpu) { |
1750 return NULL; | 1751 return NULL; |
1751 } | 1752 } |
1752 | 1753 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1946 fResourceCache->printStats(); | 1947 fResourceCache->printStats(); |
1947 } | 1948 } |
1948 #endif | 1949 #endif |
1949 | 1950 |
1950 #if GR_GPU_STATS | 1951 #if GR_GPU_STATS |
1951 const GrContext::GPUStats* GrContext::gpuStats() const { | 1952 const GrContext::GPUStats* GrContext::gpuStats() const { |
1952 return fGpu->gpuStats(); | 1953 return fGpu->gpuStats(); |
1953 } | 1954 } |
1954 #endif | 1955 #endif |
1955 | 1956 |
OLD | NEW |