blob: e55bb5d3e71a5ac64fe29e30b47c791588061606 [file] [log] [blame]
Nathaniel Nifong20b177a2019-12-12 11:05:10 -05001/*
2 * Copyright 2019 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 "include/core/SkPaint.h"
9#include "include/core/SkPicture.h"
10#include "include/core/SkPictureRecorder.h"
11#include "include/core/SkRect.h"
12#include "tests/Test.h"
13#include "tools/debugger/DebugLayerManager.h"
14
15// Adds one full update, one partial update, and requests one image a few frames later.
16static void test_basic(skiatest::Reporter* reporter) {
17 // prepare supporting objects
18 int layerWidth = 100;
19 int layerHeight = 100;
20
21 // make a picture that fully updates the layer
22 SkPictureRecorder rec;
23 SkCanvas* canvas = rec.beginRecording(layerWidth, layerHeight);
24 canvas->clear(0x00000000);
25 SkPaint paint;
26 paint.setColor(SK_ColorBLUE);
27 canvas->drawOval(SkRect::MakeLTRB(1,1,99,99), paint);
Nathaniel Nifong20b177a2019-12-12 11:05:10 -050028 auto picture1 = rec.finishRecordingAsPicture();
29 SkIRect dirtyRectFull = SkIRect::MakeLTRB(0, 0, layerWidth, layerHeight);
30
31 // make a second picture that acts as a partial update.
32 SkPictureRecorder rec2;
33 canvas = rec2.beginRecording(layerWidth, layerHeight);
34 paint.setColor(SK_ColorGREEN);
35 canvas->drawOval(SkRect::MakeLTRB(40,40,60,60), paint);
Nathaniel Nifong20b177a2019-12-12 11:05:10 -050036 auto picture2 = rec2.finishRecordingAsPicture();
37 SkIRect dirtyRectPartial = SkIRect::MakeLTRB(40,40,60,60);
38
39 int node = 2;
40
41 // create and exercise DebugLayerManager
42 DebugLayerManager dlm;
43 dlm.storeSkPicture(node, 0, picture1, dirtyRectFull);
44 dlm.storeSkPicture(node, 10, picture2, dirtyRectPartial);
45 auto frames = dlm.listFramesForNode(node);
46
47 // Confirm the layer manager stored these at the right places.
48 REPORTER_ASSERT(reporter, frames.size() == 2);
49 REPORTER_ASSERT(reporter, frames[0] == 0);
50 REPORTER_ASSERT(reporter, frames[1] == 10);
51
52 SkPixmap pixmap;
53 // request an image of the layer between the two updates.
54 for (int i=0; i<10; i++) {
55 auto image = dlm.getLayerAsImage(node, i);
56 REPORTER_ASSERT(reporter, image->width() == layerWidth);
57 REPORTER_ASSERT(reporter, image->height() == layerHeight);
58 // confirm center is blue, proving only first pic was drawn.
59 image->peekPixels(&pixmap);
60 SkColor paintColor = pixmap.getColor(50, 50);
61 REPORTER_ASSERT(reporter, paintColor == SK_ColorBLUE);
62 }
63
64 // For any images after the second draw, confirm the center is green, but the area just outside
65 // that smaller circle is still blue, proving dlm drew both pictures.
66 for (int i=10; i<12; i++) {
67 auto image = dlm.getLayerAsImage(node, i);
68 REPORTER_ASSERT(reporter, image->width() == layerWidth);
69 REPORTER_ASSERT(reporter, image->height() == layerHeight);
70 image->peekPixels(&pixmap);
71 auto innerColor = pixmap.getColor(50, 50);
72 REPORTER_ASSERT(reporter, innerColor == SK_ColorGREEN);
73 auto outerColor = pixmap.getColor(10, 50);
74 REPORTER_ASSERT(reporter, outerColor == SK_ColorBLUE);
75 }
76
77
78}
79
80DEF_TEST(DebugLayerManagerTest, reporter) {
81 test_basic(reporter);
82}