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 #ifndef GrPathRange_DEFINED | 8 #ifndef GrPathRange_DEFINED |
9 #define GrPathRange_DEFINED | 9 #define GrPathRange_DEFINED |
10 | 10 |
11 #include "GrGpuResource.h" | 11 #include "GrGpuResource.h" |
12 #include "GrResourceCache.h" | 12 #include "GrResourceCache.h" |
13 #include "SkStrokeRec.h" | 13 #include "SkStrokeRec.h" |
14 #include "SkTemplates.h" | |
14 | 15 |
15 class SkPath; | 16 class SkPath; |
17 class SkDescriptor; | |
16 | 18 |
17 /** | 19 /** |
18 * Represents a contiguous range of GPU path objects with a common stroke. The | 20 * Represents a contiguous range of GPU path objects, all with a common stroke. |
19 * path range is immutable with the exception that individual paths can be | 21 * This object is immutable with the exception that individual paths may be |
20 * initialized lazily. Unititialized paths are silently ignored by drawing | 22 * initialized lazily. |
21 * functions. | |
22 */ | 23 */ |
24 | |
23 class GrPathRange : public GrGpuResource { | 25 class GrPathRange : public GrGpuResource { |
24 public: | 26 public: |
25 SK_DECLARE_INST_COUNT(GrPathRange); | 27 SK_DECLARE_INST_COUNT(GrPathRange); |
26 | 28 |
27 static const bool kIsWrapped = false; | 29 static const bool kIsWrapped = false; |
28 | 30 |
31 /** | |
32 * Return the resourceType intended for cache lookups involving GrPathRange. | |
33 */ | |
29 static GrResourceKey::ResourceType resourceType() { | 34 static GrResourceKey::ResourceType resourceType() { |
30 static const GrResourceKey::ResourceType type = GrResourceKey::GenerateR esourceType(); | 35 static const GrResourceKey::ResourceType type = GrResourceKey::GenerateR esourceType(); |
31 return type; | 36 return type; |
32 } | 37 } |
33 | 38 |
34 /** | 39 /** |
35 * Initialize to a range with a fixed size and stroke. Stroke must not be ha irline. | 40 * Class that generates the paths for a specific range. |
36 */ | 41 */ |
37 GrPathRange(GrGpu* gpu, size_t size, const SkStrokeRec& stroke) | 42 class PathGenerator { |
bsalomon
2014/09/15 14:16:21
Since this object has a semi-interesting lifetime
Chris Dalton
2014/09/15 21:05:25
Agreed. I was actually wondering myself what the s
| |
38 : INHERITED(gpu, kIsWrapped), | 43 public: |
39 fSize(size), | 44 virtual uint32_t getNumPaths() = 0; |
40 fStroke(stroke) { | 45 virtual void generatePath(uint32_t index, SkPath* out) = 0; |
41 this->registerWithCache(); | 46 virtual bool isEqualTo(const SkDescriptor&) const { return false; } |
47 virtual ~PathGenerator() {} | |
48 }; | |
49 | |
50 /** | |
51 * Initialize a lazy-loaded path range. This class will generate an SkPath a nd call | |
52 * onInitPath() for each path within the range before it is drawn for the fi rst time. | |
53 * This class assumes ownership of the PathGenerator and deletes it when don e. | |
54 */ | |
55 GrPathRange(GrGpu*, PathGenerator*, const SkStrokeRec& stroke); | |
56 | |
57 /** | |
58 * Initialize an eager-loaded path range. The subclass is responsible for en suring all | |
59 * the paths are initialized up front. | |
60 */ | |
61 GrPathRange(GrGpu*, uint32_t numPaths, const SkStrokeRec& stroke); | |
62 | |
63 virtual bool isEqualTo(const SkDescriptor& desc) const { | |
64 return NULL != fPathGenerator.get() && fPathGenerator->isEqualTo(desc); | |
42 } | 65 } |
43 | 66 |
44 size_t getSize() const { return fSize; } | 67 uint32_t getNumPaths() const { return fNumPaths; } |
bsalomon
2014/09/15 14:16:21
tiny nit: we usually use (signed) int for counts.
Chris Dalton
2014/09/15 21:05:25
Acknowledged.
| |
45 const SkStrokeRec& getStroke() const { return fStroke; } | 68 const SkStrokeRec& getStroke() const { return fStroke; } |
46 | 69 const PathGenerator* getPathGenerator() const { return fPathGenerator.get(); } |
47 /** | |
48 * Initialize a path in the range. It is invalid to call this method for a | |
49 * path that has already been initialized. | |
50 */ | |
51 virtual void initAt(size_t index, const SkPath&) = 0; | |
52 | 70 |
53 protected: | 71 protected: |
54 size_t fSize; | 72 // Initialize a path in the range before drawing. This is only called when |
55 SkStrokeRec fStroke; | 73 // fPathGenerator is non-null. The child class need not call didChangeGpuMem orySize(), |
74 // GrPathRange will take care of that after the call is complete. | |
75 virtual void onInitPath(uint32_t index, const SkPath&) const = 0; | |
56 | 76 |
57 private: | 77 private: |
78 // Notify when paths will be drawn in case this is a lazy-loaded path range. | |
79 friend class GrGpu; | |
80 void willDrawPaths(const uint32_t indices[], int count) const; | |
81 | |
82 mutable SkAutoTDelete<PathGenerator> fPathGenerator; | |
83 mutable SkTArray<uint8_t, true /*MEM_COPY*/> fGeneratedPaths; | |
84 const uint32_t fNumPaths; | |
85 const SkStrokeRec fStroke; | |
86 | |
58 typedef GrGpuResource INHERITED; | 87 typedef GrGpuResource INHERITED; |
59 }; | 88 }; |
60 | 89 |
61 #endif | 90 #endif |
OLD | NEW |