OLD | NEW |
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 "GrGLPathRange.h" | 8 #include "GrGLPathRange.h" |
9 #include "GrGLPath.h" | 9 #include "GrGLPath.h" |
10 #include "GrGLPathRendering.h" | 10 #include "GrGLPathRendering.h" |
11 #include "GrGLGpu.h" | 11 #include "GrGLGpu.h" |
12 | 12 |
13 GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, PathGenerator* pathGenerator, const G
rStrokeInfo& stroke) | 13 GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, PathGenerator* pathGenerator, const G
rStyle& style) |
14 : INHERITED(gpu, pathGenerator), | 14 : INHERITED(gpu, pathGenerator), |
15 fStroke(stroke), | 15 fStyle(style), |
16 fBasePathID(gpu->glPathRendering()->genPaths(this->getNumPaths())), | 16 fBasePathID(gpu->glPathRendering()->genPaths(this->getNumPaths())), |
17 fGpuMemorySize(0) { | 17 fGpuMemorySize(0) { |
18 this->init(); | 18 this->init(); |
19 this->registerWithCache(SkBudgeted::kYes); | 19 this->registerWithCache(SkBudgeted::kYes); |
20 } | 20 } |
21 | 21 |
22 GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, | 22 GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, |
23 GrGLuint basePathID, | 23 GrGLuint basePathID, |
24 int numPaths, | 24 int numPaths, |
25 size_t gpuMemorySize, | 25 size_t gpuMemorySize, |
26 const GrStrokeInfo& stroke) | 26 const GrStyle& style) |
27 : INHERITED(gpu, numPaths), | 27 : INHERITED(gpu, numPaths), |
28 fStroke(stroke), | 28 fStyle(style), |
29 fBasePathID(basePathID), | 29 fBasePathID(basePathID), |
30 fGpuMemorySize(gpuMemorySize) { | 30 fGpuMemorySize(gpuMemorySize) { |
31 this->init(); | 31 this->init(); |
32 this->registerWithCache(SkBudgeted::kYes); | 32 this->registerWithCache(SkBudgeted::kYes); |
33 } | 33 } |
34 | 34 |
35 void GrGLPathRange::init() { | 35 void GrGLPathRange::init() { |
| 36 const SkStrokeRec& stroke = fStyle.strokeRec(); |
36 // Must force fill: | 37 // Must force fill: |
37 // * dashing: NVPR stroke dashing is different to Skia. | 38 // * dashing: NVPR stroke dashing is different to Skia. |
38 // * end caps: NVPR stroking degenerate contours with end caps is different
to Skia. | 39 // * end caps: NVPR stroking degenerate contours with end caps is different
to Skia. |
39 bool forceFill = fStroke.isDashed() || | 40 bool forceFill = fStyle.pathEffect() || |
40 (fStroke.needToApply() && fStroke.getCap() != SkPaint::kButt_Cap); | 41 (stroke.needToApply() && stroke.getCap() != SkPaint::kButt_Cap); |
41 | 42 |
42 if (forceFill) { | 43 if (forceFill) { |
43 fShouldStroke = false; | 44 fShouldStroke = false; |
44 fShouldFill = true; | 45 fShouldFill = true; |
45 } else { | 46 } else { |
46 fShouldStroke = fStroke.needToApply(); | 47 fShouldStroke = stroke.needToApply(); |
47 fShouldFill = fStroke.isFillStyle() || | 48 fShouldFill = stroke.isFillStyle() || |
48 fStroke.getStyle() == SkStrokeRec::kStrokeAndFill_Style; | 49 stroke.getStyle() == SkStrokeRec::kStrokeAndFill_Style; |
49 } | 50 } |
50 } | 51 } |
51 | 52 |
52 void GrGLPathRange::onInitPath(int index, const SkPath& origSkPath) const { | 53 void GrGLPathRange::onInitPath(int index, const SkPath& origSkPath) const { |
53 GrGLGpu* gpu = static_cast<GrGLGpu*>(this->getGpu()); | 54 GrGLGpu* gpu = static_cast<GrGLGpu*>(this->getGpu()); |
54 if (nullptr == gpu) { | 55 if (nullptr == gpu) { |
55 return; | 56 return; |
56 } | 57 } |
57 | |
58 // Make sure the path at this index hasn't been initted already. | 58 // Make sure the path at this index hasn't been initted already. |
59 SkDEBUGCODE( | 59 SkDEBUGCODE( |
60 GrGLboolean isPath; | 60 GrGLboolean isPath; |
61 GR_GL_CALL_RET(gpu->glInterface(), isPath, IsPath(fBasePathID + index)))
; | 61 GR_GL_CALL_RET(gpu->glInterface(), isPath, IsPath(fBasePathID + index)))
; |
62 SkASSERT(GR_GL_FALSE == isPath); | 62 SkASSERT(GR_GL_FALSE == isPath); |
63 | 63 |
64 if (origSkPath.isEmpty()) { | 64 if (origSkPath.isEmpty()) { |
65 GrGLPath::InitPathObjectEmptyPath(gpu, fBasePathID + index); | 65 GrGLPath::InitPathObjectEmptyPath(gpu, fBasePathID + index); |
66 } else if (fShouldStroke) { | 66 } else if (fShouldStroke) { |
67 GrGLPath::InitPathObjectPathData(gpu, fBasePathID + index, origSkPath); | 67 GrGLPath::InitPathObjectPathData(gpu, fBasePathID + index, origSkPath); |
68 GrGLPath::InitPathObjectStroke(gpu, fBasePathID + index, fStroke); | 68 GrGLPath::InitPathObjectStroke(gpu, fBasePathID + index, fStyle.strokeRe
c()); |
69 } else { | 69 } else { |
70 const SkPath* skPath = &origSkPath; | 70 const SkPath* skPath = &origSkPath; |
71 SkTLazy<SkPath> tmpPath; | 71 SkTLazy<SkPath> tmpPath; |
72 const GrStrokeInfo* stroke = &fStroke; | 72 if (!fStyle.isSimpleFill()) { |
73 GrStrokeInfo tmpStroke(SkStrokeRec::kFill_InitStyle); | 73 SkStrokeRec::InitStyle fill; |
74 | 74 // The path effect must be applied to the path. However, if a path e
ffect is present, |
75 // Dashing must be applied to the path. However, if dashing is present, | 75 // we must convert all the paths to fills. The path effect applicati
on may leave |
76 // we must convert all the paths to fills. The GrStrokeInfo::applyDash l
eaves | 76 // simple paths as strokes but converts other paths to fills. |
77 // simple paths as strokes but converts other paths to fills. | 77 // Thus we must stroke the strokes here, so that all paths in the |
78 // Thus we must stroke the strokes here, so that all paths in the | 78 // path range are using the same style. |
79 // path range are using the same style. | 79 if (!fStyle.applyToPath(tmpPath.init(), &fill, *skPath, SK_Scalar1))
{ |
80 if (fStroke.isDashed()) { | |
81 if (!stroke->applyDashToPath(tmpPath.init(), &tmpStroke, *skPath)) { | |
82 return; | 80 return; |
83 } | 81 } |
| 82 // We shouldn't have allowed hairlines or arbitrary path effect styl
es to get here |
| 83 // so after application we better have a filled path. |
| 84 SkASSERT(SkStrokeRec::kFill_InitStyle == fill); |
84 skPath = tmpPath.get(); | 85 skPath = tmpPath.get(); |
85 stroke = &tmpStroke; | 86 |
86 } | |
87 if (stroke->needToApply()) { | |
88 if (!tmpPath.isValid()) { | |
89 tmpPath.init(); | |
90 } | |
91 if (!stroke->applyToPath(tmpPath.get(), *tmpPath.get())) { | |
92 return; | |
93 } | |
94 } | 87 } |
95 GrGLPath::InitPathObjectPathData(gpu, fBasePathID + index, *skPath); | 88 GrGLPath::InitPathObjectPathData(gpu, fBasePathID + index, *skPath); |
96 } | 89 } |
97 // TODO: Use a better approximation for the individual path sizes. | 90 // TODO: Use a better approximation for the individual path sizes. |
98 fGpuMemorySize += 100; | 91 fGpuMemorySize += 100; |
99 } | 92 } |
100 | 93 |
101 void GrGLPathRange::onRelease() { | 94 void GrGLPathRange::onRelease() { |
102 SkASSERT(this->getGpu()); | 95 SkASSERT(this->getGpu()); |
103 | 96 |
104 if (0 != fBasePathID) { | 97 if (0 != fBasePathID) { |
105 static_cast<GrGLGpu*>(this->getGpu())->glPathRendering()->deletePaths(fB
asePathID, | 98 static_cast<GrGLGpu*>(this->getGpu())->glPathRendering()->deletePaths(fB
asePathID, |
106 th
is->getNumPaths()); | 99 th
is->getNumPaths()); |
107 fBasePathID = 0; | 100 fBasePathID = 0; |
108 } | 101 } |
109 | 102 |
110 INHERITED::onRelease(); | 103 INHERITED::onRelease(); |
111 } | 104 } |
112 | 105 |
113 void GrGLPathRange::onAbandon() { | 106 void GrGLPathRange::onAbandon() { |
114 fBasePathID = 0; | 107 fBasePathID = 0; |
115 | 108 |
116 INHERITED::onAbandon(); | 109 INHERITED::onAbandon(); |
117 } | 110 } |
OLD | NEW |