Merge pull request #1 from scribam/linux

Make travis happy with BUILD and LINT
This commit is contained in:
Doug Johnson 2017-09-22 12:48:27 -06:00 committed by GitHub
commit 0406f19f4d
29 changed files with 186 additions and 262 deletions

View File

@ -22,17 +22,19 @@ matrix:
# LLVMGold.so is not installed correctly # LLVMGold.so is not installed correctly
- env: BUILD=true CONFIG=Release - env: BUILD=true CONFIG=Release
dist: trusty
sudo: required sudo: required
addons: addons:
apt: apt:
sources: sources:
# - ubuntu-toolchain-r-test # - ubuntu-toolchain-r-test
- llvm-toolchain-precise - llvm-toolchain-trusty
packages: packages:
- clang-3.8 - clang-3.8
- clang-format-3.8 - clang-format-3.8
- libc++-dev - libc++-dev
- libc++abi-dev
- libgtk-3-dev
- liblz4-dev
git: git:
# We handle submodules ourselves in xenia-build setup. # We handle submodules ourselves in xenia-build setup.
@ -43,6 +45,10 @@ before_script:
- export CC=clang-3.8 - export CC=clang-3.8
# Dump useful info. # Dump useful info.
- $CXX --version - $CXX --version
# Add Vulkan dependencies
- wget http://mirrors.kernel.org/ubuntu/pool/universe/v/vulkan/libvulkan1_1.0.42.0+dfsg1-1ubuntu1~16.04.1_amd64.deb
- wget http://mirrors.kernel.org/ubuntu/pool/universe/v/vulkan/libvulkan-dev_1.0.42.0+dfsg1-1ubuntu1~16.04.1_amd64.deb
- sudo dpkg -i libvulkan1_1.0.42.0+dfsg1-1ubuntu1~16.04.1_amd64.deb libvulkan-dev_1.0.42.0+dfsg1-1ubuntu1~16.04.1_amd64.deb
# Prepare environment (pull dependencies, build tools). # Prepare environment (pull dependencies, build tools).
- travis_retry ./xenia-build setup - travis_retry ./xenia-build setup

View File

@ -34,8 +34,8 @@ filter({})
characterset("Unicode") characterset("Unicode")
flags({ flags({
--"ExtraWarnings", -- Sets the compiler's maximum warning level. "ExtraWarnings", -- Sets the compiler's maximum warning level.
"FatalWarnings", -- Treat warnings as errors. --"FatalWarnings", -- Treat warnings as errors.
}) })
filter("kind:StaticLib") filter("kind:StaticLib")

View File

@ -24,13 +24,12 @@ constexpr size_t kMaxHandlerCount = 8;
// Executed in order. // Executed in order.
std::pair<ExceptionHandler::Handler, void*> handlers_[kMaxHandlerCount]; std::pair<ExceptionHandler::Handler, void*> handlers_[kMaxHandlerCount];
void ExceptionHandler::Install(Handler fn, void* data) { void ExceptionHandler::Install(Handler fn, void* data) {
//TODO(dougvj) stub // TODO(dougvj) stub
} }
void ExceptionHandler::Uninstall(Handler fn, void* data) { void ExceptionHandler::Uninstall(Handler fn, void* data) {
//TODO(dougvj) stub // TODO(dougvj) stub
} }
} // namespace xe } // namespace xe

View File

@ -12,11 +12,11 @@
#include "xenia/base/string.h" #include "xenia/base/string.h"
#include <dirent.h> #include <dirent.h>
#include <fcntl.h>
#include <ftw.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <ftw.h>
#include <fcntl.h>
namespace xe { namespace xe {
namespace filesystem { namespace filesystem {
@ -26,7 +26,6 @@ bool PathExists(const std::wstring& path) {
return stat(xe::to_string(path).c_str(), &st) == 0; return stat(xe::to_string(path).c_str(), &st) == 0;
} }
FILE* OpenFile(const std::wstring& path, const char* mode) { FILE* OpenFile(const std::wstring& path, const char* mode) {
auto fixed_path = xe::fix_path_separators(path); auto fixed_path = xe::fix_path_separators(path);
return fopen(xe::to_string(fixed_path).c_str(), mode); return fopen(xe::to_string(fixed_path).c_str(), mode);
@ -36,23 +35,25 @@ bool CreateFolder(const std::wstring& path) {
return mkdir(xe::to_string(path).c_str(), 0774); return mkdir(xe::to_string(path).c_str(), 0774);
} }
static int removeCallback(const char *fpath, const struct stat* sb, static int removeCallback(const char* fpath, const struct stat* sb,
int typeflag, struct FTW* ftwbuf) { int typeflag, struct FTW* ftwbuf) {
int rv = remove(fpath); int rv = remove(fpath);
return rv; return rv;
} }
bool DeleteFolder(const std::wstring& path) { bool DeleteFolder(const std::wstring& path) {
return nftw(xe::to_string(path).c_str(), removeCallback, 64, return nftw(xe::to_string(path).c_str(), removeCallback, 64,
FTW_DEPTH | FTW_PHYS) == 0 ? true : false; FTW_DEPTH | FTW_PHYS) == 0
? true
: false;
} }
static uint64_t convertUnixtimeToWinFiletime(time_t unixtime) { static uint64_t convertUnixtimeToWinFiletime(time_t unixtime) {
//Linux uses number of seconds since 1/1/1970, and Windows uses // Linux uses number of seconds since 1/1/1970, and Windows uses
//number of nanoseconds since 1/1/1601 // number of nanoseconds since 1/1/1601
//so we convert linux time to nanoseconds and then add the number of // so we convert linux time to nanoseconds and then add the number of
//nanoseconds from 1601 to 1970 // nanoseconds from 1601 to 1970
//see https://msdn.microsoft.com/en-us/library/ms724228 // see https://msdn.microsoft.com/en-us/library/ms724228
uint64_t filetime = filetime = (unixtime * 10000000) + 116444736000000000; uint64_t filetime = filetime = (unixtime * 10000000) + 116444736000000000;
return filetime; return filetime;
} }
@ -60,8 +61,7 @@ static uint64_t convertUnixtimeToWinFiletime(time_t unixtime) {
bool IsFolder(const std::wstring& path) { bool IsFolder(const std::wstring& path) {
struct stat st; struct stat st;
if (stat(xe::to_string(path).c_str(), &st) == 0) { if (stat(xe::to_string(path).c_str(), &st) == 0) {
if (S_ISDIR(st.st_mode)) if (S_ISDIR(st.st_mode)) return true;
return true;
} }
return false; return false;
} }
@ -89,11 +89,9 @@ class PosixFileHandle : public FileHandle {
} }
bool Read(size_t file_offset, void* buffer, size_t buffer_length, bool Read(size_t file_offset, void* buffer, size_t buffer_length,
size_t* out_bytes_read) override { size_t* out_bytes_read) override {
ssize_t out = pread(handle_, buffer, buffer_length, file_offset); ssize_t out = pread(handle_, buffer, buffer_length, file_offset);
*out_bytes_read = out; *out_bytes_read = out;
return out >= 0 ? true : false; return out >= 0 ? true : false;
} }
bool Write(size_t file_offset, const void* buffer, size_t buffer_length, bool Write(size_t file_offset, const void* buffer, size_t buffer_length,
size_t* out_bytes_written) override { size_t* out_bytes_written) override {
@ -144,8 +142,7 @@ bool GetInfo(const std::wstring& path, FileInfo* out_info) {
if (stat(xe::to_string(path).c_str(), &st) == 0) { if (stat(xe::to_string(path).c_str(), &st) == 0) {
if (S_ISDIR(st.st_mode)) { if (S_ISDIR(st.st_mode)) {
out_info->type = FileInfo::Type::kDirectory; out_info->type = FileInfo::Type::kDirectory;
} } else {
else {
out_info->type = FileInfo::Type::kFile; out_info->type = FileInfo::Type::kFile;
} }
out_info->create_timestamp = convertUnixtimeToWinFiletime(st.st_ctime); out_info->create_timestamp = convertUnixtimeToWinFiletime(st.st_ctime);
@ -186,7 +183,5 @@ std::vector<FileInfo> ListFiles(const std::wstring& path) {
return result; return result;
} }
} // namespace filesystem } // namespace filesystem
} // namespace xe } // namespace xe

View File

@ -11,10 +11,10 @@
#define XENIA_BASE_MATH_H_ #define XENIA_BASE_MATH_H_
#include <algorithm> #include <algorithm>
#include <cmath>
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <type_traits> #include <type_traits>
#include <cmath>
#include "xenia/base/platform.h" #include "xenia/base/platform.h"
#if XE_ARCH_AMD64 #if XE_ARCH_AMD64

View File

@ -18,5 +18,4 @@ void LaunchBrowser(const char* url) {
system(cmd.c_str()); system(cmd.c_str());
} }
} // namespace xe } // namespace xe

View File

@ -18,15 +18,15 @@
// Xlib/Xcb is used only for GLX/Vulkan interaction, the window management // Xlib/Xcb is used only for GLX/Vulkan interaction, the window management
// and input events are done with gtk/gdk // and input events are done with gtk/gdk
#include <X11/Xlib.h>
#include <X11/Xlib-xcb.h> #include <X11/Xlib-xcb.h>
#include <X11/Xutil.h> #include <X11/Xlib.h>
#include <X11/Xos.h> #include <X11/Xos.h>
#include <X11/Xutil.h>
#include <xcb/xcb.h> #include <xcb/xcb.h>
//Used for window management. Gtk is for GUI and wigets, gdk is for lower // Used for window management. Gtk is for GUI and wigets, gdk is for lower
//level events like key presses, mouse events, window handles, etc // level events like key presses, mouse events, window handles, etc
#include <gtk/gtk.h>
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <gtk/gtk.h>
#endif // XENIA_BASE_PLATFORM_X11_H_ #endif // XENIA_BASE_PLATFORM_X11_H_

View File

@ -16,13 +16,13 @@
#include <climits> #include <climits>
#include <condition_variable> #include <condition_variable>
#include <cstdint> #include <cstdint>
#include <functional>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <string> #include <string>
#include <thread> #include <thread>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <functional>
namespace xe { namespace xe {
namespace threading { namespace threading {

View File

@ -13,8 +13,5 @@
#include <time.h> #include <time.h>
namespace xe { namespace xe {
namespace threading { namespace threading {} // namespace threading
} // namespace threading
} // namespace xe } // namespace xe

View File

@ -14,18 +14,16 @@
#include <pthread.h> #include <pthread.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
namespace xe { namespace xe {
namespace threading { namespace threading {
//TODO(dougvj) // TODO(dougvj)
void EnableAffinityConfiguration() { void EnableAffinityConfiguration() {}
}
// uint64_t ticks() { return mach_absolute_time(); } // uint64_t ticks() { return mach_absolute_time(); }
@ -46,9 +44,7 @@ void MaybeYield() {
__sync_synchronize(); __sync_synchronize();
} }
void SyncMemory() { void SyncMemory() { __sync_synchronize(); }
__sync_synchronize();
}
void Sleep(std::chrono::microseconds duration) { void Sleep(std::chrono::microseconds duration) {
timespec rqtp = {time_t(duration.count() / 1000000), timespec rqtp = {time_t(duration.count() / 1000000),
@ -57,35 +53,28 @@ void Sleep(std::chrono::microseconds duration) {
// TODO(benvanik): spin while rmtp >0? // TODO(benvanik): spin while rmtp >0?
} }
//TODO(dougvj) Not sure how to implement the equivalent of this on POSIX. // TODO(dougvj) Not sure how to implement the equivalent of this on POSIX.
SleepResult AlertableSleep(std::chrono::microseconds duration) { SleepResult AlertableSleep(std::chrono::microseconds duration) {
sleep(duration.count() / 1000); sleep(duration.count() / 1000);
return SleepResult::kSuccess; return SleepResult::kSuccess;
} }
//TODO(dougvj) We can probably wrap this with pthread_key_t but the type of // TODO(dougvj) We can probably wrap this with pthread_key_t but the type of
//TlsHandle probably needs to be refactored // TlsHandle probably needs to be refactored
TlsHandle AllocateTlsHandle() { TlsHandle AllocateTlsHandle() { assert_always(); }
assert_always();
}
bool FreeTlsHandle(TlsHandle handle) { return true; } bool FreeTlsHandle(TlsHandle handle) { return true; }
uintptr_t GetTlsValue(TlsHandle handle) { uintptr_t GetTlsValue(TlsHandle handle) { assert_always(); }
assert_always();
}
bool SetTlsValue(TlsHandle handle, uintptr_t value) { bool SetTlsValue(TlsHandle handle, uintptr_t value) { assert_always(); }
assert_always();
}
//TODO(dougvj) // TODO(dougvj)
class PosixHighResolutionTimer : public HighResolutionTimer { class PosixHighResolutionTimer : public HighResolutionTimer {
public: public:
PosixHighResolutionTimer(std::function<void()> callback) PosixHighResolutionTimer(std::function<void()> callback)
: callback_(callback) {} : callback_(callback) {}
~PosixHighResolutionTimer() override { ~PosixHighResolutionTimer() override {}
}
bool Initialize(std::chrono::milliseconds period) { bool Initialize(std::chrono::milliseconds period) {
assert_always(); assert_always();
@ -111,7 +100,7 @@ std::unique_ptr<HighResolutionTimer> HighResolutionTimer::CreateRepeating(
// some more functionality // some more functionality
class PosixCondition { class PosixCondition {
public: public:
PosixCondition(): signal_(false) { PosixCondition() : signal_(false) {
pthread_mutex_init(&mutex_, NULL); pthread_mutex_init(&mutex_, NULL);
pthread_cond_init(&cond_, NULL); pthread_cond_init(&cond_, NULL);
} }
@ -135,7 +124,7 @@ class PosixCondition {
} }
bool Wait(unsigned int timeout_ms) { bool Wait(unsigned int timeout_ms) {
//Assume 0 means no timeout, not instant timeout // Assume 0 means no timeout, not instant timeout
if (timeout_ms == 0) { if (timeout_ms == 0) {
Wait(); Wait();
} }
@ -143,42 +132,40 @@ class PosixCondition {
struct timeval now; struct timeval now;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
//Add the number of seconds we want to wait to the current time // Add the number of seconds we want to wait to the current time
time_to_wait.tv_sec = now.tv_sec + (timeout_ms/1000); time_to_wait.tv_sec = now.tv_sec + (timeout_ms / 1000);
//Add the number of nanoseconds we want to wait to the current nanosecond // Add the number of nanoseconds we want to wait to the current nanosecond
//stride // stride
long nsec = (now.tv_usec+(timeout_ms % 1000)) * 1000; long nsec = (now.tv_usec + (timeout_ms % 1000)) * 1000;
//If we overflowed the nanosecond count then we add a second // If we overflowed the nanosecond count then we add a second
time_to_wait.tv_sec += nsec/1000000000UL; time_to_wait.tv_sec += nsec / 1000000000UL;
//We only add nanoseconds within the 1 second stride // We only add nanoseconds within the 1 second stride
time_to_wait.tv_nsec = nsec % 1000000000UL; time_to_wait.tv_nsec = nsec % 1000000000UL;
pthread_mutex_lock(&mutex_); pthread_mutex_lock(&mutex_);
while(!signal_) { while (!signal_) {
int status = pthread_cond_timedwait(&cond_, &mutex_, &time_to_wait); int status = pthread_cond_timedwait(&cond_, &mutex_, &time_to_wait);
if (status == ETIMEDOUT) if (status == ETIMEDOUT) return false; // We timed out
return false; //We timed out
} }
pthread_mutex_unlock(&mutex_); pthread_mutex_unlock(&mutex_);
return true; //We didn't time out return true; // We didn't time out
} }
bool Wait() { bool Wait() {
pthread_mutex_lock(&mutex_); pthread_mutex_lock(&mutex_);
while(!signal_) { while (!signal_) {
pthread_cond_wait(&cond_, &mutex_); pthread_cond_wait(&cond_, &mutex_);
} }
pthread_mutex_unlock(&mutex_); pthread_mutex_unlock(&mutex_);
return true; //Did not time out; return true; // Did not time out;
} }
private: private:
bool signal_; bool signal_;
pthread_cond_t cond_; pthread_cond_t cond_;
pthread_mutex_t mutex_; pthread_mutex_t mutex_;
}; };
//Native posix thread handle // Native posix thread handle
template <typename T> template <typename T>
class PosixThreadHandle : public T { class PosixThreadHandle : public T {
public: public:
@ -193,8 +180,8 @@ class PosixThreadHandle : public T {
pthread_t handle_; pthread_t handle_;
}; };
//This is wraps a condition object as our handle because posix has no single // This is wraps a condition object as our handle because posix has no single
//native handle for higher level concurrency constructs such as semaphores // native handle for higher level concurrency constructs such as semaphores
template <typename T> template <typename T>
class PosixConditionHandle : public T { class PosixConditionHandle : public T {
public: public:
@ -208,10 +195,9 @@ class PosixConditionHandle : public T {
PosixCondition handle_; PosixCondition handle_;
}; };
// TODO(dougvj) // TODO(dougvj)
WaitResult Wait(WaitHandle* wait_handle, bool is_alertable, WaitResult Wait(WaitHandle* wait_handle, bool is_alertable,
std::chrono::milliseconds timeout) { std::chrono::milliseconds timeout) {
assert_always(); assert_always();
return WaitResult::kFailed; return WaitResult::kFailed;
} }
@ -233,15 +219,15 @@ std::pair<WaitResult, size_t> WaitMultiple(WaitHandle* wait_handles[],
return std::pair<WaitResult, size_t>(WaitResult::kFailed, 0); return std::pair<WaitResult, size_t>(WaitResult::kFailed, 0);
} }
// TODO(dougvj)
//TODO(dougvj) class PosixEvent : public PosixConditionHandle<Event> {
class PosixEvent: public PosixConditionHandle<Event> {
public: public:
PosixEvent(bool initial_state, int auto_reset) { assert_always(); } PosixEvent(bool initial_state, int auto_reset) { assert_always(); }
~PosixEvent() override = default; ~PosixEvent() override = default;
void Set() override { assert_always(); } void Set() override { assert_always(); }
void Reset() override { assert_always(); } void Reset() override { assert_always(); }
void Pulse() override { assert_always(); } void Pulse() override { assert_always(); }
private: private:
PosixCondition condition_; PosixCondition condition_;
}; };
@ -254,7 +240,7 @@ std::unique_ptr<Event> Event::CreateAutoResetEvent(bool initial_state) {
return std::make_unique<PosixEvent>(PosixEvent(initial_state, true)); return std::make_unique<PosixEvent>(PosixEvent(initial_state, true));
} }
//TODO(dougvj) // TODO(dougvj)
class PosixSemaphore : public PosixConditionHandle<Semaphore> { class PosixSemaphore : public PosixConditionHandle<Semaphore> {
public: public:
PosixSemaphore(int initial_count, int maximum_count) { assert_always(); } PosixSemaphore(int initial_count, int maximum_count) { assert_always(); }
@ -270,22 +256,22 @@ std::unique_ptr<Semaphore> Semaphore::Create(int initial_count,
return std::make_unique<PosixSemaphore>(initial_count, maximum_count); return std::make_unique<PosixSemaphore>(initial_count, maximum_count);
} }
//TODO(dougvj) // TODO(dougvj)
class PosixMutant : public PosixConditionHandle<Mutant> { class PosixMutant : public PosixConditionHandle<Mutant> {
public: public:
PosixMutant(bool initial_owner) { PosixMutant(bool initial_owner) { assert_always(); }
assert_always();
}
~PosixMutant() = default; ~PosixMutant() = default;
bool Release() override { assert_always(); return false; } bool Release() override {
private: assert_always();
return false;
}
}; };
std::unique_ptr<Mutant> Mutant::Create(bool initial_owner) { std::unique_ptr<Mutant> Mutant::Create(bool initial_owner) {
return std::make_unique<PosixMutant>(initial_owner); return std::make_unique<PosixMutant>(initial_owner);
} }
//TODO(dougvj) // TODO(dougvj)
class PosixTimer : public PosixConditionHandle<Timer> { class PosixTimer : public PosixConditionHandle<Timer> {
public: public:
PosixTimer(bool manual_reset) { assert_always(); } PosixTimer(bool manual_reset) { assert_always(); }
@ -305,7 +291,6 @@ class PosixTimer : public PosixConditionHandle<Timer> {
assert_always(); assert_always();
return false; return false;
} }
}; };
std::unique_ptr<Timer> Timer::CreateManualResetTimer() { std::unique_ptr<Timer> Timer::CreateManualResetTimer() {

View File

@ -23,8 +23,8 @@
#include <llvm/ADT/BitVector.h> #include <llvm/ADT/BitVector.h>
#pragma warning(pop) #pragma warning(pop)
#else #else
#include <cmath>
#include <llvm/ADT/BitVector.h> #include <llvm/ADT/BitVector.h>
#include <cmath>
#endif // XE_COMPILER_MSVC #endif // XE_COMPILER_MSVC
namespace xe { namespace xe {

View File

@ -22,8 +22,8 @@
#include <llvm/ADT/BitVector.h> #include <llvm/ADT/BitVector.h>
#pragma warning(pop) #pragma warning(pop)
#else #else
#include <cmath>
#include <llvm/ADT/BitVector.h> #include <llvm/ADT/BitVector.h>
#include <cmath>
#endif // XE_COMPILER_MSVC #endif // XE_COMPILER_MSVC
namespace xe { namespace xe {

View File

@ -240,4 +240,3 @@ class CommandProcessor {
} // namespace xe } // namespace xe
#endif // XENIA_GPU_COMMAND_PROCESSOR_H_ #endif // XENIA_GPU_COMMAND_PROCESSOR_H_

View File

@ -11,10 +11,10 @@
#define XENIA_GPU_GL4_SHADER_CACHE_H_ #define XENIA_GPU_GL4_SHADER_CACHE_H_
#include <cstdint> #include <cstdint>
#include <vector>
#include <cstring> #include <cstring>
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
#include <vector>
#include "xenia/gpu/xenos.h" #include "xenia/gpu/xenos.h"

View File

@ -761,7 +761,7 @@ bool RenderCache::ParseConfiguration(RenderConfiguration* config) {
config->color[i].format = ColorRenderTargetFormat::k_2_10_10_10_FLOAT; config->color[i].format = ColorRenderTargetFormat::k_2_10_10_10_FLOAT;
break; break;
default: default:
//The rest are good // The rest are good
break; break;
} }
} }
@ -1149,7 +1149,7 @@ void RenderCache::BlitToImage(VkCommandBuffer command_buffer,
format = uint32_t(ColorRenderTargetFormat::k_2_10_10_10_FLOAT); format = uint32_t(ColorRenderTargetFormat::k_2_10_10_10_FLOAT);
break; break;
default: default:
//Rest are OK // Rest are OK
break; break;
} }
} }
@ -1265,7 +1265,7 @@ void RenderCache::ClearEDRAMColor(VkCommandBuffer command_buffer,
format = ColorRenderTargetFormat::k_2_10_10_10_FLOAT; format = ColorRenderTargetFormat::k_2_10_10_10_FLOAT;
break; break;
default: default:
//Rest are OK // Rest are OK
break; break;
} }

View File

@ -9,11 +9,11 @@
#include "xenia/ui/file_picker.h" #include "xenia/ui/file_picker.h"
#include <codecvt>
#include <locale>
#include <string>
#include "xenia/base/assert.h" #include "xenia/base/assert.h"
#include "xenia/base/platform_linux.h" #include "xenia/base/platform_linux.h"
#include <locale>
#include <codecvt>
#include <string>
namespace xe { namespace xe {
namespace ui { namespace ui {
@ -36,39 +36,34 @@ GtkFilePicker::GtkFilePicker() = default;
GtkFilePicker::~GtkFilePicker() = default; GtkFilePicker::~GtkFilePicker() = default;
bool GtkFilePicker::Show(void* parent_window_handle) { bool GtkFilePicker::Show(void* parent_window_handle) {
// TODO(benvanik): FileSaveDialog. // TODO(benvanik): FileSaveDialog.
assert_true(mode() == Mode::kOpen); assert_true(mode() == Mode::kOpen);
// TODO(benvanik): folder dialogs. // TODO(benvanik): folder dialogs.
assert_true(type() == Type::kFile); assert_true(type() == Type::kFile);
GtkWidget *dialog; GtkWidget* dialog;
gint res; gint res;
dialog = gtk_file_chooser_dialog_new ("Open File", dialog = gtk_file_chooser_dialog_new(
(GtkWindow*)parent_window_handle, "Open File", (GtkWindow*)parent_window_handle,
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_OPEN, "_Cancel", GTK_RESPONSE_CANCEL, "_Open",
"_Cancel", GTK_RESPONSE_ACCEPT, NULL);
GTK_RESPONSE_CANCEL,
"_Open",
GTK_RESPONSE_ACCEPT,
NULL);
res = gtk_dialog_run (GTK_DIALOG (dialog)); res = gtk_dialog_run(GTK_DIALOG(dialog));
char *filename; char* filename;
if (res == GTK_RESPONSE_ACCEPT) { if (res == GTK_RESPONSE_ACCEPT) {
GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog); GtkFileChooser* chooser = GTK_FILE_CHOOSER(dialog);
filename = gtk_file_chooser_get_filename (chooser); filename = gtk_file_chooser_get_filename(chooser);
std::vector<std::wstring> selected_files; std::vector<std::wstring> selected_files;
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter; std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring ws_filename = converter.from_bytes(filename); std::wstring ws_filename = converter.from_bytes(filename);
selected_files.push_back(ws_filename); selected_files.push_back(ws_filename);
set_selected_files(selected_files); set_selected_files(selected_files);
gtk_widget_destroy (dialog); gtk_widget_destroy(dialog);
return true; return true;
} }
gtk_widget_destroy (dialog); gtk_widget_destroy(dialog);
return false;; return false;
} }
} // namespace ui } // namespace ui

View File

@ -21,7 +21,6 @@
#include "xenia/ui/gl/gl_immediate_drawer.h" #include "xenia/ui/gl/gl_immediate_drawer.h"
#include "xenia/ui/window.h" #include "xenia/ui/window.h"
DEFINE_bool(thread_safe_gl, false, DEFINE_bool(thread_safe_gl, false,
"Only allow one GL context to be active at a time."); "Only allow one GL context to be active at a time.");
@ -40,7 +39,6 @@ namespace xe {
namespace ui { namespace ui {
namespace gl { namespace gl {
std::recursive_mutex GLContext::global_gl_mutex_; std::recursive_mutex GLContext::global_gl_mutex_;
void GLContext::FatalGLError(std::string error) { void GLContext::FatalGLError(std::string error) {
@ -51,10 +49,8 @@ void GLContext::FatalGLError(std::string error) {
"of supported GPUs."); "of supported GPUs.");
} }
GLContext::GLContext(GraphicsProvider* provider, Window* target_window) GLContext::GLContext(GraphicsProvider* provider, Window* target_window)
: GraphicsContext(provider, target_window) { } : GraphicsContext(provider, target_window) {}
GLContext::~GLContext() {} GLContext::~GLContext() {}
@ -218,8 +214,6 @@ ImmediateDrawer* GLContext::immediate_drawer() {
return immediate_drawer_.get(); return immediate_drawer_.get();
} }
bool GLContext::WasLost() { bool GLContext::WasLost() {
if (!robust_access_supported_) { if (!robust_access_supported_) {
// Can't determine if we lost the context. // Can't determine if we lost the context.

View File

@ -29,7 +29,6 @@ DECLARE_bool(gl_debug);
DECLARE_bool(gl_debug_output); DECLARE_bool(gl_debug_output);
DECLARE_bool(gl_debug_output_synchronous); DECLARE_bool(gl_debug_output_synchronous);
namespace xe { namespace xe {
namespace ui { namespace ui {
namespace gl { namespace gl {
@ -69,6 +68,7 @@ class GLContext : public GraphicsContext {
void AssertExtensionsPresent(); void AssertExtensionsPresent();
void DebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity, void DebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity,
GLsizei length, const GLchar* message); GLsizei length, const GLchar* message);
private: private:
friend class GLProvider; friend class GLProvider;
@ -79,15 +79,11 @@ class GLContext : public GraphicsContext {
GLContext* parent_context); GLContext* parent_context);
private: private:
static void GLAPIENTRY DebugMessageThunk(GLenum source, GLenum type, static void GLAPIENTRY DebugMessageThunk(GLenum source, GLenum type,
GLuint id, GLenum severity, GLuint id, GLenum severity,
GLsizei length, GLsizei length,
const GLchar* message, const GLchar* message,
GLvoid* user_param); GLvoid* user_param);
}; };
} // namespace gl } // namespace gl

View File

@ -24,23 +24,20 @@
#include "third_party/GL/wglew.h" #include "third_party/GL/wglew.h"
namespace xe { namespace xe {
namespace ui { namespace ui {
namespace gl { namespace gl {
thread_local GLEWContext* tls_glew_context_ = nullptr; thread_local GLEWContext* tls_glew_context_ = nullptr;
thread_local WGLEWContext* tls_wglew_context_ = nullptr; thread_local WGLEWContext* tls_wglew_context_ = nullptr;
extern "C" GLEWContext* glewGetContext() { return tls_glew_context_; } extern "C" GLEWContext* glewGetContext() { return tls_glew_context_; }
extern "C" WGLEWContext* wglewGetContext() { return tls_wglew_context_; } extern "C" WGLEWContext* wglewGetContext() { return tls_wglew_context_; }
std::unique_ptr<GLContext> GLContext::Create(GraphicsProvider* provider, std::unique_ptr<GLContext> GLContext::Create(GraphicsProvider* provider,
Window* target_window, Window* target_window,
GLContext* share_context) { GLContext* share_context) {
auto context = auto context =
std::unique_ptr<GLContext>(new WGLContext(provider, target_window)); std::unique_ptr<GLContext>(new WGLContext(provider, target_window));
if (!context->Initialize(share_context)) { if (!context->Initialize(share_context)) {
return nullptr; return nullptr;
} }
@ -48,11 +45,10 @@ std::unique_ptr<GLContext> GLContext::Create(GraphicsProvider* provider,
return context; return context;
} }
std::unique_ptr<GLContext> GLContext::CreateOffscreen( std::unique_ptr<GLContext> GLContext::CreateOffscreen(
GraphicsProvider* provider, GLContext* parent_context) { GraphicsProvider* provider, GLContext* parent_context) {
return WGLContext::CreateOffscreen(provider, return WGLContext::CreateOffscreen(provider,
static_cast<WGLContext*>(parent_context)); static_cast<WGLContext*>(parent_context));
} }
WGLContext::WGLContext(GraphicsProvider* provider, Window* target_window) WGLContext::WGLContext(GraphicsProvider* provider, Window* target_window)
@ -296,7 +292,6 @@ void WGLContext::ClearCurrent() {
} }
} }
void WGLContext::BeginSwap() { void WGLContext::BeginSwap() {
SCOPE_profile_cpu_i("gpu", "xe::ui::gl::WGLContext::BeginSwap"); SCOPE_profile_cpu_i("gpu", "xe::ui::gl::WGLContext::BeginSwap");
float clear_color[] = {238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 1.0f}; float clear_color[] = {238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 1.0f};

View File

@ -14,9 +14,9 @@
#include <memory> #include <memory>
#include "xenia/ui/gl/gl_context.h"
#include "xenia/ui/gl/blitter.h" #include "xenia/ui/gl/blitter.h"
#include "xenia/ui/gl/gl.h" #include "xenia/ui/gl/gl.h"
#include "xenia/ui/gl/gl_context.h"
#include "xenia/ui/graphics_context.h" #include "xenia/ui/graphics_context.h"
typedef struct HDC__* HDC; typedef struct HDC__* HDC;
@ -33,7 +33,6 @@ class WGLContext : public GLContext {
public: public:
~WGLContext() override; ~WGLContext() override;
bool is_current() override; bool is_current() override;
bool MakeCurrent() override; bool MakeCurrent() override;
void ClearCurrent() override; void ClearCurrent() override;
@ -41,25 +40,21 @@ class WGLContext : public GLContext {
void BeginSwap() override; void BeginSwap() override;
void EndSwap() override; void EndSwap() override;
protected: protected:
friend class GLContext; friend class GLContext;
WGLContext(GraphicsProvider* provider, Window* target_window); WGLContext(GraphicsProvider* provider, Window* target_window);
static std::unique_ptr<WGLContext> CreateOffscreen(GraphicsProvider* provider, static std::unique_ptr<WGLContext> CreateOffscreen(
WGLContext* parent_context); GraphicsProvider* provider, WGLContext* parent_context);
bool Initialize(GLContext* share_context) override; bool Initialize(GLContext* share_context) override;
void* handle() override {return glrc_;}; void* handle() override { return glrc_; }
private: private:
HDC dc_ = nullptr; HDC dc_ = nullptr;
HGLRC glrc_ = nullptr; HGLRC glrc_ = nullptr;
std::unique_ptr<GLEWContext> glew_context_; std::unique_ptr<GLEWContext> glew_context_;
std::unique_ptr<WGLEWContext> wglew_context_; std::unique_ptr<WGLEWContext> wglew_context_;
}; };
} // namespace gl } // namespace gl

View File

@ -11,9 +11,11 @@
#include <gflags/gflags.h> #include <gflags/gflags.h>
#include <gdk/gdkx.h>
#include <mutex> #include <mutex>
#include <string> #include <string>
#include "third_party/GL/glxew.h"
#include "xenia/base/assert.h" #include "xenia/base/assert.h"
#include "xenia/base/logging.h" #include "xenia/base/logging.h"
#include "xenia/base/math.h" #include "xenia/base/math.h"
@ -21,27 +23,21 @@
#include "xenia/base/profiling.h" #include "xenia/base/profiling.h"
#include "xenia/ui/gl/gl_immediate_drawer.h" #include "xenia/ui/gl/gl_immediate_drawer.h"
#include "xenia/ui/window.h" #include "xenia/ui/window.h"
#include "third_party/GL/glxew.h"
#include <gdk/gdkx.h>
namespace xe { namespace xe {
namespace ui { namespace ui {
namespace gl { namespace gl {
thread_local GLEWContext* tls_glew_context_ = nullptr; thread_local GLEWContext* tls_glew_context_ = nullptr;
thread_local GLXEWContext* tls_glxew_context_ = nullptr; thread_local GLXEWContext* tls_glxew_context_ = nullptr;
extern "C" GLEWContext* glewGetContext() { return tls_glew_context_; } extern "C" GLEWContext* glewGetContext() { return tls_glew_context_; }
extern "C" GLXEWContext* glxewGetContext() { return tls_glxew_context_; } extern "C" GLXEWContext* glxewGetContext() { return tls_glxew_context_; }
std::unique_ptr<GLContext> GLContext::Create(GraphicsProvider* provider, std::unique_ptr<GLContext> GLContext::Create(GraphicsProvider* provider,
Window* target_window, Window* target_window,
GLContext* share_context) { GLContext* share_context) {
auto context = auto context =
std::unique_ptr<GLContext>(new GLXContext(provider, target_window)); std::unique_ptr<GLContext>(new GLXContext(provider, target_window));
if (!context->Initialize(share_context)) { if (!context->Initialize(share_context)) {
return nullptr; return nullptr;
} }
@ -50,9 +46,9 @@ std::unique_ptr<GLContext> GLContext::Create(GraphicsProvider* provider,
} }
std::unique_ptr<GLContext> GLContext::CreateOffscreen( std::unique_ptr<GLContext> GLContext::CreateOffscreen(
GraphicsProvider* provider, GLContext* parent_context) { GraphicsProvider* provider, GLContext* parent_context) {
return GLXContext::CreateOffscreen(provider, return GLXContext::CreateOffscreen(provider,
static_cast<GLXContext*>(parent_context)); static_cast<GLXContext*>(parent_context));
} }
GLXContext::GLXContext(GraphicsProvider* provider, Window* target_window) GLXContext::GLXContext(GraphicsProvider* provider, Window* target_window)
@ -74,8 +70,6 @@ GLXContext::~GLXContext() {
} }
} }
bool GLXContext::Initialize(GLContext* share_context) { bool GLXContext::Initialize(GLContext* share_context) {
GtkWidget* window = GTK_WIDGET(target_window_->native_handle()); GtkWidget* window = GTK_WIDGET(target_window_->native_handle());
GtkWidget* draw_area = gtk_drawing_area_new(); GtkWidget* draw_area = gtk_drawing_area_new();
@ -90,8 +84,8 @@ bool GLXContext::Initialize(GLContext* share_context) {
Display* display = gdk_x11_display_get_xdisplay(gdk_display); Display* display = gdk_x11_display_get_xdisplay(gdk_display);
disp_ = display; disp_ = display;
::Window root = gdk_x11_get_default_root_xwindow(); ::Window root = gdk_x11_get_default_root_xwindow();
static int vis_attrib_list[] = static int vis_attrib_list[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24,
{GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None}; GLX_DOUBLEBUFFER, None};
XVisualInfo* vi = glXChooseVisual(display, 0, vis_attrib_list); XVisualInfo* vi = glXChooseVisual(display, 0, vis_attrib_list);
if (vi == NULL) { if (vi == NULL) {
FatalGLError("No matching visuals for X display"); FatalGLError("No matching visuals for X display");
@ -151,8 +145,8 @@ bool GLXContext::Initialize(GLContext* share_context) {
GLXContext* share_context_glx = static_cast<GLXContext*>(share_context); GLXContext* share_context_glx = static_cast<GLXContext*>(share_context);
glx_context_ = glXCreateContextAttribsARB( glx_context_ = glXCreateContextAttribsARB(
display, nullptr, display, nullptr,
share_context ? share_context_glx->glx_context_ : nullptr, True, share_context ? share_context_glx->glx_context_ : nullptr, True,
attrib_list); attrib_list);
glXMakeCurrent(display, 0, nullptr); glXMakeCurrent(display, 0, nullptr);
glXDestroyContext(display, temp_context); glXDestroyContext(display, temp_context);
if (!glx_context_) { if (!glx_context_) {
@ -222,7 +216,8 @@ std::unique_ptr<GLXContext> GLXContext::CreateOffscreen(
robust_access_supported ? GLX_LOSE_CONTEXT_ON_RESET_ARB : 0, robust_access_supported ? GLX_LOSE_CONTEXT_ON_RESET_ARB : 0,
0}; 0};
new_glrc = glXCreateContextAttribsARB(parent_context->disp_, nullptr, new_glrc = glXCreateContextAttribsARB(parent_context->disp_, nullptr,
parent_context->glx_context_, True, attrib_list); parent_context->glx_context_, True,
attrib_list);
if (!new_glrc) { if (!new_glrc) {
FatalGLError("Could not create shared context."); FatalGLError("Could not create shared context.");
return nullptr; return nullptr;
@ -271,13 +266,10 @@ std::unique_ptr<GLXContext> GLXContext::CreateOffscreen(
return new_context; return new_context;
} }
bool GLXContext::is_current() { bool GLXContext::is_current() {
return tls_glew_context_ == glew_context_.get(); return tls_glew_context_ == glew_context_.get();
} }
bool GLXContext::MakeCurrent() { bool GLXContext::MakeCurrent() {
SCOPE_profile_cpu_f("gpu"); SCOPE_profile_cpu_f("gpu");
if (FLAGS_thread_safe_gl) { if (FLAGS_thread_safe_gl) {
@ -308,7 +300,6 @@ void GLXContext::ClearCurrent() {
} }
} }
void GLXContext::BeginSwap() { void GLXContext::BeginSwap() {
SCOPE_profile_cpu_i("gpu", "xe::ui::gl::GLXContext::BeginSwap"); SCOPE_profile_cpu_i("gpu", "xe::ui::gl::GLXContext::BeginSwap");
float clear_color[] = {238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 1.0f}; float clear_color[] = {238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 1.0f};

View File

@ -14,16 +14,15 @@
#include <memory> #include <memory>
#include "xenia/ui/gl/gl_context.h"
#include "xenia/ui/gl/blitter.h"
#include "xenia/ui/gl/gl.h"
#include "xenia/ui/graphics_context.h"
#include "third_party/GL/glxew.h" #include "third_party/GL/glxew.h"
#include "xenia/base/platform_linux.h" #include "xenia/base/platform_linux.h"
#include "xenia/ui/gl/blitter.h"
#include "xenia/ui/gl/gl.h"
#include "xenia/ui/gl/gl_context.h"
#include "xenia/ui/graphics_context.h"
DECLARE_bool(thread_safe_gl); DECLARE_bool(thread_safe_gl);
namespace xe { namespace xe {
namespace ui { namespace ui {
namespace gl { namespace gl {
@ -35,7 +34,6 @@ class GLXContext : public GLContext {
public: public:
~GLXContext() override; ~GLXContext() override;
bool is_current() override; bool is_current() override;
bool MakeCurrent() override; bool MakeCurrent() override;
@ -44,13 +42,12 @@ class GLXContext : public GLContext {
void BeginSwap() override; void BeginSwap() override;
void EndSwap() override; void EndSwap() override;
protected: protected:
static std::unique_ptr<GLXContext> CreateOffscreen(GraphicsProvider* provider, static std::unique_ptr<GLXContext> CreateOffscreen(
GLXContext* parent_context); GraphicsProvider* provider, GLXContext* parent_context);
bool Initialize(GLContext* share_context) override; bool Initialize(GLContext* share_context) override;
void* handle() override {return glx_context_;} void* handle() override { return glx_context_; }
private: private:
friend class GLContext; friend class GLContext;

View File

@ -14,7 +14,6 @@
namespace xe { namespace xe {
namespace ui { namespace ui {
class PostedFn { class PostedFn {
public: public:
explicit PostedFn(std::function<void()> fn) : fn_(std::move(fn)) {} explicit PostedFn(std::function<void()> fn) : fn_(std::move(fn)) {}
@ -28,7 +27,7 @@ std::unique_ptr<Loop> Loop::Create() { return std::make_unique<GTKLoop>(); }
GTKLoop::GTKLoop() : thread_id_() { GTKLoop::GTKLoop() : thread_id_() {
gtk_init(nullptr, nullptr); gtk_init(nullptr, nullptr);
xe::threading::Fence init_fence; xe::threading::Fence init_fence;
thread_ = std::thread([&init_fence, this]() { thread_ = std::thread([&init_fence, this]() {
xe::threading::set_name("GTK Loop"); xe::threading::set_name("GTK Loop");
@ -47,39 +46,31 @@ GTKLoop::~GTKLoop() {
thread_.join(); thread_.join();
} }
void GTKLoop::ThreadMain() { void GTKLoop::ThreadMain() { gtk_main(); }
gtk_main();
}
bool GTKLoop::is_on_loop_thread() { bool GTKLoop::is_on_loop_thread() {
return thread_id_ == std::this_thread::get_id(); return thread_id_ == std::this_thread::get_id();
} }
gboolean _posted_fn_thunk(gpointer posted_fn) { gboolean _posted_fn_thunk(gpointer posted_fn) {
PostedFn* Fn = reinterpret_cast<PostedFn*>(posted_fn); PostedFn* Fn = reinterpret_cast<PostedFn*>(posted_fn);
Fn->Call(); Fn->Call();
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
void GTKLoop::Post(std::function<void()> fn) { void GTKLoop::Post(std::function<void()> fn) {
assert_true(thread_id_ != std::thread::id()); assert_true(thread_id_ != std::thread::id());
gdk_threads_add_idle(_posted_fn_thunk, gdk_threads_add_idle(_posted_fn_thunk,
reinterpret_cast<gpointer>(new PostedFn(std::move(fn)))); reinterpret_cast<gpointer>(new PostedFn(std::move(fn))));
} }
void GTKLoop::PostDelayed(std::function<void()> fn, uint64_t delay_millis) { void GTKLoop::PostDelayed(std::function<void()> fn, uint64_t delay_millis) {
gdk_threads_add_timeout(delay_millis, _posted_fn_thunk, gdk_threads_add_timeout(
reinterpret_cast<gpointer>(new PostedFn(std::move(fn)))); delay_millis, _posted_fn_thunk,
reinterpret_cast<gpointer>(new PostedFn(std::move(fn))));
} }
void GTKLoop::Quit() { void GTKLoop::Quit() { assert_true(thread_id_ != std::thread::id()); }
assert_true(thread_id_ != std::thread::id());
}
void GTKLoop::AwaitQuit() { quit_fence_.Wait(); } void GTKLoop::AwaitQuit() { quit_fence_.Wait(); }

View File

@ -35,15 +35,13 @@ class GTKLoop : public Loop {
void Quit() override; void Quit() override;
void AwaitQuit() override; void AwaitQuit() override;
private:
private:
void ThreadMain(); void ThreadMain();
std::thread::id thread_id_; std::thread::id thread_id_;
std::thread thread_; std::thread thread_;
xe::threading::Fence quit_fence_; xe::threading::Fence quit_fence_;
}; };
} // namespace ui } // namespace ui

View File

@ -12,8 +12,8 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <vector>
#include <string> #include <string>
#include <vector>
#include "xenia/ui/ui_event.h" #include "xenia/ui/ui_event.h"

View File

@ -73,16 +73,15 @@ bool VulkanContext::Initialize() {
assert(GDK_IS_X11_DISPLAY(gdk_display)); assert(GDK_IS_X11_DISPLAY(gdk_display));
xcb_connection_t* connection = xcb_connection_t* connection =
XGetXCBConnection(gdk_x11_display_get_xdisplay(gdk_display)); XGetXCBConnection(gdk_x11_display_get_xdisplay(gdk_display));
xcb_window_t window = gdk_x11_window_get_xid( xcb_window_t window =
gtk_widget_get_window(window_handle)); gdk_x11_window_get_xid(gtk_widget_get_window(window_handle));
VkXcbSurfaceCreateInfoKHR create_info; VkXcbSurfaceCreateInfoKHR create_info;
create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
create_info.pNext = nullptr; create_info.pNext = nullptr;
create_info.flags = 0; create_info.flags = 0;
create_info.connection = static_cast<xcb_connection_t*> create_info.connection = static_cast<xcb_connection_t*>(
(target_window_->native_platform_handle()); target_window_->native_platform_handle());
create_info.window = create_info.window = static_cast<xcb_window_t>(window);
static_cast<xcb_window_t>(window);
auto err = vkCreateXcbSurfaceKHR(*provider->instance(), &create_info, auto err = vkCreateXcbSurfaceKHR(*provider->instance(), &create_info,
nullptr, &surface); nullptr, &surface);
CheckResult(err, "vkCreateXcbSurfaceKHR"); CheckResult(err, "vkCreateXcbSurfaceKHR");

View File

@ -397,18 +397,17 @@ bool VulkanInstance::QueryDevices(Window* any_target_window) {
assert(GDK_IS_X11_DISPLAY(gdk_display)); assert(GDK_IS_X11_DISPLAY(gdk_display));
xcb_connection_t* connection = xcb_connection_t* connection =
XGetXCBConnection(gdk_x11_display_get_xdisplay(gdk_display)); XGetXCBConnection(gdk_x11_display_get_xdisplay(gdk_display));
xcb_window_t window = gdk_x11_window_get_xid( xcb_window_t window =
gtk_widget_get_window(window_handle)); gdk_x11_window_get_xid(gtk_widget_get_window(window_handle));
VkXcbSurfaceCreateInfoKHR create_info; VkXcbSurfaceCreateInfoKHR create_info;
create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
create_info.pNext = nullptr; create_info.pNext = nullptr;
create_info.flags = 0; create_info.flags = 0;
create_info.connection = static_cast<xcb_connection_t*> create_info.connection = static_cast<xcb_connection_t*>(
(any_target_window->native_platform_handle()); any_target_window->native_platform_handle());
create_info.window = create_info.window = static_cast<xcb_window_t>(window);
static_cast<xcb_window_t>(window); auto err =
auto err = vkCreateXcbSurfaceKHR(handle, &create_info, vkCreateXcbSurfaceKHR(handle, &create_info, nullptr, &any_surface);
nullptr, &any_surface);
CheckResult(err, "vkCreateXcbSurfaceKHR"); CheckResult(err, "vkCreateXcbSurfaceKHR");
#else #else
#error Unsupported GDK Backend on Linux. #error Unsupported GDK Backend on Linux.

View File

@ -17,7 +17,6 @@
namespace xe { namespace xe {
namespace ui { namespace ui {
class FnWrapper { class FnWrapper {
public: public:
explicit FnWrapper(std::function<void()> fn) : fn_(std::move(fn)) {} explicit FnWrapper(std::function<void()> fn) : fn_(std::move(fn)) {}
@ -161,12 +160,12 @@ void GTKWindow::set_focus(bool value) {
if (value) { if (value) {
gtk_window_activate_focus(GTK_WINDOW(window_)); gtk_window_activate_focus(GTK_WINDOW(window_));
} else { } else {
// TODO(dougvj) Check to see if we need to do somethign here to unset // TODO(dougvj) Check to see if we need to do something here to unset
// the focus. // the focus.
} }
} else { } else {
has_focus_ = value; has_focus_ = value;
} }
} }
void GTKWindow::Resize(int32_t width, int32_t height) { void GTKWindow::Resize(int32_t width, int32_t height) {
@ -219,8 +218,6 @@ void GTKWindow::OnMainMenuChange() {
} }
} }
bool GTKWindow::HandleWindowOwnerChange(GdkEventOwnerChange* event) { bool GTKWindow::HandleWindowOwnerChange(GdkEventOwnerChange* event) {
if (event->type == GDK_OWNER_CHANGE) { if (event->type == GDK_OWNER_CHANGE) {
if (event->reason == GDK_OWNER_CHANGE_DESTROY) { if (event->reason == GDK_OWNER_CHANGE_DESTROY) {
@ -231,8 +228,8 @@ bool GTKWindow::HandleWindowOwnerChange(GdkEventOwnerChange* event) {
OnClose(); OnClose();
} }
return true; return true;
} }
return false; return false;
} }
bool GTKWindow::HandleWindowResize(GdkEventConfigure* event) { bool GTKWindow::HandleWindowResize(GdkEventConfigure* event) {
@ -244,8 +241,6 @@ bool GTKWindow::HandleWindowResize(GdkEventConfigure* event) {
return false; return false;
} }
bool GTKWindow::HandleWindowVisibility(GdkEventVisibility* event) { bool GTKWindow::HandleWindowVisibility(GdkEventVisibility* event) {
// TODO(dougvj) The gdk docs say that this is deprecated because modern window // TODO(dougvj) The gdk docs say that this is deprecated because modern window
// managers composite everything and nothing is truly hidden. // managers composite everything and nothing is truly hidden.
@ -258,8 +253,8 @@ bool GTKWindow::HandleWindowVisibility(GdkEventVisibility* event) {
OnHidden(&e); OnHidden(&e);
} }
return true; return true;
} }
return false; return false;
} }
bool GTKWindow::HandleWindowFocus(GdkEventFocus* event) { bool GTKWindow::HandleWindowFocus(GdkEventFocus* event) {
@ -274,8 +269,8 @@ bool GTKWindow::HandleWindowFocus(GdkEventFocus* event) {
OnGotFocus(&e); OnGotFocus(&e);
} }
return true; return true;
} }
return false; return false;
} }
bool GTKWindow::HandleMouse(GdkEventAny* event) { bool GTKWindow::HandleMouse(GdkEventAny* event) {
@ -326,26 +321,26 @@ bool GTKWindow::HandleMouse(GdkEventAny* event) {
dy = e->delta_y; dy = e->delta_y;
break; break;
} }
} }
auto e = MouseEvent(this, button, x, y, dx, dy); auto e = MouseEvent(this, button, x, y, dx, dy);
switch (event->type) { switch (event->type) {
case GDK_BUTTON_PRESS: case GDK_BUTTON_PRESS:
OnMouseDown(&e); OnMouseDown(&e);
break; break;
case GDK_BUTTON_RELEASE: case GDK_BUTTON_RELEASE:
OnMouseUp(&e); OnMouseUp(&e);
break; break;
case GDK_MOTION_NOTIFY: case GDK_MOTION_NOTIFY:
OnMouseMove(&e); OnMouseMove(&e);
break; break;
case GDK_SCROLL: case GDK_SCROLL:
OnMouseWheel(&e); OnMouseWheel(&e);
break; break;
default: default:
return false; return false;
} }
return e.is_handled(); return e.is_handled();
} }
bool GTKWindow::HandleKeyboard(GdkEventKey* event) { bool GTKWindow::HandleKeyboard(GdkEventKey* event) {
@ -364,8 +359,8 @@ bool GTKWindow::HandleKeyboard(GdkEventKey* event) {
case GDK_KEY_RELEASE: case GDK_KEY_RELEASE:
OnKeyUp(&e); OnKeyUp(&e);
break; break;
// TODO(dougvj) GDK doesn't have a KEY CHAR event, so we will have to // TODO(dougvj) GDK doesn't have a KEY CHAR event, so we will have to
// figure out its equivalent here to call OnKeyChar(&e); // figure out its equivalent here to call OnKeyChar(&e);
default: default:
return false; return false;
} }

View File

@ -13,9 +13,9 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "xenia/base/platform_linux.h"
#include "xenia/ui/menu_item.h" #include "xenia/ui/menu_item.h"
#include "xenia/ui/window.h" #include "xenia/ui/window.h"
#include "xenia/base/platform_linux.h"
namespace xe { namespace xe {
namespace ui { namespace ui {
@ -27,9 +27,10 @@ class GTKWindow : public Window {
GTKWindow(Loop* loop, const std::wstring& title); GTKWindow(Loop* loop, const std::wstring& title);
~GTKWindow() override; ~GTKWindow() override;
NativePlatformHandle native_platform_handle() const override {return nullptr;} NativePlatformHandle native_platform_handle() const override {
NativeWindowHandle native_handle() const override { return window_;} return nullptr;
}
NativeWindowHandle native_handle() const override { return window_; }
bool set_title(const std::wstring& title) override; bool set_title(const std::wstring& title) override;
@ -60,7 +61,6 @@ class GTKWindow : public Window {
void OnResize(UIEvent* e) override; void OnResize(UIEvent* e) override;
private: private:
void Create(); void Create();
GtkWidget* window_; GtkWidget* window_;
@ -75,16 +75,15 @@ class GTKWindow : public Window {
bool closing_ = false; bool closing_ = false;
bool fullscreen_ = false; bool fullscreen_ = false;
}; };
class GTKMenuItem : public MenuItem { class GTKMenuItem : public MenuItem {
public: public:
GTKMenuItem(Type type, const std::wstring& text, const std::wstring& hotkey, GTKMenuItem(Type type, const std::wstring& text, const std::wstring& hotkey,
std::function<void()> callback); std::function<void()> callback);
~GTKMenuItem() override; ~GTKMenuItem() override;
GtkWidget* handle() {return menu_;} GtkWidget* handle() { return menu_; }
using MenuItem::OnSelected; using MenuItem::OnSelected;
protected: protected: