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

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

Issue 1424313010: Separate out natively-texture image/bmp draws from cached-as-texture image/bmp draws (Closed) Base URL: https://skia.googlesource.com/skia.git@const
Patch Set: update Created 5 years, 1 month 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/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"
11 #include "GrContext.h" 11 #include "GrContext.h"
12 #include "GrDrawContext.h" 12 #include "GrDrawContext.h"
13 #include "GrFontScaler.h" 13 #include "GrFontScaler.h"
14 #include "GrGpu.h" 14 #include "GrGpu.h"
15 #include "GrGpuResourcePriv.h" 15 #include "GrGpuResourcePriv.h"
16 #include "GrImageIDTextureAdjuster.h"
16 #include "GrLayerHoister.h" 17 #include "GrLayerHoister.h"
17 #include "GrRecordReplaceDraw.h" 18 #include "GrRecordReplaceDraw.h"
18 #include "GrStrokeInfo.h" 19 #include "GrStrokeInfo.h"
19 #include "GrTextContext.h" 20 #include "GrTextContext.h"
20 #include "GrTracing.h" 21 #include "GrTracing.h"
21 #include "SkCanvasPriv.h" 22 #include "SkCanvasPriv.h"
22 #include "SkDrawProcs.h" 23 #include "SkDrawProcs.h"
23 #include "SkErrorInternals.h" 24 #include "SkErrorInternals.h"
24 #include "SkGlyphCache.h" 25 #include "SkGlyphCache.h"
25 #include "SkGrTexturePixelRef.h" 26 #include "SkGrTexturePixelRef.h"
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 SkIRect outClippedSrcRect; 835 SkIRect outClippedSrcRect;
835 836
836 return this->shouldTileImageID(image->unique(), image->bounds(), viewMatrix, params, srcRectPtr, 837 return this->shouldTileImageID(image->unique(), image->bounds(), viewMatrix, params, srcRectPtr,
837 maxTileSize, &outTileSize, &outClippedSrcRect ); 838 maxTileSize, &outTileSize, &outClippedSrcRect );
838 } 839 }
839 840
840 void SkGpuDevice::drawBitmap(const SkDraw& origDraw, 841 void SkGpuDevice::drawBitmap(const SkDraw& origDraw,
841 const SkBitmap& bitmap, 842 const SkBitmap& bitmap,
842 const SkMatrix& m, 843 const SkMatrix& m,
843 const SkPaint& paint) { 844 const SkPaint& paint) {
845
846 GrTexture* texture = bitmap.getTexture();
847 if (texture) {
848 CHECK_SHOULD_DRAW(origDraw);
849 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType();
850 GrBitmapTextureAdjuster adjuster(&bitmap);
851 SkMatrix viewMatrix;
852 viewMatrix.setConcat(*origDraw.fMatrix, m);
853 this->drawTextureAdjuster(&adjuster, alphaOnly, nullptr, nullptr,
854 SkCanvas::kFast_SrcRectConstraint, viewMatrix, fClip, paint);
855 return;
856 }
844 SkMatrix concat; 857 SkMatrix concat;
845 SkTCopyOnFirstWrite<SkDraw> draw(origDraw); 858 SkTCopyOnFirstWrite<SkDraw> draw(origDraw);
846 if (!m.isIdentity()) { 859 if (!m.isIdentity()) {
847 concat.setConcat(*draw->fMatrix, m); 860 concat.setConcat(*draw->fMatrix, m);
848 draw.writable()->fMatrix = &concat; 861 draw.writable()->fMatrix = &concat;
849 } 862 }
850 this->drawBitmapCommon(*draw, bitmap, nullptr, nullptr, paint, SkCanvas::kSt rict_SrcRectConstraint); 863 this->drawBitmapCommon(*draw, bitmap, nullptr, nullptr, paint,
864 SkCanvas::kStrict_SrcRectConstraint);
851 } 865 }
852 866
853 // This method outsets 'iRect' by 'outset' all around and then clamps its extent s to 867 // This method outsets 'iRect' by 'outset' all around and then clamps its extent s to
854 // 'clamp'. 'offset' is adjusted to remain positioned over the top-left corner 868 // 'clamp'. 'offset' is adjusted to remain positioned over the top-left corner
855 // of 'iRect' for all possible outsets/clamps. 869 // of 'iRect' for all possible outsets/clamps.
856 static inline void clamped_outset_with_offset(SkIRect* iRect, 870 static inline void clamped_outset_with_offset(SkIRect* iRect,
857 int outset, 871 int outset,
858 SkPoint* offset, 872 SkPoint* offset,
859 const SkIRect& clamp) { 873 const SkIRect& clamp) {
860 iRect->outset(outset, outset); 874 iRect->outset(outset, outset);
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 } 1191 }
1178 } 1192 }
1179 1193
1180 // Break 'bitmap' into several tiles to draw it since it has already 1194 // Break 'bitmap' into several tiles to draw it since it has already
1181 // been determined to be too large to fit in VRAM 1195 // been determined to be too large to fit in VRAM
1182 void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, 1196 void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap,
1183 const SkMatrix& viewMatrix, 1197 const SkMatrix& viewMatrix,
1184 const SkRect& srcRect, 1198 const SkRect& srcRect,
1185 const SkIRect& clippedSrcIRect, 1199 const SkIRect& clippedSrcIRect,
1186 const GrTextureParams& params, 1200 const GrTextureParams& params,
1187 const SkPaint& paint, 1201 const SkPaint& origPaint,
1188 SkCanvas::SrcRectConstraint constraint, 1202 SkCanvas::SrcRectConstraint constraint,
1189 int tileSize, 1203 int tileSize,
1190 bool bicubic) { 1204 bool bicubic) {
1191 // The following pixel lock is technically redundant, but it is desirable 1205 // The following pixel lock is technically redundant, but it is desirable
1192 // to lock outside of the tile loop to prevent redecoding the whole image 1206 // to lock outside of the tile loop to prevent redecoding the whole image
1193 // at each tile in cases where 'bitmap' holds an SkDiscardablePixelRef that 1207 // at each tile in cases where 'bitmap' holds an SkDiscardablePixelRef that
1194 // is larger than the limit of the discardable memory pool. 1208 // is larger than the limit of the discardable memory pool.
1195 SkAutoLockPixels alp(bitmap); 1209 SkAutoLockPixels alp(bitmap);
1210
1211 const SkPaint* paint = &origPaint;
1212 SkPaint tempPaint;
1213 if (origPaint.isAntiAlias() && !fRenderTarget->isUnifiedMultisampled()) {
1214 // Drop antialiasing to avoid seams at tile boundaries.
1215 tempPaint = origPaint;
1216 tempPaint.setAntiAlias(false);
1217 paint = &tempPaint;
1218 }
1196 SkRect clippedSrcRect = SkRect::Make(clippedSrcIRect); 1219 SkRect clippedSrcRect = SkRect::Make(clippedSrcIRect);
1197 1220
1198 int nx = bitmap.width() / tileSize; 1221 int nx = bitmap.width() / tileSize;
1199 int ny = bitmap.height() / tileSize; 1222 int ny = bitmap.height() / tileSize;
1200 for (int x = 0; x <= nx; x++) { 1223 for (int x = 0; x <= nx; x++) {
1201 for (int y = 0; y <= ny; y++) { 1224 for (int y = 0; y <= ny; y++) {
1202 SkRect tileR; 1225 SkRect tileR;
1203 tileR.set(SkIntToScalar(x * tileSize), 1226 tileR.set(SkIntToScalar(x * tileSize),
1204 SkIntToScalar(y * tileSize), 1227 SkIntToScalar(y * tileSize),
1205 SkIntToScalar((x + 1) * tileSize), 1228 SkIntToScalar((x + 1) * tileSize),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 tileR.offset(-offset.fX, -offset.fY); 1270 tileR.offset(-offset.fX, -offset.fY);
1248 GrTextureParams paramsTemp = params; 1271 GrTextureParams paramsTemp = params;
1249 bool needsTextureDomain = needs_texture_domain( 1272 bool needsTextureDomain = needs_texture_domain(
1250 bitmap, srcRect, params Temp, 1273 bitmap, srcRect, params Temp,
1251 viewM, bicubic, 1274 viewM, bicubic,
1252 fRenderTarget->isUnifie dMultisampled()); 1275 fRenderTarget->isUnifie dMultisampled());
1253 this->internalDrawBitmap(tmpB, 1276 this->internalDrawBitmap(tmpB,
1254 viewM, 1277 viewM,
1255 tileR, 1278 tileR,
1256 paramsTemp, 1279 paramsTemp,
1257 paint, 1280 *paint,
1258 constraint, 1281 constraint,
1259 bicubic, 1282 bicubic,
1260 needsTextureDomain); 1283 needsTextureDomain);
1261 } 1284 }
1262 } 1285 }
1263 } 1286 }
1264 } 1287 }
1265 1288
1266 1289
1267 /* 1290 /*
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 SkIntToScalar(h)), 1498 SkIntToScalar(h)),
1476 SkRect::MakeXYWH(0, 1499 SkRect::MakeXYWH(0,
1477 0, 1500 0,
1478 SK_Scalar1 * w / texture->widt h(), 1501 SK_Scalar1 * w / texture->widt h(),
1479 SK_Scalar1 * h / texture->heig ht())); 1502 SK_Scalar1 * h / texture->heig ht()));
1480 } 1503 }
1481 1504
1482 void SkGpuDevice::drawBitmapRect(const SkDraw& origDraw, const SkBitmap& bitmap, 1505 void SkGpuDevice::drawBitmapRect(const SkDraw& origDraw, const SkBitmap& bitmap,
1483 const SkRect* src, const SkRect& dst, 1506 const SkRect* src, const SkRect& dst,
1484 const SkPaint& paint, SkCanvas::SrcRectConstrai nt constraint) { 1507 const SkPaint& paint, SkCanvas::SrcRectConstrai nt constraint) {
1508 if (GrTexture* tex = bitmap.getTexture()) {
1509 CHECK_SHOULD_DRAW(origDraw);
1510 bool alphaOnly = GrPixelConfigIsAlphaOnly(tex->config());
1511 GrBitmapTextureAdjuster adjuster(&bitmap);
1512 this->drawTextureAdjuster(&adjuster, alphaOnly, src, &dst, constraint, * origDraw.fMatrix,
1513 fClip, paint);
1514 return;
1515 }
1516
1485 SkMatrix matrix; 1517 SkMatrix matrix;
1486 SkRect bitmapBounds, tmpSrc; 1518 SkRect bitmapBounds, tmpSrc;
1487 1519
1488 bitmapBounds.set(0, 0, 1520 bitmapBounds.set(0, 0,
1489 SkIntToScalar(bitmap.width()), 1521 SkIntToScalar(bitmap.width()),
1490 SkIntToScalar(bitmap.height())); 1522 SkIntToScalar(bitmap.height()));
1491 1523
1492 // Compute matrix from the two rectangles 1524 // Compute matrix from the two rectangles
1493 if (src) { 1525 if (src) {
1494 tmpSrc = *src; 1526 tmpSrc = *src;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 return true; 1668 return true;
1637 } else { 1669 } else {
1638 return as_IB(image)->getROPixels(bm); 1670 return as_IB(image)->getROPixels(bm);
1639 } 1671 }
1640 } 1672 }
1641 1673
1642 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x , SkScalar y, 1674 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x , SkScalar y,
1643 const SkPaint& paint) { 1675 const SkPaint& paint) {
1644 SkBitmap bm; 1676 SkBitmap bm;
1645 if (GrTexture* tex = as_IB(image)->peekTexture()) { 1677 if (GrTexture* tex = as_IB(image)->peekTexture()) {
1646 GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpa que(), &bm); 1678 CHECK_SHOULD_DRAW(draw);
1679 SkMatrix viewMatrix = *draw.fMatrix;
1680 viewMatrix.preTranslate(x, y);
1681 bool alphaOnly = GrPixelConfigIsAlphaOnly(tex->config());
1682 GrImageTextureAdjuster adjuster(as_IB(image));
1683 this->drawTextureAdjuster(&adjuster, alphaOnly, nullptr, nullptr,
1684 SkCanvas::kFast_SrcRectConstraint, viewMatrix, fClip, paint);
1685 return;
1647 } else { 1686 } else {
1648 if (this->shouldTileImage(image, nullptr, SkCanvas::kFast_SrcRectConstra int, 1687 if (this->shouldTileImage(image, nullptr, SkCanvas::kFast_SrcRectConstra int,
1649 paint.getFilterQuality(), *draw.fMatrix)) { 1688 paint.getFilterQuality(), *draw.fMatrix)) {
1650 // only support tiling as bitmap at the moment, so force raster-vers ion 1689 // only support tiling as bitmap at the moment, so force raster-vers ion
1651 if (!as_IB(image)->getROPixels(&bm)) { 1690 if (!as_IB(image)->getROPixels(&bm)) {
1652 return; 1691 return;
1653 } 1692 }
1654 } else { 1693 } else {
1655 if (!wrap_as_bm(this->context(), image, &bm)) { 1694 if (!wrap_as_bm(this->context(), image, &bm)) {
1656 return; 1695 return;
1657 } 1696 }
1658 } 1697 }
1659 } 1698 }
1660 this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); 1699 this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint);
1661 } 1700 }
1662 1701
1663 void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const SkRect* src, 1702 void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const SkRect* src,
1664 const SkRect& dst, const SkPaint& paint, 1703 const SkRect& dst, const SkPaint& paint,
1665 SkCanvas::SrcRectConstraint constraint) { 1704 SkCanvas::SrcRectConstraint constraint) {
1705 if (GrTexture* tex = as_IB(image)->peekTexture()) {
1706 CHECK_SHOULD_DRAW(draw);
1707 GrImageTextureAdjuster adjuster(as_IB(image));
1708 bool alphaOnly = GrPixelConfigIsAlphaOnly(tex->config());
1709 this->drawTextureAdjuster(&adjuster, alphaOnly, src, &dst, constraint, * draw.fMatrix,
1710 fClip, paint);
1711 return;
1712 }
1666 SkBitmap bm; 1713 SkBitmap bm;
1667 if (GrTexture* tex = as_IB(image)->peekTexture()) { 1714 SkMatrix viewMatrix = *draw.fMatrix;
1668 GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpa que(), &bm); 1715 viewMatrix.preScale(dst.width() / (src ? src->width() : image->width()),
1716 dst.height() / (src ? src->height() : image->height()));
1717 if (this->shouldTileImage(image, src, constraint, paint.getFilterQuality(), viewMatrix)) {
1718 // only support tiling as bitmap at the moment, so force raster-version
1719 if (!as_IB(image)->getROPixels(&bm)) {
1720 return;
1721 }
1669 } else { 1722 } else {
1670 SkMatrix viewMatrix = *draw.fMatrix; 1723 if (!wrap_as_bm(this->context(), image, &bm)) {
1671 viewMatrix.preScale(dst.width() / (src ? src->width() : image->width()), 1724 return;
1672 dst.height() / (src ? src->height() : image->height( )));
1673
1674 if (this->shouldTileImage(image, src, constraint, paint.getFilterQuality (), viewMatrix)) {
1675 // only support tiling as bitmap at the moment, so force raster-vers ion
1676 if (!as_IB(image)->getROPixels(&bm)) {
1677 return;
1678 }
1679 } else {
1680 if (!wrap_as_bm(this->context(), image, &bm)) {
1681 return;
1682 }
1683 } 1725 }
1684 } 1726 }
1685 this->drawBitmapRect(draw, bm, src, dst, paint, constraint); 1727 this->drawBitmapRect(draw, bm, src, dst, paint, constraint);
1686 } 1728 }
1687 1729
1688 /////////////////////////////////////////////////////////////////////////////// 1730 ///////////////////////////////////////////////////////////////////////////////
1689 1731
1690 // must be in SkCanvas::VertexMode order 1732 // must be in SkCanvas::VertexMode order
1691 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { 1733 static const GrPrimitiveType gVertexMode2PrimitiveType[] = {
1692 kTriangles_GrPrimitiveType, 1734 kTriangles_GrPrimitiveType,
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); 2067 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
2026 } 2068 }
2027 2069
2028 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { 2070 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
2029 // We always return a transient cache, so it is freed after each 2071 // We always return a transient cache, so it is freed after each
2030 // filter traversal. 2072 // filter traversal.
2031 return SkGpuDevice::NewImageFilterCache(); 2073 return SkGpuDevice::NewImageFilterCache();
2032 } 2074 }
2033 2075
2034 #endif 2076 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | src/gpu/SkGpuDevice_drawTexture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698