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

Side by Side Diff: src/gpu/batches/GrDrawPathBatch.h

Issue 1507203002: Improve nvpr glyph batching (Closed) Base URL: https://skia.googlesource.com/skia.git@upload_drawpathbatch
Patch Set: re-fix issue dependencies Created 5 years 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 | « src/gpu/GrStencilAndCoverTextContext.cpp ('k') | src/gpu/batches/GrDrawPathBatch.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 2015 Google Inc. 2 * Copyright 2015 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 GrDrawPathBatch_DEFINED 8 #ifndef GrDrawPathBatch_DEFINED
9 #define GrDrawPathBatch_DEFINED 9 #define GrDrawPathBatch_DEFINED
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 void onPrepare(GrBatchFlushState*) override {} 87 void onPrepare(GrBatchFlushState*) override {}
88 88
89 void onDraw(GrBatchFlushState* state) override; 89 void onDraw(GrBatchFlushState* state) override;
90 90
91 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; 91 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath;
92 92
93 typedef GrDrawPathBatchBase INHERITED; 93 typedef GrDrawPathBatchBase INHERITED;
94 }; 94 };
95 95
96 /**
97 * This could be nested inside the batch class, but for now it must be declarabl e in a public
98 * header (GrDrawContext)
99 */
100 class GrPathRangeDraw : public GrNonAtomicRef {
101 public:
102 typedef GrPathRendering::PathTransformType TransformType;
103
104 static GrPathRangeDraw* Create(TransformType transformType, int reserveCnt) {
105 return new GrPathRangeDraw(transformType, reserveCnt);
106 }
107
108 void append(uint16_t index, float transform[]) {
109 fTransforms.push_back_n(GrPathRendering::PathTransformSize(fTransformTyp e), transform);
110 fIndices.push_back(index);
111 }
112
113 int count() const { return fIndices.count(); }
114
115 TransformType transformType() const { return fTransformType; }
116
117 const float* transforms() const { return fTransforms.begin(); }
118
119 const uint16_t* indices() const { return fIndices.begin(); }
120
121 static bool CanMerge(const GrPathRangeDraw& a, const GrPathRangeDraw& b) {
122 return a.transformType() == b.transformType();
123 }
124
125 private:
126 GrPathRangeDraw(TransformType transformType, int reserveCnt)
127 : fTransformType(transformType)
128 , fIndices(reserveCnt)
129 , fTransforms(reserveCnt * GrPathRendering::PathTransformSize(transformT ype)) {
130 SkDEBUGCODE(fUsedInBatch = false;)
131 }
132
133 // Reserve space for 64 paths where indices are 16 bit and transforms are tr anslations.
134 static const int kIndexReserveCnt = 64;
135 static const int kTransformBufferReserveCnt = 2 * 64;
136
137 GrPathRendering::PathTransformType fTransformType;
138 SkSTArray<kIndexReserveCnt, uint16_t, true> fIndices;
139 SkSTArray<kTransformBufferReserveCnt, float, true> fTransforms;
140
141 // To ensure we don't reuse these across batches.
142 #ifdef SK_DEBUG
143 bool fUsedInBatch;
144 friend class GrDrawPathRangeBatch;
145 #endif
146
147 typedef GrNonAtomicRef INHERITED;
148 };
149
150 // Template this if we decide to support index types other than 16bit 96 // Template this if we decide to support index types other than 16bit
151 class GrDrawPathRangeBatch final : public GrDrawPathBatchBase { 97 class GrDrawPathRangeBatch final : public GrDrawPathBatchBase {
152 public: 98 public:
99 typedef GrPathRendering::PathTransformType TransformType;
100
153 DEFINE_BATCH_CLASS_ID 101 DEFINE_BATCH_CLASS_ID
154 102
103 struct InstanceData : public SkNoncopyable {
104 public:
105 static InstanceData* Alloc(TransformType transformType, int reserveCnt) {
106 int transformSize = GrPathRendering::PathTransformSize(transformType );
107 uint8_t* ptr = (uint8_t*)sk_malloc_throw(Align32(sizeof(InstanceData )) +
108 Align32(reserveCnt * sizeof (uint16_t)) +
109 reserveCnt * transformSize * sizeof(float));
110 InstanceData* instanceData = (InstanceData*)ptr;
111 instanceData->fIndices = (uint16_t*)&ptr[Align32(sizeof(InstanceData ))];
112 instanceData->fTransformValues = (float*)&ptr[Align32(sizeof(Instanc eData)) +
113 Align32(reserveCnt * s izeof(uint16_t))];
114 instanceData->fTransformType = transformType;
115 instanceData->fInstanceCount = 0;
116 instanceData->fRefCnt = 1;
117 SkDEBUGCODE(instanceData->fReserveCnt = reserveCnt;)
118 return instanceData;
119 }
120
121 // Overload this method if we start using other transform types.
122 void append(uint16_t index, float x, float y) {
123 SkASSERT(GrPathRendering::kTranslate_PathTransformType == fTransform Type);
124 SkASSERT(fInstanceCount < fReserveCnt);
125 fIndices[fInstanceCount] = index;
126 fTransformValues[2 * fInstanceCount] = x;
127 fTransformValues[2 * fInstanceCount + 1] = y;
128 ++fInstanceCount;
129 }
130
131 TransformType transformType() const { return fTransformType; }
132 int count() const { return fInstanceCount; }
133
134 const uint16_t* indices() const { return fIndices; }
135 uint16_t* indices() { return fIndices; }
136
137 const float* transformValues() const { return fTransformValues; }
138 float* transformValues() { return fTransformValues; }
139
140 void ref() const { ++fRefCnt; }
141
142 void unref() const {
143 if (0 == --fRefCnt) {
144 sk_free(const_cast<InstanceData*>(this));
145 }
146 }
147
148 private:
149 static int Align32(int sizeInBytes) { return (sizeInBytes + 3) & ~3; }
150
151 InstanceData() {}
152 ~InstanceData() {}
153
154 uint16_t* fIndices;
155 float* fTransformValues;
156 TransformType fTransformType;
157 int fInstanceCount;
158 mutable int fRefCnt;
159 SkDEBUGCODE(int fReserveCnt;)
160 };
161
155 // This can't return a more abstract type because we install the stencil set tings late :( 162 // This can't return a more abstract type because we install the stencil set tings late :(
156 static GrDrawPathBatchBase* Create(const SkMatrix& viewMatrix, const SkMatri x& localMatrix, 163 static GrDrawPathBatchBase* Create(const SkMatrix& viewMatrix, SkScalar scal e, SkScalar x,
157 GrColor color, GrPathRendering::FillType fill, 164 SkScalar y, GrColor color, GrPathRenderin g::FillType fill,
158 GrPathRange* range, GrPathRangeDraw* draw , 165 GrPathRange* range, const InstanceData* i nstanceData,
159 const SkRect& bounds) { 166 const SkRect& bounds) {
160 return new GrDrawPathRangeBatch(viewMatrix, localMatrix, color, fill, ra nge, draw, 167 return new GrDrawPathRangeBatch(viewMatrix, scale, x, y, color, fill, ra nge, instanceData,
161 bounds); 168 bounds);
162 } 169 }
163 170
164 ~GrDrawPathRangeBatch() override;
165
166 const char* name() const override { return "DrawPathRange"; } 171 const char* name() const override { return "DrawPathRange"; }
167 172
168 SkString dumpInfo() const override; 173 SkString dumpInfo() const override;
169 174
170 private: 175 private:
171 GrDrawPathRangeBatch(const SkMatrix& viewMatrix, const SkMatrix& localMatrix , GrColor color, 176 GrDrawPathRangeBatch(const SkMatrix& viewMatrix, SkScalar scale, SkScalar x, SkScalar y,
172 GrPathRendering::FillType fill, GrPathRange* range, 177 GrColor color, GrPathRendering::FillType fill, GrPathRa nge* range,
173 GrPathRangeDraw* draw, const SkRect& bounds); 178 const InstanceData* instanceData, const SkRect& bounds) ;
179
180 TransformType transformType() const { return fDraws.head()->fInstanceData->t ransformType(); }
174 181
175 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override; 182 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override;
176 183
177 void onPrepare(GrBatchFlushState*) override {} 184 void onPrepare(GrBatchFlushState*) override {}
178 185
179 void onDraw(GrBatchFlushState* state) override; 186 void onDraw(GrBatchFlushState* state) override;
180 187
188 struct Draw {
189 void set(const InstanceData* instanceData, SkScalar x, SkScalar y) {
190 fInstanceData.reset(SkRef(instanceData));
191 fX = x;
192 fY = y;
193 }
194
195 SkAutoTUnref<const InstanceData> fInstanceData;
196 SkScalar fX, fY;
197 };
198
181 typedef GrPendingIOResource<const GrPathRange, kRead_GrIOType> PendingPathRa nge; 199 typedef GrPendingIOResource<const GrPathRange, kRead_GrIOType> PendingPathRa nge;
182 typedef SkTLList<GrPathRangeDraw*, 4> DrawList; 200 typedef SkTLList<Draw, 4> DrawList;
201
183 PendingPathRange fPathRange; 202 PendingPathRange fPathRange;
184 DrawList fDraws; 203 DrawList fDraws;
185 int fTotalPathCount; 204 int fTotalPathCount;
186 SkMatrix fLocalMatrix; 205 SkScalar fScale;
187 206
188 typedef GrDrawPathBatchBase INHERITED; 207 typedef GrDrawPathBatchBase INHERITED;
189 }; 208 };
190 209
191 #endif 210 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrStencilAndCoverTextContext.cpp ('k') | src/gpu/batches/GrDrawPathBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698