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

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

Issue 1293543002: drawBitmapImage can batch across AA rects (Closed) Base URL: https://skia.googlesource.com/skia.git@gmfordrawimagerect
Patch Set: rebase and broken Created 5 years, 4 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 | « no previous file | src/gpu/batches/GrRectBatchFactory.h » ('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 21 matching lines...) Expand all
32 #include "SkPictureData.h" 32 #include "SkPictureData.h"
33 #include "SkRRect.h" 33 #include "SkRRect.h"
34 #include "SkRecord.h" 34 #include "SkRecord.h"
35 #include "SkStroke.h" 35 #include "SkStroke.h"
36 #include "SkSurface.h" 36 #include "SkSurface.h"
37 #include "SkSurface_Gpu.h" 37 #include "SkSurface_Gpu.h"
38 #include "SkTLazy.h" 38 #include "SkTLazy.h"
39 #include "SkUtils.h" 39 #include "SkUtils.h"
40 #include "SkVertState.h" 40 #include "SkVertState.h"
41 #include "SkXfermode.h" 41 #include "SkXfermode.h"
42 #include "batches/GrRectBatchFactory.h"
42 #include "effects/GrBicubicEffect.h" 43 #include "effects/GrBicubicEffect.h"
43 #include "effects/GrDashingEffect.h" 44 #include "effects/GrDashingEffect.h"
44 #include "effects/GrSimpleTextureEffect.h" 45 #include "effects/GrSimpleTextureEffect.h"
45 #include "effects/GrTextureDomain.h" 46 #include "effects/GrTextureDomain.h"
46 47
47 #if SK_SUPPORT_GPU 48 #if SK_SUPPORT_GPU
48 49
49 enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 }; 50 enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 };
50 51
51 #if 0 52 #if 0
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 if (isDstPixelAligned) 981 if (isDstPixelAligned)
981 directDraw = true; 982 directDraw = true;
982 } 983 }
983 } 984 }
984 985
985 if (paint.getMaskFilter() || !directDraw) { 986 if (paint.getMaskFilter() || !directDraw) {
986 // Convert the bitmap to a shader so that the rect can be drawn 987 // Convert the bitmap to a shader so that the rect can be drawn
987 // through drawRect, which supports mask filters. 988 // through drawRect, which supports mask filters.
988 SkBitmap tmp; // subset of bitmap, if necessary 989 SkBitmap tmp; // subset of bitmap, if necessary
989 const SkBitmap* bitmapPtr = &bitmap; 990 const SkBitmap* bitmapPtr = &bitmap;
990 SkMatrix localM; 991 SkMatrix srcRectToDstRect;
991 if (srcRectPtr) { 992 if (srcRectPtr) {
992 localM.setTranslate(-srcRectPtr->fLeft, -srcRectPtr->fTop); 993 srcRectToDstRect.setTranslate(-srcRectPtr->fLeft, -srcRectPtr->fTop) ;
993 localM.postScale(dstSize.fWidth / srcRectPtr->width(), 994 srcRectToDstRect.postScale(dstSize.fWidth / srcRectPtr->width(),
994 dstSize.fHeight / srcRectPtr->height()); 995 dstSize.fHeight / srcRectPtr->height());
995 // In bleed mode we position and trim the bitmap based on the src re ct which is 996 // In bleed mode we position and trim the bitmap based on the src re ct which is
996 // already accounted for in 'm' and 'srcRect'. In clamp mode we need to chop out 997 // already accounted for in 'm' and 'srcRect'. In clamp mode we need to chop out
997 // the desired portion of the bitmap and then update 'm' and 'srcRec t' to 998 // the desired portion of the bitmap and then update 'm' and 'srcRec t' to
998 // compensate. 999 // compensate.
999 if (SkCanvas::kStrict_SrcRectConstraint == constraint) { 1000 if (SkCanvas::kStrict_SrcRectConstraint == constraint) {
1000 SkIRect iSrc; 1001 SkIRect iSrc;
1001 srcRect.roundOut(&iSrc); 1002 srcRect.roundOut(&iSrc);
1002 1003
1003 SkPoint offset = SkPoint::Make(SkIntToScalar(iSrc.fLeft), 1004 SkPoint offset = SkPoint::Make(SkIntToScalar(iSrc.fLeft),
1004 SkIntToScalar(iSrc.fTop)); 1005 SkIntToScalar(iSrc.fTop));
1005 1006
1006 if (!bitmap.extractSubset(&tmp, iSrc)) { 1007 if (!bitmap.extractSubset(&tmp, iSrc)) {
1007 return; // extraction failed 1008 return; // extraction failed
1008 } 1009 }
1009 bitmapPtr = &tmp; 1010 bitmapPtr = &tmp;
1010 srcRect.offset(-offset.fX, -offset.fY); 1011 srcRect.offset(-offset.fX, -offset.fY);
1011 1012
1012 // The source rect has changed so update the matrix 1013 // The source rect has changed so update the matrix
1013 localM.preTranslate(offset.fX, offset.fY); 1014 srcRectToDstRect.preTranslate(offset.fX, offset.fY);
1014 } 1015 }
1015 } else { 1016 } else {
1016 localM.reset(); 1017 srcRectToDstRect.reset();
1017 } 1018 }
1018 1019
1019 SkPaint paintWithShader(paint); 1020 // If we have a maskfilter then we can't batch, so we take a slow path. However, we fast
1020 paintWithShader.setShader(SkShader::CreateBitmapShader(*bitmapPtr, 1021 // path the case where we are drawing an AA rect so we can batch many dr awImageRect calls
1021 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &localM))->unr ef(); 1022 if (paint.getMaskFilter()) {
1022 SkRect dstRect = {0, 0, dstSize.fWidth, dstSize.fHeight}; 1023 SkPaint paintWithShader(paint);
1023 this->drawRect(draw, dstRect, paintWithShader); 1024 paintWithShader.setShader(SkShader::CreateBitmapShader(*bitmapPtr,
robertphillips 2015/08/14 18:49:20 tab over to line up with '(' ?
1025 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode,
1026 &srcRectToDstRect))->unref();
1027 SkRect dstRect = {0, 0, dstSize.fWidth, dstSize.fHeight};
1028 this->drawRect(draw, dstRect, paintWithShader);
1029 } else {
robertphillips 2015/08/14 18:49:20 Can/should this be a subroutine ?
1030 SkShader::TileMode tm[] = {
1031 SkShader::kClamp_TileMode,
1032 SkShader::kClamp_TileMode,
1033 };
1034
1035 bool doBicubic;
1036 GrTextureParams::FilterMode textureFilterMode =
1037 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *d raw.fMatrix,
1038 srcRectToDstRect,
1039 &doBicubic);
1040
1041 // Setup texture to wrap bitmap
1042 GrTextureParams params(tm, textureFilterMode);
1043 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(fContext, * bitmapPtr,
1044 &params));
1045
1046 if (!texture) {
1047 SkErrorInternals::SetError(kInternalError_SkError,
1048 "Couldn't convert bitmap to texture." );
1049 return;
1050 }
1051
1052 // Setup paint
1053 GrColor paintColor = (kAlpha_8_SkColorType == bitmapPtr->colorType() ) ?
1054 SkColor2GrColor(paint.getColor()) :
1055 SkColor2GrColorJustAlpha(paint.getColor());
1056
1057 GrPaint grPaint;
1058
1059 // Create and insert texture effect
1060 SkAutoTUnref<const GrFragmentProcessor> fp;
1061 if (doBicubic) {
1062 fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager (), texture,
1063 SkMatrix::I(),
1064 tm));
1065 } else {
1066 fp.reset(GrSimpleTextureEffect::Create(grPaint.getProcessorDataM anager(), texture,
1067 SkMatrix::I(), params));
1068 }
1069
1070 grPaint.addColorProcessor(fp);
1071
1072 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fM atrix, true,
1073 &grPaint)) {
1074 return;
1075 }
1076
1077 grPaint.setColor(paintColor);
1078
1079 // Setup dst rect and final matrix
1080 SkRect dstRect = {0, 0, dstSize.fWidth, dstSize.fHeight};
1081
1082 SkRect devRect;
1083 draw.fMatrix->mapRect(&devRect, dstRect);
1084
1085 SkMatrix matrix;
1086 matrix.setIDiv(bitmapPtr->width(), bitmapPtr->height());
1087
1088 SkMatrix dstRectToSrcRect;
1089 if (!srcRectToDstRect.invert(&dstRectToSrcRect)) {
1090 return;
1091 }
1092 matrix.preConcat(dstRectToSrcRect);
1093
1094 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateFillAA(grP aint.getColor(),
1095 *dr aw.fMatrix,
1096 ma trix,
1097 ds tRect,
1098 de vRect));
1099
1100 fDrawContext->drawBatch(fRenderTarget, fClip, grPaint, batch);
1101 }
1024 1102
1025 return; 1103 return;
1026 } 1104 }
1027 1105
1028 // If there is no mask filter than it is OK to handle the src rect -> dst re ct scaling using 1106 // If there is no mask filter than it is OK to handle the src rect -> dst re ct scaling using
1029 // the view matrix rather than a local matrix. 1107 // the view matrix rather than a local matrix.
1030 SkMatrix m; 1108 SkMatrix m;
1031 m.setScale(dstSize.fWidth / srcRect.width(), 1109 m.setScale(dstSize.fWidth / srcRect.width(),
1032 dstSize.fHeight / srcRect.height()); 1110 dstSize.fHeight / srcRect.height());
1033 SkMatrix viewM = *draw.fMatrix; 1111 SkMatrix viewM = *draw.fMatrix;
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 #endif 1915 #endif
1838 } 1916 }
1839 1917
1840 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { 1918 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
1841 // We always return a transient cache, so it is freed after each 1919 // We always return a transient cache, so it is freed after each
1842 // filter traversal. 1920 // filter traversal.
1843 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); 1921 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
1844 } 1922 }
1845 1923
1846 #endif 1924 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/batches/GrRectBatchFactory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698