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

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

Issue 1454933002: Initial implementation of GPU no filter NinePatch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks 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
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 12 matching lines...) Expand all
23 #include "SkDrawProcs.h" 23 #include "SkDrawProcs.h"
24 #include "SkErrorInternals.h" 24 #include "SkErrorInternals.h"
25 #include "SkGlyphCache.h" 25 #include "SkGlyphCache.h"
26 #include "SkGrTexturePixelRef.h" 26 #include "SkGrTexturePixelRef.h"
27 #include "SkGr.h" 27 #include "SkGr.h"
28 #include "SkGrPriv.h" 28 #include "SkGrPriv.h"
29 #include "SkImage_Base.h" 29 #include "SkImage_Base.h"
30 #include "SkImageFilter.h" 30 #include "SkImageFilter.h"
31 #include "SkLayerInfo.h" 31 #include "SkLayerInfo.h"
32 #include "SkMaskFilter.h" 32 #include "SkMaskFilter.h"
33 #include "SkNinePatchIter.h"
33 #include "SkPathEffect.h" 34 #include "SkPathEffect.h"
34 #include "SkPicture.h" 35 #include "SkPicture.h"
35 #include "SkPictureData.h" 36 #include "SkPictureData.h"
36 #include "SkRRect.h" 37 #include "SkRRect.h"
37 #include "SkRecord.h" 38 #include "SkRecord.h"
38 #include "SkStroke.h" 39 #include "SkStroke.h"
39 #include "SkSurface.h" 40 #include "SkSurface.h"
40 #include "SkSurface_Gpu.h" 41 #include "SkSurface_Gpu.h"
41 #include "SkTLazy.h" 42 #include "SkTLazy.h"
42 #include "SkUtils.h" 43 #include "SkUtils.h"
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 paramsTemp, 1280 paramsTemp,
1280 *paint, 1281 *paint,
1281 constraint, 1282 constraint,
1282 bicubic, 1283 bicubic,
1283 needsTextureDomain); 1284 needsTextureDomain);
1284 } 1285 }
1285 } 1286 }
1286 } 1287 }
1287 } 1288 }
1288 1289
1289
1290 /* 1290 /*
1291 * This is called by drawBitmap(), which has to handle images that may be too 1291 * This is called by drawBitmap(), which has to handle images that may be too
1292 * large to be represented by a single texture. 1292 * large to be represented by a single texture.
1293 * 1293 *
1294 * internalDrawBitmap assumes that the specified bitmap will fit in a texture 1294 * internalDrawBitmap assumes that the specified bitmap will fit in a texture
1295 * and that non-texture portion of the GrPaint has already been setup. 1295 * and that non-texture portion of the GrPaint has already been setup.
1296 */ 1296 */
1297 void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap, 1297 void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
1298 const SkMatrix& viewMatrix, 1298 const SkMatrix& viewMatrix,
1299 const SkRect& srcRect, 1299 const SkRect& srcRect,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 // local coords with the bitmap draw since it may mess up texture look u ps for the shader. 1333 // local coords with the bitmap draw since it may mess up texture look u ps for the shader.
1334 // Thus we need to pass in the transform matrix directly to the texture processor used for 1334 // Thus we need to pass in the transform matrix directly to the texture processor used for
1335 // the bitmap draw. 1335 // the bitmap draw.
1336 texMatrix.setScale(wInv, hInv); 1336 texMatrix.setScale(wInv, hInv);
1337 } 1337 }
1338 1338
1339 SkRect textureDomain = SkRect::MakeEmpty(); 1339 SkRect textureDomain = SkRect::MakeEmpty();
1340 1340
1341 // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring 1341 // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring
1342 // the rest from the SkPaint. 1342 // the rest from the SkPaint.
1343 GrPaint grPaint;
1344 SkAutoTUnref<const GrFragmentProcessor> fp; 1343 SkAutoTUnref<const GrFragmentProcessor> fp;
1345 1344
1346 if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint )) { 1345 if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint )) {
1347 // Use a constrained texture domain to avoid color bleeding 1346 // Use a constrained texture domain to avoid color bleeding
1348 SkScalar left, top, right, bottom; 1347 SkScalar left, top, right, bottom;
1349 if (srcRect.width() > SK_Scalar1) { 1348 if (srcRect.width() > SK_Scalar1) {
1350 SkScalar border = SK_ScalarHalf / texture->width(); 1349 SkScalar border = SK_ScalarHalf / texture->width();
1351 left = paintRect.left() + border; 1350 left = paintRect.left() + border;
1352 right = paintRect.right() - border; 1351 right = paintRect.right() - border;
1353 } else { 1352 } else {
(...skipping 17 matching lines...) Expand all
1371 params.filterMode())); 1370 params.filterMode()));
1372 } 1371 }
1373 } else if (bicubic) { 1372 } else if (bicubic) {
1374 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); 1373 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode());
1375 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil eModeY() }; 1374 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil eModeY() };
1376 fp.reset(GrBicubicEffect::Create(texture, texMatrix, tileModes)); 1375 fp.reset(GrBicubicEffect::Create(texture, texMatrix, tileModes));
1377 } else { 1376 } else {
1378 fp.reset(GrSimpleTextureEffect::Create(texture, texMatrix, params)); 1377 fp.reset(GrSimpleTextureEffect::Create(texture, texMatrix, params));
1379 } 1378 }
1380 1379
1381 SkAutoTUnref<const GrFragmentProcessor> shaderFP; 1380 GrPaint grPaint;
1382 1381 if (!SkPaintToGrPaintWithTexture(this->context(), paint, viewMatrix, fp,
1383 if (kAlpha_8_SkColorType == bitmap.colorType()) { 1382 kAlpha_8_SkColorType == bitmap.colorType(), &grPaint)) {
1384 if (const SkShader* shader = paint.getShader()) {
1385 shaderFP.reset(shader->asFragmentProcessor(this->context(),
1386 viewMatrix,
1387 nullptr,
1388 paint.getFilterQuality()) );
1389 if (!shaderFP) {
1390 return;
1391 }
1392 const GrFragmentProcessor* fpSeries[] = { shaderFP.get(), fp.get() } ;
1393 fp.reset(GrFragmentProcessor::RunInSeries(fpSeries, 2));
1394 } else {
1395 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp));
1396 }
1397 } else {
1398 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp));
1399 }
1400
1401 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) {
1402 return; 1383 return;
1403 } 1384 }
1404 1385
1405 if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) { 1386 if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) {
1406 // We don't have local coords in this case and have previously set the t ransform 1387 // We don't have local coords in this case and have previously set the t ransform
1407 // matrices directly on the texture processor. 1388 // matrices directly on the texture processor.
1408 fDrawContext->drawRect(fClip, grPaint, viewMatrix, dstRect); 1389 fDrawContext->drawRect(fClip, grPaint, viewMatrix, dstRect);
1409 } else { 1390 } else {
1410 fDrawContext->fillRectToRect(fClip, grPaint, viewMatrix, dstRect, paintR ect); 1391 fDrawContext->fillRectToRect(fClip, grPaint, viewMatrix, dstRect, paintR ect);
1411 } 1392 }
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 return; 1701 return;
1721 } 1702 }
1722 } else { 1703 } else {
1723 if (!wrap_as_bm(this->context(), image, &bm)) { 1704 if (!wrap_as_bm(this->context(), image, &bm)) {
1724 return; 1705 return;
1725 } 1706 }
1726 } 1707 }
1727 this->drawBitmapRect(draw, bm, src, dst, paint, constraint); 1708 this->drawBitmapRect(draw, bm, src, dst, paint, constraint);
1728 } 1709 }
1729 1710
1711 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image,
1712 const SkIRect& center, const SkRect& dst, const SkPaint& paint) {
1713 // TODO write native implementation
1714 SkBitmap bitmap;
1715 if (!wrap_as_bm(this->context(), image, &bitmap)) {
1716 return;
1717 }
1718 return this->drawBitmapNine(draw, bitmap, center, dst, paint);
1719 }
1720
1721 void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, con st SkIRect& center,
1722 const SkRect& dst, const SkPaint& paint) {
1723 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawBitmapNine", fContext);
1724
1725 CHECK_FOR_ANNOTATION(paint);
1726 CHECK_SHOULD_DRAW(draw);
1727
robertphillips 2015/11/18 18:12:07 This comment seems wrong ...
joshualitt 2015/11/18 19:07:07 Acknowledged.
1728 // we fallback for bitmap backed textures
1729 bool useFallback = paint.getMaskFilter() || paint.isAntiAlias();
1730 bool doBicubic;
1731 GrTextureParams::FilterMode textureFilterMode =
1732 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMat rix, SkMatrix::I(),
1733 &doBicubic);
1734
1735 // TODO handle bilerp
1736 if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != texture FilterMode) {
1737 SkNinePatchIter iter(bitmap.width(), bitmap.height(), center, dst);
1738
1739 SkRect srcR, dstR;
1740 while (iter.next(&srcR, &dstR)) {
1741 this->drawBitmapRect(draw, bitmap, &srcR, dstR, paint,
1742 SkCanvas::kStrict_SrcRectConstraint);
1743 }
1744 return;
1745 }
1746
1747 GrTextureParams params = GrTextureParams::ClampNoFilter();
1748
1749 GrTexture* texture(GrRefCachedBitmapTexture(this->context(), bitmap, params) );
1750 if (nullptr == texture) {
1751 return;
1752 }
1753
1754 SkMatrix texMatrix;
1755 texMatrix.setIDiv(texture->width(), texture->height());
1756
1757 SkAutoTUnref<const GrFragmentProcessor> fp(GrSimpleTextureEffect::Create(tex ture, texMatrix,
1758 par ams));
1759
1760 GrPaint grPaint;
1761 if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, fp,
1762 kAlpha_8_SkColorType == bitmap.colorType(), &grPaint)) {
1763 return;
1764 }
1765
1766 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, bitmap.width(), b itmap.height(),
1767 center, dst);
1768 }
1769
1730 /////////////////////////////////////////////////////////////////////////////// 1770 ///////////////////////////////////////////////////////////////////////////////
1731 1771
1732 // must be in SkCanvas::VertexMode order 1772 // must be in SkCanvas::VertexMode order
1733 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { 1773 static const GrPrimitiveType gVertexMode2PrimitiveType[] = {
1734 kTriangles_GrPrimitiveType, 1774 kTriangles_GrPrimitiveType,
1735 kTriangleStrip_GrPrimitiveType, 1775 kTriangleStrip_GrPrimitiveType,
1736 kTriangleFan_GrPrimitiveType, 1776 kTriangleFan_GrPrimitiveType,
1737 }; 1777 };
1738 1778
1739 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, 1779 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
2070 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); 2110 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
2071 } 2111 }
2072 2112
2073 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { 2113 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
2074 // We always return a transient cache, so it is freed after each 2114 // We always return a transient cache, so it is freed after each
2075 // filter traversal. 2115 // filter traversal.
2076 return SkGpuDevice::NewImageFilterCache(); 2116 return SkGpuDevice::NewImageFilterCache();
2077 } 2117 }
2078 2118
2079 #endif 2119 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698