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,7 +24,6 @@ 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
} }

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);
@ -44,7 +43,9 @@ static int removeCallback(const char *fpath, const struct stat* sb,
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) {
@ -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,8 +14,8 @@
#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>
@ -23,9 +23,7 @@ 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),
@ -65,27 +61,20 @@ SleepResult AlertableSleep(std::chrono::microseconds duration) {
// 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();
@ -155,8 +144,7 @@ class PosixCondition {
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
@ -175,7 +163,6 @@ class PosixCondition {
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
@ -208,7 +195,6 @@ 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) {
@ -233,7 +219,6 @@ 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:
@ -242,6 +227,7 @@ class PosixEvent: public PosixConditionHandle<Event> {
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_;
}; };
@ -273,12 +259,12 @@ std::unique_ptr<Semaphore> Semaphore::Create(int initial_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) {
@ -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

@ -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,7 +36,6 @@ 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);
@ -45,14 +44,10 @@ bool GtkFilePicker::Show(void* parent_window_handle) {
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;
@ -68,7 +63,7 @@ bool GtkFilePicker::Show(void* parent_window_handle) {
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,8 +49,6 @@ 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) {}
@ -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,18 +24,15 @@
#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) {
@ -48,7 +45,6 @@ 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,
@ -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,22 +23,16 @@
#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) {
@ -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");
@ -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,10 +42,9 @@ 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_; }

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)) {}
@ -47,17 +46,12 @@ 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();
@ -70,16 +64,13 @@ void GTKLoop::Post(std::function<void()> fn) {
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(
delay_millis, _posted_fn_thunk,
reinterpret_cast<gpointer>(new PostedFn(std::move(fn)))); 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,7 +160,7 @@ 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 {
@ -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) {
@ -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.

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,10 +27,11 @@ 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 {
return nullptr;
}
NativeWindowHandle native_handle() const override { return window_; } NativeWindowHandle native_handle() const override { return window_; }
bool set_title(const std::wstring& title) override; bool set_title(const std::wstring& title) override;
bool SetIcon(const void* buffer, size_t size) override; bool SetIcon(const void* buffer, size_t size) 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,7 +75,6 @@ class GTKWindow : public Window {
bool closing_ = false; bool closing_ = false;
bool fullscreen_ = false; bool fullscreen_ = false;
}; };
class GTKMenuItem : public MenuItem { class GTKMenuItem : public MenuItem {