Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: src/gpu/GrPathRange.h

Issue 1382013002: Make path range loading explicit (Closed) Base URL: https://skia.googlesource.com/skia.git@upload4_cache
Patch Set: Fix clang build Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/gpu/GrPathRange.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkPath.h"
12 #include "SkRefCnt.h" 13 #include "SkRefCnt.h"
13 #include "SkTArray.h" 14 #include "SkTArray.h"
14 15
15 class SkPath;
16 class SkDescriptor; 16 class SkDescriptor;
17 17
18 /** 18 /**
19 * Represents a contiguous range of GPU path objects. 19 * Represents a contiguous range of GPU path objects.
20 * This object is immutable with the exception that individual paths may be 20 * This object is immutable with the exception that individual paths may be
21 * initialized lazily. 21 * initialized lazily.
22 */ 22 */
23 23
24 class GrPathRange : public GrGpuResource { 24 class GrPathRange : public GrGpuResource {
25 public: 25 public:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 /** 64 /**
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;
74
75 template<typename IndexType> void loadPathsIfNeeded(const void* indices, int count) const {
76 if (!fPathGenerator) {
77 return;
78 }
79
80 const IndexType* indexArray = reinterpret_cast<const IndexType*>(indices );
81 bool didLoadPaths = false;
82
83 for (int i = 0; i < count; ++i) {
84 SkASSERT(indexArray[i] < static_cast<uint32_t>(fNumPaths));
85
86 const int groupIndex = indexArray[i] / kPathsPerGroup;
87 const int groupByte = groupIndex / 8;
88 const uint8_t groupBit = 1 << (groupIndex % 8);
89
90 const bool hasPath = SkToBool(fGeneratedPaths[groupByte] & groupBit) ;
91 if (!hasPath) {
92 // We track which paths are loaded in groups of kPathsPerGroup. To
93 // mark a path as loaded we need to load the entire group.
94 const int groupFirstPath = groupIndex * kPathsPerGroup;
95 const int groupLastPath = SkTMin(groupFirstPath + kPathsPerGroup , fNumPaths) - 1;
96
97 SkPath path;
98 for (int pathIdx = groupFirstPath; pathIdx <= groupLastPath; ++p athIdx) {
99 fPathGenerator->generatePath(pathIdx, &path);
100 this->onInitPath(pathIdx, path);
101 }
102
103 fGeneratedPaths[groupByte] |= groupBit;
104 didLoadPaths = true;
105 }
106 }
107
108 if (didLoadPaths) {
109 this->didChangeGpuMemorySize();
110 }
111 }
112
73 #ifdef SK_DEBUG 113 #ifdef SK_DEBUG
114 void assertPathsLoaded(const void* indices, PathIndexType, int count) const;
115
116 template<typename IndexType> void assertPathsLoaded(const void* indices, int count) const {
117 if (!fPathGenerator) {
118 return;
119 }
120
121 const IndexType* indexArray = reinterpret_cast<const IndexType*>(indices );
122
123 for (int i = 0; i < count; ++i) {
124 SkASSERT(indexArray[i] < static_cast<uint32_t>(fNumPaths));
125
126 const int groupIndex = indexArray[i] / kPathsPerGroup;
127 const int groupByte = groupIndex / 8;
128 const uint8_t groupBit = 1 << (groupIndex % 8);
129
130 SkASSERT(fGeneratedPaths[groupByte] & groupBit);
131 }
132 }
133
74 virtual bool isEqualTo(const SkDescriptor& desc) const { 134 virtual bool isEqualTo(const SkDescriptor& desc) const {
75 return nullptr != fPathGenerator.get() && fPathGenerator->isEqualTo(desc ); 135 return nullptr != fPathGenerator.get() && fPathGenerator->isEqualTo(desc );
76 } 136 }
77 #endif 137 #endif
78 protected: 138 protected:
79 // Initialize a path in the range before drawing. This is only called when 139 // Initialize a path in the range before drawing. This is only called when
80 // fPathGenerator is non-null. The child class need not call didChangeGpuMem orySize(), 140 // fPathGenerator is non-null. The child class need not call didChangeGpuMem orySize(),
81 // GrPathRange will take care of that after the call is complete. 141 // GrPathRange will take care of that after the call is complete.
82 virtual void onInitPath(int index, const SkPath&) const = 0; 142 virtual void onInitPath(int index, const SkPath&) const = 0;
83 143
84 private: 144 private:
85 // Notify when paths will be drawn in case this is a lazy-loaded path range. 145 enum {
86 friend class GrPathRendering; 146 kPathsPerGroup = 16 // Paths get tracked in groups of 16 for lazy loadin g.
87 void willDrawPaths(const void* indices, PathIndexType, int count) const; 147 };
88 template<typename IndexType> void willDrawPaths(const void* indices, int cou nt) const;
89 148
90 mutable SkAutoTUnref<PathGenerator> fPathGenerator; 149 mutable SkAutoTUnref<PathGenerator> fPathGenerator;
91 mutable SkTArray<uint8_t, true /*MEM_COPY*/> fGeneratedPaths; 150 mutable SkTArray<uint8_t, true /*MEM_COPY*/> fGeneratedPaths;
92 const int fNumPaths; 151 const int fNumPaths;
93 152
94 typedef GrGpuResource INHERITED; 153 typedef GrGpuResource INHERITED;
95 }; 154 };
96 155
97 #endif 156 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrPathRange.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698