浏览代码

fix vsync issue on plugin side

/prepare_2.0.6
Xingwei Zhu 3 年前
当前提交
ee9a5c09
共有 20 个文件被更改,包括 65 次插入78 次删除
  1. 6
      engine/src/shell/platform/unity/android/uiwidgets_panel.cc
  2. 2
      engine/src/shell/platform/unity/android/uiwidgets_panel.h
  3. 21
      engine/src/shell/platform/unity/android/uiwidgets_system.cc
  4. 4
      engine/src/shell/platform/unity/android/uiwidgets_system.h
  5. 2
      engine/src/shell/platform/unity/darwin/ios/uiwidgets_panel.h
  6. 8
      engine/src/shell/platform/unity/darwin/ios/uiwidgets_panel.mm
  7. 4
      engine/src/shell/platform/unity/darwin/ios/uiwidgets_system.h
  8. 21
      engine/src/shell/platform/unity/darwin/ios/uiwidgets_system.mm
  9. 2
      engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.h
  10. 8
      engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.mm
  11. 4
      engine/src/shell/platform/unity/darwin/macos/uiwidgets_system.h
  12. 21
      engine/src/shell/platform/unity/darwin/macos/uiwidgets_system.mm
  13. 8
      engine/src/shell/platform/unity/windows/uiwidgets_panel.cc
  14. 2
      engine/src/shell/platform/unity/windows/uiwidgets_panel.h
  15. 23
      engine/src/shell/platform/unity/windows/uiwidgets_system.cc
  16. 4
      engine/src/shell/platform/unity/windows/uiwidgets_system.h
  17. 3
      engine/third_party/Unity/IUnityUIWidgets.h

6
engine/src/shell/platform/unity/android/uiwidgets_panel.cc


ProcessMessages();
// drain pending vsync batons
ProcessVSync();
ProcessVSync(0);
process_events_ = false;

return std::chrono::nanoseconds(task_runner_->ProcessTasks().count());
}
void UIWidgetsPanel::ProcessVSync()
void UIWidgetsPanel::ProcessVSync(double frame_duration)
{
std::vector<intptr_t> batons;
vsync_batons_.swap(batons);

reinterpret_cast<EmbedderEngine *>(engine_)->OnVsyncEvent(
baton, fml::TimePoint::Now(),
fml::TimePoint::Now() +
fml::TimeDelta::FromNanoseconds(1000000000 / 60));
fml::TimeDelta::FromNanoseconds(1000000000 * frame_duration));
}
}

2
engine/src/shell/platform/unity/android/uiwidgets_panel.h


std::chrono::nanoseconds ProcessMessages();
void ProcessVSync();
void ProcessVSync(double frame_duration);
void VSyncCallback(intptr_t baton);

21
engine/src/shell/platform/unity/android/uiwidgets_system.cc


}
void UIWidgetsSystem::Wait(std::chrono::nanoseconds max_duration) {
Update();
std::chrono::nanoseconds wait_duration =
std::max(std::chrono::nanoseconds(0),
next_uiwidgets_event_time_ - TimePoint::clock::now());
wait_duration = std::min(max_duration, wait_duration);
//TODO: find a proper api similar to MsgWaitForMultipleObjects on Windows
// which will notify os to wait for the given period of time
//do nothing
}
void UIWidgetsSystem::Update() {

next_uiwidgets_event_time_ = next_event_time;
}
void UIWidgetsSystem::VSync() {
void UIWidgetsSystem::VSync(double frame_duration) {
//use default frame_duration if undefined in Unity engine
if (frame_duration <= 0)
{
frame_duration = 1.0 / 60;
}
uiwidgets_panel->ProcessVSync();
uiwidgets_panel->ProcessVSync(frame_duration);
}
}

4
engine/src/shell/platform/unity/android/uiwidgets_system.h


GetInstancePtr()->Wait(std::chrono::nanoseconds(max_duration));
}
UIWIDGETS_CALLBACK(void) _VSync() { GetInstancePtr()->VSync(); }
UIWIDGETS_CALLBACK(void) _VSync(double frame_duration) { GetInstancePtr()->VSync(frame_duration); }
UIWIDGETS_CALLBACK(void) _WakeUp() { GetInstancePtr()->WakeUp(); }

void Update();
void Wait(std::chrono::nanoseconds max_duration);
void VSync();
void VSync(double frame_duration);
void WakeUp();
void GfxWorkerCallback(int eventId, void* data);

2
engine/src/shell/platform/unity/darwin/ios/uiwidgets_panel.h


std::chrono::nanoseconds ProcessMessages();
void ProcessVSync();
void ProcessVSync(double frame_duration);
void VSyncCallback(intptr_t baton);

8
engine/src/shell/platform/unity/darwin/ios/uiwidgets_panel.mm


ProcessMessages();
// drain pending vsync batons
ProcessVSync();
ProcessVSync(0);
process_events_ = false;

return std::chrono::nanoseconds(task_runner_->ProcessTasks().count());
}
void UIWidgetsPanel::ProcessVSync() {
void UIWidgetsPanel::ProcessVSync(double frame_duration) {
std::vector<intptr_t> batons;
vsync_batons_.swap(batons);

fml::TimePoint::Now() +
fml::TimeDelta::FromNanoseconds(1000000000 / 60));
fml::TimeDelta::FromNanoseconds(1000000000 * frame_duration));
}
}

panel->ProcessMessages();
//_ProcessVSync
panel->ProcessVSync();
panel->ProcessVSync(0);
//_Wait
panel->ProcessMessages();

4
engine/src/shell/platform/unity/darwin/ios/uiwidgets_system.h


GetInstancePtr()->Wait(std::chrono::nanoseconds(max_duration));
}
UIWIDGETS_CALLBACK(void) _VSync() { GetInstancePtr()->VSync(); }
UIWIDGETS_CALLBACK(void) _VSync(double frame_duration) { GetInstancePtr()->VSync(frame_duration); }
UIWIDGETS_CALLBACK(void) _WakeUp() { GetInstancePtr()->WakeUp(); }

void Update();
void Wait(std::chrono::nanoseconds max_duration);
void VSync();
void VSync(double frame_duration);
void WakeUp();
void GfxWorkerCallback(int eventId, void* data);

21
engine/src/shell/platform/unity/darwin/ios/uiwidgets_system.mm


}
void UIWidgetsSystem::Wait(std::chrono::nanoseconds max_duration) {
Update();
std::chrono::nanoseconds wait_duration =
std::max(std::chrono::nanoseconds(0),
next_uiwidgets_event_time_ - TimePoint::clock::now());
wait_duration = std::min(max_duration, wait_duration);
//TODO: find a proper api similar to MsgWaitForMultipleObjects on Windows
// which will notify os to wait for the given period of time
//do nothing
}
void UIWidgetsSystem::Update() {

next_uiwidgets_event_time_ = next_event_time;
}
void UIWidgetsSystem::VSync() {
void UIWidgetsSystem::VSync(double frame_duration) {
//use default frame_duration if undefined in Unity engine
if (frame_duration <= 0)
{
frame_duration = 1.0 / 60;
}
uiwidgets_panel->ProcessVSync();
uiwidgets_panel->ProcessVSync(frame_duration);
}
}

2
engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.h


std::chrono::nanoseconds ProcessMessages();
void ProcessVSync();
void ProcessVSync(double frame_duration);
void VSyncCallback(intptr_t baton);

8
engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.mm


ProcessMessages();
// drain pending vsync batons
ProcessVSync();
ProcessVSync(0);
process_events_ = false;

return std::chrono::nanoseconds(task_runner_->ProcessTasks().count());
}
void UIWidgetsPanel::ProcessVSync() {
void UIWidgetsPanel::ProcessVSync(double frame_duration) {
std::vector<intptr_t> batons;
vsync_batons_.swap(batons);

fml::TimePoint::Now() +
fml::TimeDelta::FromNanoseconds(1000000000 / 60));
fml::TimeDelta::FromNanoseconds(1000000000 * frame_duration));
}
}

panel->ProcessMessages();
//_ProcessVSync
panel->ProcessVSync();
panel->ProcessVSync(0);
//_Wait
panel->ProcessMessages();

4
engine/src/shell/platform/unity/darwin/macos/uiwidgets_system.h


GetInstancePtr()->Wait(std::chrono::nanoseconds(max_duration));
}
UIWIDGETS_CALLBACK(void) _VSync() { GetInstancePtr()->VSync(); }
UIWIDGETS_CALLBACK(void) _VSync(double frame_duration) { GetInstancePtr()->VSync(frame_duration); }
UIWIDGETS_CALLBACK(void) _WakeUp() { GetInstancePtr()->WakeUp(); }

void Update();
void Wait(std::chrono::nanoseconds max_duration);
void VSync();
void VSync(double frame_duration);
void WakeUp();
void GfxWorkerCallback(int eventId, void* data);

21
engine/src/shell/platform/unity/darwin/macos/uiwidgets_system.mm


}
void UIWidgetsSystem::Wait(std::chrono::nanoseconds max_duration) {
Update();
std::chrono::nanoseconds wait_duration =
std::max(std::chrono::nanoseconds(0),
next_uiwidgets_event_time_ - TimePoint::clock::now());
wait_duration = std::min(max_duration, wait_duration);
//TODO: find a proper api similar to MsgWaitForMultipleObjects on Windows
// which will notify os to wait for the given period of time
//do nothing
}
void UIWidgetsSystem::Update() {

next_uiwidgets_event_time_ = next_event_time;
}
void UIWidgetsSystem::VSync() {
void UIWidgetsSystem::VSync(double frame_duration) {
//use default frame_duration if undefined in Unity engine
if (frame_duration <= 0)
{
frame_duration = 1.0 / 60;
}
uiwidgets_panel->ProcessVSync();
uiwidgets_panel->ProcessVSync(frame_duration);
}
}

8
engine/src/shell/platform/unity/windows/uiwidgets_panel.cc


ProcessMessages();
// drain pending vsync batons
ProcessVSync();
ProcessVSync(0);
process_events_ = false;

return std::chrono::nanoseconds(task_runner_->ProcessTasks().count());
}
void UIWidgetsPanel::ProcessVSync() {
void UIWidgetsPanel::ProcessVSync(double frame_duration) {
std::vector<intptr_t> batons;
vsync_batons_.swap(batons);

fml::TimePoint::Now() +
fml::TimeDelta::FromNanoseconds(1000000000 / 60));
fml::TimeDelta::FromNanoseconds(1000000000 * frame_duration));
}
}

panel->ProcessMessages();
//_ProcessVSync
panel->ProcessVSync();
panel->ProcessVSync(0);
//_Wait
panel->ProcessMessages();

2
engine/src/shell/platform/unity/windows/uiwidgets_panel.h


std::chrono::nanoseconds ProcessMessages();
void ProcessVSync();
void ProcessVSync(double frame_duration);
void VSyncCallback(intptr_t baton);

23
engine/src/shell/platform/unity/windows/uiwidgets_system.cc


}
void UIWidgetsSystem::Wait(std::chrono::nanoseconds max_duration) {
Update();
std::chrono::nanoseconds wait_duration =
std::max(std::chrono::nanoseconds(0),
next_uiwidgets_event_time_ - TimePoint::clock::now());
wait_duration = std::min(max_duration, wait_duration);
wait_duration = std::max(std::chrono::nanoseconds(0), wait_duration);
::MsgWaitForMultipleObjects(0, nullptr, FALSE,
static_cast<DWORD>(wait_duration.count() / 1000000),
QS_ALLINPUT);
//do nothing
}
void UIWidgetsSystem::Update() {

next_uiwidgets_event_time_ = next_event_time;
}
void UIWidgetsSystem::VSync() {
void UIWidgetsSystem::VSync(double frame_duration) {
//use default frame_duration if undefined in Unity engine
if (frame_duration <= 0)
{
frame_duration = 1.0 / 60;
}
uiwidgets_panel->ProcessVSync();
uiwidgets_panel->ProcessVSync(frame_duration);
}
}

4
engine/src/shell/platform/unity/windows/uiwidgets_system.h


GetInstancePtr()->Wait(std::chrono::nanoseconds(max_duration));
}
UIWIDGETS_CALLBACK(void) _VSync() { GetInstancePtr()->VSync(); }
UIWIDGETS_CALLBACK(void) _VSync(double frame_duration) { GetInstancePtr()->VSync(frame_duration); }
UIWIDGETS_CALLBACK(void) _WakeUp() { GetInstancePtr()->WakeUp(); }

void Update();
void Wait(std::chrono::nanoseconds max_duration);
void VSync();
void VSync(double frame_duration);
void WakeUp();
void GfxWorkerCallback(int eventId, void* data);

3
engine/third_party/Unity/IUnityUIWidgets.h


namespace UnityUIWidgets {
typedef void (*VoidCallback)();
typedef void (*VoidCallbackLong)(long);
typedef void (*VoidCallbackDouble)(double);
virtual void SetVSyncCallback(VoidCallback callback) = 0;
virtual void SetVSyncCallback(VoidCallbackDouble callback) = 0;
virtual void SetWaitCallback(VoidCallbackLong callback) = 0;
virtual void SetWakeUpCallback(VoidCallback callback) = 0;
virtual void IssuePluginEventAndData(UnityRenderingEventAndData callback,

部分文件因为文件数量过多而无法显示

正在加载...
取消
保存