OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 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 "GrGLPathRange.h" | 9 #include "GrGLPathRange.h" |
10 #include "GrGLPath.h" | 10 #include "GrGLPath.h" |
11 #include "GrGLPathRendering.h" | 11 #include "GrGLPathRendering.h" |
12 #include "GrGLGpu.h" | 12 #include "GrGLGpu.h" |
13 | 13 |
14 GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, PathGenerator* pathGenerator, const S
kStrokeRec& stroke) | 14 GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, PathGenerator* pathGenerator, const G
rStrokeInfo& stroke) |
15 : INHERITED(gpu, pathGenerator, stroke), | 15 : INHERITED(gpu, pathGenerator), |
| 16 fStroke(stroke), |
16 fBasePathID(gpu->glPathRendering()->genPaths(this->getNumPaths())), | 17 fBasePathID(gpu->glPathRendering()->genPaths(this->getNumPaths())), |
17 fGpuMemorySize(0) { | 18 fGpuMemorySize(0) { |
| 19 this->init(); |
18 this->registerWithCache(); | 20 this->registerWithCache(); |
19 } | 21 } |
20 | 22 |
21 GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, | 23 GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, |
22 GrGLuint basePathID, | 24 GrGLuint basePathID, |
23 int numPaths, | 25 int numPaths, |
24 size_t gpuMemorySize, | 26 size_t gpuMemorySize, |
25 const SkStrokeRec& stroke) | 27 const GrStrokeInfo& stroke) |
26 : INHERITED(gpu, numPaths, stroke), | 28 : INHERITED(gpu, numPaths), |
| 29 fStroke(stroke), |
27 fBasePathID(basePathID), | 30 fBasePathID(basePathID), |
28 fGpuMemorySize(gpuMemorySize) { | 31 fGpuMemorySize(gpuMemorySize) { |
| 32 this->init(); |
29 this->registerWithCache(); | 33 this->registerWithCache(); |
30 } | 34 } |
31 | 35 |
32 void GrGLPathRange::onInitPath(int index, const SkPath& skPath) const { | 36 void GrGLPathRange::init() { |
| 37 if (fStroke.isDashed()) { |
| 38 fShouldStroke = false; |
| 39 fShouldFill = true; |
| 40 } else { |
| 41 const SkStrokeRec& strokeRec = fStroke.getStrokeRec(); |
| 42 fShouldStroke = strokeRec.needToApply(); |
| 43 fShouldFill = fStroke.isFillStyle() || |
| 44 strokeRec.getStyle() == SkStrokeRec::kStrokeAndFill_Style; |
| 45 } |
| 46 } |
| 47 |
| 48 void GrGLPathRange::onInitPath(int index, const SkPath& origSkPath) const { |
33 GrGLGpu* gpu = static_cast<GrGLGpu*>(this->getGpu()); | 49 GrGLGpu* gpu = static_cast<GrGLGpu*>(this->getGpu()); |
34 if (NULL == gpu) { | 50 if (NULL == gpu) { |
35 return; | 51 return; |
36 } | 52 } |
37 | 53 |
38 // Make sure the path at this index hasn't been initted already. | 54 // Make sure the path at this index hasn't been initted already. |
39 SkDEBUGCODE( | 55 SkDEBUGCODE( |
40 GrGLboolean isPath; | 56 GrGLboolean isPath; |
41 GR_GL_CALL_RET(gpu->glInterface(), isPath, IsPath(fBasePathID + index)))
; | 57 GR_GL_CALL_RET(gpu->glInterface(), isPath, IsPath(fBasePathID + index)))
; |
42 SkASSERT(GR_GL_FALSE == isPath); | 58 SkASSERT(GR_GL_FALSE == isPath); |
43 | 59 |
44 GrGLPath::InitPathObject(gpu, fBasePathID + index, skPath, this->getStroke()
); | 60 const SkPath* skPath = &origSkPath; |
| 61 SkTLazy<SkPath> tmpPath; |
| 62 const GrStrokeInfo* stroke = &fStroke; |
| 63 GrStrokeInfo tmpStroke(fStroke, false); |
| 64 |
| 65 // Dashing must be applied to the path. However, if dashing is present, |
| 66 // we must convert all the paths to fills. The GrStrokeInfo::applyDash leave
s |
| 67 // simple paths as strokes but converts other paths to fills. |
| 68 // Thus we must stroke the strokes here, so that all paths in the |
| 69 // path range are using the same style. |
| 70 if (fStroke.isDashed()) { |
| 71 if (!stroke->applyDash(tmpPath.init(), &tmpStroke, *skPath)) { |
| 72 return; |
| 73 } |
| 74 skPath = tmpPath.get(); |
| 75 stroke = &tmpStroke; |
| 76 if (tmpStroke.getStrokeRec().needToApply()) { |
| 77 SkStrokeRec* strokeRec = tmpStroke.getStrokeRecPtr(); |
| 78 if (!strokeRec->applyToPath(tmpPath.get(), *tmpPath.get())) { |
| 79 return; |
| 80 } |
| 81 strokeRec->setFillStyle(); |
| 82 } |
| 83 } |
| 84 |
| 85 GrGLPath::InitPathObject(gpu, fBasePathID + index, *skPath, *stroke); |
45 | 86 |
46 // TODO: Use a better approximation for the individual path sizes. | 87 // TODO: Use a better approximation for the individual path sizes. |
47 fGpuMemorySize += 100; | 88 fGpuMemorySize += 100; |
48 } | 89 } |
49 | 90 |
50 void GrGLPathRange::onRelease() { | 91 void GrGLPathRange::onRelease() { |
51 SkASSERT(this->getGpu()); | 92 SkASSERT(this->getGpu()); |
52 | 93 |
53 if (0 != fBasePathID && !this->isWrapped()) { | 94 if (0 != fBasePathID && !this->isWrapped()) { |
54 static_cast<GrGLGpu*>(this->getGpu())->glPathRendering()->deletePaths(fB
asePathID, | 95 static_cast<GrGLGpu*>(this->getGpu())->glPathRendering()->deletePaths(fB
asePathID, |
55 th
is->getNumPaths()); | 96 th
is->getNumPaths()); |
56 fBasePathID = 0; | 97 fBasePathID = 0; |
57 } | 98 } |
58 | 99 |
59 INHERITED::onRelease(); | 100 INHERITED::onRelease(); |
60 } | 101 } |
61 | 102 |
62 void GrGLPathRange::onAbandon() { | 103 void GrGLPathRange::onAbandon() { |
63 fBasePathID = 0; | 104 fBasePathID = 0; |
64 | 105 |
65 INHERITED::onAbandon(); | 106 INHERITED::onAbandon(); |
66 } | 107 } |
OLD | NEW |