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 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1818 GatherGPUInfo(picture, data); | 1818 GatherGPUInfo(picture, data); |
1819 } | 1819 } |
1820 | 1820 |
1821 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { | 1821 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { |
1822 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 1822 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
1823 result->setInfo(info); | 1823 result->setInfo(info); |
1824 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 1824 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
1825 } | 1825 } |
1826 | 1826 |
1827 void SkGpuDevice::EXPERIMENTAL_purge(const SkPicture* picture) { | 1827 void SkGpuDevice::EXPERIMENTAL_purge(const SkPicture* picture) { |
1828 | 1828 fContext->getLayerCache()->purge(picture); |
1829 } | 1829 } |
1830 | 1830 |
1831 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* canvas, const SkPicture* pi
cture) { | 1831 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* canvas, const SkPicture* pi
cture) { |
1832 | 1832 |
1833 if (NULL == picture->fPlayback.get()) { | 1833 if (NULL == picture->fPlayback.get()) { |
1834 return false; | 1834 return false; |
1835 } | 1835 } |
1836 | 1836 |
1837 SkPicture::AccelData::Key key = GPUAccelData::ComputeAccelDataKey(); | 1837 SkPicture::AccelData::Key key = GPUAccelData::ComputeAccelDataKey(); |
1838 | 1838 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1944 layerInfo->fPos = info.fOffset; | 1944 layerInfo->fPos = info.fOffset; |
1945 | 1945 |
1946 GrTextureDesc desc; | 1946 GrTextureDesc desc; |
1947 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 1947 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
1948 desc.fWidth = info.fSize.fWidth; | 1948 desc.fWidth = info.fSize.fWidth; |
1949 desc.fHeight = info.fSize.fHeight; | 1949 desc.fHeight = info.fSize.fHeight; |
1950 desc.fConfig = kSkia8888_GrPixelConfig; | 1950 desc.fConfig = kSkia8888_GrPixelConfig; |
1951 // TODO: need to deal with sample count | 1951 // TODO: need to deal with sample count |
1952 | 1952 |
1953 bool needsRendering = !fContext->getLayerCache()->lock(layer, desc); | 1953 bool needsRendering = !fContext->getLayerCache()->lock(layer, desc); |
1954 if (NULL == layer->getTexture()) { | 1954 if (NULL == layer->texture()) { |
1955 continue; | 1955 continue; |
1956 } | 1956 } |
1957 | 1957 |
1958 layerInfo->fBM = SkNEW(SkBitmap); // fBM is allocated so Replacemen
tInfo can be POD | 1958 layerInfo->fBM = SkNEW(SkBitmap); // fBM is allocated so Replacemen
tInfo can be POD |
1959 wrap_texture(layer->getTexture(), desc.fWidth, desc.fHeight, layerIn
fo->fBM); | 1959 wrap_texture(layer->texture(), |
| 1960 layer->rect().isEmpty() ? desc.fWidth : layer->texture(
)->width(), |
| 1961 layer->rect().isEmpty() ? desc.fHeight : layer->texture
()->height(), |
| 1962 layerInfo->fBM); |
1960 | 1963 |
1961 SkASSERT(info.fPaint); | 1964 SkASSERT(info.fPaint); |
1962 layerInfo->fPaint = info.fPaint; | 1965 layerInfo->fPaint = info.fPaint; |
1963 | 1966 |
| 1967 if (layer->rect().isEmpty()) { |
| 1968 layerInfo->fSrcRect = SkIRect::MakeWH(desc.fWidth, desc.fHeight)
; |
| 1969 } else { |
| 1970 layerInfo->fSrcRect = SkIRect::MakeXYWH(layer->rect().fLeft, |
| 1971 layer->rect().fTop, |
| 1972 layer->rect().width(), |
| 1973 layer->rect().height()); |
| 1974 } |
| 1975 |
1964 if (needsRendering) { | 1976 if (needsRendering) { |
1965 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect
( | 1977 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect
( |
1966 layer->getTexture()->asRende
rTarget())); | 1978 layer->texture()->asRenderTa
rget(), |
| 1979 SkSurface::kStandard_TextRen
derMode, |
| 1980 SkSurface::kDontClear_Render
TargetFlag)); |
1967 | 1981 |
1968 SkCanvas* canvas = surface->getCanvas(); | 1982 SkCanvas* canvas = surface->getCanvas(); |
1969 | 1983 |
| 1984 if (!layer->rect().isEmpty()) { |
| 1985 // Add a rect clip to make sure the rendering doesn't |
| 1986 // extend beyond the boundaries of the atlased sub-rect |
| 1987 SkRect bound = SkRect::MakeXYWH(SkIntToScalar(layer->rect().
fLeft), |
| 1988 SkIntToScalar(layer->rect().
fTop), |
| 1989 SkIntToScalar(layer->rect().
width()), |
| 1990 SkIntToScalar(layer->rect().
height())); |
| 1991 canvas->clipRect(bound); |
| 1992 // Since 'clear' doesn't respect the clip we need to draw a
rect |
| 1993 // TODO: ensure none of the atlased layers contain a clear c
all! |
| 1994 SkPaint paint; |
| 1995 paint.setColor(SK_ColorTRANSPARENT); |
| 1996 canvas->drawRect(bound, paint); |
| 1997 } else { |
| 1998 canvas->clear(SK_ColorTRANSPARENT); |
| 1999 } |
| 2000 |
1970 canvas->setMatrix(info.fCTM); | 2001 canvas->setMatrix(info.fCTM); |
1971 canvas->clear(SK_ColorTRANSPARENT); | 2002 |
| 2003 if (!layer->rect().isEmpty()) { |
| 2004 // info.fCTM maps the layer's top/left to the origin. |
| 2005 // Since this layer is atlased the top/left corner needs |
| 2006 // to be offset to some arbitrary location in the backing |
| 2007 // texture. |
| 2008 canvas->translate(SkIntToScalar(layer->rect().fLeft), |
| 2009 SkIntToScalar(layer->rect().fTop)); |
| 2010 } |
1972 | 2011 |
1973 picture->fPlayback->setDrawLimits(info.fSaveLayerOpID, info.fRes
toreOpID); | 2012 picture->fPlayback->setDrawLimits(info.fSaveLayerOpID, info.fRes
toreOpID); |
1974 picture->fPlayback->draw(*canvas, NULL); | 2013 picture->fPlayback->draw(*canvas, NULL); |
1975 picture->fPlayback->setDrawLimits(0, 0); | 2014 picture->fPlayback->setDrawLimits(0, 0); |
| 2015 |
1976 canvas->flush(); | 2016 canvas->flush(); |
1977 } | 2017 } |
1978 } | 2018 } |
1979 } | 2019 } |
1980 | 2020 |
1981 // Playback using new layers | 2021 // Playback using new layers |
1982 picture->fPlayback->setReplacements(&replacements); | 2022 picture->fPlayback->setReplacements(&replacements); |
1983 picture->fPlayback->draw(*canvas, NULL); | 2023 picture->fPlayback->draw(*canvas, NULL); |
1984 picture->fPlayback->setReplacements(NULL); | 2024 picture->fPlayback->setReplacements(NULL); |
1985 | 2025 |
1986 // unlock the layers | 2026 // unlock the layers |
1987 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 2027 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
1988 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); | 2028 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); |
1989 fContext->getLayerCache()->unlock(layer); | 2029 fContext->getLayerCache()->unlock(layer); |
1990 } | 2030 } |
1991 | 2031 |
1992 return true; | 2032 return true; |
1993 } | 2033 } |
OLD | NEW |