diff --git a/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc index 13d3160eb7806..016ca50c2f4e9 100644 --- a/impeller/aiks/aiks_unittests.cc +++ b/impeller/aiks/aiks_unittests.cc @@ -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); @@ -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); @@ -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(); @@ -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(CreateTextureForFixture("kalimba.jpg")); @@ -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(CreateTextureForFixture("kalimba.jpg")); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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}); @@ -162,7 +163,7 @@ TEST_F(AiksTest, CanRenderDifferenceClips) { ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } -TEST_F(AiksTest, ClipsUseCurrentTransform) { +TEST_P(AiksTest, ClipsUseCurrentTransform) { std::array colors = {Color::White(), Color::Black(), Color::SkyBlue(), Color::Red(), Color::Yellow()}; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -271,7 +272,7 @@ TEST_F(AiksTest, CanPerformSaveLayerWithBounds) { ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } -TEST_F(AiksTest, +TEST_P(AiksTest, CanPerformSaveLayerWithBoundsAndLargerIntermediateIsNotAllocated) { Canvas canvas; @@ -298,7 +299,7 @@ TEST_F(AiksTest, ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } -TEST_F(AiksTest, CanRenderRoundedRectWithNonUniformRadii) { +TEST_P(AiksTest, CanRenderRoundedRectWithNonUniformRadii) { Canvas canvas; Paint paint; @@ -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; @@ -393,7 +394,7 @@ bool RenderTextInCanvas(std::shared_ptr 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!.?", @@ -401,7 +402,7 @@ TEST_F(AiksTest, CanRenderTextFrame) { 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!.?", @@ -409,7 +410,7 @@ TEST_F(AiksTest, CanRenderItalicizedText) { ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } -TEST_F(AiksTest, CanRenderEmojiTextFrame) { +TEST_P(AiksTest, CanRenderEmojiTextFrame) { Canvas canvas; ASSERT_TRUE(RenderTextInCanvas( GetContext(), canvas, @@ -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}); @@ -439,7 +440,7 @@ 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; @@ -447,7 +448,7 @@ TEST_F(AiksTest, CanDrawPaint) { ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } -TEST_F(AiksTest, PaintBlendModeIsRespected) { +TEST_P(AiksTest, PaintBlendModeIsRespected) { Paint paint; Canvas canvas; // Default is kSourceOver. @@ -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()); @@ -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) { @@ -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; @@ -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(); diff --git a/impeller/base/config.h b/impeller/base/config.h index a0750d5db17fe..610661a48db33 100644 --- a/impeller/base/config.h +++ b/impeller/base/config.h @@ -4,6 +4,10 @@ #pragma once +#include + +#include "flutter/fml/logging.h" + #if defined(__GNUC__) || defined(__clang__) #define IMPELLER_COMPILER_CLANG 1 #else // defined(__GNUC__) || defined(__clang__) @@ -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 diff --git a/impeller/display_list/display_list_unittests.cc b/impeller/display_list/display_list_unittests.cc index 13160d39f5002..321832e721393 100644 --- a/impeller/display_list/display_list_unittests.cc +++ b/impeller/display_list/display_list_unittests.cc @@ -18,15 +18,16 @@ 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()), @@ -34,7 +35,7 @@ TEST_F(DisplayListTest, CanDrawTextBlob) { 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), @@ -42,7 +43,7 @@ TEST_F(DisplayListTest, CanDrawImage) { ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); } -TEST_F(DisplayListTest, CanDrawCapsAndJoins) { +TEST_P(DisplayListTest, CanDrawCapsAndJoins) { flutter::DisplayListBuilder builder; builder.setStyle(SkPaint::Style::kStroke_Style); @@ -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) { @@ -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); diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index 9898b217add98..4fc0fa74ad512 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -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 { diff --git a/impeller/entity/contents/solid_stroke_contents.h b/impeller/entity/contents/solid_stroke_contents.h index bde9f332f9b54..e0d3f3abee260 100644 --- a/impeller/entity/contents/solid_stroke_contents.h +++ b/impeller/entity/contents/solid_stroke_contents.h @@ -10,7 +10,7 @@ #include "flutter/fml/macros.h" #include "impeller/entity/contents/contents.h" -#include "impeller/entity/solid_stroke.vert.h" +#include "impeller/entity/mtl/solid_stroke.vert.h" #include "impeller/geometry/color.h" #include "impeller/geometry/path_component.h" #include "impeller/geometry/point.h" diff --git a/impeller/entity/contents/texture_contents.cc b/impeller/entity/contents/texture_contents.cc index 024140093b994..77e0a16d06439 100644 --- a/impeller/entity/contents/texture_contents.cc +++ b/impeller/entity/contents/texture_contents.cc @@ -6,8 +6,8 @@ #include "impeller/entity/contents/content_context.h" #include "impeller/entity/entity.h" -#include "impeller/entity/texture_fill.frag.h" -#include "impeller/entity/texture_fill.vert.h" +#include "impeller/entity/mtl/texture_fill.frag.h" +#include "impeller/entity/mtl/texture_fill.vert.h" #include "impeller/renderer/render_pass.h" #include "impeller/renderer/sampler_library.h" #include "impeller/tessellator/tessellator.h" diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 2978d2dd8018a..7401ddb187b9d 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -24,20 +24,21 @@ namespace impeller { namespace testing { using EntityTest = EntityPlayground; +INSTANTIATE_PLAYGROUND_SUITE(EntityTest); -TEST_F(EntityTest, CanCreateEntity) { +TEST_P(EntityTest, CanCreateEntity) { Entity entity; ASSERT_TRUE(entity.GetTransformation().IsIdentity()); } -TEST_F(EntityTest, CanDrawRect) { +TEST_P(EntityTest, CanDrawRect) { Entity entity; entity.SetPath(PathBuilder{}.AddRect({100, 100, 100, 100}).TakePath()); entity.SetContents(SolidColorContents::Make(Color::Red())); ASSERT_TRUE(OpenPlaygroundHere(entity)); } -TEST_F(EntityTest, ThreeStrokesInOnePath) { +TEST_P(EntityTest, ThreeStrokesInOnePath) { Path path = PathBuilder{} .MoveTo({100, 100}) .LineTo({100, 200}) @@ -56,7 +57,7 @@ TEST_F(EntityTest, ThreeStrokesInOnePath) { ASSERT_TRUE(OpenPlaygroundHere(entity)); } -TEST_F(EntityTest, TriangleInsideASquare) { +TEST_P(EntityTest, TriangleInsideASquare) { auto callback = [&](ContentContext& context, RenderPass& pass) { Point a = IMPELLER_PLAYGROUND_POINT(Point(10, 10), 20, Color::White()); Point b = IMPELLER_PLAYGROUND_POINT(Point(210, 10), 20, Color::White()); @@ -89,7 +90,7 @@ TEST_F(EntityTest, TriangleInsideASquare) { ASSERT_TRUE(OpenPlaygroundHere(callback)); } -TEST_F(EntityTest, StrokeCapAndJoinTest) { +TEST_P(EntityTest, StrokeCapAndJoinTest) { const Point padding(300, 250); const Point margin(140, 180); @@ -224,7 +225,7 @@ TEST_F(EntityTest, StrokeCapAndJoinTest) { ASSERT_TRUE(OpenPlaygroundHere(callback)); } -TEST_F(EntityTest, CubicCurveTest) { +TEST_P(EntityTest, CubicCurveTest) { // Compare with https://fiddle.skia.org/c/b3625f26122c9de7afe7794fcf25ead3 Path path = PathBuilder{} @@ -246,7 +247,7 @@ TEST_F(EntityTest, CubicCurveTest) { ASSERT_TRUE(OpenPlaygroundHere(entity)); } -TEST_F(EntityTest, CubicCurveAndOverlapTest) { +TEST_P(EntityTest, CubicCurveAndOverlapTest) { // Compare with https://fiddle.skia.org/c/7a05a3e186c65a8dfb732f68020aae06 Path path = PathBuilder{} @@ -474,7 +475,7 @@ TEST_F(EntityTest, CubicCurveAndOverlapTest) { ASSERT_TRUE(OpenPlaygroundHere(entity)); } -TEST_F(EntityTest, SolidStrokeContentsSetStrokeCapsAndJoins) { +TEST_P(EntityTest, SolidStrokeContentsSetStrokeCapsAndJoins) { { SolidStrokeContents stroke; // Defaults. @@ -495,7 +496,7 @@ TEST_F(EntityTest, SolidStrokeContentsSetStrokeCapsAndJoins) { } } -TEST_F(EntityTest, SolidStrokeContentsSetMiter) { +TEST_P(EntityTest, SolidStrokeContentsSetMiter) { SolidStrokeContents contents; ASSERT_FLOAT_EQ(contents.GetStrokeMiter(), 4); @@ -506,7 +507,7 @@ TEST_F(EntityTest, SolidStrokeContentsSetMiter) { ASSERT_FLOAT_EQ(contents.GetStrokeMiter(), 8); } -TEST_F(EntityTest, BlendingModeOptions) { +TEST_P(EntityTest, BlendingModeOptions) { std::vector blend_mode_names; std::vector blend_mode_values; { @@ -637,7 +638,7 @@ TEST_F(EntityTest, BlendingModeOptions) { ASSERT_TRUE(OpenPlaygroundHere(callback)); } -TEST_F(EntityTest, BezierCircleScaled) { +TEST_P(EntityTest, BezierCircleScaled) { Entity entity; auto path = PathBuilder{} .MoveTo({97.325, 34.818}) @@ -662,7 +663,7 @@ TEST_F(EntityTest, BezierCircleScaled) { ASSERT_TRUE(OpenPlaygroundHere(entity)); } -TEST_F(EntityTest, Filters) { +TEST_P(EntityTest, Filters) { auto bridge = CreateTextureForFixture("bay_bridge.jpg"); auto boston = CreateTextureForFixture("boston.jpg"); auto kalimba = CreateTextureForFixture("kalimba.jpg"); @@ -688,7 +689,7 @@ TEST_F(EntityTest, Filters) { ASSERT_TRUE(OpenPlaygroundHere(callback)); } -TEST_F(EntityTest, GaussianBlurFilter) { +TEST_P(EntityTest, GaussianBlurFilter) { auto bridge = CreateTextureForFixture("bay_bridge.jpg"); auto boston = CreateTextureForFixture("boston.jpg"); auto kalimba = CreateTextureForFixture("kalimba.jpg"); @@ -792,14 +793,14 @@ TEST_F(EntityTest, GaussianBlurFilter) { ASSERT_TRUE(OpenPlaygroundHere(callback)); } -TEST_F(EntityTest, SetBlendMode) { +TEST_P(EntityTest, SetBlendMode) { Entity entity; ASSERT_EQ(entity.GetBlendMode(), Entity::BlendMode::kSourceOver); entity.SetBlendMode(Entity::BlendMode::kClear); ASSERT_EQ(entity.GetBlendMode(), Entity::BlendMode::kClear); } -TEST_F(EntityTest, ContentsGetBoundsForEmptyPathReturnsNullopt) { +TEST_P(EntityTest, ContentsGetBoundsForEmptyPathReturnsNullopt) { Entity entity; entity.SetContents(std::make_shared()); entity.SetPath({}); @@ -807,7 +808,7 @@ TEST_F(EntityTest, ContentsGetBoundsForEmptyPathReturnsNullopt) { ASSERT_FALSE(entity.GetPathCoverage().has_value()); } -TEST_F(EntityTest, SolidStrokeCoverageIsCorrect) { +TEST_P(EntityTest, SolidStrokeCoverageIsCorrect) { { Entity entity; auto contents = std::make_unique(); diff --git a/impeller/playground/BUILD.gn b/impeller/playground/BUILD.gn index 5f9618e98db35..dc4d452ecfb59 100644 --- a/impeller/playground/BUILD.gn +++ b/impeller/playground/BUILD.gn @@ -9,12 +9,28 @@ impeller_component("playground") { testonly = true sources = [ + "playground.cc", "playground.h", - "playground.mm", + "playground_impl.cc", + "playground_impl.h", "widgets.cc", "widgets.h", ] + if (impeller_enable_metal) { + sources += [ + "backend/metal/playground_impl_mtl.h", + "backend/metal/playground_impl_mtl.mm", + ] + } + + if (impeller_enable_opengles) { + sources += [ + "backend/gles/playground_impl_gles.cc", + "backend/gles/playground_impl_gles.h", + ] + } + public_deps = [ "../entity:entity_shaders", "../fixtures:shader_fixtures", diff --git a/impeller/playground/backend/gles/playground_impl_gles.cc b/impeller/playground/backend/gles/playground_impl_gles.cc new file mode 100644 index 0000000000000..b5a47e2bc514b --- /dev/null +++ b/impeller/playground/backend/gles/playground_impl_gles.cc @@ -0,0 +1,37 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/playground/backend/gles/playground_impl_gles.h" +#include "impeller/renderer/backend/gles/context_gles.h" + +namespace impeller { + +PlaygroundImplGLES::PlaygroundImplGLES() = default; + +PlaygroundImplGLES::~PlaygroundImplGLES() = default; + +// |PlaygroundImpl| +std::shared_ptr PlaygroundImplGLES::CreateContext() const { + return std::make_shared(); +} + +// |PlaygroundImpl| +bool PlaygroundImplGLES::SetupWindow(WindowHandle handle, + std::shared_ptr context) { + return true; +} + +// |PlaygroundImpl| +bool PlaygroundImplGLES::TeardownWindow(WindowHandle handle, + std::shared_ptr context) { + return true; +} + +// |PlaygroundImpl| +std::unique_ptr PlaygroundImplGLES::AcquireSurfaceFrame( + std::shared_ptr context) { + return nullptr; +} + +} // namespace impeller diff --git a/impeller/playground/backend/gles/playground_impl_gles.h b/impeller/playground/backend/gles/playground_impl_gles.h new file mode 100644 index 0000000000000..246d099ea188b --- /dev/null +++ b/impeller/playground/backend/gles/playground_impl_gles.h @@ -0,0 +1,37 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include "flutter/fml/macros.h" +#include "impeller/playground/playground_impl.h" + +namespace impeller { + +class PlaygroundImplGLES final : public PlaygroundImpl { + public: + PlaygroundImplGLES(); + + ~PlaygroundImplGLES(); + + private: + // |PlaygroundImpl| + std::shared_ptr CreateContext() const override; + + // |PlaygroundImpl| + bool SetupWindow(WindowHandle handle, + std::shared_ptr context) override; + + // |PlaygroundImpl| + bool TeardownWindow(WindowHandle handle, + std::shared_ptr context) override; + + // |PlaygroundImpl| + std::unique_ptr AcquireSurfaceFrame( + std::shared_ptr context) override; + + FML_DISALLOW_COPY_AND_ASSIGN(PlaygroundImplGLES); +}; + +} // namespace impeller diff --git a/impeller/playground/backend/metal/playground_impl_mtl.h b/impeller/playground/backend/metal/playground_impl_mtl.h new file mode 100644 index 0000000000000..75f9ef5ba62de --- /dev/null +++ b/impeller/playground/backend/metal/playground_impl_mtl.h @@ -0,0 +1,45 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include + +#include "flutter/fml/macros.h" +#include "impeller/playground/playground_impl.h" + +namespace impeller { + +class PlaygroundImplMTL final : public PlaygroundImpl { + public: + PlaygroundImplMTL(); + + ~PlaygroundImplMTL(); + + private: + struct Data; + + WindowHandle handle_ = nullptr; + // To ensure that ObjC stuff doesn't leak into C++ TUs. + std::unique_ptr data_; + + // |PlaygroundImpl| + std::shared_ptr CreateContext() const override; + + // |PlaygroundImpl| + bool SetupWindow(WindowHandle handle, + std::shared_ptr context) override; + + // |PlaygroundImpl| + bool TeardownWindow(WindowHandle handle, + std::shared_ptr context) override; + + // |PlaygroundImpl| + std::unique_ptr AcquireSurfaceFrame( + std::shared_ptr context) override; + + FML_DISALLOW_COPY_AND_ASSIGN(PlaygroundImplMTL); +}; + +} // namespace impeller diff --git a/impeller/playground/backend/metal/playground_impl_mtl.mm b/impeller/playground/backend/metal/playground_impl_mtl.mm new file mode 100644 index 0000000000000..f791df7f16c95 --- /dev/null +++ b/impeller/playground/backend/metal/playground_impl_mtl.mm @@ -0,0 +1,95 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/playground/backend/metal/playground_impl_mtl.h" + +#define GLFW_INCLUDE_NONE +#import "third_party/glfw/include/GLFW/glfw3.h" + +#define GLFW_EXPOSE_NATIVE_COCOA +#import "third_party/glfw/include/GLFW/glfw3native.h" + +#include +#include + +#include "flutter/fml/mapping.h" +#include "impeller/entity/mtl/entity_shaders.h" +#include "impeller/fixtures/mtl/shader_fixtures.h" +#include "impeller/playground/imgui/mtl/imgui_shaders.h" +#include "impeller/renderer/backend/metal/context_mtl.h" +#include "impeller/renderer/backend/metal/formats_mtl.h" +#include "impeller/renderer/backend/metal/surface_mtl.h" +#include "impeller/renderer/backend/metal/texture_mtl.h" + +namespace impeller { + +struct PlaygroundImplMTL::Data { + CAMetalLayer* metal_layer = nil; +}; + +static std::vector> +ShaderLibraryMappingsForPlayground() { + return { + std::make_shared(impeller_entity_shaders_data, + impeller_entity_shaders_length), + std::make_shared(impeller_shader_fixtures_data, + impeller_shader_fixtures_length), + std::make_shared(impeller_imgui_shaders_data, + impeller_imgui_shaders_length), + + }; +} + +PlaygroundImplMTL::PlaygroundImplMTL() : data_(std::make_unique()) {} + +PlaygroundImplMTL::~PlaygroundImplMTL() = default; + +std::shared_ptr PlaygroundImplMTL::CreateContext() const { + return ContextMTL::Create(ShaderLibraryMappingsForPlayground(), + "Playground Library"); +} + +bool PlaygroundImplMTL::SetupWindow(WindowHandle handle, + std::shared_ptr context) { + if (handle_ != nullptr) { + return false; + } + + handle_ = handle; + + NSWindow* cocoa_window = + ::glfwGetCocoaWindow(reinterpret_cast(handle_)); + data_->metal_layer = [CAMetalLayer layer]; + data_->metal_layer.device = ContextMTL::Cast(*context).GetMTLDevice(); + // This pixel format is one of the documented supported formats. + data_->metal_layer.pixelFormat = ToMTLPixelFormat(PixelFormat::kDefaultColor); + cocoa_window.contentView.layer = data_->metal_layer; + cocoa_window.contentView.wantsLayer = YES; + return true; +} + +bool PlaygroundImplMTL::TeardownWindow(WindowHandle handle, + std::shared_ptr context) { + if (handle_ != handle) { + return false; + } + handle_ = nullptr; + data_->metal_layer = nil; + return true; +} + +std::unique_ptr PlaygroundImplMTL::AcquireSurfaceFrame( + std::shared_ptr context) { + if (!data_->metal_layer) { + return nullptr; + } + + const auto layer_size = data_->metal_layer.bounds.size; + const auto layer_scale = data_->metal_layer.contentsScale; + data_->metal_layer.drawableSize = CGSizeMake(layer_size.width * layer_scale, + layer_size.height * layer_scale); + return SurfaceMTL::WrapCurrentMetalLayerDrawable(context, data_->metal_layer); +} + +} // namespace impeller diff --git a/impeller/playground/imgui/imgui_impl_impeller.cc b/impeller/playground/imgui/imgui_impl_impeller.cc index b42696c4dc6e4..5703e2be59a2c 100644 --- a/impeller/playground/imgui/imgui_impl_impeller.cc +++ b/impeller/playground/imgui/imgui_impl_impeller.cc @@ -9,8 +9,8 @@ #include #include -#include "imgui_raster.frag.h" -#include "imgui_raster.vert.h" +#include "impeller/playground/imgui/mtl/imgui_raster.frag.h" +#include "impeller/playground/imgui/mtl/imgui_raster.vert.h" #include "third_party/imgui/imgui.h" #include "impeller/geometry/matrix.h" diff --git a/impeller/playground/playground.mm b/impeller/playground/playground.cc similarity index 77% rename from impeller/playground/playground.mm rename to impeller/playground/playground.cc index c8a157af957db..e843a6ee5c64b 100644 --- a/impeller/playground/playground.mm +++ b/impeller/playground/playground.cc @@ -4,20 +4,17 @@ #include +#define GLFW_INCLUDE_NONE +#import "third_party/glfw/include/GLFW/glfw3.h" + #include "flutter/fml/paths.h" #include "flutter/testing/testing.h" #include "impeller/base/validation.h" -#include "impeller/entity/entity_shaders.h" -#include "impeller/fixtures/shader_fixtures.h" #include "impeller/image/compressed_image.h" #include "impeller/playground/imgui/imgui_impl_impeller.h" -#include "impeller/playground/imgui/imgui_shaders.h" #include "impeller/playground/playground.h" +#include "impeller/playground/playground_impl.h" #include "impeller/renderer/allocator.h" -#include "impeller/renderer/backend/metal/context_mtl.h" -#include "impeller/renderer/backend/metal/formats_mtl.h" -#include "impeller/renderer/backend/metal/surface_mtl.h" -#include "impeller/renderer/backend/metal/texture_mtl.h" #include "impeller/renderer/context.h" #include "impeller/renderer/formats.h" #include "impeller/renderer/render_pass.h" @@ -25,37 +22,35 @@ #include "third_party/imgui/backends/imgui_impl_glfw.h" #include "third_party/imgui/imgui.h" -#define GLFW_INCLUDE_NONE -#import "third_party/glfw/include/GLFW/glfw3.h" -#define GLFW_EXPOSE_NATIVE_COCOA -#import "third_party/glfw/include/GLFW/glfw3native.h" - -#include -#include - namespace impeller { -static std::vector> -ShaderLibraryMappingsForPlayground() { - return { - std::make_shared(impeller_entity_shaders_data, - impeller_entity_shaders_length), - std::make_shared(impeller_shader_fixtures_data, - impeller_shader_fixtures_length), - std::make_shared(impeller_imgui_shaders_data, - impeller_imgui_shaders_length), - - }; +std::string PlaygroundBackendToString(PlaygroundBackend backend) { + switch (backend) { + case PlaygroundBackend::kMetal: + return "Metal"; + case PlaygroundBackend::kOpenGLES: + return "OpenGLES"; + } + FML_UNREACHABLE(); } Playground::Playground() - : renderer_(ContextMTL::Create(ShaderLibraryMappingsForPlayground(), - "Playground Library")) {} + : impl_(PlaygroundImpl::Create(GetParam())), + renderer_(impl_->CreateContext()), + is_valid_(Playground::is_enabled() && renderer_.IsValid()) {} Playground::~Playground() = default; +bool Playground::IsValid() const { + return is_valid_; +} + +PlaygroundBackend Playground::GetBackend() const { + return GetParam(); +} + std::shared_ptr Playground::GetContext() const { - return renderer_.IsValid() ? renderer_.GetContext() : nullptr; + return IsValid() ? renderer_.GetContext() : nullptr; } static void PlaygroundKeyCallback(GLFWwindow* window, @@ -92,6 +87,10 @@ static void PlaygroundKeyCallback(GLFWwindow* window, return true; } + if (!IsValid()) { + return false; + } + if (!render_callback) { return true; } @@ -169,13 +168,9 @@ static void PlaygroundKeyCallback(GLFWwindow* window, fml::ScopedCleanupClosure shutdown_imgui_impeller( []() { ImGui_ImplImpeller_Shutdown(); }); - NSWindow* cocoa_window = ::glfwGetCocoaWindow(window); - CAMetalLayer* layer = [CAMetalLayer layer]; - layer.device = ContextMTL::Cast(*renderer_.GetContext()).GetMTLDevice(); - // This pixel format is one of the documented supported formats. - layer.pixelFormat = ToMTLPixelFormat(PixelFormat::kDefaultColor); - cocoa_window.contentView.layer = layer; - cocoa_window.contentView.wantsLayer = YES; + if (!impl_->SetupWindow(window, renderer_.GetContext())) { + return false; + } while (true) { ::glfwWaitEventsTimeout(1.0 / 30.0); @@ -186,11 +181,6 @@ static void PlaygroundKeyCallback(GLFWwindow* window, ImGui_ImplGlfw_NewFrame(); - const auto layer_size = layer.bounds.size; - const auto layer_scale = layer.contentsScale; - layer.drawableSize = CGSizeMake(layer_size.width * layer_scale, - layer_size.height * layer_scale); - Renderer::RenderCallback wrapped_callback = [render_callback](auto& pass) { pass.SetLabel("Playground Main Render Pass"); @@ -201,19 +191,26 @@ static void PlaygroundKeyCallback(GLFWwindow* window, return result; }; - if (!renderer_.Render(SurfaceMTL::WrapCurrentMetalLayerDrawable( - renderer_.GetContext(), layer), + if (!renderer_.Render(impl_->AcquireSurfaceFrame(renderer_.GetContext()), wrapped_callback)) { VALIDATION_LOG << "Could not render into the surface."; return false; } } + if (!impl_->TeardownWindow(window, renderer_.GetContext())) { + return false; + } + return true; } std::shared_ptr Playground::CreateTextureForFixture( const char* fixture_name) const { + if (!IsValid()) { + return nullptr; + } + auto compressed_image = CompressedImage::Create( flutter::testing::OpenFixtureAsMapping(fixture_name)); if (!compressed_image) { diff --git a/impeller/playground/playground.h b/impeller/playground/playground.h index b1779a624d956..dc382b0a456c4 100644 --- a/impeller/playground/playground.h +++ b/impeller/playground/playground.h @@ -13,7 +13,16 @@ namespace impeller { -class Playground : public ::testing::Test { +class PlaygroundImpl; + +enum class PlaygroundBackend { + kMetal, + kOpenGLES, +}; + +std::string PlaygroundBackendToString(PlaygroundBackend backend); + +class Playground : public ::testing::TestWithParam { public: Playground(); @@ -21,6 +30,10 @@ class Playground : public ::testing::Test { static constexpr bool is_enabled() { return is_enabled_; } + PlaygroundBackend GetBackend() const; + + bool IsValid() const; + Point GetCursorPosition() const; ISize GetWindowSize() const; @@ -39,9 +52,11 @@ class Playground : public ::testing::Test { static const bool is_enabled_ = false; #endif // IMPELLER_ENABLE_PLAYGROUND + std::unique_ptr impl_; Renderer renderer_; Point cursor_position_; ISize window_size_ = ISize{1024, 768}; + bool is_valid_ = false; void SetCursorPosition(Point pos); @@ -50,4 +65,11 @@ class Playground : public ::testing::Test { FML_DISALLOW_COPY_AND_ASSIGN(Playground); }; +#define INSTANTIATE_PLAYGROUND_SUITE(playground) \ + INSTANTIATE_TEST_SUITE_P( \ + Play, playground, ::testing::Values(PlaygroundBackend::kMetal), \ + [](const ::testing::TestParamInfo& info) { \ + return PlaygroundBackendToString(info.param); \ + }); + } // namespace impeller diff --git a/impeller/playground/playground_impl.cc b/impeller/playground/playground_impl.cc new file mode 100644 index 0000000000000..276b0f9e6cb65 --- /dev/null +++ b/impeller/playground/playground_impl.cc @@ -0,0 +1,27 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/playground/playground_impl.h" + +#include "impeller/playground/backend/gles/playground_impl_gles.h" +#include "impeller/playground/backend/metal/playground_impl_mtl.h" + +namespace impeller { + +std::unique_ptr PlaygroundImpl::Create( + PlaygroundBackend backend) { + switch (backend) { + case PlaygroundBackend::kMetal: + return std::make_unique(); + case PlaygroundBackend::kOpenGLES: + return std::make_unique(); + } + FML_UNREACHABLE(); +} + +PlaygroundImpl::PlaygroundImpl() = default; + +PlaygroundImpl::~PlaygroundImpl() = default; + +} // namespace impeller diff --git a/impeller/playground/playground_impl.h b/impeller/playground/playground_impl.h new file mode 100644 index 0000000000000..c28376e3fe804 --- /dev/null +++ b/impeller/playground/playground_impl.h @@ -0,0 +1,42 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include + +#include "flutter/fml/macros.h" +#include "impeller/playground/playground.h" +#include "impeller/renderer/context.h" +#include "impeller/renderer/surface.h" + +namespace impeller { + +class PlaygroundImpl { + public: + static std::unique_ptr Create(PlaygroundBackend backend); + + virtual ~PlaygroundImpl(); + + virtual std::shared_ptr CreateContext() const = 0; + + using WindowHandle = void*; + + virtual bool SetupWindow(WindowHandle handle, + std::shared_ptr context) = 0; + + virtual bool TeardownWindow(WindowHandle handle, + std::shared_ptr context) = 0; + + virtual std::unique_ptr AcquireSurfaceFrame( + std::shared_ptr context) = 0; + + protected: + PlaygroundImpl(); + + private: + FML_DISALLOW_COPY_AND_ASSIGN(PlaygroundImpl); +}; + +} // namespace impeller diff --git a/impeller/renderer/BUILD.gn b/impeller/renderer/BUILD.gn index 49cb4d6d4aa7d..1c0f72794a4fa 100644 --- a/impeller/renderer/BUILD.gn +++ b/impeller/renderer/BUILD.gn @@ -5,101 +5,142 @@ import("//flutter/impeller/tools/impeller.gni") impeller_component("renderer") { - metal_backend_sources = [ - "backend/metal/allocator_mtl.h", - "backend/metal/allocator_mtl.mm", - "backend/metal/command_buffer_mtl.h", - "backend/metal/command_buffer_mtl.mm", - "backend/metal/context_mtl.h", - "backend/metal/context_mtl.mm", - "backend/metal/device_buffer_mtl.h", - "backend/metal/device_buffer_mtl.mm", - "backend/metal/formats_mtl.h", - "backend/metal/formats_mtl.mm", - "backend/metal/pipeline_library_mtl.h", - "backend/metal/pipeline_library_mtl.mm", - "backend/metal/pipeline_mtl.h", - "backend/metal/pipeline_mtl.mm", - "backend/metal/render_pass_mtl.h", - "backend/metal/render_pass_mtl.mm", - "backend/metal/sampler_library_mtl.h", - "backend/metal/sampler_library_mtl.mm", - "backend/metal/sampler_mtl.h", - "backend/metal/sampler_mtl.mm", - "backend/metal/shader_function_mtl.h", - "backend/metal/shader_function_mtl.mm", - "backend/metal/shader_library_mtl.h", - "backend/metal/shader_library_mtl.mm", - "backend/metal/surface_mtl.h", - "backend/metal/surface_mtl.mm", - "backend/metal/texture_mtl.h", - "backend/metal/texture_mtl.mm", - "backend/metal/vertex_descriptor_mtl.h", - "backend/metal/vertex_descriptor_mtl.mm", + sources = [ + "allocator.cc", + "allocator.h", + "buffer.cc", + "buffer.h", + "buffer_view.cc", + "buffer_view.h", + "command.cc", + "command.h", + "command_buffer.cc", + "command_buffer.h", + "context.cc", + "context.h", + "device_buffer.cc", + "device_buffer.h", + "formats.cc", + "formats.h", + "host_buffer.cc", + "host_buffer.h", + "pipeline.cc", + "pipeline.h", + "pipeline_builder.cc", + "pipeline_builder.h", + "pipeline_descriptor.cc", + "pipeline_descriptor.h", + "pipeline_library.cc", + "pipeline_library.h", + "platform.cc", + "platform.h", + "range.cc", + "range.h", + "render_pass.cc", + "render_pass.h", + "render_target.cc", + "render_target.h", + "renderer.cc", + "renderer.h", + "sampler.cc", + "sampler.h", + "sampler_descriptor.cc", + "sampler_descriptor.h", + "sampler_library.cc", + "sampler_library.h", + "shader_function.cc", + "shader_function.h", + "shader_library.cc", + "shader_library.h", + "shader_types.cc", + "shader_types.h", + "surface.cc", + "surface.h", + "texture.cc", + "texture.h", + "texture_descriptor.cc", + "texture_descriptor.h", + "vertex_buffer.cc", + "vertex_buffer.h", + "vertex_buffer_builder.cc", + "vertex_buffer_builder.h", + "vertex_descriptor.cc", + "vertex_descriptor.h", ] - sources = [ - "allocator.h", - "allocator.cc", - "buffer.h", - "buffer.cc", - "buffer_view.h", - "buffer_view.cc", - "command.h", - "command.cc", - "command_buffer.h", - "command_buffer.cc", - "context.h", - "context.cc", - "device_buffer.h", - "device_buffer.cc", - "formats.cc", - "formats.h", - "host_buffer.h", - "host_buffer.cc", - "pipeline.h", - "pipeline.cc", - "pipeline_builder.h", - "pipeline_builder.cc", - "pipeline_descriptor.h", - "pipeline_descriptor.cc", - "pipeline_library.h", - "pipeline_library.cc", - "platform.h", - "platform.cc", - "range.cc", - "range.h", - "render_pass.h", - "render_pass.cc", - "render_target.h", - "render_target.cc", - "renderer.h", - "renderer.cc", - "sampler.h", - "sampler.cc", - "sampler_descriptor.h", - "sampler_descriptor.cc", - "sampler_library.h", - "sampler_library.cc", - "shader_function.h", - "shader_function.cc", - "shader_library.h", - "shader_library.cc", - "shader_types.cc", - "shader_types.h", - "surface.h", - "surface.cc", - "texture.h", - "texture.cc", - "texture_descriptor.h", - "texture_descriptor.cc", - "vertex_buffer.h", - "vertex_buffer.cc", - "vertex_buffer_builder.h", - "vertex_buffer_builder.cc", - "vertex_descriptor.h", - "vertex_descriptor.cc", - ] + metal_backend_sources + if (impeller_enable_metal) { + sources += [ + "backend/metal/allocator_mtl.h", + "backend/metal/allocator_mtl.mm", + "backend/metal/command_buffer_mtl.h", + "backend/metal/command_buffer_mtl.mm", + "backend/metal/context_mtl.h", + "backend/metal/context_mtl.mm", + "backend/metal/device_buffer_mtl.h", + "backend/metal/device_buffer_mtl.mm", + "backend/metal/formats_mtl.h", + "backend/metal/formats_mtl.mm", + "backend/metal/pipeline_library_mtl.h", + "backend/metal/pipeline_library_mtl.mm", + "backend/metal/pipeline_mtl.h", + "backend/metal/pipeline_mtl.mm", + "backend/metal/render_pass_mtl.h", + "backend/metal/render_pass_mtl.mm", + "backend/metal/sampler_library_mtl.h", + "backend/metal/sampler_library_mtl.mm", + "backend/metal/sampler_mtl.h", + "backend/metal/sampler_mtl.mm", + "backend/metal/shader_function_mtl.h", + "backend/metal/shader_function_mtl.mm", + "backend/metal/shader_library_mtl.h", + "backend/metal/shader_library_mtl.mm", + "backend/metal/surface_mtl.h", + "backend/metal/surface_mtl.mm", + "backend/metal/texture_mtl.h", + "backend/metal/texture_mtl.mm", + "backend/metal/vertex_descriptor_mtl.h", + "backend/metal/vertex_descriptor_mtl.mm", + ] + } + + if (impeller_enable_opengles) { + sources += [ + "backend/gles/allocator_gles.cc", + "backend/gles/allocator_gles.h", + "backend/gles/command_buffer_gles.cc", + "backend/gles/command_buffer_gles.h", + "backend/gles/context_gles.cc", + "backend/gles/context_gles.h", + "backend/gles/device_buffer_gles.cc", + "backend/gles/device_buffer_gles.h", + "backend/gles/formats_gles.cc", + "backend/gles/formats_gles.h", + "backend/gles/pipeline_gles.cc", + "backend/gles/pipeline_gles.h", + "backend/gles/pipeline_library_gles.cc", + "backend/gles/pipeline_library_gles.h", + "backend/gles/proc_table_gles.cc", + "backend/gles/proc_table_gles.h", + "backend/gles/reactor_gles.cc", + "backend/gles/reactor_gles.h", + "backend/gles/render_pass_gles.cc", + "backend/gles/render_pass_gles.h", + "backend/gles/sampler_gles.cc", + "backend/gles/sampler_gles.h", + "backend/gles/sampler_library_gles.cc", + "backend/gles/sampler_library_gles.h", + "backend/gles/shader_function_gles.cc", + "backend/gles/shader_function_gles.h", + "backend/gles/shader_library_gles.cc", + "backend/gles/shader_library_gles.h", + "backend/gles/surface_gles.cc", + "backend/gles/surface_gles.h", + "backend/gles/texture_gles.cc", + "backend/gles/texture_gles.h", + "backend/gles/vertex_descriptor_gles.cc", + "backend/gles/vertex_descriptor_gles.h", + ] + } public_deps = [ "../base", @@ -109,8 +150,11 @@ impeller_component("renderer") { ] deps = [ "//flutter/fml" ] + frameworks = [] - frameworks = [ "Metal.framework" ] + if (impeller_enable_metal) { + frameworks = [ "Metal.framework" ] + } } source_set("renderer_unittests") { diff --git a/impeller/renderer/backend/gles/allocator_gles.cc b/impeller/renderer/backend/gles/allocator_gles.cc new file mode 100644 index 0000000000000..d4f2c4e726ce8 --- /dev/null +++ b/impeller/renderer/backend/gles/allocator_gles.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/allocator_gles.h" + +namespace impeller { + +// + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/allocator_gles.h b/impeller/renderer/backend/gles/allocator_gles.h new file mode 100644 index 0000000000000..9a4cdf09172e8 --- /dev/null +++ b/impeller/renderer/backend/gles/allocator_gles.h @@ -0,0 +1,45 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include "flutter/fml/macros.h" +#include "impeller/renderer/allocator.h" + +namespace impeller { + +class AllocatorGLES final : public Allocator { + public: + // |Allocator| + ~AllocatorGLES() override; + + private: + friend class ContextGLES; + + AllocatorGLES(); + + // |Allocator| + bool IsValid() const; + + // |Allocator| + std::shared_ptr CreateBuffer(StorageMode mode, + size_t length) override; + + // |Allocator| + std::shared_ptr CreateTexture( + StorageMode mode, + const TextureDescriptor& desc) override; + + // |Allocator| + std::shared_ptr CreateBufferWithCopy(const uint8_t* buffer, + size_t length) override; + + // |Allocator| + std::shared_ptr CreateBufferWithCopy( + const fml::Mapping& mapping) override; + + FML_DISALLOW_COPY_AND_ASSIGN(AllocatorGLES); +}; + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/command_buffer_gles.cc b/impeller/renderer/backend/gles/command_buffer_gles.cc new file mode 100644 index 0000000000000..c0c6fc694ac7c --- /dev/null +++ b/impeller/renderer/backend/gles/command_buffer_gles.cc @@ -0,0 +1,39 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/command_buffer_gles.h" + +#include "impeller/base/config.h" + +namespace impeller { + +CommandBufferGLES::CommandBufferGLES() = default; + +CommandBufferGLES::~CommandBufferGLES() = default; + +// |CommandBuffer| +void CommandBufferGLES::SetLabel(const std::string& label) const {} + +// |CommandBuffer| +bool CommandBufferGLES::IsValid() const { + IMPELLER_UNIMPLEMENTED; +} + +// |CommandBuffer| +bool CommandBufferGLES::SubmitCommands(CompletionCallback callback) { + IMPELLER_UNIMPLEMENTED; +} + +// |CommandBuffer| +void CommandBufferGLES::ReserveSpotInQueue() { + IMPELLER_UNIMPLEMENTED; +} + +// |CommandBuffer| +std::shared_ptr CommandBufferGLES::CreateRenderPass( + RenderTarget target) const { + IMPELLER_UNIMPLEMENTED; +} + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/command_buffer_gles.h b/impeller/renderer/backend/gles/command_buffer_gles.h new file mode 100644 index 0000000000000..6819f0f50b5b9 --- /dev/null +++ b/impeller/renderer/backend/gles/command_buffer_gles.h @@ -0,0 +1,42 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include "flutter/fml/macros.h" +#include "impeller/renderer/command_buffer.h" +#include "impeller/renderer/render_target.h" + +namespace impeller { + +class CommandBufferGLES final : public CommandBuffer { + public: + // |CommandBuffer| + ~CommandBufferGLES() override; + + private: + friend class ContextGLES; + + CommandBufferGLES(); + + // |CommandBuffer| + void SetLabel(const std::string& label) const override; + + // |CommandBuffer| + bool IsValid() const override; + + // |CommandBuffer| + bool SubmitCommands(CompletionCallback callback) override; + + // |CommandBuffer| + void ReserveSpotInQueue() override; + + // |CommandBuffer| + std::shared_ptr CreateRenderPass( + RenderTarget target) const override; + + FML_DISALLOW_COPY_AND_ASSIGN(CommandBufferGLES); +}; + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/context_gles.cc b/impeller/renderer/backend/gles/context_gles.cc new file mode 100644 index 0000000000000..efb762ddacc6f --- /dev/null +++ b/impeller/renderer/backend/gles/context_gles.cc @@ -0,0 +1,64 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/context_gles.h" + +#include "impeller/base/config.h" +#include "impeller/base/validation.h" + +namespace impeller { + +ContextGLES::ContextGLES() { + auto reactor = std::make_shared(); + if (!reactor->IsValid()) { + VALIDATION_LOG << "Could not create valid reactor."; + return; + } + + is_valid_ = true; +} + +ContextGLES::~ContextGLES() = default; + +bool ContextGLES::IsValid() const { + return is_valid_; +} + +std::shared_ptr ContextGLES::GetPermanentsAllocator() const { + IMPELLER_UNIMPLEMENTED; + return permanents_allocator_; +} + +std::shared_ptr ContextGLES::GetTransientsAllocator() const { + IMPELLER_UNIMPLEMENTED; + return transients_allocator_; +} + +std::shared_ptr ContextGLES::GetShaderLibrary() const { + IMPELLER_UNIMPLEMENTED; + return shader_library_; +} + +std::shared_ptr ContextGLES::GetSamplerLibrary() const { + IMPELLER_UNIMPLEMENTED; + return sampler_library_; +} + +std::shared_ptr ContextGLES::GetPipelineLibrary() const { + IMPELLER_UNIMPLEMENTED; + return pipeline_library_; +} + +std::shared_ptr ContextGLES::CreateRenderCommandBuffer() const { + IMPELLER_UNIMPLEMENTED; + return std::shared_ptr(new CommandBufferGLES()); +} + +std::shared_ptr ContextGLES::CreateTransferCommandBuffer() + const { + IMPELLER_UNIMPLEMENTED; + return std::shared_ptr(new CommandBufferGLES()); +} + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/context_gles.h b/impeller/renderer/backend/gles/context_gles.h new file mode 100644 index 0000000000000..15e090752c59c --- /dev/null +++ b/impeller/renderer/backend/gles/context_gles.h @@ -0,0 +1,62 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include "flutter/fml/macros.h" +#include "impeller/base/backend_cast.h" +#include "impeller/renderer/backend/gles/allocator_gles.h" +#include "impeller/renderer/backend/gles/command_buffer_gles.h" +#include "impeller/renderer/backend/gles/pipeline_library_gles.h" +#include "impeller/renderer/backend/gles/reactor_gles.h" +#include "impeller/renderer/backend/gles/shader_library_gles.h" +#include "impeller/renderer/context.h" + +namespace impeller { + +class ContextGLES final : public Context, + public BackendCast { + public: + ContextGLES(); + + // |Context| + ~ContextGLES() override; + + private: + std::shared_ptr reactor_; + std::shared_ptr shader_library_; + std::shared_ptr pipeline_library_; + std::shared_ptr sampler_library_; + std::shared_ptr permanents_allocator_; + std::shared_ptr transients_allocator_; + bool is_valid_ = false; + + // |Context| + bool IsValid() const override; + + // |Context| + std::shared_ptr GetPermanentsAllocator() const override; + + // |Context| + std::shared_ptr GetTransientsAllocator() const override; + + // |Context| + std::shared_ptr GetShaderLibrary() const override; + + // |Context| + std::shared_ptr GetSamplerLibrary() const override; + + // |Context| + std::shared_ptr GetPipelineLibrary() const override; + + // |Context| + std::shared_ptr CreateRenderCommandBuffer() const override; + + // |Context| + std::shared_ptr CreateTransferCommandBuffer() const override; + + FML_DISALLOW_COPY_AND_ASSIGN(ContextGLES); +}; + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/device_buffer_gles.cc b/impeller/renderer/backend/gles/device_buffer_gles.cc new file mode 100644 index 0000000000000..1a4392a71b757 --- /dev/null +++ b/impeller/renderer/backend/gles/device_buffer_gles.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/device_buffer_gles.h" + +namespace impeller { + +// + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/device_buffer_gles.h b/impeller/renderer/backend/gles/device_buffer_gles.h new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/impeller/renderer/backend/gles/formats_gles.cc b/impeller/renderer/backend/gles/formats_gles.cc new file mode 100644 index 0000000000000..7d5f3b832d946 --- /dev/null +++ b/impeller/renderer/backend/gles/formats_gles.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/formats_gles.h" + +namespace impeller { + +// + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/formats_gles.h b/impeller/renderer/backend/gles/formats_gles.h new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/impeller/renderer/backend/gles/pipeline_gles.cc b/impeller/renderer/backend/gles/pipeline_gles.cc new file mode 100644 index 0000000000000..3148ec1b176a9 --- /dev/null +++ b/impeller/renderer/backend/gles/pipeline_gles.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/pipeline_gles.h" + +namespace impeller { + +// + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/pipeline_gles.h b/impeller/renderer/backend/gles/pipeline_gles.h new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/impeller/renderer/backend/gles/pipeline_library_gles.cc b/impeller/renderer/backend/gles/pipeline_library_gles.cc new file mode 100644 index 0000000000000..270a77f16bfff --- /dev/null +++ b/impeller/renderer/backend/gles/pipeline_library_gles.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/pipeline_library_gles.h" + +namespace impeller { + +// + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/pipeline_library_gles.h b/impeller/renderer/backend/gles/pipeline_library_gles.h new file mode 100644 index 0000000000000..a608e19eb85a0 --- /dev/null +++ b/impeller/renderer/backend/gles/pipeline_library_gles.h @@ -0,0 +1,30 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include "flutter/fml/macros.h" +#include "impeller/renderer/pipeline_library.h" + +namespace impeller { + +class ContextGLES; + +class PipelineLibraryGLES final : public PipelineLibrary { + public: + // |PipelineLibrary| + ~PipelineLibraryGLES() override; + + private: + friend ContextGLES; + + PipelineLibraryGLES(); + + // |PipelineLibrary| + PipelineFuture GetRenderPipeline(PipelineDescriptor descriptor) override; + + FML_DISALLOW_COPY_AND_ASSIGN(PipelineLibraryGLES); +}; + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/proc_table_gles.cc b/impeller/renderer/backend/gles/proc_table_gles.cc new file mode 100644 index 0000000000000..643bc0ecc2d68 --- /dev/null +++ b/impeller/renderer/backend/gles/proc_table_gles.cc @@ -0,0 +1,17 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/proc_table_gles.h" + +namespace impeller { + +ProcTableGLES::ProcTableGLES() : is_valid_(true) {} + +ProcTableGLES::~ProcTableGLES() = default; + +bool ProcTableGLES::IsValid() const { + return is_valid_; +} + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/proc_table_gles.h b/impeller/renderer/backend/gles/proc_table_gles.h new file mode 100644 index 0000000000000..cabb5d10c43ca --- /dev/null +++ b/impeller/renderer/backend/gles/proc_table_gles.h @@ -0,0 +1,25 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include "flutter/fml/macros.h" + +namespace impeller { + +class ProcTableGLES { + public: + ProcTableGLES(); + + ~ProcTableGLES(); + + bool IsValid() const; + + private: + bool is_valid_ = false; + + FML_DISALLOW_COPY_AND_ASSIGN(ProcTableGLES); +}; + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/reactor_gles.cc b/impeller/renderer/backend/gles/reactor_gles.cc new file mode 100644 index 0000000000000..e673632dab9ff --- /dev/null +++ b/impeller/renderer/backend/gles/reactor_gles.cc @@ -0,0 +1,28 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/reactor_gles.h" + +#include "impeller/base/validation.h" + +namespace impeller { + +ReactorGLES::ReactorGLES() { + proc_table_ = std::make_unique(); + + if (!proc_table_->IsValid()) { + VALIDATION_LOG << "Could not create valid proc table."; + return; + } + + is_valid_ = true; +} + +ReactorGLES::~ReactorGLES() = default; + +bool ReactorGLES::IsValid() const { + return is_valid_; +} + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/reactor_gles.h b/impeller/renderer/backend/gles/reactor_gles.h new file mode 100644 index 0000000000000..f3a0d1bd0161d --- /dev/null +++ b/impeller/renderer/backend/gles/reactor_gles.h @@ -0,0 +1,29 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include + +#include "flutter/fml/macros.h" +#include "impeller/renderer/backend/gles/proc_table_gles.h" + +namespace impeller { + +class ReactorGLES { + public: + ReactorGLES(); + + ~ReactorGLES(); + + bool IsValid() const; + + private: + std::unique_ptr proc_table_; + bool is_valid_ = false; + + FML_DISALLOW_COPY_AND_ASSIGN(ReactorGLES); +}; + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/render_pass_gles.cc b/impeller/renderer/backend/gles/render_pass_gles.cc new file mode 100644 index 0000000000000..06771a3128558 --- /dev/null +++ b/impeller/renderer/backend/gles/render_pass_gles.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/render_pass_gles.h" + +namespace impeller { + +// + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/render_pass_gles.h b/impeller/renderer/backend/gles/render_pass_gles.h new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/impeller/renderer/backend/gles/sampler_gles.cc b/impeller/renderer/backend/gles/sampler_gles.cc new file mode 100644 index 0000000000000..cd8c1ba103add --- /dev/null +++ b/impeller/renderer/backend/gles/sampler_gles.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/sampler_gles.h" + +namespace impeller { + +// + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/sampler_gles.h b/impeller/renderer/backend/gles/sampler_gles.h new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/impeller/renderer/backend/gles/sampler_library_gles.cc b/impeller/renderer/backend/gles/sampler_library_gles.cc new file mode 100644 index 0000000000000..bff27cd6e133c --- /dev/null +++ b/impeller/renderer/backend/gles/sampler_library_gles.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/sampler_library_gles.h" + +namespace impeller { + +// + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/sampler_library_gles.h b/impeller/renderer/backend/gles/sampler_library_gles.h new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/impeller/renderer/backend/gles/shader_function_gles.cc b/impeller/renderer/backend/gles/shader_function_gles.cc new file mode 100644 index 0000000000000..db71e891ef58d --- /dev/null +++ b/impeller/renderer/backend/gles/shader_function_gles.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/shader_function_gles.h" + +namespace impeller { + +// + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/shader_function_gles.h b/impeller/renderer/backend/gles/shader_function_gles.h new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/impeller/renderer/backend/gles/shader_library_gles.cc b/impeller/renderer/backend/gles/shader_library_gles.cc new file mode 100644 index 0000000000000..7074095de2220 --- /dev/null +++ b/impeller/renderer/backend/gles/shader_library_gles.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/shader_library_gles.h" + +namespace impeller { + +// + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/shader_library_gles.h b/impeller/renderer/backend/gles/shader_library_gles.h new file mode 100644 index 0000000000000..fcc3e546c3c26 --- /dev/null +++ b/impeller/renderer/backend/gles/shader_library_gles.h @@ -0,0 +1,33 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include "flutter/fml/macros.h" +#include "impeller/renderer/shader_library.h" + +namespace impeller { + +class ShaderLibraryGLES final : public ShaderLibrary { + public: + ShaderLibraryGLES(); + + // |ShaderLibrary| + ~ShaderLibraryGLES() override; + + // |ShaderLibrary| + bool IsValid() const override; + + private: + friend class ContextGLES; + + // |ShaderLibrary| + std::shared_ptr GetFunction( + const std::string_view& name, + ShaderStage stage) override; + + FML_DISALLOW_COPY_AND_ASSIGN(ShaderLibraryGLES); +}; + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/surface_gles.cc b/impeller/renderer/backend/gles/surface_gles.cc new file mode 100644 index 0000000000000..b80a2519cb757 --- /dev/null +++ b/impeller/renderer/backend/gles/surface_gles.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/surface_gles.h" + +namespace impeller { + +// + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/surface_gles.h b/impeller/renderer/backend/gles/surface_gles.h new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/impeller/renderer/backend/gles/texture_gles.cc b/impeller/renderer/backend/gles/texture_gles.cc new file mode 100644 index 0000000000000..0ebe05e47658d --- /dev/null +++ b/impeller/renderer/backend/gles/texture_gles.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/texture_gles.h" + +namespace impeller { + +// + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/texture_gles.h b/impeller/renderer/backend/gles/texture_gles.h new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/impeller/renderer/backend/gles/vertex_descriptor_gles.cc b/impeller/renderer/backend/gles/vertex_descriptor_gles.cc new file mode 100644 index 0000000000000..677e729f2cc5f --- /dev/null +++ b/impeller/renderer/backend/gles/vertex_descriptor_gles.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/gles/vertex_descriptor_gles.h" + +namespace impeller { + +// + +} // namespace impeller diff --git a/impeller/renderer/backend/gles/vertex_descriptor_gles.h b/impeller/renderer/backend/gles/vertex_descriptor_gles.h new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/impeller/renderer/renderer.cc b/impeller/renderer/renderer.cc index fab86fcd8d9f6..849e4fc0fa3ba 100644 --- a/impeller/renderer/renderer.cc +++ b/impeller/renderer/renderer.cc @@ -19,7 +19,7 @@ Renderer::Renderer(std::shared_ptr context, : frames_in_flight_sema_(std::make_shared( std::max(1u, max_frames_in_flight))), context_(std::move(context)) { - if (!context_->IsValid()) { + if (!context_ || !context_->IsValid()) { return; } diff --git a/impeller/renderer/renderer_unittests.cc b/impeller/renderer/renderer_unittests.cc index 40fa47ecadf0d..0bd6640223221 100644 --- a/impeller/renderer/renderer_unittests.cc +++ b/impeller/renderer/renderer_unittests.cc @@ -4,12 +4,12 @@ #include "flutter/fml/time/time_point.h" #include "flutter/testing/testing.h" -#include "impeller/fixtures/box_fade.frag.h" -#include "impeller/fixtures/box_fade.vert.h" -#include "impeller/fixtures/instanced_draw.frag.h" -#include "impeller/fixtures/instanced_draw.vert.h" -#include "impeller/fixtures/test_texture.frag.h" -#include "impeller/fixtures/test_texture.vert.h" +#include "impeller/fixtures/mtl/box_fade.frag.h" +#include "impeller/fixtures/mtl/box_fade.vert.h" +#include "impeller/fixtures/mtl/instanced_draw.frag.h" +#include "impeller/fixtures/mtl/instanced_draw.vert.h" +#include "impeller/fixtures/mtl/test_texture.frag.h" +#include "impeller/fixtures/mtl/test_texture.vert.h" #include "impeller/geometry/path_builder.h" #include "impeller/image/compressed_image.h" #include "impeller/image/decompressed_image.h" @@ -30,8 +30,9 @@ namespace impeller { namespace testing { using RendererTest = Playground; +INSTANTIATE_PLAYGROUND_SUITE(RendererTest); -TEST_F(RendererTest, CanCreateBoxPrimitive) { +TEST_P(RendererTest, CanCreateBoxPrimitive) { using VS = BoxFadeVertexShader; using FS = BoxFadeFragmentShader; auto context = GetContext(); @@ -96,7 +97,7 @@ TEST_F(RendererTest, CanCreateBoxPrimitive) { OpenPlaygroundHere(callback); } -TEST_F(RendererTest, CanRenderMultiplePrimitives) { +TEST_P(RendererTest, CanRenderMultiplePrimitives) { using VS = BoxFadeVertexShader; using FS = BoxFadeFragmentShader; auto context = GetContext(); @@ -168,7 +169,7 @@ TEST_F(RendererTest, CanRenderMultiplePrimitives) { OpenPlaygroundHere(callback); } -TEST_F(RendererTest, CanRenderToTexture) { +TEST_P(RendererTest, CanRenderToTexture) { using VS = BoxFadeVertexShader; using FS = BoxFadeFragmentShader; auto context = GetContext(); @@ -272,7 +273,7 @@ TEST_F(RendererTest, CanRenderToTexture) { ASSERT_TRUE(r2t_pass->EncodeCommands(*context->GetTransientsAllocator())); } -TEST_F(RendererTest, CanRenderInstanced) { +TEST_P(RendererTest, CanRenderInstanced) { using VS = InstancedDrawVertexShader; using FS = InstancedDrawFragmentShader; @@ -290,6 +291,7 @@ TEST_F(RendererTest, CanRenderInstanced) { builder.AppendVertex(data); })); + ASSERT_NE(GetContext(), nullptr); auto pipeline = GetContext() ->GetPipelineLibrary() diff --git a/impeller/tools/impeller.gni b/impeller/tools/impeller.gni index e4430563b0fb5..1b60ddcc47b44 100644 --- a/impeller/tools/impeller.gni +++ b/impeller/tools/impeller.gni @@ -12,11 +12,21 @@ declare_args() { # Whether Impeller is supported on the platform. impeller_supports_platform = true - # Whether Impeller supports rendering on the platform. - impeller_supports_rendering = is_mac || is_ios + # Whether the Metal backend is enabled. + impeller_enable_metal = is_mac || is_ios + + # Whether the OpenGLES backend is enabled. + impeller_enable_opengles = is_mac +} +declare_args() { # Whether Impeller shaders are supported on the platform. - impeller_shaders_supports_platform = is_mac || is_ios + impeller_shaders_supports_platform = + impeller_enable_metal || impeller_enable_opengles + + # Whether Impeller supports rendering on the platform. + impeller_supports_rendering = + impeller_enable_metal || impeller_enable_opengles } # ------------------------------------------------------------------------------ @@ -106,7 +116,7 @@ template("metal_library") { script = "//flutter/impeller/tools/build_metal_library.py" - depfile = "$target_gen_dir/shader_deps/$metal_library_name.depfile" + depfile = "$target_gen_dir/mtl/$metal_library_name.depfile" args = [ "--output", @@ -151,17 +161,19 @@ template("impeller_shaders_real") { assert(defined(invoker.name), "Name of the shader library must be specified.") base_target_name = target_name - impellerc_target_name = "impellerc_$target_name" + impellerc_target_name = "impellerc_mtl_$target_name" compiled_action_foreach(impellerc_target_name) { tool = "//flutter/impeller/compiler:impellerc" sources = invoker.shaders - metal_intermediate = "$target_gen_dir/{{source_file_part}}.metal" - spirv_intermediate = "$target_gen_dir/{{source_file_part}}.spirv" - reflection_json_intermediate = "$target_gen_dir/{{source_file_part}}.json" - reflection_header_intermediate = "$target_gen_dir/{{source_file_part}}.h" - reflection_cc_intermediate = "$target_gen_dir/{{source_file_part}}.mm" + metal_intermediate = "$target_gen_dir/mtl/{{source_file_part}}.metal" + spirv_intermediate = "$target_gen_dir/mtl/{{source_file_part}}.spirv" + reflection_json_intermediate = + "$target_gen_dir/mtl/{{source_file_part}}.json" + reflection_header_intermediate = + "$target_gen_dir/mtl/{{source_file_part}}.h" + reflection_cc_intermediate = "$target_gen_dir/mtl/{{source_file_part}}.cc" outputs = [ metal_intermediate, @@ -169,7 +181,7 @@ template("impeller_shaders_real") { reflection_cc_intermediate, ] - depfile_path = "$target_gen_dir/{{source_file_part}}.d" + depfile_path = "$target_gen_dir/mtl/{{source_file_part}}.d" metal_intermediate_path = rebase_path(metal_intermediate, root_build_dir) spirv_intermediate_path = rebase_path(spirv_intermediate, root_build_dir) @@ -223,6 +235,14 @@ template("impeller_shaders_real") { target_gen_dir, impeller_root_gen_dir, ] + + if (impeller_enable_metal) { + include_dirs += [ "$impeller_root_gen_dir/mtl" ] + } + + if (impeller_enable_opengles) { + include_dirs += [ "$impeller_root_gen_dir/gles" ] + } } source_set(shader_glue_target_name) { @@ -248,8 +268,8 @@ template("impeller_shaders_real") { metal_library_files = get_target_outputs(":$metal_library_target_name") metal_library_file = metal_library_files[0] inputs = [ metal_library_file ] - output_header = "$target_gen_dir/$base_target_name.h" - output_source = "$target_gen_dir/$base_target_name.c" + output_header = "$target_gen_dir/mtl/$base_target_name.h" + output_source = "$target_gen_dir/mtl/$base_target_name.c" outputs = [ output_header, output_source, diff --git a/impeller/typographer/typographer_unittests.cc b/impeller/typographer/typographer_unittests.cc index 0cb41841aec25..41cb7c1ca9705 100644 --- a/impeller/typographer/typographer_unittests.cc +++ b/impeller/typographer/typographer_unittests.cc @@ -12,8 +12,9 @@ namespace impeller { namespace testing { using TypographerTest = Playground; +INSTANTIATE_PLAYGROUND_SUITE(TypographerTest); -TEST_F(TypographerTest, CanConvertTextBlob) { +TEST_P(TypographerTest, CanConvertTextBlob) { SkFont font; auto blob = SkTextBlob::MakeFromString( "the quick brown fox jumped over the lazy dog.", font); @@ -26,12 +27,12 @@ TEST_F(TypographerTest, CanConvertTextBlob) { } } -TEST_F(TypographerTest, CanCreateRenderContext) { +TEST_P(TypographerTest, CanCreateRenderContext) { auto context = TextRenderContext::Create(GetContext()); ASSERT_TRUE(context && context->IsValid()); } -TEST_F(TypographerTest, CanCreateGlyphAtlas) { +TEST_P(TypographerTest, CanCreateGlyphAtlas) { auto context = TextRenderContext::Create(GetContext()); ASSERT_TRUE(context && context->IsValid()); SkFont sk_font;