| 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 UpdateBoundsAfterAppend(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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 291 inline static void append_to_batch(AAFillRectBatchNoLocalMatrix* batch, GrColor
color, |
| 292 const SkMatrix& viewMatrix, const SkRect& rec
t, |
| 293 const SkRect& devRect) { |
| 294 AAFillRectBatchNoLocalMatrix::Geometry& geo = batch->geoData()->push_back(); |
| 295 geo.fColor = color; |
| 296 geo.fViewMatrix = viewMatrix; |
| 297 geo.fRect = rect; |
| 298 geo.fDevRect = devRect; |
| 299 } |
| 300 |
| 301 inline static void append_to_batch(AAFillRectBatchLocalMatrix* batch, GrColor co
lor, |
| 302 const SkMatrix& viewMatrix, const SkMatrix& l
ocalMatrix, |
| 303 const SkRect& rect, const SkRect& devRect) { |
| 304 AAFillRectBatchLocalMatrix::Geometry& geo = batch->geoData()->push_back(); |
| 305 geo.fColor = color; |
| 306 geo.fViewMatrix = viewMatrix; |
| 307 geo.fLocalMatrix = localMatrix; |
| 308 geo.fRect = rect; |
| 309 geo.fDevRect = devRect; |
| 310 } |
| 311 |
| 286 namespace GrAAFillRectBatch { | 312 namespace GrAAFillRectBatch { |
| 287 | 313 |
| 288 GrDrawBatch* Create(GrColor color, | 314 GrDrawBatch* Create(GrColor color, |
| 289 const SkMatrix& viewMatrix, | 315 const SkMatrix& viewMatrix, |
| 290 const SkRect& rect, | 316 const SkRect& rect, |
| 291 const SkRect& devRect) { | 317 const SkRect& devRect) { |
| 292 AAFillRectBatchNoLocalMatrix* batch = AAFillRectBatchNoLocalMatrix::Create()
; | 318 AAFillRectBatchNoLocalMatrix* batch = AAFillRectBatchNoLocalMatrix::Create()
; |
| 293 AAFillRectBatchNoLocalMatrix::Geometry& geo = *batch->geometry(); | 319 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(); | 320 batch->init(); |
| 299 return batch; | 321 return batch; |
| 300 } | 322 } |
| 301 | 323 |
| 302 GrDrawBatch* Create(GrColor color, | 324 GrDrawBatch* Create(GrColor color, |
| 303 const SkMatrix& viewMatrix, | 325 const SkMatrix& viewMatrix, |
| 304 const SkMatrix& localMatrix, | 326 const SkMatrix& localMatrix, |
| 305 const SkRect& rect, | 327 const SkRect& rect, |
| 306 const SkRect& devRect) { | 328 const SkRect& devRect) { |
| 307 AAFillRectBatchLocalMatrix* batch = AAFillRectBatchLocalMatrix::Create(); | 329 AAFillRectBatchLocalMatrix* batch = AAFillRectBatchLocalMatrix::Create(); |
| 308 AAFillRectBatchLocalMatrix::Geometry& geo = *batch->geometry(); | 330 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(); | 331 batch->init(); |
| 315 return batch; | 332 return batch; |
| 316 } | 333 } |
| 317 | 334 |
| 335 void Append(GrBatch* origBatch, |
| 336 GrColor color, |
| 337 const SkMatrix& viewMatrix, |
| 338 const SkRect& rect, |
| 339 const SkRect& devRect) { |
| 340 AAFillRectBatchNoLocalMatrix* batch = origBatch->cast<AAFillRectBatchNoLocal
Matrix>(); |
| 341 append_to_batch(batch, color, viewMatrix, rect, devRect); |
| 342 batch->updateBoundsAfterAppend(); |
| 343 } |
| 344 |
| 345 void Append(GrBatch* origBatch, |
| 346 GrColor color, |
| 347 const SkMatrix& viewMatrix, |
| 348 const SkMatrix& localMatrix, |
| 349 const SkRect& rect, |
| 350 const SkRect& devRect) { |
| 351 AAFillRectBatchLocalMatrix* batch = origBatch->cast<AAFillRectBatchLocalMatr
ix>(); |
| 352 append_to_batch(batch, color, viewMatrix, localMatrix, rect, devRect); |
| 353 batch->updateBoundsAfterAppend(); |
| 354 } |
| 355 |
| 318 }; | 356 }; |
| 319 | 357 |
| 320 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 358 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 321 | 359 |
| 322 #ifdef GR_TEST_UTILS | 360 #ifdef GR_TEST_UTILS |
| 323 | 361 |
| 324 #include "GrBatchTest.h" | 362 #include "GrBatchTest.h" |
| 325 | 363 |
| 326 DRAW_BATCH_TEST_DEFINE(AAFillRectBatch) { | 364 DRAW_BATCH_TEST_DEFINE(AAFillRectBatch) { |
| 327 GrColor color = GrRandomColor(random); | 365 GrColor color = GrRandomColor(random); |
| 328 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); | 366 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 329 SkRect rect = GrTest::TestRect(random); | 367 SkRect rect = GrTest::TestRect(random); |
| 330 SkRect devRect = GrTest::TestRect(random); | 368 SkRect devRect = GrTest::TestRect(random); |
| 331 return GrAAFillRectBatch::Create(color, viewMatrix, rect, devRect); | 369 return GrAAFillRectBatch::Create(color, viewMatrix, rect, devRect); |
| 332 } | 370 } |
| 333 | 371 |
| 334 DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { | 372 DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { |
| 335 GrColor color = GrRandomColor(random); | 373 GrColor color = GrRandomColor(random); |
| 336 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); | 374 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 337 SkMatrix localMatrix = GrTest::TestMatrix(random); | 375 SkMatrix localMatrix = GrTest::TestMatrix(random); |
| 338 SkRect rect = GrTest::TestRect(random); | 376 SkRect rect = GrTest::TestRect(random); |
| 339 SkRect devRect = GrTest::TestRect(random); | 377 SkRect devRect = GrTest::TestRect(random); |
| 340 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect, devRe
ct); | 378 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect, devRe
ct); |
| 341 } | 379 } |
| 342 | 380 |
| 343 #endif | 381 #endif |
| OLD | NEW |