Main window, empty GPU files.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
'poly.h',
|
||||
'string.cc',
|
||||
'string.h',
|
||||
'threading.cc',
|
||||
'threading.h',
|
||||
],
|
||||
|
||||
|
||||
18
src/poly/threading.cc
Normal file
18
src/poly/threading.cc
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2014 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <poly/threading.h>
|
||||
|
||||
namespace poly {
|
||||
namespace threading {
|
||||
|
||||
//
|
||||
|
||||
} // namespace threading
|
||||
} // namespace poly
|
||||
@@ -10,8 +10,11 @@
|
||||
#ifndef POLY_THREADING_H_
|
||||
#define POLY_THREADING_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
@@ -20,6 +23,27 @@
|
||||
namespace poly {
|
||||
namespace threading {
|
||||
|
||||
class Fence {
|
||||
public:
|
||||
Fence() : signaled_(false) {}
|
||||
void Signal() {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
signaled_.store(true);
|
||||
cond_.notify_all();
|
||||
}
|
||||
void Wait() {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
while (!signaled_.load()) {
|
||||
cond_.wait(lock);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
std::condition_variable cond_;
|
||||
std::atomic<bool> signaled_;
|
||||
};
|
||||
|
||||
// Gets the current high-performance tick count.
|
||||
uint64_t ticks();
|
||||
|
||||
@@ -35,7 +59,7 @@ void set_name(const std::string& name);
|
||||
void set_name(std::thread::native_handle_type handle, const std::string& name);
|
||||
|
||||
// Yields the current thread to the scheduler. Maybe.
|
||||
void Yield();
|
||||
void MaybeYield();
|
||||
|
||||
// Sleeps the current thread for at least as long as the given duration.
|
||||
void Sleep(std::chrono::microseconds duration);
|
||||
|
||||
@@ -32,7 +32,7 @@ void set_name(std::thread::native_handle_type handle, const std::string& name) {
|
||||
// ?
|
||||
}
|
||||
|
||||
void Yield() { pthread_yield_np(); }
|
||||
void MaybeYield() { pthread_yield_np(); }
|
||||
|
||||
void Sleep(std::chrono::microseconds duration) {
|
||||
timespec rqtp = {duration.count() / 1000000, duration.count() % 1000};
|
||||
|
||||
@@ -30,7 +30,7 @@ void set_name(std::thread::native_handle_type handle, const std::string& name) {
|
||||
pthread_setname_np(pthread_self(), name.c_str());
|
||||
}
|
||||
|
||||
void Yield() { pthread_yield_np(); }
|
||||
void MaybeYield() { pthread_yield_np(); }
|
||||
|
||||
void Sleep(std::chrono::microseconds duration) {
|
||||
timespec rqtp = {duration.count() / 1000000, duration.count() % 1000};
|
||||
|
||||
@@ -61,7 +61,7 @@ void set_name(std::thread::native_handle_type handle, const std::string& name) {
|
||||
set_name(GetThreadId(handle), name);
|
||||
}
|
||||
|
||||
void Yield() { SwitchToThread(); }
|
||||
void MaybeYield() { SwitchToThread(); }
|
||||
|
||||
void Sleep(std::chrono::microseconds duration) {
|
||||
if (duration.count() < 100) {
|
||||
|
||||
@@ -23,6 +23,7 @@ class Loop {
|
||||
virtual void Post(std::function<void()> fn) = 0;
|
||||
|
||||
virtual void Quit() = 0;
|
||||
virtual void AwaitQuit() = 0;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#include <poly/ui/win32/win32_loop.h>
|
||||
|
||||
#include <poly/assert.h>
|
||||
|
||||
namespace poly {
|
||||
namespace ui {
|
||||
namespace win32 {
|
||||
@@ -26,10 +28,18 @@ class PostedFn {
|
||||
};
|
||||
|
||||
Win32Loop::Win32Loop() : thread_id_(0) {
|
||||
thread_ = std::thread([this]() {
|
||||
poly::threading::Fence init_fence;
|
||||
thread_ = std::thread([&]() {
|
||||
poly::threading::set_name("Win32 Loop");
|
||||
thread_id_ = GetCurrentThreadId();
|
||||
|
||||
init_fence.Signal();
|
||||
|
||||
ThreadMain();
|
||||
|
||||
quit_fence_.Signal();
|
||||
});
|
||||
init_fence.Wait();
|
||||
}
|
||||
|
||||
Win32Loop::~Win32Loop() = default;
|
||||
@@ -57,16 +67,22 @@ void Win32Loop::ThreadMain() {
|
||||
}
|
||||
|
||||
void Win32Loop::Post(std::function<void()> fn) {
|
||||
assert_true(thread_id_ != 0);
|
||||
PostThreadMessage(thread_id_, kWmWin32LoopPost,
|
||||
reinterpret_cast<WPARAM>(this),
|
||||
reinterpret_cast<LPARAM>(new PostedFn(std::move(fn))));
|
||||
}
|
||||
|
||||
void Win32Loop::Quit() {
|
||||
assert_true(thread_id_ != 0);
|
||||
PostThreadMessage(thread_id_, kWmWin32LoopQuit,
|
||||
reinterpret_cast<WPARAM>(this), 0);
|
||||
}
|
||||
|
||||
void Win32Loop::AwaitQuit() {
|
||||
quit_fence_.Wait();
|
||||
}
|
||||
|
||||
} // namespace win32
|
||||
} // namespace ui
|
||||
} // namespace poly
|
||||
|
||||
@@ -13,8 +13,12 @@
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include <poly/threading.h>
|
||||
#include <poly/ui/loop.h>
|
||||
|
||||
namespace poly {
|
||||
@@ -24,17 +28,19 @@ namespace win32 {
|
||||
class Win32Loop : public Loop {
|
||||
public:
|
||||
Win32Loop();
|
||||
~Win32Loop();
|
||||
~Win32Loop() override;
|
||||
|
||||
void Post(std::function<void()> fn) override;
|
||||
|
||||
void Quit() override;
|
||||
void AwaitQuit() override;
|
||||
|
||||
private:
|
||||
void ThreadMain();
|
||||
|
||||
std::thread thread_;
|
||||
DWORD thread_id_;
|
||||
poly::threading::Fence quit_fence_;
|
||||
};
|
||||
|
||||
} // namespace win32
|
||||
|
||||
@@ -24,6 +24,11 @@ Win32Window::Win32Window(const std::wstring& title)
|
||||
|
||||
Win32Window::~Win32Window() {}
|
||||
|
||||
bool Win32Window::Initialize() {
|
||||
CreateHWND();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Win32Window::CreateHWND() {
|
||||
HINSTANCE hInstance = GetModuleHandle(nullptr);
|
||||
|
||||
@@ -62,6 +67,7 @@ bool Win32Window::CreateHWND() {
|
||||
}
|
||||
|
||||
main_menu_ = CreateMenu();
|
||||
AppendMenu(main_menu_, MF_STRING, 0, L"TODO");
|
||||
SetMenu(hwnd_, main_menu_);
|
||||
|
||||
// Disable flicks.
|
||||
@@ -130,13 +136,25 @@ bool Win32Window::set_title(const std::wstring& title) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// bool Win32Window::SetSize(uint32_t width, uint32_t height) {
|
||||
// RECT rc = {0, 0, static_cast<LONG>(width), static_cast<LONG>(height)};
|
||||
// AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);
|
||||
// // TODO(benvanik): center?
|
||||
// MoveWindow(handle_, 0, 0, rc.right - rc.left, rc.bottom - rc.top, TRUE);
|
||||
// return true;
|
||||
// }
|
||||
void Win32Window::Resize(int32_t width, int32_t height) {
|
||||
RECT rc = {0, 0, width, height};
|
||||
bool has_menu = main_menu_ ? true : false;
|
||||
AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, has_menu);
|
||||
Window::Resize(rc.right - rc.left, rc.bottom - rc.top);
|
||||
}
|
||||
|
||||
void Win32Window::Resize(int32_t left, int32_t top, int32_t right,
|
||||
int32_t bottom) {
|
||||
RECT rc = {left, top, right, bottom};
|
||||
bool has_menu = main_menu_ ? true : false;
|
||||
AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, has_menu);
|
||||
Window::Resize(rc.left, rc.top, rc.right, rc.bottom);
|
||||
}
|
||||
|
||||
void Win32Window::ResizeToFill(int32_t pad_left, int32_t pad_top,
|
||||
int32_t pad_right, int32_t pad_bottom) {
|
||||
// TODO(benvanik): fullscreen.
|
||||
}
|
||||
|
||||
void Win32Window::OnClose() {
|
||||
if (!closing_ && hwnd_) {
|
||||
|
||||
@@ -24,8 +24,16 @@ class Win32Window : public Window<Win32Control> {
|
||||
Win32Window(const std::wstring& title);
|
||||
~Win32Window() override;
|
||||
|
||||
bool Initialize() override;
|
||||
|
||||
bool set_title(const std::wstring& title) override;
|
||||
|
||||
void Resize(int32_t width, int32_t height) override;
|
||||
void Resize(int32_t left, int32_t top, int32_t right,
|
||||
int32_t bottom) override;
|
||||
void ResizeToFill(int32_t pad_left, int32_t pad_top, int32_t pad_right,
|
||||
int32_t pad_bottom) override;
|
||||
|
||||
protected:
|
||||
bool CreateHWND() override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user