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