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

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

Issue 14854005: Add geometry-based rotated AA rect drawing path (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Updated to ToT Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « include/gpu/GrAARectRenderer.h ('k') | src/gpu/GrContext.cpp » ('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 "GrAARectRenderer.h" 8 #include "GrAARectRenderer.h"
9 #include "GrRefCnt.h" 9 #include "GrRefCnt.h"
10 #include "GrGpu.h" 10 #include "GrGpu.h"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 fAAStrokeRectIndexBuffer->updateData(gStrokeAARectIdx, 354 fAAStrokeRectIndexBuffer->updateData(gStrokeAARectIdx,
355 sizeof(gStrokeAARectIdx)); 355 sizeof(gStrokeAARectIdx));
356 GR_DEBUGASSERT(updated); 356 GR_DEBUGASSERT(updated);
357 } 357 }
358 } 358 }
359 return fAAStrokeRectIndexBuffer; 359 return fAAStrokeRectIndexBuffer;
360 } 360 }
361 361
362 void GrAARectRenderer::geometryFillAARect(GrGpu* gpu, 362 void GrAARectRenderer::geometryFillAARect(GrGpu* gpu,
363 GrDrawTarget* target, 363 GrDrawTarget* target,
364 const GrRect& rect,
365 const SkMatrix& combinedMatrix,
364 const GrRect& devRect, 366 const GrRect& devRect,
365 bool useVertexCoverage) { 367 bool useVertexCoverage) {
366 GrDrawState* drawState = target->drawState(); 368 GrDrawState* drawState = target->drawState();
367 369
368 set_aa_rect_vertex_attributes(drawState, useVertexCoverage); 370 set_aa_rect_vertex_attributes(drawState, useVertexCoverage);
369 371
370 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0); 372 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0);
371 if (!geo.succeeded()) { 373 if (!geo.succeeded()) {
372 GrPrintf("Failed to get space for vertices!\n"); 374 GrPrintf("Failed to get space for vertices!\n");
373 return; 375 return;
374 } 376 }
375 377
376 GrIndexBuffer* indexBuffer = this->aaFillRectIndexBuffer(gpu); 378 GrIndexBuffer* indexBuffer = this->aaFillRectIndexBuffer(gpu);
377 if (NULL == indexBuffer) { 379 if (NULL == indexBuffer) {
378 GrPrintf("Failed to create index buffer!\n"); 380 GrPrintf("Failed to create index buffer!\n");
379 return; 381 return;
380 } 382 }
381 383
382 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); 384 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
383 size_t vsize = drawState->getVertexSize(); 385 size_t vsize = drawState->getVertexSize();
384 GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize); 386 GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize);
385 387
386 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts); 388 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts);
387 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize); 389 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize);
388 390
389 set_inset_fan(fan0Pos, vsize, devRect, -SK_ScalarHalf, -SK_ScalarHalf); 391 if (combinedMatrix.rectStaysRect()) {
390 set_inset_fan(fan1Pos, vsize, devRect, SK_ScalarHalf, SK_ScalarHalf); 392 set_inset_fan(fan0Pos, vsize, devRect, -SK_ScalarHalf, -SK_ScalarHalf);
393 set_inset_fan(fan1Pos, vsize, devRect, SK_ScalarHalf, SK_ScalarHalf);
394 } else {
395 // compute transformed (1, 0) and (0, 1) vectors
396 SkVector vec[2] = {
397 { combinedMatrix[SkMatrix::kMScaleX], combinedMatrix[SkMatrix::kMSkewY ] },
398 { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix::kMScale Y] }
399 };
400
401 vec[0].normalize();
402 vec[0].scale(SK_ScalarHalf);
403 vec[1].normalize();
404 vec[1].scale(SK_ScalarHalf);
405
406 fan0Pos->setRectFan(rect.fLeft, rect.fTop,
407 rect.fRight, rect.fBottom, vsize);
408 combinedMatrix.mapPointsWithStride(fan0Pos, vsize, 4);
409
410 // TL
411 *((SkPoint*)((intptr_t)fan1Pos + 0 * vsize)) =
412 *((SkPoint*)((intptr_t)fan0Pos + 0 * vsize)) + vec[0] + vec[1];
413 *((SkPoint*)((intptr_t)fan0Pos + 0 * vsize)) -= vec[0] + vec[1];
414 // BL
415 *((SkPoint*)((intptr_t)fan1Pos + 1 * vsize)) =
416 *((SkPoint*)((intptr_t)fan0Pos + 1 * vsize)) + vec[0] - vec[1];
417 *((SkPoint*)((intptr_t)fan0Pos + 1 * vsize)) -= vec[0] - vec[1];
418 // BR
419 *((SkPoint*)((intptr_t)fan1Pos + 2 * vsize)) =
420 *((SkPoint*)((intptr_t)fan0Pos + 2 * vsize)) - vec[0] - vec[1];
421 *((SkPoint*)((intptr_t)fan0Pos + 2 * vsize)) += vec[0] + vec[1];
422 // TR
423 *((SkPoint*)((intptr_t)fan1Pos + 3 * vsize)) =
424 *((SkPoint*)((intptr_t)fan0Pos + 3 * vsize)) - vec[0] + vec[1];
425 *((SkPoint*)((intptr_t)fan0Pos + 3 * vsize)) += vec[0] - vec[1];
426 }
391 427
392 verts += sizeof(GrPoint); 428 verts += sizeof(GrPoint);
393 for (int i = 0; i < 4; ++i) { 429 for (int i = 0; i < 4; ++i) {
394 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; 430 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
395 } 431 }
396 432
397 GrColor innerColor; 433 GrColor innerColor;
398 if (useVertexCoverage) { 434 if (useVertexCoverage) {
399 innerColor = 0xffffffff; 435 innerColor = 0xffffffff;
400 } else { 436 } else {
401 innerColor = target->getDrawState().getColor(); 437 innerColor = target->getDrawState().getColor();
402 } 438 }
403 439
404 verts += 4 * vsize; 440 verts += 4 * vsize;
405 for (int i = 0; i < 4; ++i) { 441 for (int i = 0; i < 4; ++i) {
406 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor; 442 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor;
407 } 443 }
408 444
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 // The innermost rect has full coverage 694 // The innermost rect has full coverage
659 verts += 8 * vsize; 695 verts += 8 * vsize;
660 for (int i = 0; i < 4; ++i) { 696 for (int i = 0; i < 4; ++i) {
661 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; 697 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
662 } 698 }
663 699
664 target->setIndexSourceToBuffer(indexBuffer); 700 target->setIndexSourceToBuffer(indexBuffer);
665 target->drawIndexed(kTriangles_GrPrimitiveType, 701 target->drawIndexed(kTriangles_GrPrimitiveType,
666 0, 0, 16, aaStrokeRectIndexCount()); 702 0, 0, 16, aaStrokeRectIndexCount());
667 } 703 }
OLDNEW
« no previous file with comments | « include/gpu/GrAARectRenderer.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698