Skip to content

Commit

Permalink
Add an OpenGL ES stub and parameterize all playgrounds on rendering b…
Browse files Browse the repository at this point in the history
…ackend. (flutter#141)

As we add more rendering backends, adding a new enum value to a single macro
`INSTANTIATE_PLAYGROUND_SUITE` in `playground.h` will create a new test variant
in any suite that uses playgrounds.

The invocations will look like the following:

```
[ RUN      ] Play/TypographerTest.CanCreateGlyphAtlas/Metal
[       OK ] Play/TypographerTest.CanCreateGlyphAtlas/Metal (210 ms)
[ RUN      ] Play/TypographerTest.CanCreateGlyphAtlas/OpenGLES
[       OK ] Play/TypographerTest.CanCreateGlyphAtlas/OpenGLES (xxx ms)
```

If you want to test just one backend, you may add a filter like so
`--gtest_filter="*/Metal"`

Right now, I have not added a the OpenGLES variant to the default test suite
instantiation since there are so many failures (that is just a stub ATM). But,
if the need arises to skip specific tests based on the backend in use (we won't
support instancing in OpenGLES for example), the backend for the playground may
be queried before deciding to GTEST_SKIP the invocation.

One additional change in the patch that will be reworked soon is the Metal
specificity of the source set generated after reflection. This will be made
agnostic in the coming few patches. Right now, these headers are in the `mtl`
folder.
  • Loading branch information
chinmaygarde authored and dnfield committed Apr 27, 2022
1 parent 8b881c6 commit 3b1dfc4
Show file tree
Hide file tree
Showing 56 changed files with 1,204 additions and 240 deletions.
59 changes: 30 additions & 29 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ namespace impeller {
namespace testing {

using AiksTest = AiksPlayground;
INSTANTIATE_PLAYGROUND_SUITE(AiksTest);

TEST_F(AiksTest, CanvasCTMCanBeUpdated) {
TEST_P(AiksTest, CanvasCTMCanBeUpdated) {
Canvas canvas;
Matrix identity;
ASSERT_MATRIX_NEAR(canvas.GetCurrentTransformation(), identity);
Expand All @@ -29,7 +30,7 @@ TEST_F(AiksTest, CanvasCTMCanBeUpdated) {
Matrix::MakeTranslation({100.0, 100.0, 0.0}));
}

TEST_F(AiksTest, CanvasCanPushPopCTM) {
TEST_P(AiksTest, CanvasCanPushPopCTM) {
Canvas canvas;
ASSERT_EQ(canvas.GetSaveCount(), 1u);
ASSERT_EQ(canvas.Restore(), false);
Expand All @@ -45,7 +46,7 @@ TEST_F(AiksTest, CanvasCanPushPopCTM) {
Matrix::MakeTranslation({100.0, 100.0, 0.0}));
}

TEST_F(AiksTest, CanRenderColoredRect) {
TEST_P(AiksTest, CanRenderColoredRect) {
Canvas canvas;
Paint paint;
paint.color = Color::Red();
Expand All @@ -56,7 +57,7 @@ TEST_F(AiksTest, CanRenderColoredRect) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanRenderImage) {
TEST_P(AiksTest, CanRenderImage) {
Canvas canvas;
Paint paint;
auto image = std::make_shared<Image>(CreateTextureForFixture("kalimba.jpg"));
Expand All @@ -65,7 +66,7 @@ TEST_F(AiksTest, CanRenderImage) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanRenderImageRect) {
TEST_P(AiksTest, CanRenderImageRect) {
Canvas canvas;
Paint paint;
auto image = std::make_shared<Image>(CreateTextureForFixture("kalimba.jpg"));
Expand All @@ -81,7 +82,7 @@ TEST_F(AiksTest, CanRenderImageRect) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanRenderStrokes) {
TEST_P(AiksTest, CanRenderStrokes) {
Canvas canvas;
Paint paint;
paint.color = Color::Red();
Expand All @@ -92,7 +93,7 @@ TEST_F(AiksTest, CanRenderStrokes) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanRenderCurvedStrokes) {
TEST_P(AiksTest, CanRenderCurvedStrokes) {
Canvas canvas;
Paint paint;
paint.color = Color::Red();
Expand All @@ -102,7 +103,7 @@ TEST_F(AiksTest, CanRenderCurvedStrokes) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanRenderClips) {
TEST_P(AiksTest, CanRenderClips) {
Canvas canvas;
Paint paint;
paint.color = Color::Fuchsia();
Expand All @@ -112,7 +113,7 @@ TEST_F(AiksTest, CanRenderClips) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanRenderNestedClips) {
TEST_P(AiksTest, CanRenderNestedClips) {
Canvas canvas;
Paint paint;
paint.color = Color::Fuchsia();
Expand All @@ -125,7 +126,7 @@ TEST_F(AiksTest, CanRenderNestedClips) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanRenderDifferenceClips) {
TEST_P(AiksTest, CanRenderDifferenceClips) {
Paint paint;
Canvas canvas;
canvas.Translate({400, 400});
Expand Down Expand Up @@ -162,7 +163,7 @@ TEST_F(AiksTest, CanRenderDifferenceClips) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, ClipsUseCurrentTransform) {
TEST_P(AiksTest, ClipsUseCurrentTransform) {
std::array<Color, 5> colors = {Color::White(), Color::Black(),
Color::SkyBlue(), Color::Red(),
Color::Yellow()};
Expand All @@ -180,7 +181,7 @@ TEST_F(AiksTest, ClipsUseCurrentTransform) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanSaveLayerStandalone) {
TEST_P(AiksTest, CanSaveLayerStandalone) {
Canvas canvas;

Paint red;
Expand All @@ -198,7 +199,7 @@ TEST_F(AiksTest, CanSaveLayerStandalone) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanRenderGroupOpacity) {
TEST_P(AiksTest, CanRenderGroupOpacity) {
Canvas canvas;

Paint red;
Expand All @@ -222,7 +223,7 @@ TEST_F(AiksTest, CanRenderGroupOpacity) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanPerformFullScreenMSAA) {
TEST_P(AiksTest, CanPerformFullScreenMSAA) {
Canvas canvas;

Paint red;
Expand All @@ -233,7 +234,7 @@ TEST_F(AiksTest, CanPerformFullScreenMSAA) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanPerformSkew) {
TEST_P(AiksTest, CanPerformSkew) {
Canvas canvas;

Paint red;
Expand All @@ -245,7 +246,7 @@ TEST_F(AiksTest, CanPerformSkew) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanPerformSaveLayerWithBounds) {
TEST_P(AiksTest, CanPerformSaveLayerWithBounds) {
Canvas canvas;

Paint red;
Expand All @@ -271,7 +272,7 @@ TEST_F(AiksTest, CanPerformSaveLayerWithBounds) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest,
TEST_P(AiksTest,
CanPerformSaveLayerWithBoundsAndLargerIntermediateIsNotAllocated) {
Canvas canvas;

Expand All @@ -298,7 +299,7 @@ TEST_F(AiksTest,
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanRenderRoundedRectWithNonUniformRadii) {
TEST_P(AiksTest, CanRenderRoundedRectWithNonUniformRadii) {
Canvas canvas;

Paint paint;
Expand All @@ -318,7 +319,7 @@ TEST_F(AiksTest, CanRenderRoundedRectWithNonUniformRadii) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanRenderDifferencePaths) {
TEST_P(AiksTest, CanRenderDifferencePaths) {
Canvas canvas;

Paint paint;
Expand Down Expand Up @@ -393,23 +394,23 @@ bool RenderTextInCanvas(std::shared_ptr<Context> context,
return true;
}

TEST_F(AiksTest, CanRenderTextFrame) {
TEST_P(AiksTest, CanRenderTextFrame) {
Canvas canvas;
ASSERT_TRUE(RenderTextInCanvas(
GetContext(), canvas, "the quick brown fox jumped over the lazy dog!.?",
"Roboto-Regular.ttf"));
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanRenderItalicizedText) {
TEST_P(AiksTest, CanRenderItalicizedText) {
Canvas canvas;
ASSERT_TRUE(RenderTextInCanvas(
GetContext(), canvas, "the quick brown fox jumped over the lazy dog!.?",
"HomemadeApple.ttf"));
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanRenderEmojiTextFrame) {
TEST_P(AiksTest, CanRenderEmojiTextFrame) {
Canvas canvas;
ASSERT_TRUE(RenderTextInCanvas(
GetContext(), canvas,
Expand All @@ -418,7 +419,7 @@ TEST_F(AiksTest, CanRenderEmojiTextFrame) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanRenderTextInSaveLayer) {
TEST_P(AiksTest, CanRenderTextInSaveLayer) {
Canvas canvas;
canvas.DrawPaint({.color = Color::White()});
canvas.Translate({100, 100});
Expand All @@ -439,15 +440,15 @@ TEST_F(AiksTest, CanRenderTextInSaveLayer) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanDrawPaint) {
TEST_P(AiksTest, CanDrawPaint) {
Paint paint;
paint.color = Color::MediumTurquoise();
Canvas canvas;
canvas.DrawPaint(paint);
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, PaintBlendModeIsRespected) {
TEST_P(AiksTest, PaintBlendModeIsRespected) {
Paint paint;
Canvas canvas;
// Default is kSourceOver.
Expand All @@ -466,7 +467,7 @@ TEST_F(AiksTest, PaintBlendModeIsRespected) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, TransformMultipliesCorrectly) {
TEST_P(AiksTest, TransformMultipliesCorrectly) {
Canvas canvas;
ASSERT_MATRIX_NEAR(canvas.GetCurrentTransformation(), Matrix());

Expand Down Expand Up @@ -505,7 +506,7 @@ TEST_F(AiksTest, TransformMultipliesCorrectly) {
// clang-format on
}

TEST_F(AiksTest, SolidStrokesRenderCorrectly) {
TEST_P(AiksTest, SolidStrokesRenderCorrectly) {
// Compare with https://fiddle.skia.org/c/027392122bec8ac2b5d5de00a4b9bbe2
bool first_frame = true;
auto callback = [&](AiksContext& renderer, RenderPass& pass) {
Expand Down Expand Up @@ -578,7 +579,7 @@ TEST_F(AiksTest, SolidStrokesRenderCorrectly) {
ASSERT_TRUE(OpenPlaygroundHere(callback));
}

TEST_F(AiksTest, CoverageOriginShouldBeAccountedForInSubpasses) {
TEST_P(AiksTest, CoverageOriginShouldBeAccountedForInSubpasses) {
auto callback = [](AiksContext& renderer, RenderPass& pass) {
Canvas canvas;
Paint alpha;
Expand Down Expand Up @@ -610,7 +611,7 @@ TEST_F(AiksTest, CoverageOriginShouldBeAccountedForInSubpasses) {
ASSERT_TRUE(OpenPlaygroundHere(callback));
}

TEST_F(AiksTest, DrawRectStrokesRenderCorrectly) {
TEST_P(AiksTest, DrawRectStrokesRenderCorrectly) {
Canvas canvas;
Paint paint;
paint.color = Color::Red();
Expand Down
19 changes: 19 additions & 0 deletions impeller/base/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#pragma once

#include <cstdlib>

#include "flutter/fml/logging.h"

#if defined(__GNUC__) || defined(__clang__)
#define IMPELLER_COMPILER_CLANG 1
#else // defined(__GNUC__) || defined(__clang__)
Expand All @@ -16,3 +20,18 @@
#else // IMPELLER_COMPILER_CLANG
#define IMPELLER_PRINTF_FORMAT(format_number, args_number)
#endif // IMPELLER_COMPILER_CLANG

#define IMPELLER_UNIMPLEMENTED \
impeller::ImpellerUnimplemented(__FUNCTION__, __FILE__, __LINE__);

namespace impeller {

[[noreturn]] inline void ImpellerUnimplemented(const char* method,
const char* file,
int line) {
FML_CHECK(false) << "Unimplemented: " << method << " in " << file << ":"
<< line;
std::abort();
}

} // namespace impeller
13 changes: 7 additions & 6 deletions impeller/display_list/display_list_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,32 @@ namespace impeller {
namespace testing {

using DisplayListTest = DisplayListPlayground;
INSTANTIATE_PLAYGROUND_SUITE(DisplayListTest);

TEST_F(DisplayListTest, CanDrawRect) {
TEST_P(DisplayListTest, CanDrawRect) {
flutter::DisplayListBuilder builder;
builder.setColor(SK_ColorBLUE);
builder.drawRect(SkRect::MakeXYWH(10, 10, 100, 100));
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

TEST_F(DisplayListTest, CanDrawTextBlob) {
TEST_P(DisplayListTest, CanDrawTextBlob) {
flutter::DisplayListBuilder builder;
builder.setColor(SK_ColorBLUE);
builder.drawTextBlob(SkTextBlob::MakeFromString("Hello", CreateTestFont()),
100, 100);
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

TEST_F(DisplayListTest, CanDrawImage) {
TEST_P(DisplayListTest, CanDrawImage) {
auto texture = CreateTextureForFixture("embarcadero.jpg");
flutter::DisplayListBuilder builder;
builder.drawImage(DlImageImpeller::Make(texture), SkPoint::Make(100, 100),
SkSamplingOptions{}, true);
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

TEST_F(DisplayListTest, CanDrawCapsAndJoins) {
TEST_P(DisplayListTest, CanDrawCapsAndJoins) {
flutter::DisplayListBuilder builder;

builder.setStyle(SkPaint::Style::kStroke_Style);
Expand Down Expand Up @@ -87,7 +88,7 @@ TEST_F(DisplayListTest, CanDrawCapsAndJoins) {
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

TEST_F(DisplayListTest, CanDrawArc) {
TEST_P(DisplayListTest, CanDrawArc) {
bool first_frame = true;
auto callback = [&]() {
if (first_frame) {
Expand Down Expand Up @@ -127,7 +128,7 @@ TEST_F(DisplayListTest, CanDrawArc) {
ASSERT_TRUE(OpenPlaygroundHere(callback));
}

TEST_F(DisplayListTest, StrokedPathsDrawCorrectly) {
TEST_P(DisplayListTest, StrokedPathsDrawCorrectly) {
flutter::DisplayListBuilder builder;
builder.setColor(SK_ColorRED);
builder.setStyle(SkPaint::Style::kStroke_Style);
Expand Down
36 changes: 18 additions & 18 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
#include "flutter/fml/macros.h"
#include "fml/logging.h"
#include "impeller/base/validation.h"
#include "impeller/entity/border_mask_blur.frag.h"
#include "impeller/entity/border_mask_blur.vert.h"
#include "impeller/entity/entity.h"
#include "impeller/entity/gaussian_blur.frag.h"
#include "impeller/entity/gaussian_blur.vert.h"
#include "impeller/entity/glyph_atlas.frag.h"
#include "impeller/entity/glyph_atlas.vert.h"
#include "impeller/entity/gradient_fill.frag.h"
#include "impeller/entity/gradient_fill.vert.h"
#include "impeller/entity/solid_fill.frag.h"
#include "impeller/entity/solid_fill.vert.h"
#include "impeller/entity/solid_stroke.frag.h"
#include "impeller/entity/solid_stroke.vert.h"
#include "impeller/entity/texture_blend.frag.h"
#include "impeller/entity/texture_blend.vert.h"
#include "impeller/entity/texture_blend_screen.frag.h"
#include "impeller/entity/texture_blend_screen.vert.h"
#include "impeller/entity/texture_fill.frag.h"
#include "impeller/entity/texture_fill.vert.h"
#include "impeller/entity/mtl/border_mask_blur.frag.h"
#include "impeller/entity/mtl/border_mask_blur.vert.h"
#include "impeller/entity/mtl/gaussian_blur.frag.h"
#include "impeller/entity/mtl/gaussian_blur.vert.h"
#include "impeller/entity/mtl/glyph_atlas.frag.h"
#include "impeller/entity/mtl/glyph_atlas.vert.h"
#include "impeller/entity/mtl/gradient_fill.frag.h"
#include "impeller/entity/mtl/gradient_fill.vert.h"
#include "impeller/entity/mtl/solid_fill.frag.h"
#include "impeller/entity/mtl/solid_fill.vert.h"
#include "impeller/entity/mtl/solid_stroke.frag.h"
#include "impeller/entity/mtl/solid_stroke.vert.h"
#include "impeller/entity/mtl/texture_blend.frag.h"
#include "impeller/entity/mtl/texture_blend.vert.h"
#include "impeller/entity/mtl/texture_blend_screen.frag.h"
#include "impeller/entity/mtl/texture_blend_screen.vert.h"
#include "impeller/entity/mtl/texture_fill.frag.h"
#include "impeller/entity/mtl/texture_fill.vert.h"
#include "impeller/renderer/formats.h"

namespace impeller {
Expand Down
Loading

0 comments on commit 3b1dfc4

Please sign in to comment.