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