blob: 324946e5d7a218364d3305b46606e5db652f01a3 [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
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000010void SkRecordDraw(const SkRecord& record, SkCanvas* canvas) {
11 for (SkRecords::Draw draw(canvas); draw.index() < record.count(); draw.next()) {
12 record.visit<void>(draw.index(), draw);
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000013 }
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000014}
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +000015
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000016namespace SkRecords {
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000017
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000018bool Draw::skip(const PairedPushCull& r) {
19 if (fCanvas->quickReject(r.base->rect)) {
20 fIndex += r.skip;
21 return true;
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000022 }
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000023 return false;
24}
commit-bot@chromium.org2e0c32a2014-04-28 16:19:45 +000025
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000026bool Draw::skip(const BoundedDrawPosTextH& r) {
27 return fCanvas->quickRejectY(r.minY, r.maxY);
28}
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000029
commit-bot@chromium.org2e0c32a2014-04-28 16:19:45 +000030// NoOps draw nothing.
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000031template <> void Draw::draw(const NoOp&) {}
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000032
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000033#define DRAW(T, call) template <> void Draw::draw(const T& r) { fCanvas->call; }
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000034DRAW(Restore, restore());
35DRAW(Save, save(r.flags));
36DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags));
37DRAW(PopCull, popCull());
commit-bot@chromium.org88c3e272014-04-22 16:57:20 +000038DRAW(PushCull, pushCull(r.rect));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000039DRAW(Clear, clear(r.color));
40DRAW(Concat, concat(r.matrix));
41DRAW(SetMatrix, setMatrix(r.matrix));
42
43DRAW(ClipPath, clipPath(r.path, r.op, r.doAA));
44DRAW(ClipRRect, clipRRect(r.rrect, r.op, r.doAA));
45DRAW(ClipRect, clipRect(r.rect, r.op, r.doAA));
46DRAW(ClipRegion, clipRegion(r.region, r.op));
47
48DRAW(DrawBitmap, drawBitmap(r.bitmap, r.left, r.top, r.paint));
49DRAW(DrawBitmapMatrix, drawBitmapMatrix(r.bitmap, r.matrix, r.paint));
50DRAW(DrawBitmapNine, drawBitmapNine(r.bitmap, r.center, r.dst, r.paint));
51DRAW(DrawBitmapRectToRect, drawBitmapRectToRect(r.bitmap, r.src, r.dst, r.paint, r.flags));
52DRAW(DrawDRRect, drawDRRect(r.outer, r.inner, r.paint));
53DRAW(DrawOval, drawOval(r.oval, r.paint));
54DRAW(DrawPaint, drawPaint(r.paint));
55DRAW(DrawPath, drawPath(r.path, r.paint));
56DRAW(DrawPoints, drawPoints(r.mode, r.count, r.pts, r.paint));
57DRAW(DrawPosText, drawPosText(r.text, r.byteLength, r.pos, r.paint));
58DRAW(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint));
59DRAW(DrawRRect, drawRRect(r.rrect, r.paint));
60DRAW(DrawRect, drawRect(r.rect, r.paint));
61DRAW(DrawSprite, drawSprite(r.bitmap, r.left, r.top, r.paint));
62DRAW(DrawText, drawText(r.text, r.byteLength, r.x, r.y, r.paint));
63DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.paint));
64DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.colors,
65 r.xmode.get(), r.indices, r.indexCount, r.paint));
66#undef DRAW
67
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000068template <> void Draw::draw(const PairedPushCull& r) { this->draw(*r.base); }
69template <> void Draw::draw(const BoundedDrawPosTextH& r) { this->draw(*r.base); }
commit-bot@chromium.org88c3e272014-04-22 16:57:20 +000070
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000071} // namespace SkRecords