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 1576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 | 1587 |
1588 GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW, NULL, NULL); | 1588 GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW, NULL, NULL); |
1589 if (NULL == target) { | 1589 if (NULL == target) { |
1590 return; | 1590 return; |
1591 } | 1591 } |
1592 SkIPoint dstPoint; | 1592 SkIPoint dstPoint; |
1593 dstPoint.setZero(); | 1593 dstPoint.setZero(); |
1594 target->copySurface(dst, src, srcRect, dstPoint); | 1594 target->copySurface(dst, src, srcRect, dstPoint); |
1595 } | 1595 } |
1596 | 1596 |
1597 bool GrContext::writeRenderTargetPixels(GrRenderTarget* target, | 1597 bool GrContext::writeRenderTargetPixels(GrRenderTarget* renderTarget, |
1598 int left, int top, int width, int height
, | 1598 int left, int top, int width, int height
, |
1599 GrPixelConfig srcConfig, | 1599 GrPixelConfig srcConfig, |
1600 const void* buffer, | 1600 const void* buffer, |
1601 size_t rowBytes, | 1601 size_t rowBytes, |
1602 uint32_t flags) { | 1602 uint32_t flags) { |
1603 ASSERT_OWNED_RESOURCE(target); | 1603 ASSERT_OWNED_RESOURCE(renderTarget); |
1604 | 1604 |
1605 if (NULL == target) { | 1605 if (NULL == renderTarget) { |
1606 target = fRenderTarget.get(); | 1606 renderTarget = fRenderTarget.get(); |
1607 if (NULL == target) { | 1607 if (NULL == renderTarget) { |
1608 return false; | 1608 return false; |
1609 } | 1609 } |
1610 } | 1610 } |
1611 | 1611 |
1612 // TODO: when underlying api has a direct way to do this we should use it (e
.g. glDrawPixels on | 1612 // TODO: when underlying api has a direct way to do this we should use it (e
.g. glDrawPixels on |
1613 // desktop GL). | 1613 // desktop GL). |
1614 | 1614 |
1615 // We will always call some form of writeTexturePixels and we will pass our
flags on to it. | 1615 // We will always call some form of writeTexturePixels and we will pass our
flags on to it. |
1616 // Thus, we don't perform a flush here since that call will do it (if the kN
oFlush flag isn't | 1616 // Thus, we don't perform a flush here since that call will do it (if the kN
oFlush flag isn't |
1617 // set.) | 1617 // set.) |
1618 | 1618 |
1619 // If the RT is also a texture and we don't have to premultiply then take th
e texture path. | 1619 // If the RT is also a texture and we don't have to premultiply then take th
e texture path. |
1620 // We expect to be at least as fast or faster since it doesn't use an interm
ediate texture as | 1620 // We expect to be at least as fast or faster since it doesn't use an interm
ediate texture as |
1621 // we do below. | 1621 // we do below. |
1622 | 1622 |
1623 #if !defined(SK_BUILD_FOR_MAC) | 1623 #if !defined(SK_BUILD_FOR_MAC) |
1624 // At least some drivers on the Mac get confused when glTexImage2D is called
on a texture | 1624 // At least some drivers on the Mac get confused when glTexImage2D is called
on a texture |
1625 // attached to an FBO. The FBO still sees the old image. TODO: determine wha
t OS versions and/or | 1625 // attached to an FBO. The FBO still sees the old image. TODO: determine wha
t OS versions and/or |
1626 // HW is affected. | 1626 // HW is affected. |
1627 if (target->asTexture() && !(kUnpremul_PixelOpsFlag & flags) && | 1627 if (renderTarget->asTexture() && !(kUnpremul_PixelOpsFlag & flags) && |
1628 fGpu->canWriteTexturePixels(target->asTexture(), srcConfig)) { | 1628 fGpu->canWriteTexturePixels(renderTarget->asTexture(), srcConfig)) { |
1629 return this->writeTexturePixels(target->asTexture(), | 1629 return this->writeTexturePixels(renderTarget->asTexture(), |
1630 left, top, width, height, | 1630 left, top, width, height, |
1631 srcConfig, buffer, rowBytes, flags); | 1631 srcConfig, buffer, rowBytes, flags); |
1632 } | 1632 } |
1633 #endif | 1633 #endif |
1634 | 1634 |
1635 // We ignore the preferred config unless it is a R/B swap of the src config.
In that case | 1635 // We ignore the preferred config unless it is a R/B swap of the src config.
In that case |
1636 // we will upload the original src data to a scratch texture but we will spo
of it as the swapped | 1636 // we will upload the original src data to a scratch texture but we will spo
of it as the swapped |
1637 // config. This scratch will then have R and B swapped. We correct for this
by swapping again | 1637 // config. This scratch will then have R and B swapped. We correct for this
by swapping again |
1638 // when drawing the scratch to the dst using a conversion effect. | 1638 // when drawing the scratch to the dst using a conversion effect. |
1639 bool swapRAndB = false; | 1639 bool swapRAndB = false; |
1640 GrPixelConfig writeConfig = srcConfig; | 1640 GrPixelConfig writeConfig = srcConfig; |
1641 if (GrPixelConfigSwapRAndB(srcConfig) == | 1641 if (GrPixelConfigSwapRAndB(srcConfig) == |
1642 fGpu->preferredWritePixelsConfig(srcConfig, target->config())) { | 1642 fGpu->preferredWritePixelsConfig(srcConfig, renderTarget->config())) { |
1643 writeConfig = GrPixelConfigSwapRAndB(srcConfig); | 1643 writeConfig = GrPixelConfigSwapRAndB(srcConfig); |
1644 swapRAndB = true; | 1644 swapRAndB = true; |
1645 } | 1645 } |
1646 | 1646 |
1647 GrTextureDesc desc; | 1647 GrTextureDesc desc; |
1648 desc.fWidth = width; | 1648 desc.fWidth = width; |
1649 desc.fHeight = height; | 1649 desc.fHeight = height; |
1650 desc.fConfig = writeConfig; | 1650 desc.fConfig = writeConfig; |
1651 GrAutoScratchTexture ast(this, desc); | 1651 GrAutoScratchTexture ast(this, desc); |
1652 GrTexture* texture = ast.texture(); | 1652 GrTexture* texture = ast.texture(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 if (!srcPI.convertPixelsTo(&dstPI, width, height)) { | 1687 if (!srcPI.convertPixelsTo(&dstPI, width, height)) { |
1688 return false; | 1688 return false; |
1689 } | 1689 } |
1690 | 1690 |
1691 buffer = tmpPixels.get(); | 1691 buffer = tmpPixels.get(); |
1692 rowBytes = 4 * width; | 1692 rowBytes = 4 * width; |
1693 } | 1693 } |
1694 } | 1694 } |
1695 if (NULL == fp) { | 1695 if (NULL == fp) { |
1696 fp.reset(GrConfigConversionEffect::Create(texture, | 1696 fp.reset(GrConfigConversionEffect::Create(texture, |
1697 swapRAndB, | 1697 swapRAndB, |
1698 GrConfigConversionEffect::
kNone_PMConversion, | 1698 GrConfigConversionEffect::kNon
e_PMConversion, |
1699 textureMatrix)); | 1699 textureMatrix)); |
1700 } | 1700 } |
1701 | 1701 |
1702 if (!this->writeTexturePixels(texture, | 1702 if (!this->writeTexturePixels(texture, |
1703 0, 0, width, height, | 1703 0, 0, width, height, |
1704 writeConfig, buffer, rowBytes, | 1704 writeConfig, buffer, rowBytes, |
1705 flags & ~kUnpremul_PixelOpsFlag)) { | 1705 flags & ~kUnpremul_PixelOpsFlag)) { |
1706 return false; | 1706 return false; |
1707 } | 1707 } |
1708 | 1708 |
1709 // TODO: Usually this could go to fDrawBuffer but currently | |
1710 // writeRenderTargetPixels can be called in the midst of drawing another | |
1711 // object (e.g., when uploading a SW path rendering to the gpu while | |
1712 // drawing a rect). So we always draw directly to GrGpu and preserve the cur
rent geometry. | |
1713 // But that means we also have to flush the draw buffer if there is a pendin
g IO operation to | |
1714 // the render target. | |
1715 if (!(kDontFlush_PixelOpsFlag & flags) && target->hasPendingIO()) { | |
1716 this->flush(); | |
1717 } | |
1718 SkMatrix matrix; | 1709 SkMatrix matrix; |
1719 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 1710 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
1720 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRI
nit, &matrix); | 1711 |
1721 GrDrawState* drawState = fGpu->drawState(); | 1712 // This function can be called in the midst of drawing another object (e.g.,
when uploading a |
1722 SkASSERT(fp); | 1713 // SW-rasterized clip while issuing a draw). So we push the current geometry
state before |
| 1714 // drawing a rect to the render target. |
| 1715 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, kYes_BufferedDraw, NULL
, NULL); |
| 1716 GrDrawTarget::AutoGeometryAndStatePush agasp(drawTarget, GrDrawTarget::kRese
t_ASRInit, &matrix); |
| 1717 GrDrawState* drawState = drawTarget->drawState(); |
1723 drawState->addColorProcessor(fp); | 1718 drawState->addColorProcessor(fp); |
1724 | 1719 drawState->setRenderTarget(renderTarget); |
1725 drawState->setRenderTarget(target); | 1720 drawState->disableState(GrDrawState::kClip_StateBit); |
1726 | 1721 drawTarget->drawSimpleRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScala
r(height))); |
1727 fGpu->drawSimpleRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heig
ht))); | |
1728 return true; | 1722 return true; |
1729 } | 1723 } |
1730 //////////////////////////////////////////////////////////////////////////////// | 1724 //////////////////////////////////////////////////////////////////////////////// |
1731 | 1725 |
1732 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, | 1726 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, |
1733 BufferedDraw buffered, | 1727 BufferedDraw buffered, |
1734 AutoRestoreEffects* are, | 1728 AutoRestoreEffects* are, |
1735 AutoCheckFlush* acf) { | 1729 AutoCheckFlush* acf) { |
1736 // All users of this draw state should be freeing up all effects when they'r
e done. | 1730 // All users of this draw state should be freeing up all effects when they'r
e done. |
1737 // Otherwise effects that own resources may keep those resources alive indef
initely. | 1731 // Otherwise effects that own resources may keep those resources alive indef
initely. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 fResourceCache->printStats(); | 1932 fResourceCache->printStats(); |
1939 } | 1933 } |
1940 #endif | 1934 #endif |
1941 | 1935 |
1942 #if GR_GPU_STATS | 1936 #if GR_GPU_STATS |
1943 const GrContext::GPUStats* GrContext::gpuStats() const { | 1937 const GrContext::GPUStats* GrContext::gpuStats() const { |
1944 return fGpu->gpuStats(); | 1938 return fGpu->gpuStats(); |
1945 } | 1939 } |
1946 #endif | 1940 #endif |
1947 | 1941 |
OLD | NEW |