Flutter Engine
 
Loading...
Searching...
No Matches
shell_test_platform_view_gl.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
6
7#include <utility>
8
9#include <EGL/egl.h>
10
12#include "impeller/entity/gles/entity_shaders_gles.h"
13
14namespace flutter {
15namespace testing {
16
17static std::vector<std::shared_ptr<fml::Mapping>> ShaderLibraryMappings() {
18 return {
19 std::make_shared<fml::NonOwnedMapping>(
20 impeller_entity_shaders_gles_data,
21 impeller_entity_shaders_gles_length),
22 };
23}
24
25std::unique_ptr<ShellTestPlatformView> ShellTestPlatformView::CreateGL(
26 PlatformView::Delegate& delegate,
27 const TaskRunners& task_runners,
28 const std::shared_ptr<ShellTestVsyncClock>& vsync_clock,
29 const CreateVsyncWaiter& create_vsync_waiter,
30 const std::shared_ptr<ShellTestExternalViewEmbedder>&
31 shell_test_external_view_embedder,
32 const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch) {
33 return std::make_unique<ShellTestPlatformViewGL>(
34 delegate, task_runners, vsync_clock, create_vsync_waiter,
35 shell_test_external_view_embedder);
36}
37
39 PlatformView::Delegate& delegate,
40 const TaskRunners& task_runners,
41 std::shared_ptr<ShellTestVsyncClock> vsync_clock,
42 CreateVsyncWaiter create_vsync_waiter,
43 std::shared_ptr<ShellTestExternalViewEmbedder>
44 shell_test_external_view_embedder)
45 : ShellTestPlatformView(delegate, task_runners),
46 gl_surface_(DlISize(800, 600)),
47 create_vsync_waiter_(std::move(create_vsync_waiter)),
48 vsync_clock_(std::move(vsync_clock)),
49 shell_test_external_view_embedder_(
50 std::move(shell_test_external_view_embedder)) {
51 if (GetSettings().enable_impeller) {
52 auto resolver = [](const char* name) -> void* {
53 return reinterpret_cast<void*>(::eglGetProcAddress(name));
54 };
55 // ANGLE needs this to initialize version strings checked by
56 // impeller::ProcTableGLES.
57 gl_surface_.MakeCurrent();
58 auto gl = std::make_unique<impeller::ProcTableGLES>(resolver);
59 if (!gl->IsValid()) {
60 FML_LOG(ERROR) << "Proc table when a shell unittests invalid.";
61 return;
62 }
63 impeller_context_ = impeller::ContextGLES::Create(
64 impeller::Flags{}, std::move(gl), ShaderLibraryMappings(), true);
65 }
66}
67
69
70std::unique_ptr<VsyncWaiter> ShellTestPlatformViewGL::CreateVSyncWaiter() {
71 return create_vsync_waiter_();
72}
73
74// |ShellTestPlatformView|
76 vsync_clock_->SimulateVSync();
77}
78
79// |PlatformView|
80std::unique_ptr<Surface> ShellTestPlatformViewGL::CreateRenderingSurface() {
81 return std::make_unique<GPUSurfaceGLSkia>(this, true);
82}
83
84// |PlatformView|
85std::shared_ptr<ExternalViewEmbedder>
86ShellTestPlatformViewGL::CreateExternalViewEmbedder() {
87 return shell_test_external_view_embedder_;
88}
89
90// |PlatformView|
91PointerDataDispatcherMaker ShellTestPlatformViewGL::GetDispatcherMaker() {
92 return [](DefaultPointerDataDispatcher::Delegate& delegate) {
93 return std::make_unique<SmoothPointerDataDispatcher>(delegate);
94 };
95}
96
97// |GPUSurfaceGLDelegate|
98std::unique_ptr<GLContextResult>
99ShellTestPlatformViewGL::GLContextMakeCurrent() {
100 return std::make_unique<GLContextDefaultResult>(gl_surface_.MakeCurrent());
101}
102
103// |GPUSurfaceGLDelegate|
104bool ShellTestPlatformViewGL::GLContextClearCurrent() {
105 return gl_surface_.ClearCurrent();
106}
107
108// |GPUSurfaceGLDelegate|
109bool ShellTestPlatformViewGL::GLContextPresent(
110 const GLPresentInfo& present_info) {
111 return gl_surface_.Present();
112}
113
114// |GPUSurfaceGLDelegate|
115GLFBOInfo ShellTestPlatformViewGL::GLContextFBO(GLFrameInfo frame_info) const {
116 return GLFBOInfo{
117 .fbo_id = gl_surface_.GetFramebuffer(frame_info.width, frame_info.height),
118 };
119}
120
121// |GPUSurfaceGLDelegate|
123ShellTestPlatformViewGL::GetGLProcResolver() const {
124 return [surface = &gl_surface_](const char* name) -> void* {
125 return surface->GetProcAddress(name);
126 };
127}
128
129} // namespace testing
130} // namespace flutter
std::function< void *(const char *)> GLProcResolver
Used to forward events from the platform view to interested subsystems. This forwarding is done by th...
const Settings & GetSettings() const
Get the settings for this platform view instance.
ShellTestPlatformViewGL(PlatformView::Delegate &delegate, const TaskRunners &task_runners, std::shared_ptr< ShellTestVsyncClock > vsync_clock, CreateVsyncWaiter create_vsync_waiter, std::shared_ptr< ShellTestExternalViewEmbedder > shell_test_external_view_embedder)
static std::unique_ptr< ShellTestPlatformView > CreateGL(PlatformView::Delegate &delegate, const TaskRunners &task_runners, const std::shared_ptr< ShellTestVsyncClock > &vsync_clock, const CreateVsyncWaiter &create_vsync_waiter, const std::shared_ptr< ShellTestExternalViewEmbedder > &shell_test_external_view_embedder, const std::shared_ptr< const fml::SyncSwitch > &is_gpu_disabled_sync_switch)
uint32_t GetFramebuffer(uint32_t width, uint32_t height) const
static std::shared_ptr< ContextGLES > Create(const Flags &flags, std::unique_ptr< ProcTableGLES > gl, const std::vector< std::shared_ptr< fml::Mapping > > &shader_libraries, bool enable_gpu_tracing)
VkSurfaceKHR surface
Definition main.cc:65
#define FML_LOG(severity)
Definition logging.h:101
std::function< std::unique_ptr< VsyncWaiter >()> CreateVsyncWaiter
static std::vector< std::shared_ptr< fml::Mapping > > ShaderLibraryMappings()
std::function< std::unique_ptr< PointerDataDispatcher >(PointerDataDispatcher::Delegate &)> PointerDataDispatcherMaker
Signature for constructing PointerDataDispatcher.
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27
Definition ref_ptr.h:261