Flutter Engine
stub_flutter_glfw_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/glfw/client_wrapper/testing/stub_flutter_glfw_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<StubFlutterGlfwApi> stub)
24  : stub_(std::move(stub)) {
25  previous_stub_ = StubFlutterGlfwApi::GetTestStub();
27 }
28 
30  StubFlutterGlfwApi::SetTestStub(previous_stub_);
31 }
32 
33 } // namespace testing
34 } // namespace flutter
35 
36 // Forwarding dummy implementations of the C API.
37 
39  if (s_stub_implementation) {
40  s_stub_implementation->Init();
41  }
42  return true;
43 }
44 
46  if (s_stub_implementation) {
47  s_stub_implementation->Terminate();
48  }
49 }
50 
52  const FlutterDesktopWindowProperties& window_properties,
53  const FlutterDesktopEngineProperties& engine_properties) {
54  if (s_stub_implementation) {
55  return s_stub_implementation->CreateWindow(window_properties,
56  engine_properties);
57  }
58  return nullptr;
59 }
60 
62  if (s_stub_implementation) {
63  s_stub_implementation->DestroyWindow();
64  }
65 }
66 
68  bool enabled) {
69  if (s_stub_implementation) {
70  s_stub_implementation->SetHoverEnabled(enabled);
71  }
72 }
73 
75  const char* title) {
76  if (s_stub_implementation) {
77  s_stub_implementation->SetWindowTitle(title);
78  }
79 }
80 
82  uint8_t* pixel_data,
83  int width,
84  int height) {
85  if (s_stub_implementation) {
86  s_stub_implementation->SetWindowIcon(pixel_data, width, height);
87  }
88 }
89 
91  int* x,
92  int* y,
93  int* width,
94  int* height) {
95  if (s_stub_implementation) {
96  s_stub_implementation->GetWindowFrame(x, y, width, height);
97  }
98 }
99 
101  int x,
102  int y,
103  int width,
104  int height) {
105  if (s_stub_implementation) {
106  s_stub_implementation->SetWindowFrame(x, y, width, height);
107  }
108 }
109 
111  FlutterDesktopSize minimum_size,
112  FlutterDesktopSize maximum_size) {
113  if (s_stub_implementation) {
114  s_stub_implementation->SetSizeLimits(minimum_size, maximum_size);
115  }
116 }
117 
119  FlutterDesktopWindowRef flutter_window) {
120  if (s_stub_implementation) {
121  return s_stub_implementation->GetWindowScaleFactor();
122  }
123  return 1.0;
124 }
125 
127  FlutterDesktopWindowRef flutter_window,
128  double pixel_ratio) {
129  if (s_stub_implementation) {
130  return s_stub_implementation->SetPixelRatioOverride(pixel_ratio);
131  }
132 }
133 
136  uint32_t millisecond_timeout) {
137  if (s_stub_implementation) {
138  return s_stub_implementation->RunWindowEventLoopWithTimeout(
139  millisecond_timeout);
140  }
141  return true;
142 }
143 
145  const FlutterDesktopEngineProperties& properties) {
146  if (s_stub_implementation) {
147  return s_stub_implementation->RunEngine(properties);
148  }
149  return nullptr;
150 }
151 
154  uint32_t timeout_milliseconds) {
155  if (s_stub_implementation) {
156  s_stub_implementation->RunEngineEventLoopWithTimeout(timeout_milliseconds);
157  }
158 }
159 
161  if (s_stub_implementation) {
162  return s_stub_implementation->ShutDownEngine();
163  }
164  return true;
165 }
166 
169  // The stub ignores this, so just return an arbitrary non-zero value.
170  return reinterpret_cast<FlutterDesktopWindowRef>(1);
171 }
172 
175  // The stub ignores this, so just return an arbitrary non-zero value.
176  return reinterpret_cast<FlutterDesktopEngineRef>(3);
177 }
178 
181  const char* plugin_name) {
182  // The stub ignores this, so just return an arbitrary non-zero value.
183  return reinterpret_cast<FlutterDesktopPluginRegistrarRef>(2);
184 }
185 
188  // The stub ignores this, so just return an arbitrary non-zero value.
189  return reinterpret_cast<FlutterDesktopWindowRef>(3);
190 }
191 
194  const char* channel) {
195  if (s_stub_implementation) {
196  s_stub_implementation->PluginRegistrarEnableInputBlocking(channel);
197  }
198 }
void FlutterDesktopWindowGetFrame(FlutterDesktopWindowRef flutter_window, int *x, int *y, int *width, int *height)
bool FlutterDesktopInit()
void FlutterDesktopWindowSetPixelRatioOverride(FlutterDesktopWindowRef flutter_window, double pixel_ratio)
virtual void SetSizeLimits(FlutterDesktopSize minimum_size, FlutterDesktopSize maximum_size)
void FlutterDesktopWindowSetIcon(FlutterDesktopWindowRef flutter_window, uint8_t *pixel_data, int width, int height)
void FlutterDesktopTerminate()
void FlutterDesktopWindowSetTitle(FlutterDesktopWindowRef flutter_window, const char *title)
virtual void SetHoverEnabled(bool enabled)
double FlutterDesktopWindowGetScaleFactor(FlutterDesktopWindowRef flutter_window)
void FlutterDesktopWindowSetHoverEnabled(FlutterDesktopWindowRef flutter_window, bool enabled)
virtual void SetWindowIcon(uint8_t *pixel_data, int width, int height)
Definition: ref_ptr.h:252
virtual void SetPixelRatioOverride(double pixel_ratio)
FlutterDesktopEngineRef FlutterDesktopGetEngine(FlutterDesktopWindowControllerRef controller)
bool FlutterDesktopShutDownEngine(FlutterDesktopEngineRef engine_ref)
bool FlutterDesktopRunWindowEventLoopWithTimeout(FlutterDesktopWindowControllerRef controller, uint32_t millisecond_timeout)
void FlutterDesktopDestroyWindow(FlutterDesktopWindowControllerRef controller)
static void SetTestStub(StubFlutterGlfwApi *stub)
virtual FlutterDesktopWindowControllerRef CreateWindow(const FlutterDesktopWindowProperties &window_properties, const FlutterDesktopEngineProperties &engine_properties)
void FlutterDesktopWindowSetFrame(FlutterDesktopWindowRef flutter_window, int x, int y, int width, int height)
void FlutterDesktopPluginRegistrarEnableInputBlocking(FlutterDesktopPluginRegistrarRef registrar, const char *channel)
FlutterDesktopWindowRef FlutterDesktopGetWindow(FlutterDesktopWindowControllerRef controller)
ScopedStubFlutterGlfwApi(std::unique_ptr< StubFlutterGlfwApi > stub)
virtual void SetWindowTitle(const char *title)
FlutterDesktopWindowRef FlutterDesktopPluginRegistrarGetWindow(FlutterDesktopPluginRegistrarRef registrar)
void FlutterDesktopWindowSetSizeLimits(FlutterDesktopWindowRef flutter_window, FlutterDesktopSize minimum_size, FlutterDesktopSize maximum_size)
int32_t height
FlutterDesktopEngineRef FlutterDesktopRunEngine(const FlutterDesktopEngineProperties &properties)
int32_t width
static StubFlutterGlfwApi * GetTestStub()
virtual void PluginRegistrarEnableInputBlocking(const char *channel)
virtual void SetWindowFrame(int x, int y, int width, int height)
virtual void GetWindowFrame(int *x, int *y, int *width, int *height)
virtual bool RunWindowEventLoopWithTimeout(uint32_t millisecond_timeout)
static flutter::testing::StubFlutterGlfwApi * s_stub_implementation
FlutterDesktopPluginRegistrarRef FlutterDesktopGetPluginRegistrar(FlutterDesktopEngineRef engine, const char *plugin_name)
FlutterDesktopWindowControllerRef FlutterDesktopCreateWindow(const FlutterDesktopWindowProperties &window_properties, const FlutterDesktopEngineProperties &engine_properties)
virtual FlutterDesktopEngineRef RunEngine(const FlutterDesktopEngineProperties &properties)
virtual void RunEngineEventLoopWithTimeout(uint32_t millisecond_timeout)
void FlutterDesktopRunEngineEventLoopWithTimeout(FlutterDesktopEngineRef engine, uint32_t timeout_milliseconds)