Flutter Engine
The Flutter Engine
stub_flutter_windows_api.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_CLIENT_WRAPPER_TESTING_STUB_FLUTTER_WINDOWS_API_H_
6#define FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_TESTING_STUB_FLUTTER_WINDOWS_API_H_
7
8#include <memory>
9
10#include "flutter/shell/platform/windows/flutter_windows_internal.h"
11#include "flutter/shell/platform/windows/public/flutter_windows.h"
12
13namespace flutter {
14namespace testing {
15
16// Base class for a object that provides test implementations of the APIs in
17// the headers in platform/windows/public/.
18
19// Linking this class into a test binary will provide dummy forwarding
20// implementations of that C API, so that the wrapper can be tested separately
21// from the actual library.
23 public:
24 // Sets |stub| as the instance to which calls to the Flutter library C APIs
25 // will be forwarded.
26 static void SetTestStub(StubFlutterWindowsApi* stub);
27
28 // Returns the current stub, as last set by SetTestFlutterStub.
30
32
33 // Called for FlutterDesktopViewControllerCreate.
36 return nullptr;
37 }
38
39 // Called for FlutterDesktopViewControllerDestroy.
40 virtual void ViewControllerDestroy() {}
41
42 // Called for FlutterDesktopViewControllerForceRedraw.
43 virtual void ViewControllerForceRedraw() {}
44
45 // Called for FlutterDesktopViewControllerHandleTopLevelWindowProc.
48 WPARAM wparam,
49 LPARAM lparam,
50 LRESULT* result) {
51 return false;
52 }
53
54 // Called for FlutterDesktopEngineCreate.
56 const FlutterDesktopEngineProperties& engine_properties) {
57 return nullptr;
58 }
59
60 // Called for FlutterDesktopEngineDestroy.
61 virtual bool EngineDestroy() { return true; }
62
63 // Called for FlutterDesktopEngineRun.
64 virtual bool EngineRun(const char* entry_point) { return true; }
65
66 // Called for FlutterDesktopEngineProcessMessages.
67 virtual uint64_t EngineProcessMessages() { return 0; }
68
69 // Called for FlutterDesktopEngineSetNextFrameCallback.
71 void* user_data) {}
72
73 // Called for FlutterDesktopEngineReloadSystemFonts.
74 virtual void EngineReloadSystemFonts() {}
75
76 // Called for FlutterDesktopEngineRegisterPlatformViewType.
78 const char* view_type_name,
80
81 // Called for FlutterDesktopViewGetHWND.
82 virtual HWND ViewGetHWND() { return reinterpret_cast<HWND>(1); }
83
84 // Called for FlutterDesktopViewGetGraphicsAdapter.
85 virtual IDXGIAdapter* ViewGetGraphicsAdapter() {
86 return reinterpret_cast<IDXGIAdapter*>(2);
87 }
88
89 // Called for FlutterDesktopPluginRegistrarGetView.
90 virtual FlutterDesktopViewRef PluginRegistrarGetView() { return nullptr; }
91
92 // Called for FlutterDesktopPluginRegistrarGetViewById.
94 FlutterDesktopViewId view_id) {
95 return nullptr;
96 }
97
98 // Called for FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate.
101 void* user_data) {}
102
103 // Called for
104 // FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate.
107
108 // Called for FlutterDesktopEngineProcessExternalWindowMessage.
111 HWND hwnd,
113 WPARAM wparam,
114 LPARAM lparam,
115 LRESULT* result) {
116 return false;
117 }
118};
119
120// A test helper that owns a stub implementation, making it the test stub for
121// the lifetime of the object, then restoring the previous value.
123 public:
124 // Calls SetTestFlutterStub with |stub|.
125 ScopedStubFlutterWindowsApi(std::unique_ptr<StubFlutterWindowsApi> stub);
126
127 // Restores the previous test stub.
129
130 StubFlutterWindowsApi* stub() { return stub_.get(); }
131
132 private:
133 std::unique_ptr<StubFlutterWindowsApi> stub_;
134 // The previous stub.
135 StubFlutterWindowsApi* previous_stub_;
136};
137
138} // namespace testing
139} // namespace flutter
140
141#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_TESTING_STUB_FLUTTER_WINDOWS_API_H_
ScopedStubFlutterWindowsApi(std::unique_ptr< StubFlutterWindowsApi > stub)
virtual bool ViewControllerHandleTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT *result)
virtual void EngineSetNextFrameCallback(VoidCallback callback, void *user_data)
virtual FlutterDesktopEngineRef EngineCreate(const FlutterDesktopEngineProperties &engine_properties)
virtual FlutterDesktopViewRef PluginRegistrarGetViewById(FlutterDesktopViewId view_id)
virtual FlutterDesktopViewControllerRef ViewControllerCreate(int width, int height, FlutterDesktopEngineRef engine)
virtual bool EngineRun(const char *entry_point)
virtual void EngineRegisterPlatformViewType(const char *view_type_name, FlutterPlatformViewTypeEntry view_type)
static void SetTestStub(StubFlutterWindowsApi *stub)
static StubFlutterWindowsApi * GetTestStub()
virtual void PluginRegistrarUnregisterTopLevelWindowProcDelegate(FlutterDesktopWindowProcCallback delegate)
virtual FlutterDesktopViewRef PluginRegistrarGetView()
virtual void PluginRegistrarRegisterTopLevelWindowProcDelegate(FlutterDesktopWindowProcCallback delegate, void *user_data)
virtual bool EngineProcessExternalWindowMessage(FlutterDesktopEngineRef engine, HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT *result)
FlutterEngine engine
Definition: main.cc:68
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
GAsyncResult * result
struct FlutterDesktopViewController * FlutterDesktopViewControllerRef
bool(* FlutterDesktopWindowProcCallback)(HWND, UINT, WPARAM, LPARAM, void *, LRESULT *result)
int64_t FlutterDesktopViewId
struct FlutterDesktopView * FlutterDesktopViewRef
Win32Message message
int32_t height
int32_t width
void * user_data
LONG_PTR LRESULT
Definition: windows_types.h:61
unsigned int UINT
Definition: windows_types.h:32
LONG_PTR LPARAM
Definition: windows_types.h:60
UINT_PTR WPARAM
Definition: windows_types.h:59