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

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

Issue 1438663004: API changes to GrTextureAdjuster. (Closed) Base URL: https://skia.googlesource.com/skia.git@dividemat
Patch Set: back away from lambdas 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 2015 Google Inc. 2 * Copyright 2015 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 const SkRect* dstRect, 58 const SkRect* dstRect,
59 SkCanvas::SrcRectConstraint constraint, 59 SkCanvas::SrcRectConstraint constraint,
60 const SkMatrix& viewMatrix, 60 const SkMatrix& viewMatrix,
61 const GrClip& clip, 61 const GrClip& clip,
62 const SkPaint& paint) { 62 const SkPaint& paint) {
63 // Figure out the actual dst and src rect by clipping the src rect to the bo unds of the 63 // Figure out the actual dst and src rect by clipping the src rect to the bo unds of the
64 // adjuster. If the src rect is clipped then the dst rect must be recomputed . Also determine 64 // adjuster. If the src rect is clipped then the dst rect must be recomputed . Also determine
65 // the matrix that maps the src rect to the dst rect. 65 // the matrix that maps the src rect to the dst rect.
66 SkRect clippedSrcRect; 66 SkRect clippedSrcRect;
67 SkRect clippedDstRect; 67 SkRect clippedDstRect;
68 SkIRect contentIBounds; 68 const SkRect srcBounds = SkRect::MakeIWH(adjuster->width(), adjuster->height ());
69 adjuster->getContentArea(&contentIBounds);
70 const SkRect contentBounds = SkRect::Make(contentIBounds);
71 SkMatrix srcToDstMatrix; 69 SkMatrix srcToDstMatrix;
72 if (srcRect) { 70 if (srcRect) {
73 if (!dstRect) { 71 if (!dstRect) {
74 dstRect = &contentBounds; 72 dstRect = &srcBounds;
75 } 73 }
76 if (!contentBounds.contains(*srcRect)) { 74 if (!srcBounds.contains(*srcRect)) {
77 clippedSrcRect = *srcRect; 75 clippedSrcRect = *srcRect;
78 if (!clippedSrcRect.intersect(contentBounds)) { 76 if (!clippedSrcRect.intersect(srcBounds)) {
79 return; 77 return;
80 } 78 }
81 if (!srcToDstMatrix.setRectToRect(*srcRect, *dstRect, SkMatrix::kFil l_ScaleToFit)) { 79 if (!srcToDstMatrix.setRectToRect(*srcRect, *dstRect, SkMatrix::kFil l_ScaleToFit)) {
82 return; 80 return;
83 } 81 }
84 srcToDstMatrix.mapRect(&clippedDstRect, clippedSrcRect); 82 srcToDstMatrix.mapRect(&clippedDstRect, clippedSrcRect);
85 } else { 83 } else {
86 clippedSrcRect = *srcRect; 84 clippedSrcRect = *srcRect;
87 clippedDstRect = *dstRect; 85 clippedDstRect = *dstRect;
88 if (!srcToDstMatrix.setRectToRect(*srcRect, *dstRect, SkMatrix::kFil l_ScaleToFit)) { 86 if (!srcToDstMatrix.setRectToRect(*srcRect, *dstRect, SkMatrix::kFil l_ScaleToFit)) {
89 return; 87 return;
90 } 88 }
91 } 89 }
92 } else { 90 } else {
93 clippedSrcRect = contentBounds; 91 clippedSrcRect = srcBounds;
94 if (dstRect) { 92 if (dstRect) {
95 clippedDstRect = *dstRect; 93 clippedDstRect = *dstRect;
96 if (!srcToDstMatrix.setRectToRect(contentBounds, *dstRect, 94 if (!srcToDstMatrix.setRectToRect(srcBounds, *dstRect, SkMatrix::kFi ll_ScaleToFit)) {
97 SkMatrix::kFill_ScaleToFit)) {
98 return; 95 return;
99 } 96 }
100 } else { 97 } else {
101 clippedDstRect = contentBounds; 98 clippedDstRect = srcBounds;
102 srcToDstMatrix.reset(); 99 srcToDstMatrix.reset();
103 } 100 }
104 } 101 }
105 102
106 this->drawTextureAdjusterImpl(adjuster, alphaOnly, clippedSrcRect, clippedDs tRect, constraint, 103 this->drawTextureAdjusterImpl(adjuster, alphaOnly, clippedSrcRect, clippedDs tRect, constraint,
107 viewMatrix, srcToDstMatrix, clip, paint); 104 viewMatrix, srcToDstMatrix, clip, paint);
108 } 105 }
109 106
110 void SkGpuDevice::drawTextureAdjusterImpl(GrTextureAdjuster* adjuster, 107 void SkGpuDevice::drawTextureAdjusterImpl(GrTextureAdjuster* adjuster,
111 bool alphaTexture, 108 bool alphaTexture,
112 const SkRect& clippedSrcRect, 109 const SkRect& clippedSrcRect,
113 const SkRect& clippedDstRect, 110 const SkRect& clippedDstRect,
114 SkCanvas::SrcRectConstraint constraint , 111 SkCanvas::SrcRectConstraint constraint ,
115 const SkMatrix& viewMatrix, 112 const SkMatrix& viewMatrix,
116 const SkMatrix& srcToDstMatrix, 113 const SkMatrix& srcToDstMatrix,
117 const GrClip& clip, 114 const GrClip& clip,
118 const SkPaint& paint) { 115 const SkPaint& paint) {
119 // Specifying the texture coords as local coordinates is an attempt to enabl e more batching 116 // Specifying the texture coords as local coordinates is an attempt to enabl e more batching
120 // by not baking anything about the srcRect, dstRect, or viewMatrix, into th e texture FP. In 117 // by not baking anything about the srcRect, dstRect, or viewMatrix, into th e texture FP. In
121 // the future this should be an opaque optimization enabled by the combinati on of batch/GP and 118 // the future this should be an opaque optimization enabled by the combinati on of batch/GP and
122 // FP. 119 // FP.
123 SkMatrix textureFPMatrix;
124 const SkMaskFilter* mf = paint.getMaskFilter(); 120 const SkMaskFilter* mf = paint.getMaskFilter();
125 GrTexture* texture = adjuster->originalTexture();
126 // The shader expects proper local coords, so we can't replace local coords with texture coords 121 // The shader expects proper local coords, so we can't replace local coords with texture coords
127 // if the shader will be used. If we have a mask filter we will change the u nderlying geometry 122 // if the shader will be used. If we have a mask filter we will change the u nderlying geometry
128 // that is rendered. 123 // that is rendered.
129 bool canUseTextureCoordsAsLocalCoords = !use_shader(alphaTexture, paint) && !mf; 124 bool canUseTextureCoordsAsLocalCoords = !use_shader(alphaTexture, paint) && !mf;
130 if (canUseTextureCoordsAsLocalCoords) {
131 textureFPMatrix.setIDiv(texture->width(), texture->height());
132 } else {
133 if (!srcToDstMatrix.invert(&textureFPMatrix)) {
134 return;
135 }
136 textureFPMatrix.postIDiv(texture->width(), texture->height());
137 }
138 125
139 bool doBicubic; 126 bool doBicubic;
140 GrTextureParams::FilterMode fm = 127 GrTextureParams::FilterMode fm =
141 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewMatrix, sr cToDstMatrix, 128 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewMatrix, sr cToDstMatrix,
142 &doBicubic); 129 &doBicubic);
143 const GrTextureParams::FilterMode* filterMode = doBicubic ? nullptr : &fm; 130 const GrTextureParams::FilterMode* filterMode = doBicubic ? nullptr : &fm;
144 131
145 GrTextureAdjuster::FilterConstraint constraintMode; 132 GrTextureAdjuster::FilterConstraint constraintMode;
146 if (SkCanvas::kFast_SrcRectConstraint == constraint) { 133 if (SkCanvas::kFast_SrcRectConstraint == constraint) {
147 constraintMode = GrTextureAdjuster::kNo_FilterConstraint; 134 constraintMode = GrTextureAdjuster::kNo_FilterConstraint;
148 } else { 135 } else {
149 constraintMode = GrTextureAdjuster::kYes_FilterConstraint; 136 constraintMode = GrTextureAdjuster::kYes_FilterConstraint;
150 } 137 }
151 138
152 // If we have to outset for AA then we will generate texture coords outside the src rect. The 139 // If we have to outset for AA then we will generate texture coords outside the src rect. The
153 // same happens for any mask filter that extends the bounds rendered in the dst. 140 // same happens for any mask filter that extends the bounds rendered in the dst.
154 // This is conservative as a mask filter does not have to expand the bounds rendered. 141 // This is conservative as a mask filter does not have to expand the bounds rendered.
155 bool coordsAllInsideSrcRect = !paint.isAntiAlias() && !mf; 142 bool coordsAllInsideSrcRect = !paint.isAntiAlias() && !mf;
156 143
144 const SkMatrix* textureMatrix;
145 SkMatrix tempMatrix;
146 if (canUseTextureCoordsAsLocalCoords) {
147 textureMatrix = &SkMatrix::I();
148 } else {
149 if (!srcToDstMatrix.invert(&tempMatrix)) {
150 return;
151 }
152 textureMatrix = &tempMatrix;
153 }
157 SkAutoTUnref<const GrFragmentProcessor> fp(adjuster->createFragmentProcessor ( 154 SkAutoTUnref<const GrFragmentProcessor> fp(adjuster->createFragmentProcessor (
158 textureFPMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect, filterMode)); 155 *textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect, filterMode));
159 if (!fp) { 156 if (!fp) {
160 return; 157 return;
161 } 158 }
162 fp.reset(mix_texture_fp_with_paint_color_and_shader(fp, alphaTexture, this-> context(), 159 fp.reset(mix_texture_fp_with_paint_color_and_shader(fp, alphaTexture, this-> context(),
163 viewMatrix, paint)); 160 viewMatrix, paint));
164 GrPaint grPaint; 161 GrPaint grPaint;
165 if (!SkPaintToGrPaintReplaceShader(fContext, paint, fp, &grPaint)) { 162 if (!SkPaintToGrPaintReplaceShader(fContext, paint, fp, &grPaint)) {
166 return; 163 return;
167 } 164 }
168 165
(...skipping 19 matching lines...) Expand all
188 rec, 185 rec,
189 rrect)) { 186 rrect)) {
190 return; 187 return;
191 } 188 }
192 SkPath rectPath; 189 SkPath rectPath;
193 rectPath.addRect(clippedDstRect); 190 rectPath.addRect(clippedDstRect);
194 GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext, fRenderTa rget, fClip, 191 GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext, fRenderTa rget, fClip,
195 rectPath, &grPaint, viewMatrix, mf, pain t.getPathEffect(), 192 rectPath, &grPaint, viewMatrix, mf, pain t.getPathEffect(),
196 GrStrokeInfo::FillInfo()); 193 GrStrokeInfo::FillInfo());
197 } 194 }
OLDNEW
« src/gpu/GrTextureParamsAdjuster.h ('K') | « src/gpu/GrTextureParamsAdjuster.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698