Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "GrAAFillRectBatch.h" | 8 #include "GrAAFillRectBatch.h" |
| 9 | 9 |
| 10 #include "GrColor.h" | 10 #include "GrColor.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 } | 192 } |
| 193 | 193 |
| 194 static const GrIndexBuffer* GetIndexBuffer(GrResourceProvider* rp) { | 194 static const GrIndexBuffer* GetIndexBuffer(GrResourceProvider* rp) { |
| 195 return get_index_buffer(rp); | 195 return get_index_buffer(rp); |
| 196 } | 196 } |
| 197 | 197 |
| 198 template <class Geometry> | 198 template <class Geometry> |
| 199 static void SetBounds(const Geometry& geo, SkRect* outBounds) { | 199 static void SetBounds(const Geometry& geo, SkRect* outBounds) { |
| 200 *outBounds = geo.fDevRect; | 200 *outBounds = geo.fDevRect; |
| 201 } | 201 } |
| 202 | |
| 203 template <class Geometry> | |
| 204 static void UpdateBounds(const Geometry& geo, SkRect* outBounds) { | |
| 205 outBounds->join(geo.fDevRect); | |
| 206 } | |
| 202 }; | 207 }; |
| 203 | 208 |
| 204 class AAFillRectBatchNoLocalMatrixImp : public AAFillRectBatchBase { | 209 class AAFillRectBatchNoLocalMatrixImp : public AAFillRectBatchBase { |
| 205 public: | 210 public: |
| 206 struct Geometry { | 211 struct Geometry { |
| 207 SkMatrix fViewMatrix; | 212 SkMatrix fViewMatrix; |
| 208 SkRect fRect; | 213 SkRect fRect; |
| 209 SkRect fDevRect; | 214 SkRect fDevRect; |
| 210 GrColor fColor; | 215 GrColor fColor; |
| 211 }; | 216 }; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry & geo, | 280 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry & geo, |
| 276 const GrPipelineOptimizations& opts) { | 281 const GrPipelineOptimizations& opts) { |
| 277 generate_aa_fill_rect_geometry(vertices, vertexStride, | 282 generate_aa_fill_rect_geometry(vertices, vertexStride, |
| 278 geo.fColor, geo.fViewMatrix, geo.fRect, g eo.fDevRect, opts, | 283 geo.fColor, geo.fViewMatrix, geo.fRect, g eo.fDevRect, opts, |
| 279 &geo.fLocalMatrix); | 284 &geo.fLocalMatrix); |
| 280 } | 285 } |
| 281 }; | 286 }; |
| 282 | 287 |
| 283 typedef GrTInstanceBatch<AAFillRectBatchNoLocalMatrixImp> AAFillRectBatchNoLocal Matrix; | 288 typedef GrTInstanceBatch<AAFillRectBatchNoLocalMatrixImp> AAFillRectBatchNoLocal Matrix; |
| 284 typedef GrTInstanceBatch<AAFillRectBatchLocalMatrixImp> AAFillRectBatchLocalMatr ix; | 289 typedef GrTInstanceBatch<AAFillRectBatchLocalMatrixImp> AAFillRectBatchLocalMatr ix; |
| 285 | 290 |
|
robertphillips
2015/09/18 17:42:25
"inline" these to document our hopes & prayers ?
joshualitt
2015/09/18 18:34:10
Acknowledged.
| |
| 291 static void append_to_batch(AAFillRectBatchNoLocalMatrix* batch, GrColor color, | |
| 292 const SkMatrix& viewMatrix, const SkRect& rect, cons t SkRect& devRect) { | |
| 293 AAFillRectBatchNoLocalMatrix::Geometry& geo = batch->geoData()->push_back(); | |
| 294 geo.fColor = color; | |
| 295 geo.fViewMatrix = viewMatrix; | |
| 296 geo.fRect = rect; | |
| 297 geo.fDevRect = devRect; | |
| 298 } | |
| 299 | |
| 300 static void append_to_batch(AAFillRectBatchLocalMatrix* batch, GrColor color, | |
| 301 const SkMatrix& viewMatrix, const SkMatrix& localMat rix, | |
| 302 const SkRect& rect, const SkRect& devRect) { | |
| 303 AAFillRectBatchLocalMatrix::Geometry& geo = batch->geoData()->push_back(); | |
| 304 geo.fColor = color; | |
| 305 geo.fViewMatrix = viewMatrix; | |
| 306 geo.fLocalMatrix = localMatrix; | |
| 307 geo.fRect = rect; | |
| 308 geo.fDevRect = devRect; | |
| 309 } | |
| 310 | |
| 286 namespace GrAAFillRectBatch { | 311 namespace GrAAFillRectBatch { |
| 287 | 312 |
| 288 GrDrawBatch* Create(GrColor color, | 313 GrDrawBatch* Create(GrColor color, |
| 289 const SkMatrix& viewMatrix, | 314 const SkMatrix& viewMatrix, |
| 290 const SkRect& rect, | 315 const SkRect& rect, |
| 291 const SkRect& devRect) { | 316 const SkRect& devRect) { |
| 292 AAFillRectBatchNoLocalMatrix* batch = AAFillRectBatchNoLocalMatrix::Create() ; | 317 AAFillRectBatchNoLocalMatrix* batch = AAFillRectBatchNoLocalMatrix::Create() ; |
| 293 AAFillRectBatchNoLocalMatrix::Geometry& geo = *batch->geometry(); | 318 append_to_batch(batch, color, viewMatrix, rect, devRect); |
| 294 geo.fColor = color; | |
| 295 geo.fViewMatrix = viewMatrix; | |
| 296 geo.fRect = rect; | |
| 297 geo.fDevRect = devRect; | |
| 298 batch->init(); | 319 batch->init(); |
| 299 return batch; | 320 return batch; |
| 300 } | 321 } |
| 301 | 322 |
| 302 GrDrawBatch* Create(GrColor color, | 323 GrDrawBatch* Create(GrColor color, |
| 303 const SkMatrix& viewMatrix, | 324 const SkMatrix& viewMatrix, |
| 304 const SkMatrix& localMatrix, | 325 const SkMatrix& localMatrix, |
| 305 const SkRect& rect, | 326 const SkRect& rect, |
| 306 const SkRect& devRect) { | 327 const SkRect& devRect) { |
| 307 AAFillRectBatchLocalMatrix* batch = AAFillRectBatchLocalMatrix::Create(); | 328 AAFillRectBatchLocalMatrix* batch = AAFillRectBatchLocalMatrix::Create(); |
| 308 AAFillRectBatchLocalMatrix::Geometry& geo = *batch->geometry(); | 329 append_to_batch(batch, color, viewMatrix, localMatrix, rect, devRect); |
| 309 geo.fColor = color; | |
| 310 geo.fViewMatrix = viewMatrix; | |
| 311 geo.fLocalMatrix = localMatrix; | |
| 312 geo.fRect = rect; | |
| 313 geo.fDevRect = devRect; | |
| 314 batch->init(); | 330 batch->init(); |
| 315 return batch; | 331 return batch; |
| 316 } | 332 } |
| 317 | 333 |
| 334 void Append(GrBatch* origBatch, | |
| 335 GrColor color, | |
| 336 const SkMatrix& viewMatrix, | |
| 337 const SkRect& rect, | |
| 338 const SkRect& devRect) { | |
| 339 AAFillRectBatchNoLocalMatrix* batch = origBatch->cast<AAFillRectBatchNoLocal Matrix>(); | |
| 340 append_to_batch(batch, color, viewMatrix, rect, devRect); | |
| 341 batch->updateBounds(); | |
| 342 } | |
| 343 | |
| 344 void Append(GrBatch* origBatch, | |
| 345 GrColor color, | |
| 346 const SkMatrix& viewMatrix, | |
| 347 const SkMatrix& localMatrix, | |
| 348 const SkRect& rect, | |
| 349 const SkRect& devRect) { | |
| 350 AAFillRectBatchLocalMatrix* batch = origBatch->cast<AAFillRectBatchLocalMatr ix>(); | |
| 351 append_to_batch(batch, color, viewMatrix, localMatrix, rect, devRect); | |
| 352 batch->updateBounds(); | |
| 353 } | |
| 354 | |
| 318 }; | 355 }; |
| 319 | 356 |
| 320 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 357 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
| 321 | 358 |
| 322 #ifdef GR_TEST_UTILS | 359 #ifdef GR_TEST_UTILS |
| 323 | 360 |
| 324 #include "GrBatchTest.h" | 361 #include "GrBatchTest.h" |
| 325 | 362 |
| 326 DRAW_BATCH_TEST_DEFINE(AAFillRectBatch) { | 363 DRAW_BATCH_TEST_DEFINE(AAFillRectBatch) { |
| 327 GrColor color = GrRandomColor(random); | 364 GrColor color = GrRandomColor(random); |
| 328 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); | 365 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 329 SkRect rect = GrTest::TestRect(random); | 366 SkRect rect = GrTest::TestRect(random); |
| 330 SkRect devRect = GrTest::TestRect(random); | 367 SkRect devRect = GrTest::TestRect(random); |
| 331 return GrAAFillRectBatch::Create(color, viewMatrix, rect, devRect); | 368 return GrAAFillRectBatch::Create(color, viewMatrix, rect, devRect); |
| 332 } | 369 } |
| 333 | 370 |
| 334 DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { | 371 DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { |
| 335 GrColor color = GrRandomColor(random); | 372 GrColor color = GrRandomColor(random); |
| 336 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); | 373 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 337 SkMatrix localMatrix = GrTest::TestMatrix(random); | 374 SkMatrix localMatrix = GrTest::TestMatrix(random); |
| 338 SkRect rect = GrTest::TestRect(random); | 375 SkRect rect = GrTest::TestRect(random); |
| 339 SkRect devRect = GrTest::TestRect(random); | 376 SkRect devRect = GrTest::TestRect(random); |
| 340 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect, devRe ct); | 377 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect, devRe ct); |
| 341 } | 378 } |
| 342 | 379 |
| 343 #endif | 380 #endif |
| OLD | NEW |