mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Auto merge of #23900 - paulrouget:tasks, r=jdm
Use tasks instead of events <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23900) <!-- Reviewable:end -->
This commit is contained in:
commit
45af8a34fe
3 changed files with 19 additions and 55 deletions
|
@ -36,7 +36,7 @@ void BrowserPage::Shutdown() {
|
||||||
// shutdown event to Servo.
|
// shutdown event to Servo.
|
||||||
} else {
|
} else {
|
||||||
HANDLE hEvent = ::CreateEventA(nullptr, FALSE, FALSE, sShutdownEvent);
|
HANDLE hEvent = ::CreateEventA(nullptr, FALSE, FALSE, sShutdownEvent);
|
||||||
SendEventToServo({{Event::SHUTDOWN}});
|
RunOnGLThread([=] {mServo->RequestShutdown();});
|
||||||
log("Waiting for Servo to shutdown");
|
log("Waiting for Servo to shutdown");
|
||||||
::WaitForSingleObject(hEvent, INFINITE);
|
::WaitForSingleObject(hEvent, INFINITE);
|
||||||
StopRenderLoop();
|
StopRenderLoop();
|
||||||
|
@ -132,39 +132,12 @@ void BrowserPage::Loop(cancellation_token cancel) {
|
||||||
if (!mAnimating) {
|
if (!mAnimating) {
|
||||||
::WaitForSingleObject(hEvent, INFINITE);
|
::WaitForSingleObject(hEvent, INFINITE);
|
||||||
}
|
}
|
||||||
mEventsMutex.lock();
|
mTasksMutex.lock();
|
||||||
for (auto &&e : mEvents) {
|
for (auto &&task : mTasks) {
|
||||||
switch (e.type) {
|
task();
|
||||||
case Event::CLICK: {
|
|
||||||
auto [x, y] = e.clickCoords;
|
|
||||||
mServo->Click(x, y);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Event::SCROLL: {
|
|
||||||
auto [x, y, dx, dy] = e.scrollCoords;
|
|
||||||
mServo->Scroll(x, y, dx, dy);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Event::FORWARD:
|
|
||||||
mServo->GoForward();
|
|
||||||
break;
|
|
||||||
case Event::BACK:
|
|
||||||
mServo->GoBack();
|
|
||||||
break;
|
|
||||||
case Event::RELOAD:
|
|
||||||
mServo->Reload();
|
|
||||||
break;
|
|
||||||
case Event::STOP:
|
|
||||||
mServo->Stop();
|
|
||||||
break;
|
|
||||||
case Event::SHUTDOWN:
|
|
||||||
log("Requesting Servo to shutdown");
|
|
||||||
mServo->RequestShutdown();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mEvents.clear();
|
mTasks.clear();
|
||||||
mEventsMutex.unlock();
|
mTasksMutex.unlock();
|
||||||
mServo->PerformUpdates();
|
mServo->PerformUpdates();
|
||||||
}
|
}
|
||||||
log("Leaving loop");
|
log("Leaving loop");
|
||||||
|
@ -271,22 +244,22 @@ template <typename Callable> void BrowserPage::RunOnUIThread(Callable cb) {
|
||||||
|
|
||||||
void BrowserPage::OnBackButtonClicked(IInspectable const &,
|
void BrowserPage::OnBackButtonClicked(IInspectable const &,
|
||||||
RoutedEventArgs const &) {
|
RoutedEventArgs const &) {
|
||||||
SendEventToServo({{Event::BACK}});
|
RunOnGLThread([=] { mServo->GoBack(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserPage::OnForwardButtonClicked(IInspectable const &,
|
void BrowserPage::OnForwardButtonClicked(IInspectable const &,
|
||||||
RoutedEventArgs const &) {
|
RoutedEventArgs const &) {
|
||||||
SendEventToServo({{Event::FORWARD}});
|
RunOnGLThread([=] { mServo->GoForward(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserPage::OnReloadButtonClicked(IInspectable const &,
|
void BrowserPage::OnReloadButtonClicked(IInspectable const &,
|
||||||
RoutedEventArgs const &) {
|
RoutedEventArgs const &) {
|
||||||
SendEventToServo({{Event::RELOAD}});
|
RunOnGLThread([=] { mServo->Reload(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserPage::OnStopButtonClicked(IInspectable const &,
|
void BrowserPage::OnStopButtonClicked(IInspectable const &,
|
||||||
RoutedEventArgs const &) {
|
RoutedEventArgs const &) {
|
||||||
SendEventToServo({{Event::STOP}});
|
RunOnGLThread([=] { mServo->Stop(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserPage::OnImmersiveButtonClicked(IInspectable const &,
|
void BrowserPage::OnImmersiveButtonClicked(IInspectable const &,
|
||||||
|
@ -313,9 +286,7 @@ void BrowserPage::OnSurfaceManipulationDelta(
|
||||||
auto y = e.Position().Y;
|
auto y = e.Position().Y;
|
||||||
auto dx = e.Delta().Translation.X;
|
auto dx = e.Delta().Translation.X;
|
||||||
auto dy = e.Delta().Translation.Y;
|
auto dy = e.Delta().Translation.Y;
|
||||||
Event event = {{Event::SCROLL}};
|
RunOnGLThread([=] { mServo->Scroll(x, y, dx, dy); });
|
||||||
event.scrollCoords = {dx, dy, x, y};
|
|
||||||
SendEventToServo(event);
|
|
||||||
e.Handled(true);
|
e.Handled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,14 +295,14 @@ void BrowserPage::OnSurfaceClicked(IInspectable const &,
|
||||||
auto coords = e.GetCurrentPoint(swapChainPanel());
|
auto coords = e.GetCurrentPoint(swapChainPanel());
|
||||||
auto x = coords.Position().X;
|
auto x = coords.Position().X;
|
||||||
auto y = coords.Position().Y;
|
auto y = coords.Position().Y;
|
||||||
SendEventToServo({{Event::CLICK}, {x, y}});
|
RunOnGLThread([=] { mServo->Click(x, y); });
|
||||||
e.Handled(true);
|
e.Handled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserPage::SendEventToServo(Event event) {
|
void BrowserPage::RunOnGLThread(std::function<void()> task) {
|
||||||
mEventsMutex.lock();
|
mTasksMutex.lock();
|
||||||
mEvents.push_back(event);
|
mTasks.push_back(task);
|
||||||
mEventsMutex.unlock();
|
mTasksMutex.unlock();
|
||||||
WakeUp();
|
WakeUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,6 @@ namespace winrt::ServoApp::implementation {
|
||||||
static char sWakeupEvent[] = "SIGNAL_WAKEUP";
|
static char sWakeupEvent[] = "SIGNAL_WAKEUP";
|
||||||
static char sShutdownEvent[] = "SIGNAL_SHUTDOWN";
|
static char sShutdownEvent[] = "SIGNAL_SHUTDOWN";
|
||||||
|
|
||||||
struct Event {
|
|
||||||
enum { CLICK, SCROLL, BACK, FORWARD, RELOAD, STOP, SHUTDOWN } type;
|
|
||||||
std::tuple<float, float> clickCoords;
|
|
||||||
std::tuple<float, float, float, float> scrollCoords;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BrowserPage : BrowserPageT<BrowserPage>,
|
struct BrowserPage : BrowserPageT<BrowserPage>,
|
||||||
public servo::ServoDelegate {
|
public servo::ServoDelegate {
|
||||||
public:
|
public:
|
||||||
|
@ -44,6 +38,7 @@ public:
|
||||||
Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs const &e);
|
Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs const &e);
|
||||||
|
|
||||||
template <typename Callable> void RunOnUIThread(Callable);
|
template <typename Callable> void RunOnUIThread(Callable);
|
||||||
|
void RunOnGLThread(std::function<void()>);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
virtual void WakeUp();
|
virtual void WakeUp();
|
||||||
|
@ -80,9 +75,8 @@ private:
|
||||||
EGLSurface mRenderSurface{EGL_NO_SURFACE};
|
EGLSurface mRenderSurface{EGL_NO_SURFACE};
|
||||||
std::unique_ptr<servo::Servo> mServo;
|
std::unique_ptr<servo::Servo> mServo;
|
||||||
|
|
||||||
void BrowserPage::SendEventToServo(Event event);
|
std::vector<std::function<void()>> mTasks;
|
||||||
std::vector<Event> mEvents;
|
std::mutex mTasksMutex;
|
||||||
std::mutex mEventsMutex;
|
|
||||||
|
|
||||||
OpenGLES mOpenGLES; // FIXME: shared pointer
|
OpenGLES mOpenGLES; // FIXME: shared pointer
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "Servo.h"
|
#include "Servo.h"
|
||||||
|
|
||||||
// FIXME: rename mozilla to something else
|
|
||||||
namespace servo {
|
namespace servo {
|
||||||
|
|
||||||
void on_load_started() { sServo->Delegate().OnLoadStarted(); }
|
void on_load_started() { sServo->Delegate().OnLoadStarted(); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue