Flutter Engine
The Flutter Engine
Functions
DebugLayerManagerTest.cpp File Reference
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImage.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPicture.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "tests/Test.h"
#include "tools/debugger/DebugLayerManager.h"
#include <vector>

Go to the source code of this file.

Functions

static void test_basic (skiatest::Reporter *reporter)
 
 DEF_TEST (DebugLayerManagerTest, reporter)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( DebugLayerManagerTest  ,
reporter   
)

Definition at line 87 of file DebugLayerManagerTest.cpp.

87 {
89}
static void test_basic(skiatest::Reporter *reporter)
reporter
Definition: FontMgrTest.cpp:39

◆ test_basic()

static void test_basic ( skiatest::Reporter reporter)
static

Definition at line 23 of file DebugLayerManagerTest.cpp.

23 {
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}
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#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)
Definition: SkCanvas.cpp:1698
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
Definition: color_source.cc:38
sk_sp< const SkImage > image
Definition: SkRecords.h:269
Definition: SkRect.h:32
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