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 /* io_task_runner */ nullptr);
44
45 const std::shared_ptr<impeller::Context> context =
46 surface.CreateImpellerContext();
47 const std::shared_ptr<impeller::ShaderLibrary> shaders =
48 context->GetShaderLibrary();
49 const std::shared_ptr<const impeller::ShaderFunction> func =
50 shaders->GetFunction("imp_uber_sdf_fragment_main",
52 const auto gles_func = impeller::ShaderFunctionGLES::Cast(func.get());
53 const std::shared_ptr<const fml::Mapping> source =
54 gles_func->GetSourceMapping();
55 const auto text =
56 std::string_view(reinterpret_cast<const char*>(source->GetMapping()));
57 EXPECT_THAT(text, StartsWith("#version 300 es"));
58}
59
60TEST(EmbedderSurfaceGLImpellerTest, GLES2ContextDoesNotHaveGLES3Shaders) {
61 const auto gl_dispatch_table =
62 StubDispatchTable(/* version */ "OpenGL ES 2.0");
64 gl_dispatch_table, /* fbo_reset_after_present */ false,
65 /* external_view_embedder */ nullptr,
66 /* io_task_runner */ nullptr);
67
68 const std::shared_ptr<impeller::Context> context =
69 surface.CreateImpellerContext();
70 const std::shared_ptr<impeller::ShaderLibrary> shaders =
71 context->GetShaderLibrary();
72 const std::shared_ptr<const impeller::ShaderFunction> func =
73 shaders->GetFunction("imp_uber_sdf_fragment_main",
75 const auto gles_func = impeller::ShaderFunctionGLES::Cast(func.get());
76 const std::shared_ptr<const fml::Mapping> source =
77 gles_func->GetSourceMapping();
78 const auto text =
79 std::string_view(reinterpret_cast<const char*>(source->GetMapping()));
80 EXPECT_THAT(text, StartsWith("#version 100"));
81}
82} // namespace testing
83} // 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:417
VkSurfaceKHR surface
Definition main.cc:65
std::u16string text
TEST(NativeAssetsManagerTest, NoAvailableAssets)
impeller::Matrix DlMatrix
const ProcTableGLES::Resolver kMockResolverGLES
Definition mock_gles.cc:459
std::shared_ptr< ContextGLES > context