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

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

Issue 12676027: Replace edge types with GrEdgeEffect (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 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 "GrAAHairLinePathRenderer.h" 9 #include "GrAAHairLinePathRenderer.h"
10 10
11 #include "GrContext.h" 11 #include "GrContext.h"
12 #include "GrDrawState.h" 12 #include "GrDrawState.h"
13 #include "GrGpu.h" 13 #include "GrGpu.h"
14 #include "GrIndexBuffer.h" 14 #include "GrIndexBuffer.h"
15 #include "GrPathUtils.h" 15 #include "GrPathUtils.h"
16 #include "SkGeometry.h" 16 #include "SkGeometry.h"
17 #include "SkStroke.h" 17 #include "SkStroke.h"
18 #include "SkTemplates.h" 18 #include "SkTemplates.h"
19 19
20 #include "effects/GrEdgeEffect.h"
21
20 namespace { 22 namespace {
21 // quadratics are rendered as 5-sided polys in order to bound the 23 // quadratics are rendered as 5-sided polys in order to bound the
22 // AA stroke around the center-curve. See comments in push_quad_index_buffer and 24 // AA stroke around the center-curve. See comments in push_quad_index_buffer and
23 // bloat_quad. 25 // bloat_quad.
24 static const int kVertsPerQuad = 5; 26 static const int kVertsPerQuad = 5;
25 static const int kIdxsPerQuad = 9; 27 static const int kIdxsPerQuad = 9;
26 28
27 static const int kVertsPerLineSeg = 4; 29 static const int kVertsPerLineSeg = 4;
28 static const int kIdxsPerLineSeg = 6; 30 static const int kIdxsPerLineSeg = 6;
29 31
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 502
501 GrIRect devClipBounds; 503 GrIRect devClipBounds;
502 target->getClip()->getConservativeBounds(drawState->getRenderTarget(), 504 target->getClip()->getConservativeBounds(drawState->getRenderTarget(),
503 &devClipBounds); 505 &devClipBounds);
504 506
505 // position + edge 507 // position + edge
506 static const GrVertexAttrib kAttribs[] = { 508 static const GrVertexAttrib kAttribs[] = {
507 {kVec2f_GrVertexAttribType, 0}, 509 {kVec2f_GrVertexAttribType, 0},
508 {kVec4f_GrVertexAttribType, sizeof(GrPoint)} 510 {kVec4f_GrVertexAttribType, sizeof(GrPoint)}
509 }; 511 };
510 static const GrAttribBindings kBindings = GrDrawState::kEdge_AttribBindingsB it;
511 SkMatrix viewM = drawState->getViewMatrix(); 512 SkMatrix viewM = drawState->getViewMatrix();
512 513
513 PREALLOC_PTARRAY(128) lines; 514 PREALLOC_PTARRAY(128) lines;
514 PREALLOC_PTARRAY(128) quads; 515 PREALLOC_PTARRAY(128) quads;
515 IntArray qSubdivs; 516 IntArray qSubdivs;
516 *quadCnt = generate_lines_and_quads(path, viewM, devClipBounds, 517 *quadCnt = generate_lines_and_quads(path, viewM, devClipBounds,
517 &lines, &quads, &qSubdivs); 518 &lines, &quads, &qSubdivs);
518 519
519 *lineCnt = lines.count() / 2; 520 *lineCnt = lines.count() / 2;
520 int vertCnt = kVertsPerLineSeg * *lineCnt + kVertsPerQuad * *quadCnt; 521 int vertCnt = kVertsPerLineSeg * *lineCnt + kVertsPerQuad * *quadCnt;
521 522
522 target->drawState()->setVertexAttribs(kAttribs, SK_ARRAY_COUNT(kAttribs)); 523 target->drawState()->setVertexAttribs(kAttribs, SK_ARRAY_COUNT(kAttribs));
523 target->drawState()->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0); 524 target->drawState()->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
524 target->drawState()->setAttribIndex(GrDrawState::kEdge_AttribIndex, 1); 525 target->drawState()->setAttribBindings(GrDrawState::kDefault_AttribBindings) ;
525 target->drawState()->setAttribBindings(kBindings);
526 GrAssert(sizeof(Vertex) == target->getDrawState().getVertexSize()); 526 GrAssert(sizeof(Vertex) == target->getDrawState().getVertexSize());
527 527
528 if (!arg->set(target, vertCnt, 0)) { 528 if (!arg->set(target, vertCnt, 0)) {
529 return false; 529 return false;
530 } 530 }
531 531
532 Vertex* verts = reinterpret_cast<Vertex*>(arg->vertices()); 532 Vertex* verts = reinterpret_cast<Vertex*>(arg->vertices());
533 533
534 const SkMatrix* toDevice = NULL; 534 const SkMatrix* toDevice = NULL;
535 const SkMatrix* toSrc = NULL; 535 const SkMatrix* toSrc = NULL;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 int quadCnt; 581 int quadCnt;
582 GrDrawTarget::AutoReleaseGeometry arg; 582 GrDrawTarget::AutoReleaseGeometry arg;
583 if (!this->createGeom(path, 583 if (!this->createGeom(path,
584 target, 584 target,
585 &lineCnt, 585 &lineCnt,
586 &quadCnt, 586 &quadCnt,
587 &arg)) { 587 &arg)) {
588 return false; 588 return false;
589 } 589 }
590 590
591 GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kPreserve_ASRInit);
592 GrDrawState* drawState = target->drawState();
593
591 GrDrawState::AutoDeviceCoordDraw adcd; 594 GrDrawState::AutoDeviceCoordDraw adcd;
592 GrDrawState* drawState = target->drawState();
593 // createGeom transforms the geometry to device space when the matrix does n ot have 595 // createGeom transforms the geometry to device space when the matrix does n ot have
594 // perspective. 596 // perspective.
595 if (!drawState->getViewMatrix().hasPerspective()) { 597 if (!drawState->getViewMatrix().hasPerspective()) {
596 adcd.set(drawState); 598 adcd.set(drawState);
597 if (!adcd.succeeded()) { 599 if (!adcd.succeeded()) {
598 return false; 600 return false;
599 } 601 }
600 } 602 }
601 603
602 // TODO: See whether rendering lines as degenerate quads improves perf 604 // TODO: See whether rendering lines as degenerate quads improves perf
603 // when we have a mix 605 // when we have a mix
604 606
605 GrDrawState::VertexEdgeType oldEdgeType = drawState->getVertexEdgeType(); 607 enum {
608 // the edge effects share this stage with glyph rendering
609 // (kGlyphMaskStage in GrTextContext) && SW path rendering
610 // (kPathMaskStage in GrSWMaskHelper)
611 kEdgeEffectStage = GrPaint::kTotalStages,
612 };
613 static const int kEdgeAttrIndex = 1;
606 614
615 GrEffectRef* hairLineEffect = GrEdgeEffect::Create(GrEdgeEffect::kHairLine_E dgeType);
616 GrEffectRef* hairQuadEffect = GrEdgeEffect::Create(GrEdgeEffect::kHairQuad_E dgeType);
617
607 target->setIndexSourceToBuffer(fLinesIndexBuffer); 618 target->setIndexSourceToBuffer(fLinesIndexBuffer);
608 int lines = 0; 619 int lines = 0;
609 int nBufLines = fLinesIndexBuffer->maxQuads(); 620 int nBufLines = fLinesIndexBuffer->maxQuads();
610 drawState->setVertexEdgeType(GrDrawState::kHairLine_EdgeType); 621 drawState->setEffect(kEdgeEffectStage, hairLineEffect, kEdgeAttrIndex)->unre f();
611 while (lines < lineCnt) { 622 while (lines < lineCnt) {
612 int n = GrMin(lineCnt - lines, nBufLines); 623 int n = GrMin(lineCnt - lines, nBufLines);
613 target->drawIndexed(kTriangles_GrPrimitiveType, 624 target->drawIndexed(kTriangles_GrPrimitiveType,
614 kVertsPerLineSeg*lines, // startV 625 kVertsPerLineSeg*lines, // startV
615 0, // startI 626 0, // startI
616 kVertsPerLineSeg*n, // vCount 627 kVertsPerLineSeg*n, // vCount
617 kIdxsPerLineSeg*n); // iCount 628 kIdxsPerLineSeg*n); // iCount
618 lines += n; 629 lines += n;
619 } 630 }
620 631
621 target->setIndexSourceToBuffer(fQuadsIndexBuffer); 632 target->setIndexSourceToBuffer(fQuadsIndexBuffer);
622 int quads = 0; 633 int quads = 0;
623 drawState->setVertexEdgeType(GrDrawState::kHairQuad_EdgeType); 634 drawState->setEffect(kEdgeEffectStage, hairQuadEffect, kEdgeAttrIndex)->unre f();
624 while (quads < quadCnt) { 635 while (quads < quadCnt) {
625 int n = GrMin(quadCnt - quads, kNumQuadsInIdxBuffer); 636 int n = GrMin(quadCnt - quads, kNumQuadsInIdxBuffer);
626 target->drawIndexed(kTriangles_GrPrimitiveType, 637 target->drawIndexed(kTriangles_GrPrimitiveType,
627 4 * lineCnt + kVertsPerQuad*quads, // startV 638 4 * lineCnt + kVertsPerQuad*quads, // startV
628 0, // startI 639 0, // startI
629 kVertsPerQuad*n, // vCount 640 kVertsPerQuad*n, // vCount
630 kIdxsPerQuad*n); // iCount 641 kIdxsPerQuad*n); // iCount
631 quads += n; 642 quads += n;
632 } 643 }
633 drawState->setVertexEdgeType(oldEdgeType); 644
634 return true; 645 return true;
635 } 646 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698