blob: a40136b1a4367f50eef5e6503162bafed6bf3085 [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);
28 canvas->flush();
29 auto picture1 = rec.finishRecordingAsPicture();
30 SkIRect dirtyRectFull = SkIRect::MakeLTRB(0, 0, layerWidth, layerHeight);
31
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 canvas->flush();
38 auto picture2 = rec2.finishRecordingAsPicture();
39 SkIRect dirtyRectPartial = SkIRect::MakeLTRB(40,40,60,60);
40
41 int node = 2;
42
43 // create and exercise DebugLayerManager
44 DebugLayerManager dlm;
45 dlm.storeSkPicture(node, 0, picture1, dirtyRectFull);
46 dlm.storeSkPicture(node, 10, picture2, dirtyRectPartial);
47 auto frames = dlm.listFramesForNode(node);
48
49 // Confirm the layer manager stored these at the right places.
50 REPORTER_ASSERT(reporter, frames.size() == 2);
51 REPORTER_ASSERT(reporter, frames[0] == 0);
52 REPORTER_ASSERT(reporter, frames[1] == 10);
53
54 SkPixmap pixmap;
55 // request an image of the layer between the two updates.
56 for (int i=0; i<10; i++) {
57 auto image = dlm.getLayerAsImage(node, i);
58 REPORTER_ASSERT(reporter, image->width() == layerWidth);
59 REPORTER_ASSERT(reporter, image->height() == layerHeight);
60 // confirm center is blue, proving only first pic was drawn.
61 image->peekPixels(&pixmap);
62 SkColor paintColor = pixmap.getColor(50, 50);
63 REPORTER_ASSERT(reporter, paintColor == SK_ColorBLUE);
64 }
65
66 // For any images after the second draw, confirm the center is green, but the area just outside
67 // that smaller circle is still blue, proving dlm drew both pictures.
68 for (int i=10; i<12; i++) {
69 auto image = dlm.getLayerAsImage(node, i);
70 REPORTER_ASSERT(reporter, image->width() == layerWidth);
71 REPORTER_ASSERT(reporter, image->height() == layerHeight);
72 image->peekPixels(&pixmap);
73 auto innerColor = pixmap.getColor(50, 50);
74 REPORTER_ASSERT(reporter, innerColor == SK_ColorGREEN);
75 auto outerColor = pixmap.getColor(10, 50);
76 REPORTER_ASSERT(reporter, outerColor == SK_ColorBLUE);
77 }
78
79
80}
81
82DEF_TEST(DebugLayerManagerTest, reporter) {
83 test_basic(reporter);
84}