Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
manager.h
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#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_MANAGER_H_
6#define FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_MANAGER_H_
7
8// OpenGL ES and EGL includes
9#include <EGL/egl.h>
10#include <EGL/eglext.h>
11#include <EGL/eglplatform.h>
12#include <GLES2/gl2.h>
13#include <GLES2/gl2ext.h>
14
15// Windows platform specific includes
16#include <d3d11.h>
17#include <dxgi.h>
18#include <dxgi1_6.h>
19#include <windows.h>
20#include <wrl/client.h>
21#include <memory>
22#include <optional>
23
24#include "flutter/fml/macros.h"
28
29namespace flutter {
30namespace egl {
31
37
38// A manager for initializing ANGLE correctly and using it to create and
39// destroy surfaces
40class Manager {
41 public:
42 static std::unique_ptr<Manager> Create(GpuPreference gpu_preference);
43
44 virtual ~Manager();
45
46 // Whether the manager is currently valid.
47 bool IsValid() const;
48
49 // Creates an EGL surface that can be used to render a Flutter view into a
50 // win32 HWND.
51 //
52 // After the surface is created, |WindowSurface::SetVSyncEnabled| should be
53 // called on a thread that can make the surface current.
54 //
55 // HWND is the window backing the surface. Width and height are the surface's
56 // physical pixel dimensions.
57 //
58 // Returns nullptr on failure.
59 virtual std::unique_ptr<WindowSurface> CreateWindowSurface(HWND hwnd,
60 size_t width,
61 size_t height);
62
63 // Check if the current thread has a context bound.
64 bool HasContextCurrent();
65
66 // Creates a |EGLSurface| from the provided handle.
67 EGLSurface CreateSurfaceFromHandle(EGLenum handle_type,
68 EGLClientBuffer handle,
69 const EGLint* attributes) const;
70
71 // Gets the |EGLDisplay|.
72 EGLDisplay egl_display() const { return display_; };
73
74 // Gets the |EGLConfig|.
75 EGLConfig egl_config() const { return config_; };
76
77 // Gets the |ID3D11Device| chosen by ANGLE.
78 bool GetDevice(ID3D11Device** device);
79
80 // Get the EGL context used to render Flutter views.
81 virtual Context* render_context() const;
82
83 // Get the EGL context used for async texture uploads.
84 virtual Context* resource_context() const;
85
86 static std::optional<LUID> GetLowPowerGpuLuid();
87
88 static std::optional<LUID> GetHighPerformanceGpuLuid();
89
90 protected:
91 // Creates a new surface manager retaining reference to the passed-in target
92 // for the lifetime of the manager.
93 explicit Manager(GpuPreference gpu_preference);
94
95 private:
96 // Number of active instances of Manager
97 static int instance_count_;
98
99 // Helper function to get GPU LUID by preference.
100 static std::optional<LUID> GetGpuLuidByPreference(
101 DXGI_GPU_PREFERENCE preference);
102
103 // Initialize the EGL display.
104 bool InitializeDisplay(GpuPreference gpu_preference);
105
106 // Initialize the EGL configs.
107 bool InitializeConfig();
108
109 // Initialize the EGL render and resource contexts.
110 bool InitializeContexts();
111
112 // Initialize the D3D11 device.
113 bool InitializeDevice();
114
115 void CleanUp();
116
117 // Whether the manager was initialized successfully.
118 bool is_valid_ = false;
119
120 // EGL representation of native display.
121 EGLDisplay display_ = EGL_NO_DISPLAY;
122
123 // EGL framebuffer configuration.
124 EGLConfig config_ = nullptr;
125
126 // The EGL context used to render Flutter views.
127 std::unique_ptr<Context> render_context_;
128
129 // The EGL context used for async texture uploads.
130 std::unique_ptr<Context> resource_context_;
131
132 // The current D3D device.
133 Microsoft::WRL::ComPtr<ID3D11Device> resolved_device_ = nullptr;
134
136};
137
138} // namespace egl
139} // namespace flutter
140
141#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_MANAGER_H_
virtual Context * resource_context() const
Definition manager.cc:339
EGLConfig egl_config() const
Definition manager.h:75
EGLSurface CreateSurfaceFromHandle(EGLenum handle_type, EGLClientBuffer handle, const EGLint *attributes) const
Definition manager.cc:317
static std::optional< LUID > GetLowPowerGpuLuid()
Definition manager.cc:376
virtual Context * render_context() const
Definition manager.cc:335
static std::optional< LUID > GetHighPerformanceGpuLuid()
Definition manager.cc:380
static std::unique_ptr< Manager > Create(GpuPreference gpu_preference)
Definition manager.cc:17
virtual std::unique_ptr< WindowSurface > CreateWindowSurface(HWND hwnd, size_t width, size_t height)
Definition manager.cc:283
bool GetDevice(ID3D11Device **device)
Definition manager.cc:324
EGLDisplay egl_display() const
Definition manager.h:72
bool IsValid() const
Definition manager.cc:279
VkDevice device
Definition main.cc:69
@ LowPowerPreference
@ HighPerformancePreference
@ NoPreference
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
int32_t height
int32_t width