Flutter Engine
stub_flutter_windows_api.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 "flutter/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.h"
6 
8 
9 namespace flutter {
10 namespace testing {
11 
12 // static
14  s_stub_implementation = stub;
15 }
16 
17 // static
19  return s_stub_implementation;
20 }
21 
23  std::unique_ptr<StubFlutterWindowsApi> stub)
24  : stub_(std::move(stub)) {
25  previous_stub_ = StubFlutterWindowsApi::GetTestStub();
27 }
28 
30  StubFlutterWindowsApi::SetTestStub(previous_stub_);
31 }
32 
33 } // namespace testing
34 } // namespace flutter
35 
36 // Forwarding dummy implementations of the C API.
37 
39  int width,
40  int height,
42  if (s_stub_implementation) {
43  return s_stub_implementation->ViewControllerCreate(width, height, engine);
44  }
45  return nullptr;
46 }
47 
50  if (s_stub_implementation) {
51  s_stub_implementation->ViewControllerDestroy();
52  }
53 }
54 
57  // The stub ignores this, so just return an arbitrary non-zero value.
58  return reinterpret_cast<FlutterDesktopEngineRef>(1);
59 }
60 
63  // The stub ignores this, so just return an arbitrary non-zero value.
64  return reinterpret_cast<FlutterDesktopViewRef>(1);
65 }
66 
68  FlutterDesktopViewControllerRef controller) {}
69 
72  HWND hwnd,
73  UINT message,
74  WPARAM wparam,
75  LPARAM lparam,
76  LRESULT* result) {
77  if (s_stub_implementation) {
78  return s_stub_implementation->ViewControllerHandleTopLevelWindowProc(
79  hwnd, message, wparam, lparam, result);
80  }
81  return false;
82 }
83 
85  const FlutterDesktopEngineProperties* engine_properties) {
86  if (s_stub_implementation) {
87  return s_stub_implementation->EngineCreate(*engine_properties);
88  }
89  return nullptr;
90 }
91 
93  if (s_stub_implementation) {
94  return s_stub_implementation->EngineDestroy();
95  }
96  return true;
97 }
98 
100  const char* entry_point) {
101  if (s_stub_implementation) {
102  return s_stub_implementation->EngineRun(entry_point);
103  }
104  return true;
105 }
106 
108  if (s_stub_implementation) {
109  return s_stub_implementation->EngineProcessMessages();
110  }
111  return 0;
112 }
113 
115  if (s_stub_implementation) {
116  s_stub_implementation->EngineReloadSystemFonts();
117  }
118 }
119 
122  if (s_stub_implementation) {
123  s_stub_implementation->EngineReloadPlatformBrightness();
124  }
125 }
126 
129  const char* plugin_name) {
130  // The stub ignores this, so just return an arbitrary non-zero value.
131  return reinterpret_cast<FlutterDesktopPluginRegistrarRef>(1);
132 }
133 
136  // The stub ignores this, so just return an arbitrary non-zero value.
137  return reinterpret_cast<FlutterDesktopMessengerRef>(2);
138 }
139 
142  // The stub ignores this, so just return an arbitrary non-zero value.
143  return reinterpret_cast<FlutterDesktopTextureRegistrarRef>(3);
144 }
145 
147  if (s_stub_implementation) {
148  return s_stub_implementation->ViewGetHWND();
149  }
150  return reinterpret_cast<HWND>(-1);
151 }
152 
155  // The stub ignores this, so just return an arbitrary non-zero value.
156  return reinterpret_cast<FlutterDesktopViewRef>(1);
157 }
158 
162  void* user_data) {
163  if (s_stub_implementation) {
164  return s_stub_implementation
166  user_data);
167  }
168 }
169 
173  if (s_stub_implementation) {
174  return s_stub_implementation
176  }
177 }
virtual bool ViewControllerHandleTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT *result)
ScopedStubFlutterWindowsApi(std::unique_ptr< StubFlutterWindowsApi > stub)
FlutterDesktopEngineRef FlutterDesktopEngineCreate(const FlutterDesktopEngineProperties *engine_properties)
HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef controller)
FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine(FlutterDesktopViewControllerRef controller)
FlutterDesktopTextureRegistrarRef FlutterDesktopEngineGetTextureRegistrar(FlutterDesktopEngineRef engine)
void FlutterDesktopEngineReloadSystemFonts(FlutterDesktopEngineRef engine)
void FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate(FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopWindowProcCallback delegate, void *user_data)
bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine_ref)
FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate(int width, int height, FlutterDesktopEngineRef engine)
WINUWP.
void * user_data
Definition: ref_ptr.h:252
void FlutterDesktopViewControllerDestroy(FlutterDesktopViewControllerRef controller)
GAsyncResult * result
void FlutterDesktopEngineReloadPlatformBrightness(FlutterDesktopEngineRef engine)
LONG_PTR LRESULT
Definition: windows_types.h:61
struct FlutterDesktopTextureRegistrar * FlutterDesktopTextureRegistrarRef
UINT_PTR WPARAM
Definition: windows_types.h:59
struct FlutterDesktopView * FlutterDesktopViewRef
uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine)
FlutterDesktopMessengerRef FlutterDesktopEngineGetMessenger(FlutterDesktopEngineRef engine)
void FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate(FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopWindowProcCallback delegate)
FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar(FlutterDesktopEngineRef engine, const char *plugin_name)
int32_t width
bool(* FlutterDesktopWindowProcCallback)(HWND, UINT, WPARAM, LPARAM, void *, LRESULT *result)
static flutter::testing::StubFlutterWindowsApi * s_stub_implementation
int32_t height
static void SetTestStub(StubFlutterWindowsApi *stub)
FlutterDesktopViewRef FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef controller)
static StubFlutterWindowsApi * GetTestStub()
LONG_PTR LPARAM
Definition: windows_types.h:60
virtual void PluginRegistrarRegisterTopLevelWindowProcDelegate(FlutterDesktopWindowProcCallback delegate, void *user_data)
bool FlutterDesktopViewControllerHandleTopLevelWindowProc(FlutterDesktopViewControllerRef controller, HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT *result)
virtual FlutterDesktopViewControllerRef ViewControllerCreate(int width, int height, FlutterDesktopEngineRef engine)
unsigned int UINT
Definition: windows_types.h:32
void FlutterDesktopViewControllerForceRedraw(FlutterDesktopViewControllerRef controller)
virtual bool EngineRun(const char *entry_point)
virtual FlutterDesktopEngineRef EngineCreate(const FlutterDesktopEngineProperties &engine_properties)
FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView(FlutterDesktopPluginRegistrarRef controller)
bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, const char *entry_point)
virtual void PluginRegistrarUnregisterTopLevelWindowProcDelegate(FlutterDesktopWindowProcCallback delegate)