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

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

Issue 1967513002: Revert of Replace GrStrokeInfo with GrStyle. (Closed) Base URL: https://chromium.googlesource.com/skia.git@resscale
Patch Set: 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
« no previous file with comments | « src/gpu/effects/GrDashingEffect.h ('k') | src/gpu/gl/GrGLPath.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 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 "GrStyle.h" 19 #include "GrStrokeInfo.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 GrStyle& style , 32 bool GrDashingEffect::CanDrawDashLine(const SkPoint pts[2], const GrStrokeInfo& strokeInfo,
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 (!style.isDashed() || 2 != style.dashIntervalCnt()) { 45 if (!strokeInfo.isDashed() || 2 != strokeInfo.getDashCount()) {
46 return false; 46 return false;
47 } 47 }
48 48
49 const SkScalar* intervals = style.dashIntervals(); 49 const SkScalar* intervals = strokeInfo.getDashIntervals();
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 = style.strokeRec().getCap(); 54 SkPaint::Cap cap = strokeInfo.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 GrStyle& style, bool msaaRT) { 693 bool useAA, const GrStrokeInfo& strokeInfo, boo l msaaRT) {
694 SkASSERT(GrDashingEffect::CanDrawDashLine(pts, style, viewMatrix)); 694 const SkScalar* intervals = strokeInfo.getDashIntervals();
695 const SkScalar* intervals = style.dashIntervals(); 695 SkScalar phase = strokeInfo.getDashPhase();
696 SkScalar phase = style.dashPhase();
697 696
698 SkPaint::Cap cap = style.strokeRec().getCap(); 697 SkPaint::Cap cap = strokeInfo.getCap();
699 698
700 DashBatch::Geometry geometry; 699 DashBatch::Geometry geometry;
701 geometry.fSrcStrokeWidth = style.strokeRec().getWidth(); 700 geometry.fSrcStrokeWidth = strokeInfo.getWidth();
702 701
703 // the phase should be normalized to be [0, sum of all intervals) 702 // the phase should be normalized to be [0, sum of all intervals)
704 SkASSERT(phase >= 0 && phase < intervals[0] + intervals[1]); 703 SkASSERT(phase >= 0 && phase < intervals[0] + intervals[1]);
705 704
706 // Rotate the src pts so they are aligned horizontally with pts[0].fX < pts[ 1].fX 705 // Rotate the src pts so they are aligned horizontally with pts[0].fX < pts[ 1].fX
707 if (pts[0].fY != pts[1].fY || pts[0].fX > pts[1].fX) { 706 if (pts[0].fY != pts[1].fY || pts[0].fX > pts[1].fX) {
708 SkMatrix rotMatrix; 707 SkMatrix rotMatrix;
709 align_to_x_axis(pts, &rotMatrix, geometry.fPtsRot); 708 align_to_x_axis(pts, &rotMatrix, geometry.fPtsRot);
710 if(!rotMatrix.invert(&geometry.fSrcRotInv)) { 709 if(!rotMatrix.invert(&geometry.fSrcRotInv)) {
711 SkDebugf("Failed to create invertible rotation matrix!\n"); 710 SkDebugf("Failed to create invertible rotation matrix!\n");
(...skipping 29 matching lines...) Expand all
741 geometry.fIntervals[1] = intervals[1]; 740 geometry.fIntervals[1] = intervals[1];
742 741
743 return DashBatch::Create(geometry, cap, aaMode, fullDash); 742 return DashBatch::Create(geometry, cap, aaMode, fullDash);
744 } 743 }
745 744
746 GrDrawBatch* GrDashingEffect::CreateDashLineBatch(GrColor color, 745 GrDrawBatch* GrDashingEffect::CreateDashLineBatch(GrColor color,
747 const SkMatrix& viewMatrix, 746 const SkMatrix& viewMatrix,
748 const SkPoint pts[2], 747 const SkPoint pts[2],
749 bool useAA, 748 bool useAA,
750 bool msaaIsEnabled, 749 bool msaaIsEnabled,
751 const GrStyle& style) { 750 const GrStrokeInfo& strokeInfo ) {
752 return create_batch(color, viewMatrix, pts, useAA, style, msaaIsEnabled); 751 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaIsEnabled );
753 } 752 }
754 753
755 ////////////////////////////////////////////////////////////////////////////// 754 //////////////////////////////////////////////////////////////////////////////
756 755
757 class GLDashingCircleEffect; 756 class GLDashingCircleEffect;
758 757
759 /* 758 /*
760 * This effect will draw a dotted line (defined as a dashed lined with round cap s and no on 759 * This effect will draw a dotted line (defined as a dashed lined with round cap s and no on
761 * interval). The radius of the dots is given by the strokeWidth and the spacing by the DashInfo. 760 * interval). The radius of the dots is given by the strokeWidth and the spacing by the DashInfo.
762 * Both of the previous two parameters are in device space. This effect also req uires the setting of 761 * 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
1283 1282
1284 } 1283 }
1285 1284
1286 // phase is 0 < sum (i0, i1) 1285 // phase is 0 < sum (i0, i1)
1287 SkScalar phase = random->nextRangeScalar(0, intervals[0] + intervals[1]); 1286 SkScalar phase = random->nextRangeScalar(0, intervals[0] + intervals[1]);
1288 1287
1289 SkPaint p; 1288 SkPaint p;
1290 p.setStyle(SkPaint::kStroke_Style); 1289 p.setStyle(SkPaint::kStroke_Style);
1291 p.setStrokeWidth(SkIntToScalar(1)); 1290 p.setStrokeWidth(SkIntToScalar(1));
1292 p.setStrokeCap(cap); 1291 p.setStrokeCap(cap);
1293 p.setPathEffect(GrTest::TestDashPathEffect::Make(intervals, 2, phase));
1294 1292
1295 GrStyle style(p); 1293 GrStrokeInfo strokeInfo(p);
1296 1294
1297 return create_batch(color, viewMatrix, pts, useAA, style, msaaRT); 1295 SkPathEffect::DashInfo info;
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);
1298 } 1303 }
1299 1304
1300 #endif 1305 #endif
OLDNEW
« no previous file with comments | « src/gpu/effects/GrDashingEffect.h ('k') | src/gpu/gl/GrGLPath.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698