Switch from Nz prefix to namespace Nz for linux

Former-commit-id: 64eeaf3c633254b04910ebd4576fd9e910002be0
This commit is contained in:
Youri Hubaut 2015-09-27 15:58:49 +02:00
parent 752518ef14
commit 37586e7283
49 changed files with 3918 additions and 3732 deletions

View File

@ -116,6 +116,7 @@
#endif #endif
#elif defined(__linux__) || defined(__unix__) #elif defined(__linux__) || defined(__unix__)
#define NAZARA_PLATFORM_LINUX #define NAZARA_PLATFORM_LINUX
#define NAZARA_PLATFORM_GLX
#define NAZARA_PLATFORM_POSIX #define NAZARA_PLATFORM_POSIX
#define NAZARA_PLATFORM_X11 #define NAZARA_PLATFORM_X11

View File

@ -21,10 +21,10 @@
#include <GL3/glext.h> #include <GL3/glext.h>
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_WINDOWS)
#include <GL3/wglext.h> #include <GL3/wglext.h>
#elif defined(NAZARA_PLATFORM_LINUX) #elif defined(NAZARA_PLATFORM_GLX)
namespace GLX namespace GLX
{ {
#include <GL3/glx.h> #include <GL/glx.h> // Defined in a namespace to avoid conflict
} }
#include <GL3/glxext.h> #include <GL3/glxext.h>
#endif #endif
@ -329,7 +329,7 @@ NAZARA_RENDERER_API extern PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAtt
NAZARA_RENDERER_API extern PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB; NAZARA_RENDERER_API extern PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB;
NAZARA_RENDERER_API extern PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT; NAZARA_RENDERER_API extern PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT;
NAZARA_RENDERER_API extern PFNWGLSWAPINTERVALEXTPROC wglSwapInterval; NAZARA_RENDERER_API extern PFNWGLSWAPINTERVALEXTPROC wglSwapInterval;
#elif defined(NAZARA_PLATFORM_LINUX) #elif defined(NAZARA_PLATFORM_GLX)
NAZARA_RENDERER_API extern GLX::PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs; NAZARA_RENDERER_API extern GLX::PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs;
NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT; NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALMESAPROC NzglXSwapIntervalMESA; NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALMESAPROC NzglXSwapIntervalMESA;

View File

@ -8,14 +8,16 @@
#define NAZARA_WINDOWHANDLE_HPP #define NAZARA_WINDOWHANDLE_HPP
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#if defined(NAZARA_PLATFORM_X11)
#include <xcb/xcb.h>
#endif
namespace Nz namespace Nz
{ {
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_WINDOWS)
// http://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx // http://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx
typedef void* WindowHandle; typedef void* WindowHandle;
#elif defined(NAZARA_PLATFORM_LINUX) #elif defined(NAZARA_PLATFORM_X11)
#include <xcb/xcb.h>
// http://en.wikipedia.org/wiki/Xlib#Data_types // http://en.wikipedia.org/wiki/Xlib#Data_types
using WindowHandle = xcb_window_t; using WindowHandle = xcb_window_t;
#else #else

View File

@ -10,22 +10,22 @@
void* operator new(std::size_t size) void* operator new(std::size_t size)
{ {
return NzMemoryManager::Allocate(size, false); return Nz::MemoryManager::Allocate(size, false);
} }
void* operator new[](std::size_t size) void* operator new[](std::size_t size)
{ {
return NzMemoryManager::Allocate(size, true); return Nz::MemoryManager::Allocate(size, true);
} }
void operator delete(void* pointer) noexcept void operator delete(void* pointer) noexcept
{ {
NzMemoryManager::Free(pointer, false); Nz::MemoryManager::Free(pointer, false);
} }
void operator delete[](void* pointer) noexcept void operator delete[](void* pointer) noexcept
{ {
NzMemoryManager::Free(pointer, true); Nz::MemoryManager::Free(pointer, true);
} }
#endif // NAZARA_AUDIO_MANAGE_MEMORY #endif // NAZARA_AUDIO_MANAGE_MEMORY

View File

@ -8,21 +8,24 @@
#include <sys/time.h> #include <sys/time.h>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
bool NzClockImplInitializeHighPrecision() namespace Nz
{
bool ClockImplInitializeHighPrecision()
{ {
return true; // No initialization needed return true; // No initialization needed
} }
nzUInt64 NzClockImplGetMicroseconds() UInt64 ClockImplGetElapsedMicroseconds()
{ {
timeval clock; timeval clock;
gettimeofday(&clock, nullptr); gettimeofday(&clock, nullptr);
return static_cast<nzUInt64>(clock.tv_sec*1000000 + clock.tv_usec); return static_cast<UInt64>(clock.tv_sec*1000000 + clock.tv_usec);
} }
nzUInt64 NzClockImplGetMilliseconds() UInt64 ClockImplGetElapsedMilliseconds()
{ {
timeval clock; timeval clock;
gettimeofday(&clock, nullptr); gettimeofday(&clock, nullptr);
return static_cast<nzUInt64>(clock.tv_sec*1000 + (clock.tv_usec/1000)); return static_cast<UInt64>(clock.tv_sec*1000 + (clock.tv_usec/1000));
}
} }

View File

@ -9,8 +9,11 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
bool NzClockImplInitializeHighPrecision(); namespace Nz
nzUInt64 NzClockImplGetMicroseconds(); {
nzUInt64 NzClockImplGetMilliseconds(); bool ClockImplInitializeHighPrecision();
UInt64 ClockImplGetElapsedMicroseconds();
UInt64 ClockImplGetElapsedMilliseconds();
}
#endif // NAZARA_CLOCKIMPL_POSIX_HPP #endif // NAZARA_CLOCKIMPL_POSIX_HPP

View File

@ -6,32 +6,34 @@
#include <Nazara/Core/Posix/MutexImpl.hpp> #include <Nazara/Core/Posix/MutexImpl.hpp>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
NzConditionVariableImpl::NzConditionVariableImpl() namespace Nz
{
ConditionVariableImpl::ConditionVariableImpl()
{ {
pthread_cond_init(&m_cv, nullptr); pthread_cond_init(&m_cv, nullptr);
} }
NzConditionVariableImpl::~NzConditionVariableImpl() ConditionVariableImpl::~ConditionVariableImpl()
{ {
pthread_cond_destroy(&m_cv); pthread_cond_destroy(&m_cv);
} }
void NzConditionVariableImpl::Signal() void ConditionVariableImpl::Signal()
{ {
pthread_cond_signal(&m_cv); pthread_cond_signal(&m_cv);
} }
void NzConditionVariableImpl::SignalAll() void ConditionVariableImpl::SignalAll()
{ {
pthread_cond_broadcast(&m_cv); pthread_cond_broadcast(&m_cv);
} }
void NzConditionVariableImpl::Wait(NzMutexImpl* mutex) void ConditionVariableImpl::Wait(MutexImpl* mutex)
{ {
pthread_cond_wait(&m_cv, &mutex->m_handle); pthread_cond_wait(&m_cv, &mutex->m_handle);
} }
bool NzConditionVariableImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout) bool ConditionVariableImpl::Wait(MutexImpl* mutex, UInt32 timeout)
{ {
// get the current time // get the current time
timeval tv; timeval tv;
@ -45,3 +47,4 @@ bool NzConditionVariableImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout)
return pthread_cond_timedwait(&m_cv,&mutex->m_handle, &ti) != 0; return pthread_cond_timedwait(&m_cv,&mutex->m_handle, &ti) != 0;
} }
}

View File

@ -14,22 +14,25 @@
#include <unistd.h> #include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
class NzMutexImpl; namespace Nz
{
class MutexImpl;
class NzConditionVariableImpl class ConditionVariableImpl
{ {
public: public:
NzConditionVariableImpl(); ConditionVariableImpl();
~NzConditionVariableImpl(); ~ConditionVariableImpl();
void Signal(); void Signal();
void SignalAll(); void SignalAll();
void Wait(NzMutexImpl* mutex); void Wait(MutexImpl* mutex);
bool Wait(NzMutexImpl* mutex, nzUInt32 timeout); bool Wait(MutexImpl* mutex, UInt32 timeout);
private: private:
pthread_cond_t m_cv; pthread_cond_t m_cv;
}; };
}
#endif // NAZARA_CONDITIONVARIABLEIMPL_HPP #endif // NAZARA_CONDITIONVARIABLEIMPL_HPP

View File

@ -9,30 +9,32 @@
#include <errno.h> #include <errno.h>
#include <sys/param.h> #include <sys/param.h>
NzDirectoryImpl::NzDirectoryImpl(const NzDirectory* parent) namespace Nz
{
DirectoryImpl::DirectoryImpl(const Directory* parent)
{ {
NazaraUnused(parent); NazaraUnused(parent);
} }
void NzDirectoryImpl::Close() void DirectoryImpl::Close()
{ {
closedir(m_handle); closedir(m_handle);
} }
NzString NzDirectoryImpl::GetResultName() const String DirectoryImpl::GetResultName() const
{ {
return m_result->d_name; return m_result->d_name;
} }
nzUInt64 NzDirectoryImpl::GetResultSize() const UInt64 DirectoryImpl::GetResultSize() const
{ {
struct stat64 resulststat; struct stat64 resulststat;
stat64(m_result->d_name, &resulststat); stat64(m_result->d_name, &resulststat);
return static_cast<nzUInt64>(resulststat.st_size); return static_cast<UInt64>(resulststat.st_size);
} }
bool NzDirectoryImpl::IsResultDirectory() const bool DirectoryImpl::IsResultDirectory() const
{ {
struct stat64 filestats; struct stat64 filestats;
if (stat64(m_result->d_name, &filestats) == -1) // error if (stat64(m_result->d_name, &filestats) == -1) // error
@ -41,39 +43,39 @@ bool NzDirectoryImpl::IsResultDirectory() const
return S_ISDIR(filestats.st_mode); return S_ISDIR(filestats.st_mode);
} }
bool NzDirectoryImpl::NextResult() bool DirectoryImpl::NextResult()
{ {
if ((m_result = readdir64(m_handle))) if ((m_result = readdir64(m_handle)))
return true; return true;
else else
{ {
if (errno != ENOENT) if (errno != ENOENT)
NazaraError("Unable to get next result: " + NzError::GetLastSystemError()); NazaraError("Unable to get next result: " + Error::GetLastSystemError());
return false; return false;
} }
} }
bool NzDirectoryImpl::Open(const NzString& dirPath) bool DirectoryImpl::Open(const String& dirPath)
{ {
m_handle = opendir(dirPath.GetConstBuffer()); m_handle = opendir(dirPath.GetConstBuffer());
if (!m_handle) if (!m_handle)
{ {
NazaraError("Unable to open directory: " + NzError::GetLastSystemError()); NazaraError("Unable to open directory: " + Error::GetLastSystemError());
return false; return false;
} }
return true; return true;
} }
bool NzDirectoryImpl::Create(const NzString& dirPath) bool DirectoryImpl::Create(const String& dirPath)
{ {
mode_t permissions; // TODO: check permissions mode_t permissions; // TODO: check permissions
return mkdir(dirPath.GetConstBuffer(), permissions) != -1;; return mkdir(dirPath.GetConstBuffer(), permissions) != -1;;
} }
bool NzDirectoryImpl::Exists(const NzString& dirPath) bool DirectoryImpl::Exists(const String& dirPath)
{ {
struct stat64 filestats; struct stat64 filestats;
if (stat64(dirPath.GetConstBuffer(), &filestats) == -1) // error if (stat64(dirPath.GetConstBuffer(), &filestats) == -1) // error
@ -82,22 +84,23 @@ bool NzDirectoryImpl::Exists(const NzString& dirPath)
return S_ISDIR(filestats.st_mode) || S_ISREG(filestats.st_mode); return S_ISDIR(filestats.st_mode) || S_ISREG(filestats.st_mode);
} }
NzString NzDirectoryImpl::GetCurrent() String DirectoryImpl::GetCurrent()
{ {
NzString currentPath; String currentPath;
char path[MAXPATHLEN]; char path[MAXPATHLEN];
if (getcwd(path, MAXPATHLEN)) if (getcwd(path, MAXPATHLEN))
currentPath = path; currentPath = path;
else else
NazaraError("Unable to get current directory: " + NzError::GetLastSystemError()); // Bug: initialisation -> if no path for log ! NazaraError("Unable to get current directory: " + Error::GetLastSystemError()); // Bug: initialisation -> if no path for log !
return currentPath; return currentPath;
} }
bool NzDirectoryImpl::Remove(const NzString& dirPath) bool DirectoryImpl::Remove(const String& dirPath)
{ {
bool success = rmdir(dirPath.GetConstBuffer()) != -1; bool success = rmdir(dirPath.GetConstBuffer()) != -1;
return success; return success;
} }
}

View File

@ -8,40 +8,47 @@
#define NAZARA_DIRECTORYIMPL_HPP #define NAZARA_DIRECTORYIMPL_HPP
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <dirent.h> #include <dirent.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
class NzDirectory; namespace Nz
class NzString; {
class Directory;
class String;
class NzDirectoryImpl : NzNonCopyable class DirectoryImpl
{ {
public: public:
NzDirectoryImpl(const NzDirectory* parent); DirectoryImpl(const Directory* parent);
~NzDirectoryImpl() = default; DirectoryImpl(const DirectoryImpl&) = delete;
DirectoryImpl(DirectoryImpl&&) = delete; ///TODO
~DirectoryImpl() = default;
void Close(); void Close();
NzString GetResultName() const; String GetResultName() const;
nzUInt64 GetResultSize() const; UInt64 GetResultSize() const;
bool IsResultDirectory() const; bool IsResultDirectory() const;
bool NextResult(); bool NextResult();
bool Open(const NzString& dirPath); bool Open(const String& dirPath);
static bool Create(const NzString& dirPath); DirectoryImpl& operator=(const DirectoryImpl&) = delete;
static bool Exists(const NzString& dirPath); DirectoryImpl& operator=(DirectoryImpl&&) = delete; ///TODO
static NzString GetCurrent();
static bool Remove(const NzString& dirPath); static bool Create(const String& dirPath);
static bool Exists(const String& dirPath);
static String GetCurrent();
static bool Remove(const String& dirPath);
private: private:
DIR* m_handle; DIR* m_handle;
dirent64* m_result; dirent64* m_result;
}; };
}
#endif // NAZARA_DIRECTORYIMPL_HPP #endif // NAZARA_DIRECTORYIMPL_HPP

View File

@ -8,12 +8,14 @@
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
NzDynLibImpl::NzDynLibImpl(NzDynLib* parent) namespace Nz
{
DynLibImpl::DynLibImpl(DynLib* parent)
{ {
NazaraUnused(parent); NazaraUnused(parent);
} }
NzDynLibFunc NzDynLibImpl::GetSymbol(const NzString& symbol, NzString* errorMessage) const DynLibFunc DynLibImpl::GetSymbol(const String& symbol, String* errorMessage) const
{ {
/* /*
Il n'est pas standard de cast un pointeur d'objet vers un pointeur de fonction. Il n'est pas standard de cast un pointeur d'objet vers un pointeur de fonction.
@ -23,7 +25,7 @@ NzDynLibFunc NzDynLibImpl::GetSymbol(const NzString& symbol, NzString* errorMess
*/ */
union union
{ {
NzDynLibFunc func; DynLibFunc func;
void* pointer; void* pointer;
} converter; } converter;
@ -36,12 +38,12 @@ NzDynLibFunc NzDynLibImpl::GetSymbol(const NzString& symbol, NzString* errorMess
return converter.func; return converter.func;
} }
bool NzDynLibImpl::Load(const NzString& libraryPath, NzString* errorMessage) bool DynLibImpl::Load(const String& libraryPath, String* errorMessage)
{ {
NzString path = libraryPath; String path = libraryPath;
unsigned int pos = path.FindLast(".so"); unsigned int pos = path.FindLast(".so");
if (pos == NzString::npos || (path.GetLength() > pos+3 && path[pos+3] != '.')) if (pos == String::npos || (path.GetLength() > pos+3 && path[pos+3] != '.'))
path += ".so"; path += ".so";
dlerror(); // Clear error flag dlerror(); // Clear error flag
@ -56,7 +58,8 @@ bool NzDynLibImpl::Load(const NzString& libraryPath, NzString* errorMessage)
} }
} }
void NzDynLibImpl::Unload() void DynLibImpl::Unload()
{ {
dlclose(m_handle); dlclose(m_handle);
} }
}

View File

@ -8,23 +8,25 @@
#define NAZARA_DYNLIBIMPL_HPP #define NAZARA_DYNLIBIMPL_HPP
#include <Nazara/Core/DynLib.hpp> #include <Nazara/Core/DynLib.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <dlfcn.h> #include <dlfcn.h>
class NzString; namespace Nz
{
class String;
class NzDynLibImpl : NzNonCopyable class DynLibImpl
{ {
public: public:
NzDynLibImpl(NzDynLib* m_parent); DynLibImpl(DynLib* m_parent);
~NzDynLibImpl() = default; ~DynLibImpl() = default;
NzDynLibFunc GetSymbol(const NzString& symbol, NzString* errorMessage) const; DynLibFunc GetSymbol(const String& symbol, String* errorMessage) const;
bool Load(const NzString& libraryPath, NzString* errorMessage); bool Load(const String& libraryPath, String* errorMessage);
void Unload(); void Unload();
private: private:
void* m_handle; void* m_handle;
}; };
}
#endif // NAZARA_DYNLIBIMPL_HPP #endif // NAZARA_DYNLIBIMPL_HPP

View File

@ -7,19 +7,21 @@
#include <cstdio> #include <cstdio>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
NzFileImpl::NzFileImpl(const NzFile* parent) : namespace Nz
{
FileImpl::FileImpl(const File* parent) :
m_endOfFile(false), m_endOfFile(false),
m_endOfFileUpdated(true) m_endOfFileUpdated(true)
{ {
NazaraUnused(parent); NazaraUnused(parent);
} }
void NzFileImpl::Close() void FileImpl::Close()
{ {
close(m_fileDescriptor); close(m_fileDescriptor);
} }
bool NzFileImpl::EndOfFile() const bool FileImpl::EndOfFile() const
{ {
if (!m_endOfFileUpdated) if (!m_endOfFileUpdated)
{ {
@ -27,64 +29,64 @@ bool NzFileImpl::EndOfFile() const
if (fstat64(m_fileDescriptor, &fileSize) == -1) if (fstat64(m_fileDescriptor, &fileSize) == -1)
fileSize.st_size = 0; fileSize.st_size = 0;
m_endOfFile = (GetCursorPos() >= static_cast<nzUInt64>(fileSize.st_size)); m_endOfFile = (GetCursorPos() >= static_cast<UInt64>(fileSize.st_size));
m_endOfFileUpdated = true; m_endOfFileUpdated = true;
} }
return m_endOfFile; return m_endOfFile;
} }
void NzFileImpl::Flush() void FileImpl::Flush()
{ {
if (fsync(m_fileDescriptor) == -1) if (fsync(m_fileDescriptor) == -1)
NazaraError("Unable to flush file: " + NzError::GetLastSystemError()); NazaraError("Unable to flush file: " + Error::GetLastSystemError());
} }
nzUInt64 NzFileImpl::GetCursorPos() const UInt64 FileImpl::GetCursorPos() const
{ {
off64_t position = lseek64(m_fileDescriptor, 0, SEEK_CUR); off64_t position = lseek64(m_fileDescriptor, 0, SEEK_CUR);
return static_cast<nzUInt64>(position); return static_cast<UInt64>(position);
} }
bool NzFileImpl::Open(const NzString& filePath, unsigned int mode) bool FileImpl::Open(const String& filePath, unsigned int mode)
{ {
int flags; int flags;
mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
if (mode & nzOpenMode_ReadOnly) if (mode & OpenMode_ReadOnly)
flags = O_RDONLY; flags = O_RDONLY;
else if (mode & nzOpenMode_ReadWrite) else if (mode & OpenMode_ReadWrite)
{ {
flags = O_CREAT | O_RDWR; flags = O_CREAT | O_RDWR;
if (mode & nzOpenMode_Append) if (mode & OpenMode_Append)
flags |= O_APPEND; flags |= O_APPEND;
if (mode & nzOpenMode_Truncate) if (mode & OpenMode_Truncate)
flags |= O_TRUNC; flags |= O_TRUNC;
} }
else if (mode & nzOpenMode_WriteOnly) else if (mode & OpenMode_WriteOnly)
{ {
flags = O_CREAT | O_WRONLY; flags = O_CREAT | O_WRONLY;
if (mode & nzOpenMode_Append) if (mode & OpenMode_Append)
flags |= O_APPEND; flags |= O_APPEND;
if (mode & nzOpenMode_Truncate) if (mode & OpenMode_Truncate)
flags |= O_TRUNC; flags |= O_TRUNC;
} }
else else
return false; return false;
///TODO: lock ///TODO: lock
// if ((mode & nzOpenMode_Lock) == 0) // if ((mode & OpenMode_Lock) == 0)
// shareMode |= FILE_SHARE_WRITE; // shareMode |= FILE_SHARE_WRITE;
m_fileDescriptor = open64(filePath.GetConstBuffer(), flags, permissions); m_fileDescriptor = open64(filePath.GetConstBuffer(), flags, permissions);
return m_fileDescriptor != -1; return m_fileDescriptor != -1;
} }
std::size_t NzFileImpl::Read(void* buffer, std::size_t size) std::size_t FileImpl::Read(void* buffer, std::size_t size)
{ {
ssize_t bytes; ssize_t bytes;
if ((bytes = read(m_fileDescriptor, buffer, size)) != -1) if ((bytes = read(m_fileDescriptor, buffer, size)) != -1)
@ -98,25 +100,25 @@ std::size_t NzFileImpl::Read(void* buffer, std::size_t size)
return 0; return 0;
} }
bool NzFileImpl::SetCursorPos(nzCursorPosition pos, nzInt64 offset) bool FileImpl::SetCursorPos(CursorPosition pos, Int64 offset)
{ {
int moveMethod; int moveMethod;
switch (pos) switch (pos)
{ {
case nzCursorPosition_AtBegin: case CursorPosition_AtBegin:
moveMethod = SEEK_SET; moveMethod = SEEK_SET;
break; break;
case nzCursorPosition_AtCurrent: case CursorPosition_AtCurrent:
moveMethod = SEEK_CUR; moveMethod = SEEK_CUR;
break; break;
case nzCursorPosition_AtEnd: case CursorPosition_AtEnd:
moveMethod = SEEK_END; moveMethod = SEEK_END;
break; break;
default: default:
NazaraInternalError("Cursor position not handled (0x" + NzString::Number(pos, 16) + ')'); NazaraInternalError("Cursor position not handled (0x" + String::Number(pos, 16) + ')');
return false; return false;
} }
@ -125,7 +127,7 @@ bool NzFileImpl::SetCursorPos(nzCursorPosition pos, nzInt64 offset)
return lseek64(m_fileDescriptor, offset, moveMethod) != -1; return lseek64(m_fileDescriptor, offset, moveMethod) != -1;
} }
std::size_t NzFileImpl::Write(const void* buffer, std::size_t size) std::size_t FileImpl::Write(const void* buffer, std::size_t size)
{ {
lockf64(m_fileDescriptor, F_LOCK, size); lockf64(m_fileDescriptor, F_LOCK, size);
ssize_t written = write(m_fileDescriptor, buffer, size); ssize_t written = write(m_fileDescriptor, buffer, size);
@ -136,12 +138,12 @@ std::size_t NzFileImpl::Write(const void* buffer, std::size_t size)
return written; return written;
} }
bool NzFileImpl::Copy(const NzString& sourcePath, const NzString& targetPath) bool FileImpl::Copy(const String& sourcePath, const String& targetPath)
{ {
int fd1 = open64(sourcePath.GetConstBuffer(), O_RDONLY); int fd1 = open64(sourcePath.GetConstBuffer(), O_RDONLY);
if (fd1 == -1) if (fd1 == -1)
{ {
NazaraError("Fail to open input file (" + sourcePath + "): " + NzError::GetLastSystemError()); NazaraError("Fail to open input file (" + sourcePath + "): " + Error::GetLastSystemError());
return false; return false;
} }
@ -149,7 +151,7 @@ bool NzFileImpl::Copy(const NzString& sourcePath, const NzString& targetPath)
int fd2 = open64(targetPath.GetConstBuffer(), O_WRONLY | O_TRUNC, permissions); int fd2 = open64(targetPath.GetConstBuffer(), O_WRONLY | O_TRUNC, permissions);
if (fd2 == -1) if (fd2 == -1)
{ {
NazaraError("Fail to open output file (" + targetPath + "): " + NzError::GetLastSystemError()); // TODO: more info ? NazaraError("Fail to open output file (" + targetPath + "): " + Error::GetLastSystemError()); // TODO: more info ?
close(fd1); close(fd1);
return false; return false;
} }
@ -163,7 +165,7 @@ bool NzFileImpl::Copy(const NzString& sourcePath, const NzString& targetPath)
{ {
close(fd1); close(fd1);
close(fd2); close(fd2);
NazaraError("An error occured from copy : " + NzError::GetLastSystemError()); NazaraError("An error occured from copy : " + Error::GetLastSystemError());
return false; return false;
} }
write(fd2,buffer,bytes); write(fd2,buffer,bytes);
@ -175,7 +177,7 @@ bool NzFileImpl::Copy(const NzString& sourcePath, const NzString& targetPath)
return true; return true;
} }
bool NzFileImpl::Delete(const NzString& filePath) bool FileImpl::Delete(const String& filePath)
{ {
bool success = unlink(filePath.GetConstBuffer()) != -1; bool success = unlink(filePath.GetConstBuffer()) != -1;
@ -183,12 +185,12 @@ bool NzFileImpl::Delete(const NzString& filePath)
return true; return true;
else else
{ {
NazaraError("Failed to delete file (" + filePath + "): " + NzError::GetLastSystemError()); NazaraError("Failed to delete file (" + filePath + "): " + Error::GetLastSystemError());
return false; return false;
} }
} }
bool NzFileImpl::Exists(const NzString& filePath) bool FileImpl::Exists(const String& filePath)
{ {
const char* path = filePath.GetConstBuffer(); const char* path = filePath.GetConstBuffer();
if (access(path, F_OK) != -1) if (access(path, F_OK) != -1)
@ -197,14 +199,14 @@ bool NzFileImpl::Exists(const NzString& filePath)
return false; return false;
} }
time_t NzFileImpl::GetCreationTime(const NzString& filePath) time_t FileImpl::GetCreationTime(const String& filePath)
{ {
NazaraWarning("Posix has no creation time information"); NazaraWarning("Posix has no creation time information");
return 0; return 0;
} }
time_t NzFileImpl::GetLastAccessTime(const NzString& filePath) time_t FileImpl::GetLastAccessTime(const String& filePath)
{ {
struct stat64 stats; struct stat64 stats;
stat64(filePath.GetConstBuffer(), &stats); stat64(filePath.GetConstBuffer(), &stats);
@ -212,7 +214,7 @@ time_t NzFileImpl::GetLastAccessTime(const NzString& filePath)
return stats.st_atime; return stats.st_atime;
} }
time_t NzFileImpl::GetLastWriteTime(const NzString& filePath) time_t FileImpl::GetLastWriteTime(const String& filePath)
{ {
struct stat64 stats; struct stat64 stats;
stat64(filePath.GetConstBuffer(), &stats); stat64(filePath.GetConstBuffer(), &stats);
@ -220,15 +222,15 @@ time_t NzFileImpl::GetLastWriteTime(const NzString& filePath)
return stats.st_mtime; return stats.st_mtime;
} }
nzUInt64 NzFileImpl::GetSize(const NzString& filePath) UInt64 FileImpl::GetSize(const String& filePath)
{ {
struct stat64 stats; struct stat64 stats;
stat64(filePath.GetConstBuffer(), &stats); stat64(filePath.GetConstBuffer(), &stats);
return static_cast<nzUInt64>(stats.st_size); return static_cast<UInt64>(stats.st_size);
} }
bool NzFileImpl::Rename(const NzString& sourcePath, const NzString& targetPath) bool FileImpl::Rename(const String& sourcePath, const String& targetPath)
{ {
bool success = std::rename(sourcePath.GetConstBuffer(), targetPath.GetConstBuffer()) != -1; bool success = std::rename(sourcePath.GetConstBuffer(), targetPath.GetConstBuffer()) != -1;
@ -236,7 +238,8 @@ bool NzFileImpl::Rename(const NzString& sourcePath, const NzString& targetPath)
return true; return true;
else else
{ {
NazaraError("Unable to rename file: " + NzError::GetLastSystemError()); NazaraError("Unable to rename file: " + Error::GetLastSystemError());
return false; return false;
} }
} }
}

View File

@ -13,44 +13,51 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/File.hpp> #include <Nazara/Core/File.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <ctime> #include <ctime>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
class NzFile; namespace Nz
class NzString; {
class File;
class String;
class NzFileImpl : NzNonCopyable class FileImpl
{ {
public: public:
NzFileImpl(const NzFile* parent); FileImpl(const File* parent);
~NzFileImpl() = default; FileImpl(const FileImpl&) = delete;
FileImpl(FileImpl&&) = delete; ///TODO
~FileImpl() = default;
void Close(); void Close();
bool EndOfFile() const; bool EndOfFile() const;
void Flush(); void Flush();
nzUInt64 GetCursorPos() const; UInt64 GetCursorPos() const;
bool Open(const NzString& filePath, unsigned int mode); bool Open(const String& filePath, unsigned int mode);
std::size_t Read(void* buffer, std::size_t size); std::size_t Read(void* buffer, std::size_t size);
bool SetCursorPos(nzCursorPosition pos, nzInt64 offset); bool SetCursorPos(CursorPosition pos, Int64 offset);
std::size_t Write(const void* buffer, std::size_t size); std::size_t Write(const void* buffer, std::size_t size);
static bool Copy(const NzString& sourcePath, const NzString& targetPath); FileImpl& operator=(const FileImpl&) = delete;
static bool Delete(const NzString& filePath); FileImpl& operator=(FileImpl&&) = delete; ///TODO
static bool Exists(const NzString& filePath);
static time_t GetCreationTime(const NzString& filePath); static bool Copy(const String& sourcePath, const String& targetPath);
static time_t GetLastAccessTime(const NzString& filePath); static bool Delete(const String& filePath);
static time_t GetLastWriteTime(const NzString& filePath); static bool Exists(const String& filePath);
static nzUInt64 GetSize(const NzString& filePath); static time_t GetCreationTime(const String& filePath);
static bool Rename(const NzString& sourcePath, const NzString& targetPath); static time_t GetLastAccessTime(const String& filePath);
static time_t GetLastWriteTime(const String& filePath);
static UInt64 GetSize(const String& filePath);
static bool Rename(const String& sourcePath, const String& targetPath);
private: private:
int m_fileDescriptor; int m_fileDescriptor;
mutable bool m_endOfFile; mutable bool m_endOfFile;
mutable bool m_endOfFileUpdated; mutable bool m_endOfFileUpdated;
}; };
}
#endif // NAZARA_FILEIMPL_HPP #endif // NAZARA_FILEIMPL_HPP

View File

@ -6,7 +6,9 @@
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
void NzHardwareInfoImpl::Cpuid(nzUInt32 functionId, nzUInt32 subFunctionId, nzUInt32 registers[4]) namespace Nz
{
void HardwareInfoImpl::Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 registers[4])
{ {
#if defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL) #if defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL)
// Source: http://stackoverflow.com/questions/1666093/cpuid-implementations-in-c // Source: http://stackoverflow.com/questions/1666093/cpuid-implementations-in-c
@ -18,21 +20,21 @@ void NzHardwareInfoImpl::Cpuid(nzUInt32 functionId, nzUInt32 subFunctionId, nzUI
#endif #endif
} }
unsigned int NzHardwareInfoImpl::GetProcessorCount() unsigned int HardwareInfoImpl::GetProcessorCount()
{ {
// Plus simple (et plus portable) que de passer par le CPUID // Plus simple (et plus portable) que de passer par le CPUID
return sysconf(_SC_NPROCESSORS_CONF); return sysconf(_SC_NPROCESSORS_CONF);
} }
nzUInt64 NzHardwareInfoImpl::GetTotalMemory() UInt64 HardwareInfoImpl::GetTotalMemory()
{ {
nzUInt64 pages = sysconf(_SC_PHYS_PAGES); UInt64 pages = sysconf(_SC_PHYS_PAGES);
nzUInt64 page_size = sysconf(_SC_PAGE_SIZE); UInt64 page_size = sysconf(_SC_PAGE_SIZE);
return pages * page_size; return pages * page_size;
} }
bool NzHardwareInfoImpl::IsCpuidSupported() bool HardwareInfoImpl::IsCpuidSupported()
{ {
#ifdef NAZARA_PLATFORM_x64 #ifdef NAZARA_PLATFORM_x64
return true; // Toujours supporté sur un processeur 64 bits return true; // Toujours supporté sur un processeur 64 bits
@ -61,3 +63,4 @@ bool NzHardwareInfoImpl::IsCpuidSupported()
#endif #endif
#endif #endif
} }
}

View File

@ -10,13 +10,16 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <unistd.h> #include <unistd.h>
class NzHardwareInfoImpl namespace Nz
{
class HardwareInfoImpl
{ {
public: public:
static void Cpuid(nzUInt32 functionId, nzUInt32 subFunctionId, nzUInt32 registers[4]); static void Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 registers[4]);
static unsigned int GetProcessorCount(); static unsigned int GetProcessorCount();
static nzUInt64 GetTotalMemory(); static UInt64 GetTotalMemory();
static bool IsCpuidSupported(); static bool IsCpuidSupported();
}; };
}
#endif // NAZARA_HARDWAREINFOIMPL_POSIX_HPP #endif // NAZARA_HARDWAREINFOIMPL_POSIX_HPP

View File

@ -5,7 +5,9 @@
#include <Nazara/Core/Posix/MutexImpl.hpp> #include <Nazara/Core/Posix/MutexImpl.hpp>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
NzMutexImpl::NzMutexImpl() namespace Nz
{
MutexImpl::MutexImpl()
{ {
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr); pthread_mutexattr_init(&attr);
@ -14,22 +16,23 @@ NzMutexImpl::NzMutexImpl()
pthread_mutex_init(&m_handle, &attr); pthread_mutex_init(&m_handle, &attr);
} }
NzMutexImpl::~NzMutexImpl() MutexImpl::~MutexImpl()
{ {
pthread_mutex_destroy(&m_handle); pthread_mutex_destroy(&m_handle);
} }
void NzMutexImpl::Lock() void MutexImpl::Lock()
{ {
pthread_mutex_lock(&m_handle); pthread_mutex_lock(&m_handle);
} }
bool NzMutexImpl::TryLock() bool MutexImpl::TryLock()
{ {
return pthread_mutex_trylock(&m_handle) == 0; return pthread_mutex_trylock(&m_handle) == 0;
} }
void NzMutexImpl::Unlock() void MutexImpl::Unlock()
{ {
pthread_mutex_unlock(&m_handle); pthread_mutex_unlock(&m_handle);
} }
}

View File

@ -9,13 +9,15 @@
#include <pthread.h> #include <pthread.h>
class NzMutexImpl namespace Nz
{ {
friend class NzConditionVariableImpl; class MutexImpl
{
friend class ConditionVariableImpl;
public: public:
NzMutexImpl(); MutexImpl();
~NzMutexImpl(); ~MutexImpl();
void Lock(); void Lock();
bool TryLock(); bool TryLock();
@ -24,5 +26,6 @@ class NzMutexImpl
private: private:
pthread_mutex_t m_handle; pthread_mutex_t m_handle;
}; };
}
#endif // NAZARA_MUTEXIMPL_HPP #endif // NAZARA_MUTEXIMPL_HPP

View File

@ -9,45 +9,47 @@
#include <sys/time.h> #include <sys/time.h>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
NzSemaphoreImpl::NzSemaphoreImpl(unsigned int count) namespace Nz
{
SemaphoreImpl::SemaphoreImpl(unsigned int count)
{ {
if(sem_init(&m_semaphore, 0, count) != 0) if(sem_init(&m_semaphore, 0, count) != 0)
NazaraError("Failed to create semaphore: " + NzError::GetLastSystemError()); NazaraError("Failed to create semaphore: " + Error::GetLastSystemError());
} }
NzSemaphoreImpl::~NzSemaphoreImpl() SemaphoreImpl::~SemaphoreImpl()
{ {
sem_destroy(&m_semaphore); sem_destroy(&m_semaphore);
} }
unsigned int NzSemaphoreImpl::GetCount() const unsigned int SemaphoreImpl::GetCount() const
{ {
int count=0; int count=0;
sem_getvalue(const_cast<sem_t*>(&m_semaphore), &count); sem_getvalue(const_cast<sem_t*>(&m_semaphore), &count);
return static_cast<unsigned int>(count); return static_cast<unsigned int>(count);
} }
void NzSemaphoreImpl::Post() void SemaphoreImpl::Post()
{ {
#if NAZARA_CORE_SAFE #if NAZARA_CORE_SAFE
if (sem_post(&m_semaphore)==-1) if (sem_post(&m_semaphore)==-1)
NazaraError("Failed to release semaphore: " + NzError::GetLastSystemError()); NazaraError("Failed to release semaphore: " + Error::GetLastSystemError());
#else #else
sem_post(&m_semaphore); sem_post(&m_semaphore);
#endif #endif
} }
void NzSemaphoreImpl::Wait() void SemaphoreImpl::Wait()
{ {
#if NAZARA_CORE_SAFE #if NAZARA_CORE_SAFE
if (sem_wait(&m_semaphore) == -1 ) if (sem_wait(&m_semaphore) == -1 )
NazaraError("Failed to wait for semaphore: " + NzError::GetLastSystemError()); NazaraError("Failed to wait for semaphore: " + Error::GetLastSystemError());
#else #else
sem_wait(&m_semaphore); sem_wait(&m_semaphore);
#endif #endif
} }
bool NzSemaphoreImpl::Wait(nzUInt32 timeout) bool SemaphoreImpl::Wait(UInt32 timeout)
{ {
timeval tv; timeval tv;
gettimeofday(&tv, nullptr); gettimeofday(&tv, nullptr);
@ -60,7 +62,7 @@ bool NzSemaphoreImpl::Wait(nzUInt32 timeout)
#if NAZARA_CORE_SAFE #if NAZARA_CORE_SAFE
if (sem_timedwait(&m_semaphore, &ti) != 0) if (sem_timedwait(&m_semaphore, &ti) != 0)
{ {
NazaraError("Failed to wait for semaphore: " + NzError::GetLastSystemError()); NazaraError("Failed to wait for semaphore: " + Error::GetLastSystemError());
return false; return false;
} }
@ -69,3 +71,4 @@ bool NzSemaphoreImpl::Wait(nzUInt32 timeout)
return sem_timedwait(&m_semaphore, &ti) != 0; return sem_timedwait(&m_semaphore, &ti) != 0;
#endif #endif
} }
}

View File

@ -10,19 +10,22 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <semaphore.h> #include <semaphore.h>
class NzSemaphoreImpl namespace Nz
{
class SemaphoreImpl
{ {
public: public:
NzSemaphoreImpl(unsigned int count); SemaphoreImpl(unsigned int count);
~NzSemaphoreImpl(); ~SemaphoreImpl();
unsigned int GetCount() const; unsigned int GetCount() const;
void Post(); void Post();
void Wait(); void Wait();
bool Wait(nzUInt32 timeout); bool Wait(UInt32 timeout);
private: private:
sem_t m_semaphore; sem_t m_semaphore;
}; };
}
#endif // NAZARA_SEMAPHOREIMPL_HPP #endif // NAZARA_SEMAPHOREIMPL_HPP

View File

@ -7,7 +7,9 @@
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
bool NzTaskSchedulerImpl::Initialize(unsigned int workerCount) namespace Nz
{
bool TaskSchedulerImpl::Initialize(unsigned int workerCount)
{ {
if (IsInitialized()) if (IsInitialized())
return true; // Déjà initialisé return true; // Déjà initialisé
@ -44,12 +46,12 @@ bool NzTaskSchedulerImpl::Initialize(unsigned int workerCount)
return true; return true;
} }
bool NzTaskSchedulerImpl::IsInitialized() bool TaskSchedulerImpl::IsInitialized()
{ {
return s_workerCount > 0; return s_workerCount > 0;
} }
void NzTaskSchedulerImpl::Run(NzFunctor** tasks, unsigned int count) void TaskSchedulerImpl::Run(Functor** tasks, unsigned int count)
{ {
// On s'assure que des tâches ne sont pas déjà en cours // On s'assure que des tâches ne sont pas déjà en cours
Wait(); Wait();
@ -64,7 +66,7 @@ void NzTaskSchedulerImpl::Run(NzFunctor** tasks, unsigned int count)
pthread_mutex_unlock(&s_mutexQueue); pthread_mutex_unlock(&s_mutexQueue);
} }
void NzTaskSchedulerImpl::Uninitialize() void TaskSchedulerImpl::Uninitialize()
{ {
#ifdef NAZARA_CORE_SAFE #ifdef NAZARA_CORE_SAFE
if (s_workerCount == 0) if (s_workerCount == 0)
@ -77,7 +79,7 @@ void NzTaskSchedulerImpl::Uninitialize()
// On réveille les threads pour qu'ils sortent de la boucle et terminent. // On réveille les threads pour qu'ils sortent de la boucle et terminent.
pthread_mutex_lock(&s_mutexQueue); pthread_mutex_lock(&s_mutexQueue);
// On commence par vider la queue et demander qu'ils s'arrêtent. // On commence par vider la queue et demander qu'ils s'arrêtent.
std::queue<NzFunctor*> emptyQueue; std::queue<Functor*> emptyQueue;
std::swap(s_tasks, emptyQueue); std::swap(s_tasks, emptyQueue);
s_shouldFinish = true; s_shouldFinish = true;
pthread_cond_broadcast(&s_cvNotEmpty); pthread_cond_broadcast(&s_cvNotEmpty);
@ -96,7 +98,7 @@ void NzTaskSchedulerImpl::Uninitialize()
s_workerCount = 0; s_workerCount = 0;
} }
void NzTaskSchedulerImpl::WaitForTasks() void TaskSchedulerImpl::WaitForTasks()
{ {
#ifdef NAZARA_CORE_SAFE #ifdef NAZARA_CORE_SAFE
if (s_workerCount == 0) if (s_workerCount == 0)
@ -109,9 +111,9 @@ void NzTaskSchedulerImpl::WaitForTasks()
Wait(); Wait();
} }
NzFunctor* NzTaskSchedulerImpl::PopQueue() Functor* TaskSchedulerImpl::PopQueue()
{ {
NzFunctor* task = nullptr; Functor* task = nullptr;
pthread_mutex_lock(&s_mutexQueue); pthread_mutex_lock(&s_mutexQueue);
@ -126,7 +128,7 @@ NzFunctor* NzTaskSchedulerImpl::PopQueue()
return task; return task;
} }
void NzTaskSchedulerImpl::Wait() void TaskSchedulerImpl::Wait()
{ {
if (s_isDone) if (s_isDone)
return; return;
@ -140,7 +142,7 @@ void NzTaskSchedulerImpl::Wait()
s_isDone = true; s_isDone = true;
} }
void* NzTaskSchedulerImpl::WorkerProc(void* /*userdata*/) void* TaskSchedulerImpl::WorkerProc(void* /*userdata*/)
{ {
// On s'assure que tous les threads soient correctement lancés. // On s'assure que tous les threads soient correctement lancés.
pthread_barrier_wait(&s_barrier); pthread_barrier_wait(&s_barrier);
@ -148,7 +150,7 @@ void* NzTaskSchedulerImpl::WorkerProc(void* /*userdata*/)
// On quitte s'il doit terminer. // On quitte s'il doit terminer.
while (!s_shouldFinish) while (!s_shouldFinish)
{ {
NzFunctor* task = PopQueue(); Functor* task = PopQueue();
if (task) if (task)
{ {
@ -179,14 +181,15 @@ void* NzTaskSchedulerImpl::WorkerProc(void* /*userdata*/)
return nullptr; return nullptr;
} }
std::queue<NzFunctor*> NzTaskSchedulerImpl::s_tasks; std::queue<Functor*> TaskSchedulerImpl::s_tasks;
std::unique_ptr<pthread_t[]> NzTaskSchedulerImpl::s_threads; std::unique_ptr<pthread_t[]> TaskSchedulerImpl::s_threads;
std::atomic<bool> NzTaskSchedulerImpl::s_isDone; std::atomic<bool> TaskSchedulerImpl::s_isDone;
std::atomic<bool> NzTaskSchedulerImpl::s_isWaiting; std::atomic<bool> TaskSchedulerImpl::s_isWaiting;
std::atomic<bool> NzTaskSchedulerImpl::s_shouldFinish; std::atomic<bool> TaskSchedulerImpl::s_shouldFinish;
unsigned int NzTaskSchedulerImpl::s_workerCount; unsigned int TaskSchedulerImpl::s_workerCount;
pthread_mutex_t NzTaskSchedulerImpl::s_mutexQueue; pthread_mutex_t TaskSchedulerImpl::s_mutexQueue;
pthread_cond_t NzTaskSchedulerImpl::s_cvEmpty; pthread_cond_t TaskSchedulerImpl::s_cvEmpty;
pthread_cond_t NzTaskSchedulerImpl::s_cvNotEmpty; pthread_cond_t TaskSchedulerImpl::s_cvNotEmpty;
pthread_barrier_t NzTaskSchedulerImpl::s_barrier; pthread_barrier_t TaskSchedulerImpl::s_barrier;
}

View File

@ -14,24 +14,26 @@
#include <pthread.h> #include <pthread.h>
#include <queue> #include <queue>
class NzTaskSchedulerImpl namespace Nz
{
class TaskSchedulerImpl
{ {
public: public:
NzTaskSchedulerImpl() = delete; TaskSchedulerImpl() = delete;
~NzTaskSchedulerImpl() = delete; ~TaskSchedulerImpl() = delete;
static bool Initialize(unsigned int workerCount); static bool Initialize(unsigned int workerCount);
static bool IsInitialized(); static bool IsInitialized();
static void Run(NzFunctor** tasks, unsigned int count); static void Run(Functor** tasks, unsigned int count);
static void Uninitialize(); static void Uninitialize();
static void WaitForTasks(); static void WaitForTasks();
private: private:
static NzFunctor* PopQueue(); static Functor* PopQueue();
static void Wait(); static void Wait();
static void* WorkerProc(void* userdata); static void* WorkerProc(void* userdata);
static std::queue<NzFunctor*> s_tasks; static std::queue<Functor*> s_tasks;
static std::unique_ptr<pthread_t[]> s_threads; static std::unique_ptr<pthread_t[]> s_threads;
static std::atomic<bool> s_isDone; static std::atomic<bool> s_isDone;
static std::atomic<bool> s_isWaiting; static std::atomic<bool> s_isWaiting;
@ -43,5 +45,6 @@ class NzTaskSchedulerImpl
static pthread_cond_t s_cvNotEmpty; static pthread_cond_t s_cvNotEmpty;
static pthread_barrier_t s_barrier; static pthread_barrier_t s_barrier;
}; };
}
#endif // NAZARA_TASKSCHEDULERIMPL_HPP #endif // NAZARA_TASKSCHEDULERIMPL_HPP

View File

@ -9,33 +9,35 @@
#include <sys/time.h> #include <sys/time.h>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
NzThreadImpl::NzThreadImpl(NzFunctor* functor) namespace Nz
{ {
int error = pthread_create(&m_handle, nullptr, &NzThreadImpl::ThreadProc, functor); ThreadImpl::ThreadImpl(Functor* functor)
{
int error = pthread_create(&m_handle, nullptr, &ThreadImpl::ThreadProc, functor);
if (error != 0) if (error != 0)
NazaraInternalError("Failed to create thread: " + NzError::GetLastSystemError()); NazaraInternalError("Failed to create thread: " + Error::GetLastSystemError());
} }
void NzThreadImpl::Detach() void ThreadImpl::Detach()
{ {
pthread_detach(m_handle); pthread_detach(m_handle);
} }
void NzThreadImpl::Join() void ThreadImpl::Join()
{ {
pthread_join(m_handle, nullptr); pthread_join(m_handle, nullptr);
} }
void* NzThreadImpl::ThreadProc(void* userdata) void* ThreadImpl::ThreadProc(void* userdata)
{ {
NzFunctor* func = static_cast<NzFunctor*>(userdata); Functor* func = static_cast<Functor*>(userdata);
func->Run(); func->Run();
delete func; delete func;
return nullptr; return nullptr;
} }
void NzThreadImpl::Sleep(nzUInt32 time) void ThreadImpl::Sleep(UInt32 time)
{ {
// code from SFML2 Unix SleepImpl.cpp source https://github.com/LaurentGomila/SFML/blob/master/src/SFML/System/Unix/SleepImpl.cpp // code from SFML2 Unix SleepImpl.cpp source https://github.com/LaurentGomila/SFML/blob/master/src/SFML/System/Unix/SleepImpl.cpp
@ -70,3 +72,4 @@ void NzThreadImpl::Sleep(nzUInt32 time)
pthread_cond_destroy(&condition); pthread_cond_destroy(&condition);
pthread_mutex_destroy(&mutex); pthread_mutex_destroy(&mutex);
} }
}

View File

@ -10,22 +10,25 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <pthread.h> #include <pthread.h>
struct NzFunctor; namespace Nz
{
struct Functor;
class NzThreadImpl class ThreadImpl
{ {
public: public:
NzThreadImpl(NzFunctor* threadFunc); ThreadImpl(Functor* threadFunc);
void Detach(); void Detach();
void Join(); void Join();
static void Sleep(nzUInt32 time); static void Sleep(UInt32 time);
private: private:
static void* ThreadProc(void* userdata); static void* ThreadProc(void* userdata);
pthread_t m_handle; pthread_t m_handle;
}; };
}
#endif // NAZARA_THREADIMPL_HPP #endif // NAZARA_THREADIMPL_HPP

View File

@ -10,22 +10,22 @@
void* operator new(std::size_t size) void* operator new(std::size_t size)
{ {
return NzMemoryManager::Allocate(size, false); return Nz::MemoryManager::Allocate(size, false);
} }
void* operator new[](std::size_t size) void* operator new[](std::size_t size)
{ {
return NzMemoryManager::Allocate(size, true); return Nz::MemoryManager::Allocate(size, true);
} }
void operator delete(void* pointer) noexcept void operator delete(void* pointer) noexcept
{ {
NzMemoryManager::Free(pointer, false); Nz::MemoryManager::Free(pointer, false);
} }
void operator delete[](void* pointer) noexcept void operator delete[](void* pointer) noexcept
{ {
NzMemoryManager::Free(pointer, true); Nz::MemoryManager::Free(pointer, true);
} }
#endif // NAZARA_GRAPHICS_MANAGE_MEMORY #endif // NAZARA_GRAPHICS_MANAGE_MEMORY

View File

@ -689,7 +689,7 @@ namespace Nz
// On envoie les lumières directionnelles s'il y a (Les mêmes pour tous) // On envoie les lumières directionnelles s'il y a (Les mêmes pour tous)
if (shaderUniforms->hasLightUniforms) if (shaderUniforms->hasLightUniforms)
{ {
lightCount = std::min(m_renderQueue.directionalLights.size(), NazaraSuffixMacro(NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS, U)); lightCount = std::min(m_renderQueue.directionalLights.size(), static_cast<decltype(m_renderQueue.directionalLights.size())>(NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS));
for (unsigned int i = 0; i < lightCount; ++i) for (unsigned int i = 0; i < lightCount; ++i)
SendLightUniforms(shader, shaderUniforms->lightUniforms, i, shaderUniforms->lightOffset * i); SendLightUniforms(shader, shaderUniforms->lightUniforms, i, shaderUniforms->lightOffset * i);

View File

@ -10,22 +10,22 @@
void* operator new(std::size_t size) void* operator new(std::size_t size)
{ {
return NzMemoryManager::Allocate(size, false); return Nz::MemoryManager::Allocate(size, false);
} }
void* operator new[](std::size_t size) void* operator new[](std::size_t size)
{ {
return NzMemoryManager::Allocate(size, true); return Nz::MemoryManager::Allocate(size, true);
} }
void operator delete(void* pointer) noexcept void operator delete(void* pointer) noexcept
{ {
NzMemoryManager::Free(pointer, false); Nz::MemoryManager::Free(pointer, false);
} }
void operator delete[](void* pointer) noexcept void operator delete[](void* pointer) noexcept
{ {
NzMemoryManager::Free(pointer, true); Nz::MemoryManager::Free(pointer, true);
} }
#endif // NAZARA_LUA_MANAGE_MEMORY #endif // NAZARA_LUA_MANAGE_MEMORY

View File

@ -10,22 +10,22 @@
void* operator new(std::size_t size) void* operator new(std::size_t size)
{ {
return NzMemoryManager::Allocate(size, false); return Nz::MemoryManager::Allocate(size, false);
} }
void* operator new[](std::size_t size) void* operator new[](std::size_t size)
{ {
return NzMemoryManager::Allocate(size, true); return Nz::MemoryManager::Allocate(size, true);
} }
void operator delete(void* pointer) noexcept void operator delete(void* pointer) noexcept
{ {
NzMemoryManager::Free(pointer, false); Nz::MemoryManager::Free(pointer, false);
} }
void operator delete[](void* pointer) noexcept void operator delete[](void* pointer) noexcept
{ {
NzMemoryManager::Free(pointer, true); Nz::MemoryManager::Free(pointer, true);
} }
#endif // NAZARA_NOISE_MANAGE_MEMORY #endif // NAZARA_NOISE_MANAGE_MEMORY

View File

@ -10,22 +10,22 @@
void* operator new(std::size_t size) void* operator new(std::size_t size)
{ {
return NzMemoryManager::Allocate(size, false); return Nz::MemoryManager::Allocate(size, false);
} }
void* operator new[](std::size_t size) void* operator new[](std::size_t size)
{ {
return NzMemoryManager::Allocate(size, true); return Nz::MemoryManager::Allocate(size, true);
} }
void operator delete(void* pointer) noexcept void operator delete(void* pointer) noexcept
{ {
NzMemoryManager::Free(pointer, false); Nz::MemoryManager::Free(pointer, false);
} }
void operator delete[](void* pointer) noexcept void operator delete[](void* pointer) noexcept
{ {
NzMemoryManager::Free(pointer, true); Nz::MemoryManager::Free(pointer, true);
} }
#endif // NAZARA_PHYSICS_MANAGE_MEMORY #endif // NAZARA_PHYSICS_MANAGE_MEMORY

View File

@ -14,7 +14,7 @@
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Renderer/Win32/ContextImpl.hpp> #include <Nazara/Renderer/Win32/ContextImpl.hpp>
#elif defined(NAZARA_PLATFORM_LINUX) #elif defined(NAZARA_PLATFORM_GLX)
#include <Nazara/Renderer/GLX/ContextImpl.hpp> #include <Nazara/Renderer/GLX/ContextImpl.hpp>
#define CALLBACK #define CALLBACK
#else #else

View File

@ -10,22 +10,22 @@
void* operator new(std::size_t size) void* operator new(std::size_t size)
{ {
return NzMemoryManager::Allocate(size, false); return Nz::MemoryManager::Allocate(size, false);
} }
void* operator new[](std::size_t size) void* operator new[](std::size_t size)
{ {
return NzMemoryManager::Allocate(size, true); return Nz::MemoryManager::Allocate(size, true);
} }
void operator delete(void* pointer) noexcept void operator delete(void* pointer) noexcept
{ {
NzMemoryManager::Free(pointer, false); Nz::MemoryManager::Free(pointer, false);
} }
void operator delete[](void* pointer) noexcept void operator delete[](void* pointer) noexcept
{ {
NzMemoryManager::Free(pointer, true); Nz::MemoryManager::Free(pointer, true);
} }
#endif // NAZARA_RENDERER_MANAGE_MEMORY #endif // NAZARA_RENDERER_MANAGE_MEMORY

View File

@ -12,6 +12,8 @@
using namespace GLX; using namespace GLX;
namespace Nz
{
namespace namespace
{ {
Display* m_display; Display* m_display;
@ -25,7 +27,7 @@ namespace
} }
} }
NzContextImpl::NzContextImpl() : ContextImpl::ContextImpl() :
m_colormap(0), m_colormap(0),
m_context(0), m_context(0),
m_window(0), m_window(0),
@ -37,7 +39,7 @@ m_ownsWindow(false)
++m_sharedDisplay; ++m_sharedDisplay;
} }
NzContextImpl::~NzContextImpl() ContextImpl::~ContextImpl()
{ {
Destroy(); Destroy();
@ -48,15 +50,15 @@ NzContextImpl::~NzContextImpl()
} }
} }
bool NzContextImpl::Activate() bool ContextImpl::Activate()
{ {
return glXMakeCurrent(m_display, m_window, m_context) == true; return glXMakeCurrent(m_display, m_window, m_context) == true;
} }
bool NzContextImpl::Create(NzContextParameters& parameters) bool ContextImpl::Create(ContextParameters& parameters)
{ {
// En cas d'exception, la ressource sera quand même libérée // En cas d'exception, la ressource sera quand même libérée
NzCallOnExit onExit([this] () CallOnExit onExit([this] ()
{ {
Destroy(); Destroy();
}); });
@ -251,7 +253,7 @@ bool NzContextImpl::Create(NzContextParameters& parameters)
return true; return true;
} }
void NzContextImpl::Destroy() void ContextImpl::Destroy()
{ {
// Destroy the context // Destroy the context
if (m_context) if (m_context)
@ -273,7 +275,7 @@ void NzContextImpl::Destroy()
} }
} }
void NzContextImpl::EnableVerticalSync(bool enabled) void ContextImpl::EnableVerticalSync(bool enabled)
{ {
if (glXSwapIntervalEXT) if (glXSwapIntervalEXT)
glXSwapIntervalEXT(m_display, glXGetCurrentDrawable(), enabled ? 1 : 0); glXSwapIntervalEXT(m_display, glXGetCurrentDrawable(), enabled ? 1 : 0);
@ -285,13 +287,14 @@ void NzContextImpl::EnableVerticalSync(bool enabled)
NazaraError("Vertical sync not supported"); NazaraError("Vertical sync not supported");
} }
void NzContextImpl::SwapBuffers() void ContextImpl::SwapBuffers()
{ {
if (m_window) if (m_window)
glXSwapBuffers(m_display, m_window); glXSwapBuffers(m_display, m_window);
} }
bool NzContextImpl::Desactivate() bool ContextImpl::Desactivate()
{ {
return glXMakeCurrent(m_display, None, nullptr) == true; return glXMakeCurrent(m_display, None, nullptr) == true;
} }
}

View File

@ -9,17 +9,19 @@
#include <Nazara/Renderer/OpenGL.hpp> #include <Nazara/Renderer/OpenGL.hpp>
class NzContextParameters; namespace Nz
{
class ContextParameters;
class NzContextImpl class ContextImpl
{ {
public: public:
NzContextImpl(); ContextImpl();
~NzContextImpl(); ~ContextImpl();
bool Activate(); bool Activate();
bool Create(NzContextParameters& parameters); bool Create(ContextParameters& parameters);
void Destroy(); void Destroy();
@ -35,5 +37,6 @@ class NzContextImpl
GLX::Window m_window; GLX::Window m_window;
bool m_ownsWindow; bool m_ownsWindow;
}; };
}
#endif // NAZARA_CONTEXTIMPL_HPP #endif // NAZARA_CONTEXTIMPL_HPP

View File

@ -9,6 +9,9 @@
#include <Nazara/Math/Algorithm.hpp> #include <Nazara/Math/Algorithm.hpp>
#include <Nazara/Renderer/Context.hpp> #include <Nazara/Renderer/Context.hpp>
#include <Nazara/Renderer/RenderTarget.hpp> #include <Nazara/Renderer/RenderTarget.hpp>
#if defined(NAZARA_PLATFORM_GLX)
#include <Nazara/Utility/X11/Display.hpp>
#endif // NAZARA_PLATFORM_GLX
#include <cstring> #include <cstring>
#include <set> #include <set>
#include <sstream> #include <sstream>
@ -30,7 +33,7 @@ namespace Nz
OpenGLFunc entry = reinterpret_cast<OpenGLFunc>(wglGetProcAddress(name)); OpenGLFunc entry = reinterpret_cast<OpenGLFunc>(wglGetProcAddress(name));
if (!entry) // wglGetProcAddress ne fonctionne pas sur les fonctions OpenGL <= 1.1 if (!entry) // wglGetProcAddress ne fonctionne pas sur les fonctions OpenGL <= 1.1
entry = reinterpret_cast<OpenGLFunc>(GetProcAddress(openGLlibrary, name)); entry = reinterpret_cast<OpenGLFunc>(GetProcAddress(openGLlibrary, name));
#elif defined(NAZARA_PLATFORM_LINUX) #elif defined(NAZARA_PLATFORM_GLX)
OpenGLFunc entry = reinterpret_cast<OpenGLFunc>(GLX::glXGetProcAddress(reinterpret_cast<const unsigned char*>(name))); OpenGLFunc entry = reinterpret_cast<OpenGLFunc>(GLX::glXGetProcAddress(reinterpret_cast<const unsigned char*>(name)));
#else #else
#error OS not handled #error OS not handled
@ -716,6 +719,15 @@ namespace Nz
if (s_initialized) if (s_initialized)
return true; return true;
#if defined(NAZARA_PLATFORM_GLX)
Initializer<X11> display;
if (!display)
{
NazaraError("Failed to load display library");
return false;
}
#endif
if (!LoadLibrary()) if (!LoadLibrary())
{ {
NazaraError("Failed to load OpenGL library"); NazaraError("Failed to load OpenGL library");
@ -1004,7 +1016,7 @@ namespace Nz
wglGetExtensionsStringARB = reinterpret_cast<PFNWGLGETEXTENSIONSSTRINGARBPROC>(LoadEntry("wglGetExtensionsStringARB", false)); wglGetExtensionsStringARB = reinterpret_cast<PFNWGLGETEXTENSIONSSTRINGARBPROC>(LoadEntry("wglGetExtensionsStringARB", false));
wglGetExtensionsStringEXT = reinterpret_cast<PFNWGLGETEXTENSIONSSTRINGEXTPROC>(LoadEntry("wglGetExtensionsStringEXT", false)); wglGetExtensionsStringEXT = reinterpret_cast<PFNWGLGETEXTENSIONSSTRINGEXTPROC>(LoadEntry("wglGetExtensionsStringEXT", false));
wglSwapInterval = reinterpret_cast<PFNWGLSWAPINTERVALEXTPROC>(LoadEntry("wglSwapIntervalEXT", false)); wglSwapInterval = reinterpret_cast<PFNWGLSWAPINTERVALEXTPROC>(LoadEntry("wglSwapIntervalEXT", false));
#elif defined(NAZARA_PLATFORM_LINUX) #elif defined(NAZARA_PLATFORM_GLX)
glXSwapIntervalEXT = reinterpret_cast<GLX::PFNGLXSWAPINTERVALEXTPROC>(LoadEntry("glXSwapIntervalEXT", false)); glXSwapIntervalEXT = reinterpret_cast<GLX::PFNGLXSWAPINTERVALEXTPROC>(LoadEntry("glXSwapIntervalEXT", false));
NzglXSwapIntervalMESA = reinterpret_cast<GLX::PFNGLXSWAPINTERVALMESAPROC>(LoadEntry("glXSwapIntervalMESA", false)); NzglXSwapIntervalMESA = reinterpret_cast<GLX::PFNGLXSWAPINTERVALMESAPROC>(LoadEntry("glXSwapIntervalMESA", false));
glXSwapIntervalSGI = reinterpret_cast<GLX::PFNGLXSWAPINTERVALSGIPROC>(LoadEntry("glXSwapIntervalSGI", false)); glXSwapIntervalSGI = reinterpret_cast<GLX::PFNGLXSWAPINTERVALSGIPROC>(LoadEntry("glXSwapIntervalSGI", false));
@ -2242,7 +2254,7 @@ PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = nullptr;
PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = nullptr; PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = nullptr;
PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT = nullptr; PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT = nullptr;
PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = nullptr; PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = nullptr;
#elif defined(NAZARA_PLATFORM_LINUX) #elif defined(NAZARA_PLATFORM_GLX)
GLX::PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = nullptr; GLX::PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = nullptr;
GLX::PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = nullptr; GLX::PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = nullptr;
GLX::PFNGLXSWAPINTERVALMESAPROC NzglXSwapIntervalMESA = nullptr; GLX::PFNGLXSWAPINTERVALMESAPROC NzglXSwapIntervalMESA = nullptr;

View File

@ -10,22 +10,22 @@
void* operator new(std::size_t size) void* operator new(std::size_t size)
{ {
return NzMemoryManager::Allocate(size, false); return Nz::MemoryManager::Allocate(size, false);
} }
void* operator new[](std::size_t size) void* operator new[](std::size_t size)
{ {
return NzMemoryManager::Allocate(size, true); return Nz::MemoryManager::Allocate(size, true);
} }
void operator delete(void* pointer) noexcept void operator delete(void* pointer) noexcept
{ {
NzMemoryManager::Free(pointer, false); Nz::MemoryManager::Free(pointer, false);
} }
void operator delete[](void* pointer) noexcept void operator delete[](void* pointer) noexcept
{ {
NzMemoryManager::Free(pointer, true); Nz::MemoryManager::Free(pointer, true);
} }
#endif // NAZARA_UTILITY_MANAGE_MEMORY #endif // NAZARA_UTILITY_MANAGE_MEMORY

View File

@ -12,10 +12,12 @@
#include <xcb/xcb_renderutil.h> #include <xcb/xcb_renderutil.h>
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
bool NzCursorImpl::Create(const NzImage& cursor, int hotSpotX, int hotSpotY) namespace Nz
{ {
NzImage cursorImage(cursor); // Vive le COW bool CursorImpl::Create(const Image& cursor, int hotSpotX, int hotSpotY)
if (!cursorImage.Convert(nzPixelFormat_BGRA8)) {
Image cursorImage(cursor); // Vive le COW
if (!cursorImage.Convert(Nz::PixelFormatType_BGRA8))
{ {
NazaraError("Failed to convert cursor to BGRA8"); NazaraError("Failed to convert cursor to BGRA8");
return false; return false;
@ -24,12 +26,12 @@ bool NzCursorImpl::Create(const NzImage& cursor, int hotSpotX, int hotSpotY)
auto width = cursorImage.GetWidth(); auto width = cursorImage.GetWidth();
auto height = cursorImage.GetHeight(); auto height = cursorImage.GetHeight();
NzScopedXCBConnection connection; ScopedXCBConnection connection;
xcb_screen_t* screen = X11::XCBDefaultScreen(connection); xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
NzScopedXCB<xcb_generic_error_t> error(nullptr); ScopedXCB<xcb_generic_error_t> error(nullptr);
NzScopedXCB<xcb_render_query_pict_formats_reply_t> formatsReply = xcb_render_query_pict_formats_reply( ScopedXCB<xcb_render_query_pict_formats_reply_t> formatsReply = xcb_render_query_pict_formats_reply(
connection, connection,
xcb_render_query_pict_formats(connection), xcb_render_query_pict_formats(connection),
&error); &error);
@ -79,13 +81,13 @@ bool NzCursorImpl::Create(const NzImage& cursor, int hotSpotX, int hotSpotY)
xcb_render_picture_t pic = XCB_NONE; xcb_render_picture_t pic = XCB_NONE;
NzCallOnExit onExit([&](){ CallOnExit onExit([&](){
xcb_image_destroy(xi); xcb_image_destroy(xi);
if (pic != XCB_NONE) if (pic != XCB_NONE)
xcb_render_free_picture(connection, pic); xcb_render_free_picture(connection, pic);
}); });
NzXCBPixmap pix(connection); XCBPixmap pix(connection);
if (!pix.Create(32, screen->root, width, height)) if (!pix.Create(32, screen->root, width, height))
{ {
NazaraError("Failed to create pixmap for cursor"); NazaraError("Failed to create pixmap for cursor");
@ -108,7 +110,7 @@ bool NzCursorImpl::Create(const NzImage& cursor, int hotSpotX, int hotSpotY)
return false; return false;
} }
NzXCBGContext gc(connection); XCBGContext gc(connection);
if (!gc.Create(pix, 0, nullptr)) if (!gc.Create(pix, 0, nullptr))
{ {
NazaraError("Failed to create gcontext for cursor"); NazaraError("Failed to create gcontext for cursor");
@ -147,15 +149,16 @@ bool NzCursorImpl::Create(const NzImage& cursor, int hotSpotX, int hotSpotY)
return true; return true;
} }
void NzCursorImpl::Destroy() void CursorImpl::Destroy()
{ {
NzScopedXCBConnection connection; ScopedXCBConnection connection;
xcb_free_cursor(connection, m_cursor); xcb_free_cursor(connection, m_cursor);
m_cursor = 0; m_cursor = 0;
} }
xcb_cursor_t NzCursorImpl::GetCursor() xcb_cursor_t CursorImpl::GetCursor()
{ {
return m_cursor; return m_cursor;
} }
}

View File

@ -7,14 +7,17 @@
#ifndef NAZARA_CURSORIMPL_HPP #ifndef NAZARA_CURSORIMPL_HPP
#define NAZARA_CURSORIMPL_HPP #define NAZARA_CURSORIMPL_HPP
#include <Nazara/Prerequesites.hpp>
#include <xcb/xcb_cursor.h> #include <xcb/xcb_cursor.h>
class NzImage; namespace Nz
{
class Image;
class NzCursorImpl class CursorImpl
{ {
public: public:
bool Create(const NzImage& image, int hotSpotX, int hotSpotY); bool Create(const Image& image, int hotSpotX, int hotSpotY);
void Destroy(); void Destroy();
xcb_cursor_t GetCursor(); xcb_cursor_t GetCursor();
@ -22,5 +25,6 @@ class NzCursorImpl
private: private:
xcb_cursor_t m_cursor; xcb_cursor_t m_cursor;
}; };
}
#endif // NAZARA_CURSORIMPL_HPP #endif // NAZARA_CURSORIMPL_HPP

View File

@ -4,10 +4,14 @@
#include <Nazara/Utility/X11/Display.hpp> #include <Nazara/Utility/X11/Display.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/String.hpp>
#include <xcb/xcb_keysyms.h> #include <xcb/xcb_keysyms.h>
#include <map> #include <map>
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
namespace Nz
{
namespace namespace
{ {
// The shared display and its reference counter // The shared display and its reference counter
@ -15,21 +19,19 @@ namespace
int screen_nbr = 0; int screen_nbr = 0;
unsigned int referenceCountConnection = 0; unsigned int referenceCountConnection = 0;
xcb_key_symbols_t* sharedkeySymbol; xcb_key_symbols_t* sharedkeySymbol = nullptr;
unsigned int referenceCountKeySymbol = 0; unsigned int referenceCountKeySymbol = 0;
xcb_ewmh_connection_t* sharedEwmhConnection; xcb_ewmh_connection_t* sharedEwmhConnection = nullptr;
unsigned int referenceCountEwmhConnection = 0; unsigned int referenceCountEwmhConnection = 0;
using AtomMap = std::map<std::string, xcb_atom_t>; using AtomMap = std::map<String, xcb_atom_t>;
AtomMap atoms; AtomMap atoms;
} }
namespace X11 bool X11::CheckCookie(xcb_connection_t* connection, xcb_void_cookie_t cookie)
{ {
bool CheckCookie(xcb_connection_t* connection, xcb_void_cookie_t cookie) ScopedXCB<xcb_generic_error_t> error(xcb_request_check(
{
NzScopedXCB<xcb_generic_error_t> error(xcb_request_check(
connection, connection,
cookie cookie
)); ));
@ -40,36 +42,36 @@ namespace X11
return true; return true;
} }
void CloseConnection(xcb_connection_t* connection) void X11::CloseConnection(xcb_connection_t* connection)
{ {
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
--referenceCountConnection; --referenceCountConnection;
} }
void CloseEWMHConnection(xcb_ewmh_connection_t* ewmh_connection) void X11::CloseEWMHConnection(xcb_ewmh_connection_t* ewmh_connection)
{ {
NazaraAssert(ewmh_connection == sharedEwmhConnection, "The model is meant for one connection to X11 server"); NazaraAssert(ewmh_connection == sharedEwmhConnection, "The model is meant for one connection to X11 server");
--referenceCountEwmhConnection; --referenceCountEwmhConnection;
} }
xcb_atom_t GetAtom(const std::string& name, bool onlyIfExists) xcb_atom_t X11::GetAtom(const String& name, bool onlyIfExists)
{ {
AtomMap::const_iterator iter = atoms.find(name); AtomMap::const_iterator iter = atoms.find(name);
if (iter != atoms.end()) if (iter != atoms.end())
return iter->second; return iter->second;
NzScopedXCB<xcb_generic_error_t> error(nullptr); ScopedXCB<xcb_generic_error_t> error(nullptr);
xcb_connection_t* connection = OpenConnection(); xcb_connection_t* connection = OpenConnection();
NzScopedXCB<xcb_intern_atom_reply_t> reply(xcb_intern_atom_reply( ScopedXCB<xcb_intern_atom_reply_t> reply(xcb_intern_atom_reply(
connection, connection,
xcb_intern_atom( xcb_intern_atom(
connection, connection,
onlyIfExists, onlyIfExists,
name.size(), name.GetSize(),
name.c_str() name.GetConstBuffer()
), ),
&error &error
)); ));
@ -87,8 +89,16 @@ namespace X11
return reply->atom; return reply->atom;
} }
void Initialize() bool X11::Initialize()
{ {
if (IsInitialized())
{
s_moduleReferenceCounter++;
return true; // Déjà initialisé
}
s_moduleReferenceCounter++;
NazaraAssert(referenceCountConnection == 0, "Initialize should be called before anything"); NazaraAssert(referenceCountConnection == 0, "Initialize should be called before anything");
NazaraAssert(referenceCountKeySymbol == 0, "Initialize should be called before anything"); NazaraAssert(referenceCountKeySymbol == 0, "Initialize should be called before anything");
NazaraAssert(referenceCountEwmhConnection == 0, "Initialize should be called before anything"); NazaraAssert(referenceCountEwmhConnection == 0, "Initialize should be called before anything");
@ -125,9 +135,17 @@ namespace X11
OpenEWMHConnection(sharedConnection); OpenEWMHConnection(sharedConnection);
} }
NazaraNotice("Initialized: Utility module");
return true;
} }
xcb_key_symbols_t* XCBKeySymbolsAlloc(xcb_connection_t* connection) bool X11::IsInitialized()
{
return s_moduleReferenceCounter != 0;
}
xcb_key_symbols_t* X11::XCBKeySymbolsAlloc(xcb_connection_t* connection)
{ {
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
@ -135,20 +153,20 @@ namespace X11
return sharedkeySymbol; return sharedkeySymbol;
} }
void XCBKeySymbolsFree(xcb_key_symbols_t* keySymbols) void X11::XCBKeySymbolsFree(xcb_key_symbols_t* keySymbols)
{ {
NazaraAssert(keySymbols == sharedkeySymbol, "The model is meant for one connection to X11 server"); NazaraAssert(keySymbols == sharedkeySymbol, "The model is meant for one connection to X11 server");
--referenceCountKeySymbol; --referenceCountKeySymbol;
} }
xcb_connection_t* OpenConnection() xcb_connection_t* X11::OpenConnection()
{ {
++referenceCountConnection; ++referenceCountConnection;
return sharedConnection; return sharedConnection;
} }
xcb_ewmh_connection_t* OpenEWMHConnection(xcb_connection_t* connection) xcb_ewmh_connection_t* X11::OpenEWMHConnection(xcb_connection_t* connection)
{ {
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
@ -156,8 +174,19 @@ namespace X11
return sharedEwmhConnection; return sharedEwmhConnection;
} }
void Uninitialize() void X11::Uninitialize()
{ {
if (s_moduleReferenceCounter != 1)
{
// Le module est soit encore utilisé, soit pas initialisé
if (s_moduleReferenceCounter > 1)
s_moduleReferenceCounter--;
return;
}
s_moduleReferenceCounter = 0;
{ {
NazaraAssert(referenceCountEwmhConnection == 1, "Uninitialize should be called after anything or a close is missing"); NazaraAssert(referenceCountEwmhConnection == 1, "Uninitialize should be called after anything or a close is missing");
CloseEWMHConnection(sharedEwmhConnection); CloseEWMHConnection(sharedEwmhConnection);
@ -179,9 +208,11 @@ namespace X11
xcb_disconnect(sharedConnection); xcb_disconnect(sharedConnection);
} }
NazaraNotice("Uninitialized: Display module");
} }
xcb_window_t XCBDefaultRootWindow(xcb_connection_t* connection) xcb_window_t X11::XCBDefaultRootWindow(xcb_connection_t* connection)
{ {
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
xcb_screen_t* screen = XCBDefaultScreen(connection); xcb_screen_t* screen = XCBDefaultScreen(connection);
@ -190,19 +221,19 @@ namespace X11
return XCB_NONE; return XCB_NONE;
} }
xcb_screen_t* XCBDefaultScreen(xcb_connection_t* connection) xcb_screen_t* X11::XCBDefaultScreen(xcb_connection_t* connection)
{ {
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
return XCBScreenOfDisplay(connection, screen_nbr); return XCBScreenOfDisplay(connection, screen_nbr);
} }
int XCBScreen(xcb_connection_t* connection) int X11::XCBScreen(xcb_connection_t* connection)
{ {
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
return screen_nbr; return screen_nbr;
} }
xcb_screen_t* XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr) xcb_screen_t* X11::XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr)
{ {
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(connection)); xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(connection));
@ -215,4 +246,6 @@ namespace X11
return nullptr; return nullptr;
} }
unsigned int X11::s_moduleReferenceCounter = 0;
} }

View File

@ -7,35 +7,47 @@
#ifndef NAZARA_X11DISPLAY_HPP #ifndef NAZARA_X11DISPLAY_HPP
#define NAZARA_X11DISPLAY_HPP #define NAZARA_X11DISPLAY_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/WindowHandle.hpp> #include <Nazara/Utility/WindowHandle.hpp>
#include <Nazara/Utility/X11/ScopedXCB.hpp> #include <Nazara/Utility/X11/ScopedXCB.hpp>
#include <xcb/xcb_ewmh.h>
#include <string>
typedef struct _XCBKeySymbols xcb_key_symbols_t; typedef struct _XCBKeySymbols xcb_key_symbols_t;
namespace X11 namespace Nz
{ {
bool CheckCookie(xcb_connection_t* connection, xcb_void_cookie_t cookie); class String;
void CloseConnection(xcb_connection_t* connection);
void CloseEWMHConnection(xcb_ewmh_connection_t* ewmh_connection);
xcb_atom_t GetAtom(const std::string& name, bool onlyIfExists = false); class X11
{
public:
X11() = delete;
~X11() = delete;
void Initialize(); static bool CheckCookie(xcb_connection_t* connection, xcb_void_cookie_t cookie);
static void CloseConnection(xcb_connection_t* connection);
static void CloseEWMHConnection(xcb_ewmh_connection_t* ewmh_connection);
xcb_key_symbols_t* XCBKeySymbolsAlloc(xcb_connection_t* connection); static xcb_atom_t GetAtom(const String& name, bool onlyIfExists = false);
void XCBKeySymbolsFree(xcb_key_symbols_t* keySymbols);
xcb_connection_t* OpenConnection(); static bool Initialize();
xcb_ewmh_connection_t* OpenEWMHConnection(xcb_connection_t* connection); static bool IsInitialized();
void Uninitialize(); static xcb_key_symbols_t* XCBKeySymbolsAlloc(xcb_connection_t* connection);
static void XCBKeySymbolsFree(xcb_key_symbols_t* keySymbols);
xcb_screen_t* XCBDefaultScreen(xcb_connection_t* connection); static xcb_connection_t* OpenConnection();
xcb_window_t XCBDefaultRootWindow(xcb_connection_t* connection); static xcb_ewmh_connection_t* OpenEWMHConnection(xcb_connection_t* connection);
int XCBScreen(xcb_connection_t* connection);
xcb_screen_t* XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr); static void Uninitialize();
static xcb_screen_t* XCBDefaultScreen(xcb_connection_t* connection);
static xcb_window_t XCBDefaultRootWindow(xcb_connection_t* connection);
static int XCBScreen(xcb_connection_t* connection);
static xcb_screen_t* XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr);
private:
static unsigned int s_moduleReferenceCounter;
};
} }
#endif // NAZARA_X11DISPLAY_HPP #endif // NAZARA_X11DISPLAY_HPP

View File

@ -10,18 +10,20 @@
#include <Nazara/Utility/X11/Display.hpp> #include <Nazara/Utility/X11/Display.hpp>
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
NzIconImpl::NzIconImpl() namespace Nz
{ {
NzScopedXCBConnection connection; IconImpl::IconImpl()
{
ScopedXCBConnection connection;
m_iconPixmap.Connect(connection); m_iconPixmap.Connect(connection);
m_maskPixmap.Connect(connection); m_maskPixmap.Connect(connection);
} }
bool NzIconImpl::Create(const NzImage& icon) bool IconImpl::Create(const Image& icon)
{ {
NzImage iconImage(icon); // Vive le COW Image iconImage(icon); // Vive le COW
if (!iconImage.Convert(nzPixelFormat_BGRA8)) if (!iconImage.Convert(Nz::PixelFormatType_BGRA8))
{ {
NazaraError("Failed to convert icon to BGRA8"); NazaraError("Failed to convert icon to BGRA8");
return false; return false;
@ -30,7 +32,7 @@ bool NzIconImpl::Create(const NzImage& icon)
auto width = iconImage.GetWidth(); auto width = iconImage.GetWidth();
auto height = iconImage.GetHeight(); auto height = iconImage.GetHeight();
NzScopedXCBConnection connection; ScopedXCBConnection connection;
xcb_screen_t* screen = X11::XCBDefaultScreen(connection); xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
@ -44,11 +46,11 @@ bool NzIconImpl::Create(const NzImage& icon)
return false; return false;
} }
NzCallOnExit onExit([this](){ CallOnExit onExit([this](){
Destroy(); Destroy();
}); });
NzXCBGContext iconGC(connection); XCBGContext iconGC(connection);
if (!iconGC.Create( if (!iconGC.Create(
m_iconPixmap, m_iconPixmap,
@ -82,7 +84,7 @@ bool NzIconImpl::Create(const NzImage& icon)
// Create the mask pixmap (must have 1 bit depth) // Create the mask pixmap (must have 1 bit depth)
std::size_t pitch = (width + 7) / 8; std::size_t pitch = (width + 7) / 8;
static std::vector<nzUInt8> maskPixels(pitch * height, 0); static std::vector<UInt8> maskPixels(pitch * height, 0);
for (std::size_t j = 0; j < height; ++j) for (std::size_t j = 0; j < height; ++j)
{ {
for (std::size_t i = 0; i < pitch; ++i) for (std::size_t i = 0; i < pitch; ++i)
@ -91,7 +93,7 @@ bool NzIconImpl::Create(const NzImage& icon)
{ {
if (i * 8 + k < width) if (i * 8 + k < width)
{ {
nzUInt8 opacity = (iconImage.GetConstPixels()[(i * 8 + k + j * width) * 4 + 3] > 0) ? 1 : 0; UInt8 opacity = (iconImage.GetConstPixels()[(i * 8 + k + j * width) * 4 + 3] > 0) ? 1 : 0;
maskPixels[i + j * pitch] |= (opacity << k); maskPixels[i + j * pitch] |= (opacity << k);
} }
} }
@ -117,18 +119,19 @@ bool NzIconImpl::Create(const NzImage& icon)
return true; return true;
} }
void NzIconImpl::Destroy() void IconImpl::Destroy()
{ {
m_iconPixmap.Destroy(); m_iconPixmap.Destroy();
m_maskPixmap.Destroy(); m_maskPixmap.Destroy();
} }
xcb_pixmap_t NzIconImpl::GetIcon() xcb_pixmap_t IconImpl::GetIcon()
{ {
return m_iconPixmap; return m_iconPixmap;
} }
xcb_pixmap_t NzIconImpl::GetMask() xcb_pixmap_t IconImpl::GetMask()
{ {
return m_maskPixmap; return m_maskPixmap;
} }
}

View File

@ -7,24 +7,28 @@
#ifndef NAZARA_ICONIMPL_HPP #ifndef NAZARA_ICONIMPL_HPP
#define NAZARA_ICONIMPL_HPP #define NAZARA_ICONIMPL_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/X11/ScopedXCB.hpp> #include <Nazara/Utility/X11/ScopedXCB.hpp>
class NzImage; namespace Nz
{
class Image;
class NzIconImpl class IconImpl
{ {
public: public:
NzIconImpl(); IconImpl();
bool Create(const NzImage& image); bool Create(const Image& image);
void Destroy(); void Destroy();
xcb_pixmap_t GetIcon(); xcb_pixmap_t GetIcon();
xcb_pixmap_t GetMask(); xcb_pixmap_t GetMask();
private: private:
NzXCBPixmap m_iconPixmap; XCBPixmap m_iconPixmap;
NzXCBPixmap m_maskPixmap; XCBPixmap m_maskPixmap;
}; };
}
#endif // NAZARA_ICONIMPL_HPP #endif // NAZARA_ICONIMPL_HPP

View File

@ -12,166 +12,167 @@
#include <xcb/xcb_keysyms.h> #include <xcb/xcb_keysyms.h>
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
namespace Nz
{
namespace namespace
{ {
KeySym GetKeySym(Keyboard::Key key)
KeySym GetKeySym(NzKeyboard::Key key)
{ {
// X11 keysym correspondant // X11 keysym correspondant
KeySym keysym = 0; KeySym keysym = 0;
switch (key) switch (key)
{ {
// Lettres // Lettres
case NzKeyboard::A: keysym = XK_A; break; case Keyboard::A: keysym = XK_A; break;
case NzKeyboard::B: keysym = XK_B; break; case Keyboard::B: keysym = XK_B; break;
case NzKeyboard::C: keysym = XK_C; break; case Keyboard::C: keysym = XK_C; break;
case NzKeyboard::D: keysym = XK_D; break; case Keyboard::D: keysym = XK_D; break;
case NzKeyboard::E: keysym = XK_E; break; case Keyboard::E: keysym = XK_E; break;
case NzKeyboard::F: keysym = XK_F; break; case Keyboard::F: keysym = XK_F; break;
case NzKeyboard::G: keysym = XK_G; break; case Keyboard::G: keysym = XK_G; break;
case NzKeyboard::H: keysym = XK_H; break; case Keyboard::H: keysym = XK_H; break;
case NzKeyboard::I: keysym = XK_I; break; case Keyboard::I: keysym = XK_I; break;
case NzKeyboard::J: keysym = XK_J; break; case Keyboard::J: keysym = XK_J; break;
case NzKeyboard::K: keysym = XK_K; break; case Keyboard::K: keysym = XK_K; break;
case NzKeyboard::L: keysym = XK_L; break; case Keyboard::L: keysym = XK_L; break;
case NzKeyboard::M: keysym = XK_M; break; case Keyboard::M: keysym = XK_M; break;
case NzKeyboard::N: keysym = XK_N; break; case Keyboard::N: keysym = XK_N; break;
case NzKeyboard::O: keysym = XK_O; break; case Keyboard::O: keysym = XK_O; break;
case NzKeyboard::P: keysym = XK_P; break; case Keyboard::P: keysym = XK_P; break;
case NzKeyboard::Q: keysym = XK_Q; break; case Keyboard::Q: keysym = XK_Q; break;
case NzKeyboard::R: keysym = XK_R; break; case Keyboard::R: keysym = XK_R; break;
case NzKeyboard::S: keysym = XK_S; break; case Keyboard::S: keysym = XK_S; break;
case NzKeyboard::T: keysym = XK_T; break; case Keyboard::T: keysym = XK_T; break;
case NzKeyboard::U: keysym = XK_U; break; case Keyboard::U: keysym = XK_U; break;
case NzKeyboard::V: keysym = XK_V; break; case Keyboard::V: keysym = XK_V; break;
case NzKeyboard::W: keysym = XK_W; break; case Keyboard::W: keysym = XK_W; break;
case NzKeyboard::X: keysym = XK_X; break; case Keyboard::X: keysym = XK_X; break;
case NzKeyboard::Y: keysym = XK_Y; break; case Keyboard::Y: keysym = XK_Y; break;
case NzKeyboard::Z: keysym = XK_Z; break; case Keyboard::Z: keysym = XK_Z; break;
// Touches de fonction // Touches de fonction
case NzKeyboard::F1: keysym = XK_F1; break; case Keyboard::F1: keysym = XK_F1; break;
case NzKeyboard::F2: keysym = XK_F2; break; case Keyboard::F2: keysym = XK_F2; break;
case NzKeyboard::F3: keysym = XK_F3; break; case Keyboard::F3: keysym = XK_F3; break;
case NzKeyboard::F4: keysym = XK_F4; break; case Keyboard::F4: keysym = XK_F4; break;
case NzKeyboard::F5: keysym = XK_F5; break; case Keyboard::F5: keysym = XK_F5; break;
case NzKeyboard::F6: keysym = XK_F6; break; case Keyboard::F6: keysym = XK_F6; break;
case NzKeyboard::F7: keysym = XK_F7; break; case Keyboard::F7: keysym = XK_F7; break;
case NzKeyboard::F8: keysym = XK_F8; break; case Keyboard::F8: keysym = XK_F8; break;
case NzKeyboard::F9: keysym = XK_F9; break; case Keyboard::F9: keysym = XK_F9; break;
case NzKeyboard::F10: keysym = XK_F10; break; case Keyboard::F10: keysym = XK_F10; break;
case NzKeyboard::F11: keysym = XK_F11; break; case Keyboard::F11: keysym = XK_F11; break;
case NzKeyboard::F12: keysym = XK_F12; break; case Keyboard::F12: keysym = XK_F12; break;
case NzKeyboard::F13: keysym = XK_F13; break; case Keyboard::F13: keysym = XK_F13; break;
case NzKeyboard::F14: keysym = XK_F14; break; case Keyboard::F14: keysym = XK_F14; break;
case NzKeyboard::F15: keysym = XK_F15; break; case Keyboard::F15: keysym = XK_F15; break;
// Flèches directionnelles // Flèches directionnelles
case NzKeyboard::Down: keysym = XK_Down; break; case Keyboard::Down: keysym = XK_Down; break;
case NzKeyboard::Left: keysym = XK_Left; break; case Keyboard::Left: keysym = XK_Left; break;
case NzKeyboard::Right: keysym = XK_Right; break; case Keyboard::Right: keysym = XK_Right; break;
case NzKeyboard::Up: keysym = XK_Up; break; case Keyboard::Up: keysym = XK_Up; break;
// Pavé numérique // Pavé numérique
case NzKeyboard::Add: keysym = XK_KP_Add; break; case Keyboard::Add: keysym = XK_KP_Add; break;
case NzKeyboard::Decimal: keysym = XK_KP_Decimal; break; case Keyboard::Decimal: keysym = XK_KP_Decimal; break;
case NzKeyboard::Divide: keysym = XK_KP_Divide; break; case Keyboard::Divide: keysym = XK_KP_Divide; break;
case NzKeyboard::Multiply: keysym = XK_KP_Multiply; break; case Keyboard::Multiply: keysym = XK_KP_Multiply; break;
case NzKeyboard::Numpad0: keysym = XK_KP_0; break; case Keyboard::Numpad0: keysym = XK_KP_0; break;
case NzKeyboard::Numpad1: keysym = XK_KP_1; break; case Keyboard::Numpad1: keysym = XK_KP_1; break;
case NzKeyboard::Numpad2: keysym = XK_KP_2; break; case Keyboard::Numpad2: keysym = XK_KP_2; break;
case NzKeyboard::Numpad3: keysym = XK_KP_3; break; case Keyboard::Numpad3: keysym = XK_KP_3; break;
case NzKeyboard::Numpad4: keysym = XK_KP_4; break; case Keyboard::Numpad4: keysym = XK_KP_4; break;
case NzKeyboard::Numpad5: keysym = XK_KP_5; break; case Keyboard::Numpad5: keysym = XK_KP_5; break;
case NzKeyboard::Numpad6: keysym = XK_KP_6; break; case Keyboard::Numpad6: keysym = XK_KP_6; break;
case NzKeyboard::Numpad7: keysym = XK_KP_7; break; case Keyboard::Numpad7: keysym = XK_KP_7; break;
case NzKeyboard::Numpad8: keysym = XK_KP_8; break; case Keyboard::Numpad8: keysym = XK_KP_8; break;
case NzKeyboard::Numpad9: keysym = XK_KP_9; break; case Keyboard::Numpad9: keysym = XK_KP_9; break;
case NzKeyboard::Subtract: keysym = XK_KP_Subtract; break; case Keyboard::Subtract: keysym = XK_KP_Subtract; break;
// Divers // Divers
case NzKeyboard::Backslash: keysym = XK_backslash; break; case Keyboard::Backslash: keysym = XK_backslash; break;
case NzKeyboard::Backspace: keysym = XK_BackSpace; break; case Keyboard::Backspace: keysym = XK_BackSpace; break;
case NzKeyboard::Clear: keysym = XK_Clear; break; case Keyboard::Clear: keysym = XK_Clear; break;
case NzKeyboard::Comma: keysym = XK_comma; break; case Keyboard::Comma: keysym = XK_comma; break;
case NzKeyboard::Dash: keysym = XK_minus; break; case Keyboard::Dash: keysym = XK_minus; break;
case NzKeyboard::Delete: keysym = XK_Delete; break; case Keyboard::Delete: keysym = XK_Delete; break;
case NzKeyboard::End: keysym = XK_End; break; case Keyboard::End: keysym = XK_End; break;
case NzKeyboard::Equal: keysym = XK_equal; break; case Keyboard::Equal: keysym = XK_equal; break;
case NzKeyboard::Escape: keysym = XK_Escape; break; case Keyboard::Escape: keysym = XK_Escape; break;
case NzKeyboard::Home: keysym = XK_Home; break; case Keyboard::Home: keysym = XK_Home; break;
case NzKeyboard::Insert: keysym = XK_Insert; break; case Keyboard::Insert: keysym = XK_Insert; break;
case NzKeyboard::LAlt: keysym = XK_Alt_L; break; case Keyboard::LAlt: keysym = XK_Alt_L; break;
case NzKeyboard::LBracket: keysym = XK_bracketleft; break; case Keyboard::LBracket: keysym = XK_bracketleft; break;
case NzKeyboard::LControl: keysym = XK_Control_L; break; case Keyboard::LControl: keysym = XK_Control_L; break;
case NzKeyboard::LShift: keysym = XK_Shift_L; break; case Keyboard::LShift: keysym = XK_Shift_L; break;
case NzKeyboard::LSystem: keysym = XK_Super_L; break; case Keyboard::LSystem: keysym = XK_Super_L; break;
case NzKeyboard::Num0: keysym = XK_0; break; case Keyboard::Num0: keysym = XK_0; break;
case NzKeyboard::Num1: keysym = XK_1; break; case Keyboard::Num1: keysym = XK_1; break;
case NzKeyboard::Num2: keysym = XK_2; break; case Keyboard::Num2: keysym = XK_2; break;
case NzKeyboard::Num3: keysym = XK_3; break; case Keyboard::Num3: keysym = XK_3; break;
case NzKeyboard::Num4: keysym = XK_4; break; case Keyboard::Num4: keysym = XK_4; break;
case NzKeyboard::Num5: keysym = XK_5; break; case Keyboard::Num5: keysym = XK_5; break;
case NzKeyboard::Num6: keysym = XK_6; break; case Keyboard::Num6: keysym = XK_6; break;
case NzKeyboard::Num7: keysym = XK_7; break; case Keyboard::Num7: keysym = XK_7; break;
case NzKeyboard::Num8: keysym = XK_8; break; case Keyboard::Num8: keysym = XK_8; break;
case NzKeyboard::Num9: keysym = XK_9; break; case Keyboard::Num9: keysym = XK_9; break;
case NzKeyboard::PageDown: keysym = XK_Page_Down; break; case Keyboard::PageDown: keysym = XK_Page_Down; break;
case NzKeyboard::PageUp: keysym = XK_Page_Up; break; case Keyboard::PageUp: keysym = XK_Page_Up; break;
case NzKeyboard::Pause: keysym = XK_Pause; break; case Keyboard::Pause: keysym = XK_Pause; break;
case NzKeyboard::Period: keysym = XK_period; break; case Keyboard::Period: keysym = XK_period; break;
case NzKeyboard::Print: keysym = XK_Print; break; case Keyboard::Print: keysym = XK_Print; break;
case NzKeyboard::PrintScreen: keysym = XK_Sys_Req; break; case Keyboard::PrintScreen: keysym = XK_Sys_Req; break;
case NzKeyboard::Quote: keysym = XK_quotedbl; break; case Keyboard::Quote: keysym = XK_quotedbl; break;
case NzKeyboard::RAlt: keysym = XK_Alt_R; break; case Keyboard::RAlt: keysym = XK_Alt_R; break;
case NzKeyboard::RBracket: keysym = XK_bracketright; break; case Keyboard::RBracket: keysym = XK_bracketright; break;
case NzKeyboard::RControl: keysym = XK_Control_R; break; case Keyboard::RControl: keysym = XK_Control_R; break;
case NzKeyboard::Return: keysym = XK_Return; break; case Keyboard::Return: keysym = XK_Return; break;
case NzKeyboard::RShift: keysym = XK_Shift_R; break; case Keyboard::RShift: keysym = XK_Shift_R; break;
case NzKeyboard::RSystem: keysym = XK_Super_R; break; case Keyboard::RSystem: keysym = XK_Super_R; break;
case NzKeyboard::Semicolon: keysym = XK_semicolon; break; case Keyboard::Semicolon: keysym = XK_semicolon; break;
case NzKeyboard::Slash: keysym = XK_slash; break; case Keyboard::Slash: keysym = XK_slash; break;
case NzKeyboard::Space: keysym = XK_space; break; case Keyboard::Space: keysym = XK_space; break;
case NzKeyboard::Tab: keysym = XK_Tab; break; case Keyboard::Tab: keysym = XK_Tab; break;
case NzKeyboard::Tilde: keysym = XK_grave; break; case Keyboard::Tilde: keysym = XK_grave; break;
// Touches navigateur // Touches navigateur
case NzKeyboard::Browser_Back: keysym = XF86XK_Back; break; case Keyboard::Browser_Back: keysym = XF86XK_Back; break;
case NzKeyboard::Browser_Favorites: keysym = XF86XK_Favorites; break; case Keyboard::Browser_Favorites: keysym = XF86XK_Favorites; break;
case NzKeyboard::Browser_Forward: keysym = XF86XK_Forward; break; case Keyboard::Browser_Forward: keysym = XF86XK_Forward; break;
case NzKeyboard::Browser_Home: keysym = XF86XK_HomePage; break; case Keyboard::Browser_Home: keysym = XF86XK_HomePage; break;
case NzKeyboard::Browser_Refresh: keysym = XF86XK_Refresh; break; case Keyboard::Browser_Refresh: keysym = XF86XK_Refresh; break;
case NzKeyboard::Browser_Search: keysym = XF86XK_Search; break; case Keyboard::Browser_Search: keysym = XF86XK_Search; break;
case NzKeyboard::Browser_Stop: keysym = XF86XK_Stop; break; case Keyboard::Browser_Stop: keysym = XF86XK_Stop; break;
// Touches de contrôle // Touches de contrôle
case NzKeyboard::Media_Next: keysym = XF86XK_AudioNext; break; case Keyboard::Media_Next: keysym = XF86XK_AudioNext; break;
case NzKeyboard::Media_Play: keysym = XF86XK_AudioPlay; break; case Keyboard::Media_Play: keysym = XF86XK_AudioPlay; break;
case NzKeyboard::Media_Previous: keysym = XF86XK_AudioPrev; break; case Keyboard::Media_Previous: keysym = XF86XK_AudioPrev; break;
case NzKeyboard::Media_Stop: keysym = XF86XK_AudioStop; break; case Keyboard::Media_Stop: keysym = XF86XK_AudioStop; break;
// Touches de contrôle du volume // Touches de contrôle du volume
case NzKeyboard::Volume_Down: keysym = XF86XK_AudioLowerVolume; break; case Keyboard::Volume_Down: keysym = XF86XK_AudioLowerVolume; break;
case NzKeyboard::Volume_Mute: keysym = XF86XK_AudioMute; break; case Keyboard::Volume_Mute: keysym = XF86XK_AudioMute; break;
case NzKeyboard::Volume_Up: keysym = XF86XK_AudioRaiseVolume; break; case Keyboard::Volume_Up: keysym = XF86XK_AudioRaiseVolume; break;
// Touches à verrouillage // Touches à verrouillage
case NzKeyboard::CapsLock: keysym = XK_Caps_Lock; break; case Keyboard::CapsLock: keysym = XK_Caps_Lock; break;
case NzKeyboard::NumLock: keysym = XK_Num_Lock; break; case Keyboard::NumLock: keysym = XK_Num_Lock; break;
case NzKeyboard::ScrollLock: keysym = XK_Scroll_Lock; break; case Keyboard::ScrollLock: keysym = XK_Scroll_Lock; break;
default: break; default: break;
} }
// Sanity checks // Sanity checks
if (key < 0 || key >= NzKeyboard::Count || keysym == 0) if (key < 0 || key >= Keyboard::Count || keysym == 0)
NazaraWarning("Key " + NzString::Number(key) + " is not handled in NzKeyboard"); NazaraWarning("Key " + String::Number(key) + " is not handled in Keyboard");
return keysym; return keysym;
} }
} }
NzString NzEventImpl::GetKeyName(NzKeyboard::Key key) String EventImpl::GetKeyName(Keyboard::Key key)
{ {
KeySym keySym = GetKeySym(key); KeySym keySym = GetKeySym(key);
@ -179,13 +180,13 @@ NzString NzEventImpl::GetKeyName(NzKeyboard::Key key)
return XKeysymToString(keySym); return XKeysymToString(keySym);
} }
NzVector2i NzEventImpl::GetMousePosition() Vector2i EventImpl::GetMousePosition()
{ {
NzScopedXCBConnection connection; ScopedXCBConnection connection;
NzScopedXCB<xcb_generic_error_t> error(nullptr); ScopedXCB<xcb_generic_error_t> error(nullptr);
NzScopedXCB<xcb_query_pointer_reply_t> pointer( ScopedXCB<xcb_query_pointer_reply_t> pointer(
xcb_query_pointer_reply( xcb_query_pointer_reply(
connection, connection,
xcb_query_pointer( xcb_query_pointer(
@ -199,23 +200,23 @@ NzVector2i NzEventImpl::GetMousePosition()
if (error) if (error)
{ {
NazaraError("Failed to query pointer"); NazaraError("Failed to query pointer");
return NzVector2i(-1, -1); return Vector2i(-1, -1);
} }
return NzVector2i(pointer->root_x, pointer->root_y); return Vector2i(pointer->root_x, pointer->root_y);
} }
NzVector2i NzEventImpl::GetMousePosition(const NzWindow& relativeTo) Vector2i EventImpl::GetMousePosition(const Window& relativeTo)
{ {
NzWindowHandle handle = relativeTo.GetHandle(); WindowHandle handle = relativeTo.GetHandle();
if (handle) if (handle)
{ {
// Open a connection with the X server // Open a connection with the X server
NzScopedXCBConnection connection; ScopedXCBConnection connection;
NzScopedXCB<xcb_generic_error_t> error(nullptr); ScopedXCB<xcb_generic_error_t> error(nullptr);
NzScopedXCB<xcb_query_pointer_reply_t> pointer( ScopedXCB<xcb_query_pointer_reply_t> pointer(
xcb_query_pointer_reply( xcb_query_pointer_reply(
connection, connection,
xcb_query_pointer( xcb_query_pointer(
@ -229,21 +230,21 @@ NzVector2i NzEventImpl::GetMousePosition(const NzWindow& relativeTo)
if (error) if (error)
{ {
NazaraError("Failed to query pointer"); NazaraError("Failed to query pointer");
return NzVector2i(-1, -1); return Vector2i(-1, -1);
} }
return NzVector2i(pointer->win_x, pointer->win_y); return Vector2i(pointer->win_x, pointer->win_y);
} }
else else
{ {
NazaraError("No window handle"); NazaraError("No window handle");
return NzVector2i(-1, -1); return Vector2i(-1, -1);
} }
} }
bool NzEventImpl::IsKeyPressed(NzKeyboard::Key key) bool EventImpl::IsKeyPressed(Keyboard::Key key)
{ {
NzScopedXCBConnection connection; ScopedXCBConnection connection;
xcb_keysym_t keySym = GetKeySym(key); xcb_keysym_t keySym = GetKeySym(key);
@ -254,7 +255,7 @@ bool NzEventImpl::IsKeyPressed(NzKeyboard::Key key)
return false; return false;
} }
NzScopedXCB<xcb_keycode_t> keyCode = xcb_key_symbols_get_keycode(keySymbols, keySym); ScopedXCB<xcb_keycode_t> keyCode = xcb_key_symbols_get_keycode(keySymbols, keySym);
if (!keyCode) if (!keyCode)
{ {
NazaraError("Failed to get key code"); NazaraError("Failed to get key code");
@ -262,10 +263,10 @@ bool NzEventImpl::IsKeyPressed(NzKeyboard::Key key)
} }
X11::XCBKeySymbolsFree(keySymbols); X11::XCBKeySymbolsFree(keySymbols);
NzScopedXCB<xcb_generic_error_t> error(nullptr); ScopedXCB<xcb_generic_error_t> error(nullptr);
// Get the whole keyboard state // Get the whole keyboard state
NzScopedXCB<xcb_query_keymap_reply_t> keymap( ScopedXCB<xcb_query_keymap_reply_t> keymap(
xcb_query_keymap_reply( xcb_query_keymap_reply(
connection, connection,
xcb_query_keymap(connection), xcb_query_keymap(connection),
@ -283,14 +284,14 @@ bool NzEventImpl::IsKeyPressed(NzKeyboard::Key key)
return (keymap->keys[*keyCode.get() / 8] & (1 << (*keyCode.get() % 8))) != 0; return (keymap->keys[*keyCode.get() / 8] & (1 << (*keyCode.get() % 8))) != 0;
} }
bool NzEventImpl::IsMouseButtonPressed(NzMouse::Button button) bool EventImpl::IsMouseButtonPressed(Mouse::Button button)
{ {
NzScopedXCBConnection connection; ScopedXCBConnection connection;
NzScopedXCB<xcb_generic_error_t> error(nullptr); ScopedXCB<xcb_generic_error_t> error(nullptr);
// Get pointer mask // Get pointer mask
NzScopedXCB<xcb_query_pointer_reply_t> pointer( ScopedXCB<xcb_query_pointer_reply_t> pointer(
xcb_query_pointer_reply( xcb_query_pointer_reply(
connection, connection,
xcb_query_pointer( xcb_query_pointer(
@ -311,20 +312,20 @@ bool NzEventImpl::IsMouseButtonPressed(NzMouse::Button button)
switch (button) switch (button)
{ {
case NzMouse::Left: return buttons & XCB_BUTTON_MASK_1; case Mouse::Left: return buttons & XCB_BUTTON_MASK_1;
case NzMouse::Right: return buttons & XCB_BUTTON_MASK_3; case Mouse::Right: return buttons & XCB_BUTTON_MASK_3;
case NzMouse::Middle: return buttons & XCB_BUTTON_MASK_2; case Mouse::Middle: return buttons & XCB_BUTTON_MASK_2;
case NzMouse::XButton1: return false; // not supported by X case Mouse::XButton1: return false; // not supported by X
case NzMouse::XButton2: return false; // not supported by X case Mouse::XButton2: return false; // not supported by X
} }
NazaraError("Mouse button not supported."); NazaraError("Mouse button not supported.");
return false; return false;
} }
void NzEventImpl::SetMousePosition(int x, int y) void EventImpl::SetMousePosition(int x, int y)
{ {
NzScopedXCBConnection connection; ScopedXCBConnection connection;
xcb_window_t root = X11::XCBDefaultRootWindow(connection); xcb_window_t root = X11::XCBDefaultRootWindow(connection);
@ -344,11 +345,11 @@ void NzEventImpl::SetMousePosition(int x, int y)
xcb_flush(connection); xcb_flush(connection);
} }
void NzEventImpl::SetMousePosition(int x, int y, const NzWindow& relativeTo) void EventImpl::SetMousePosition(int x, int y, const Window& relativeTo)
{ {
NzScopedXCBConnection connection; ScopedXCBConnection connection;
NzWindowHandle handle = relativeTo.GetHandle(); WindowHandle handle = relativeTo.GetHandle();
if (handle) if (handle)
{ {
if (!X11::CheckCookie( if (!X11::CheckCookie(
@ -369,3 +370,4 @@ void NzEventImpl::SetMousePosition(int x, int y, const NzWindow& relativeTo)
else else
NazaraError("No window handle"); NazaraError("No window handle");
} }
}

View File

@ -7,21 +7,25 @@
#ifndef NAZARA_INPUTIMPL_HPP #ifndef NAZARA_INPUTIMPL_HPP
#define NAZARA_INPUTIMPL_HPP #define NAZARA_INPUTIMPL_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector2.hpp> #include <Nazara/Math/Vector2.hpp>
#include <Nazara/Utility/Keyboard.hpp> #include <Nazara/Utility/Keyboard.hpp>
#include <Nazara/Utility/Mouse.hpp> #include <Nazara/Utility/Mouse.hpp>
class NzEventImpl namespace Nz
{
class EventImpl
{ {
public: public:
static NzString GetKeyName(NzKeyboard::Key key); static String GetKeyName(Keyboard::Key key);
static NzVector2i GetMousePosition(); static Vector2i GetMousePosition();
static NzVector2i GetMousePosition(const NzWindow& relativeTo); static Vector2i GetMousePosition(const Window& relativeTo);
static bool IsKeyPressed(NzKeyboard::Key key); static bool IsKeyPressed(Keyboard::Key key);
static bool IsMouseButtonPressed(NzMouse::Button button); static bool IsMouseButtonPressed(Mouse::Button button);
static void SetMousePosition(int x, int y); static void SetMousePosition(int x, int y);
static void SetMousePosition(int x, int y, const NzWindow& relativeTo); static void SetMousePosition(int x, int y, const Window& relativeTo);
}; };
}
#endif // NAZARA_INPUTIMPL_HPP #endif // NAZARA_INPUTIMPL_HPP

View File

@ -8,68 +8,70 @@
#include <xcb/xcb_image.h> #include <xcb/xcb_image.h>
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
namespace Nz
{
/*********************************************** /***********************************************
NzScopedXCBConnection ScopedXCBConnection
***********************************************/ ***********************************************/
NzScopedXCBConnection::NzScopedXCBConnection() : ScopedXCBConnection::ScopedXCBConnection() :
m_connection(nullptr) m_connection(nullptr)
{ {
m_connection = X11::OpenConnection(); m_connection = X11::OpenConnection();
} }
NzScopedXCBConnection::~NzScopedXCBConnection() ScopedXCBConnection::~ScopedXCBConnection()
{ {
X11::CloseConnection(m_connection); X11::CloseConnection(m_connection);
} }
NzScopedXCBConnection::operator xcb_connection_t*() const ScopedXCBConnection::operator xcb_connection_t*() const
{ {
return m_connection; return m_connection;
} }
/*********************************************** /***********************************************
NzScopedXCBEWMHConnection ScopedXCBEWMHConnection
***********************************************/ ***********************************************/
NzScopedXCBEWMHConnection::NzScopedXCBEWMHConnection(xcb_connection_t* connection) : ScopedXCBEWMHConnection::ScopedXCBEWMHConnection(xcb_connection_t* connection) :
m_ewmhConnection(nullptr) m_ewmhConnection(nullptr)
{ {
m_ewmhConnection = X11::OpenEWMHConnection(connection); m_ewmhConnection = X11::OpenEWMHConnection(connection);
} }
NzScopedXCBEWMHConnection::~NzScopedXCBEWMHConnection() ScopedXCBEWMHConnection::~ScopedXCBEWMHConnection()
{ {
X11::CloseEWMHConnection(m_ewmhConnection); X11::CloseEWMHConnection(m_ewmhConnection);
} }
xcb_ewmh_connection_t* NzScopedXCBEWMHConnection::operator ->() const xcb_ewmh_connection_t* ScopedXCBEWMHConnection::operator ->() const
{ {
return m_ewmhConnection; return m_ewmhConnection;
} }
NzScopedXCBEWMHConnection::operator xcb_ewmh_connection_t*() const ScopedXCBEWMHConnection::operator xcb_ewmh_connection_t*() const
{ {
return m_ewmhConnection; return m_ewmhConnection;
} }
/*********************************************** /***********************************************
NzXCBGContext XCBGContext
***********************************************/ ***********************************************/
NzXCBGContext::NzXCBGContext(xcb_connection_t* connection) : XCBGContext::XCBGContext(xcb_connection_t* connection) :
m_connection(connection), m_connection(connection),
m_gcontext(XCB_NONE) m_gcontext(XCB_NONE)
{ {
NazaraAssert(connection, "Connection must have been established"); NazaraAssert(connection, "Connection must have been established");
} }
NzXCBGContext::~NzXCBGContext() XCBGContext::~XCBGContext()
{ {
Destroy(); Destroy();
} }
bool NzXCBGContext::Create(xcb_drawable_t drawable, uint32_t value_mask, const uint32_t* value_list) bool XCBGContext::Create(xcb_drawable_t drawable, uint32_t value_mask, const uint32_t* value_list)
{ {
NazaraAssert(m_gcontext == XCB_NONE, "Context must have been destroyed before or just created"); NazaraAssert(m_gcontext == XCB_NONE, "Context must have been destroyed before or just created");
@ -86,7 +88,7 @@ bool NzXCBGContext::Create(xcb_drawable_t drawable, uint32_t value_mask, const u
)); ));
} }
void NzXCBGContext::Destroy() void XCBGContext::Destroy()
{ {
if (m_gcontext == XCB_NONE) if (m_gcontext == XCB_NONE)
return; return;
@ -103,40 +105,40 @@ void NzXCBGContext::Destroy()
m_gcontext = XCB_NONE; m_gcontext = XCB_NONE;
} }
NzXCBGContext::operator xcb_gcontext_t() const XCBGContext::operator xcb_gcontext_t() const
{ {
return m_gcontext; return m_gcontext;
} }
/*********************************************** /***********************************************
NzXCBPixmap XCBPixmap
***********************************************/ ***********************************************/
NzXCBPixmap::NzXCBPixmap() : XCBPixmap::XCBPixmap() :
m_connection(nullptr), m_connection(nullptr),
m_pixmap(XCB_NONE) m_pixmap(XCB_NONE)
{ {
} }
NzXCBPixmap::NzXCBPixmap(xcb_connection_t* connection) : XCBPixmap::XCBPixmap(xcb_connection_t* connection) :
m_connection(connection), m_connection(connection),
m_pixmap(XCB_NONE) m_pixmap(XCB_NONE)
{ {
} }
NzXCBPixmap::~NzXCBPixmap() XCBPixmap::~XCBPixmap()
{ {
Destroy(); Destroy();
} }
void NzXCBPixmap::Connect(xcb_connection_t* connection) void XCBPixmap::Connect(xcb_connection_t* connection)
{ {
NazaraAssert(connection && !m_connection, "Connection must be established"); NazaraAssert(connection && !m_connection, "Connection must be established");
m_connection = connection; m_connection = connection;
} }
bool NzXCBPixmap::Create(uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height) bool XCBPixmap::Create(uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height)
{ {
NazaraAssert(m_pixmap == XCB_NONE, "Pixmap must have been destroyed before or just created"); NazaraAssert(m_pixmap == XCB_NONE, "Pixmap must have been destroyed before or just created");
@ -154,7 +156,7 @@ bool NzXCBPixmap::Create(uint8_t depth, xcb_drawable_t drawable, uint16_t width,
)); ));
} }
bool NzXCBPixmap::CreatePixmapFromBitmapData(xcb_drawable_t drawable, uint8_t* data, uint32_t width, uint32_t height, uint32_t depth, uint32_t fg, uint32_t bg, xcb_gcontext_t* gcp) bool XCBPixmap::CreatePixmapFromBitmapData(xcb_drawable_t drawable, uint8_t* data, uint32_t width, uint32_t height, uint32_t depth, uint32_t fg, uint32_t bg, xcb_gcontext_t* gcp)
{ {
NazaraAssert(m_pixmap == XCB_NONE, "Pixmap must have been destroyed before or just created"); NazaraAssert(m_pixmap == XCB_NONE, "Pixmap must have been destroyed before or just created");
@ -173,7 +175,7 @@ bool NzXCBPixmap::CreatePixmapFromBitmapData(xcb_drawable_t drawable, uint8_t* d
return m_pixmap != XCB_NONE; return m_pixmap != XCB_NONE;
} }
void NzXCBPixmap::Destroy() void XCBPixmap::Destroy()
{ {
if (m_pixmap == XCB_NONE) if (m_pixmap == XCB_NONE)
return; return;
@ -190,7 +192,8 @@ void NzXCBPixmap::Destroy()
m_pixmap = XCB_NONE; m_pixmap = XCB_NONE;
} }
NzXCBPixmap::operator xcb_pixmap_t() const XCBPixmap::operator xcb_pixmap_t() const
{ {
return m_pixmap; return m_pixmap;
} }
}

View File

@ -7,13 +7,17 @@
#ifndef NAZARA_SCOPEDXCB_HPP #ifndef NAZARA_SCOPEDXCB_HPP
#define NAZARA_SCOPEDXCB_HPP #define NAZARA_SCOPEDXCB_HPP
#include <Nazara/Prerequesites.hpp>
#include <xcb/xcb.h>
#include <xcb/xcb_ewmh.h> #include <xcb/xcb_ewmh.h>
class NzScopedXCBConnection namespace Nz
{
class ScopedXCBConnection
{ {
public: public:
NzScopedXCBConnection(); ScopedXCBConnection();
~NzScopedXCBConnection(); ~ScopedXCBConnection();
operator xcb_connection_t*() const; operator xcb_connection_t*() const;
@ -21,11 +25,11 @@ class NzScopedXCBConnection
xcb_connection_t* m_connection; xcb_connection_t* m_connection;
}; };
class NzScopedXCBEWMHConnection class ScopedXCBEWMHConnection
{ {
public: public:
NzScopedXCBEWMHConnection(xcb_connection_t* connection); ScopedXCBEWMHConnection(xcb_connection_t* connection);
~NzScopedXCBEWMHConnection(); ~ScopedXCBEWMHConnection();
xcb_ewmh_connection_t* operator ->() const; xcb_ewmh_connection_t* operator ->() const;
@ -36,11 +40,11 @@ class NzScopedXCBEWMHConnection
}; };
template <typename T> template <typename T>
class NzScopedXCB class ScopedXCB
{ {
public: public:
NzScopedXCB(T* pointer); ScopedXCB(T* pointer);
~NzScopedXCB(); ~ScopedXCB();
T* operator ->() const; T* operator ->() const;
T** operator &(); T** operator &();
@ -53,11 +57,11 @@ class NzScopedXCB
T* m_pointer; T* m_pointer;
}; };
class NzXCBGContext class XCBGContext
{ {
public: public:
NzXCBGContext(xcb_connection_t* connection); XCBGContext(xcb_connection_t* connection);
~NzXCBGContext(); ~XCBGContext();
bool Create(xcb_drawable_t drawable, uint32_t value_mask, const uint32_t* value_list); bool Create(xcb_drawable_t drawable, uint32_t value_mask, const uint32_t* value_list);
@ -70,12 +74,12 @@ class NzXCBGContext
xcb_gcontext_t m_gcontext; xcb_gcontext_t m_gcontext;
}; };
class NzXCBPixmap class XCBPixmap
{ {
public: public:
NzXCBPixmap(); XCBPixmap();
NzXCBPixmap(xcb_connection_t* connection); XCBPixmap(xcb_connection_t* connection);
~NzXCBPixmap(); ~XCBPixmap();
void Connect(xcb_connection_t* connection); void Connect(xcb_connection_t* connection);
bool Create(uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height); bool Create(uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height);
@ -89,6 +93,7 @@ class NzXCBPixmap
xcb_connection_t* m_connection; xcb_connection_t* m_connection;
xcb_pixmap_t m_pixmap; xcb_pixmap_t m_pixmap;
}; };
}
#include <Nazara/Utility/X11/ScopedXCB.inl> #include <Nazara/Utility/X11/ScopedXCB.inl>

View File

@ -10,16 +10,18 @@
#include <algorithm> #include <algorithm>
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
NzVideoMode NzVideoModeImpl::GetDesktopMode() namespace Nz
{ {
NzVideoMode desktopMode; VideoMode VideoModeImpl::GetDesktopMode()
{
VideoMode desktopMode;
NzScopedXCBConnection connection; ScopedXCBConnection connection;
// Retrieve the default screen // Retrieve the default screen
xcb_screen_t* screen = X11::XCBDefaultScreen(connection); xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
NzScopedXCB<xcb_generic_error_t> error(nullptr); ScopedXCB<xcb_generic_error_t> error(nullptr);
// Check if the RandR extension is present // Check if the RandR extension is present
const xcb_query_extension_reply_t* randrExt = xcb_get_extension_data(connection, &xcb_randr_id); const xcb_query_extension_reply_t* randrExt = xcb_get_extension_data(connection, &xcb_randr_id);
@ -32,7 +34,7 @@ NzVideoMode NzVideoModeImpl::GetDesktopMode()
} }
// Load RandR and check its version // Load RandR and check its version
NzScopedXCB<xcb_randr_query_version_reply_t> randrVersion(xcb_randr_query_version_reply( ScopedXCB<xcb_randr_query_version_reply_t> randrVersion(xcb_randr_query_version_reply(
connection, connection,
xcb_randr_query_version( xcb_randr_query_version(
connection, connection,
@ -49,7 +51,7 @@ NzVideoMode NzVideoModeImpl::GetDesktopMode()
} }
// Get the current configuration // Get the current configuration
NzScopedXCB<xcb_randr_get_screen_info_reply_t> config(xcb_randr_get_screen_info_reply( ScopedXCB<xcb_randr_get_screen_info_reply_t> config(xcb_randr_get_screen_info_reply(
connection, connection,
xcb_randr_get_screen_info( xcb_randr_get_screen_info(
connection, connection,
@ -73,7 +75,7 @@ NzVideoMode NzVideoModeImpl::GetDesktopMode()
xcb_randr_screen_size_t* sizes = xcb_randr_get_screen_info_sizes(config.get()); xcb_randr_screen_size_t* sizes = xcb_randr_get_screen_info_sizes(config.get());
if (sizes && (nbSizes > 0)) if (sizes && (nbSizes > 0))
{ {
desktopMode = NzVideoMode(sizes[currentMode].width, sizes[currentMode].height, screen->root_depth); desktopMode = VideoMode(sizes[currentMode].width, sizes[currentMode].height, screen->root_depth);
if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 || if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 ||
config->rotation == XCB_RANDR_ROTATION_ROTATE_270) config->rotation == XCB_RANDR_ROTATION_ROTATE_270)
@ -87,14 +89,14 @@ NzVideoMode NzVideoModeImpl::GetDesktopMode()
return desktopMode; return desktopMode;
} }
void NzVideoModeImpl::GetFullscreenModes(std::vector<NzVideoMode>& modes) void VideoModeImpl::GetFullscreenModes(std::vector<VideoMode>& modes)
{ {
NzScopedXCBConnection connection; ScopedXCBConnection connection;
// Retrieve the default screen // Retrieve the default screen
xcb_screen_t* screen = X11::XCBDefaultScreen(connection); xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
NzScopedXCB<xcb_generic_error_t> error(nullptr); ScopedXCB<xcb_generic_error_t> error(nullptr);
const xcb_query_extension_reply_t* randrExt = xcb_get_extension_data(connection, &xcb_randr_id); const xcb_query_extension_reply_t* randrExt = xcb_get_extension_data(connection, &xcb_randr_id);
@ -106,7 +108,7 @@ void NzVideoModeImpl::GetFullscreenModes(std::vector<NzVideoMode>& modes)
} }
// Load RandR and check its version // Load RandR and check its version
NzScopedXCB<xcb_randr_query_version_reply_t> randrVersion(xcb_randr_query_version_reply( ScopedXCB<xcb_randr_query_version_reply_t> randrVersion(xcb_randr_query_version_reply(
connection, connection,
xcb_randr_query_version( xcb_randr_query_version(
connection, connection,
@ -123,7 +125,7 @@ void NzVideoModeImpl::GetFullscreenModes(std::vector<NzVideoMode>& modes)
} }
// Get the current configuration // Get the current configuration
NzScopedXCB<xcb_randr_get_screen_info_reply_t> config(xcb_randr_get_screen_info_reply( ScopedXCB<xcb_randr_get_screen_info_reply_t> config(xcb_randr_get_screen_info_reply(
connection, connection,
xcb_randr_get_screen_info( xcb_randr_get_screen_info(
connection, connection,
@ -151,7 +153,7 @@ void NzVideoModeImpl::GetFullscreenModes(std::vector<NzVideoMode>& modes)
for (int j = 0; j < config->nSizes; ++j) for (int j = 0; j < config->nSizes; ++j)
{ {
// Convert to VideoMode // Convert to VideoMode
NzVideoMode mode(sizes[j].width, sizes[j].height, iter.data->depth); VideoMode mode(sizes[j].width, sizes[j].height, iter.data->depth);
if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 || if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 ||
config->rotation == XCB_RANDR_ROTATION_ROTATE_270) config->rotation == XCB_RANDR_ROTATION_ROTATE_270)
@ -164,3 +166,4 @@ void NzVideoModeImpl::GetFullscreenModes(std::vector<NzVideoMode>& modes)
} }
} }
} }
}

View File

@ -7,13 +7,17 @@
#ifndef NAZARA_VIDEOMODEIMPL_HPP #ifndef NAZARA_VIDEOMODEIMPL_HPP
#define NAZARA_VIDEOMODEIMPL_HPP #define NAZARA_VIDEOMODEIMPL_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/VideoMode.hpp> #include <Nazara/Utility/VideoMode.hpp>
class NzVideoModeImpl namespace Nz
{
class VideoModeImpl
{ {
public: public:
static NzVideoMode GetDesktopMode(); static VideoMode GetDesktopMode();
static void GetFullscreenModes(std::vector<NzVideoMode>& modes); static void GetFullscreenModes(std::vector<VideoMode>& modes);
}; };
}
#endif // NNAZARA_VIDEOMODEIMPL_HPP #endif // NNAZARA_VIDEOMODEIMPL_HPP

File diff suppressed because it is too large Load Diff

View File

@ -9,44 +9,48 @@
#ifndef NAZARA_WINDOWIMPL_HPP #ifndef NAZARA_WINDOWIMPL_HPP
#define NAZARA_WINDOWIMPL_HPP #define NAZARA_WINDOWIMPL_HPP
#include <Nazara/Core/NonCopyable.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Thread.hpp> #include <Nazara/Core/Thread.hpp>
#include <Nazara/Math/Vector2.hpp> #include <Nazara/Math/Vector2.hpp>
#include <Nazara/Utility/Enums.hpp> #include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Keyboard.hpp> #include <Nazara/Utility/Keyboard.hpp>
#include <Nazara/Utility/X11/Display.hpp>
#include <xcb/randr.h> #include <xcb/randr.h>
#include <xcb/xcb_icccm.h> #include <xcb/xcb_icccm.h>
#include <Nazara/Utility/X11/Display.hpp>
namespace Nz
{
#if NAZARA_UTILITY_THREADED_WINDOW #if NAZARA_UTILITY_THREADED_WINDOW
class NzConditionVariable; class ConditionVariable;
class NzMutex; class Mutex;
#endif #endif
class NzCursor; class Cursor;
class NzIcon; class Icon;
class NzVideoMode; class VideoMode;
class NzWindow; class Window;
class NzWindowImpl : NzNonCopyable class WindowImpl
{ {
public: public:
NzWindowImpl(NzWindow* parent); WindowImpl(Window* parent);
~NzWindowImpl(); WindowImpl(const WindowImpl&) = delete;
WindowImpl(WindowImpl&&) = delete; ///TODO?
~WindowImpl();
bool Create(const NzVideoMode& mode, const NzString& title, nzUInt32 style); bool Create(const VideoMode& mode, const String& title, UInt32 style);
bool Create(NzWindowHandle handle); bool Create(WindowHandle handle);
void Destroy(); void Destroy();
void EnableKeyRepeat(bool enable); void EnableKeyRepeat(bool enable);
void EnableSmoothScrolling(bool enable); void EnableSmoothScrolling(bool enable);
NzWindowHandle GetHandle() const; WindowHandle GetHandle() const;
unsigned int GetHeight() const; unsigned int GetHeight() const;
NzVector2i GetPosition() const; Vector2i GetPosition() const;
NzVector2ui GetSize() const; Vector2ui GetSize() const;
nzUInt32 GetStyle() const; UInt32 GetStyle() const;
NzString GetTitle() const; String GetTitle() const;
unsigned int GetWidth() const; unsigned int GetWidth() const;
bool HasFocus() const; bool HasFocus() const;
@ -58,19 +62,22 @@ class NzWindowImpl : NzNonCopyable
void ProcessEvents(bool block); void ProcessEvents(bool block);
void SetCursor(nzWindowCursor cursor); void SetCursor(WindowCursor cursor);
void SetCursor(const NzCursor& cursor); void SetCursor(const Cursor& cursor);
void SetEventListener(bool listener); void SetEventListener(bool listener);
void SetFocus(); void SetFocus();
void SetIcon(const NzIcon& icon); void SetIcon(const Icon& icon);
void SetMaximumSize(int width, int height); void SetMaximumSize(int width, int height);
void SetMinimumSize(int width, int height); void SetMinimumSize(int width, int height);
void SetPosition(int x, int y); void SetPosition(int x, int y);
void SetSize(unsigned int width, unsigned int height); void SetSize(unsigned int width, unsigned int height);
void SetStayOnTop(bool stayOnTop); void SetStayOnTop(bool stayOnTop);
void SetTitle(const NzString& title); void SetTitle(const String& title);
void SetVisible(bool visible); void SetVisible(bool visible);
WindowImpl& operator=(const WindowImpl&) = delete;
WindowImpl& operator=(WindowImpl&&) = delete; ///TODO?
static bool Initialize(); static bool Initialize();
static void Uninitialize(); static void Uninitialize();
@ -78,8 +85,8 @@ class NzWindowImpl : NzNonCopyable
void CleanUp(); void CleanUp();
xcb_keysym_t ConvertKeyCodeToKeySym(xcb_keycode_t keycode, uint16_t state); xcb_keysym_t ConvertKeyCodeToKeySym(xcb_keycode_t keycode, uint16_t state);
NzKeyboard::Key ConvertVirtualKey(xcb_keysym_t symbol); Keyboard::Key ConvertVirtualKey(xcb_keysym_t symbol);
const char* ConvertWindowCursorToXName(nzWindowCursor cursor); const char* ConvertWindowCursorToXName(WindowCursor cursor);
void CommonInitialize(); void CommonInitialize();
void ProcessEvent(xcb_generic_event_t* windowEvent); void ProcessEvent(xcb_generic_event_t* windowEvent);
@ -88,25 +95,25 @@ class NzWindowImpl : NzNonCopyable
void SetCursor(xcb_cursor_t cursor); void SetCursor(xcb_cursor_t cursor);
void SetMotifHints(); void SetMotifHints();
void SetVideoMode(const NzVideoMode& mode); void SetVideoMode(const VideoMode& mode);
void SwitchToFullscreen(); void SwitchToFullscreen();
bool UpdateNormalHints(); bool UpdateNormalHints();
void UpdateEventQueue(xcb_generic_event_t* event); void UpdateEventQueue(xcb_generic_event_t* event);
#if NAZARA_UTILITY_THREADED_WINDOW #if NAZARA_UTILITY_THREADED_WINDOW
static void WindowThread(NzWindowImpl* window, NzMutex* mutex, NzConditionVariable* condition); static void WindowThread(WindowImpl* window, Mutex* mutex, ConditionVariable* condition);
#endif #endif
xcb_window_t m_window; xcb_window_t m_window;
xcb_screen_t* m_screen; xcb_screen_t* m_screen;
xcb_randr_get_screen_info_reply_t m_oldVideoMode; xcb_randr_get_screen_info_reply_t m_oldVideoMode;
xcb_size_hints_t m_size_hints; xcb_size_hints_t m_size_hints;
nzUInt32 m_style; UInt32 m_style;
#if NAZARA_UTILITY_THREADED_WINDOW #if NAZARA_UTILITY_THREADED_WINDOW
NzThread m_thread; Thread m_thread;
#endif #endif
NzWindow* m_parent; Window* m_parent;
bool m_eventListener; bool m_eventListener;
bool m_ownsWindow; bool m_ownsWindow;
bool m_smoothScrolling; bool m_smoothScrolling;
@ -114,7 +121,7 @@ class NzWindowImpl : NzNonCopyable
bool m_threadActive; bool m_threadActive;
#endif #endif
short m_scrolling; short m_scrolling;
NzVector2i m_mousePos; Vector2i m_mousePos;
bool m_keyRepeat; bool m_keyRepeat;
struct struct
@ -123,4 +130,6 @@ class NzWindowImpl : NzNonCopyable
xcb_generic_event_t* next = nullptr; xcb_generic_event_t* next = nullptr;
} m_eventQueue; } m_eventQueue;
}; };
}
#endif // NAZARA_WINDOWIMPL_HPP #endif // NAZARA_WINDOWIMPL_HPP