2 * Copyright 2019 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "include/core/SkPaint.h"
9 #include "include/core/SkPicture.h"
10 #include "include/core/SkPictureRecorder.h"
11 #include "include/core/SkPixmap.h"
12 #include "include/core/SkRect.h"
13 #include "tests/Test.h"
14 #include "tools/debugger/DebugLayerManager.h"
16 // Adds one full update, one partial update, and requests one image a few frames later.
17 static void test_basic(skiatest::Reporter* reporter) {
18 // prepare supporting objects
20 int layerHeight = 100;
22 // make a picture that fully updates the layer
23 SkPictureRecorder rec;
24 SkCanvas* canvas = rec.beginRecording(layerWidth, layerHeight);
25 canvas->clear(0x00000000);
27 paint.setColor(SK_ColorBLUE);
28 canvas->drawOval(SkRect::MakeLTRB(1,1,99,99), paint);
29 auto picture1 = rec.finishRecordingAsPicture();
30 SkIRect dirtyRectFull = SkIRect::MakeLTRB(0, 0, layerWidth, layerHeight);
32 // make a second picture that acts as a partial update.
33 SkPictureRecorder rec2;
34 canvas = rec2.beginRecording(layerWidth, layerHeight);
35 paint.setColor(SK_ColorGREEN);
36 canvas->drawOval(SkRect::MakeLTRB(40,40,60,60), paint);
37 auto picture2 = rec2.finishRecordingAsPicture();
38 SkIRect dirtyRectPartial = SkIRect::MakeLTRB(40,40,60,60);
42 // create and exercise DebugLayerManager
43 DebugLayerManager dlm;
44 dlm.storeSkPicture(node, 0, picture1, dirtyRectFull);
45 dlm.storeSkPicture(node, 10, picture2, dirtyRectPartial);
46 auto frames = dlm.listFramesForNode(node);
48 // Confirm the layer manager stored these at the right places.
49 REPORTER_ASSERT(reporter, frames.size() == 2);
50 REPORTER_ASSERT(reporter, frames[0] == 0);
51 REPORTER_ASSERT(reporter, frames[1] == 10);
54 // request an image of the layer between the two updates.
55 for (int i=0; i<10; i++) {
56 auto image = dlm.getLayerAsImage(node, i);
57 REPORTER_ASSERT(reporter, image->width() == layerWidth);
58 REPORTER_ASSERT(reporter, image->height() == layerHeight);
59 // confirm center is blue, proving only first pic was drawn.
60 image->peekPixels(&pixmap);
61 SkColor paintColor = pixmap.getColor(50, 50);
62 REPORTER_ASSERT(reporter, paintColor == SK_ColorBLUE);
65 // For any images after the second draw, confirm the center is green, but the area just outside
66 // that smaller circle is still blue, proving dlm drew both pictures.
67 for (int i=10; i<12; i++) {
68 auto image = dlm.getLayerAsImage(node, i);
69 REPORTER_ASSERT(reporter, image->width() == layerWidth);
70 REPORTER_ASSERT(reporter, image->height() == layerHeight);
71 image->peekPixels(&pixmap);
72 auto innerColor = pixmap.getColor(50, 50);
73 REPORTER_ASSERT(reporter, innerColor == SK_ColorGREEN);
74 auto outerColor = pixmap.getColor(10, 50);
75 REPORTER_ASSERT(reporter, outerColor == SK_ColorBLUE);
81 DEF_TEST(DebugLayerManagerTest, reporter) {