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

Side by Side Diff: src/gpu/batches/GrAADistanceFieldPathRenderer.cpp

Issue 1483103003: Make onPrepareDraws const (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: merge Created 5 years 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 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrAADistanceFieldPathRenderer.h" 9 #include "GrAADistanceFieldPathRenderer.h"
10 10
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 fStroke.setStrokeStyle(-1.0f); 136 fStroke.setStrokeStyle(-1.0f);
137 } 137 }
138 } 138 }
139 } 139 }
140 SkPath fPath; 140 SkPath fPath;
141 // The unique ID of the path involved in this draw. This may be differen t than the ID 141 // The unique ID of the path involved in this draw. This may be differen t than the ID
142 // in fPath since that path may have resulted from a SkStrokeRec::applyT oPath call. 142 // in fPath since that path may have resulted from a SkStrokeRec::applyT oPath call.
143 uint32_t fGenID; 143 uint32_t fGenID;
144 SkStrokeRec fStroke; 144 SkStrokeRec fStroke;
145 bool fAntiAlias; 145 bool fAntiAlias;
146 PathData* fPathData;
147 }; 146 };
148 147
149 static GrDrawBatch* Create(const Geometry& geometry, GrColor color, const Sk Matrix& viewMatrix, 148 static GrDrawBatch* Create(const Geometry& geometry, GrColor color, const Sk Matrix& viewMatrix,
150 GrBatchAtlas* atlas, PathCache* pathCache, PathDa taList* pathList) { 149 GrBatchAtlas* atlas, PathCache* pathCache, PathDa taList* pathList) {
151 return new AADistanceFieldPathBatch(geometry, color, viewMatrix, atlas, pathCache, 150 return new AADistanceFieldPathBatch(geometry, color, viewMatrix, atlas, pathCache,
152 pathList); 151 pathList);
153 } 152 }
154 153
155 const char* name() const override { return "AADistanceFieldPathBatch"; } 154 const char* name() const override { return "AADistanceFieldPathBatch"; }
156 155
(...skipping 19 matching lines...) Expand all
176 fBatch.fCoverageIgnored = !overrides.readsCoverage(); 175 fBatch.fCoverageIgnored = !overrides.readsCoverage();
177 } 176 }
178 177
179 struct FlushInfo { 178 struct FlushInfo {
180 SkAutoTUnref<const GrVertexBuffer> fVertexBuffer; 179 SkAutoTUnref<const GrVertexBuffer> fVertexBuffer;
181 SkAutoTUnref<const GrIndexBuffer> fIndexBuffer; 180 SkAutoTUnref<const GrIndexBuffer> fIndexBuffer;
182 int fVertexOffset; 181 int fVertexOffset;
183 int fInstancesToFlush; 182 int fInstancesToFlush;
184 }; 183 };
185 184
186 void onPrepareDraws(Target* target) override { 185 void onPrepareDraws(Target* target) const override {
187 int instanceCount = fGeoData.count(); 186 int instanceCount = fGeoData.count();
188 187
189 SkMatrix invert; 188 SkMatrix invert;
190 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { 189 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) {
191 SkDebugf("Could not invert viewmatrix\n"); 190 SkDebugf("Could not invert viewmatrix\n");
192 return; 191 return;
193 } 192 }
194 193
195 uint32_t flags = 0; 194 uint32_t flags = 0;
196 flags |= this->viewMatrix().isSimilarity() ? kSimilarity_DistanceFieldEf fectFlag : 0; 195 flags |= this->viewMatrix().isSimilarity() ? kSimilarity_DistanceFieldEf fectFlag : 0;
(...skipping 25 matching lines...) Expand all
222 &flushInfo.fVertexOffset); 221 &flushInfo.fVertexOffset);
223 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); 222 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer));
224 flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuf fer()); 223 flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuf fer());
225 if (!vertices || !flushInfo.fIndexBuffer) { 224 if (!vertices || !flushInfo.fIndexBuffer) {
226 SkDebugf("Could not allocate vertices\n"); 225 SkDebugf("Could not allocate vertices\n");
227 return; 226 return;
228 } 227 }
229 228
230 flushInfo.fInstancesToFlush = 0; 229 flushInfo.fInstancesToFlush = 0;
231 for (int i = 0; i < instanceCount; i++) { 230 for (int i = 0; i < instanceCount; i++) {
232 Geometry& args = fGeoData[i]; 231 const Geometry& args = fGeoData[i];
233 232
234 // get mip level 233 // get mip level
235 SkScalar maxScale = this->viewMatrix().getMaxScale(); 234 SkScalar maxScale = this->viewMatrix().getMaxScale();
236 const SkRect& bounds = args.fPath.getBounds(); 235 const SkRect& bounds = args.fPath.getBounds();
237 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); 236 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height());
238 SkScalar size = maxScale * maxDim; 237 SkScalar size = maxScale * maxDim;
239 uint32_t desiredDimension; 238 uint32_t desiredDimension;
240 if (size <= kSmallMIP) { 239 if (size <= kSmallMIP) {
241 desiredDimension = kSmallMIP; 240 desiredDimension = kSmallMIP;
242 } else if (size <= kMediumMIP) { 241 } else if (size <= kMediumMIP) {
243 desiredDimension = kMediumMIP; 242 desiredDimension = kMediumMIP;
244 } else { 243 } else {
245 desiredDimension = kLargeMIP; 244 desiredDimension = kLargeMIP;
246 } 245 }
247 246
248 // check to see if path is cached 247 // check to see if path is cached
249 PathData::Key key(args.fGenID, desiredDimension, args.fStroke); 248 PathData::Key key(args.fGenID, desiredDimension, args.fStroke);
250 args.fPathData = fPathCache->find(key); 249 PathData* pathData = fPathCache->find(key);
251 if (nullptr == args.fPathData || !atlas->hasID(args.fPathData->fID)) { 250 if (nullptr == pathData || !atlas->hasID(pathData->fID)) {
252 // Remove the stale cache entry 251 // Remove the stale cache entry
253 if (args.fPathData) { 252 if (pathData) {
254 fPathCache->remove(args.fPathData->fKey); 253 fPathCache->remove(pathData->fKey);
255 fPathList->remove(args.fPathData); 254 fPathList->remove(pathData);
256 delete args.fPathData; 255 delete pathData;
257 } 256 }
258 SkScalar scale = desiredDimension/maxDim; 257 SkScalar scale = desiredDimension/maxDim;
259 args.fPathData = new PathData; 258 pathData = new PathData;
260 if (!this->addPathToAtlas(target, 259 if (!this->addPathToAtlas(target,
261 dfProcessor, 260 dfProcessor,
262 this->pipeline(), 261 this->pipeline(),
263 &flushInfo, 262 &flushInfo,
264 atlas, 263 atlas,
265 args.fPathData, 264 pathData,
266 args.fPath, 265 args.fPath,
267 args.fGenID, 266 args.fGenID,
268 args.fStroke, 267 args.fStroke,
269 args.fAntiAlias, 268 args.fAntiAlias,
270 desiredDimension, 269 desiredDimension,
271 scale)) { 270 scale)) {
272 SkDebugf("Can't rasterize path\n"); 271 SkDebugf("Can't rasterize path\n");
273 return; 272 return;
274 } 273 }
275 } 274 }
276 275
277 atlas->setLastUseToken(args.fPathData->fID, target->currentToken()); 276 atlas->setLastUseToken(pathData->fID, target->currentToken());
278 277
279 // Now set vertices 278 // Now set vertices
280 intptr_t offset = reinterpret_cast<intptr_t>(vertices); 279 intptr_t offset = reinterpret_cast<intptr_t>(vertices);
281 offset += i * kVerticesPerQuad * vertexStride; 280 offset += i * kVerticesPerQuad * vertexStride;
282 SkPoint* positions = reinterpret_cast<SkPoint*>(offset); 281 SkPoint* positions = reinterpret_cast<SkPoint*>(offset);
283 this->writePathVertices(target, 282 this->writePathVertices(target,
284 atlas, 283 atlas,
285 this->pipeline(), 284 this->pipeline(),
286 dfProcessor, 285 dfProcessor,
287 positions, 286 positions,
288 vertexStride, 287 vertexStride,
289 this->viewMatrix(), 288 this->viewMatrix(),
290 args.fPath, 289 args.fPath,
291 args.fPathData); 290 pathData);
292 flushInfo.fInstancesToFlush++; 291 flushInfo.fInstancesToFlush++;
293 } 292 }
294 293
295 this->flush(target, &flushInfo); 294 this->flush(target, &flushInfo);
296 } 295 }
297 296
298 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 297 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
299 298
300 AADistanceFieldPathBatch(const Geometry& geometry, GrColor color, const SkMa trix& viewMatrix, 299 AADistanceFieldPathBatch(const Geometry& geometry, GrColor color, const SkMa trix& viewMatrix,
301 GrBatchAtlas* atlas, 300 GrBatchAtlas* atlas,
302 PathCache* pathCache, PathDataList* pathList) 301 PathCache* pathCache, PathDataList* pathList)
303 : INHERITED(ClassID()) { 302 : INHERITED(ClassID()) {
304 fBatch.fColor = color; 303 fBatch.fColor = color;
305 fBatch.fViewMatrix = viewMatrix; 304 fBatch.fViewMatrix = viewMatrix;
306 fGeoData.push_back(geometry); 305 fGeoData.push_back(geometry);
307 fGeoData.back().fPathData = nullptr;
308 306
309 fAtlas = atlas; 307 fAtlas = atlas;
310 fPathCache = pathCache; 308 fPathCache = pathCache;
311 fPathList = pathList; 309 fPathList = pathList;
312 310
313 // Compute bounds 311 // Compute bounds
314 fBounds = geometry.fPath.getBounds(); 312 fBounds = geometry.fPath.getBounds();
315 viewMatrix.mapRect(&fBounds); 313 viewMatrix.mapRect(&fBounds);
316 } 314 }
317 315
318 bool addPathToAtlas(GrVertexBatch::Target* target, 316 bool addPathToAtlas(GrVertexBatch::Target* target,
319 const GrGeometryProcessor* dfProcessor, 317 const GrGeometryProcessor* dfProcessor,
320 const GrPipeline* pipeline, 318 const GrPipeline* pipeline,
321 FlushInfo* flushInfo, 319 FlushInfo* flushInfo,
322 GrBatchAtlas* atlas, 320 GrBatchAtlas* atlas,
323 PathData* pathData, 321 PathData* pathData,
324 const SkPath& path, 322 const SkPath& path,
325 uint32_t genID, 323 uint32_t genID,
326 const SkStrokeRec& stroke, 324 const SkStrokeRec& stroke,
327 bool antiAlias, 325 bool antiAlias,
328 uint32_t dimension, 326 uint32_t dimension,
329 SkScalar scale) { 327 SkScalar scale) const {
330 const SkRect& bounds = path.getBounds(); 328 const SkRect& bounds = path.getBounds();
331 329
332 // generate bounding rect for bitmap draw 330 // generate bounding rect for bitmap draw
333 SkRect scaledBounds = bounds; 331 SkRect scaledBounds = bounds;
334 // scale to mip level size 332 // scale to mip level size
335 scaledBounds.fLeft *= scale; 333 scaledBounds.fLeft *= scale;
336 scaledBounds.fTop *= scale; 334 scaledBounds.fTop *= scale;
337 scaledBounds.fRight *= scale; 335 scaledBounds.fRight *= scale;
338 scaledBounds.fBottom *= scale; 336 scaledBounds.fBottom *= scale;
339 // move the origin to an integer boundary (gives better results) 337 // move the origin to an integer boundary (gives better results)
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 434 }
437 435
438 void writePathVertices(GrDrawBatch::Target* target, 436 void writePathVertices(GrDrawBatch::Target* target,
439 GrBatchAtlas* atlas, 437 GrBatchAtlas* atlas,
440 const GrPipeline* pipeline, 438 const GrPipeline* pipeline,
441 const GrGeometryProcessor* gp, 439 const GrGeometryProcessor* gp,
442 SkPoint* positions, 440 SkPoint* positions,
443 size_t vertexStride, 441 size_t vertexStride,
444 const SkMatrix& viewMatrix, 442 const SkMatrix& viewMatrix,
445 const SkPath& path, 443 const SkPath& path,
446 const PathData* pathData) { 444 const PathData* pathData) const {
447 GrTexture* texture = atlas->getTexture(); 445 GrTexture* texture = atlas->getTexture();
448 446
449 SkScalar dx = pathData->fBounds.fLeft; 447 SkScalar dx = pathData->fBounds.fLeft;
450 SkScalar dy = pathData->fBounds.fTop; 448 SkScalar dy = pathData->fBounds.fTop;
451 SkScalar width = pathData->fBounds.width(); 449 SkScalar width = pathData->fBounds.width();
452 SkScalar height = pathData->fBounds.height(); 450 SkScalar height = pathData->fBounds.height();
453 451
454 SkScalar invScale = 1.0f / pathData->fScale; 452 SkScalar invScale = 1.0f / pathData->fScale;
455 dx *= invScale; 453 dx *= invScale;
456 dy *= invScale; 454 dy *= invScale;
(...skipping 12 matching lines...) Expand all
469 467
470 // vertex texture coords 468 // vertex texture coords
471 SkPoint* textureCoords = positions + 1; 469 SkPoint* textureCoords = positions + 1;
472 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normaliz eFixedX(tx)), 470 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normaliz eFixedX(tx)),
473 SkFixedToFloat(texture->texturePriv().normaliz eFixedY(ty)), 471 SkFixedToFloat(texture->texturePriv().normaliz eFixedY(ty)),
474 SkFixedToFloat(texture->texturePriv().normaliz eFixedX(tx + tw)), 472 SkFixedToFloat(texture->texturePriv().normaliz eFixedX(tx + tw)),
475 SkFixedToFloat(texture->texturePriv().normaliz eFixedY(ty + th)), 473 SkFixedToFloat(texture->texturePriv().normaliz eFixedY(ty + th)),
476 vertexStride); 474 vertexStride);
477 } 475 }
478 476
479 void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) { 477 void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) const {
480 GrVertices vertices; 478 GrVertices vertices;
481 int maxInstancesPerDraw = flushInfo->fIndexBuffer->maxQuads(); 479 int maxInstancesPerDraw = flushInfo->fIndexBuffer->maxQuads();
482 vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuf fer, 480 vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuf fer,
483 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, kVerticesPerQuad, 481 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, kVerticesPerQuad,
484 kIndicesPerQuad, flushInfo->fInstancesToFlush, maxInstancesPerDraw); 482 kIndicesPerQuad, flushInfo->fInstancesToFlush, maxInstancesPerDraw);
485 target->draw(vertices); 483 target->draw(vertices);
486 flushInfo->fVertexOffset += kVerticesPerQuad * flushInfo->fInstancesToFl ush; 484 flushInfo->fVertexOffset += kVerticesPerQuad * flushInfo->fInstancesToFl ush;
487 flushInfo->fInstancesToFlush = 0; 485 flushInfo->fInstancesToFlush = 0;
488 } 486 }
489 487
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 geometry.fAntiAlias = random->nextBool(); 633 geometry.fAntiAlias = random->nextBool();
636 geometry.fGenID = random->nextU(); 634 geometry.fGenID = random->nextU();
637 635
638 return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix, 636 return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix,
639 gTestStruct.fAtlas, 637 gTestStruct.fAtlas,
640 &gTestStruct.fPathCache, 638 &gTestStruct.fPathCache,
641 &gTestStruct.fPathList); 639 &gTestStruct.fPathList);
642 } 640 }
643 641
644 #endif 642 #endif
OLDNEW
« no previous file with comments | « src/gpu/batches/GrAAConvexPathRenderer.cpp ('k') | src/gpu/batches/GrAAHairLinePathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698