cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrPathRange_DEFINED |
| 9 | #define GrPathRange_DEFINED |
| 10 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 11 | #include "GrGpuResource.h" |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 12 | #include "GrResourceCache.h" |
| 13 | #include "SkStrokeRec.h" |
| 14 | |
| 15 | class SkPath; |
| 16 | |
| 17 | /** |
| 18 | * Represents a contiguous range of GPU path objects with a common stroke. The |
| 19 | * path range is immutable with the exception that individual paths can be |
| 20 | * initialized lazily. Unititialized paths are silently ignored by drawing |
| 21 | * functions. |
| 22 | */ |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 23 | class GrPathRange : public GrGpuResource { |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 24 | public: |
| 25 | SK_DECLARE_INST_COUNT(GrPathRange); |
| 26 | |
| 27 | static const bool kIsWrapped = false; |
| 28 | |
| 29 | static GrResourceKey::ResourceType resourceType() { |
| 30 | static const GrResourceKey::ResourceType type = GrResourceKey::GenerateResourceType(); |
| 31 | return type; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Initialize to a range with a fixed size and stroke. Stroke must not be hairline. |
| 36 | */ |
| 37 | GrPathRange(GrGpu* gpu, size_t size, const SkStrokeRec& stroke) |
| 38 | : INHERITED(gpu, kIsWrapped), |
| 39 | fSize(size), |
| 40 | fStroke(stroke) { |
bsalomon | 1696126 | 2014-08-26 14:01:07 -0700 | [diff] [blame^] | 41 | this->registerWithCache(); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | size_t getSize() const { return fSize; } |
| 45 | const SkStrokeRec& getStroke() const { return fStroke; } |
| 46 | |
| 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 | |
| 53 | protected: |
| 54 | size_t fSize; |
| 55 | SkStrokeRec fStroke; |
| 56 | |
| 57 | private: |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 58 | typedef GrGpuResource INHERITED; |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | #endif |