| 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 12 matching lines...) Expand all Loading... |
| 23 #include "SkGrTexturePixelRef.h" | 23 #include "SkGrTexturePixelRef.h" |
| 24 | 24 |
| 25 #include "SkDeviceImageFilterProxy.h" | 25 #include "SkDeviceImageFilterProxy.h" |
| 26 #include "SkDrawProcs.h" | 26 #include "SkDrawProcs.h" |
| 27 #include "SkGlyphCache.h" | 27 #include "SkGlyphCache.h" |
| 28 #include "SkImageFilter.h" | 28 #include "SkImageFilter.h" |
| 29 #include "SkMaskFilter.h" | 29 #include "SkMaskFilter.h" |
| 30 #include "SkPathEffect.h" | 30 #include "SkPathEffect.h" |
| 31 #include "SkPicture.h" | 31 #include "SkPicture.h" |
| 32 #include "SkPictureData.h" | 32 #include "SkPictureData.h" |
| 33 #include "SkPicturePlayback.h" |
| 33 #include "SkRRect.h" | 34 #include "SkRRect.h" |
| 34 #include "SkStroke.h" | 35 #include "SkStroke.h" |
| 35 #include "SkSurface.h" | 36 #include "SkSurface.h" |
| 36 #include "SkTLazy.h" | 37 #include "SkTLazy.h" |
| 37 #include "SkUtils.h" | 38 #include "SkUtils.h" |
| 38 #include "SkVertState.h" | 39 #include "SkVertState.h" |
| 39 #include "SkErrorInternals.h" | 40 #include "SkErrorInternals.h" |
| 40 | 41 |
| 41 #define CACHE_COMPATIBLE_DEVICE_TEXTURES 1 | 42 #define CACHE_COMPATIBLE_DEVICE_TEXTURES 1 |
| 42 | 43 |
| (...skipping 1809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1852 pullForward[i] = false; | 1853 pullForward[i] = false; |
| 1853 } | 1854 } |
| 1854 | 1855 |
| 1855 SkRect clipBounds; | 1856 SkRect clipBounds; |
| 1856 if (!canvas->getClipBounds(&clipBounds)) { | 1857 if (!canvas->getClipBounds(&clipBounds)) { |
| 1857 return true; | 1858 return true; |
| 1858 } | 1859 } |
| 1859 SkIRect query; | 1860 SkIRect query; |
| 1860 clipBounds.roundOut(&query); | 1861 clipBounds.roundOut(&query); |
| 1861 | 1862 |
| 1862 const SkPicture::OperationList& ops = picture->EXPERIMENTAL_getActiveOps(que
ry); | 1863 SkAutoTDelete<const SkPicture::OperationList> ops(picture->EXPERIMENTAL_getA
ctiveOps(query)); |
| 1863 | 1864 |
| 1864 // This code pre-renders the entire layer since it will be cached and potent
ially | 1865 // This code pre-renders the entire layer since it will be cached and potent
ially |
| 1865 // reused with different clips (e.g., in different tiles). Because of this t
he | 1866 // reused with different clips (e.g., in different tiles). Because of this t
he |
| 1866 // clip will not be limiting the size of the pre-rendered layer. kSaveLayerM
axSize | 1867 // clip will not be limiting the size of the pre-rendered layer. kSaveLayerM
axSize |
| 1867 // is used to limit which clips are pre-rendered. | 1868 // is used to limit which clips are pre-rendered. |
| 1868 static const int kSaveLayerMaxSize = 256; | 1869 static const int kSaveLayerMaxSize = 256; |
| 1869 | 1870 |
| 1870 if (ops.valid()) { | 1871 if (NULL != ops.get()) { |
| 1871 // In this case the picture has been generated with a BBH so we use | 1872 // In this case the picture has been generated with a BBH so we use |
| 1872 // the BBH to limit the pre-rendering to just the layers needed to cover | 1873 // the BBH to limit the pre-rendering to just the layers needed to cover |
| 1873 // the region being drawn | 1874 // the region being drawn |
| 1874 for (int i = 0; i < ops.numOps(); ++i) { | 1875 for (int i = 0; i < ops->numOps(); ++i) { |
| 1875 uint32_t offset = ops.offset(i); | 1876 uint32_t offset = ops->offset(i); |
| 1876 | 1877 |
| 1877 // For now we're saving all the layers in the GPUAccelData so they | 1878 // For now we're saving all the layers in the GPUAccelData so they |
| 1878 // can be nested. Additionally, the nested layers appear before | 1879 // can be nested. Additionally, the nested layers appear before |
| 1879 // their parent in the list. | 1880 // their parent in the list. |
| 1880 for (int j = 0 ; j < gpuData->numSaveLayers(); ++j) { | 1881 for (int j = 0 ; j < gpuData->numSaveLayers(); ++j) { |
| 1881 const GPUAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo
(j); | 1882 const GPUAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo
(j); |
| 1882 | 1883 |
| 1883 if (pullForward[j]) { | 1884 if (pullForward[j]) { |
| 1884 continue; // already pulling forward | 1885 continue; // already pulling forward |
| 1885 } | 1886 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1921 kSaveLayerMaxSize < info.fSize.fWidth || | 1922 kSaveLayerMaxSize < info.fSize.fWidth || |
| 1922 kSaveLayerMaxSize < info.fSize.fHeight || | 1923 kSaveLayerMaxSize < info.fSize.fHeight || |
| 1923 info.fIsNested) { | 1924 info.fIsNested) { |
| 1924 continue; | 1925 continue; |
| 1925 } | 1926 } |
| 1926 | 1927 |
| 1927 pullForward[j] = true; | 1928 pullForward[j] = true; |
| 1928 } | 1929 } |
| 1929 } | 1930 } |
| 1930 | 1931 |
| 1931 SkPictureData::PlaybackReplacements replacements; | 1932 SkPicturePlayback::PlaybackReplacements replacements; |
| 1932 | 1933 |
| 1933 // Generate the layer and/or ensure it is locked | 1934 // Generate the layer and/or ensure it is locked |
| 1934 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 1935 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
| 1935 if (pullForward[i]) { | 1936 if (pullForward[i]) { |
| 1936 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(
picture, i); | 1937 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(
picture, i); |
| 1937 | 1938 |
| 1938 const GPUAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); | 1939 const GPUAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); |
| 1939 | 1940 |
| 1940 SkPictureData::PlaybackReplacements::ReplacementInfo* layerInfo = | 1941 SkPicturePlayback::PlaybackReplacements::ReplacementInfo* layerInfo
= |
| 1941 replacem
ents.push(); | 1942 replacem
ents.push(); |
| 1942 layerInfo->fStart = info.fSaveLayerOpID; | 1943 layerInfo->fStart = info.fSaveLayerOpID; |
| 1943 layerInfo->fStop = info.fRestoreOpID; | 1944 layerInfo->fStop = info.fRestoreOpID; |
| 1944 layerInfo->fPos = info.fOffset; | 1945 layerInfo->fPos = info.fOffset; |
| 1945 | 1946 |
| 1946 GrTextureDesc desc; | 1947 GrTextureDesc desc; |
| 1947 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 1948 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1948 desc.fWidth = info.fSize.fWidth; | 1949 desc.fWidth = info.fSize.fWidth; |
| 1949 desc.fHeight = info.fSize.fHeight; | 1950 desc.fHeight = info.fSize.fHeight; |
| 1950 desc.fConfig = kSkia8888_GrPixelConfig; | 1951 desc.fConfig = kSkia8888_GrPixelConfig; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2002 | 2003 |
| 2003 if (!layer->rect().isEmpty()) { | 2004 if (!layer->rect().isEmpty()) { |
| 2004 // info.fCTM maps the layer's top/left to the origin. | 2005 // info.fCTM maps the layer's top/left to the origin. |
| 2005 // Since this layer is atlased the top/left corner needs | 2006 // Since this layer is atlased the top/left corner needs |
| 2006 // to be offset to some arbitrary location in the backing | 2007 // to be offset to some arbitrary location in the backing |
| 2007 // texture. | 2008 // texture. |
| 2008 canvas->translate(SkIntToScalar(layer->rect().fLeft), | 2009 canvas->translate(SkIntToScalar(layer->rect().fLeft), |
| 2009 SkIntToScalar(layer->rect().fTop)); | 2010 SkIntToScalar(layer->rect().fTop)); |
| 2010 } | 2011 } |
| 2011 | 2012 |
| 2012 picture->fData->setDrawLimits(info.fSaveLayerOpID, info.fRestore
OpID); | 2013 SkPicturePlayback playback(picture); |
| 2013 picture->fData->draw(*canvas, NULL); | 2014 playback.setDrawLimits(info.fSaveLayerOpID, info.fRestoreOpID); |
| 2014 picture->fData->setDrawLimits(0, 0); | 2015 playback.draw(canvas, NULL); |
| 2015 | 2016 |
| 2016 canvas->flush(); | 2017 canvas->flush(); |
| 2017 } | 2018 } |
| 2018 } | 2019 } |
| 2019 } | 2020 } |
| 2020 | 2021 |
| 2021 // Playback using new layers | 2022 // Playback using new layers |
| 2022 picture->fData->setReplacements(&replacements); | 2023 SkPicturePlayback playback(picture); |
| 2023 picture->fData->draw(*canvas, NULL); | 2024 |
| 2024 picture->fData->setReplacements(NULL); | 2025 playback.setReplacements(&replacements); |
| 2026 playback.draw(canvas, NULL); |
| 2025 | 2027 |
| 2026 // unlock the layers | 2028 // unlock the layers |
| 2027 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 2029 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
| 2028 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); | 2030 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); |
| 2029 fContext->getLayerCache()->unlock(layer); | 2031 fContext->getLayerCache()->unlock(layer); |
| 2030 } | 2032 } |
| 2031 | 2033 |
| 2032 return true; | 2034 return true; |
| 2033 } | 2035 } |
| OLD | NEW |