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

Side by Side Diff: src/gpu/batches/GrNonAAFillRectBatch.cpp

Issue 1353553002: Create append methods in batch namespaces (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rob's feedback Created 5 years, 3 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 | « src/gpu/batches/GrNonAAFillRectBatch.h ('k') | src/gpu/batches/GrNonAAStrokeRectBatch.h » ('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 #include "GrNonAAFillRectBatch.h" 8 #include "GrNonAAFillRectBatch.h"
9 9
10 #include "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
(...skipping 16 matching lines...) Expand all
27 } 27 }
28 28
29 static const GrIndexBuffer* GetIndexBuffer(GrResourceProvider* rp) { 29 static const GrIndexBuffer* GetIndexBuffer(GrResourceProvider* rp) {
30 return rp->refQuadIndexBuffer(); 30 return rp->refQuadIndexBuffer();
31 } 31 }
32 32
33 template <typename Geometry> 33 template <typename Geometry>
34 static void SetBounds(const Geometry& geo, SkRect* outBounds) { 34 static void SetBounds(const Geometry& geo, SkRect* outBounds) {
35 geo.fViewMatrix.mapRect(outBounds, geo.fRect); 35 geo.fViewMatrix.mapRect(outBounds, geo.fRect);
36 } 36 }
37
38 template <typename Geometry>
39 static void UpdateBoundsAfterAppend(const Geometry& geo, SkRect* outBounds) {
40 SkRect bounds = geo.fRect;
41 geo.fViewMatrix.mapRect(&bounds);
42 outBounds->join(bounds);
43 }
37 }; 44 };
38 45
39 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes 46 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes
40 we have explicit local coords and sometimes not. We *could* always provide explicit local 47 we have explicit local coords and sometimes not. We *could* always provide explicit local
41 coords and just duplicate the positions when the caller hasn't provided a lo cal coord rect, 48 coords and just duplicate the positions when the caller hasn't provided a lo cal coord rect,
42 but we haven't seen a use case which frequently switches between local rect and no local 49 but we haven't seen a use case which frequently switches between local rect and no local
43 rect draws. 50 rect draws.
44 51
45 The vertex attrib order is always pos, color, [local coords]. 52 The vertex attrib order is always pos, color, [local coords].
46 */ 53 */
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.f Rect, &quad); 187 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.f Rect, &quad);
181 } else { 188 } else {
182 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.f Rect, nullptr); 189 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.f Rect, nullptr);
183 } 190 }
184 } 191 }
185 }; 192 };
186 193
187 typedef GrTInstanceBatch<NonAAFillRectBatchImp> NonAAFillRectBatchSimple; 194 typedef GrTInstanceBatch<NonAAFillRectBatchImp> NonAAFillRectBatchSimple;
188 typedef GrTInstanceBatch<NonAAFillRectBatchPerspectiveImp> NonAAFillRectBatchPer spective; 195 typedef GrTInstanceBatch<NonAAFillRectBatchPerspectiveImp> NonAAFillRectBatchPer spective;
189 196
190 namespace GrNonAAFillRectBatch { 197 inline static void append_to_batch(NonAAFillRectBatchSimple* batch, GrColor colo r,
191 198 const SkMatrix& viewMatrix, const SkRect& rec t,
192 GrDrawBatch* Create(GrColor color, 199 const SkRect* localRect, const SkMatrix* loca lMatrix) {
193 const SkMatrix& viewMatrix,
194 const SkRect& rect,
195 const SkRect* localRect,
196 const SkMatrix* localMatrix) {
197 SkASSERT(!viewMatrix.hasPerspective() && (!localMatrix || !localMatrix->hasP erspective())); 200 SkASSERT(!viewMatrix.hasPerspective() && (!localMatrix || !localMatrix->hasP erspective()));
198 NonAAFillRectBatchSimple* batch = NonAAFillRectBatchSimple::Create(); 201 NonAAFillRectBatchSimple::Geometry& geo = batch->geoData()->push_back();
199 NonAAFillRectBatchSimple::Geometry& geo = *batch->geometry();
200 202
201 geo.fColor = color; 203 geo.fColor = color;
202 geo.fViewMatrix = viewMatrix; 204 geo.fViewMatrix = viewMatrix;
203 geo.fRect = rect; 205 geo.fRect = rect;
204 206
205 if (localRect && localMatrix) { 207 if (localRect && localMatrix) {
206 geo.fLocalQuad.setFromMappedRect(*localRect, *localMatrix); 208 geo.fLocalQuad.setFromMappedRect(*localRect, *localMatrix);
207 } else if (localRect) { 209 } else if (localRect) {
208 geo.fLocalQuad.set(*localRect); 210 geo.fLocalQuad.set(*localRect);
209 } else if (localMatrix) { 211 } else if (localMatrix) {
210 geo.fLocalQuad.setFromMappedRect(rect, *localMatrix); 212 geo.fLocalQuad.setFromMappedRect(rect, *localMatrix);
211 } else { 213 } else {
212 geo.fLocalQuad.set(rect); 214 geo.fLocalQuad.set(rect);
213 } 215 }
214
215 batch->init();
216 return batch;
217 } 216 }
218 217
219 GrDrawBatch* CreateWithPerspective(GrColor color, 218 inline static void append_to_batch(NonAAFillRectBatchPerspective* batch, GrColor color,
220 const SkMatrix& viewMatrix, 219 const SkMatrix& viewMatrix, const SkRect& rec t,
221 const SkRect& rect, 220 const SkRect* localRect, const SkMatrix* loca lMatrix) {
222 const SkRect* localRect,
223 const SkMatrix* localMatrix) {
224 SkASSERT(viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPers pective())); 221 SkASSERT(viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPers pective()));
225 NonAAFillRectBatchPerspective* batch = NonAAFillRectBatchPerspective::Create (); 222 NonAAFillRectBatchPerspective::Geometry& geo = batch->geoData()->push_back() ;
226 NonAAFillRectBatchPerspective::Geometry& geo = *batch->geometry();
227 223
228 geo.fColor = color; 224 geo.fColor = color;
229 geo.fViewMatrix = viewMatrix; 225 geo.fViewMatrix = viewMatrix;
230 geo.fRect = rect; 226 geo.fRect = rect;
231 geo.fHasLocalRect = SkToBool(localRect); 227 geo.fHasLocalRect = SkToBool(localRect);
232 geo.fHasLocalMatrix = SkToBool(localMatrix); 228 geo.fHasLocalMatrix = SkToBool(localMatrix);
233 if (localMatrix) { 229 if (localMatrix) {
234 geo.fLocalMatrix = *localMatrix; 230 geo.fLocalMatrix = *localMatrix;
235 } 231 }
236 if (localRect) { 232 if (localRect) {
237 geo.fLocalRect = *localRect; 233 geo.fLocalRect = *localRect;
238 } 234 }
239 235
236 }
237
238 namespace GrNonAAFillRectBatch {
239
240 GrDrawBatch* Create(GrColor color,
241 const SkMatrix& viewMatrix,
242 const SkRect& rect,
243 const SkRect* localRect,
244 const SkMatrix* localMatrix) {
245 NonAAFillRectBatchSimple* batch = NonAAFillRectBatchSimple::Create();
246 append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix);
240 batch->init(); 247 batch->init();
241 return batch; 248 return batch;
242 } 249 }
243 250
251 GrDrawBatch* CreateWithPerspective(GrColor color,
252 const SkMatrix& viewMatrix,
253 const SkRect& rect,
254 const SkRect* localRect,
255 const SkMatrix* localMatrix) {
256 NonAAFillRectBatchPerspective* batch = NonAAFillRectBatchPerspective::Create ();
257 append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix);
258 batch->init();
259 return batch;
260 }
261
262 bool Append(GrBatch* origBatch,
263 GrColor color,
264 const SkMatrix& viewMatrix,
265 const SkRect& rect,
266 const SkRect* localRect,
267 const SkMatrix* localMatrix) {
268 bool usePerspective = viewMatrix.hasPerspective() ||
269 (localMatrix && localMatrix->hasPerspective());
270
271 if (usePerspective && origBatch->classID() != NonAAFillRectBatchPerspective: :ClassID()) {
272 return false;
273 }
274
275 if (!usePerspective) {
276 NonAAFillRectBatchSimple* batch = origBatch->cast<NonAAFillRectBatchSimp le>();
277 append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix);
278 batch->updateBoundsAfterAppend();
279 } else {
280 NonAAFillRectBatchPerspective* batch = origBatch->cast<NonAAFillRectBatc hPerspective>();
281 const NonAAFillRectBatchPerspective::Geometry& geo = batch->geoData()->b ack();
282
283 if (!geo.fViewMatrix.cheapEqualTo(viewMatrix) ||
284 geo.fHasLocalRect != SkToBool(localRect) ||
285 geo.fHasLocalMatrix != SkToBool(localMatrix) ||
286 (geo.fHasLocalMatrix && !geo.fLocalMatrix.cheapEqualTo(*localMatrix) )) {
287 return false;
288 }
289
290 append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix);
291 batch->updateBoundsAfterAppend();
292 }
293
294 return true;
295 }
296
244 }; 297 };
245 298
246 //////////////////////////////////////////////////////////////////////////////// /////////////////// 299 //////////////////////////////////////////////////////////////////////////////// ///////////////////
247 300
248 #ifdef GR_TEST_UTILS 301 #ifdef GR_TEST_UTILS
249 302
250 #include "GrBatchTest.h" 303 #include "GrBatchTest.h"
251 304
252 DRAW_BATCH_TEST_DEFINE(RectBatch) { 305 DRAW_BATCH_TEST_DEFINE(RectBatch) {
253 GrColor color = GrRandomColor(random); 306 GrColor color = GrRandomColor(random);
254 SkRect rect = GrTest::TestRect(random); 307 SkRect rect = GrTest::TestRect(random);
255 SkRect localRect = GrTest::TestRect(random); 308 SkRect localRect = GrTest::TestRect(random);
256 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); 309 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
257 SkMatrix localMatrix = GrTest::TestMatrix(random); 310 SkMatrix localMatrix = GrTest::TestMatrix(random);
258 311
259 bool hasLocalRect = random->nextBool(); 312 bool hasLocalRect = random->nextBool();
260 bool hasLocalMatrix = random->nextBool(); 313 bool hasLocalMatrix = random->nextBool();
261 return GrNonAAFillRectBatch::Create(color, viewMatrix, rect, 314 return GrNonAAFillRectBatch::Create(color, viewMatrix, rect,
262 hasLocalRect ? &localRect : nullptr, 315 hasLocalRect ? &localRect : nullptr,
263 hasLocalMatrix ? &localMatrix : nullptr) ; 316 hasLocalMatrix ? &localMatrix : nullptr) ;
264 } 317 }
265 318
266 #endif 319 #endif
OLDNEW
« no previous file with comments | « src/gpu/batches/GrNonAAFillRectBatch.h ('k') | src/gpu/batches/GrNonAAStrokeRectBatch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698