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

Side by Side Diff: src/gpu/effects/GrDashingEffect.cpp

Issue 1957363002: Replace GrStrokeInfo with GrStyle. (Closed) Base URL: https://chromium.googlesource.com/skia.git@resscale
Patch Set: Fix issue where hairlines were going to MSAAPathRenderer Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "GrDashingEffect.h" 8 #include "GrDashingEffect.h"
9 9
10 #include "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
11 #include "GrBatchTest.h" 11 #include "GrBatchTest.h"
12 #include "GrCaps.h" 12 #include "GrCaps.h"
13 #include "GrGeometryProcessor.h" 13 #include "GrGeometryProcessor.h"
14 #include "GrContext.h" 14 #include "GrContext.h"
15 #include "GrCoordTransform.h" 15 #include "GrCoordTransform.h"
16 #include "GrDefaultGeoProcFactory.h" 16 #include "GrDefaultGeoProcFactory.h"
17 #include "GrInvariantOutput.h" 17 #include "GrInvariantOutput.h"
18 #include "GrProcessor.h" 18 #include "GrProcessor.h"
19 #include "GrStrokeInfo.h" 19 #include "GrStyle.h"
20 #include "SkGr.h" 20 #include "SkGr.h"
21 #include "batches/GrVertexBatch.h" 21 #include "batches/GrVertexBatch.h"
22 #include "glsl/GrGLSLFragmentShaderBuilder.h" 22 #include "glsl/GrGLSLFragmentShaderBuilder.h"
23 #include "glsl/GrGLSLGeometryProcessor.h" 23 #include "glsl/GrGLSLGeometryProcessor.h"
24 #include "glsl/GrGLSLProgramDataManager.h" 24 #include "glsl/GrGLSLProgramDataManager.h"
25 #include "glsl/GrGLSLUniformHandler.h" 25 #include "glsl/GrGLSLUniformHandler.h"
26 #include "glsl/GrGLSLVarying.h" 26 #include "glsl/GrGLSLVarying.h"
27 #include "glsl/GrGLSLVertexShaderBuilder.h" 27 #include "glsl/GrGLSLVertexShaderBuilder.h"
28 28
29 /////////////////////////////////////////////////////////////////////////////// 29 ///////////////////////////////////////////////////////////////////////////////
30 30
31 // Returns whether or not the gpu can fast path the dash line effect. 31 // Returns whether or not the gpu can fast path the dash line effect.
32 bool GrDashingEffect::CanDrawDashLine(const SkPoint pts[2], const GrStrokeInfo& strokeInfo, 32 bool GrDashingEffect::CanDrawDashLine(const SkPoint pts[2], const GrStyle& style ,
33 const SkMatrix& viewMatrix) { 33 const SkMatrix& viewMatrix) {
34 // Pts must be either horizontal or vertical in src space 34 // Pts must be either horizontal or vertical in src space
35 if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) { 35 if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) {
36 return false; 36 return false;
37 } 37 }
38 38
39 // May be able to relax this to include skew. As of now cannot do perspectiv e 39 // May be able to relax this to include skew. As of now cannot do perspectiv e
40 // because of the non uniform scaling of bloating a rect 40 // because of the non uniform scaling of bloating a rect
41 if (!viewMatrix.preservesRightAngles()) { 41 if (!viewMatrix.preservesRightAngles()) {
42 return false; 42 return false;
43 } 43 }
44 44
45 if (!strokeInfo.isDashed() || 2 != strokeInfo.getDashCount()) { 45 if (!style.isDashed() || 2 != style.dashIntervalCnt()) {
46 return false; 46 return false;
47 } 47 }
48 48
49 const SkScalar* intervals = strokeInfo.getDashIntervals(); 49 const SkScalar* intervals = style.dashIntervals();
50 if (0 == intervals[0] && 0 == intervals[1]) { 50 if (0 == intervals[0] && 0 == intervals[1]) {
51 return false; 51 return false;
52 } 52 }
53 53
54 SkPaint::Cap cap = strokeInfo.getCap(); 54 SkPaint::Cap cap = style.strokeRec().getCap();
55 // Current we do don't handle Round or Square cap dashes 55 // Current we do don't handle Round or Square cap dashes
56 if (SkPaint::kRound_Cap == cap && intervals[0] != 0.f) { 56 if (SkPaint::kRound_Cap == cap && intervals[0] != 0.f) {
57 return false; 57 return false;
58 } 58 }
59 59
60 return true; 60 return true;
61 } 61 }
62 62
63 namespace { 63 namespace {
64 struct DashLineVertex { 64 struct DashLineVertex {
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 static const int kVertsPerDash = 4; 683 static const int kVertsPerDash = 4;
684 static const int kIndicesPerDash = 6; 684 static const int kIndicesPerDash = 6;
685 685
686 BatchTracker fBatch; 686 BatchTracker fBatch;
687 SkSTArray<1, Geometry, true> fGeoData; 687 SkSTArray<1, Geometry, true> fGeoData;
688 688
689 typedef GrVertexBatch INHERITED; 689 typedef GrVertexBatch INHERITED;
690 }; 690 };
691 691
692 static GrDrawBatch* create_batch(GrColor color, const SkMatrix& viewMatrix, cons t SkPoint pts[2], 692 static GrDrawBatch* create_batch(GrColor color, const SkMatrix& viewMatrix, cons t SkPoint pts[2],
693 bool useAA, const GrStrokeInfo& strokeInfo, boo l msaaRT) { 693 bool useAA, const GrStyle& style, bool msaaRT) {
694 const SkScalar* intervals = strokeInfo.getDashIntervals(); 694 SkASSERT(GrDashingEffect::CanDrawDashLine(pts, style, viewMatrix));
695 SkScalar phase = strokeInfo.getDashPhase(); 695 const SkScalar* intervals = style.dashIntervals();
696 SkScalar phase = style.dashPhase();
696 697
697 SkPaint::Cap cap = strokeInfo.getCap(); 698 SkPaint::Cap cap = style.strokeRec().getCap();
698 699
699 DashBatch::Geometry geometry; 700 DashBatch::Geometry geometry;
700 geometry.fSrcStrokeWidth = strokeInfo.getWidth(); 701 geometry.fSrcStrokeWidth = style.strokeRec().getWidth();
701 702
702 // the phase should be normalized to be [0, sum of all intervals) 703 // the phase should be normalized to be [0, sum of all intervals)
703 SkASSERT(phase >= 0 && phase < intervals[0] + intervals[1]); 704 SkASSERT(phase >= 0 && phase < intervals[0] + intervals[1]);
704 705
705 // Rotate the src pts so they are aligned horizontally with pts[0].fX < pts[ 1].fX 706 // Rotate the src pts so they are aligned horizontally with pts[0].fX < pts[ 1].fX
706 if (pts[0].fY != pts[1].fY || pts[0].fX > pts[1].fX) { 707 if (pts[0].fY != pts[1].fY || pts[0].fX > pts[1].fX) {
707 SkMatrix rotMatrix; 708 SkMatrix rotMatrix;
708 align_to_x_axis(pts, &rotMatrix, geometry.fPtsRot); 709 align_to_x_axis(pts, &rotMatrix, geometry.fPtsRot);
709 if(!rotMatrix.invert(&geometry.fSrcRotInv)) { 710 if(!rotMatrix.invert(&geometry.fSrcRotInv)) {
710 SkDebugf("Failed to create invertible rotation matrix!\n"); 711 SkDebugf("Failed to create invertible rotation matrix!\n");
(...skipping 29 matching lines...) Expand all
740 geometry.fIntervals[1] = intervals[1]; 741 geometry.fIntervals[1] = intervals[1];
741 742
742 return DashBatch::Create(geometry, cap, aaMode, fullDash); 743 return DashBatch::Create(geometry, cap, aaMode, fullDash);
743 } 744 }
744 745
745 GrDrawBatch* GrDashingEffect::CreateDashLineBatch(GrColor color, 746 GrDrawBatch* GrDashingEffect::CreateDashLineBatch(GrColor color,
746 const SkMatrix& viewMatrix, 747 const SkMatrix& viewMatrix,
747 const SkPoint pts[2], 748 const SkPoint pts[2],
748 bool useAA, 749 bool useAA,
749 bool msaaIsEnabled, 750 bool msaaIsEnabled,
750 const GrStrokeInfo& strokeInfo ) { 751 const GrStyle& style) {
751 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaIsEnabled ); 752 return create_batch(color, viewMatrix, pts, useAA, style, msaaIsEnabled);
752 } 753 }
753 754
754 ////////////////////////////////////////////////////////////////////////////// 755 //////////////////////////////////////////////////////////////////////////////
755 756
756 class GLDashingCircleEffect; 757 class GLDashingCircleEffect;
757 758
758 /* 759 /*
759 * This effect will draw a dotted line (defined as a dashed lined with round cap s and no on 760 * This effect will draw a dotted line (defined as a dashed lined with round cap s and no on
760 * interval). The radius of the dots is given by the strokeWidth and the spacing by the DashInfo. 761 * interval). The radius of the dots is given by the strokeWidth and the spacing by the DashInfo.
761 * Both of the previous two parameters are in device space. This effect also req uires the setting of 762 * Both of the previous two parameters are in device space. This effect also req uires the setting of
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 1283
1283 } 1284 }
1284 1285
1285 // phase is 0 < sum (i0, i1) 1286 // phase is 0 < sum (i0, i1)
1286 SkScalar phase = random->nextRangeScalar(0, intervals[0] + intervals[1]); 1287 SkScalar phase = random->nextRangeScalar(0, intervals[0] + intervals[1]);
1287 1288
1288 SkPaint p; 1289 SkPaint p;
1289 p.setStyle(SkPaint::kStroke_Style); 1290 p.setStyle(SkPaint::kStroke_Style);
1290 p.setStrokeWidth(SkIntToScalar(1)); 1291 p.setStrokeWidth(SkIntToScalar(1));
1291 p.setStrokeCap(cap); 1292 p.setStrokeCap(cap);
1293 p.setPathEffect(GrTest::TestDashPathEffect::Make(intervals, 2, phase));
1292 1294
1293 GrStrokeInfo strokeInfo(p); 1295 GrStyle style(p);
1294 1296
1295 SkPathEffect::DashInfo info; 1297 return create_batch(color, viewMatrix, pts, useAA, style, msaaRT);
1296 info.fIntervals = intervals;
1297 info.fCount = 2;
1298 info.fPhase = phase;
1299 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info);
1300 SkASSERT(success);
1301
1302 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT);
1303 } 1298 }
1304 1299
1305 #endif 1300 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698