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 "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
9 | 9 |
10 #include "effects/GrBicubicEffect.h" | 10 #include "effects/GrBicubicEffect.h" |
(...skipping 1824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 result->setInfo(info); | 1835 result->setInfo(info); |
1836 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 1836 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
1837 } | 1837 } |
1838 | 1838 |
1839 void SkGpuDevice::EXPERIMENTAL_purge(const SkPicture* picture) { | 1839 void SkGpuDevice::EXPERIMENTAL_purge(const SkPicture* picture) { |
1840 | 1840 |
1841 } | 1841 } |
1842 | 1842 |
1843 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* canvas, const SkPicture* pi
cture) { | 1843 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* canvas, const SkPicture* pi
cture) { |
1844 | 1844 |
| 1845 if (NULL == picture->fPlayback.get()) { |
| 1846 return false; |
| 1847 } |
| 1848 |
1845 SkPicture::AccelData::Key key = GPUAccelData::ComputeAccelDataKey(); | 1849 SkPicture::AccelData::Key key = GPUAccelData::ComputeAccelDataKey(); |
1846 | 1850 |
1847 const SkPicture::AccelData* data = picture->EXPERIMENTAL_getAccelData(key); | 1851 const SkPicture::AccelData* data = picture->EXPERIMENTAL_getAccelData(key); |
1848 if (NULL == data) { | 1852 if (NULL == data) { |
1849 return false; | 1853 return false; |
1850 } | 1854 } |
1851 | 1855 |
1852 const GPUAccelData *gpuData = static_cast<const GPUAccelData*>(data); | 1856 const GPUAccelData *gpuData = static_cast<const GPUAccelData*>(data); |
1853 | 1857 |
1854 if (0 == gpuData->numSaveLayers()) { | 1858 if (0 == gpuData->numSaveLayers()) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 info.fIsNested) { | 1935 info.fIsNested) { |
1932 continue; | 1936 continue; |
1933 } | 1937 } |
1934 | 1938 |
1935 pullForward[j] = true; | 1939 pullForward[j] = true; |
1936 } | 1940 } |
1937 } | 1941 } |
1938 | 1942 |
1939 SkPicturePlayback::PlaybackReplacements replacements; | 1943 SkPicturePlayback::PlaybackReplacements replacements; |
1940 | 1944 |
| 1945 // Generate the layer and/or ensure it is locked |
1941 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 1946 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
1942 if (pullForward[i]) { | 1947 if (pullForward[i]) { |
1943 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(
picture, i); | 1948 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(
picture, i); |
1944 | 1949 |
1945 const GPUAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); | 1950 const GPUAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); |
1946 | 1951 |
1947 if (NULL != picture->fPlayback.get()) { | 1952 SkPicturePlayback::PlaybackReplacements::ReplacementInfo* layerInfo
= |
1948 SkPicturePlayback::PlaybackReplacements::ReplacementInfo* layerI
nfo = | |
1949 replacem
ents.push(); | 1953 replacem
ents.push(); |
1950 layerInfo->fStart = info.fSaveLayerOpID; | 1954 layerInfo->fStart = info.fSaveLayerOpID; |
1951 layerInfo->fStop = info.fRestoreOpID; | 1955 layerInfo->fStop = info.fRestoreOpID; |
1952 layerInfo->fPos = info.fOffset; | 1956 layerInfo->fPos = info.fOffset; |
1953 | 1957 |
1954 GrTextureDesc desc; | 1958 GrTextureDesc desc; |
1955 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 1959 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
1956 desc.fWidth = info.fSize.fWidth; | 1960 desc.fWidth = info.fSize.fWidth; |
1957 desc.fHeight = info.fSize.fHeight; | 1961 desc.fHeight = info.fSize.fHeight; |
1958 desc.fConfig = kSkia8888_GrPixelConfig; | 1962 desc.fConfig = kSkia8888_GrPixelConfig; |
1959 // TODO: need to deal with sample count | 1963 // TODO: need to deal with sample count |
1960 | 1964 |
1961 bool bNeedsRendering = true; | 1965 bool needsRendering = !fContext->getLayerCache()->lock(layer, desc); |
| 1966 if (NULL == layer->getTexture()) { |
| 1967 continue; |
| 1968 } |
1962 | 1969 |
1963 // This just uses scratch textures and doesn't cache the texture
. | 1970 layerInfo->fBM = SkNEW(SkBitmap); // fBM is allocated so Replacemen
tInfo can be POD |
1964 // This can yield a lot of re-rendering | 1971 wrap_texture(layer->getTexture(), desc.fWidth, desc.fHeight, layerIn
fo->fBM); |
1965 if (NULL == layer->getTexture()) { | |
1966 layer->setTexture(fContext->lockAndRefScratchTexture(desc, | |
1967 GrContext::kApprox_Scrat
chTexMatch)); | |
1968 if (NULL == layer->getTexture()) { | |
1969 continue; | |
1970 } | |
1971 } else { | |
1972 bNeedsRendering = false; | |
1973 } | |
1974 | 1972 |
1975 layerInfo->fBM = SkNEW(SkBitmap); | 1973 SkASSERT(info.fPaint); |
1976 wrap_texture(layer->getTexture(), desc.fWidth, desc.fHeight, lay
erInfo->fBM); | 1974 layerInfo->fPaint = info.fPaint; |
1977 | 1975 |
1978 SkASSERT(info.fPaint); | 1976 if (needsRendering) { |
1979 layerInfo->fPaint = info.fPaint; | 1977 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect
( |
| 1978 layer->getTexture()->asRende
rTarget())); |
1980 | 1979 |
1981 if (bNeedsRendering) { | 1980 SkCanvas* canvas = surface->getCanvas(); |
1982 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDi
rect( | |
1983 layer->getTexture()->asR
enderTarget())); | |
1984 | 1981 |
1985 SkCanvas* canvas = surface->getCanvas(); | 1982 canvas->setMatrix(info.fCTM); |
| 1983 canvas->clear(SK_ColorTRANSPARENT); |
1986 | 1984 |
1987 canvas->setMatrix(info.fCTM); | 1985 picture->fPlayback->setDrawLimits(info.fSaveLayerOpID, info.fRes
toreOpID); |
1988 canvas->clear(SK_ColorTRANSPARENT); | 1986 picture->fPlayback->draw(*canvas, NULL); |
1989 | 1987 picture->fPlayback->setDrawLimits(0, 0); |
1990 picture->fPlayback->setDrawLimits(info.fSaveLayerOpID, info.
fRestoreOpID); | 1988 canvas->flush(); |
1991 picture->fPlayback->draw(*canvas, NULL); | |
1992 picture->fPlayback->setDrawLimits(0, 0); | |
1993 canvas->flush(); | |
1994 } | |
1995 } | 1989 } |
1996 } | 1990 } |
1997 } | 1991 } |
1998 | 1992 |
1999 // Playback using new layers | 1993 // Playback using new layers |
2000 picture->fPlayback->setReplacements(&replacements); | 1994 picture->fPlayback->setReplacements(&replacements); |
2001 picture->fPlayback->draw(*canvas, NULL); | 1995 picture->fPlayback->draw(*canvas, NULL); |
2002 picture->fPlayback->setReplacements(NULL); | 1996 picture->fPlayback->setReplacements(NULL); |
2003 | 1997 |
| 1998 // unlock the layers |
2004 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 1999 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
2005 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(pict
ure, i); | 2000 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); |
2006 | 2001 fContext->getLayerCache()->unlock(layer); |
2007 if (NULL != layer->getTexture()) { | |
2008 fContext->unlockScratchTexture(layer->getTexture()); | |
2009 layer->setTexture(NULL); | |
2010 } | |
2011 } | 2002 } |
2012 | 2003 |
2013 return true; | 2004 return true; |
2014 } | 2005 } |
OLD | NEW |