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

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

Issue 2335343008: Add optional sw generated path coverage mask caching (Closed)
Patch Set: Add .fs to literals in new gm Created 4 years, 2 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 | « src/gpu/GrSWMaskHelper.h ('k') | src/gpu/GrSoftwarePathRenderer.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 2012 Google Inc. 2 * Copyright 2012 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 "GrSWMaskHelper.h" 8 #include "GrSWMaskHelper.h"
9 9
10 #include "GrCaps.h" 10 #include "GrCaps.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 fDraw.fDst = fPixels; 92 fDraw.fDst = fPixels;
93 fRasterClip.setRect(bounds); 93 fRasterClip.setRect(bounds);
94 fDraw.fRC = &fRasterClip; 94 fDraw.fRC = &fRasterClip;
95 fDraw.fMatrix = &fMatrix; 95 fDraw.fMatrix = &fMatrix;
96 return true; 96 return true;
97 } 97 }
98 98
99 /** 99 /**
100 * Get a texture (from the texture cache) of the correct size & format. 100 * Get a texture (from the texture cache) of the correct size & format.
101 */ 101 */
102 GrTexture* GrSWMaskHelper::createTexture() { 102 GrTexture* GrSWMaskHelper::createTexture(TextureType textureType) {
103 GrSurfaceDesc desc; 103 GrSurfaceDesc desc;
104 desc.fWidth = fPixels.width(); 104 desc.fWidth = fPixels.width();
105 desc.fHeight = fPixels.height(); 105 desc.fHeight = fPixels.height();
106 desc.fConfig = kAlpha_8_GrPixelConfig; 106 desc.fConfig = kAlpha_8_GrPixelConfig;
107 107
108 return fTexProvider->createApproxTexture(desc); 108 if (TextureType::kApproximateFit == textureType) {
109 return fTexProvider->createApproxTexture(desc);
110 } else {
111 return fTexProvider->createTexture(desc, SkBudgeted::kYes);
112 }
109 } 113 }
110 114
111 /** 115 /**
112 * Move the result of the software mask generation back to the gpu 116 * Move the result of the software mask generation back to the gpu
113 */ 117 */
114 void GrSWMaskHelper::toTexture(GrTexture *texture) { 118 void GrSWMaskHelper::toTexture(GrTexture *texture) {
115 // Since we're uploading to it, and it's compressed, 'texture' shouldn't 119 // Since we're uploading to it, and it's compressed, 'texture' shouldn't
116 // have a render target. 120 // have a render target.
117 SkASSERT(!texture->asRenderTarget()); 121 SkASSERT(!texture->asRenderTarget());
118 122
(...skipping 12 matching lines...) Expand all
131 135
132 //////////////////////////////////////////////////////////////////////////////// 136 ////////////////////////////////////////////////////////////////////////////////
133 /** 137 /**
134 * Software rasterizes shape to A8 mask and uploads the result to a scratch text ure. Returns the 138 * Software rasterizes shape to A8 mask and uploads the result to a scratch text ure. Returns the
135 * resulting texture on success; nullptr on failure. 139 * resulting texture on success; nullptr on failure.
136 */ 140 */
137 GrTexture* GrSWMaskHelper::DrawShapeMaskToTexture(GrTextureProvider* texProvider , 141 GrTexture* GrSWMaskHelper::DrawShapeMaskToTexture(GrTextureProvider* texProvider ,
138 const GrShape& shape, 142 const GrShape& shape,
139 const SkIRect& resultBounds, 143 const SkIRect& resultBounds,
140 bool antiAlias, 144 bool antiAlias,
145 TextureType textureType,
141 const SkMatrix* matrix) { 146 const SkMatrix* matrix) {
142 GrSWMaskHelper helper(texProvider); 147 GrSWMaskHelper helper(texProvider);
143 148
144 if (!helper.init(resultBounds, matrix)) { 149 if (!helper.init(resultBounds, matrix)) {
145 return nullptr; 150 return nullptr;
146 } 151 }
147 152
148 helper.drawShape(shape, SkRegion::kReplace_Op, antiAlias, 0xFF); 153 helper.drawShape(shape, SkRegion::kReplace_Op, antiAlias, 0xFF);
149 154
150 GrTexture* texture(helper.createTexture()); 155 GrTexture* texture(helper.createTexture(textureType));
151 if (!texture) { 156 if (!texture) {
152 return nullptr; 157 return nullptr;
153 } 158 }
154 159
155 helper.toTexture(texture); 160 helper.toTexture(texture);
156 161
157 return texture; 162 return texture;
158 } 163 }
159 164
160 void GrSWMaskHelper::DrawToTargetWithShapeMask(GrTexture* texture, 165 void GrSWMaskHelper::DrawToTargetWithShapeMask(GrTexture* texture,
161 GrDrawContext* drawContext, 166 GrDrawContext* drawContext,
162 const GrPaint& paint, 167 const GrPaint& paint,
163 const GrUserStencilSettings& user StencilSettings, 168 const GrUserStencilSettings& user StencilSettings,
164 const GrClip& clip, 169 const GrClip& clip,
165 const SkMatrix& viewMatrix, 170 const SkMatrix& viewMatrix,
166 const SkIRect& rect) { 171 const SkIPoint& textureOriginInDe viceSpace,
172 const SkIRect& deviceSpaceRectToD raw) {
167 SkMatrix invert; 173 SkMatrix invert;
168 if (!viewMatrix.invert(&invert)) { 174 if (!viewMatrix.invert(&invert)) {
169 return; 175 return;
170 } 176 }
171 177
172 SkRect dstRect = SkRect::MakeLTRB(SK_Scalar1 * rect.fLeft, 178 SkRect dstRect = SkRect::Make(deviceSpaceRectToDraw);
173 SK_Scalar1 * rect.fTop,
174 SK_Scalar1 * rect.fRight,
175 SK_Scalar1 * rect.fBottom);
176 179
177 // We use device coords to compute the texture coordinates. We take the devi ce coords and apply 180 // We use device coords to compute the texture coordinates. We take the devi ce coords and apply
178 // a translation so that the top-left of the device bounds maps to 0,0, and then a scaling 181 // a translation so that the top-left of the device bounds maps to 0,0, and then a scaling
179 // matrix to normalized coords. 182 // matrix to normalized coords.
180 SkMatrix maskMatrix; 183 SkMatrix maskMatrix;
181 maskMatrix.setIDiv(texture->width(), texture->height()); 184 maskMatrix.setIDiv(texture->width(), texture->height());
182 maskMatrix.preTranslate(SkIntToScalar(-rect.fLeft), SkIntToScalar(-rect.fTop )); 185 maskMatrix.preTranslate(SkIntToScalar(-textureOriginInDeviceSpace.fX),
186 SkIntToScalar(-textureOriginInDeviceSpace.fY));
183 187
184 GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(paint)); 188 GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(paint));
185 pipelineBuilder.setUserStencil(&userStencilSettings); 189 pipelineBuilder.setUserStencil(&userStencilSettings);
186 190
187 pipelineBuilder.addCoverageFragmentProcessor( 191 pipelineBuilder.addCoverageFragmentProcessor(
188 GrSimpleTextureEffect::Make(texture, 192 GrSimpleTextureEffect::Make(texture,
189 nullptr, 193 nullptr,
190 maskMatrix, 194 maskMatrix,
191 GrTextureParams::kNone_Filt erMode, 195 GrTextureParams::kNone_Filt erMode,
192 kDevice_GrCoordSet)); 196 kDevice_GrCoordSet));
193 197
194 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(paint.ge tColor(), 198 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(paint.ge tColor(),
195 SkMatrix ::I(), 199 SkMatrix ::I(),
196 dstRect, nullptr, &invert)); 200 dstRect, nullptr, &invert));
197 drawContext->drawBatch(pipelineBuilder, clip, batch); 201 drawContext->drawBatch(pipelineBuilder, clip, batch);
198 } 202 }
OLDNEW
« no previous file with comments | « src/gpu/GrSWMaskHelper.h ('k') | src/gpu/GrSoftwarePathRenderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698