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 "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // Helper for turning a bitmap into a texture. If the bitmap is GrTexture backed
this | 73 // Helper for turning a bitmap into a texture. If the bitmap is GrTexture backed
this |
74 // just accesses the backing GrTexture. Otherwise, it creates a cached texture | 74 // just accesses the backing GrTexture. Otherwise, it creates a cached texture |
75 // representation and releases it in the destructor. | 75 // representation and releases it in the destructor. |
76 class AutoBitmapTexture : public SkNoncopyable { | 76 class AutoBitmapTexture : public SkNoncopyable { |
77 public: | 77 public: |
78 AutoBitmapTexture() {} | 78 AutoBitmapTexture() {} |
79 | 79 |
80 AutoBitmapTexture(GrContext* context, | 80 AutoBitmapTexture(GrContext* context, |
81 const SkBitmap& bitmap, | 81 const SkBitmap& bitmap, |
82 const GrTextureParams& params, | 82 const GrTextureParams& params, |
| 83 bool gammaCorrect, |
83 GrTexture** texture) { | 84 GrTexture** texture) { |
84 SkASSERT(texture); | 85 SkASSERT(texture); |
85 *texture = this->set(context, bitmap, params); | 86 *texture = this->set(context, bitmap, params, gammaCorrect); |
86 } | 87 } |
87 | 88 |
88 GrTexture* set(GrContext* context, | 89 GrTexture* set(GrContext* context, |
89 const SkBitmap& bitmap, | 90 const SkBitmap& bitmap, |
90 const GrTextureParams& params) { | 91 const GrTextureParams& params, |
| 92 bool gammaCorrect) { |
91 // Either get the texture directly from the bitmap, or else use the cach
e and | 93 // Either get the texture directly from the bitmap, or else use the cach
e and |
92 // remember to unref it. | 94 // remember to unref it. |
93 if (GrTexture* bmpTexture = bitmap.getTexture()) { | 95 if (GrTexture* bmpTexture = bitmap.getTexture()) { |
94 fTexture.reset(nullptr); | 96 fTexture.reset(nullptr); |
95 return bmpTexture; | 97 return bmpTexture; |
96 } else { | 98 } else { |
97 fTexture.reset(GrRefCachedBitmapTexture(context, bitmap, params)); | 99 fTexture.reset(GrRefCachedBitmapTexture(context, bitmap, params, gam
maCorrect)); |
98 return fTexture.get(); | 100 return fTexture.get(); |
99 } | 101 } |
100 } | 102 } |
101 | 103 |
102 private: | 104 private: |
103 SkAutoTUnref<GrTexture> fTexture; | 105 SkAutoTUnref<GrTexture> fTexture; |
104 }; | 106 }; |
105 | 107 |
106 /////////////////////////////////////////////////////////////////////////////// | 108 /////////////////////////////////////////////////////////////////////////////// |
107 | 109 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 return; | 255 return; |
254 } | 256 } |
255 | 257 |
256 SkAutoLockPixels alp(bitmap, !bitmap.getTexture()); | 258 SkAutoLockPixels alp(bitmap, !bitmap.getTexture()); |
257 if (!bitmap.getTexture() && !bitmap.readyToDraw()) { | 259 if (!bitmap.getTexture() && !bitmap.readyToDraw()) { |
258 return; | 260 return; |
259 } | 261 } |
260 | 262 |
261 GrTexture* texture; | 263 GrTexture* texture; |
262 // draw sprite neither filters nor tiles. | 264 // draw sprite neither filters nor tiles. |
263 AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), &t
exture); | 265 AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), fa
lse, &texture); |
264 if (!texture) { | 266 if (!texture) { |
265 return; | 267 return; |
266 } | 268 } |
267 | 269 |
268 SkBitmap newBitmap; | 270 SkBitmap newBitmap; |
269 | 271 |
270 GrWrapTextureInBitmap(texture, texture->width(), texture->height(), | 272 GrWrapTextureInBitmap(texture, texture->width(), texture->height(), |
271 bitmap.isOpaque(), &newBitmap); | 273 bitmap.isOpaque(), &newBitmap); |
272 | 274 |
273 INHERITED::drawSpriteWithFilter(draw, newBitmap, x, y, paint); | 275 INHERITED::drawSpriteWithFilter(draw, newBitmap, x, y, paint); |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 // We should have already handled bitmaps larger than the max texture size. | 1160 // We should have already handled bitmaps larger than the max texture size. |
1159 SkASSERT(bitmap.width() <= fContext->caps()->maxTextureSize() && | 1161 SkASSERT(bitmap.width() <= fContext->caps()->maxTextureSize() && |
1160 bitmap.height() <= fContext->caps()->maxTextureSize()); | 1162 bitmap.height() <= fContext->caps()->maxTextureSize()); |
1161 // Unless the bitmap is inherently texture-backed, we should be respecting t
he max tile size | 1163 // Unless the bitmap is inherently texture-backed, we should be respecting t
he max tile size |
1162 // by the time we get here. | 1164 // by the time we get here. |
1163 SkASSERT(bitmap.getTexture() || | 1165 SkASSERT(bitmap.getTexture() || |
1164 (bitmap.width() <= fContext->caps()->maxTileSize() && | 1166 (bitmap.width() <= fContext->caps()->maxTileSize() && |
1165 bitmap.height() <= fContext->caps()->maxTileSize())); | 1167 bitmap.height() <= fContext->caps()->maxTileSize())); |
1166 | 1168 |
1167 GrTexture* texture; | 1169 GrTexture* texture; |
1168 AutoBitmapTexture abt(fContext, bitmap, params, &texture); | 1170 AutoBitmapTexture abt(fContext, bitmap, params, this->surfaceProps().isGamma
Correct(), |
| 1171 &texture); |
1169 if (nullptr == texture) { | 1172 if (nullptr == texture) { |
1170 return; | 1173 return; |
1171 } | 1174 } |
1172 | 1175 |
1173 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() }; | 1176 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() }; |
1174 SkRect paintRect; | 1177 SkRect paintRect; |
1175 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); | 1178 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); |
1176 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); | 1179 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); |
1177 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), | 1180 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), |
1178 SkScalarMul(srcRect.fTop, hInv), | 1181 SkScalarMul(srcRect.fTop, hInv), |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 return; | 1260 return; |
1258 } | 1261 } |
1259 | 1262 |
1260 int offX = bitmap.pixelRefOrigin().fX; | 1263 int offX = bitmap.pixelRefOrigin().fX; |
1261 int offY = bitmap.pixelRefOrigin().fY; | 1264 int offY = bitmap.pixelRefOrigin().fY; |
1262 int w = bitmap.width(); | 1265 int w = bitmap.width(); |
1263 int h = bitmap.height(); | 1266 int h = bitmap.height(); |
1264 | 1267 |
1265 GrTexture* texture; | 1268 GrTexture* texture; |
1266 // draw sprite neither filters nor tiles. | 1269 // draw sprite neither filters nor tiles. |
1267 AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), &t
exture); | 1270 AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), fa
lse, &texture); |
1268 if (!texture) { | 1271 if (!texture) { |
1269 return; | 1272 return; |
1270 } | 1273 } |
1271 | 1274 |
1272 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType(); | 1275 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType(); |
1273 | 1276 |
1274 SkASSERT(!paint.getImageFilter()); | 1277 SkASSERT(!paint.getImageFilter()); |
1275 | 1278 |
1276 GrPaint grPaint; | 1279 GrPaint grPaint; |
1277 SkAutoTUnref<const GrFragmentProcessor> fp( | 1280 SkAutoTUnref<const GrFragmentProcessor> fp( |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1513 | 1516 |
1514 SkRect srcR, dstR; | 1517 SkRect srcR, dstR; |
1515 while (iter.next(&srcR, &dstR)) { | 1518 while (iter.next(&srcR, &dstR)) { |
1516 this->drawTextureProducer(producer, &srcR, &dstR, SkCanvas::kStrict_
SrcRectConstraint, | 1519 this->drawTextureProducer(producer, &srcR, &dstR, SkCanvas::kStrict_
SrcRectConstraint, |
1517 *draw.fMatrix, fClip, paint); | 1520 *draw.fMatrix, fClip, paint); |
1518 } | 1521 } |
1519 return; | 1522 return; |
1520 } | 1523 } |
1521 | 1524 |
1522 static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_Filt
erMode; | 1525 static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_Filt
erMode; |
| 1526 bool gammaCorrect = this->surfaceProps().isGammaCorrect(); |
1523 SkAutoTUnref<const GrFragmentProcessor> fp( | 1527 SkAutoTUnref<const GrFragmentProcessor> fp( |
1524 producer->createFragmentProcessor(SkMatrix::I(), | 1528 producer->createFragmentProcessor(SkMatrix::I(), |
1525 SkRect::MakeIWH(producer->width(), pro
ducer->height()), | 1529 SkRect::MakeIWH(producer->width(), pro
ducer->height()), |
1526 GrTextureProducer::kNo_FilterConstrain
t, true, | 1530 GrTextureProducer::kNo_FilterConstrain
t, true, |
1527 &kMode)); | 1531 &kMode, gammaCorrect)); |
1528 GrPaint grPaint; | 1532 GrPaint grPaint; |
1529 if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, fp, | 1533 if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, fp, |
1530 producer->isAlphaOnly(), | 1534 producer->isAlphaOnly(), gammaCorrect, &grP
aint)) { |
1531 this->surfaceProps().isGammaCorrect(), &grP
aint)) { | |
1532 return; | 1535 return; |
1533 } | 1536 } |
1534 | 1537 |
1535 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, producer->width()
, | 1538 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, producer->width()
, |
1536 producer->height(), center, dst); | 1539 producer->height(), center, dst); |
1537 } | 1540 } |
1538 | 1541 |
1539 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, | 1542 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, |
1540 const SkIRect& center, const SkRect& dst, const
SkPaint& paint) { | 1543 const SkIRect& center, const SkRect& dst, const
SkPaint& paint) { |
1541 ASSERT_SINGLE_OWNER | 1544 ASSERT_SINGLE_OWNER |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1923 } | 1926 } |
1924 | 1927 |
1925 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1928 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
1926 ASSERT_SINGLE_OWNER | 1929 ASSERT_SINGLE_OWNER |
1927 // We always return a transient cache, so it is freed after each | 1930 // We always return a transient cache, so it is freed after each |
1928 // filter traversal. | 1931 // filter traversal. |
1929 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1932 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
1930 } | 1933 } |
1931 | 1934 |
1932 #endif | 1935 #endif |
OLD | NEW |