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

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

Issue 1293543002: drawBitmapImage can batch across AA rects (Closed) Base URL: https://skia.googlesource.com/skia.git@gmfordrawimagerect
Patch Set: tweaks 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 | « src/gpu/SkGpuDevice.cpp ('k') | 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 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 "GrAAFillRectBatch.h" 8 #include "GrAAFillRectBatch.h"
9 9
10 #include "GrColor.h" 10 #include "GrColor.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 *((SkPoint*)((intptr_t)fan1Pos + 3 * vertexStride)) = 243 *((SkPoint*)((intptr_t)fan1Pos + 3 * vertexStride)) =
244 *((SkPoint*)((intptr_t)fan0Pos + 3 * vertexStride)) - vec[0] + v ec[1]; 244 *((SkPoint*)((intptr_t)fan0Pos + 3 * vertexStride)) - vec[0] + v ec[1];
245 *((SkPoint*)((intptr_t)fan0Pos + 3 * vertexStride)) += vec[0] - vec[ 1]; 245 *((SkPoint*)((intptr_t)fan0Pos + 3 * vertexStride)) += vec[0] - vec[ 1];
246 } 246 }
247 247
248 Base::FillInAttributes(verts, vertexStride, fan0Pos, args); 248 Base::FillInAttributes(verts, vertexStride, fan0Pos, args);
249 249
250 // Make verts point to vertex color and then set all the color and cover age vertex attrs 250 // Make verts point to vertex color and then set all the color and cover age vertex attrs
251 // values. 251 // values.
252 verts += sizeof(SkPoint); 252 verts += sizeof(SkPoint);
253
254 // The coverage offset is always the last vertex attribute
255 intptr_t coverageOffset = vertexStride - sizeof(GrColor) - sizeof(SkPoin t);
253 for (int i = 0; i < 4; ++i) { 256 for (int i = 0; i < 4; ++i) {
254 if (tweakAlphaForCoverage) { 257 if (tweakAlphaForCoverage) {
255 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = 0; 258 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = 0;
256 } else { 259 } else {
257 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = args.fCo lor; 260 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = args.fCo lor;
258 *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrCo lor)) = 0; 261 *reinterpret_cast<float*>(verts + i * vertexStride + coverageOff set) = 0;
259 } 262 }
260 } 263 }
261 264
262 int scale; 265 int scale;
263 if (inset < SK_ScalarHalf) { 266 if (inset < SK_ScalarHalf) {
264 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)) ; 267 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)) ;
265 SkASSERT(scale >= 0 && scale <= 255); 268 SkASSERT(scale >= 0 && scale <= 255);
266 } else { 269 } else {
267 scale = 0xff; 270 scale = 0xff;
268 } 271 }
269 272
270 verts += 4 * vertexStride; 273 verts += 4 * vertexStride;
271 274
272 float innerCoverage = GrNormalizeByteToFloat(scale); 275 float innerCoverage = GrNormalizeByteToFloat(scale);
273 GrColor scaledColor = (0xff == scale) ? args.fColor : SkAlphaMulQ(args.f Color, scale); 276 GrColor scaledColor = (0xff == scale) ? args.fColor : SkAlphaMulQ(args.f Color, scale);
274 277
275 for (int i = 0; i < 4; ++i) { 278 for (int i = 0; i < 4; ++i) {
276 if (tweakAlphaForCoverage) { 279 if (tweakAlphaForCoverage) {
277 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledCo lor; 280 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledCo lor;
278 } else { 281 } else {
279 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = args.fCo lor; 282 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = args.fCo lor;
280 *reinterpret_cast<float*>(verts + i * vertexStride + 283 *reinterpret_cast<float*>(verts + i * vertexStride +
281 sizeof(GrColor)) = innerCoverage; 284 coverageOffset) = innerCoverage;
282 } 285 }
283 } 286 }
284 } 287 }
285 288
286 static const GrGeometryProcessor* CreateFillRectGP( 289 static const GrGeometryProcessor* CreateFillRectGP(
287 bool tweakAlphaForCoverage, 290 bool tweakAlphaForCoverage,
288 const SkMatrix& viewMatrix, 291 const SkMatrix& viewMatrix,
289 bool usesLocalCoords, 292 bool usesLocalCoords,
290 GrDefaultGeoProcFactory::LocalCoords::T ype localCoordsType, 293 GrDefaultGeoProcFactory::LocalCoords::T ype localCoordsType,
291 bool coverageIgnored) { 294 bool coverageIgnored) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 388
386 inline static void FillInAttributes(intptr_t vertices, size_t vertexStride, 389 inline static void FillInAttributes(intptr_t vertices, size_t vertexStride,
387 SkPoint* fan0Pos, const Geometry& args) { 390 SkPoint* fan0Pos, const Geometry& args) {
388 SkMatrix invViewMatrix; 391 SkMatrix invViewMatrix;
389 if (!args.fViewMatrix.invert(&invViewMatrix)) { 392 if (!args.fViewMatrix.invert(&invViewMatrix)) {
390 SkASSERT(false); 393 SkASSERT(false);
391 invViewMatrix = SkMatrix::I(); 394 invViewMatrix = SkMatrix::I();
392 } 395 }
393 SkMatrix localCoordMatrix; 396 SkMatrix localCoordMatrix;
394 localCoordMatrix.setConcat(args.fLocalMatrix, invViewMatrix); 397 localCoordMatrix.setConcat(args.fLocalMatrix, invViewMatrix);
395 SkPoint* fan0Loc = reinterpret_cast<SkPoint*>(vertices + vertexStride - sizeof(SkPoint)); 398 SkPoint* fan0Loc = reinterpret_cast<SkPoint*>(vertices + sizeof(SkPoint) + sizeof(GrColor));
396 localCoordMatrix.mapPointsWithStride(fan0Loc, fan0Pos, vertexStride, 8); 399 localCoordMatrix.mapPointsWithStride(fan0Loc, fan0Pos, vertexStride, 8);
397 } 400 }
398 }; 401 };
399 402
400 typedef AAFillRectBatch<AAFillRectBatchNoLocalMatrixImp> AAFillRectBatchNoLocalM atrix; 403 typedef AAFillRectBatch<AAFillRectBatchNoLocalMatrixImp> AAFillRectBatchNoLocalM atrix;
401 typedef AAFillRectBatch<AAFillRectBatchLocalMatrixImp> AAFillRectBatchLocalMatri x; 404 typedef AAFillRectBatch<AAFillRectBatchLocalMatrixImp> AAFillRectBatchLocalMatri x;
402 405
403 namespace GrAAFillRectBatch { 406 namespace GrAAFillRectBatch {
404 407
405 GrDrawBatch* Create(GrColor color, 408 GrDrawBatch* Create(GrColor color,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { 454 DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) {
452 GrColor color = GrRandomColor(random); 455 GrColor color = GrRandomColor(random);
453 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); 456 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
454 SkMatrix localMatrix = GrTest::TestMatrix(random); 457 SkMatrix localMatrix = GrTest::TestMatrix(random);
455 SkRect rect = GrTest::TestRect(random); 458 SkRect rect = GrTest::TestRect(random);
456 SkRect devRect = GrTest::TestRect(random); 459 SkRect devRect = GrTest::TestRect(random);
457 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect, devRe ct); 460 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect, devRe ct);
458 } 461 }
459 462
460 #endif 463 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | src/gpu/batches/GrRectBatchFactory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698