Flutter Engine
 
Loading...
Searching...
No Matches
task_runner_window.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_TASK_RUNNER_WINDOW_H_
6#define FLUTTER_SHELL_PLATFORM_WINDOWS_TASK_RUNNER_WINDOW_H_
7
8#include <windows.h>
9
10#include <chrono>
11#include <memory>
12#include <string>
13#include <vector>
14
15#include "flutter/fml/macros.h"
16
17namespace flutter {
18
19// Hidden HWND responsible for processing flutter tasks on main thread
21 public:
22 class Delegate {
23 public:
24 // Executes expired task, and returns the duration until the next task
25 // deadline if exists, otherwise returns `std::chrono::nanoseconds::max()`.
26 //
27 // Each platform implementation must call this to schedule the tasks.
28 virtual std::chrono::nanoseconds ProcessTasks() = 0;
29 };
30
31 static std::shared_ptr<TaskRunnerWindow> GetSharedInstance();
32
33 // Triggers processing delegate tasks on main thread
34 void WakeUp();
35
36 void AddDelegate(Delegate* delegate);
37 void RemoveDelegate(Delegate* delegate);
38
39 void PollOnce(std::chrono::milliseconds timeout);
40
42
43 private:
45
46 void ProcessTasks();
47
48 void SetTimer(std::chrono::nanoseconds when);
49
50 WNDCLASS RegisterWindowClass();
51
53 HandleMessage(UINT const message,
54 WPARAM const wparam,
55 LPARAM const lparam) noexcept;
56
57 static LRESULT CALLBACK WndProc(HWND const window,
58 UINT const message,
59 WPARAM const wparam,
60 LPARAM const lparam) noexcept;
61
62 void OnTimer();
63
64 static void TimerProc(PTP_CALLBACK_INSTANCE Instance,
66 PTP_TIMER Timer);
67
68 HWND window_handle_;
69 std::wstring window_class_name_;
70 std::vector<Delegate*> delegates_;
71 PTP_TIMER timer_ = nullptr;
72 DWORD thread_id_ = 0;
73
75};
76} // namespace flutter
77
78#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TASK_RUNNER_WINDOW_H_
virtual std::chrono::nanoseconds ProcessTasks()=0
void PollOnce(std::chrono::milliseconds timeout)
static std::shared_ptr< TaskRunnerWindow > GetSharedInstance()
void AddDelegate(Delegate *delegate)
void RemoveDelegate(Delegate *delegate)
To do anything rendering related with Impeller, you need a context.
Definition context.h:65
GLFWwindow * window
Definition main.cc:60
G_BEGIN_DECLS GBytes * message
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
void * PVOID
LONG_PTR LRESULT
unsigned int UINT
LONG_PTR LPARAM
UINT_PTR WPARAM
unsigned long DWORD
#define CALLBACK