Chromium Code Reviews| Index: src/gpu/GrPathRange.h |
| diff --git a/src/gpu/GrPathRange.h b/src/gpu/GrPathRange.h |
| index b52fef170c62798894ee042bbb86c27e396209d0..18d562fcfb6af385d36e67c7820130ef72353e5c 100644 |
| --- a/src/gpu/GrPathRange.h |
| +++ b/src/gpu/GrPathRange.h |
| @@ -11,50 +11,79 @@ |
| #include "GrGpuResource.h" |
| #include "GrResourceCache.h" |
| #include "SkStrokeRec.h" |
| +#include "SkTemplates.h" |
| class SkPath; |
| +class SkDescriptor; |
| /** |
| - * Represents a contiguous range of GPU path objects with a common stroke. The |
| - * path range is immutable with the exception that individual paths can be |
| - * initialized lazily. Unititialized paths are silently ignored by drawing |
| - * functions. |
| + * Represents a contiguous range of GPU path objects, all with a common stroke. |
| + * This object is immutable with the exception that individual paths may be |
| + * initialized lazily. |
| */ |
| + |
| class GrPathRange : public GrGpuResource { |
| public: |
| SK_DECLARE_INST_COUNT(GrPathRange); |
| static const bool kIsWrapped = false; |
| + /** |
| + * Return the resourceType intended for cache lookups involving GrPathRange. |
| + */ |
| static GrResourceKey::ResourceType resourceType() { |
| static const GrResourceKey::ResourceType type = GrResourceKey::GenerateResourceType(); |
| return type; |
| } |
| /** |
| - * Initialize to a range with a fixed size and stroke. Stroke must not be hairline. |
| + * Class that generates the paths for a specific range. |
| */ |
| - GrPathRange(GrGpu* gpu, size_t size, const SkStrokeRec& stroke) |
| - : INHERITED(gpu, kIsWrapped), |
| - fSize(size), |
| - fStroke(stroke) { |
| - this->registerWithCache(); |
| - } |
| + 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
|
| + public: |
| + virtual uint32_t getNumPaths() = 0; |
| + virtual void generatePath(uint32_t index, SkPath* out) = 0; |
| + virtual bool isEqualTo(const SkDescriptor&) const { return false; } |
| + virtual ~PathGenerator() {} |
| + }; |
| - size_t getSize() const { return fSize; } |
| - const SkStrokeRec& getStroke() const { return fStroke; } |
| + /** |
| + * Initialize a lazy-loaded path range. This class will generate an SkPath and call |
| + * onInitPath() for each path within the range before it is drawn for the first time. |
| + * This class assumes ownership of the PathGenerator and deletes it when done. |
| + */ |
| + GrPathRange(GrGpu*, PathGenerator*, const SkStrokeRec& stroke); |
| /** |
| - * Initialize a path in the range. It is invalid to call this method for a |
| - * path that has already been initialized. |
| + * Initialize an eager-loaded path range. The subclass is responsible for ensuring all |
| + * the paths are initialized up front. |
| */ |
| - virtual void initAt(size_t index, const SkPath&) = 0; |
| + GrPathRange(GrGpu*, uint32_t numPaths, const SkStrokeRec& stroke); |
| + |
| + virtual bool isEqualTo(const SkDescriptor& desc) const { |
| + return NULL != fPathGenerator.get() && fPathGenerator->isEqualTo(desc); |
| + } |
| + |
| + 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.
|
| + const SkStrokeRec& getStroke() const { return fStroke; } |
| + const PathGenerator* getPathGenerator() const { return fPathGenerator.get(); } |
| protected: |
| - size_t fSize; |
| - SkStrokeRec fStroke; |
| + // Initialize a path in the range before drawing. This is only called when |
| + // fPathGenerator is non-null. The child class need not call didChangeGpuMemorySize(), |
| + // GrPathRange will take care of that after the call is complete. |
| + virtual void onInitPath(uint32_t index, const SkPath&) const = 0; |
| private: |
| + // Notify when paths will be drawn in case this is a lazy-loaded path range. |
| + friend class GrGpu; |
| + void willDrawPaths(const uint32_t indices[], int count) const; |
| + |
| + mutable SkAutoTDelete<PathGenerator> fPathGenerator; |
| + mutable SkTArray<uint8_t, true /*MEM_COPY*/> fGeneratedPaths; |
| + const uint32_t fNumPaths; |
| + const SkStrokeRec fStroke; |
| + |
| typedef GrGpuResource INHERITED; |
| }; |