OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 modelToUV; |
bsalomon
2015/08/13 17:00:34
Let's keep are labeling consistent and not introdu
| |
991 if (srcRectPtr) { | 992 if (srcRectPtr) { |
992 localM.setTranslate(-srcRectPtr->fLeft, -srcRectPtr->fTop); | 993 modelToUV.setTranslate(-srcRectPtr->fLeft, -srcRectPtr->fTop); |
993 localM.postScale(dstSize.fWidth / srcRectPtr->width(), | 994 modelToUV.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 modelToUV.preTranslate(offset.fX, offset.fY); |
1014 } | 1015 } |
1015 } else { | 1016 } else { |
1016 localM.reset(); | 1017 modelToUV.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, |
1025 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &model ToUV))->unref(); | |
1026 SkRect dstRect = {0, 0, dstSize.fWidth, dstSize.fHeight}; | |
1027 this->drawRect(draw, dstRect, paintWithShader); | |
1028 } else { | |
1029 SkShader::TileMode tm[] = { | |
1030 SkShader::kClamp_TileMode, | |
1031 SkShader::kClamp_TileMode, | |
1032 }; | |
1033 | |
1034 bool doBicubic; | |
1035 GrTextureParams::FilterMode textureFilterMode = | |
1036 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *d raw.fMatrix, | |
1037 modelToUV, | |
1038 &doBicubic); | |
1039 | |
1040 // Setup texture to wrap bitmap | |
1041 GrTextureParams params(tm, textureFilterMode); | |
1042 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(fContext, * bitmapPtr, | |
1043 ¶ms)); | |
1044 | |
1045 if (!texture) { | |
1046 SkErrorInternals::SetError(kInternalError_SkError, | |
1047 "Couldn't convert bitmap to texture." ); | |
1048 return; | |
1049 } | |
1050 | |
1051 // Setup paint | |
1052 GrColor paintColor = (kAlpha_8_SkColorType == bitmapPtr->colorType() ) ? | |
1053 SkColor2GrColor(paint.getColor()) : | |
1054 SkColor2GrColorJustAlpha(paint.getColor()); | |
1055 | |
1056 GrPaint grPaint; | |
1057 | |
1058 // Create and insert texture effect | |
1059 SkAutoTUnref<const GrFragmentProcessor> fp; | |
1060 if (doBicubic) { | |
1061 fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager (), texture, | |
1062 SkMatrix::I(), | |
1063 tm)); | |
1064 } else { | |
1065 fp.reset(GrSimpleTextureEffect::Create(grPaint.getProcessorDataM anager(), texture, | |
1066 SkMatrix::I(), params)); | |
1067 } | |
1068 | |
1069 grPaint.addColorProcessor(fp); | |
1070 | |
1071 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fM atrix, true, | |
1072 &grPaint)) { | |
1073 return; | |
1074 } | |
1075 | |
1076 grPaint.setColor(paintColor); | |
1077 | |
1078 // Setup dst rect and final matrix | |
1079 SkRect dstRect = {0, 0, dstSize.fWidth, dstSize.fHeight}; | |
1080 | |
1081 SkRect devRect; | |
1082 draw.fMatrix->mapRect(&devRect, dstRect); | |
1083 | |
1084 SkMatrix matrix; | |
1085 matrix.setIDiv(bitmapPtr->width(), bitmapPtr->height()); | |
1086 | |
1087 SkMatrix uvToModel; | |
1088 if (!modelToUV.invert(&uvToModel)) { | |
1089 return; | |
1090 } | |
1091 matrix.preConcat(uvToModel); | |
1092 | |
1093 SkAutoTUnref<GrBatch> batch(GrRectBatchFactory::CreateFillAA(grPaint .getColor(), | |
1094 *draw.f Matrix, | |
1095 matrix, | |
1096 dstRect , | |
1097 devRect )); | |
1098 | |
1099 fDrawContext->drawBatch(fRenderTarget, fClip, grPaint, batch); | |
1100 } | |
1024 | 1101 |
1025 return; | 1102 return; |
1026 } | 1103 } |
1027 | 1104 |
1028 // If there is no mask filter than it is OK to handle the src rect -> dst re ct scaling using | 1105 // 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. | 1106 // the view matrix rather than a local matrix. |
1030 SkMatrix m; | 1107 SkMatrix m; |
1031 m.setScale(dstSize.fWidth / srcRect.width(), | 1108 m.setScale(dstSize.fWidth / srcRect.width(), |
1032 dstSize.fHeight / srcRect.height()); | 1109 dstSize.fHeight / srcRect.height()); |
1033 SkMatrix viewM = *draw.fMatrix; | 1110 SkMatrix viewM = *draw.fMatrix; |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1837 #endif | 1914 #endif |
1838 } | 1915 } |
1839 | 1916 |
1840 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1917 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1841 // We always return a transient cache, so it is freed after each | 1918 // We always return a transient cache, so it is freed after each |
1842 // filter traversal. | 1919 // filter traversal. |
1843 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1920 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1844 } | 1921 } |
1845 | 1922 |
1846 #endif | 1923 #endif |
OLD | NEW |