blob: 89efb8e18bf088150e55ae7ef510b8f80036afd4 [file] [log] [blame]
commit-bot@chromium.orgc4b21e62014-04-11 18:33:31 +00001/*
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.org506db0b2014-04-08 23:31:35 +00008#include "SkRecordDraw.h"
9
Mike Kleinc11530e2014-06-24 11:29:06 -040010void SkRecordDraw(const SkRecord& record, SkCanvas* canvas, SkDrawPictureCallback* callback) {
11 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000012 for (SkRecords::Draw draw(canvas); draw.index() < record.count(); draw.next()) {
Mike Kleinc11530e2014-06-24 11:29:06 -040013 if (NULL != callback && callback->abortDrawing()) {
14 return;
15 }
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000016 record.visit<void>(draw.index(), draw);
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000017 }
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000018}
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +000019
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000020namespace SkRecords {
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000021
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000022bool Draw::skip(const PairedPushCull& r) {
23 if (fCanvas->quickReject(r.base->rect)) {
24 fIndex += r.skip;
25 return true;
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000026 }
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000027 return false;
28}
commit-bot@chromium.org2e0c32a2014-04-28 16:19:45 +000029
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000030bool Draw::skip(const BoundedDrawPosTextH& r) {
31 return fCanvas->quickRejectY(r.minY, r.maxY);
32}
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000033
mtklein7cdc1ee2014-07-07 10:41:04 -070034// FIXME: SkBitmaps are stateful, so we need to copy them to play back in multiple threads.
35static SkBitmap shallow_copy(const SkBitmap& bitmap) {
36 return bitmap;
37}
38
commit-bot@chromium.org2e0c32a2014-04-28 16:19:45 +000039// NoOps draw nothing.
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000040template <> void Draw::draw(const NoOp&) {}
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000041
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000042#define DRAW(T, call) template <> void Draw::draw(const T& r) { fCanvas->call; }
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000043DRAW(Restore, restore());
Florin Malita5f6102d2014-06-30 10:13:28 -040044DRAW(Save, save());
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000045DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags));
46DRAW(PopCull, popCull());
commit-bot@chromium.org88c3e272014-04-22 16:57:20 +000047DRAW(PushCull, pushCull(r.rect));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000048DRAW(Clear, clear(r.color));
49DRAW(Concat, concat(r.matrix));
commit-bot@chromium.org99bd7d82014-05-19 15:51:12 +000050DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix)));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000051
52DRAW(ClipPath, clipPath(r.path, r.op, r.doAA));
53DRAW(ClipRRect, clipRRect(r.rrect, r.op, r.doAA));
54DRAW(ClipRect, clipRect(r.rect, r.op, r.doAA));
55DRAW(ClipRegion, clipRegion(r.region, r.op));
56
mtklein7cdc1ee2014-07-07 10:41:04 -070057DRAW(DrawBitmap, drawBitmap(shallow_copy(r.bitmap), r.left, r.top, r.paint));
58DRAW(DrawBitmapMatrix, drawBitmapMatrix(shallow_copy(r.bitmap), r.matrix, r.paint));
59DRAW(DrawBitmapNine, drawBitmapNine(shallow_copy(r.bitmap), r.center, r.dst, r.paint));
60DRAW(DrawBitmapRectToRect,
61 drawBitmapRectToRect(shallow_copy(r.bitmap), r.src, r.dst, r.paint, r.flags));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000062DRAW(DrawDRRect, drawDRRect(r.outer, r.inner, r.paint));
63DRAW(DrawOval, drawOval(r.oval, r.paint));
64DRAW(DrawPaint, drawPaint(r.paint));
65DRAW(DrawPath, drawPath(r.path, r.paint));
66DRAW(DrawPoints, drawPoints(r.mode, r.count, r.pts, r.paint));
67DRAW(DrawPosText, drawPosText(r.text, r.byteLength, r.pos, r.paint));
68DRAW(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint));
69DRAW(DrawRRect, drawRRect(r.rrect, r.paint));
70DRAW(DrawRect, drawRect(r.rect, r.paint));
mtklein7cdc1ee2014-07-07 10:41:04 -070071DRAW(DrawSprite, drawSprite(shallow_copy(r.bitmap), r.left, r.top, r.paint));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000072DRAW(DrawText, drawText(r.text, r.byteLength, r.x, r.y, r.paint));
73DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.paint));
74DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.colors,
75 r.xmode.get(), r.indices, r.indexCount, r.paint));
76#undef DRAW
77
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000078template <> void Draw::draw(const PairedPushCull& r) { this->draw(*r.base); }
79template <> void Draw::draw(const BoundedDrawPosTextH& r) { this->draw(*r.base); }
commit-bot@chromium.org88c3e272014-04-22 16:57:20 +000080
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000081} // namespace SkRecords