Flutter Engine
The 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
5#include "flutter/shell/platform/fuchsia/flutter/canvas_spy.h"
6
7#include "gtest/gtest.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
27 spy->DrawCircle({0, 0}, 60, paint);
28 ASSERT_TRUE(canvas_spy.DidDrawIntoCanvas());
29}
30
31TEST(CanvasSpyTest, SpiedCanvasIsDrawing) {
32 auto actual_surface =
34 SkCanvas* actual_canvas = actual_surface->getCanvas();
35
36 auto expected_surface =
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
#define TEST(S, s, D, expected)
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void clear(SkColor color)
Definition SkCanvas.h:1199
void scale(SkScalar sx, SkScalar sy)
virtual void addCanvas(SkCanvas *)
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
size_t rowBytes() const
Definition SkPixmap.h:145
const void * addr() const
Definition SkPixmap.h:153
int height() const
Definition SkPixmap.h:166
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:37
virtual void DrawCircle(const SkPoint &center, SkScalar radius, const DlPaint &paint)=0
virtual void Translate(SkScalar tx, SkScalar ty)=0
void Clear(DlColor color)
Definition dl_canvas.h:131
const Paint & paint
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
it will be possible to load the file into Perfetto s trace viewer 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
Definition switches.h:259
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609
static constexpr DlColor kTransparent()
Definition dl_color.h:21