mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 8 | #include "Test.h" |
| 9 | #include "SkLiteDL.h" |
| 10 | #include "SkLiteRecorder.h" |
| 11 | |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 12 | DEF_TEST(SkLiteDL_basics, r) { |
Derek Sollenberger | d7875f5 | 2017-03-01 15:33:23 -0500 | [diff] [blame] | 13 | SkLiteDL p; |
| 14 | p.save(); |
| 15 | p.clipRect(SkRect{2,3,4,5}, kIntersect_SkClipOp, true); |
| 16 | p.drawRect(SkRect{0,0,9,9}, SkPaint{}); |
| 17 | p.restore(); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 18 | } |
| 19 | |
Derek Sollenberger | d7875f5 | 2017-03-01 15:33:23 -0500 | [diff] [blame] | 20 | DEF_TEST(SkLiteDL_unbalanced, r) { |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 21 | SkLiteRecorder rec; |
| 22 | SkCanvas* c = &rec; |
| 23 | |
Derek Sollenberger | d7875f5 | 2017-03-01 15:33:23 -0500 | [diff] [blame] | 24 | SkLiteDL p; |
| 25 | rec.reset(&p, {2,2,3,3}); |
| 26 | c->save(); |
| 27 | c->scale(2,2); |
| 28 | c->save(); |
| 29 | c->translate(1,1); |
| 30 | // missing restore() but SkLiteDL::draw should balance it for us |
| 31 | c->restore(); |
| 32 | |
| 33 | // reinit the recorder so we can playback the original SkLiteDL |
| 34 | SkLiteDL p2; |
| 35 | rec.reset(&p2, {2,2,3,3}); |
| 36 | |
| 37 | REPORTER_ASSERT(r, 1 == rec.getSaveCount()); |
| 38 | p.draw(c); |
| 39 | REPORTER_ASSERT(r, 1 == rec.getSaveCount()); |
| 40 | } |
| 41 | |
| 42 | DEF_TEST(SkLiteRecorder, r) { |
| 43 | SkLiteDL p; |
| 44 | SkLiteRecorder rec; |
| 45 | SkCanvas* c = &rec; |
| 46 | |
| 47 | rec.reset(&p, {2,2,3,3}); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 48 | |
| 49 | c->save(); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 50 | c->clipRect(SkRect{2,3,4,5}, kIntersect_SkClipOp, true); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 51 | c->drawRect(SkRect{0,0,9,9}, SkPaint{}); |
| 52 | c->restore(); |
| 53 | } |