Flutter Engine
 
Loading...
Searching...
No Matches
canvas_spy_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include "gtest/gtest.h"
8#include "third_party/skia/include/core/SkPictureRecorder.h"
9#include "third_party/skia/include/core/SkSurface.h"
10
11namespace flutter {
12namespace testing {
13
14TEST(CanvasSpyTest, DrawingIsTracked) {
15 SkPictureRecorder picture_recorder;
16 SkCanvas* canvas = picture_recorder.beginRecording(100, 100);
17 CanvasSpy canvas_spy = CanvasSpy(canvas);
18 DlCanvas* spy = canvas_spy.GetSpyingCanvas();
19
20 ASSERT_FALSE(canvas_spy.DidDrawIntoCanvas());
21
22 spy->Translate(128, 128);
24 ASSERT_FALSE(canvas_spy.DidDrawIntoCanvas());
25
26 DlPaint paint;
27 spy->DrawCircle(DlPoint(0, 0), 60, paint);
28 ASSERT_TRUE(canvas_spy.DidDrawIntoCanvas());
29}
30
31TEST(CanvasSpyTest, SpiedCanvasIsDrawing) {
32 auto actual_surface =
33 SkSurfaces::Raster(SkImageInfo::MakeN32Premul(100, 100));
34 SkCanvas* actual_canvas = actual_surface->getCanvas();
35
36 auto expected_surface =
37 SkSurfaces::Raster(SkImageInfo::MakeN32Premul(100, 100));
38 SkCanvas* expected_canvas = expected_surface->getCanvas();
39
40 CanvasSpy canvas_spy = CanvasSpy(actual_canvas);
41 SkCanvas* spy = canvas_spy.GetRawSpyingCanvas();
42
43 SkNWayCanvas multi_canvas = SkNWayCanvas(100, 100);
44 multi_canvas.addCanvas(spy);
45 multi_canvas.addCanvas(expected_canvas);
46
47 multi_canvas.clipRect(SkRect::MakeWH(100, 100));
48 multi_canvas.clear(SK_ColorRED);
49 multi_canvas.scale(.5, .5);
50 multi_canvas.clipRect(SkRect::MakeWH(100, 100));
51 multi_canvas.clear(SK_ColorBLUE);
52
53 ASSERT_TRUE(canvas_spy.DidDrawIntoCanvas());
54
55 SkPixmap actual;
56 SkPixmap expected;
57
58 ASSERT_TRUE(actual_surface->peekPixels(&actual));
59 ASSERT_TRUE(expected_surface->peekPixels(&expected));
60
61 const auto size = actual.rowBytes() * actual.height();
62 ASSERT_NE(size, 0u);
63
64 ASSERT_EQ(::memcmp(actual.addr(), expected.addr(), size), 0);
65}
66} // namespace testing
67} // namespace flutter
SkCanvas * GetRawSpyingCanvas()
The underlying Skia canvas that implements the spying (mainly for testing)
Definition canvas_spy.cc:24
bool DidDrawIntoCanvas()
Returns true if any non transparent content has been drawn into the spying canvas....
Definition canvas_spy.cc:38
DlCanvas * GetSpyingCanvas()
The returned canvas delegate all operations to the target canvas while spying on them.
Definition canvas_spy.cc:20
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
virtual void DrawCircle(const DlPoint &center, DlScalar radius, const DlPaint &paint)=0
virtual void Translate(DlScalar tx, DlScalar ty)=0
void Clear(DlColor color)
Definition dl_canvas.h:104
TEST(NativeAssetsManagerTest, NoAvailableAssets)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
impeller::Point DlPoint
static constexpr DlColor kTransparent()
Definition dl_color.h:68