Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
embedder_test_surface_gl_impeller.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flatbuffers/stl_emulation.h"
9
10#include "gmock/gmock.h"
11#include "gtest/gtest.h"
12
13namespace flutter {
14namespace testing {
15
16using ::testing::Not;
17using ::testing::StartsWith;
18
19namespace {
20EmbedderSurfaceGLSkia::GLDispatchTable StubDispatchTable(
21 std::string_view version) {
22 impeller::testing::MockGLES::Init(flatbuffers::nullopt, version.data());
23 static constexpr auto dummy_always_true = [] { return true; };
24 return EmbedderSurfaceGLSkia::GLDispatchTable{
25 .gl_make_current_callback = dummy_always_true,
26 .gl_clear_current_callback = dummy_always_true,
27 .gl_present_callback = [](const auto) { return true; },
28 .gl_fbo_callback = [](const auto) { return 0; },
29 .gl_make_resource_current_callback = dummy_always_true,
30 .gl_surface_transformation_callback = [] { return DlMatrix{}; },
31 .gl_proc_resolver = impeller::testing::kMockResolverGLES,
32 .gl_populate_existing_damage = [](const auto) { return GLFBOInfo{}; },
33 };
34}
35} // namespace
36
37TEST(EmbedderSurfaceGLImpellerTest, GLES3ContextHasGLES3Shaders) {
38 const auto gl_dispatch_table =
39 StubDispatchTable(/* version */ "OpenGL ES 3.0");
41 gl_dispatch_table, /* fbo_reset_after_present */ false,
42 /* external_view_embedder */ nullptr);
43
44 const std::shared_ptr<impeller::Context> context =
45 surface.CreateImpellerContext();
46 const std::shared_ptr<impeller::ShaderLibrary> shaders =
47 context->GetShaderLibrary();
48 const std::shared_ptr<const impeller::ShaderFunction> func =
49 shaders->GetFunction("imp_line_fragment_main",
51 const auto gles_func = impeller::ShaderFunctionGLES::Cast(func.get());
52 const std::shared_ptr<const fml::Mapping> source =
53 gles_func->GetSourceMapping();
54 const auto text =
55 std::string_view(reinterpret_cast<const char*>(source->GetMapping()));
56 EXPECT_THAT(text, StartsWith("#version 300 es"));
57}
58
59TEST(EmbedderSurfaceGLImpellerTest, GLES2ContextDoesNotHaveGLES3Shaders) {
60 const auto gl_dispatch_table =
61 StubDispatchTable(/* version */ "OpenGL ES 2.0");
63 gl_dispatch_table, /* fbo_reset_after_present */ false,
64 /* external_view_embedder */ nullptr);
65
66 const std::shared_ptr<impeller::Context> context =
67 surface.CreateImpellerContext();
68 const std::shared_ptr<impeller::ShaderLibrary> shaders =
69 context->GetShaderLibrary();
70 const std::shared_ptr<const impeller::ShaderFunction> func =
71 shaders->GetFunction("imp_line_fragment_main",
73 const auto gles_func = impeller::ShaderFunctionGLES::Cast(func.get());
74 const std::shared_ptr<const fml::Mapping> source =
75 gles_func->GetSourceMapping();
76 const auto text =
77 std::string_view(reinterpret_cast<const char*>(source->GetMapping()));
78 EXPECT_THAT(text, StartsWith("#version 100"));
79}
80} // namespace testing
81} // namespace flutter
static ShaderFunctionGLES & Cast(ShaderFunction &base)
static std::shared_ptr< MockGLES > Init(std::unique_ptr< MockGLESImpl > impl, const std::optional< std::vector< const char * > > &extensions=std::nullopt, const char *version_string="OpenGL ES 3.0")
Definition mock_gles.cc:360
VkSurfaceKHR surface
Definition main.cc:65
std::u16string text
TEST(NativeAssetsManagerTest, NoAvailableAssets)
impeller::Matrix DlMatrix
const ProcTableGLES::Resolver kMockResolverGLES
Definition mock_gles.cc:402