mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-21 07:25:39 -04:00
UI: Massive revamp, new features and improvements
This commit is contained in:
@ -896,6 +896,105 @@ void GrowableMemoryByteStream::Grow(u32 MinimumGrowth)
|
||||
ResizeMemory(NewSize);
|
||||
}
|
||||
|
||||
bool ByteStream::ReadU8(u8* dest)
|
||||
{
|
||||
return Read2(dest, sizeof(u8));
|
||||
}
|
||||
|
||||
bool ByteStream::ReadU16(u16* dest)
|
||||
{
|
||||
return Read2(dest, sizeof(u16));
|
||||
}
|
||||
|
||||
bool ByteStream::ReadU32(u32* dest)
|
||||
{
|
||||
return Read2(dest, sizeof(u32));
|
||||
}
|
||||
|
||||
bool ByteStream::ReadU64(u64* dest)
|
||||
{
|
||||
return Read2(dest, sizeof(u64));
|
||||
}
|
||||
|
||||
bool ByteStream::ReadS8(s8* dest)
|
||||
{
|
||||
return Read2(dest, sizeof(s8));
|
||||
}
|
||||
|
||||
bool ByteStream::ReadS16(s16* dest)
|
||||
{
|
||||
return Read2(dest, sizeof(s16));
|
||||
}
|
||||
|
||||
bool ByteStream::ReadS32(s32* dest)
|
||||
{
|
||||
return Read2(dest, sizeof(s32));
|
||||
}
|
||||
|
||||
bool ByteStream::ReadS64(s64* dest)
|
||||
{
|
||||
return Read2(dest, sizeof(s64));
|
||||
}
|
||||
|
||||
bool ByteStream::ReadSizePrefixedString(std::string* dest)
|
||||
{
|
||||
u32 size;
|
||||
if (!Read2(&size, sizeof(size)))
|
||||
return false;
|
||||
|
||||
dest->resize(size);
|
||||
if (!Read2(dest->data(), size))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ByteStream::WriteU8(u8 dest)
|
||||
{
|
||||
return Write2(&dest, sizeof(u8));
|
||||
}
|
||||
|
||||
bool ByteStream::WriteU16(u16 dest)
|
||||
{
|
||||
return Write2(&dest, sizeof(u16));
|
||||
}
|
||||
|
||||
bool ByteStream::WriteU32(u32 dest)
|
||||
{
|
||||
return Write2(&dest, sizeof(u32));
|
||||
}
|
||||
|
||||
bool ByteStream::WriteU64(u64 dest)
|
||||
{
|
||||
return Write2(&dest, sizeof(u64));
|
||||
}
|
||||
|
||||
bool ByteStream::WriteS8(s8 dest)
|
||||
{
|
||||
return Write2(&dest, sizeof(s8));
|
||||
}
|
||||
|
||||
bool ByteStream::WriteS16(s16 dest)
|
||||
{
|
||||
return Write2(&dest, sizeof(s16));
|
||||
}
|
||||
|
||||
bool ByteStream::WriteS32(s32 dest)
|
||||
{
|
||||
return Write2(&dest, sizeof(s32));
|
||||
}
|
||||
|
||||
bool ByteStream::WriteS64(s64 dest)
|
||||
{
|
||||
return Write2(&dest, sizeof(s64));
|
||||
}
|
||||
|
||||
bool ByteStream::WriteSizePrefixedString(const std::string_view& str)
|
||||
{
|
||||
const u32 size = static_cast<u32>(str.size());
|
||||
return (Write2(&size, sizeof(size)) && (size == 0 || Write2(str.data(), size)));
|
||||
}
|
||||
|
||||
std::unique_ptr<ByteStream> ByteStream::OpenFile(const char* fileName, u32 openMode)
|
||||
{
|
||||
if ((openMode & (BYTESTREAM_OPEN_CREATE | BYTESTREAM_OPEN_WRITE)) == BYTESTREAM_OPEN_WRITE)
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "types.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
// base byte stream creation functions
|
||||
@ -76,6 +77,26 @@ public:
|
||||
inline void SetErrorState() { m_errorState = true; }
|
||||
inline void ClearErrorState() { m_errorState = false; }
|
||||
|
||||
bool ReadU8(u8* dest);
|
||||
bool ReadU16(u16* dest);
|
||||
bool ReadU32(u32* dest);
|
||||
bool ReadU64(u64* dest);
|
||||
bool ReadS8(s8* dest);
|
||||
bool ReadS16(s16* dest);
|
||||
bool ReadS32(s32* dest);
|
||||
bool ReadS64(s64* dest);
|
||||
bool ReadSizePrefixedString(std::string* dest);
|
||||
|
||||
bool WriteU8(u8 dest);
|
||||
bool WriteU16(u16 dest);
|
||||
bool WriteU32(u32 dest);
|
||||
bool WriteU64(u64 dest);
|
||||
bool WriteS8(s8 dest);
|
||||
bool WriteS16(s16 dest);
|
||||
bool WriteS32(s32 dest);
|
||||
bool WriteS64(s64 dest);
|
||||
bool WriteSizePrefixedString(const std::string_view& str);
|
||||
|
||||
// base byte stream creation functions
|
||||
// opens a local file-based stream. fills in error if passed, and returns false if the file cannot be opened.
|
||||
static std::unique_ptr<ByteStream> OpenFile(const char* FileName, u32 OpenMode);
|
||||
|
@ -167,7 +167,7 @@ std::string ShaderCache::GetCacheBaseFileName(const std::string_view& base_path,
|
||||
bool debug)
|
||||
{
|
||||
std::string base_filename(base_path);
|
||||
base_filename += "d3d_shaders_";
|
||||
base_filename += FS_OSPATH_SEPARATOR_STR "d3d_shaders_";
|
||||
|
||||
switch (feature_level)
|
||||
{
|
||||
|
@ -226,7 +226,7 @@ std::string ShaderCache::GetCacheBaseFileName(const std::string_view& base_path,
|
||||
D3D_FEATURE_LEVEL feature_level, bool debug)
|
||||
{
|
||||
std::string base_filename(base_path);
|
||||
base_filename += "d3d12_";
|
||||
base_filename += FS_OSPATH_SEPARATOR_STR "d3d12_";
|
||||
base_filename += type;
|
||||
base_filename += "_";
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "../file_system.h"
|
||||
#include "../log.h"
|
||||
#include "../md5_digest.h"
|
||||
#include "../path.h"
|
||||
#include "../string_util.h"
|
||||
Log_SetChannel(GL::ShaderCache);
|
||||
|
||||
@ -251,12 +252,12 @@ ShaderCache::CacheIndexKey ShaderCache::GetCacheKey(const std::string_view& vert
|
||||
|
||||
std::string ShaderCache::GetIndexFileName() const
|
||||
{
|
||||
return StringUtil::StdStringFromFormat("%sgl_programs.idx", m_base_path.c_str());
|
||||
return Path::Combine(m_base_path, "gl_programs.idx");
|
||||
}
|
||||
|
||||
std::string ShaderCache::GetBlobFileName() const
|
||||
{
|
||||
return StringUtil::StdStringFromFormat("%sgl_programs.bin", m_base_path.c_str());
|
||||
return Path::Combine(m_base_path, "gl_programs.bin");
|
||||
}
|
||||
|
||||
std::optional<Program> ShaderCache::GetProgram(const std::string_view vertex_shader,
|
||||
|
@ -7,7 +7,7 @@ Log_SetChannel(HTTPDownloader);
|
||||
static constexpr float DEFAULT_TIMEOUT_IN_SECONDS = 30;
|
||||
static constexpr u32 DEFAULT_MAX_ACTIVE_REQUESTS = 4;
|
||||
|
||||
namespace FrontendCommon {
|
||||
namespace Common {
|
||||
|
||||
const char HTTPDownloader::DEFAULT_USER_AGENT[] =
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0";
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace FrontendCommon {
|
||||
namespace Common {
|
||||
|
||||
class HTTPDownloader
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <signal.h>
|
||||
Log_SetChannel(HTTPDownloaderCurl);
|
||||
|
||||
namespace FrontendCommon {
|
||||
namespace Common {
|
||||
|
||||
HTTPDownloaderCurl::HTTPDownloaderCurl() : HTTPDownloader() {}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <mutex>
|
||||
#include <curl/curl.h>
|
||||
|
||||
namespace FrontendCommon {
|
||||
namespace Common {
|
||||
|
||||
class HTTPDownloaderCurl final : public HTTPDownloader
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ Log_SetChannel(HTTPDownloaderWinHttp);
|
||||
using namespace winrt::Windows::Foundation;
|
||||
using namespace winrt::Windows::Web::Http;
|
||||
|
||||
namespace FrontendCommon {
|
||||
namespace Common {
|
||||
|
||||
HTTPDownloaderUWP::HTTPDownloaderUWP(std::string user_agent) : HTTPDownloader(), m_user_agent(std::move(user_agent)) {}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <winrt/windows.Web.Http.h>
|
||||
|
||||
namespace FrontendCommon {
|
||||
namespace Common {
|
||||
|
||||
class HTTPDownloaderUWP final : public HTTPDownloader
|
||||
{
|
||||
|
@ -9,7 +9,7 @@ Log_SetChannel(HTTPDownloaderWinHttp);
|
||||
|
||||
#pragma comment(lib, "winhttp.lib")
|
||||
|
||||
namespace FrontendCommon {
|
||||
namespace Common {
|
||||
|
||||
HTTPDownloaderWinHttp::HTTPDownloaderWinHttp() : HTTPDownloader() {}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include <winhttp.h>
|
||||
|
||||
namespace FrontendCommon {
|
||||
namespace Common {
|
||||
|
||||
class HTTPDownloaderWinHttp final : public HTTPDownloader
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "heterogeneous_containers.h"
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
|
||||
@ -13,7 +14,7 @@ class LRUCache
|
||||
CounterType last_access;
|
||||
};
|
||||
|
||||
using MapType = std::map<K, Item>;
|
||||
using MapType = std::conditional_t<std::is_same_v<K, std::string>, StringMap<Item>, std::map<K, Item>>;
|
||||
|
||||
public:
|
||||
LRUCache(std::size_t max_capacity = 16, bool manual_evict = false)
|
||||
|
@ -24,15 +24,18 @@
|
||||
#include <sys/syscall.h>
|
||||
#define gettid() syscall(SYS_gettid)
|
||||
#endif
|
||||
#else
|
||||
#elif defined(__APPLE__)
|
||||
#include <mach/mach.h>
|
||||
#include <mach/mach_error.h>
|
||||
#include <mach/mach_time.h>
|
||||
#include <mach/semaphore.h>
|
||||
#include <mach/task.h>
|
||||
#include <pthread_np.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
// This hacky union would probably fail on some cpu platforms if the contents of FILETIME aren't
|
||||
// packed (but for any x86 CPU and microsoft compiler, they will be).
|
||||
union FileTimeSucks
|
||||
union FileTimeU64Union
|
||||
{
|
||||
FILETIME filetime;
|
||||
u64 u64time;
|
||||
@ -208,18 +211,16 @@ Threading::ThreadHandle& Threading::ThreadHandle::operator=(const ThreadHandle&
|
||||
|
||||
u64 Threading::ThreadHandle::GetCPUTime() const
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
#if 0
|
||||
#if defined(_WIN32) && !defined(_UWP) && !defined(_M_ARM64)
|
||||
u64 ret = 0;
|
||||
if (m_native_handle)
|
||||
QueryThreadCycleTime((HANDLE)m_native_handle, &ret);
|
||||
return ret;
|
||||
#else
|
||||
FileTimeSucks user = {}, kernel = {};
|
||||
#elif defined(_WIN32)
|
||||
FileTimeU64Union user = {}, kernel = {};
|
||||
FILETIME dummy;
|
||||
GetThreadTimes((HANDLE)m_native_handle, &dummy, &dummy, &kernel.filetime, &user.filetime);
|
||||
return user.u64time + kernel.u64time;
|
||||
#endif
|
||||
#elif defined(__APPLE__)
|
||||
return getthreadtime(pthread_mach_thread_np((pthread_t)m_native_handle));
|
||||
#elif defined(__linux__)
|
||||
@ -457,17 +458,15 @@ Threading::ThreadHandle& Threading::Thread::operator=(Thread&& thread)
|
||||
|
||||
u64 Threading::GetThreadCpuTime()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
#if 0
|
||||
#if defined(_WIN32) && !defined(_UWP) && !defined(_M_ARM64)
|
||||
u64 ret = 0;
|
||||
QueryThreadCycleTime(GetCurrentThread(), &ret);
|
||||
return ret;
|
||||
#else
|
||||
FileTimeSucks user = {}, kernel = {};
|
||||
#elif defined(_WIN32)
|
||||
FileTimeU64Union user = {}, kernel = {};
|
||||
FILETIME dummy;
|
||||
GetThreadTimes(GetCurrentThread(), &dummy, &dummy, &kernel.filetime, &user.filetime);
|
||||
return user.u64time + kernel.u64time;
|
||||
#endif
|
||||
#elif defined(__APPLE__)
|
||||
return getthreadtime(pthread_mach_thread_np(pthread_self()));
|
||||
#else
|
||||
@ -477,17 +476,33 @@ u64 Threading::GetThreadCpuTime()
|
||||
|
||||
u64 Threading::GetThreadTicksPerSecond()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
#if 0
|
||||
#if defined(_WIN32) && !defined(_UWP) && !defined(_M_ARM64)
|
||||
// On x86, despite what the MS documentation says, this basically appears to be rdtsc.
|
||||
// So, the frequency is our base clock speed (and stable regardless of power management).
|
||||
static u64 frequency = 0;
|
||||
if (unlikely(frequency == 0))
|
||||
frequency = x86caps.CachedMHz() * u64(1000000);
|
||||
if (UNLIKELY(frequency == 0))
|
||||
{
|
||||
frequency = 1000000;
|
||||
|
||||
HKEY hKey;
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &hKey) ==
|
||||
ERROR_SUCCESS)
|
||||
{
|
||||
DWORD value;
|
||||
DWORD value_size = sizeof(value);
|
||||
if (RegQueryValueExW(hKey, L"~MHz", 0, nullptr, reinterpret_cast<LPBYTE>(&value), &value_size) == ERROR_SUCCESS)
|
||||
{
|
||||
// value is in mhz, convert to hz
|
||||
frequency *= value;
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
|
||||
return frequency;
|
||||
#else
|
||||
#elif defined(_WIN32)
|
||||
return 10000000;
|
||||
#endif
|
||||
#elif defined(__APPLE__)
|
||||
return 1000000;
|
||||
|
||||
@ -539,3 +554,60 @@ void Threading::SetNameOfCurrentThread(const char* name)
|
||||
pthread_set_name_np(pthread_self(), name);
|
||||
#endif
|
||||
}
|
||||
|
||||
Threading::KernelSemaphore::KernelSemaphore()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
m_sema = CreateSemaphore(nullptr, 0, LONG_MAX, nullptr);
|
||||
#elif defined(__APPLE__)
|
||||
semaphore_create(mach_task_self(), &m_sema, SYNC_POLICY_FIFO, 0);
|
||||
#else
|
||||
sem_init(&m_sema, false, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
Threading::KernelSemaphore::~KernelSemaphore()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
CloseHandle(m_sema);
|
||||
#elif defined(__APPLE__)
|
||||
semaphore_destroy(mach_task_self(), m_sema);
|
||||
#else
|
||||
sem_destroy(&m_sema);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Threading::KernelSemaphore::Post()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
ReleaseSemaphore(m_sema, 1, nullptr);
|
||||
#elif defined(__APPLE__)
|
||||
semaphore_signal(m_sema);
|
||||
#else
|
||||
sem_post(&m_sema);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Threading::KernelSemaphore::Wait()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
WaitForSingleObject(m_sema, INFINITE);
|
||||
#elif defined(__APPLE__)
|
||||
semaphore_wait(m_sema);
|
||||
#else
|
||||
sem_wait(&m_sema);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Threading::KernelSemaphore::TryWait()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return WaitForSingleObject(m_sema, 0) == WAIT_OBJECT_0;
|
||||
#elif defined(__APPLE__)
|
||||
mach_timespec_t time = {};
|
||||
kern_return_t res = semaphore_timedwait(m_sema, time);
|
||||
return (res != KERN_OPERATION_TIMED_OUT);
|
||||
#else
|
||||
return sem_trywait(&m_sema) == 0;
|
||||
#endif
|
||||
}
|
||||
|
@ -55,6 +55,16 @@ char (&__countof_ArraySizeHelper(T (&array)[N]))[N];
|
||||
#define printflike(n,m)
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// TODO: Use C++20 [[likely]] when available.
|
||||
#define LIKELY(x) (!!(x))
|
||||
#define UNLIKELY(x) (!!(x))
|
||||
#else
|
||||
#define LIKELY(x) __builtin_expect(!!(x), 1)
|
||||
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
#endif
|
||||
|
||||
|
||||
// disable warnings that show up at warning level 4
|
||||
// TODO: Move to build system instead
|
||||
#ifdef _MSC_VER
|
||||
|
@ -386,7 +386,7 @@ void ShaderCache::ClosePipelineCache()
|
||||
std::string ShaderCache::GetShaderCacheBaseFileName(const std::string_view& base_path, bool debug)
|
||||
{
|
||||
std::string base_filename(base_path);
|
||||
base_filename += "vulkan_shaders";
|
||||
base_filename += FS_OSPATH_SEPARATOR_STR "vulkan_shaders";
|
||||
|
||||
if (debug)
|
||||
base_filename += "_debug";
|
||||
@ -397,7 +397,7 @@ std::string ShaderCache::GetShaderCacheBaseFileName(const std::string_view& base
|
||||
std::string ShaderCache::GetPipelineCacheBaseFileName(const std::string_view& base_path, bool debug)
|
||||
{
|
||||
std::string base_filename(base_path);
|
||||
base_filename += "vulkan_pipelines";
|
||||
base_filename += FS_OSPATH_SEPARATOR_STR "vulkan_pipelines";
|
||||
|
||||
if (debug)
|
||||
base_filename += "_debug";
|
||||
|
Reference in New Issue
Block a user