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

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

Issue 611383003: Revert of GrResourceCache2 manages scratch texture. (Closed) Base URL: https://skia.googlesource.com/skia.git@surfimpl
Patch Set: Created 6 years, 2 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
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } \ 69 } \
70 } while (false) \ 70 } while (false) \
71 71
72 /////////////////////////////////////////////////////////////////////////////// 72 ///////////////////////////////////////////////////////////////////////////////
73 73
74 #define CHECK_FOR_ANNOTATION(paint) \ 74 #define CHECK_FOR_ANNOTATION(paint) \
75 do { if (paint.getAnnotation()) { return; } } while (0) 75 do { if (paint.getAnnotation()) { return; } } while (0)
76 76
77 /////////////////////////////////////////////////////////////////////////////// 77 ///////////////////////////////////////////////////////////////////////////////
78 78
79 // Helper for turning a bitmap into a texture. If the bitmap is GrTexture backed this 79
80 // just accesses the backing GrTexture. Otherwise, it creates a cached texture 80 class SkGpuDevice::SkAutoCachedTexture : public ::SkNoncopyable {
81 // representation and releases it in the destructor.
82 class AutoBitmapTexture : public SkNoncopyable {
83 public: 81 public:
84 AutoBitmapTexture() {} 82 SkAutoCachedTexture()
85 83 : fDevice(NULL)
86 AutoBitmapTexture(GrContext* context, 84 , fTexture(NULL) {
87 const SkBitmap& bitmap,
88 const GrTextureParams* params,
89 GrTexture** texture) {
90 SkASSERT(texture);
91 *texture = this->set(context, bitmap, params);
92 } 85 }
93 86
94 GrTexture* set(GrContext* context, 87 SkAutoCachedTexture(SkGpuDevice* device,
95 const SkBitmap& bitmap, 88 const SkBitmap& bitmap,
96 const GrTextureParams* params) { 89 const GrTextureParams* params,
97 // Either get the texture directly from the bitmap, or else use the cach e and 90 GrTexture** texture)
98 // remember to unref it. 91 : fDevice(NULL)
99 if (GrTexture* bmpTexture = bitmap.getTexture()) { 92 , fTexture(NULL) {
100 fTexture.reset(NULL); 93 SkASSERT(texture);
101 return bmpTexture; 94 *texture = this->set(device, bitmap, params);
102 } else { 95 }
103 fTexture.reset(GrRefCachedBitmapTexture(context, bitmap, params)); 96
104 return fTexture.get(); 97 ~SkAutoCachedTexture() {
98 if (fTexture) {
99 GrUnlockAndUnrefCachedBitmapTexture(fTexture);
105 } 100 }
106 } 101 }
107 102
103 GrTexture* set(SkGpuDevice* device,
104 const SkBitmap& bitmap,
105 const GrTextureParams* params) {
106 if (fTexture) {
107 GrUnlockAndUnrefCachedBitmapTexture(fTexture);
108 fTexture = NULL;
109 }
110 fDevice = device;
111 GrTexture* result = (GrTexture*)bitmap.getTexture();
112 if (NULL == result) {
113 // Cannot return the native texture so look it up in our cache
114 fTexture = GrLockAndRefCachedBitmapTexture(device->context(), bitmap , params);
115 result = fTexture;
116 }
117 return result;
118 }
119
108 private: 120 private:
109 SkAutoTUnref<GrTexture> fTexture; 121 SkGpuDevice* fDevice;
122 GrTexture* fTexture;
110 }; 123 };
111 124
112 /////////////////////////////////////////////////////////////////////////////// 125 ///////////////////////////////////////////////////////////////////////////////
113 126
114 struct GrSkDrawProcs : public SkDrawProcs { 127 struct GrSkDrawProcs : public SkDrawProcs {
115 public: 128 public:
116 GrContext* fContext; 129 GrContext* fContext;
117 GrTextContext* fTextContext; 130 GrTextContext* fTextContext;
118 GrFontScaler* fFontScaler; // cached in the skia glyphcache 131 GrFontScaler* fFontScaler; // cached in the skia glyphcache
119 }; 132 };
(...skipping 12 matching lines...) Expand all
132 145
133 fDrawProcs = NULL; 146 fDrawProcs = NULL;
134 147
135 fContext = SkRef(surface->getContext()); 148 fContext = SkRef(surface->getContext());
136 149
137 fNeedClear = flags & kNeedClear_Flag; 150 fNeedClear = flags & kNeedClear_Flag;
138 151
139 fRenderTarget = SkRef(surface->asRenderTarget()); 152 fRenderTarget = SkRef(surface->asRenderTarget());
140 153
141 SkImageInfo info = surface->surfacePriv().info(); 154 SkImageInfo info = surface->surfacePriv().info();
142 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface)); 155 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef,
156 (info, surface, SkToBool(flags & kCached_Flag))) ;
143 fLegacyBitmap.setInfo(info); 157 fLegacyBitmap.setInfo(info);
144 fLegacyBitmap.setPixelRef(pr)->unref(); 158 fLegacyBitmap.setPixelRef(pr)->unref();
145 159
146 this->setPixelGeometry(props.pixelGeometry()); 160 this->setPixelGeometry(props.pixelGeometry());
147 161
148 bool useDFFonts = !!(flags & kDFFonts_Flag); 162 bool useDFFonts = !!(flags & kDFFonts_Flag);
149 fMainTextContext = fContext->createTextContext(fRenderTarget, this->getLeaky Properties(), useDFFonts); 163 fMainTextContext = fContext->createTextContext(fRenderTarget, this->getLeaky Properties(), useDFFonts);
150 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, this->getL eakyProperties())); 164 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, this->getL eakyProperties()));
151 } 165 }
152 166
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 const SkRect& srcRect, 1287 const SkRect& srcRect,
1274 const GrTextureParams& params, 1288 const GrTextureParams& params,
1275 const SkPaint& paint, 1289 const SkPaint& paint,
1276 SkCanvas::DrawBitmapRectFlags flags, 1290 SkCanvas::DrawBitmapRectFlags flags,
1277 bool bicubic, 1291 bool bicubic,
1278 bool needsTextureDomain) { 1292 bool needsTextureDomain) {
1279 SkASSERT(bitmap.width() <= fContext->getMaxTextureSize() && 1293 SkASSERT(bitmap.width() <= fContext->getMaxTextureSize() &&
1280 bitmap.height() <= fContext->getMaxTextureSize()); 1294 bitmap.height() <= fContext->getMaxTextureSize());
1281 1295
1282 GrTexture* texture; 1296 GrTexture* texture;
1283 AutoBitmapTexture abt(fContext, bitmap, &params, &texture); 1297 SkAutoCachedTexture act(this, bitmap, &params, &texture);
1284 if (NULL == texture) { 1298 if (NULL == texture) {
1285 return; 1299 return;
1286 } 1300 }
1287 1301
1288 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() }; 1302 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() };
1289 SkRect paintRect; 1303 SkRect paintRect;
1290 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); 1304 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width()));
1291 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); 1305 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height()));
1292 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), 1306 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv),
1293 SkScalarMul(srcRect.fTop, hInv), 1307 SkScalarMul(srcRect.fTop, hInv),
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 SkAutoLockPixels alp(bitmap, !bitmap.getTexture()); 1382 SkAutoLockPixels alp(bitmap, !bitmap.getTexture());
1369 if (!bitmap.getTexture() && !bitmap.readyToDraw()) { 1383 if (!bitmap.getTexture() && !bitmap.readyToDraw()) {
1370 return; 1384 return;
1371 } 1385 }
1372 1386
1373 int w = bitmap.width(); 1387 int w = bitmap.width();
1374 int h = bitmap.height(); 1388 int h = bitmap.height();
1375 1389
1376 GrTexture* texture; 1390 GrTexture* texture;
1377 // draw sprite uses the default texture params 1391 // draw sprite uses the default texture params
1378 AutoBitmapTexture abt(fContext, bitmap, NULL, &texture); 1392 SkAutoCachedTexture act(this, bitmap, NULL, &texture);
1379 1393
1380 SkImageFilter* filter = paint.getImageFilter(); 1394 SkImageFilter* filter = paint.getImageFilter();
1381 // This bitmap will own the filtered result as a texture. 1395 // This bitmap will own the filtered result as a texture.
1382 SkBitmap filteredBitmap; 1396 SkBitmap filteredBitmap;
1383 1397
1384 if (filter) { 1398 if (filter) {
1385 SkIPoint offset = SkIPoint::Make(0, 0); 1399 SkIPoint offset = SkIPoint::Make(0, 0);
1386 SkMatrix matrix(*draw.fMatrix); 1400 SkMatrix matrix(*draw.fMatrix);
1387 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); 1401 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top));
1388 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); 1402 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height());
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 } 1559 }
1546 1560
1547 SkAutoLockPixels alp(src, !src.getTexture()); 1561 SkAutoLockPixels alp(src, !src.getTexture());
1548 if (!src.getTexture() && !src.readyToDraw()) { 1562 if (!src.getTexture() && !src.readyToDraw()) {
1549 return false; 1563 return false;
1550 } 1564 }
1551 1565
1552 GrTexture* texture; 1566 GrTexture* texture;
1553 // We assume here that the filter will not attempt to tile the src. Otherwis e, this cache lookup 1567 // We assume here that the filter will not attempt to tile the src. Otherwis e, this cache lookup
1554 // must be pushed upstack. 1568 // must be pushed upstack.
1555 AutoBitmapTexture abt(fContext, src, NULL, &texture); 1569 SkAutoCachedTexture act(this, src, NULL, &texture);
1556 1570
1557 return filter_texture(this, fContext, texture, filter, src.width(), src.heig ht(), ctx, 1571 return filter_texture(this, fContext, texture, filter, src.width(), src.heig ht(), ctx,
1558 result, offset); 1572 result, offset);
1559 } 1573 }
1560 1574
1561 /////////////////////////////////////////////////////////////////////////////// 1575 ///////////////////////////////////////////////////////////////////////////////
1562 1576
1563 // must be in SkCanvas::VertexMode order 1577 // must be in SkCanvas::VertexMode order
1564 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { 1578 static const GrPrimitiveType gVertexMode2PrimitiveType[] = {
1565 kTriangles_GrPrimitiveType, 1579 kTriangles_GrPrimitiveType,
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 desc.fHeight = info.height(); 1790 desc.fHeight = info.height();
1777 desc.fSampleCnt = fRenderTarget->numSamples(); 1791 desc.fSampleCnt = fRenderTarget->numSamples();
1778 1792
1779 SkAutoTUnref<GrTexture> texture; 1793 SkAutoTUnref<GrTexture> texture;
1780 // Skia's convention is to only clear a device if it is non-opaque. 1794 // Skia's convention is to only clear a device if it is non-opaque.
1781 unsigned flags = info.isOpaque() ? 0 : kNeedClear_Flag; 1795 unsigned flags = info.isOpaque() ? 0 : kNeedClear_Flag;
1782 1796
1783 #if CACHE_COMPATIBLE_DEVICE_TEXTURES 1797 #if CACHE_COMPATIBLE_DEVICE_TEXTURES
1784 // layers are never draw in repeat modes, so we can request an approx 1798 // layers are never draw in repeat modes, so we can request an approx
1785 // match and ignore any padding. 1799 // match and ignore any padding.
1800 flags |= kCached_Flag;
1786 const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == usage) ? 1801 const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == usage) ?
1787 GrContext::kApprox_ScratchTexMat ch : 1802 GrContext::kApprox_ScratchTexMat ch :
1788 GrContext::kExact_ScratchTexMatc h; 1803 GrContext::kExact_ScratchTexMatc h;
1789 texture.reset(fContext->lockAndRefScratchTexture(desc, match)); 1804 texture.reset(fContext->lockAndRefScratchTexture(desc, match));
1790 #else 1805 #else
1791 texture.reset(fContext->createUncachedTexture(desc, NULL, 0)); 1806 texture.reset(fContext->createUncachedTexture(desc, NULL, 0));
1792 #endif 1807 #endif
1793 if (texture.get()) { 1808 if (texture.get()) {
1794 return SkGpuDevice::Create(texture, SkSurfaceProps(SkSurfaceProps::kLega cyFontHost_InitType), flags); 1809 return SkGpuDevice::Create(texture, SkSurfaceProps(SkSurfaceProps::kLega cyFontHost_InitType), flags);
1795 } else { 1810 } else {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 GrLayerHoister::UnlockLayers(fContext->getLayerCache(), atlased, nonAtlased) ; 1870 GrLayerHoister::UnlockLayers(fContext->getLayerCache(), atlased, nonAtlased) ;
1856 1871
1857 return true; 1872 return true;
1858 } 1873 }
1859 1874
1860 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { 1875 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
1861 // We always return a transient cache, so it is freed after each 1876 // We always return a transient cache, so it is freed after each
1862 // filter traversal. 1877 // filter traversal.
1863 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); 1878 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
1864 } 1879 }
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698