5 #include "flutter/fml/native_library.h"
6 #include "flutter/testing/testing.h"
30 auto context = CreateContext();
35 hpp::DisplayListBuilder builder;
38 ASSERT_EQ(builder.GetSaveCount(), 1u);
40 ASSERT_EQ(builder.GetSaveCount(), 2u);
42 ASSERT_EQ(builder.GetSaveCount(), 1u);
46 auto context = CreateContext();
48 const auto window_size = GetWindowSize();
67 color = {1.0, 0.0, 0.0, 1.0};
80 auto dl = Adopt<DisplayList>(
84 OpenPlaygroundHere([&](
const auto& context,
const auto& surface) ->
bool {
91 auto compressed = LoadFixtureImageCompressed(
92 flutter::testing::OpenFixtureAsMapping(
"boston.jpg"));
93 ASSERT_NE(compressed,
nullptr);
94 auto decompressed = compressed->Decode().ConvertToRGBA();
95 ASSERT_TRUE(decompressed.IsValid());
97 mapping.
data = decompressed.GetAllocation()->GetMapping();
98 mapping.
length = decompressed.GetAllocation()->GetSize();
100 auto context = GetInteropContext();
103 desc.
size = {decompressed.GetSize().
width, decompressed.GetSize().height};
106 context.GetC(), &desc, &mapping,
nullptr));
107 ASSERT_TRUE(texture);
114 auto dl = Adopt<DisplayList>(
117 OpenPlaygroundHere([&](
const auto& context,
const auto& surface) ->
bool {
124 auto context = GetInteropContext();
126 auto impeller_context = context->GetContext();
128 if (impeller_context->GetBackendType() !=
130 GTEST_SKIP() <<
"This test works with OpenGL handles is only suitable for "
136 const auto& gl = gl_context.GetReactor()->GetProcTable();
138 constexpr
ISize external_texture_size = {200, 300};
142 texture_data.
Truncate(
Bytes{external_texture_size.Area() * 4u},
false));
146 for (
size_t i = 0; i < external_texture_size.Area() * 4u; i += 4u) {
147 memcpy(texture_data.
GetBuffer() + i, kClearColor.data(), 4);
150 GLuint external_texture = GL_NONE;
151 gl.GenTextures(1u, &external_texture);
152 ASSERT_NE(external_texture, 0u);
153 gl.BindTexture(GL_TEXTURE_2D, external_texture);
154 gl.TexImage2D(GL_TEXTURE_2D,
157 external_texture_size.width,
158 external_texture_size.height,
167 desc.
size = {external_texture_size.
width, external_texture_size.height};
174 ASSERT_TRUE(texture);
184 auto dl = Adopt<DisplayList>(
187 OpenPlaygroundHere([&](
const auto& context,
const auto& surface) ->
bool {
194 auto context = GetInteropContext();
195 auto impeller_context = context->GetContext();
196 if (impeller_context->GetBackendType() !=
198 GTEST_SKIP() <<
"This test works with OpenGL handles is only suitable for "
203 const auto& gl = gl_context.GetReactor()->GetProcTable();
211 color = {1.0, 0.0, 0.0, 1.0};
217 auto dl = Adopt<DisplayList>(
221 OpenPlaygroundHere([&](
const auto& context,
const auto& surface) ->
bool {
225 GLboolean stencil_enabled =
true;
226 gl.GetBooleanv(GL_STENCIL_TEST, &stencil_enabled);
227 return stencil_enabled == GL_FALSE;
233 hpp::TypographyContext type_context;
234 ASSERT_TRUE(type_context);
237 hpp::ParagraphBuilder builder(type_context);
238 ASSERT_TRUE(builder);
242 hpp::ParagraphStyle style;
244 style.SetFontSize(150.0f);
245 style.SetHeight(2.0f);
250 paint.SetColor({1.0, 0.0, 0.0, 1.0});
251 style.SetForeground(paint);
256 paint.SetColor({1.0, 1.0, 1.0, 1.0});
257 style.SetBackground(paint);
261 builder.PushStyle(style);
262 std::string text =
"the ⚡️ quick ⚡️ brown 🦊 fox jumps over the lazy dog 🐶.";
265 builder.AddText(text);
268 auto paragraph = builder.Build(1200.0f);
269 ASSERT_TRUE(paragraph);
272 hpp::DisplayListBuilder dl_builder;
273 dl_builder.DrawParagraph(paragraph, {20, 20});
276 auto dl = dl_builder.Build();
279 OpenPlaygroundHere([&](
const auto& context,
const auto& surface) ->
bool {
280 hpp::Surface window(surface.GetC());
287 hpp::DisplayListBuilder builder;
289 hpp::Paint red_paint;
290 red_paint.SetColor({1.0, 0.0, 0.0, 1.0});
291 red_paint.SetStrokeWidth(10.0);
293 builder.Translate(10, 10);
294 builder.DrawRect({0, 0, 100, 100}, red_paint);
295 builder.Translate(100, 100);
296 builder.DrawOval({0, 0, 100, 100}, red_paint);
297 builder.Translate(100, 100);
298 builder.DrawLine({0, 0}, {100, 100}, red_paint);
300 builder.Translate(100, 100);
304 builder.DrawRoundedRect({0, 0, 100, 100}, radii, red_paint);
306 builder.Translate(100, 100);
307 builder.DrawPath(hpp::PathBuilder{}.AddOval({0, 0, 100, 100}).Build(),
310 auto dl = builder.Build();
312 OpenPlaygroundHere([&](
const auto& context,
const auto& surface) ->
bool {
313 hpp::Surface window(surface.GetC());
322 ASSERT_TRUE(type_context);
325 std::unique_ptr<fml::Mapping> font_data =
326 flutter::testing::OpenFixtureAsMapping(
"wtf.otf");
327 ASSERT_NE(font_data,
nullptr);
328 ASSERT_GT(font_data->GetSize(), 0u);
330 .
data = font_data->GetMapping(),
331 .length = font_data->GetSize(),
332 .on_release = [](
auto ctx) {
333 delete reinterpret_cast<fml::Mapping*
>(ctx);
341 ASSERT_TRUE(registered);
346 ASSERT_TRUE(builder);
365 std::string text =
"0F0F0F0";
369 reinterpret_cast<const uint8_t*
>(text.data()),
373 auto paragraph = Adopt<Paragraph>(
375 ASSERT_TRUE(paragraph);
383 auto dl = Adopt<DisplayList>(
387 OpenPlaygroundHere([&](
const auto& context,
const auto& surface) ->
bool {
394 hpp::DisplayListBuilder& builder,
395 hpp::ParagraphStyle& p_style,
396 const hpp::Paint& bg,
401 "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
409 builder.DrawRect(box_rect, fg);
413 p_style.SetForeground(fg);
414 p_style.SetBackground(bg);
415 p_style.SetTextAlignment(align);
417 hpp::ParagraphBuilder p_builder(tc);
418 p_builder.PushStyle(p_style);
419 p_builder.AddText(
reinterpret_cast<const uint8_t*
>(text),
sizeof(text));
421 auto left_p = p_builder.Build(box_rect.
width - 20.0);
423 float w = left_p.GetMaxWidth();
424 float h = left_p.GetHeight();
425 builder.DrawParagraph(left_p, pt);
430 builder.DrawRect(inner_box_rect, fg);
434 hpp::TypographyContext tc;
436 hpp::DisplayListBuilder builder;
438 hpp::ParagraphStyle p_style;
439 p_style.SetFontFamily(
"Roboto");
440 p_style.SetFontSize(24.0);
445 bg.SetColor(clear_color);
446 builder.DrawPaint(bg);
462 auto dl = builder.Build();
465 OpenPlaygroundHere([&](
const auto& context,
const auto& surface) ->
bool {
466 hpp::Surface window(surface.GetC());
Describes an allocation on the heap.
uint8_t * GetBuffer() const
Gets the pointer to the start of the allocation.
bool Truncate(Bytes length, bool npot=true)
Resize the underlying allocation to at least given number of bytes.
static ContextGLES & Cast(Context &base)
@ kImpellerTextureSamplingLinear
@ kImpellerDrawStyleStroke
@ kImpellerTextAlignmentLeft
@ kImpellerTextAlignmentCenter
@ kImpellerTextAlignmentRight
@ kImpellerClipOperationDifference
@ kImpellerPixelFormatRGBA8888
TEST_P(InteropPlaygroundTest, CanCreateContext)
static void DrawTextFrame(const hpp::TypographyContext &tc, hpp::DisplayListBuilder &builder, hpp::ParagraphStyle &p_style, const hpp::Paint &bg, ImpellerColor color, ImpellerTextAlignment align, float x_offset)
INSTANTIATE_OPENGLES_PLAYGROUND_SUITE(InteropPlaygroundTest)
IMPELLER_EXTERN_C uint64_t ImpellerTextureGetOpenGLHandle(ImpellerTexture texture)
IMPELLER_EXTERN_C ImpellerSurface ImpellerSurfaceCreateWrappedFBONew(ImpellerContext context, uint64_t fbo, ImpellerPixelFormat format, const ImpellerISize *size)
IMPELLER_EXTERN_C ImpellerDisplayList ImpellerDisplayListBuilderCreateDisplayListNew(ImpellerDisplayListBuilder builder)
IMPELLER_EXTERN_C ImpellerParagraphBuilder ImpellerParagraphBuilderNew(ImpellerTypographyContext context)
IMPELLER_EXTERN_C ImpellerDisplayListBuilder ImpellerDisplayListBuilderNew(const ImpellerRect *cull_rect)
IMPELLER_EXTERN_C ImpellerPaint ImpellerPaintNew()
IMPELLER_EXTERN_C ImpellerParagraph ImpellerParagraphBuilderBuildParagraphNew(ImpellerParagraphBuilder paragraph_builder, float width)
IMPELLER_EXTERN_C void ImpellerParagraphBuilderPushStyle(ImpellerParagraphBuilder paragraph_builder, ImpellerParagraphStyle style)
IMPELLER_EXTERN_C ImpellerTypographyContext ImpellerTypographyContextNew()
IMPELLER_EXTERN_C void ImpellerDisplayListBuilderClipRect(ImpellerDisplayListBuilder builder, const ImpellerRect *rect, ImpellerClipOperation op)
constexpr Matrix ToImpellerType(const ImpellerMatrix &m)
IMPELLER_EXTERN_C ImpellerTexture ImpellerTextureCreateWithOpenGLTextureHandleNew(ImpellerContext context, const ImpellerTextureDescriptor *descriptor, uint64_t external_gl_handle)
IMPELLER_EXTERN_C ImpellerTexture ImpellerTextureCreateWithContentsNew(ImpellerContext context, const ImpellerTextureDescriptor *descriptor, const ImpellerMapping *contents, void *contents_on_release_user_data)
IMPELLER_EXTERN_C void ImpellerDisplayListBuilderTransform(ImpellerDisplayListBuilder builder, const ImpellerMatrix *transform)
IMPELLER_EXTERN_C bool ImpellerTypographyContextRegisterFont(ImpellerTypographyContext context, const ImpellerMapping *contents, void *contents_on_release_user_data, const char *family_name_alias)
IMPELLER_EXTERN_C void ImpellerParagraphStyleSetFontSize(ImpellerParagraphStyle paragraph_style, float size)
IMPELLER_EXTERN_C void ImpellerDisplayListBuilderDrawParagraph(ImpellerDisplayListBuilder builder, ImpellerParagraph paragraph, const ImpellerPoint *point)
IMPELLER_EXTERN_C void ImpellerParagraphStyleSetFontFamily(ImpellerParagraphStyle paragraph_style, const char *family_name)
IMPELLER_EXTERN_C bool ImpellerSurfaceDrawDisplayList(ImpellerSurface surface, ImpellerDisplayList display_list)
IMPELLER_EXTERN_C void ImpellerDisplayListBuilderTranslate(ImpellerDisplayListBuilder builder, float x_translation, float y_translation)
IMPELLER_EXTERN_C void ImpellerParagraphStyleSetForeground(ImpellerParagraphStyle paragraph_style, ImpellerPaint paint)
IMPELLER_EXTERN_C ImpellerParagraphStyle ImpellerParagraphStyleNew()
IMPELLER_EXTERN_C void ImpellerDisplayListBuilderDrawTexture(ImpellerDisplayListBuilder builder, ImpellerTexture texture, const ImpellerPoint *point, ImpellerTextureSampling sampling, ImpellerPaint paint)
IMPELLER_EXTERN_C void ImpellerDisplayListBuilderDrawRect(ImpellerDisplayListBuilder builder, const ImpellerRect *rect, ImpellerPaint paint)
IMPELLER_EXTERN_C void ImpellerPaintSetColor(ImpellerPaint paint, const ImpellerColor *color)
IMPELLER_EXTERN_C void ImpellerParagraphBuilderAddText(ImpellerParagraphBuilder paragraph_builder, const uint8_t *data, uint32_t length)
const uint8_t *IMPELLER_NONNULL data
ImpellerPoint bottom_right
ImpellerPixelFormat pixel_format
constexpr std::array< uint8_t, 4 > ToR8G8B8A8() const
Convert to R8G8B8A8 representation.
static constexpr Color Fuchsia()
constexpr bool IsIdentity() const