forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partially port FML to Windows. (flutter#3562)
* Partially port FML to Windows. * Adds a message loop impl for Windows * Ports `thread.cc` to Windows All FML unittests are now passing on Windows. FML as a whole does not compile on windows yet because `mapping.cc` imports `sys/mman.h`, which is not available on Windows and the replacement API for memory-mapped files is very different on Windows, see https://msdn.microsoft.com/en-us/library/windows/desktop/aa366556%28v=vs.85%29.aspx. * update licenses * review comments
- Loading branch information
1 parent
5d9a642
commit 772a0db
Showing
7 changed files
with
131 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/fml/platform/win/message_loop_win.h" | ||
|
||
namespace fml { | ||
|
||
MessageLoopWin::MessageLoopWin() | ||
: timer_(CreateWaitableTimer(NULL, FALSE, NULL)) { | ||
FTL_CHECK(timer_.is_valid()); | ||
} | ||
|
||
MessageLoopWin::~MessageLoopWin() = default; | ||
|
||
void MessageLoopWin::Run() { | ||
running_ = true; | ||
|
||
while (running_) { | ||
FTL_CHECK(WaitForSingleObject(timer_.get(), INFINITE) == 0); | ||
RunExpiredTasksNow(); | ||
} | ||
} | ||
|
||
void MessageLoopWin::Terminate() { | ||
running_ = false; | ||
WakeUp(ftl::TimePoint::Now()); | ||
} | ||
|
||
void MessageLoopWin::WakeUp(ftl::TimePoint time_point) { | ||
LARGE_INTEGER due_time = {0}; | ||
ftl::TimePoint now = ftl::TimePoint::Now(); | ||
if (time_point > now) { | ||
due_time.QuadPart = (time_point - now).ToNanoseconds() / -100; | ||
} | ||
FTL_CHECK(SetWaitableTimer(timer_.get(), &due_time, 0, NULL, NULL, FALSE)); | ||
} | ||
|
||
} // namespace fml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_FML_PLATFORM_WIN_MESSAGE_LOOP_WIN_H_ | ||
#define FLUTTER_FML_PLATFORM_WIN_MESSAGE_LOOP_WIN_H_ | ||
|
||
#include <atomic> | ||
|
||
#include <windows.h> | ||
|
||
#include "flutter/fml/message_loop_impl.h" | ||
#include "lib/ftl/macros.h" | ||
#include "lib/ftl/memory/unique_object.h" | ||
|
||
namespace fml { | ||
|
||
class MessageLoopWin : public MessageLoopImpl { | ||
private: | ||
struct UniqueHandleTraits { | ||
static HANDLE InvalidValue() { return NULL; } | ||
static bool IsValid(HANDLE value) { return value != NULL; } | ||
static void Free(HANDLE value) { CloseHandle(value); } | ||
}; | ||
|
||
bool running_; | ||
ftl::UniqueObject<HANDLE, UniqueHandleTraits> timer_; | ||
|
||
MessageLoopWin(); | ||
|
||
~MessageLoopWin() override; | ||
|
||
void Run() override; | ||
|
||
void Terminate() override; | ||
|
||
void WakeUp(ftl::TimePoint time_point) override; | ||
|
||
FRIEND_MAKE_REF_COUNTED(MessageLoopWin); | ||
FRIEND_REF_COUNTED_THREAD_SAFE(MessageLoopWin); | ||
FTL_DISALLOW_COPY_AND_ASSIGN(MessageLoopWin); | ||
}; | ||
|
||
} // namespace fml | ||
|
||
#endif // FLUTTER_FML_PLATFORM_GENERIC_MESSAGE_LOOP_GENERIC_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters