blob: e64e5aa5cc254841b16405f649eb840c8c935e45 [file] [log] [blame]
mtklein9c5052f2016-08-06 12:51:51 -07001/*
2 * Copyright 2016 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
mtklein9c5052f2016-08-06 12:51:51 -07008#include "SkLiteDL.h"
9#include "SkLiteRecorder.h"
Mike Kleinb89c8832017-10-10 15:14:20 -040010#include "SkRSXform.h"
11#include "Test.h"
mtklein9c5052f2016-08-06 12:51:51 -070012
mtklein9c5052f2016-08-06 12:51:51 -070013DEF_TEST(SkLiteDL_basics, r) {
Derek Sollenbergerd7875f52017-03-01 15:33:23 -050014 SkLiteDL p;
15 p.save();
16 p.clipRect(SkRect{2,3,4,5}, kIntersect_SkClipOp, true);
17 p.drawRect(SkRect{0,0,9,9}, SkPaint{});
18 p.restore();
mtklein9c5052f2016-08-06 12:51:51 -070019}
20
Derek Sollenbergerd7875f52017-03-01 15:33:23 -050021DEF_TEST(SkLiteDL_unbalanced, r) {
mtklein9c5052f2016-08-06 12:51:51 -070022 SkLiteRecorder rec;
23 SkCanvas* c = &rec;
24
Derek Sollenbergerd7875f52017-03-01 15:33:23 -050025 SkLiteDL p;
26 rec.reset(&p, {2,2,3,3});
27 c->save();
28 c->scale(2,2);
29 c->save();
30 c->translate(1,1);
31 // missing restore() but SkLiteDL::draw should balance it for us
32 c->restore();
33
34 // reinit the recorder so we can playback the original SkLiteDL
35 SkLiteDL p2;
36 rec.reset(&p2, {2,2,3,3});
37
38 REPORTER_ASSERT(r, 1 == rec.getSaveCount());
39 p.draw(c);
40 REPORTER_ASSERT(r, 1 == rec.getSaveCount());
41}
42
43DEF_TEST(SkLiteRecorder, r) {
44 SkLiteDL p;
45 SkLiteRecorder rec;
46 SkCanvas* c = &rec;
47
48 rec.reset(&p, {2,2,3,3});
mtklein9c5052f2016-08-06 12:51:51 -070049
50 c->save();
Mike Reedc1f77742016-12-09 09:00:50 -050051 c->clipRect(SkRect{2,3,4,5}, kIntersect_SkClipOp, true);
mtklein9c5052f2016-08-06 12:51:51 -070052 c->drawRect(SkRect{0,0,9,9}, SkPaint{});
53 c->restore();
54}
Mike Klein7cc49d62017-08-14 10:39:28 -040055
56DEF_TEST(SkLiteRecorder_RecordsFlush, r) {
57 SkLiteDL dl;
58
59 SkLiteRecorder canvas;
60 canvas.reset(&dl, {0,0,100,100});
61
62 REPORTER_ASSERT(r, dl.empty());
63 canvas.flush();
64 REPORTER_ASSERT(r, !dl.empty());
65}