Flutter Engine
The Flutter Engine
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 <windows.h>
18#include <wrl/client.h>
19#include <memory>
20
21#include "flutter/fml/macros.h"
22#include "flutter/shell/platform/windows/egl/context.h"
23#include "flutter/shell/platform/windows/egl/surface.h"
24#include "flutter/shell/platform/windows/egl/window_surface.h"
25
26namespace flutter {
27namespace egl {
28
29// A manager for initializing ANGLE correctly and using it to create and
30// destroy surfaces
31class Manager {
32 public:
33 static std::unique_ptr<Manager> Create(bool enable_impeller);
34
35 virtual ~Manager();
36
37 // Whether the manager is currently valid.
38 bool IsValid() const;
39
40 // Creates an EGL surface that can be used to render a Flutter view into a
41 // win32 HWND.
42 //
43 // After the surface is created, |WindowSurface::SetVSyncEnabled| should be
44 // called on a thread that can make the surface current.
45 //
46 // HWND is the window backing the surface. Width and height are the surface's
47 // physical pixel dimensions.
48 //
49 // Returns nullptr on failure.
50 virtual std::unique_ptr<WindowSurface> CreateWindowSurface(HWND hwnd,
51 size_t width,
52 size_t height);
53
54 // Check if the current thread has a context bound.
55 bool HasContextCurrent();
56
57 // Creates a |EGLSurface| from the provided handle.
58 EGLSurface CreateSurfaceFromHandle(EGLenum handle_type,
59 EGLClientBuffer handle,
60 const EGLint* attributes) const;
61
62 // Gets the |EGLDisplay|.
63 EGLDisplay egl_display() const { return display_; };
64
65 // Gets the |ID3D11Device| chosen by ANGLE.
66 bool GetDevice(ID3D11Device** device);
67
68 // Get the EGL context used to render Flutter views.
69 virtual Context* render_context() const;
70
71 // Get the EGL context used for async texture uploads.
72 virtual Context* resource_context() const;
73
74 protected:
75 // Creates a new surface manager retaining reference to the passed-in target
76 // for the lifetime of the manager.
77 explicit Manager(bool enable_impeller);
78
79 private:
80 // Number of active instances of Manager
81 static int instance_count_;
82
83 // Initialize the EGL display.
84 bool InitializeDisplay();
85
86 // Initialize the EGL configs.
87 bool InitializeConfig(bool enable_impeller);
88
89 // Initialize the EGL render and resource contexts.
90 bool InitializeContexts();
91
92 // Initialize the D3D11 device.
93 bool InitializeDevice();
94
95 void CleanUp();
96
97 // Whether the manager was initialized successfully.
98 bool is_valid_ = false;
99
100 // EGL representation of native display.
101 EGLDisplay display_ = EGL_NO_DISPLAY;
102
103 // EGL framebuffer configuration.
104 EGLConfig config_ = nullptr;
105
106 // The EGL context used to render Flutter views.
107 std::unique_ptr<Context> render_context_;
108
109 // The EGL context used for async texture uploads.
110 std::unique_ptr<Context> resource_context_;
111
112 // The current D3D device.
113 Microsoft::WRL::ComPtr<ID3D11Device> resolved_device_ = nullptr;
114
115 FML_DISALLOW_COPY_AND_ASSIGN(Manager);
116};
117
118} // namespace egl
119} // namespace flutter
120
121#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_MANAGER_H_
virtual Context * resource_context() const
Definition: manager.cc:322
static std::unique_ptr< Manager > Create(bool enable_impeller)
Definition: manager.cc:17
virtual ~Manager()
Definition: manager.cc:44
bool HasContextCurrent()
Definition: manager.cc:296
EGLSurface CreateSurfaceFromHandle(EGLenum handle_type, EGLClientBuffer handle, const EGLint *attributes) const
Definition: manager.cc:300
Manager(bool enable_impeller)
Definition: manager.cc:26
virtual Context * render_context() const
Definition: manager.cc:318
virtual std::unique_ptr< WindowSurface > CreateWindowSurface(HWND hwnd, size_t width, size_t height)
Definition: manager.cc:266
bool GetDevice(ID3D11Device **device)
Definition: manager.cc:307
EGLDisplay egl_display() const
Definition: manager.h:63
bool IsValid() const
Definition: manager.cc:262
VkDevice device
Definition: main.cc:53
int32_t height
int32_t width