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

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

Issue 2037413002: Add SkSourceGammaTreatment enum so we know how to create mips (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix DM compilation Created 4 years, 6 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/GrTextureParamsAdjuster.cpp ('k') | src/gpu/SkGpuDevice_drawTexture.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 "GrBlurUtils.h" 10 #include "GrBlurUtils.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 SkSourceGammaTreatment gammaTreatment,
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, gammaTreatment);
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 SkSourceGammaTreatment gammaTreatment) {
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 maTreatment));
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
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(),
266 SkSourceGammaTreatment::kRespect, &texture);
264 if (!texture) { 267 if (!texture) {
265 return; 268 return;
266 } 269 }
267 270
268 SkBitmap newBitmap; 271 SkBitmap newBitmap;
269 272
270 GrWrapTextureInBitmap(texture, texture->width(), texture->height(), 273 GrWrapTextureInBitmap(texture, texture->width(), texture->height(),
271 bitmap.isOpaque(), &newBitmap); 274 bitmap.isOpaque(), &newBitmap);
272 275
273 INHERITED::drawSpriteWithFilter(draw, newBitmap, x, y, paint); 276 INHERITED::drawSpriteWithFilter(draw, newBitmap, x, y, paint);
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 // We should have already handled bitmaps larger than the max texture size. 1161 // We should have already handled bitmaps larger than the max texture size.
1159 SkASSERT(bitmap.width() <= fContext->caps()->maxTextureSize() && 1162 SkASSERT(bitmap.width() <= fContext->caps()->maxTextureSize() &&
1160 bitmap.height() <= fContext->caps()->maxTextureSize()); 1163 bitmap.height() <= fContext->caps()->maxTextureSize());
1161 // Unless the bitmap is inherently texture-backed, we should be respecting t he max tile size 1164 // Unless the bitmap is inherently texture-backed, we should be respecting t he max tile size
1162 // by the time we get here. 1165 // by the time we get here.
1163 SkASSERT(bitmap.getTexture() || 1166 SkASSERT(bitmap.getTexture() ||
1164 (bitmap.width() <= fContext->caps()->maxTileSize() && 1167 (bitmap.width() <= fContext->caps()->maxTileSize() &&
1165 bitmap.height() <= fContext->caps()->maxTileSize())); 1168 bitmap.height() <= fContext->caps()->maxTileSize()));
1166 1169
1167 GrTexture* texture; 1170 GrTexture* texture;
1168 AutoBitmapTexture abt(fContext, bitmap, params, &texture); 1171 SkSourceGammaTreatment gammaTreatment = this->surfaceProps().isGammaCorrect( )
1172 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
1173 AutoBitmapTexture abt(fContext, bitmap, params, gammaTreatment, &texture);
1169 if (nullptr == texture) { 1174 if (nullptr == texture) {
1170 return; 1175 return;
1171 } 1176 }
1172 1177
1173 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() }; 1178 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() };
1174 SkRect paintRect; 1179 SkRect paintRect;
1175 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); 1180 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width()));
1176 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); 1181 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height()));
1177 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), 1182 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv),
1178 SkScalarMul(srcRect.fTop, hInv), 1183 SkScalarMul(srcRect.fTop, hInv),
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 return; 1262 return;
1258 } 1263 }
1259 1264
1260 int offX = bitmap.pixelRefOrigin().fX; 1265 int offX = bitmap.pixelRefOrigin().fX;
1261 int offY = bitmap.pixelRefOrigin().fY; 1266 int offY = bitmap.pixelRefOrigin().fY;
1262 int w = bitmap.width(); 1267 int w = bitmap.width();
1263 int h = bitmap.height(); 1268 int h = bitmap.height();
1264 1269
1265 GrTexture* texture; 1270 GrTexture* texture;
1266 // draw sprite neither filters nor tiles. 1271 // draw sprite neither filters nor tiles.
1267 AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), &t exture); 1272 AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(),
1273 SkSourceGammaTreatment::kRespect, &texture);
1268 if (!texture) { 1274 if (!texture) {
1269 return; 1275 return;
1270 } 1276 }
1271 1277
1272 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType(); 1278 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType();
1273 1279
1274 SkASSERT(!paint.getImageFilter()); 1280 SkASSERT(!paint.getImageFilter());
1275 1281
1276 GrPaint grPaint; 1282 GrPaint grPaint;
1277 SkAutoTUnref<const GrFragmentProcessor> fp( 1283 SkAutoTUnref<const GrFragmentProcessor> fp(
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 1519
1514 SkRect srcR, dstR; 1520 SkRect srcR, dstR;
1515 while (iter.next(&srcR, &dstR)) { 1521 while (iter.next(&srcR, &dstR)) {
1516 this->drawTextureProducer(producer, &srcR, &dstR, SkCanvas::kStrict_ SrcRectConstraint, 1522 this->drawTextureProducer(producer, &srcR, &dstR, SkCanvas::kStrict_ SrcRectConstraint,
1517 *draw.fMatrix, fClip, paint); 1523 *draw.fMatrix, fClip, paint);
1518 } 1524 }
1519 return; 1525 return;
1520 } 1526 }
1521 1527
1522 static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_Filt erMode; 1528 static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_Filt erMode;
1529 bool gammaCorrect = this->surfaceProps().isGammaCorrect();
1530 SkSourceGammaTreatment gammaTreatment = gammaCorrect
1531 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
1523 SkAutoTUnref<const GrFragmentProcessor> fp( 1532 SkAutoTUnref<const GrFragmentProcessor> fp(
1524 producer->createFragmentProcessor(SkMatrix::I(), 1533 producer->createFragmentProcessor(SkMatrix::I(),
1525 SkRect::MakeIWH(producer->width(), pro ducer->height()), 1534 SkRect::MakeIWH(producer->width(), pro ducer->height()),
1526 GrTextureProducer::kNo_FilterConstrain t, true, 1535 GrTextureProducer::kNo_FilterConstrain t, true,
1527 &kMode)); 1536 &kMode, gammaTreatment));
1528 GrPaint grPaint; 1537 GrPaint grPaint;
1529 if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, fp, 1538 if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, fp,
1530 producer->isAlphaOnly(), 1539 producer->isAlphaOnly(), gammaCorrect, &grP aint)) {
1531 this->surfaceProps().isGammaCorrect(), &grP aint)) {
1532 return; 1540 return;
1533 } 1541 }
1534 1542
1535 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, producer->width() , 1543 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, producer->width() ,
1536 producer->height(), center, dst); 1544 producer->height(), center, dst);
1537 } 1545 }
1538 1546
1539 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, 1547 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image,
1540 const SkIRect& center, const SkRect& dst, const SkPaint& paint) { 1548 const SkIRect& center, const SkRect& dst, const SkPaint& paint) {
1541 ASSERT_SINGLE_OWNER 1549 ASSERT_SINGLE_OWNER
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 } 1931 }
1924 1932
1925 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { 1933 SkImageFilterCache* SkGpuDevice::getImageFilterCache() {
1926 ASSERT_SINGLE_OWNER 1934 ASSERT_SINGLE_OWNER
1927 // We always return a transient cache, so it is freed after each 1935 // We always return a transient cache, so it is freed after each
1928 // filter traversal. 1936 // filter traversal.
1929 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); 1937 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize);
1930 } 1938 }
1931 1939
1932 #endif 1940 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrTextureParamsAdjuster.cpp ('k') | src/gpu/SkGpuDevice_drawTexture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698