Flutter Impeller
impeller::interop::testing Namespace Reference

Classes

class  FlagObject
 
class  TestObject
 
class  PlaygroundTest
 

Typedefs

using InteropPlaygroundTest = PlaygroundTest
 

Functions

 INSTANTIATE_OPENGLES_PLAYGROUND_SUITE (InteropPlaygroundTest)
 
 TEST_P (InteropPlaygroundTest, CanCreateContext)
 
 TEST_P (InteropPlaygroundTest, CanCreateDisplayListBuilder)
 
 TEST_P (InteropPlaygroundTest, CanCreateSurface)
 
 TEST_P (InteropPlaygroundTest, CanDrawRect)
 
 TEST_P (InteropPlaygroundTest, CanDrawImage)
 
 TEST_P (InteropPlaygroundTest, CanCreateOpenGLImage)
 
 TEST_P (InteropPlaygroundTest, ClearsOpenGLStancilStateAfterTransition)
 
 TEST_P (InteropPlaygroundTest, CanCreateParagraphs)
 
 TEST_P (InteropPlaygroundTest, CanCreateShapes)
 
 TEST_P (InteropPlaygroundTest, CanCreateParagraphsWithCustomFont)
 
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)
 
 TEST_P (InteropPlaygroundTest, CanRenderTextAlignments)
 
 IMPELLER_DEFINE_HANDLE (FlagHandle)
 
 IMPELLER_DEFINE_HANDLE (TestHandle)
 
 TEST (InteropObjectTest, CanCreateScoped)
 
 TEST (InteropObjectTest, CanCreate)
 
 TEST (InteropObjectTest, CanCopyAssignMove)
 

Typedef Documentation

◆ InteropPlaygroundTest

Function Documentation

◆ DrawTextFrame()

static void impeller::interop::testing::DrawTextFrame ( const hpp::TypographyContext &  tc,
hpp::DisplayListBuilder &  builder,
hpp::ParagraphStyle &  p_style,
const hpp::Paint &  bg,
ImpellerColor  color,
ImpellerTextAlignment  align,
float  x_offset 
)
static

Definition at line 393 of file impeller_unittests.cc.

399  {
400  const char text[] =
401  "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
402 
403  hpp::Paint fg;
404 
405  // Draw a box.
406  fg.SetColor(color);
407  fg.SetDrawStyle(kImpellerDrawStyleStroke);
408  ImpellerRect box_rect = {10 + x_offset, 10, 200, 200};
409  builder.DrawRect(box_rect, fg);
410 
411  // Draw text.
412  fg.SetDrawStyle(kImpellerDrawStyleFill);
413  p_style.SetForeground(fg);
414  p_style.SetBackground(bg);
415  p_style.SetTextAlignment(align);
416 
417  hpp::ParagraphBuilder p_builder(tc);
418  p_builder.PushStyle(p_style);
419  p_builder.AddText(reinterpret_cast<const uint8_t*>(text), sizeof(text));
420 
421  auto left_p = p_builder.Build(box_rect.width - 20.0);
422  ImpellerPoint pt = {20.0f + x_offset, 20.0f};
423  float w = left_p.GetMaxWidth();
424  float h = left_p.GetHeight();
425  builder.DrawParagraph(left_p, pt);
426  fg.SetDrawStyle(kImpellerDrawStyleStroke);
427 
428  // Draw an inner box around the paragraph layout.
429  ImpellerRect inner_box_rect = {pt.x, pt.y, w, h};
430  builder.DrawRect(inner_box_rect, fg);
431 }
@ kImpellerDrawStyleStroke
Definition: impeller.h:361
@ kImpellerDrawStyleFill
Definition: impeller.h:360
float width
Definition: impeller.h:443

References kImpellerDrawStyleFill, kImpellerDrawStyleStroke, ImpellerRect::width, ImpellerPoint::x, and ImpellerPoint::y.

Referenced by TEST_P().

◆ IMPELLER_DEFINE_HANDLE() [1/2]

impeller::interop::testing::IMPELLER_DEFINE_HANDLE ( FlagHandle  )

◆ IMPELLER_DEFINE_HANDLE() [2/2]

impeller::interop::testing::IMPELLER_DEFINE_HANDLE ( TestHandle  )

◆ INSTANTIATE_OPENGLES_PLAYGROUND_SUITE()

impeller::interop::testing::INSTANTIATE_OPENGLES_PLAYGROUND_SUITE ( InteropPlaygroundTest  )

◆ TEST() [1/3]

impeller::interop::testing::TEST ( InteropObjectTest  ,
CanCopyAssignMove   
)

Definition at line 75 of file object_unittests.cc.

75  {
76  auto o = Create<TestObject>(1, 2.3, 'd');
77  ASSERT_EQ(o->GetRefCountForTests(), 1u);
78  {
79  auto o1 = o; // NOLINT(performance-unnecessary-copy-initialization)
80  ASSERT_EQ(o->GetRefCountForTests(), 2u);
81  auto o2 = o; // NOLINT(performance-unnecessary-copy-initialization)
82  ASSERT_EQ(o->GetRefCountForTests(), 3u);
83  auto o3 = o1; // NOLINT(performance-unnecessary-copy-initialization)
84  ASSERT_EQ(o->GetRefCountForTests(), 4u);
85  }
86  ASSERT_EQ(o->GetRefCountForTests(), 1u);
87 
88  {
89  auto o1(o); // NOLINT(performance-unnecessary-copy-initialization)
90  ASSERT_EQ(o->GetRefCountForTests(), 2u);
91  ASSERT_EQ(o1->GetRefCountForTests(), 2u);
92  }
93 
94  auto move_o = std::move(o);
95  ASSERT_EQ(move_o->GetRefCountForTests(), 1u);
96 }

◆ TEST() [2/3]

impeller::interop::testing::TEST ( InteropObjectTest  ,
CanCreate   
)

Definition at line 68 of file object_unittests.cc.

68  {
69  auto object = Create<TestObject>(1, 1.3, 'c');
70  ASSERT_EQ(object->GetArg1(), 1);
71  ASSERT_EQ(object->GetArg2(), 1.3);
72  ASSERT_EQ(object->GetArg3(), 'c');
73 }

◆ TEST() [3/3]

impeller::interop::testing::TEST ( InteropObjectTest  ,
CanCreateScoped   
)

Definition at line 52 of file object_unittests.cc.

52  {
53  bool destructed = false;
54  {
55  auto object = Adopt(new FlagObject(destructed)); //
56  }
57  ASSERT_TRUE(destructed);
58 
59  destructed = false;
60  {
61  auto object = Ref(new FlagObject(destructed));
62  // New objects start with retain count of 1.
63  object->Release();
64  }
65  ASSERT_TRUE(destructed);
66 }
ScopedObject< Object > Ref(Object *object)
Definition: object.h:145
ScopedObject< Object > Adopt(Object *object)
Definition: object.h:150

References impeller::interop::Adopt(), and impeller::interop::Ref().

◆ TEST_P() [1/11]

impeller::interop::testing::TEST_P ( InteropPlaygroundTest  ,
CanCreateContext   
)

Definition at line 29 of file impeller_unittests.cc.

29  {
30  auto context = CreateContext();
31  ASSERT_TRUE(context);
32 }

◆ TEST_P() [2/11]

impeller::interop::testing::TEST_P ( InteropPlaygroundTest  ,
CanCreateDisplayListBuilder   
)

Definition at line 34 of file impeller_unittests.cc.

34  {
35  hpp::DisplayListBuilder builder;
36  ASSERT_TRUE(builder);
37  ASSERT_TRUE(ToImpellerType(builder.GetTransform()).IsIdentity());
38  ASSERT_EQ(builder.GetSaveCount(), 1u);
39  builder.Save();
40  ASSERT_EQ(builder.GetSaveCount(), 2u);
41  builder.Restore();
42  ASSERT_EQ(builder.GetSaveCount(), 1u);
43 }
constexpr Matrix ToImpellerType(const ImpellerMatrix &m)
Definition: formats.h:201
constexpr bool IsIdentity() const
Definition: matrix.h:401

References impeller::Matrix::IsIdentity(), and impeller::interop::ToImpellerType().

◆ TEST_P() [3/11]

impeller::interop::testing::TEST_P ( InteropPlaygroundTest  ,
CanCreateOpenGLImage   
)

Definition at line 123 of file impeller_unittests.cc.

123  {
124  auto context = GetInteropContext();
125 
126  auto impeller_context = context->GetContext();
127 
128  if (impeller_context->GetBackendType() !=
130  GTEST_SKIP() << "This test works with OpenGL handles is only suitable for "
131  "that backend.";
132  return;
133  }
134 
135  const auto& gl_context = ContextGLES::Cast(*impeller_context);
136  const auto& gl = gl_context.GetReactor()->GetProcTable();
137 
138  constexpr ISize external_texture_size = {200, 300};
139 
140  Allocation texture_data;
141  ASSERT_TRUE(
142  texture_data.Truncate(Bytes{external_texture_size.Area() * 4u}, false));
143 
144  const auto kClearColor = Color::Fuchsia().ToR8G8B8A8();
145 
146  for (size_t i = 0; i < external_texture_size.Area() * 4u; i += 4u) {
147  memcpy(texture_data.GetBuffer() + i, kClearColor.data(), 4);
148  }
149 
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, //
155  0, //
156  GL_RGBA, //
157  external_texture_size.width, //
158  external_texture_size.height, //
159  0, //
160  GL_RGBA, //
161  GL_UNSIGNED_BYTE, //
162  texture_data.GetBuffer() //
163  );
164 
165  ImpellerTextureDescriptor desc = {};
167  desc.size = {external_texture_size.width, external_texture_size.height};
168  desc.mip_count = 1u;
169  auto texture = Adopt<Texture>(ImpellerTextureCreateWithOpenGLTextureHandleNew(
170  context.GetC(), //
171  &desc, //
172  external_texture //
173  ));
174  ASSERT_TRUE(texture);
175 
176  ASSERT_EQ(ImpellerTextureGetOpenGLHandle(texture.GetC()), external_texture);
177 
178  auto builder =
179  Adopt<DisplayListBuilder>(ImpellerDisplayListBuilderNew(nullptr));
180  ImpellerPoint point = {100, 100};
181  ImpellerDisplayListBuilderDrawTexture(builder.GetC(), texture.GetC(), &point,
183  nullptr);
184  auto dl = Adopt<DisplayList>(
186  ASSERT_TRUE(
187  OpenPlaygroundHere([&](const auto& context, const auto& surface) -> bool {
188  ImpellerSurfaceDrawDisplayList(surface.GetC(), dl.GetC());
189  return true;
190  }));
191 }
@ kImpellerTextureSamplingLinear
Definition: impeller.h:383
IMPELLER_EXPORT bool ImpellerSurfaceDrawDisplayList(ImpellerSurface IMPELLER_NULLABLE surface, ImpellerDisplayList IMPELLER_NONNULL display_list)
Draw a display list onto the surface. The same display list can be drawn multiple times to different ...
IMPELLER_EXPORT void ImpellerDisplayListBuilderDrawTexture(ImpellerDisplayListBuilder IMPELLER_NONNULL builder, ImpellerTexture IMPELLER_NONNULL texture, const ImpellerPoint *IMPELLER_NONNULL point, ImpellerTextureSampling sampling, ImpellerPaint IMPELLER_NULLABLE paint)
Draw a texture at the specified point.
IMPELLER_EXPORT uint64_t ImpellerTextureGetOpenGLHandle(ImpellerTexture IMPELLER_NONNULL texture)
Get the OpenGL handle associated with this texture. If this is not an OpenGL texture,...
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerDisplayList IMPELLER_NULLABLE ImpellerDisplayListBuilderCreateDisplayListNew(ImpellerDisplayListBuilder IMPELLER_NONNULL builder)
Create a new display list using the rendering intent already encoded in the builder....
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerTexture IMPELLER_NULLABLE ImpellerTextureCreateWithOpenGLTextureHandleNew(ImpellerContext IMPELLER_NONNULL context, const ImpellerTextureDescriptor *IMPELLER_NONNULL descriptor, uint64_t handle)
Create a texture with an externally created OpenGL texture handle.
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerDisplayListBuilder IMPELLER_NULLABLE ImpellerDisplayListBuilderNew(const ImpellerRect *IMPELLER_NULLABLE cull_rect)
Create a new display list builder.
@ kImpellerPixelFormatRGBA8888
Definition: impeller.h:378
AllocationSize< 1u > Bytes
ISize64 ISize
Definition: size.h:174
int64_t width
Definition: impeller.h:458
ImpellerPixelFormat pixel_format
Definition: impeller.h:554
ImpellerISize size
Definition: impeller.h:555

References impeller::BackendCast< ContextGLES, Context >::Cast(), impeller::Color::Fuchsia(), impeller::Allocation::GetBuffer(), impeller::interop::ImpellerDisplayListBuilderCreateDisplayListNew(), impeller::interop::ImpellerDisplayListBuilderDrawTexture(), impeller::interop::ImpellerDisplayListBuilderNew(), impeller::interop::ImpellerSurfaceDrawDisplayList(), impeller::interop::ImpellerTextureCreateWithOpenGLTextureHandleNew(), impeller::interop::ImpellerTextureGetOpenGLHandle(), kImpellerPixelFormatRGBA8888, kImpellerTextureSamplingLinear, impeller::Context::kOpenGLES, ImpellerTextureDescriptor::mip_count, ImpellerTextureDescriptor::pixel_format, ImpellerTextureDescriptor::size, impeller::Color::ToR8G8B8A8(), impeller::Allocation::Truncate(), and ImpellerISize::width.

◆ TEST_P() [4/11]

impeller::interop::testing::TEST_P ( InteropPlaygroundTest  ,
CanCreateParagraphs   
)

Definition at line 231 of file impeller_unittests.cc.

231  {
232  // Create a typography context.
233  hpp::TypographyContext type_context;
234  ASSERT_TRUE(type_context);
235 
236  // Create a builder.
237  hpp::ParagraphBuilder builder(type_context);
238  ASSERT_TRUE(builder);
239 
240  // Create a paragraph style with the font size and foreground and background
241  // colors.
242  hpp::ParagraphStyle style;
243  ASSERT_TRUE(style);
244  style.SetFontSize(150.0f);
245  style.SetHeight(2.0f);
246 
247  {
248  hpp::Paint paint;
249  ASSERT_TRUE(paint);
250  paint.SetColor({1.0, 0.0, 0.0, 1.0});
251  style.SetForeground(paint);
252  }
253 
254  {
255  hpp::Paint paint;
256  paint.SetColor({1.0, 1.0, 1.0, 1.0});
257  style.SetBackground(paint);
258  }
259 
260  // Push the style onto the style stack.
261  builder.PushStyle(style);
262  std::string text = "the ⚡️ quick ⚡️ brown 🦊 fox jumps over the lazy dog 🐶.";
263 
264  // Add the paragraph text data.
265  builder.AddText(text);
266 
267  // Layout and build the paragraph.
268  auto paragraph = builder.Build(1200.0f);
269  ASSERT_TRUE(paragraph);
270 
271  // Create a display list with just the paragraph drawn into it.
272  hpp::DisplayListBuilder dl_builder;
273  dl_builder.DrawParagraph(paragraph, {20, 20});
274 
275  // Build the display list.
276  auto dl = dl_builder.Build();
277 
278  ASSERT_TRUE(
279  OpenPlaygroundHere([&](const auto& context, const auto& surface) -> bool {
280  hpp::Surface window(surface.GetC());
281  window.Draw(dl);
282  return true;
283  }));
284 }

◆ TEST_P() [5/11]

impeller::interop::testing::TEST_P ( InteropPlaygroundTest  ,
CanCreateParagraphsWithCustomFont   
)

Definition at line 319 of file impeller_unittests.cc.

319  {
320  // Create a typography context.
321  auto type_context = Adopt<TypographyContext>(ImpellerTypographyContextNew());
322  ASSERT_TRUE(type_context);
323 
324  // Open the custom font file.
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);
329  ImpellerMapping font_data_mapping = {
330  .data = font_data->GetMapping(),
331  .length = font_data->GetSize(),
332  .on_release = [](auto ctx) {
333  delete reinterpret_cast<fml::Mapping*>(ctx);
334  }};
335  auto registered =
336  ImpellerTypographyContextRegisterFont(type_context.GetC(), //
337  &font_data_mapping, //
338  font_data.release(), //
339  nullptr //
340  );
341  ASSERT_TRUE(registered);
342 
343  // Create a builder.
344  auto builder =
345  Adopt<ParagraphBuilder>(ImpellerParagraphBuilderNew(type_context.GetC()));
346  ASSERT_TRUE(builder);
347 
348  // Create a paragraph style with the font size and foreground and background
349  // colors.
350  auto style = Adopt<ParagraphStyle>(ImpellerParagraphStyleNew());
351  ASSERT_TRUE(style);
352  ImpellerParagraphStyleSetFontSize(style.GetC(), 150.0f);
353  ImpellerParagraphStyleSetFontFamily(style.GetC(), "WhatTheFlutter");
354 
355  {
356  auto paint = Adopt<Paint>(ImpellerPaintNew());
357  ASSERT_TRUE(paint);
358  ImpellerColor color = {0.0, 1.0, 1.0, 1.0};
359  ImpellerPaintSetColor(paint.GetC(), &color);
360  ImpellerParagraphStyleSetForeground(style.GetC(), paint.GetC());
361  }
362 
363  // Push the style onto the style stack.
364  ImpellerParagraphBuilderPushStyle(builder.GetC(), style.GetC());
365  std::string text = "0F0F0F0";
366 
367  // Add the paragraph text data.
368  ImpellerParagraphBuilderAddText(builder.GetC(),
369  reinterpret_cast<const uint8_t*>(text.data()),
370  text.size());
371 
372  // Layout and build the paragraph.
373  auto paragraph = Adopt<Paragraph>(
374  ImpellerParagraphBuilderBuildParagraphNew(builder.GetC(), 1200.0f));
375  ASSERT_TRUE(paragraph);
376 
377  // Create a display list with just the paragraph drawn into it.
378  auto dl_builder =
379  Adopt<DisplayListBuilder>(ImpellerDisplayListBuilderNew(nullptr));
380  ImpellerPoint point = {20, 20};
381  ImpellerDisplayListBuilderDrawParagraph(dl_builder.GetC(), paragraph.GetC(),
382  &point);
383  auto dl = Adopt<DisplayList>(
385 
386  ASSERT_TRUE(
387  OpenPlaygroundHere([&](const auto& context, const auto& surface) -> bool {
388  ImpellerSurfaceDrawDisplayList(surface.GetC(), dl.GetC());
389  return true;
390  }));
391 } // namespace impeller::interop::testing
IMPELLER_EXPORT void ImpellerDisplayListBuilderDrawParagraph(ImpellerDisplayListBuilder IMPELLER_NONNULL builder, ImpellerParagraph IMPELLER_NONNULL paragraph, const ImpellerPoint *IMPELLER_NONNULL point)
Draw a paragraph at the specified point.
IMPELLER_EXPORT bool ImpellerTypographyContextRegisterFont(ImpellerTypographyContext IMPELLER_NONNULL context, const ImpellerMapping *IMPELLER_NONNULL contents, void *IMPELLER_NULLABLE contents_on_release_user_data, const char *IMPELLER_NULLABLE family_name_alias)
Register a custom font.
IMPELLER_EXPORT void ImpellerParagraphBuilderAddText(ImpellerParagraphBuilder IMPELLER_NONNULL paragraph_builder, const uint8_t *IMPELLER_NULLABLE data, uint32_t length)
Add UTF-8 encoded text to the paragraph. The text will be styled according to the paragraph style alr...
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerPaint IMPELLER_NULLABLE ImpellerPaintNew()
Create a new paint with default values.
IMPELLER_EXPORT void ImpellerPaintSetColor(ImpellerPaint IMPELLER_NONNULL paint, const ImpellerColor *IMPELLER_NONNULL color)
Set the paint color.
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerParagraph IMPELLER_NULLABLE ImpellerParagraphBuilderBuildParagraphNew(ImpellerParagraphBuilder IMPELLER_NONNULL paragraph_builder, float width)
Layout and build a new paragraph using the specified width. The resulting paragraph is immutable....
IMPELLER_EXPORT void ImpellerParagraphBuilderPushStyle(ImpellerParagraphBuilder IMPELLER_NONNULL paragraph_builder, ImpellerParagraphStyle IMPELLER_NONNULL style)
Push a new paragraph style onto the paragraph style stack managed by the paragraph builder.
IMPELLER_EXPORT void ImpellerParagraphStyleSetFontSize(ImpellerParagraphStyle IMPELLER_NONNULL paragraph_style, float size)
Set the font size.
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerParagraphStyle IMPELLER_NULLABLE ImpellerParagraphStyleNew()
Create a new paragraph style.
IMPELLER_EXPORT void ImpellerParagraphStyleSetForeground(ImpellerParagraphStyle IMPELLER_NONNULL paragraph_style, ImpellerPaint IMPELLER_NONNULL paint)
Set the paint used to render the text glyph contents.
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerTypographyContext IMPELLER_NULLABLE ImpellerTypographyContextNew()
Create a new typography contents.
IMPELLER_EXPORT void ImpellerParagraphStyleSetFontFamily(ImpellerParagraphStyle IMPELLER_NONNULL paragraph_style, const char *IMPELLER_NONNULL family_name)
Set the font family.
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerParagraphBuilder IMPELLER_NULLABLE ImpellerParagraphBuilderNew(ImpellerTypographyContext IMPELLER_NONNULL context)
Create a new paragraph builder.
const uint8_t *IMPELLER_NONNULL data
Definition: impeller.h:560

References ImpellerMapping::data, impeller::interop::ImpellerDisplayListBuilderCreateDisplayListNew(), impeller::interop::ImpellerDisplayListBuilderDrawParagraph(), impeller::interop::ImpellerDisplayListBuilderNew(), impeller::interop::ImpellerPaintNew(), impeller::interop::ImpellerPaintSetColor(), impeller::interop::ImpellerParagraphBuilderAddText(), impeller::interop::ImpellerParagraphBuilderBuildParagraphNew(), impeller::interop::ImpellerParagraphBuilderNew(), impeller::interop::ImpellerParagraphBuilderPushStyle(), impeller::interop::ImpellerParagraphStyleNew(), impeller::interop::ImpellerParagraphStyleSetFontFamily(), impeller::interop::ImpellerParagraphStyleSetFontSize(), impeller::interop::ImpellerParagraphStyleSetForeground(), impeller::interop::ImpellerSurfaceDrawDisplayList(), impeller::interop::ImpellerTypographyContextNew(), and impeller::interop::ImpellerTypographyContextRegisterFont().

◆ TEST_P() [6/11]

impeller::interop::testing::TEST_P ( InteropPlaygroundTest  ,
CanCreateShapes   
)

Definition at line 286 of file impeller_unittests.cc.

286  {
287  hpp::DisplayListBuilder builder;
288 
289  hpp::Paint red_paint;
290  red_paint.SetColor({1.0, 0.0, 0.0, 1.0});
291  red_paint.SetStrokeWidth(10.0);
292 
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);
299 
300  builder.Translate(100, 100);
301  ImpellerRoundingRadii radii = {};
302  radii.top_left = {10, 10};
303  radii.bottom_right = {10, 10};
304  builder.DrawRoundedRect({0, 0, 100, 100}, radii, red_paint);
305 
306  builder.Translate(100, 100);
307  builder.DrawPath(hpp::PathBuilder{}.AddOval({0, 0, 100, 100}).Build(),
308  red_paint);
309 
310  auto dl = builder.Build();
311  ASSERT_TRUE(
312  OpenPlaygroundHere([&](const auto& context, const auto& surface) -> bool {
313  hpp::Surface window(surface.GetC());
314  window.Draw(dl);
315  return true;
316  }));
317 }
ImpellerPoint top_left
Definition: impeller.h:539
ImpellerPoint bottom_right
Definition: impeller.h:542

References ImpellerRoundingRadii::bottom_right, and ImpellerRoundingRadii::top_left.

◆ TEST_P() [7/11]

impeller::interop::testing::TEST_P ( InteropPlaygroundTest  ,
CanCreateSurface   
)

Definition at line 45 of file impeller_unittests.cc.

45  {
46  auto context = CreateContext();
47  ASSERT_TRUE(context);
48  const auto window_size = GetWindowSize();
49  ImpellerISize size = {window_size.width, window_size.height};
50  auto surface = Adopt<Surface>(ImpellerSurfaceCreateWrappedFBONew(
51  context.GetC(), //
52  0u, //
54  &size) //
55  );
56  ASSERT_TRUE(surface);
57 }
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerSurface IMPELLER_NULLABLE ImpellerSurfaceCreateWrappedFBONew(ImpellerContext IMPELLER_NULLABLE context, uint64_t fbo, ImpellerPixelFormat format, const ImpellerISize *IMPELLER_NULLABLE size)
Create a new surface by wrapping an existing framebuffer object. The framebuffer must be complete as ...

References impeller::interop::ImpellerSurfaceCreateWrappedFBONew(), kImpellerPixelFormatRGBA8888, and ImpellerISize::width.

◆ TEST_P() [8/11]

impeller::interop::testing::TEST_P ( InteropPlaygroundTest  ,
CanDrawImage   
)

Definition at line 90 of file impeller_unittests.cc.

90  {
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());
96  ImpellerMapping mapping = {};
97  mapping.data = decompressed.GetAllocation()->GetMapping();
98  mapping.length = decompressed.GetAllocation()->GetSize();
99 
100  auto context = GetInteropContext();
101  ImpellerTextureDescriptor desc = {};
103  desc.size = {decompressed.GetSize().width, decompressed.GetSize().height};
104  desc.mip_count = 1u;
105  auto texture = Adopt<Texture>(ImpellerTextureCreateWithContentsNew(
106  context.GetC(), &desc, &mapping, nullptr));
107  ASSERT_TRUE(texture);
108  auto builder =
109  Adopt<DisplayListBuilder>(ImpellerDisplayListBuilderNew(nullptr));
110  ImpellerPoint point = {100, 100};
111  ImpellerDisplayListBuilderDrawTexture(builder.GetC(), texture.GetC(), &point,
113  nullptr);
114  auto dl = Adopt<DisplayList>(
116  ASSERT_TRUE(
117  OpenPlaygroundHere([&](const auto& context, const auto& surface) -> bool {
118  ImpellerSurfaceDrawDisplayList(surface.GetC(), dl.GetC());
119  return true;
120  }));
121 }
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerTexture IMPELLER_NULLABLE ImpellerTextureCreateWithContentsNew(ImpellerContext IMPELLER_NONNULL context, const ImpellerTextureDescriptor *IMPELLER_NONNULL descriptor, const ImpellerMapping *IMPELLER_NONNULL contents, void *IMPELLER_NULLABLE contents_on_release_user_data)
Create a texture with decompressed bytes.
uint64_t length
Definition: impeller.h:561

References ImpellerMapping::data, impeller::interop::ImpellerDisplayListBuilderCreateDisplayListNew(), impeller::interop::ImpellerDisplayListBuilderDrawTexture(), impeller::interop::ImpellerDisplayListBuilderNew(), impeller::interop::ImpellerSurfaceDrawDisplayList(), impeller::interop::ImpellerTextureCreateWithContentsNew(), kImpellerPixelFormatRGBA8888, kImpellerTextureSamplingLinear, ImpellerMapping::length, ImpellerTextureDescriptor::mip_count, ImpellerTextureDescriptor::pixel_format, ImpellerTextureDescriptor::size, and ImpellerISize::width.

◆ TEST_P() [9/11]

impeller::interop::testing::TEST_P ( InteropPlaygroundTest  ,
CanDrawRect   
)

Definition at line 59 of file impeller_unittests.cc.

59  {
60  auto builder =
61  Adopt<DisplayListBuilder>(ImpellerDisplayListBuilderNew(nullptr));
62  auto paint = Adopt<Paint>(ImpellerPaintNew());
63  ImpellerColor color = {0.0, 0.0, 1.0, 1.0};
64  ImpellerPaintSetColor(paint.GetC(), &color);
65  ImpellerRect rect = {10, 20, 100, 200};
66  ImpellerDisplayListBuilderDrawRect(builder.GetC(), &rect, paint.GetC());
67  color = {1.0, 0.0, 0.0, 1.0};
68  ImpellerPaintSetColor(paint.GetC(), &color);
69  ImpellerDisplayListBuilderTranslate(builder.GetC(), 110, 210);
70  ImpellerMatrix scale_transform = {
71  // clang-format off
72  2.0, 0.0, 0.0, 0.0, //
73  0.0, 2.0, 0.0, 0.0, //
74  0.0, 0.0, 1.0, 0.0, //
75  0.0, 0.0, 0.0, 1.0, //
76  // clang-format on
77  };
78  ImpellerDisplayListBuilderTransform(builder.GetC(), &scale_transform);
79  ImpellerDisplayListBuilderDrawRect(builder.GetC(), &rect, paint.GetC());
80  auto dl = Adopt<DisplayList>(
82  ASSERT_TRUE(dl);
83  ASSERT_TRUE(
84  OpenPlaygroundHere([&](const auto& context, const auto& surface) -> bool {
85  ImpellerSurfaceDrawDisplayList(surface.GetC(), dl.GetC());
86  return true;
87  }));
88 }
IMPELLER_EXPORT void ImpellerDisplayListBuilderTranslate(ImpellerDisplayListBuilder IMPELLER_NONNULL builder, float x_translation, float y_translation)
Apply a translation to the transformation matrix currently on top of the save stack.
IMPELLER_EXPORT void ImpellerDisplayListBuilderTransform(ImpellerDisplayListBuilder IMPELLER_NONNULL builder, const ImpellerMatrix *IMPELLER_NONNULL transform)
Appends the the provided transformation to the transformation already on the save stack.
IMPELLER_EXPORT void ImpellerDisplayListBuilderDrawRect(ImpellerDisplayListBuilder IMPELLER_NONNULL builder, const ImpellerRect *IMPELLER_NONNULL rect, ImpellerPaint IMPELLER_NONNULL paint)
Draws a rectangle.

References impeller::interop::ImpellerDisplayListBuilderCreateDisplayListNew(), impeller::interop::ImpellerDisplayListBuilderDrawRect(), impeller::interop::ImpellerDisplayListBuilderNew(), impeller::interop::ImpellerDisplayListBuilderTransform(), impeller::interop::ImpellerDisplayListBuilderTranslate(), impeller::interop::ImpellerPaintNew(), impeller::interop::ImpellerPaintSetColor(), and impeller::interop::ImpellerSurfaceDrawDisplayList().

◆ TEST_P() [10/11]

impeller::interop::testing::TEST_P ( InteropPlaygroundTest  ,
CanRenderTextAlignments   
)

Definition at line 433 of file impeller_unittests.cc.

433  {
434  hpp::TypographyContext tc;
435 
436  hpp::DisplayListBuilder builder;
437  hpp::Paint bg;
438  hpp::ParagraphStyle p_style;
439  p_style.SetFontFamily("Roboto");
440  p_style.SetFontSize(24.0);
441  p_style.SetFontWeight(kImpellerFontWeight400);
442 
443  // Clear the background to a white color.
444  ImpellerColor clear_color = {1.0, 1.0, 1.0, 1.0};
445  bg.SetColor(clear_color);
446  builder.DrawPaint(bg);
447 
448  // Draw red, left-aligned text.
449  ImpellerColor red = {1.0, 0.0, 0.0, 1.0};
450  DrawTextFrame(tc, builder, p_style, bg, red, kImpellerTextAlignmentLeft, 0.0);
451 
452  // Draw green, centered text.
453  ImpellerColor green = {0.0, 1.0, 0.0, 1.0};
454  DrawTextFrame(tc, builder, p_style, bg, green, kImpellerTextAlignmentCenter,
455  220.0);
456 
457  // Draw blue, right-aligned text.
458  ImpellerColor blue = {0.0, 0.0, 1.0, 1.0};
459  DrawTextFrame(tc, builder, p_style, bg, blue, kImpellerTextAlignmentRight,
460  440.0);
461 
462  auto dl = builder.Build();
463 
464  ASSERT_TRUE(
465  OpenPlaygroundHere([&](const auto& context, const auto& surface) -> bool {
466  hpp::Surface window(surface.GetC());
467  window.Draw(dl);
468  return true;
469  }));
470 }
@ kImpellerFontWeight400
Definition: impeller.h:410
@ kImpellerTextAlignmentLeft
Definition: impeller.h:424
@ kImpellerTextAlignmentCenter
Definition: impeller.h:426
@ kImpellerTextAlignmentRight
Definition: impeller.h:425
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)

References DrawTextFrame(), kImpellerFontWeight400, kImpellerTextAlignmentCenter, kImpellerTextAlignmentLeft, and kImpellerTextAlignmentRight.

◆ TEST_P() [11/11]

impeller::interop::testing::TEST_P ( InteropPlaygroundTest  ,
ClearsOpenGLStancilStateAfterTransition   
)

Definition at line 193 of file impeller_unittests.cc.

193  {
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 "
199  "that backend.";
200  return;
201  }
202  const auto& gl_context = ContextGLES::Cast(*impeller_context);
203  const auto& gl = gl_context.GetReactor()->GetProcTable();
204  auto builder =
205  Adopt<DisplayListBuilder>(ImpellerDisplayListBuilderNew(nullptr));
206  auto paint = Adopt<Paint>(ImpellerPaintNew());
207  ImpellerColor color = {0.0, 0.0, 1.0, 1.0};
208  ImpellerPaintSetColor(paint.GetC(), &color);
209  ImpellerRect rect = {10, 20, 100, 200};
210  ImpellerDisplayListBuilderDrawRect(builder.GetC(), &rect, paint.GetC());
211  color = {1.0, 0.0, 0.0, 1.0};
212  ImpellerPaintSetColor(paint.GetC(), &color);
213  ImpellerDisplayListBuilderTranslate(builder.GetC(), 110, 210);
214  ImpellerDisplayListBuilderClipRect(builder.GetC(), &rect,
216  ImpellerDisplayListBuilderDrawRect(builder.GetC(), &rect, paint.GetC());
217  auto dl = Adopt<DisplayList>(
219  ASSERT_TRUE(dl);
220  ASSERT_TRUE(
221  OpenPlaygroundHere([&](const auto& context, const auto& surface) -> bool {
222  ImpellerSurfaceDrawDisplayList(surface.GetC(), dl.GetC());
223  // OpenGL state is reset even though the operations above enable a
224  // stencil check.
225  GLboolean stencil_enabled = true;
226  gl.GetBooleanv(GL_STENCIL_TEST, &stencil_enabled);
227  return stencil_enabled == GL_FALSE;
228  }));
229 }
IMPELLER_EXPORT void ImpellerDisplayListBuilderClipRect(ImpellerDisplayListBuilder IMPELLER_NONNULL builder, const ImpellerRect *IMPELLER_NONNULL rect, ImpellerClipOperation op)
Reduces the clip region to the intersection of the current clip and the given rectangle taking into a...
@ kImpellerClipOperationDifference
Definition: impeller.h:323

References impeller::BackendCast< ContextGLES, Context >::Cast(), impeller::interop::ImpellerDisplayListBuilderClipRect(), impeller::interop::ImpellerDisplayListBuilderCreateDisplayListNew(), impeller::interop::ImpellerDisplayListBuilderDrawRect(), impeller::interop::ImpellerDisplayListBuilderNew(), impeller::interop::ImpellerDisplayListBuilderTranslate(), impeller::interop::ImpellerPaintNew(), impeller::interop::ImpellerPaintSetColor(), impeller::interop::ImpellerSurfaceDrawDisplayList(), kImpellerClipOperationDifference, and impeller::Context::kOpenGLES.