Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Side by Side Diff: src/gpu/SkGpuDevice.cpp

Issue 354533004: Begin atlasing (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix unit test Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 1840 fContext->getLayerCache()->purge(picture);
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
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->getTexture()) { 1966 if (NULL == layer->texture()) {
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->getTexture(), desc.fWidth, desc.fHeight, layerIn fo->fBM); 1971 wrap_texture(layer->texture(),
1972 layer->rect().isEmpty() ? desc.fWidth : layer->texture( )->width(),
1973 layer->rect().isEmpty() ? desc.fHeight : layer->texture ()->height(),
1974 layerInfo->fBM);
1972 1975
1973 SkASSERT(info.fPaint); 1976 SkASSERT(info.fPaint);
1974 layerInfo->fPaint = info.fPaint; 1977 layerInfo->fPaint = info.fPaint;
1975 1978
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
1976 if (needsRendering) { 1988 if (needsRendering) {
1989 static const bool kDontClearCreatedSurface = false;
1977 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect ( 1990 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect (
1978 layer->getTexture()->asRende rTarget())); 1991 layer->texture()->asRenderTa rget(),
1992 SkSurface::kStandard_TextRen derMode,
1993 kDontClearCreatedSurface));
1979 1994
1980 SkCanvas* canvas = surface->getCanvas(); 1995 SkCanvas* canvas = surface->getCanvas();
1981 1996
1997 if (!layer->rect().isEmpty()) {
1998 // Add a rect clip to make sure the rendering doesn't
1999 // extend beyond the boundaries of the atlased sub-rect
2000 SkRect bound = SkRect::MakeXYWH(SkIntToScalar(layer->rect(). fLeft),
2001 SkIntToScalar(layer->rect(). fTop),
2002 SkIntToScalar(layer->rect(). width()),
2003 SkIntToScalar(layer->rect(). height()));
2004 canvas->clipRect(bound);
2005 // Since 'clear' doesn't respect the clip we need to draw a rect
2006 // TODO: ensure none of the atlased layers contain a clear c all!
2007 SkPaint paint;
2008 paint.setColor(SK_ColorTRANSPARENT);
2009 canvas->drawRect(bound, paint);
2010 } else {
2011 canvas->clear(SK_ColorTRANSPARENT);
2012 }
2013
1982 canvas->setMatrix(info.fCTM); 2014 canvas->setMatrix(info.fCTM);
1983 canvas->clear(SK_ColorTRANSPARENT); 2015
2016 if (!layer->rect().isEmpty()) {
2017 // info.fCTM maps the layer's top/left to the origin.
2018 // Since this layer is atlased the top/left corner needs
2019 // to be offset to some arbitrary location in the backing
2020 // texture.
2021 canvas->translate(SkIntToScalar(layer->rect().fLeft),
2022 SkIntToScalar(layer->rect().fTop));
2023 }
1984 2024
1985 picture->fPlayback->setDrawLimits(info.fSaveLayerOpID, info.fRes toreOpID); 2025 picture->fPlayback->setDrawLimits(info.fSaveLayerOpID, info.fRes toreOpID);
1986 picture->fPlayback->draw(*canvas, NULL); 2026 picture->fPlayback->draw(*canvas, NULL);
1987 picture->fPlayback->setDrawLimits(0, 0); 2027 picture->fPlayback->setDrawLimits(0, 0);
2028
1988 canvas->flush(); 2029 canvas->flush();
1989 } 2030 }
1990 } 2031 }
1991 } 2032 }
1992 2033
1993 // Playback using new layers 2034 // Playback using new layers
1994 picture->fPlayback->setReplacements(&replacements); 2035 picture->fPlayback->setReplacements(&replacements);
1995 picture->fPlayback->draw(*canvas, NULL); 2036 picture->fPlayback->draw(*canvas, NULL);
1996 picture->fPlayback->setReplacements(NULL); 2037 picture->fPlayback->setReplacements(NULL);
1997 2038
1998 // unlock the layers 2039 // unlock the layers
1999 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { 2040 for (int i = 0; i < gpuData->numSaveLayers(); ++i) {
2000 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); 2041 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i);
2001 fContext->getLayerCache()->unlock(layer); 2042 fContext->getLayerCache()->unlock(layer);
2002 } 2043 }
2003 2044
2004 return true; 2045 return true;
2005 } 2046 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698