commit-bot@chromium.org | c4b21e6 | 2014-04-11 18:33:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 8 | #include "SkRecordDraw.h" |
| 9 | |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 10 | void SkRecordDraw(const SkRecord& record, SkCanvas* canvas, SkDrawPictureCallback* callback) { |
| 11 | SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 12 | for (SkRecords::Draw draw(canvas); draw.index() < record.count(); draw.next()) { |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 13 | if (NULL != callback && callback->abortDrawing()) { |
| 14 | return; |
| 15 | } |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 16 | record.visit<void>(draw.index(), draw); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 17 | } |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 18 | } |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 19 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 20 | namespace SkRecords { |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 21 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 22 | bool Draw::skip(const PairedPushCull& r) { |
| 23 | if (fCanvas->quickReject(r.base->rect)) { |
| 24 | fIndex += r.skip; |
| 25 | return true; |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 26 | } |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 27 | return false; |
| 28 | } |
commit-bot@chromium.org | 2e0c32a | 2014-04-28 16:19:45 +0000 | [diff] [blame] | 29 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 30 | bool Draw::skip(const BoundedDrawPosTextH& r) { |
| 31 | return fCanvas->quickRejectY(r.minY, r.maxY); |
| 32 | } |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 33 | |
mtklein | 7cdc1ee | 2014-07-07 10:41:04 -0700 | [diff] [blame] | 34 | // FIXME: SkBitmaps are stateful, so we need to copy them to play back in multiple threads. |
| 35 | static SkBitmap shallow_copy(const SkBitmap& bitmap) { |
| 36 | return bitmap; |
| 37 | } |
| 38 | |
commit-bot@chromium.org | 2e0c32a | 2014-04-28 16:19:45 +0000 | [diff] [blame] | 39 | // NoOps draw nothing. |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 40 | template <> void Draw::draw(const NoOp&) {} |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 41 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 42 | #define DRAW(T, call) template <> void Draw::draw(const T& r) { fCanvas->call; } |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 43 | DRAW(Restore, restore()); |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 44 | DRAW(Save, save()); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 45 | DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags)); |
| 46 | DRAW(PopCull, popCull()); |
commit-bot@chromium.org | 88c3e27 | 2014-04-22 16:57:20 +0000 | [diff] [blame] | 47 | DRAW(PushCull, pushCull(r.rect)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 48 | DRAW(Clear, clear(r.color)); |
| 49 | DRAW(Concat, concat(r.matrix)); |
commit-bot@chromium.org | 99bd7d8 | 2014-05-19 15:51:12 +0000 | [diff] [blame] | 50 | DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix))); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 51 | |
| 52 | DRAW(ClipPath, clipPath(r.path, r.op, r.doAA)); |
| 53 | DRAW(ClipRRect, clipRRect(r.rrect, r.op, r.doAA)); |
| 54 | DRAW(ClipRect, clipRect(r.rect, r.op, r.doAA)); |
| 55 | DRAW(ClipRegion, clipRegion(r.region, r.op)); |
| 56 | |
mtklein | 7cdc1ee | 2014-07-07 10:41:04 -0700 | [diff] [blame] | 57 | DRAW(DrawBitmap, drawBitmap(shallow_copy(r.bitmap), r.left, r.top, r.paint)); |
| 58 | DRAW(DrawBitmapMatrix, drawBitmapMatrix(shallow_copy(r.bitmap), r.matrix, r.paint)); |
| 59 | DRAW(DrawBitmapNine, drawBitmapNine(shallow_copy(r.bitmap), r.center, r.dst, r.paint)); |
| 60 | DRAW(DrawBitmapRectToRect, |
| 61 | drawBitmapRectToRect(shallow_copy(r.bitmap), r.src, r.dst, r.paint, r.flags)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 62 | DRAW(DrawDRRect, drawDRRect(r.outer, r.inner, r.paint)); |
| 63 | DRAW(DrawOval, drawOval(r.oval, r.paint)); |
| 64 | DRAW(DrawPaint, drawPaint(r.paint)); |
| 65 | DRAW(DrawPath, drawPath(r.path, r.paint)); |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame^] | 66 | DRAW(DrawPatch, drawPatch(r.patch, r.paint)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 67 | DRAW(DrawPoints, drawPoints(r.mode, r.count, r.pts, r.paint)); |
| 68 | DRAW(DrawPosText, drawPosText(r.text, r.byteLength, r.pos, r.paint)); |
| 69 | DRAW(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint)); |
| 70 | DRAW(DrawRRect, drawRRect(r.rrect, r.paint)); |
| 71 | DRAW(DrawRect, drawRect(r.rect, r.paint)); |
mtklein | 7cdc1ee | 2014-07-07 10:41:04 -0700 | [diff] [blame] | 72 | DRAW(DrawSprite, drawSprite(shallow_copy(r.bitmap), r.left, r.top, r.paint)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 73 | DRAW(DrawText, drawText(r.text, r.byteLength, r.x, r.y, r.paint)); |
| 74 | DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.paint)); |
| 75 | DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.colors, |
| 76 | r.xmode.get(), r.indices, r.indexCount, r.paint)); |
| 77 | #undef DRAW |
| 78 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 79 | template <> void Draw::draw(const PairedPushCull& r) { this->draw(*r.base); } |
| 80 | template <> void Draw::draw(const BoundedDrawPosTextH& r) { this->draw(*r.base); } |
commit-bot@chromium.org | 88c3e27 | 2014-04-22 16:57:20 +0000 | [diff] [blame] | 81 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 82 | } // namespace SkRecords |