| 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 | 1835 |
| 1836 fContext->getLayerCache()->trackPicture(picture); | 1836 fContext->getLayerCache()->trackPicture(picture); |
| 1837 } | 1837 } |
| 1838 | 1838 |
| 1839 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { | 1839 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { |
| 1840 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 1840 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 1841 result->setInfo(info); | 1841 result->setInfo(info); |
| 1842 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 1842 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
| 1843 } | 1843 } |
| 1844 | 1844 |
| 1845 static void convert_layers_to_replacements(const SkTDArray<GrCachedLayer*>& laye
rs, |
| 1846 GrReplacements* replacements) { |
| 1847 // TODO: just replace GrReplacements::ReplacementInfo with GrCachedLayer? |
| 1848 for (int i = 0; i < layers.count(); ++i) { |
| 1849 GrReplacements::ReplacementInfo* layerInfo = replacements->push(); |
| 1850 layerInfo->fStart = layers[i]->start(); |
| 1851 layerInfo->fStop = layers[i]->stop(); |
| 1852 layerInfo->fPos = layers[i]->offset();; |
| 1853 |
| 1854 SkBitmap bm; |
| 1855 wrap_texture(layers[i]->texture(), |
| 1856 !layers[i]->isAtlased() ? layers[i]->rect().width() |
| 1857 : layers[i]->texture()->width(), |
| 1858 !layers[i]->isAtlased() ? layers[i]->rect().height() |
| 1859 : layers[i]->texture()->height(), |
| 1860 &bm); |
| 1861 layerInfo->fImage = SkImage::NewTexture(bm); |
| 1862 |
| 1863 // TODO: copy this? |
| 1864 layerInfo->fPaint = layers[i]->paint(); |
| 1865 |
| 1866 layerInfo->fSrcRect = SkIRect::MakeXYWH(layers[i]->rect().fLeft, |
| 1867 layers[i]->rect().fTop, |
| 1868 layers[i]->rect().width(), |
| 1869 layers[i]->rect().height()); |
| 1870 } |
| 1871 } |
| 1872 |
| 1845 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
* picture, | 1873 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
* picture, |
| 1846 const SkMatrix* matrix, const SkPaint
* paint) { | 1874 const SkMatrix* matrix, const SkPaint
* paint) { |
| 1847 // todo: should handle these natively | 1875 // todo: should handle these natively |
| 1848 if (matrix || paint) { | 1876 if (matrix || paint) { |
| 1849 return false; | 1877 return false; |
| 1850 } | 1878 } |
| 1851 | 1879 |
| 1852 fContext->getLayerCache()->processDeletedPictures(); | 1880 fContext->getLayerCache()->processDeletedPictures(); |
| 1853 | 1881 |
| 1854 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); | 1882 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1868 | 1896 |
| 1869 SkRect clipBounds; | 1897 SkRect clipBounds; |
| 1870 if (!mainCanvas->getClipBounds(&clipBounds)) { | 1898 if (!mainCanvas->getClipBounds(&clipBounds)) { |
| 1871 return true; | 1899 return true; |
| 1872 } | 1900 } |
| 1873 | 1901 |
| 1874 if (!GrLayerHoister::FindLayersToHoist(gpuData, clipBounds, pullForward.get(
))) { | 1902 if (!GrLayerHoister::FindLayersToHoist(gpuData, clipBounds, pullForward.get(
))) { |
| 1875 return false; | 1903 return false; |
| 1876 } | 1904 } |
| 1877 | 1905 |
| 1878 GrReplacements replacements; | |
| 1879 | |
| 1880 SkTDArray<GrCachedLayer*> atlased, nonAtlased; | 1906 SkTDArray<GrCachedLayer*> atlased, nonAtlased; |
| 1881 atlased.setReserve(gpuData->numSaveLayers()); | 1907 atlased.setReserve(gpuData->numSaveLayers()); |
| 1882 | 1908 |
| 1883 // Generate the layer and/or ensure it is locked | 1909 // Generate the layer and/or ensure it is locked |
| 1884 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 1910 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
| 1885 if (pullForward[i]) { | 1911 if (pullForward[i]) { |
| 1886 const GrAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); | 1912 const GrAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); |
| 1887 | 1913 |
| 1888 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(
picture->uniqueID(), | 1914 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(
picture->uniqueID(), |
| 1889
info.fSaveLayerOpID, | 1915
info.fSaveLayerOpID, |
| 1890
info.fRestoreOpID, | 1916
info.fRestoreOpID, |
| 1891
info.fOffset, | 1917
info.fOffset, |
| 1892
info.fOriginXform); | 1918
info.fOriginXform, |
| 1893 | 1919
info.fPaint); |
| 1894 GrReplacements::ReplacementInfo* layerInfo = replacements.push(); | |
| 1895 layerInfo->fStart = info.fSaveLayerOpID; | |
| 1896 layerInfo->fStop = info.fRestoreOpID; | |
| 1897 layerInfo->fPos = info.fOffset; | |
| 1898 | 1920 |
| 1899 GrTextureDesc desc; | 1921 GrTextureDesc desc; |
| 1900 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 1922 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1901 desc.fWidth = info.fSize.fWidth; | 1923 desc.fWidth = info.fSize.fWidth; |
| 1902 desc.fHeight = info.fSize.fHeight; | 1924 desc.fHeight = info.fSize.fHeight; |
| 1903 desc.fConfig = kSkia8888_GrPixelConfig; | 1925 desc.fConfig = kSkia8888_GrPixelConfig; |
| 1904 // TODO: need to deal with sample count | 1926 // TODO: need to deal with sample count |
| 1905 | 1927 |
| 1906 bool needsRendering = fContext->getLayerCache()->lock(layer, desc, | 1928 bool needsRendering = fContext->getLayerCache()->lock(layer, desc, |
| 1907 info.fHasNestedLayers || inf
o.fIsNested); | 1929 info.fHasNestedLayers || inf
o.fIsNested); |
| 1908 if (NULL == layer->texture()) { | 1930 if (NULL == layer->texture()) { |
| 1909 continue; | 1931 continue; |
| 1910 } | 1932 } |
| 1911 | 1933 |
| 1912 SkBitmap bm; | |
| 1913 wrap_texture(layer->texture(), | |
| 1914 !layer->isAtlased() ? desc.fWidth : layer->texture()->w
idth(), | |
| 1915 !layer->isAtlased() ? desc.fHeight : layer->texture()->
height(), | |
| 1916 &bm); | |
| 1917 layerInfo->fImage = SkImage::NewTexture(bm); | |
| 1918 | |
| 1919 SkASSERT(info.fPaint); | |
| 1920 layerInfo->fPaint = info.fPaint; | |
| 1921 | |
| 1922 layerInfo->fSrcRect = SkIRect::MakeXYWH(layer->rect().fLeft, | |
| 1923 layer->rect().fTop, | |
| 1924 layer->rect().width(), | |
| 1925 layer->rect().height()); | |
| 1926 | |
| 1927 if (needsRendering) { | 1934 if (needsRendering) { |
| 1928 if (layer->isAtlased()) { | 1935 if (layer->isAtlased()) { |
| 1929 *atlased.append() = layer; | 1936 *atlased.append() = layer; |
| 1930 } else { | 1937 } else { |
| 1931 *nonAtlased.append() = layer; | 1938 *nonAtlased.append() = layer; |
| 1932 } | 1939 } |
| 1933 } | 1940 } |
| 1934 } | 1941 } |
| 1935 } | 1942 } |
| 1936 | 1943 |
| 1937 GrLayerHoister::DrawLayers(picture, atlased, nonAtlased); | 1944 GrLayerHoister::DrawLayers(picture, atlased, nonAtlased); |
| 1938 | 1945 |
| 1946 GrReplacements replacements; |
| 1947 |
| 1948 convert_layers_to_replacements(atlased, &replacements); |
| 1949 convert_layers_to_replacements(nonAtlased, &replacements); |
| 1950 |
| 1939 // Render the entire picture using new layers | 1951 // Render the entire picture using new layers |
| 1940 GrRecordReplaceDraw(*picture->fRecord, mainCanvas, picture->fBBH.get(), &rep
lacements, NULL); | 1952 GrRecordReplaceDraw(*picture->fRecord, mainCanvas, picture->fBBH.get(), &rep
lacements, NULL); |
| 1941 | 1953 |
| 1942 GrLayerHoister::UnlockLayers(fContext->getLayerCache(), picture); | 1954 GrLayerHoister::UnlockLayers(fContext->getLayerCache(), picture); |
| 1943 | 1955 |
| 1944 return true; | 1956 return true; |
| 1945 } | 1957 } |
| 1946 | 1958 |
| 1947 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1959 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 1948 // We always return a transient cache, so it is freed after each | 1960 // We always return a transient cache, so it is freed after each |
| 1949 // filter traversal. | 1961 // filter traversal. |
| 1950 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1962 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 1951 } | 1963 } |
| OLD | NEW |