| 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 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 * Initialize an eager-loaded path range. The subclass is responsible for en
suring all | 65 * Initialize an eager-loaded path range. The subclass is responsible for en
suring all |
| 66 * the paths are initialized up front. | 66 * the paths are initialized up front. |
| 67 */ | 67 */ |
| 68 GrPathRange(GrGpu*, int numPaths); | 68 GrPathRange(GrGpu*, int numPaths); |
| 69 | 69 |
| 70 int getNumPaths() const { return fNumPaths; } | 70 int getNumPaths() const { return fNumPaths; } |
| 71 const PathGenerator* getPathGenerator() const { return fPathGenerator.get();
} | 71 const PathGenerator* getPathGenerator() const { return fPathGenerator.get();
} |
| 72 | 72 |
| 73 void loadPathsIfNeeded(const void* indices, PathIndexType, int count) const; | 73 void loadPathsIfNeeded(const void* indices, PathIndexType, int count) const; |
| 74 | 74 |
| 75 template<typename IndexType> void loadPathsIfNeeded(const void* indices, int
count) const { | 75 template<typename IndexType> void loadPathsIfNeeded(const IndexType* indices
, int count) const { |
| 76 if (!fPathGenerator) { | 76 if (!fPathGenerator) { |
| 77 return; | 77 return; |
| 78 } | 78 } |
| 79 | 79 |
| 80 const IndexType* indexArray = reinterpret_cast<const IndexType*>(indices
); | |
| 81 bool didLoadPaths = false; | 80 bool didLoadPaths = false; |
| 82 | 81 |
| 83 for (int i = 0; i < count; ++i) { | 82 for (int i = 0; i < count; ++i) { |
| 84 SkASSERT(indexArray[i] < static_cast<uint32_t>(fNumPaths)); | 83 SkASSERT(indices[i] < static_cast<uint32_t>(fNumPaths)); |
| 85 | 84 |
| 86 const int groupIndex = indexArray[i] / kPathsPerGroup; | 85 const int groupIndex = indices[i] / kPathsPerGroup; |
| 87 const int groupByte = groupIndex / 8; | 86 const int groupByte = groupIndex / 8; |
| 88 const uint8_t groupBit = 1 << (groupIndex % 8); | 87 const uint8_t groupBit = 1 << (groupIndex % 8); |
| 89 | 88 |
| 90 const bool hasPath = SkToBool(fGeneratedPaths[groupByte] & groupBit)
; | 89 const bool hasPath = SkToBool(fGeneratedPaths[groupByte] & groupBit)
; |
| 91 if (!hasPath) { | 90 if (!hasPath) { |
| 92 // We track which paths are loaded in groups of kPathsPerGroup.
To | 91 // We track which paths are loaded in groups of kPathsPerGroup.
To |
| 93 // mark a path as loaded we need to load the entire group. | 92 // mark a path as loaded we need to load the entire group. |
| 94 const int groupFirstPath = groupIndex * kPathsPerGroup; | 93 const int groupFirstPath = groupIndex * kPathsPerGroup; |
| 95 const int groupLastPath = SkTMin(groupFirstPath + kPathsPerGroup
, fNumPaths) - 1; | 94 const int groupLastPath = SkTMin(groupFirstPath + kPathsPerGroup
, fNumPaths) - 1; |
| 96 | 95 |
| 97 SkPath path; | 96 SkPath path; |
| 98 for (int pathIdx = groupFirstPath; pathIdx <= groupLastPath; ++p
athIdx) { | 97 for (int pathIdx = groupFirstPath; pathIdx <= groupLastPath; ++p
athIdx) { |
| 99 fPathGenerator->generatePath(pathIdx, &path); | 98 fPathGenerator->generatePath(pathIdx, &path); |
| 100 this->onInitPath(pathIdx, path); | 99 this->onInitPath(pathIdx, path); |
| 101 } | 100 } |
| 102 | 101 |
| 103 fGeneratedPaths[groupByte] |= groupBit; | 102 fGeneratedPaths[groupByte] |= groupBit; |
| 104 didLoadPaths = true; | 103 didLoadPaths = true; |
| 105 } | 104 } |
| 106 } | 105 } |
| 107 | 106 |
| 108 if (didLoadPaths) { | 107 if (didLoadPaths) { |
| 109 this->didChangeGpuMemorySize(); | 108 this->didChangeGpuMemorySize(); |
| 110 } | 109 } |
| 111 } | 110 } |
| 112 | 111 |
| 113 #ifdef SK_DEBUG | 112 #ifdef SK_DEBUG |
| 114 void assertPathsLoaded(const void* indices, PathIndexType, int count) const; | 113 void assertPathsLoaded(const void* indices, PathIndexType, int count) const; |
| 115 | 114 |
| 116 template<typename IndexType> void assertPathsLoaded(const void* indices, int
count) const { | 115 template<typename IndexType> void assertPathsLoaded(const IndexType* indices
, int count) const { |
| 117 if (!fPathGenerator) { | 116 if (!fPathGenerator) { |
| 118 return; | 117 return; |
| 119 } | 118 } |
| 120 | 119 |
| 121 const IndexType* indexArray = reinterpret_cast<const IndexType*>(indices
); | 120 for (int i = 0; i < count; ++i) { |
| 121 SkASSERT(indices[i] < static_cast<uint32_t>(fNumPaths)); |
| 122 | 122 |
| 123 for (int i = 0; i < count; ++i) { | 123 const int groupIndex = indices[i] / kPathsPerGroup; |
| 124 SkASSERT(indexArray[i] < static_cast<uint32_t>(fNumPaths)); | |
| 125 | |
| 126 const int groupIndex = indexArray[i] / kPathsPerGroup; | |
| 127 const int groupByte = groupIndex / 8; | 124 const int groupByte = groupIndex / 8; |
| 128 const uint8_t groupBit = 1 << (groupIndex % 8); | 125 const uint8_t groupBit = 1 << (groupIndex % 8); |
| 129 | 126 |
| 130 SkASSERT(fGeneratedPaths[groupByte] & groupBit); | 127 SkASSERT(fGeneratedPaths[groupByte] & groupBit); |
| 131 } | 128 } |
| 132 } | 129 } |
| 133 | 130 |
| 134 virtual bool isEqualTo(const SkDescriptor& desc) const { | 131 virtual bool isEqualTo(const SkDescriptor& desc) const { |
| 135 return nullptr != fPathGenerator.get() && fPathGenerator->isEqualTo(desc
); | 132 return nullptr != fPathGenerator.get() && fPathGenerator->isEqualTo(desc
); |
| 136 } | 133 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 147 }; | 144 }; |
| 148 | 145 |
| 149 mutable SkAutoTUnref<PathGenerator> fPathGenerator; | 146 mutable SkAutoTUnref<PathGenerator> fPathGenerator; |
| 150 mutable SkTArray<uint8_t, true /*MEM_COPY*/> fGeneratedPaths; | 147 mutable SkTArray<uint8_t, true /*MEM_COPY*/> fGeneratedPaths; |
| 151 const int fNumPaths; | 148 const int fNumPaths; |
| 152 | 149 |
| 153 typedef GrGpuResource INHERITED; | 150 typedef GrGpuResource INHERITED; |
| 154 }; | 151 }; |
| 155 | 152 |
| 156 #endif | 153 #endif |
| OLD | NEW |