Starting to remove windows.h includes from things.

This commit is contained in:
Ben Vanik 2015-07-13 20:49:29 -07:00
parent 31dab70a3a
commit 72ad899e9e
33 changed files with 195 additions and 109 deletions

View File

@ -17,6 +17,7 @@
<ItemGroup>
<ClCompile Include="src\xenia\base\arena.cc" />
<ClCompile Include="src\xenia\base\clock.cc" />
<ClCompile Include="src\xenia\base\clock_win.cc" />
<ClCompile Include="src\xenia\base\debugging_win.cc" />
<ClCompile Include="src\xenia\base\filesystem.cc" />
<ClCompile Include="src\xenia\base\filesystem_win.cc" />
@ -45,6 +46,7 @@
<ClInclude Include="src\xenia\base\memory.h" />
<ClInclude Include="src\xenia\base\mutex.h" />
<ClInclude Include="src\xenia\base\platform.h" />
<ClInclude Include="src\xenia\base\platform_win.h" />
<ClInclude Include="src\xenia\base\reset_scope.h" />
<ClInclude Include="src\xenia\base\ring_buffer.h" />
<ClInclude Include="src\xenia\base\string.h" />
@ -141,4 +143,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View File

@ -54,6 +54,9 @@
<ClCompile Include="src\xenia\base\threading_win.cc">
<Filter>src\xenia\base</Filter>
</ClCompile>
<ClCompile Include="src\xenia\base\clock_win.cc">
<Filter>src\xenia\base</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\xenia\base\arena.h">
@ -119,5 +122,8 @@
<ClInclude Include="src\xenia\base\vec128.h">
<Filter>src\xenia\base</Filter>
</ClInclude>
<ClInclude Include="src\xenia\base\platform_win.h">
<Filter>src\xenia\base</Filter>
</ClInclude>
</ItemGroup>
</Project>
</Project>

View File

@ -17,6 +17,8 @@
#include "xenia/emulator.h"
#include "xenia/xbox.h"
typedef void* HANDLE;
namespace xe {
namespace kernel {
class XHostThread;

View File

@ -9,6 +9,8 @@
#include "xenia/apu/xaudio2/xaudio2_audio_driver.h"
// Must be included before xaudio2.h so we get the right windows.h include.
#include "xenia/base/platform_win.h"
#include <xaudio2.h>
#include "xenia/apu/apu_flags.h"

View File

@ -60,39 +60,40 @@ inline bool atomic_cas(int64_t old_value, int64_t new_value,
#elif XE_PLATFORM_WIN32
inline int32_t atomic_inc(volatile int32_t* value) {
return InterlockedIncrement(reinterpret_cast<volatile LONG*>(value));
return _InterlockedIncrement(reinterpret_cast<volatile long*>(value));
}
inline int32_t atomic_dec(volatile int32_t* value) {
return InterlockedDecrement(reinterpret_cast<volatile LONG*>(value));
return _InterlockedDecrement(reinterpret_cast<volatile long*>(value));
}
inline int32_t atomic_exchange(int32_t new_value, volatile int32_t* value) {
return InterlockedExchange(reinterpret_cast<volatile LONG*>(value),
new_value);
return _InterlockedExchange(reinterpret_cast<volatile long*>(value),
new_value);
}
inline int64_t atomic_exchange(int64_t new_value, volatile int64_t* value) {
return InterlockedExchange64(reinterpret_cast<volatile LONGLONG*>(value),
new_value);
return _InterlockedExchange64(reinterpret_cast<volatile long long*>(value),
new_value);
}
inline int32_t atomic_exchange_add(int32_t amount, volatile int32_t* value) {
return InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(value),
amount);
return _InterlockedExchangeAdd(reinterpret_cast<volatile long*>(value),
amount);
}
inline int64_t atomic_exchange_add(int64_t amount, volatile int64_t* value) {
return InterlockedExchangeAdd64(reinterpret_cast<volatile LONGLONG*>(value),
amount);
return _InterlockedExchangeAdd64(reinterpret_cast<volatile long long*>(value),
amount);
}
inline bool atomic_cas(int32_t old_value, int32_t new_value,
volatile int32_t* value) {
return InterlockedCompareExchange(reinterpret_cast<volatile LONG*>(value),
new_value, old_value) == old_value;
return _InterlockedCompareExchange(reinterpret_cast<volatile long*>(value),
new_value, old_value) == old_value;
}
inline bool atomic_cas(int64_t old_value, int64_t new_value,
volatile int64_t* value) {
return InterlockedCompareExchange64(reinterpret_cast<volatile LONG64*>(value),
new_value, old_value) == old_value;
return _InterlockedCompareExchange64(
reinterpret_cast<volatile long long*>(value), new_value,
old_value) == old_value;
}
#elif XE_PLATFORM_LINUX

View File

@ -13,7 +13,6 @@
#include <climits>
#include "xenia/base/assert.h"
#include "xenia/base/platform.h"
namespace xe {
@ -48,31 +47,6 @@ void UpdateGuestClock() {
guest_time_filetime_ += (guest_tick_delta * 10000000) / guest_tick_frequency_;
}
uint64_t Clock::host_tick_frequency() {
static LARGE_INTEGER frequency = {0};
if (!frequency.QuadPart) {
QueryPerformanceFrequency(&frequency);
}
return frequency.QuadPart;
}
uint64_t Clock::QueryHostTickCount() {
LARGE_INTEGER counter;
uint64_t time = 0;
if (QueryPerformanceCounter(&counter)) {
time = counter.QuadPart;
}
return time;
}
uint64_t Clock::QueryHostSystemTime() {
FILETIME t;
GetSystemTimeAsFileTime(&t);
return (uint64_t(t.dwHighDateTime) << 32) | t.dwLowDateTime;
}
uint32_t Clock::QueryHostUptimeMillis() { return ::GetTickCount(); }
double Clock::guest_time_scalar() { return guest_time_scalar_; }
void Clock::set_guest_time_scalar(double scalar) {

View File

@ -0,0 +1,41 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "xenia/base/clock.h"
#include "xenia/base/platform_win.h"
namespace xe {
uint64_t Clock::host_tick_frequency() {
static LARGE_INTEGER frequency = {0};
if (!frequency.QuadPart) {
QueryPerformanceFrequency(&frequency);
}
return frequency.QuadPart;
}
uint64_t Clock::QueryHostTickCount() {
LARGE_INTEGER counter;
uint64_t time = 0;
if (QueryPerformanceCounter(&counter)) {
time = counter.QuadPart;
}
return time;
}
uint64_t Clock::QueryHostSystemTime() {
FILETIME t;
GetSystemTimeAsFileTime(&t);
return (uint64_t(t.dwHighDateTime) << 32) | t.dwLowDateTime;
}
uint32_t Clock::QueryHostUptimeMillis() { return ::GetTickCount(); }
} // namespace xe

View File

@ -9,7 +9,7 @@
#include "xenia/base/debugging.h"
#include "xenia/base/platform.h"
#include "xenia/base/platform_win.h"
#include "xenia/base/string_buffer.h"
namespace xe {

View File

@ -11,7 +11,7 @@
#include <string>
#include "xenia/base/platform.h"
#include "xenia/base/platform_win.h"
namespace xe {
namespace filesystem {

View File

@ -11,12 +11,19 @@
#include <gflags/gflags.h>
#include <cstdarg>
#include <mutex>
#include "xenia/base/main.h"
#include "xenia/base/math.h"
#include "xenia/base/threading.h"
// For MessageBox:
// TODO(benvanik): generic API? logging_win.cc?
#if XE_PLATFORM_WIN32
#include "xenia/base/platform_win.h"
#endif // XE_PLATFORM_WIN32
DEFINE_bool(fast_stdout, false,
"Don't lock around stdout/stderr. May introduce weirdness.");
DEFINE_bool(flush_stdout, true, "Flush stdout after each log line.");

View File

@ -13,6 +13,7 @@
#include <gflags/gflags.h>
#include <io.h>
#include "xenia/base/platform_win.h"
#include "xenia/base/string.h"
namespace xe {

View File

@ -15,7 +15,7 @@
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/base/platform.h"
#include "xenia/base/platform_win.h"
namespace xe {

View File

@ -72,27 +72,27 @@ inline uint8_t lzcnt(uint32_t v) { return static_cast<uint8_t>(__lzcnt(v)); }
inline uint8_t lzcnt(uint64_t v) { return static_cast<uint8_t>(__lzcnt64(v)); }
#else
inline uint8_t lzcnt(uint8_t v) {
DWORD index;
DWORD mask = v;
BOOLEAN is_nonzero = _BitScanReverse(&index, mask);
unsigned long index;
unsigned long mask = v;
unsigned char is_nonzero = _BitScanReverse(&index, mask);
return static_cast<uint8_t>(is_nonzero ? int8_t(index) ^ 0x7 : 8);
}
inline uint8_t lzcnt(uint16_t v) {
DWORD index;
DWORD mask = v;
BOOLEAN is_nonzero = _BitScanReverse(&index, mask);
unsigned long index;
unsigned long mask = v;
unsigned char is_nonzero = _BitScanReverse(&index, mask);
return static_cast<uint8_t>(is_nonzero ? int8_t(index) ^ 0xF : 16);
}
inline uint8_t lzcnt(uint32_t v) {
DWORD index;
DWORD mask = v;
BOOLEAN is_nonzero = _BitScanReverse(&index, mask);
unsigned long index;
unsigned long mask = v;
unsigned char is_nonzero = _BitScanReverse(&index, mask);
return static_cast<uint8_t>(is_nonzero ? int8_t(index) ^ 0x1F : 32);
}
inline uint8_t lzcnt(uint64_t v) {
DWORD index;
DWORD64 mask = v;
BOOLEAN is_nonzero = _BitScanReverse64(&index, mask);
unsigned long index;
unsigned long long mask = v;
unsigned char is_nonzero = _BitScanReverse64(&index, mask);
return static_cast<uint8_t>(is_nonzero ? int8_t(index) ^ 0x3F : 64);
}
#endif // LZCNT supported

View File

@ -28,8 +28,6 @@ size_t hash_combine(size_t seed, const T& v, const Ts&... vs) {
return hash_combine(seed, vs...);
}
size_t page_size();
constexpr void* low_address(void* address) {
return (void*)(uint64_t(address) & 0xFFFFFFFF);
}

View File

@ -11,26 +11,8 @@
#include <algorithm>
#if !XE_PLATFORM_WIN32
#include <unistd.h>
#endif // !XE_PLATFORM_WIN32
namespace xe {
size_t page_size() {
static size_t value = 0;
if (!value) {
#if XE_PLATFORM_WIN32
SYSTEM_INFO si;
GetSystemInfo(&si);
value = si.dwAllocationGranularity;
#else
value = getpagesize();
#endif // XE_PLATFORM_WIN32
}
return value;
}
// TODO(benvanik): fancy AVX versions.
// http://gnuradio.org/redmine/projects/gnuradio/repository/revisions/cb32b70b79f430456208a2cd521d028e0ece5d5b/entry/volk/kernels/volk/volk_16u_byteswap.h
// http://gnuradio.org/redmine/projects/gnuradio/repository/revisions/f2bc76cc65ffba51a141950f98e75364e49df874/entry/volk/kernels/volk/volk_32u_byteswap.h

View File

@ -14,7 +14,7 @@
#include <mutex>
#include <type_traits>
#include "xenia/base/platform.h"
#include "xenia/base/platform_win.h"
namespace xe {

View File

@ -10,9 +10,15 @@
#ifndef XENIA_BASE_PLATFORM_H_
#define XENIA_BASE_PLATFORM_H_
// This file contains the main platform switches used by xenia as well as any
// fixups required to normalize the environment. Everything in here should be
// largely portable.
// Platform-specific headers, like platform_win.h, are used to house any
// super platform-specific stuff that implies code is not platform-agnostic.
//
// NOTE: ordering matters here as sometimes multiple flags are defined on
// certain platforms.
//
// Great resource on predefined macros: http://predef.sourceforge.net/preos.html
#if defined(__APPLE__)
@ -42,25 +48,12 @@
#endif
#if XE_PLATFORM_WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#define NOMINMAX
#include <SDKDDKVer.h>
#include <windows.h>
#include <ObjBase.h>
#include <shellapi.h>
#include <shlwapi.h>
#include <shobjidl.h>
#include <dwmapi.h>
#include <tpcshrd.h>
#include <windowsx.h>
#define strdup _strdup
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#undef DeleteBitmap
#undef GetFirstChild
#endif // XE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX // Don't want windows.h including min/max macros.
#endif // XE_PLATFORM_WIN32
#if XE_COMPILER_MSVC
#include <intrin.h>
@ -73,15 +66,19 @@ namespace xe {
#if XE_PLATFORM_WIN32
const char path_separator = '\\';
const wchar_t wpath_separator = L'\\';
const size_t max_path = _MAX_PATH;
const size_t max_path = 260; // _MAX_PATH
#else
const char path_separator = '/';
const wchar_t wpath_separator = L'/';
const size_t max_path = 1024; // PATH_MAX
#endif // XE_PLATFORM_WIN32
// Launches a web browser to the given URL.
void LaunchBrowser(const char* url);
// Returns the native page size of the system, in bytes.
size_t page_size();
} // namespace xe
#endif // XENIA_BASE_PLATFORM_H_

View File

@ -7,10 +7,20 @@
******************************************************************************
*/
#include "xenia/base/platform.h"
#include "xenia/base/platform_win.h"
namespace xe {
size_t page_size() {
static size_t value = 0;
if (!value) {
SYSTEM_INFO si;
GetSystemInfo(&si);
value = si.dwAllocationGranularity;
}
return value;
}
void LaunchBrowser(const char* url) {
ShellExecuteA(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
}

View File

@ -0,0 +1,36 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_BASE_PLATFORM_WIN_H_
#define XENIA_BASE_PLATFORM_WIN_H_
// NOTE: if you're including this file it means you are explicitly depending
// on Windows-specific headers. This is bad for portability and should be
// avoided!
#include "xenia/base/platform.h"
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#define NOMINMAX
#include <SDKDDKVer.h>
#include <windows.h>
#include <ObjBase.h>
#include <shellapi.h>
#include <shlwapi.h>
#include <shobjidl.h>
#include <dwmapi.h>
#include <tpcshrd.h>
#include <windowsx.h>
#undef DeleteBitmap
#undef DeleteFile
#undef GetFirstChild
#endif // XENIA_BASE_PLATFORM_WIN_H_

View File

@ -9,7 +9,7 @@
#include "xenia/base/threading.h"
#include "xenia/base/platform.h"
#include "xenia/base/platform_win.h"
namespace xe {
namespace threading {

View File

@ -16,7 +16,7 @@
#include <vector>
#include "xenia/base/mutex.h"
#include "xenia/base/platform.h"
#include "xenia/base/platform_win.h"
#include "xenia/cpu/backend/code_cache.h"
namespace xe {

View File

@ -9,6 +9,7 @@
#include "xenia/hid/winkey/winkey_input_driver.h"
#include "xenia/base/platform_win.h"
#include "xenia/hid/hid_flags.h"
namespace xe {

View File

@ -9,6 +9,8 @@
#include "xenia/hid/xinput/xinput_input_driver.h"
// Must be included before xinput.h to avoid windows.h conflicts:
#include "xenia/base/platform_win.h"
#include <xinput.h>
#include "xenia/hid/hid_flags.h"

View File

@ -10,6 +10,7 @@
#ifndef XENIA_KERNEL_XBOXKRNL_XEVENT_H_
#define XENIA_KERNEL_XBOXKRNL_XEVENT_H_
#include "xenia/base/platform_win.h"
#include "xenia/kernel/xobject.h"
#include "xenia/xbox.h"

View File

@ -10,6 +10,7 @@
#ifndef XENIA_KERNEL_XBOXKRNL_XMUTANT_H_
#define XENIA_KERNEL_XBOXKRNL_XMUTANT_H_
#include "xenia/base/platform_win.h"
#include "xenia/kernel/xobject.h"
#include "xenia/xbox.h"

View File

@ -10,6 +10,7 @@
#ifndef XENIA_KERNEL_XBOXKRNL_XSEMAPHORE_H_
#define XENIA_KERNEL_XBOXKRNL_XSEMAPHORE_H_
#include "xenia/base/platform_win.h"
#include "xenia/kernel/xobject.h"
#include "xenia/xbox.h"

View File

@ -10,6 +10,7 @@
#ifndef XENIA_KERNEL_XBOXKRNL_XTIMER_H_
#define XENIA_KERNEL_XBOXKRNL_XTIMER_H_
#include "xenia/base/platform_win.h"
#include "xenia/kernel/xobject.h"
#include "xenia/xbox.h"

View File

@ -17,7 +17,7 @@
#include <vector>
#include "xenia/base/mutex.h"
#include "xenia/base/platform.h"
#include "xenia/base/platform_win.h"
#include "xenia/cpu/mmio_handler.h"
namespace xe {

View File

@ -9,8 +9,8 @@
#include "xenia/ui/file_picker.h"
#include "xenia/base/platform.h"
#include "xenia/base/assert.h"
#include "xenia/base/platform_win.h"
namespace xe {
namespace ui {

View File

@ -13,9 +13,15 @@
#include "xenia/base/platform.h"
#include "third_party/GL/glew.h"
#include "third_party/GL/wglew.h"
extern "C" GLEWContext* glewGetContext();
#if XE_PLATFORM_WIN32
// We avoid including wglew.h here as it includes windows.h and pollutes the
// global namespace. As we don't need wglew most places we only do that as
// required.
typedef struct WGLEWContextStruct WGLEWContext;
extern "C" WGLEWContext* wglewGetContext();
#endif // XE_PLATFORM_WIN32
#endif // XENIA_UI_GL_GL_H_

View File

@ -20,6 +20,10 @@
#include "xenia/ui/gl/gl4_elemental_renderer.h"
#include "xenia/ui/window.h"
// TODO(benvanik): move win32 code to _win?
#include "xenia/base/platform_win.h"
#include "third_party/GL/wglew.h"
DEFINE_bool(thread_safe_gl, false,
"Only allow one GL context to be active at a time.");
@ -52,11 +56,16 @@ std::unique_ptr<GLContext> GLContext::Create(Window* target_window) {
return context;
}
GLContext::GLContext(Window* target_window) : GraphicsContext(target_window) {}
GLContext::GLContext(Window* target_window) : GraphicsContext(target_window) {
glew_context_.reset(new GLEWContext());
wglew_context_.reset(new WGLEWContext());
}
GLContext::GLContext(Window* target_window, HGLRC glrc)
: GraphicsContext(target_window), glrc_(glrc) {
dc_ = GetDC(HWND(target_window_->native_handle()));
glew_context_.reset(new GLEWContext());
wglew_context_.reset(new WGLEWContext());
}
GLContext::~GLContext() {
@ -100,8 +109,8 @@ bool GLContext::Initialize(Window* target_window) {
}
wglMakeCurrent(dc_, temp_context);
tls_glew_context_ = &glew_context_;
tls_wglew_context_ = &wglew_context_;
tls_glew_context_ = glew_context_.get();
tls_wglew_context_ = wglew_context_.get();
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK) {
XELOGE("Unable to initialize GLEW");
@ -403,8 +412,8 @@ bool GLContext::MakeCurrent() {
XELOGE("Unable to make GL context current");
return false;
}
tls_glew_context_ = &glew_context_;
tls_wglew_context_ = &wglew_context_;
tls_glew_context_ = glew_context_.get();
tls_wglew_context_ = wglew_context_.get();
return true;
}

View File

@ -20,6 +20,10 @@
DECLARE_bool(thread_safe_gl);
// TODO(benvanik): hide Win32 stuff.
typedef struct HDC__* HDC;
typedef struct HGLRC__* HGLRC;
namespace xe {
namespace ui {
namespace gl {
@ -61,8 +65,8 @@ class GLContext : public GraphicsContext {
HDC dc_ = nullptr;
HGLRC glrc_ = nullptr;
GLEWContext glew_context_;
WGLEWContext wglew_context_;
std::unique_ptr<GLEWContext> glew_context_;
std::unique_ptr<WGLEWContext> wglew_context_;
Blitter blitter_;
};

View File

@ -11,6 +11,7 @@
#include "xenia/base/assert.h"
#include "xenia/base/logging.h"
#include "xenia/base/platform_win.h"
#include "xenia/ui/window_win.h"
namespace xe {