OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "GrAtlasTextContext.h" | 9 #include "GrAtlasTextContext.h" |
10 #include "GrBatchTest.h" | 10 #include "GrBatchTest.h" |
11 #include "GrColor.h" | 11 #include "GrColor.h" |
12 #include "GrDrawContext.h" | 12 #include "GrDrawContext.h" |
13 #include "GrOvalRenderer.h" | 13 #include "GrOvalRenderer.h" |
14 #include "GrPathRenderer.h" | 14 #include "GrPathRenderer.h" |
15 #include "GrRenderTarget.h" | 15 #include "GrRenderTarget.h" |
16 #include "GrRenderTargetPriv.h" | 16 #include "GrRenderTargetPriv.h" |
17 #include "GrStencilAndCoverTextContext.h" | 17 #include "GrStencilAndCoverTextContext.h" |
18 | 18 |
19 #include "batches/GrBatch.h" | 19 #include "batches/GrBatch.h" |
20 #include "batches/GrDrawAtlasBatch.h" | 20 #include "batches/GrDrawAtlasBatch.h" |
21 #include "batches/GrDrawVerticesBatch.h" | 21 #include "batches/GrDrawVerticesBatch.h" |
22 #include "batches/GrRectBatchFactory.h" | 22 #include "batches/GrRectBatchFactory.h" |
23 | 23 |
24 #include "SkGr.h" | |
25 #include "SkRSXform.h" | |
26 | |
27 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext) | 24 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext) |
28 #define RETURN_IF_ABANDONED if (!fDrawTarget) { return; } | 25 #define RETURN_IF_ABANDONED if (!fDrawTarget) { return; } |
29 #define RETURN_FALSE_IF_ABANDONED if (!fDrawTarget) { return false; } | 26 #define RETURN_FALSE_IF_ABANDONED if (!fDrawTarget) { return false; } |
30 #define RETURN_NULL_IF_ABANDONED if (!fDrawTarget) { return NULL; } | 27 #define RETURN_NULL_IF_ABANDONED if (!fDrawTarget) { return NULL; } |
31 | 28 |
32 class AutoCheckFlush { | 29 class AutoCheckFlush { |
33 public: | 30 public: |
34 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context);
} | 31 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context);
} |
35 ~AutoCheckFlush() { fContext->flushIfNecessary(); } | 32 ~AutoCheckFlush() { fContext->flushIfNecessary(); } |
36 | 33 |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 const SkRect texRect[], | 410 const SkRect texRect[], |
414 const SkColor colors[]) { | 411 const SkColor colors[]) { |
415 RETURN_IF_ABANDONED | 412 RETURN_IF_ABANDONED |
416 AutoCheckFlush acf(fContext); | 413 AutoCheckFlush acf(fContext); |
417 if (!this->prepareToDraw(rt)) { | 414 if (!this->prepareToDraw(rt)) { |
418 return; | 415 return; |
419 } | 416 } |
420 | 417 |
421 GrPipelineBuilder pipelineBuilder(paint, rt, clip); | 418 GrPipelineBuilder pipelineBuilder(paint, rt, clip); |
422 | 419 |
423 // now build the renderable geometry | |
424 const int vertCount = spriteCount * 4; | |
425 SkAutoTMalloc<SkPoint> vertStorage(vertCount * 2); | |
426 SkPoint* verts = vertStorage.get(); | |
427 SkPoint* texs = verts + vertCount; | |
428 | |
429 for (int i = 0; i < spriteCount; ++i) { | |
430 xform[i].toQuad(texRect[i].width(), texRect[i].height(), verts); | |
431 texRect[i].toQuad(texs); | |
432 verts += 4; | |
433 texs += 4; | |
434 } | |
435 | |
436 // TODO clients should give us bounds | |
437 SkRect bounds; | |
438 if (!bounds.setBoundsCheck(vertStorage.get(), vertCount)) { | |
439 SkDebugf("drawAtlas call empty bounds\n"); | |
440 return; | |
441 } | |
442 | |
443 viewMatrix.mapRect(&bounds); | |
444 | |
445 // If we don't have AA then we outset for a half pixel in each direction to
account for | |
446 // snapping | |
447 if (!paint.isAntiAlias()) { | |
448 bounds.outset(0.5f, 0.5f); | |
449 } | |
450 | |
451 SkAutoTMalloc<GrColor> colorStorage; | |
452 GrColor* vertCols = NULL; | |
453 if (colors) { | |
454 colorStorage.reset(vertCount); | |
455 vertCols = colorStorage.get(); | |
456 | |
457 int paintAlpha = GrColorUnpackA(paint.getColor()); | |
458 | |
459 // need to convert byte order and from non-PM to PM | |
460 for (int i = 0; i < spriteCount; ++i) { | |
461 SkColor color = colors[i]; | |
462 if (paintAlpha != 255) { | |
463 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color),
paintAlpha)); | |
464 } | |
465 GrColor grColor = SkColor2GrColor(color); | |
466 | |
467 vertCols[0] = vertCols[1] = vertCols[2] = vertCols[3] = grColor; | |
468 vertCols += 4; | |
469 } | |
470 } | |
471 | |
472 verts = vertStorage.get(); | |
473 texs = verts + vertCount; | |
474 vertCols = colorStorage.get(); | |
475 | |
476 GrDrawAtlasBatch::Geometry geometry; | 420 GrDrawAtlasBatch::Geometry geometry; |
477 geometry.fColor = paint.getColor(); | 421 geometry.fColor = paint.getColor(); |
478 SkAutoTUnref<GrBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatrix, v
erts, vertCount, | 422 SkAutoTUnref<GrBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatrix, s
priteCount, |
479 vertCols, texs, bounds)
); | 423 xform, texRect, colors)
); |
480 | 424 |
481 fDrawTarget->drawBatch(pipelineBuilder, batch); | 425 fDrawTarget->drawBatch(pipelineBuilder, batch); |
482 } | 426 } |
483 | 427 |
484 /////////////////////////////////////////////////////////////////////////////// | 428 /////////////////////////////////////////////////////////////////////////////// |
485 | 429 |
486 void GrDrawContext::drawRRect(GrRenderTarget*rt, | 430 void GrDrawContext::drawRRect(GrRenderTarget*rt, |
487 const GrClip& clip, | 431 const GrClip& clip, |
488 const GrPaint& paint, | 432 const GrPaint& paint, |
489 const SkMatrix& viewMatrix, | 433 const SkMatrix& viewMatrix, |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 RETURN_FALSE_IF_ABANDONED | 768 RETURN_FALSE_IF_ABANDONED |
825 | 769 |
826 ASSERT_OWNED_RESOURCE(rt); | 770 ASSERT_OWNED_RESOURCE(rt); |
827 SkASSERT(rt); | 771 SkASSERT(rt); |
828 return true; | 772 return true; |
829 } | 773 } |
830 | 774 |
831 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrBatch* batch
) { | 775 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrBatch* batch
) { |
832 fDrawTarget->drawBatch(*pipelineBuilder, batch); | 776 fDrawTarget->drawBatch(*pipelineBuilder, batch); |
833 } | 777 } |
OLD | NEW |