Flutter Engine
engine_modifier.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_TESTING_ENGINE_MODIFIER_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_ENGINE_MODIFIER_H_
7 
8 #include "flutter/shell/platform/windows/flutter_windows_engine.h"
9 
10 #include <chrono>
11 
12 namespace flutter {
13 
14 // A test utility class providing the ability to access and alter various
15 // private fields in an Engine instance.
16 //
17 // This simply provides a way to access the normally-private embedder proc
18 // table, so the lifetime of any changes made to the proc table is that of the
19 // engine object, not this helper.
21  public:
22  explicit EngineModifier(FlutterWindowsEngine* engine) : engine_(engine) {}
23 
24  // Returns the engine's embedder API proc table, allowing for modification.
25  //
26  // Modifications are to the engine, and will last for the lifetime of the
27  // engine unless overwritten again.
28  FlutterEngineProcTable& embedder_api() { return engine_->embedder_api_; }
29 
30  // Explicitly sets the SurfaceManager being used by the FlutterWindowsEngine
31  // instance. This allows us to test fallback paths when a SurfaceManager fails
32  // to initialize for whatever reason.
33  //
34  // Modifications are to the engine, and will last for the lifetime of the
35  // engine unless overwritten again.
36  void SetSurfaceManager(AngleSurfaceManager* surface_manager) {
37  engine_->surface_manager_.reset(surface_manager);
38  }
39 
40  /// Reset the start_time field that is used to align vsync events.
41  void SetStartTime(uint64_t start_time_nanos) {
42  engine_->start_time_ = std::chrono::nanoseconds(start_time_nanos);
43  }
44 
45  /// Override the frame interval to the provided nanosecond interval.
46  ///
47  /// This will prevent the windows engine from delegating to dwm to
48  /// discover the true frame interval, which can vary across machines.
49  void SetFrameInterval(uint64_t frame_interval_nanos) {
50  engine_->frame_interval_override_ =
51  std::optional<std::chrono::nanoseconds>(frame_interval_nanos);
52  }
53 
54  // Explicitly releases the SurfaceManager being used by the
55  // FlutterWindowsEngine instance. This should be used if SetSurfaceManager is
56  // used to explicitly set to a non-null value (but not a valid object) to test
57  // a successful ANGLE initialization.
58  //
59  // Modifications are to the engine, and will last for the lifetime of the
60  // engine unless overwritten again.
61  void ReleaseSurfaceManager() { engine_->surface_manager_.release(); }
62 
63  private:
64  FlutterWindowsEngine* engine_;
65 };
66 
67 } // namespace flutter
68 
69 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_ENGINE_MODIFIER_H_
FlutterEngine engine
Definition: main.cc:66
Function-pointer-based versions of the APIs above.
Definition: embedder.h:2550
void SetFrameInterval(uint64_t frame_interval_nanos)
void SetStartTime(uint64_t start_time_nanos)
Reset the start_time field that is used to align vsync events.
EngineModifier(FlutterWindowsEngine *engine)
FlutterEngineProcTable & embedder_api()
void SetSurfaceManager(AngleSurfaceManager *surface_manager)