Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
DebugLayerManagerTest.cpp
Go to the documentation of this file.
1/*
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
15#include "include/core/SkRect.h"
17#include "tests/Test.h"
19
20#include <vector>
21
22// Adds one full update, one partial update, and requests one image a few frames later.
24 // prepare supporting objects
25 int layerWidth = 100;
26 int layerHeight = 100;
27
28 // make a picture that fully updates the layer
30 SkCanvas* canvas = rec.beginRecording(layerWidth, layerHeight);
31 canvas->clear(0x00000000);
33 paint.setColor(SK_ColorBLUE);
34 canvas->drawOval(SkRect::MakeLTRB(1,1,99,99), paint);
35 auto picture1 = rec.finishRecordingAsPicture();
36 SkIRect dirtyRectFull = SkIRect::MakeLTRB(0, 0, layerWidth, layerHeight);
37
38 // make a second picture that acts as a partial update.
40 canvas = rec2.beginRecording(layerWidth, layerHeight);
41 paint.setColor(SK_ColorGREEN);
42 canvas->drawOval(SkRect::MakeLTRB(40,40,60,60), paint);
43 auto picture2 = rec2.finishRecordingAsPicture();
44 SkIRect dirtyRectPartial = SkIRect::MakeLTRB(40,40,60,60);
45
46 int node = 2;
47
48 // create and exercise DebugLayerManager
50 dlm.storeSkPicture(node, 0, picture1, dirtyRectFull);
51 dlm.storeSkPicture(node, 10, picture2, dirtyRectPartial);
52 auto frames = dlm.listFramesForNode(node);
53
54 // Confirm the layer manager stored these at the right places.
55 REPORTER_ASSERT(reporter, frames.size() == 2);
56 REPORTER_ASSERT(reporter, frames[0] == 0);
57 REPORTER_ASSERT(reporter, frames[1] == 10);
58
59 SkPixmap pixmap;
60 // request an image of the layer between the two updates.
61 for (int i=0; i<10; i++) {
62 auto image = dlm.getLayerAsImage(node, i);
63 REPORTER_ASSERT(reporter, image->width() == layerWidth);
64 REPORTER_ASSERT(reporter, image->height() == layerHeight);
65 // confirm center is blue, proving only first pic was drawn.
66 image->peekPixels(&pixmap);
67 SkColor paintColor = pixmap.getColor(50, 50);
69 }
70
71 // For any images after the second draw, confirm the center is green, but the area just outside
72 // that smaller circle is still blue, proving dlm drew both pictures.
73 for (int i=10; i<12; i++) {
74 auto image = dlm.getLayerAsImage(node, i);
75 REPORTER_ASSERT(reporter, image->width() == layerWidth);
76 REPORTER_ASSERT(reporter, image->height() == layerHeight);
77 image->peekPixels(&pixmap);
78 auto innerColor = pixmap.getColor(50, 50);
80 auto outerColor = pixmap.getColor(10, 50);
82 }
83
84
85}
86
87DEF_TEST(DebugLayerManagerTest, reporter) {
89}
static void test_basic(skiatest::Reporter *reporter)
reporter
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
#define DEF_TEST(name, reporter)
Definition Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
void storeSkPicture(int nodeId, int frame, const sk_sp< SkPicture > &picture, SkIRect dirty)
std::vector< int > listFramesForNode(int nodeId) const
sk_sp< SkImage > getLayerAsImage(const int nodeId, const int frame)
void drawOval(const SkRect &oval, const SkPaint &paint)
void clear(SkColor color)
Definition SkCanvas.h:1199
bool peekPixels(SkPixmap *pixmap) const
Definition SkImage.cpp:34
int width() const
Definition SkImage.h:285
int height() const
Definition SkImage.h:291
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
SkColor getColor(int x, int y) const
Definition SkPixmap.cpp:187
const Paint & paint
sk_sp< SkImage > image
Definition examples.cpp:29
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition SkRect.h:91
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646