Home | History | Annotate | Download | only in tests
      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 "SkLiteDL.h"
      9 #include "SkLiteRecorder.h"
     10 #include "SkRSXform.h"
     11 #include "Test.h"
     12 
     13 DEF_TEST(SkLiteDL_basics, r) {
     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();
     19 }
     20 
     21 DEF_TEST(SkLiteDL_unbalanced, r) {
     22     SkLiteRecorder rec;
     23     SkCanvas* c = &rec;
     24 
     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});
     49 
     50     c->save();
     51         c->clipRect(SkRect{2,3,4,5}, kIntersect_SkClipOp, true);
     52         c->drawRect(SkRect{0,0,9,9}, SkPaint{});
     53     c->restore();
     54 }
     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 }
     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;
     76     paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
     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 }
     91