| 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 1836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1847 return SkSurface::NewRenderTarget(fContext, info, fRenderTarget->numSamples(
)); | 1847 return SkSurface::NewRenderTarget(fContext, info, fRenderTarget->numSamples(
)); |
| 1848 } | 1848 } |
| 1849 | 1849 |
| 1850 void SkGpuDevice::EXPERIMENTAL_optimize(const SkPicture* picture) { | 1850 void SkGpuDevice::EXPERIMENTAL_optimize(const SkPicture* picture) { |
| 1851 fContext->getLayerCache()->processDeletedPictures(); | 1851 fContext->getLayerCache()->processDeletedPictures(); |
| 1852 | 1852 |
| 1853 if (NULL != picture->fData.get() && !picture->fData->suitableForLayerOptimiz
ation()) { | 1853 if (NULL != picture->fData.get() && !picture->fData->suitableForLayerOptimiz
ation()) { |
| 1854 return; | 1854 return; |
| 1855 } | 1855 } |
| 1856 | 1856 |
| 1857 SkPicture::AccelData::Key key = GPUAccelData::ComputeAccelDataKey(); | 1857 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); |
| 1858 | 1858 |
| 1859 const SkPicture::AccelData* existing = picture->EXPERIMENTAL_getAccelData(ke
y); | 1859 const SkPicture::AccelData* existing = picture->EXPERIMENTAL_getAccelData(ke
y); |
| 1860 if (NULL != existing) { | 1860 if (NULL != existing) { |
| 1861 return; | 1861 return; |
| 1862 } | 1862 } |
| 1863 | 1863 |
| 1864 SkAutoTUnref<GPUAccelData> data(SkNEW_ARGS(GPUAccelData, (key))); | 1864 SkAutoTUnref<GrAccelData> data(SkNEW_ARGS(GrAccelData, (key))); |
| 1865 | 1865 |
| 1866 picture->EXPERIMENTAL_addAccelData(data); | 1866 picture->EXPERIMENTAL_addAccelData(data); |
| 1867 | 1867 |
| 1868 GatherGPUInfo(picture, data); | 1868 GatherGPUInfo(picture, data); |
| 1869 | 1869 |
| 1870 fContext->getLayerCache()->trackPicture(picture); | 1870 fContext->getLayerCache()->trackPicture(picture); |
| 1871 } | 1871 } |
| 1872 | 1872 |
| 1873 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { | 1873 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { |
| 1874 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 1874 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 1875 result->setInfo(info); | 1875 result->setInfo(info); |
| 1876 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 1876 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
| 1877 } | 1877 } |
| 1878 | 1878 |
| 1879 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
* picture, | 1879 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
* picture, |
| 1880 const SkMatrix* matrix, const SkPaint
* paint) { | 1880 const SkMatrix* matrix, const SkPaint
* paint) { |
| 1881 // todo: should handle these natively | 1881 // todo: should handle these natively |
| 1882 if (matrix || paint) { | 1882 if (matrix || paint) { |
| 1883 return false; | 1883 return false; |
| 1884 } | 1884 } |
| 1885 | 1885 |
| 1886 fContext->getLayerCache()->processDeletedPictures(); | 1886 fContext->getLayerCache()->processDeletedPictures(); |
| 1887 | 1887 |
| 1888 SkPicture::AccelData::Key key = GPUAccelData::ComputeAccelDataKey(); | 1888 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); |
| 1889 | 1889 |
| 1890 const SkPicture::AccelData* data = picture->EXPERIMENTAL_getAccelData(key); | 1890 const SkPicture::AccelData* data = picture->EXPERIMENTAL_getAccelData(key); |
| 1891 if (NULL == data) { | 1891 if (NULL == data) { |
| 1892 return false; | 1892 return false; |
| 1893 } | 1893 } |
| 1894 | 1894 |
| 1895 const GPUAccelData *gpuData = static_cast<const GPUAccelData*>(data); | 1895 const GrAccelData *gpuData = static_cast<const GrAccelData*>(data); |
| 1896 | 1896 |
| 1897 if (0 == gpuData->numSaveLayers()) { | 1897 if (0 == gpuData->numSaveLayers()) { |
| 1898 return false; | 1898 return false; |
| 1899 } | 1899 } |
| 1900 | 1900 |
| 1901 SkAutoTArray<bool> pullForward(gpuData->numSaveLayers()); | 1901 SkAutoTArray<bool> pullForward(gpuData->numSaveLayers()); |
| 1902 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 1902 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
| 1903 pullForward[i] = false; | 1903 pullForward[i] = false; |
| 1904 } | 1904 } |
| 1905 | 1905 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1918 // is used to limit which clips are pre-rendered. | 1918 // is used to limit which clips are pre-rendered. |
| 1919 static const int kSaveLayerMaxSize = 256; | 1919 static const int kSaveLayerMaxSize = 256; |
| 1920 | 1920 |
| 1921 if (NULL != ops.get()) { | 1921 if (NULL != ops.get()) { |
| 1922 // In this case the picture has been generated with a BBH so we use | 1922 // In this case the picture has been generated with a BBH so we use |
| 1923 // the BBH to limit the pre-rendering to just the layers needed to cover | 1923 // the BBH to limit the pre-rendering to just the layers needed to cover |
| 1924 // the region being drawn | 1924 // the region being drawn |
| 1925 for (int i = 0; i < ops->numOps(); ++i) { | 1925 for (int i = 0; i < ops->numOps(); ++i) { |
| 1926 uint32_t offset = ops->offset(i); | 1926 uint32_t offset = ops->offset(i); |
| 1927 | 1927 |
| 1928 // For now we're saving all the layers in the GPUAccelData so they | 1928 // For now we're saving all the layers in the GrAccelData so they |
| 1929 // can be nested. Additionally, the nested layers appear before | 1929 // can be nested. Additionally, the nested layers appear before |
| 1930 // their parent in the list. | 1930 // their parent in the list. |
| 1931 for (int j = 0 ; j < gpuData->numSaveLayers(); ++j) { | 1931 for (int j = 0 ; j < gpuData->numSaveLayers(); ++j) { |
| 1932 const GPUAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo
(j); | 1932 const GrAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(
j); |
| 1933 | 1933 |
| 1934 if (pullForward[j]) { | 1934 if (pullForward[j]) { |
| 1935 continue; // already pulling forward | 1935 continue; // already pulling forward |
| 1936 } | 1936 } |
| 1937 | 1937 |
| 1938 if (offset < info.fSaveLayerOpID || offset > info.fRestoreOpID)
{ | 1938 if (offset < info.fSaveLayerOpID || offset > info.fRestoreOpID)
{ |
| 1939 continue; // the op isn't in this range | 1939 continue; // the op isn't in this range |
| 1940 } | 1940 } |
| 1941 | 1941 |
| 1942 // TODO: once this code is more stable unsuitable layers can | 1942 // TODO: once this code is more stable unsuitable layers can |
| 1943 // just be omitted during the optimization stage | 1943 // just be omitted during the optimization stage |
| 1944 if (!info.fValid || | 1944 if (!info.fValid || |
| 1945 kSaveLayerMaxSize < info.fSize.fWidth || | 1945 kSaveLayerMaxSize < info.fSize.fWidth || |
| 1946 kSaveLayerMaxSize < info.fSize.fHeight || | 1946 kSaveLayerMaxSize < info.fSize.fHeight || |
| 1947 info.fIsNested) { | 1947 info.fIsNested) { |
| 1948 continue; // this layer is unsuitable | 1948 continue; // this layer is unsuitable |
| 1949 } | 1949 } |
| 1950 | 1950 |
| 1951 pullForward[j] = true; | 1951 pullForward[j] = true; |
| 1952 } | 1952 } |
| 1953 } | 1953 } |
| 1954 } else { | 1954 } else { |
| 1955 // In this case there is no BBH associated with the picture. Pre-render | 1955 // In this case there is no BBH associated with the picture. Pre-render |
| 1956 // all the layers that intersect the drawn region | 1956 // all the layers that intersect the drawn region |
| 1957 for (int j = 0; j < gpuData->numSaveLayers(); ++j) { | 1957 for (int j = 0; j < gpuData->numSaveLayers(); ++j) { |
| 1958 const GPUAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(j); | 1958 const GrAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(j); |
| 1959 | 1959 |
| 1960 SkIRect layerRect = SkIRect::MakeXYWH(info.fOffset.fX, | 1960 SkIRect layerRect = SkIRect::MakeXYWH(info.fOffset.fX, |
| 1961 info.fOffset.fY, | 1961 info.fOffset.fY, |
| 1962 info.fSize.fWidth, | 1962 info.fSize.fWidth, |
| 1963 info.fSize.fHeight); | 1963 info.fSize.fHeight); |
| 1964 | 1964 |
| 1965 if (!SkIRect::Intersects(query, layerRect)) { | 1965 if (!SkIRect::Intersects(query, layerRect)) { |
| 1966 continue; | 1966 continue; |
| 1967 } | 1967 } |
| 1968 | 1968 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1980 } | 1980 } |
| 1981 | 1981 |
| 1982 SkPictureReplacementPlayback::PlaybackReplacements replacements; | 1982 SkPictureReplacementPlayback::PlaybackReplacements replacements; |
| 1983 | 1983 |
| 1984 SkTDArray<GrCachedLayer*> atlased, nonAtlased; | 1984 SkTDArray<GrCachedLayer*> atlased, nonAtlased; |
| 1985 atlased.setReserve(gpuData->numSaveLayers()); | 1985 atlased.setReserve(gpuData->numSaveLayers()); |
| 1986 | 1986 |
| 1987 // Generate the layer and/or ensure it is locked | 1987 // Generate the layer and/or ensure it is locked |
| 1988 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 1988 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
| 1989 if (pullForward[i]) { | 1989 if (pullForward[i]) { |
| 1990 const GPUAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); | 1990 const GrAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); |
| 1991 | 1991 |
| 1992 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(
picture->uniqueID(), | 1992 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(
picture->uniqueID(), |
| 1993
info.fSaveLayerOpID, | 1993
info.fSaveLayerOpID, |
| 1994
info.fRestoreOpID, | 1994
info.fRestoreOpID, |
| 1995
info.fCTM); | 1995
info.fCTM); |
| 1996 | 1996 |
| 1997 SkPictureReplacementPlayback::PlaybackReplacements::ReplacementInfo*
layerInfo = | 1997 SkPictureReplacementPlayback::PlaybackReplacements::ReplacementInfo*
layerInfo = |
| 1998 replacem
ents.push(); | 1998 replacem
ents.push(); |
| 1999 layerInfo->fStart = info.fSaveLayerOpID; | 1999 layerInfo->fStart = info.fSaveLayerOpID; |
| 2000 layerInfo->fStop = info.fRestoreOpID; | 2000 layerInfo->fStop = info.fRestoreOpID; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2118 layerCanvas->flush(); | 2118 layerCanvas->flush(); |
| 2119 } | 2119 } |
| 2120 | 2120 |
| 2121 // Render the entire picture using new layers | 2121 // Render the entire picture using new layers |
| 2122 SkPictureReplacementPlayback playback(picture, &replacements, ops.get()); | 2122 SkPictureReplacementPlayback playback(picture, &replacements, ops.get()); |
| 2123 | 2123 |
| 2124 playback.draw(mainCanvas, NULL); | 2124 playback.draw(mainCanvas, NULL); |
| 2125 | 2125 |
| 2126 // unlock the layers | 2126 // unlock the layers |
| 2127 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 2127 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
| 2128 const GPUAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); | 2128 const GrAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); |
| 2129 | 2129 |
| 2130 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture->uni
queID(), | 2130 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture->uni
queID(), |
| 2131 info.fSaveLa
yerOpID, | 2131 info.fSaveLa
yerOpID, |
| 2132 info.fRestor
eOpID, | 2132 info.fRestor
eOpID, |
| 2133 info.fCTM); | 2133 info.fCTM); |
| 2134 fContext->getLayerCache()->unlock(layer); | 2134 fContext->getLayerCache()->unlock(layer); |
| 2135 } | 2135 } |
| 2136 | 2136 |
| 2137 #if DISABLE_CACHING | 2137 #if DISABLE_CACHING |
| 2138 // This code completely clears out the atlas. It is required when | 2138 // This code completely clears out the atlas. It is required when |
| 2139 // caching is disabled so the atlas doesn't fill up and force more | 2139 // caching is disabled so the atlas doesn't fill up and force more |
| 2140 // free floating layers | 2140 // free floating layers |
| 2141 fContext->getLayerCache()->purge(picture->uniqueID()); | 2141 fContext->getLayerCache()->purge(picture->uniqueID()); |
| 2142 | 2142 |
| 2143 fContext->getLayerCache()->purgeAll(); | 2143 fContext->getLayerCache()->purgeAll(); |
| 2144 #endif | 2144 #endif |
| 2145 | 2145 |
| 2146 return true; | 2146 return true; |
| 2147 } | 2147 } |
| 2148 | 2148 |
| 2149 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 2149 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 2150 // We always return a transient cache, so it is freed after each | 2150 // We always return a transient cache, so it is freed after each |
| 2151 // filter traversal. | 2151 // filter traversal. |
| 2152 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 2152 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 2153 } | 2153 } |
| OLD | NEW |