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

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

Issue 1404433002: Remove image usage type enum. Use GrTextureParams instead. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix no gpu build Created 5 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/GrTextureMaker.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 "GrBlurUtils.h" 10 #include "GrBlurUtils.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 // Helper for turning a bitmap into a texture. If the bitmap is GrTexture backed this 84 // Helper for turning a bitmap into a texture. If the bitmap is GrTexture backed this
85 // just accesses the backing GrTexture. Otherwise, it creates a cached texture 85 // just accesses the backing GrTexture. Otherwise, it creates a cached texture
86 // representation and releases it in the destructor. 86 // representation and releases it in the destructor.
87 class AutoBitmapTexture : public SkNoncopyable { 87 class AutoBitmapTexture : public SkNoncopyable {
88 public: 88 public:
89 AutoBitmapTexture() {} 89 AutoBitmapTexture() {}
90 90
91 AutoBitmapTexture(GrContext* context, 91 AutoBitmapTexture(GrContext* context,
92 const SkBitmap& bitmap, 92 const SkBitmap& bitmap,
93 const GrTextureParams* params, 93 const GrTextureParams& params,
94 GrTexture** texture) { 94 GrTexture** texture) {
95 SkASSERT(texture); 95 SkASSERT(texture);
96 *texture = this->set(context, bitmap, params); 96 *texture = this->set(context, bitmap, params);
97 } 97 }
98 98
99 GrTexture* set(GrContext* context, 99 GrTexture* set(GrContext* context,
100 const SkBitmap& bitmap, 100 const SkBitmap& bitmap,
101 const GrTextureParams* params) { 101 const GrTextureParams& params) {
102 // Either get the texture directly from the bitmap, or else use the cach e and 102 // Either get the texture directly from the bitmap, or else use the cach e and
103 // remember to unref it. 103 // remember to unref it.
104 if (GrTexture* bmpTexture = bitmap.getTexture()) { 104 if (GrTexture* bmpTexture = bitmap.getTexture()) {
105 fTexture.reset(nullptr); 105 fTexture.reset(nullptr);
106 return bmpTexture; 106 return bmpTexture;
107 } else { 107 } else {
108 fTexture.reset(GrRefCachedBitmapTexture(context, bitmap, params)); 108 fTexture.reset(GrRefCachedBitmapTexture(context, bitmap, params));
109 return fTexture.get(); 109 return fTexture.get();
110 } 110 }
111 } 111 }
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 *tileSize = determine_tile_size(*clippedSubset, maxTileSize); 758 *tileSize = determine_tile_size(*clippedSubset, maxTileSize);
759 return true; 759 return true;
760 } 760 }
761 761
762 const size_t area = imageRect.width() * imageRect.height(); 762 const size_t area = imageRect.width() * imageRect.height();
763 if (area < 4 * kBmpSmallTileSize * kBmpSmallTileSize) { 763 if (area < 4 * kBmpSmallTileSize * kBmpSmallTileSize) {
764 return false; 764 return false;
765 } 765 }
766 766
767 // if the entire image/bitmap is already in our cache then no reason to tile it 767 // if the entire image/bitmap is already in our cache then no reason to tile it
768 if (GrIsImageInCache(fContext, imageID, imageRect, nullptr, &params)) { 768 if (GrIsImageInCache(fContext, imageID, imageRect, nullptr, params)) {
769 return false; 769 return false;
770 } 770 }
771 771
772 // At this point we know we could do the draw by uploading the entire bitmap 772 // At this point we know we could do the draw by uploading the entire bitmap
773 // as a texture. However, if the texture would be large compared to the 773 // as a texture. However, if the texture would be large compared to the
774 // cache size and we don't require most of it for this draw then tile to 774 // cache size and we don't require most of it for this draw then tile to
775 // reduce the amount of upload and cache spill. 775 // reduce the amount of upload and cache spill.
776 776
777 // assumption here is that sw bitmap size is a good proxy for its size as 777 // assumption here is that sw bitmap size is a good proxy for its size as
778 // a texture 778 // a texture
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 }; 976 };
977 977
978 bool doBicubic; 978 bool doBicubic;
979 GrTextureParams::FilterMode textureFilterMode = 979 GrTextureParams::FilterMode textureFilterMode =
980 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewMatrix , 980 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewMatrix ,
981 srcRectToDstRect, 981 srcRectToDstRect,
982 &doBicubic); 982 &doBicubic);
983 983
984 // Setup texture to wrap bitmap 984 // Setup texture to wrap bitmap
985 GrTextureParams params(tm, textureFilterMode); 985 GrTextureParams params(tm, textureFilterMode);
986 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, *bitmapPtr , &params)); 986 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, *bitmapPtr , params));
987 987
988 if (!texture) { 988 if (!texture) {
989 SkErrorInternals::SetError(kInternalError_SkError, 989 SkErrorInternals::SetError(kInternalError_SkError,
990 "Couldn't convert bitmap to texture."); 990 "Couldn't convert bitmap to texture.");
991 return; 991 return;
992 } 992 }
993 993
994 994
995 GrPaint grPaint; 995 GrPaint grPaint;
996 996
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 const SkRect& srcRect, 1281 const SkRect& srcRect,
1282 const GrTextureParams& params, 1282 const GrTextureParams& params,
1283 const SkPaint& paint, 1283 const SkPaint& paint,
1284 SkCanvas::SrcRectConstraint constraint, 1284 SkCanvas::SrcRectConstraint constraint,
1285 bool bicubic, 1285 bool bicubic,
1286 bool needsTextureDomain) { 1286 bool needsTextureDomain) {
1287 SkASSERT(bitmap.width() <= fContext->caps()->maxTextureSize() && 1287 SkASSERT(bitmap.width() <= fContext->caps()->maxTextureSize() &&
1288 bitmap.height() <= fContext->caps()->maxTextureSize()); 1288 bitmap.height() <= fContext->caps()->maxTextureSize());
1289 1289
1290 GrTexture* texture; 1290 GrTexture* texture;
1291 AutoBitmapTexture abt(fContext, bitmap, &params, &texture); 1291 AutoBitmapTexture abt(fContext, bitmap, params, &texture);
1292 if (nullptr == texture) { 1292 if (nullptr == texture) {
1293 return; 1293 return;
1294 } 1294 }
1295 1295
1296 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() }; 1296 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() };
1297 SkRect paintRect; 1297 SkRect paintRect;
1298 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); 1298 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width()));
1299 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); 1299 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height()));
1300 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), 1300 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv),
1301 SkScalarMul(srcRect.fTop, hInv), 1301 SkScalarMul(srcRect.fTop, hInv),
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 1412
1413 SkAutoLockPixels alp(bitmap, !bitmap.getTexture()); 1413 SkAutoLockPixels alp(bitmap, !bitmap.getTexture());
1414 if (!bitmap.getTexture() && !bitmap.readyToDraw()) { 1414 if (!bitmap.getTexture() && !bitmap.readyToDraw()) {
1415 return; 1415 return;
1416 } 1416 }
1417 1417
1418 int w = bitmap.width(); 1418 int w = bitmap.width();
1419 int h = bitmap.height(); 1419 int h = bitmap.height();
1420 1420
1421 GrTexture* texture; 1421 GrTexture* texture;
1422 // draw sprite uses the default texture params 1422 // draw sprite neither filters nor tiles.
1423 AutoBitmapTexture abt(fContext, bitmap, nullptr, &texture); 1423 AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), &t exture);
1424 if (!texture) { 1424 if (!texture) {
1425 return; 1425 return;
1426 } 1426 }
1427 1427
1428 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType(); 1428 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType();
1429 1429
1430 SkImageFilter* filter = paint.getImageFilter(); 1430 SkImageFilter* filter = paint.getImageFilter();
1431 // This bitmap will own the filtered result as a texture. 1431 // This bitmap will own the filtered result as a texture.
1432 SkBitmap filteredBitmap; 1432 SkBitmap filteredBitmap;
1433 1433
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 } 1614 }
1615 1615
1616 SkAutoLockPixels alp(src, !src.getTexture()); 1616 SkAutoLockPixels alp(src, !src.getTexture());
1617 if (!src.getTexture() && !src.readyToDraw()) { 1617 if (!src.getTexture() && !src.readyToDraw()) {
1618 return false; 1618 return false;
1619 } 1619 }
1620 1620
1621 GrTexture* texture; 1621 GrTexture* texture;
1622 // We assume here that the filter will not attempt to tile the src. Otherwis e, this cache lookup 1622 // We assume here that the filter will not attempt to tile the src. Otherwis e, this cache lookup
1623 // must be pushed upstack. 1623 // must be pushed upstack.
1624 AutoBitmapTexture abt(fContext, src, nullptr, &texture); 1624 AutoBitmapTexture abt(fContext, src, GrTextureParams::ClampNoFilter(), &text ure);
1625 if (!texture) { 1625 if (!texture) {
1626 return false; 1626 return false;
1627 } 1627 }
1628 1628
1629 return this->filterTexture(fContext, texture, src.width(), src.height(), 1629 return this->filterTexture(fContext, texture, src.width(), src.height(),
1630 filter, ctx, result, offset); 1630 filter, ctx, result, offset);
1631 } 1631 }
1632 1632
1633 static bool wrap_as_bm(GrContext* ctx, const SkImage* image, SkBitmap* bm) { 1633 static bool wrap_as_bm(GrContext* ctx, const SkImage* image, SkBitmap* bm) {
1634 SkAutoTUnref<GrTexture> tex(as_IB(image)->asTextureRef(ctx, kUntiled_SkImage UsageType)); 1634 // TODO: It is wrong to assume these texture params here.
1635 SkAutoTUnref<GrTexture> tex(as_IB(image)->asTextureRef(ctx, GrTextureParams: :ClampNoFilter()));
1635 if (tex) { 1636 if (tex) {
1636 GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpa que(), bm); 1637 GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpa que(), bm);
1637 return true; 1638 return true;
1638 } else { 1639 } else {
1639 return as_IB(image)->getROPixels(bm); 1640 return as_IB(image)->getROPixels(bm);
1640 } 1641 }
1641 } 1642 }
1642 1643
1643 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x , SkScalar y, 1644 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x , SkScalar y,
1644 const SkPaint& paint) { 1645 const SkPaint& paint) {
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 #endif 2026 #endif
2026 } 2027 }
2027 2028
2028 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { 2029 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
2029 // We always return a transient cache, so it is freed after each 2030 // We always return a transient cache, so it is freed after each
2030 // filter traversal. 2031 // filter traversal.
2031 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); 2032 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
2032 } 2033 }
2033 2034
2034 #endif 2035 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrTextureMaker.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698