5#include <unordered_map>
11#include "gtest/gtest.h"
28 std::optional<Rect> cull_rect = std::nullopt,
29 bool requires_readback =
false) {
31 onscreen_desc.
size = {100, 100};
37 std::shared_ptr<Texture> onscreen =
38 context.
GetContext()->GetResourceAllocator()->CreateTexture(
43 if (context.
GetContext()->GetCapabilities()->SupportsOffscreenMSAA()) {
49 std::shared_ptr<Texture> onscreen_msaa =
50 context.
GetContext()->GetResourceAllocator()->CreateTexture(
62 if (cull_rect.has_value()) {
63 return std::make_unique<Canvas>(
64 context, render_target,
false,
65 requires_readback, cull_rect.value());
67 return std::make_unique<Canvas>(context, render_target,
false,
78 canvas->Translate(
Vector3(100, 200));
80 canvas->GetCurrentTransform(),
88 canvas->GetCurrentTransform(),
96 canvas->GetCurrentTransform(),
102 canvas->Translate(
Vector3(100, 200));
104 canvas->GetCurrentTransform(),
116 ASSERT_EQ(canvas->GetSaveCount(), 1u);
117 ASSERT_EQ(canvas->Restore(),
false);
119 canvas->Translate(
Size{100, 100});
121 ASSERT_EQ(canvas->GetSaveCount(), 2u);
124 ASSERT_TRUE(canvas->Restore());
125 ASSERT_EQ(canvas->GetSaveCount(), 1u);
136 canvas->Translate(
Size{100, 100});
144 GTEST_SKIP() <<
"Test requires device with framebuffer fetch";
149 canvas->SetBackdropData({}, 3);
155 EXPECT_TRUE(canvas->RequiresReadback());
157 canvas->SaveLayer({}, rect, blur.get(),
161 EXPECT_TRUE(canvas->RequiresReadback());
163 canvas->SaveLayer({}, rect, blur.get(),
167 EXPECT_TRUE(canvas->RequiresReadback());
169 canvas->SaveLayer({}, rect, blur.get(),
173 EXPECT_FALSE(canvas->RequiresReadback());
179 GTEST_SKIP() <<
"Test requires device with framebuffer fetch";
184 std::unordered_map<int64_t, BackdropData>
data;
186 canvas->SetBackdropData(
data, 3);
191 EXPECT_TRUE(canvas->RequiresReadback());
194 canvas->SaveLayer({}, std::nullopt, blur.get(),
199 EXPECT_FALSE(canvas->RequiresReadback());
201 canvas->SaveLayer({}, std::nullopt, blur.get(),
206 EXPECT_FALSE(canvas->RequiresReadback());
208 canvas->SaveLayer({}, std::nullopt, blur.get(),
213 EXPECT_FALSE(canvas->RequiresReadback());
219 GTEST_SKIP() <<
"Test requires device with framebuffer fetch";
224 std::unordered_map<int64_t, BackdropData>
data;
226 canvas->SetBackdropData(
data, 3);
231 EXPECT_TRUE(canvas->RequiresReadback());
234 canvas->SaveLayer({}, std::nullopt, blur.get(),
237 EXPECT_TRUE(canvas->RequiresReadback());
239 canvas->SaveLayer({}, std::nullopt, blur.get(),
242 EXPECT_FALSE(canvas->RequiresReadback());
244 canvas->SaveLayer({}, std::nullopt, blur.get(),
247 EXPECT_FALSE(canvas->RequiresReadback());
256 GTEST_SKIP() <<
"Test requires device with framebuffer fetch";
261 canvas->SetBackdropData({}, 2);
266 EXPECT_TRUE(canvas->RequiresReadback());
269 canvas->SaveLayer({}, std::nullopt, blur.get(),
275 canvas->SaveLayer({}, std::nullopt, blur.get(),
279 EXPECT_TRUE(canvas->RequiresReadback());
282 EXPECT_TRUE(canvas->RequiresReadback());
288 Canvas canvas(context, render_target,
true,
false);
290 std::vector<flutter::DlPoint> vertex_coordinates = {
295 std::vector<flutter::DlPoint> texture_coordinates = {
300 std::vector<uint16_t> indices = {0, 1, 2};
307 auto vertices = vertices_builder.
build();
312 std::vector<Scalar> stops = {0.0, 1.0};
314 {0, 0}, {0, 600}, 2, colors.data(), stops.data(),
319 canvas.
DrawVertices(std::make_shared<DlVerticesGeometry>(vertices, context),
330 auto runtime_stages =
331 OpenAssetAsRuntimeStage(
"runtime_stage_simple.frag.iplr");
335 ASSERT_TRUE(runtime_stage);
338 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
340 runtime_effect, {}, uniform_data);
344 Canvas canvas(context, render_target,
true,
false);
346 std::vector<flutter::DlPoint> vertex_coordinates = {
352 std::vector<flutter::DlPoint> texture_coordinates = {
357 std::vector<uint16_t> indices = {0, 1, 2};
364 auto vertices = vertices_builder.
build();
368 canvas.
DrawVertices(std::make_shared<DlVerticesGeometry>(vertices, context),
384 EXPECT_FALSE(canvas->SupportsBlitToOnscreen());
386 EXPECT_TRUE(canvas->SupportsBlitToOnscreen());
392 Size default_size(600, 400);
393 Point left_center(400, 700);
394 Point right_center(1300, 700);
400 std::shared_ptr<flutter::DlColorSource> color_source;
403 std::vector<flutter::DlColor> colors = {dl_color, dl_color};
404 std::vector<Scalar> stops = {0.0, 1.0};
406 {0, 0}, {1000, 1000}, 2, colors.data(), stops.data(),
410 auto RectMakeCenterHalfSize = [](
Point center,
Point half_size) {
411 Size size(half_size.x * 2, half_size.y * 2);
417 Canvas canvas(context, render_target,
true,
false);
422 static Scalar sigma = 0.05;
423 static Scalar radius = 200;
426 ImGui::Begin(
"Shadow",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
428 ImGui::SliderFloat(
"Sigma", &sigma, 0, 100);
429 ImGui::SliderFloat(
"Radius", &radius, 0, 1000);
434 ctm * (right_center + default_size / 2), 30,
Color::White());
436 Point half_size = (right_reference - right_center).Abs();
437 Rect left_bounds = RectMakeCenterHalfSize(left_center, half_size);
438 Rect right_bounds = RectMakeCenterHalfSize(right_center, half_size);
442 .mask_blur_descriptor =
453 paint.color_source = color_source.get();
static std::shared_ptr< DlColorSource > MakeLinear(const DlPoint start_point, const DlPoint end_point, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
static std::shared_ptr< DlColorSource > MakeRuntimeEffect(sk_sp< DlRuntimeEffect > runtime_effect, std::vector< std::shared_ptr< DlColorSource > > samplers, std::shared_ptr< std::vector< uint8_t > > uniform_data)
static std::shared_ptr< DlImageFilter > MakeBlur(DlScalar sigma_x, DlScalar sigma_y, DlTileMode tile_mode)
static sk_sp< DlRuntimeEffect > Make(std::shared_ptr< impeller::RuntimeStage > runtime_stage)
A utility class to build up a |DlVertices| object one set of data at a time.
void store_vertices(const DlPoint vertices[])
Copies the indicated list of points as vertices.
void store_indices(const uint16_t indices[])
Copies the indicated list of 16-bit indices as vertex indices.
void store_texture_coordinates(const DlPoint points[])
Copies the indicated list of points as texture coordinates.
std::shared_ptr< DlVertices > build()
Finalizes and the constructed DlVertices object.
static constexpr Flags kHasTextureCoordinates
void DrawRoundSuperellipse(const RoundSuperellipse &rse, const Paint &paint)
void DrawVertices(const std::shared_ptr< VerticesGeometry > &vertices, BlendMode blend_mode, const Paint &paint)
virtual bool SupportsFramebufferFetch() const =0
Whether the context backend is able to support pipelines with shaders that read from the framebuffer ...
virtual PixelFormat GetDefaultColorFormat() const =0
Returns a supported PixelFormat for textures that store 4-channel colors (red/green/blue/alpha).
const Capabilities & GetDeviceCapabilities() const
std::shared_ptr< Context > GetContext() const
bool OpenPlaygroundHere(const RenderCallback &render_callback)
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
FlutterDesktopBinaryReply callback
#define ASSERT_MATRIX_NEAR(a, b)
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
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
std::unique_ptr< Canvas > CreateTestCanvas(ContentContext &context, std::optional< Rect > cull_rect=std::nullopt, bool requires_readback=false)
TEST_P(AiksTest, DrawAtlasNoColor)
Point DrawPlaygroundPoint(PlaygroundPoint &point)
constexpr RuntimeStageBackend PlaygroundBackendToRuntimeStageBackend(PlaygroundBackend backend)
@ kContainsContents
The caller claims the bounds are a reasonably tight estimate of the coverage of the contents and shou...
static constexpr DlColor kBlue()
static constexpr DlColor kRed()
std::shared_ptr< Texture > resolve_texture
std::shared_ptr< Texture > texture
uint32_t ToARGB() const
Convert to ARGB 32 bit color.
static constexpr Color Azure()
static constexpr Color White()
static constexpr Color Red()
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeTranslation(const Vector3 &t)
static constexpr Matrix MakeScale(const Vector3 &s)
const flutter::DlColorSource * color_source
static RoundSuperellipse MakeRectRadius(const Rect &rect, Scalar radius)
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
static constexpr TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...