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 | |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 8 | #include "SkLiteDL.h" |
| 9 | #include "SkLiteRecorder.h" |
Mike Klein | b89c883 | 2017-10-10 15:14:20 -0400 | [diff] [blame] | 10 | #include "SkRSXform.h" |
| 11 | #include "Test.h" |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 12 | |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 13 | DEF_TEST(SkLiteDL_basics, r) { |
Derek Sollenberger | d7875f5 | 2017-03-01 15:33:23 -0500 | [diff] [blame] | 14 | 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(); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 19 | } |
| 20 | |
Derek Sollenberger | d7875f5 | 2017-03-01 15:33:23 -0500 | [diff] [blame] | 21 | DEF_TEST(SkLiteDL_unbalanced, r) { |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 22 | SkLiteRecorder rec; |
| 23 | SkCanvas* c = &rec; |
| 24 | |
Derek Sollenberger | d7875f5 | 2017-03-01 15:33:23 -0500 | [diff] [blame] | 25 | 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 | |
| 43 | DEF_TEST(SkLiteRecorder, r) { |
| 44 | SkLiteDL p; |
| 45 | SkLiteRecorder rec; |
| 46 | SkCanvas* c = &rec; |
| 47 | |
| 48 | rec.reset(&p, {2,2,3,3}); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 49 | |
| 50 | c->save(); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 51 | c->clipRect(SkRect{2,3,4,5}, kIntersect_SkClipOp, true); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 52 | c->drawRect(SkRect{0,0,9,9}, SkPaint{}); |
| 53 | c->restore(); |
| 54 | } |
Mike Klein | 7cc49d6 | 2017-08-14 10:39:28 -0400 | [diff] [blame] | 55 | |
| 56 | DEF_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 | } |
Mike Klein | b89c883 | 2017-10-10 15:14:20 -0400 | [diff] [blame] | 66 | |
| 67 | // skia:7133 regression test. |
| 68 | // At one point we recorded text before the transforms, which makes it easy for |
| 69 | // the recording buffer to not be suitably aligned for the transforms. |
| 70 | DEF_TEST(SkLiteRecorder_RSXformAlignment, r) { |
| 71 | SkLiteDL dl; |
| 72 | SkLiteRecorder canvas; |
| 73 | canvas.reset(&dl, {0,0,100,100}); |
| 74 | |
| 75 | SkPaint paint; |
Mike Reed | 97f3cc2 | 2018-12-03 09:45:17 -0500 | [diff] [blame] | 76 | paint.setTextEncoding(kUTF8_SkTextEncoding); |
Mike Klein | b89c883 | 2017-10-10 15:14:20 -0400 | [diff] [blame] | 77 | |
| 78 | // These values don't really matter... we just need 5 valid transforms. |
| 79 | SkRSXform xforms[] = { |
| 80 | {1,0, 1,1}, |
| 81 | {1,0, 2,2}, |
| 82 | {1,0, 3,3}, |
| 83 | {1,0, 4,4}, |
| 84 | {1,0, 5,5}, |
| 85 | }; |
| 86 | canvas.drawTextRSXform("hello", 5, xforms, nullptr, paint); |
| 87 | |
| 88 | // We're just checking that this recorded our draw without SkASSERTing in Debug builds. |
| 89 | REPORTER_ASSERT(r, !dl.empty()); |
| 90 | } |