mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-27 13:49:50 +02:00
Update to 20180730 release.
byuu says: These WIPs-within-WIPs are getting more and more broken ... this isn't going the way I wanted. But ... this time around, I've revamped the entire ruby API again, to solve a bunch of tough problems that have always made using ruby really clunky. But there are *so many* ruby drivers that it's going to take a long time to work through them all. This WIP is only going to run bsnes, and only on FreeBSD, and only with some drivers. hiro's Application::initialize() now calls hiro::initialize(), which you define inside of your hiro apps. This lets you call Application::setName(...) before anything else in hiro runs. This is essential on Xorg to set program icons, for instance. With the ruby rewrite and the change to hiro, I can get away from the need to make everything in bsnes/higan pointers to objects, and can now just declare them as regular objects.
This commit is contained in:
@@ -21,46 +21,36 @@
|
||||
#error "ruby::OpenGL2: unsupported platform"
|
||||
#endif
|
||||
|
||||
struct VideoGLX2 : Video {
|
||||
VideoGLX2() { initialize(); }
|
||||
struct VideoGLX2 : VideoDriver {
|
||||
VideoGLX2& self;
|
||||
|
||||
VideoGLX2(Video& super) : VideoDriver(super), self(*this) {}
|
||||
~VideoGLX2() { terminate(); }
|
||||
|
||||
auto driver() -> string override { return "OpenGL2"; }
|
||||
auto create() -> bool {
|
||||
super.setFormat("RGB24");
|
||||
return initialize();
|
||||
}
|
||||
|
||||
auto driverName() -> string override { return "OpenGL2"; }
|
||||
auto ready() -> bool override { return _ready; }
|
||||
|
||||
auto hasContext() -> bool override { return true; }
|
||||
auto hasBlocking() -> bool override { return true; }
|
||||
auto hasFlush() -> bool override { return true; }
|
||||
auto hasFormat() -> bool override { return true; }
|
||||
auto hasFormats() -> vector<string> override { return {"RGB24"}; }
|
||||
auto hasSmooth() -> bool override { return true; }
|
||||
|
||||
auto availableFormats() -> vector<string> override {
|
||||
return {"RGB24", "RGB30"};
|
||||
}
|
||||
|
||||
auto setContext(uintptr context) -> bool override {
|
||||
if(context == Video::context()) return true;
|
||||
if(!Video::setContext(context)) return false;
|
||||
return initialize();
|
||||
}
|
||||
|
||||
auto setBlocking(bool blocking) -> bool override {
|
||||
if(blocking == Video::blocking()) return true;
|
||||
if(!Video::setBlocking(blocking)) return false;
|
||||
if(glXSwapInterval) glXSwapInterval(blocking);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto setFlush(bool flush) -> bool override {
|
||||
if(flush == Video::flush()) return true;
|
||||
if(!Video::setFlush(flush)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto setFormat(string format) -> bool override {
|
||||
if(format == Video::format()) return true;
|
||||
if(!Video::setFormat(format)) return false;
|
||||
|
||||
if(format == "RGB24") {
|
||||
_glFormat = GL_UNSIGNED_INT_8_8_8_8_REV;
|
||||
return initialize();
|
||||
@@ -74,12 +64,6 @@ struct VideoGLX2 : Video {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto setSmooth(bool smooth) -> bool override {
|
||||
if(smooth == Video::smooth()) return true;
|
||||
if(!Video::setSmooth(smooth)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto clear() -> void override {
|
||||
if(!ready()) return;
|
||||
memory::fill<uint32_t>(_glBuffer, _glWidth * _glHeight);
|
||||
@@ -90,21 +74,17 @@ struct VideoGLX2 : Video {
|
||||
}
|
||||
|
||||
auto acquire(uint32_t*& data, uint& pitch, uint width, uint height) -> bool override {
|
||||
if(!ready()) return false;
|
||||
if(width != _width || height != _height) resize(width, height);
|
||||
pitch = _glWidth * sizeof(uint32_t);
|
||||
return data = _glBuffer;
|
||||
}
|
||||
|
||||
auto release() -> void override {
|
||||
if(!ready()) return;
|
||||
}
|
||||
|
||||
auto output() -> void override {
|
||||
if(!ready()) return;
|
||||
|
||||
XWindowAttributes parent, child;
|
||||
XGetWindowAttributes(_display, (Window)_context, &parent);
|
||||
XGetWindowAttributes(_display, (Window)self.context, &parent);
|
||||
XGetWindowAttributes(_display, _window, &child);
|
||||
if(child.width != parent.width || child.height != parent.height) {
|
||||
XResizeWindow(_display, _window, parent.width, parent.height);
|
||||
@@ -112,8 +92,8 @@ struct VideoGLX2 : Video {
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _smooth ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _smooth ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, self.smooth ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, self.smooth ? GL_LINEAR : GL_NEAREST);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
@@ -139,7 +119,7 @@ struct VideoGLX2 : Video {
|
||||
glFlush();
|
||||
|
||||
if(_isDoubleBuffered) glXSwapBuffers(_display, _glXWindow);
|
||||
if(flush()) glFinish();
|
||||
if(self.flush) glFinish();
|
||||
}
|
||||
|
||||
auto poll() -> void override {
|
||||
@@ -149,7 +129,7 @@ struct VideoGLX2 : Video {
|
||||
if(event.type == Expose) {
|
||||
XWindowAttributes attributes;
|
||||
XGetWindowAttributes(_display, _window, &attributes);
|
||||
doUpdate(attributes.width, attributes.height);
|
||||
super.doUpdate(attributes.width, attributes.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,9 +137,9 @@ struct VideoGLX2 : Video {
|
||||
private:
|
||||
auto initialize() -> bool {
|
||||
terminate();
|
||||
if(!_context) return false;
|
||||
if(!self.context) return false;
|
||||
|
||||
_display = XOpenDisplay(0);
|
||||
_display = XOpenDisplay(nullptr);
|
||||
_screen = DefaultScreen(_display);
|
||||
|
||||
int versionMajor = 0, versionMinor = 0;
|
||||
@@ -167,11 +147,11 @@ private:
|
||||
if(versionMajor < 1 || (versionMajor == 1 && versionMinor < 2)) return false;
|
||||
|
||||
XWindowAttributes windowAttributes;
|
||||
XGetWindowAttributes(_display, (Window)_context, &windowAttributes);
|
||||
XGetWindowAttributes(_display, (Window)self.context, &windowAttributes);
|
||||
|
||||
int redDepth = Video::format() == "RGB30" ? 10 : 8;
|
||||
int greenDepth = Video::format() == "RGB30" ? 10 : 8;
|
||||
int blueDepth = Video::format() == "RGB30" ? 10 : 8;
|
||||
int redDepth = self.format == "RGB30" ? 10 : 8;
|
||||
int greenDepth = self.format == "RGB30" ? 10 : 8;
|
||||
int blueDepth = self.format == "RGB30" ? 10 : 8;
|
||||
|
||||
int attributeList[] = {
|
||||
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
|
||||
@@ -192,7 +172,7 @@ private:
|
||||
XSetWindowAttributes attributes = {};
|
||||
attributes.colormap = _colormap;
|
||||
attributes.border_pixel = 0;
|
||||
_window = XCreateWindow(_display, (Window)_context, 0, 0, windowAttributes.width, windowAttributes.height,
|
||||
_window = XCreateWindow(_display, (Window)self.context, 0, 0, windowAttributes.width, windowAttributes.height,
|
||||
0, vi->depth, InputOutput, vi->visual, CWColormap | CWBorderPixel, &attributes);
|
||||
XSelectInput(_display, _window, ExposureMask);
|
||||
XSetWindowBackground(_display, _window, 0);
|
||||
@@ -210,7 +190,7 @@ private:
|
||||
if(!glXSwapInterval) glXSwapInterval = (int (*)(int))glGetProcAddress("glXSwapIntervalMESA");
|
||||
if(!glXSwapInterval) glXSwapInterval = (int (*)(int))glGetProcAddress("glXSwapIntervalSGI");
|
||||
|
||||
if(glXSwapInterval) glXSwapInterval(_blocking);
|
||||
if(glXSwapInterval) glXSwapInterval(self.blocking);
|
||||
|
||||
int value = 0;
|
||||
glXGetConfig(_display, vi, GLX_DOUBLEBUFFER, &value);
|
||||
|
257
ruby/video/video.cpp
Normal file
257
ruby/video/video.cpp
Normal file
@@ -0,0 +1,257 @@
|
||||
#if defined(VIDEO_CGL)
|
||||
#include <ruby/video/cgl.cpp>
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_DIRECT3D)
|
||||
#include <ruby/video/direct3d.cpp>
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_DIRECTDRAW)
|
||||
#include <ruby/video/directdraw.cpp>
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_GDI)
|
||||
#include <ruby/video/gdi.cpp>
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_GLX)
|
||||
#include <ruby/video/glx.cpp>
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_GLX2)
|
||||
#include <ruby/video/glx2.cpp>
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_WGL)
|
||||
#include <ruby/video/wgl.cpp>
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_XSHM)
|
||||
#include <ruby/video/xshm.cpp>
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_XVIDEO)
|
||||
#include <ruby/video/xvideo.cpp>
|
||||
#endif
|
||||
|
||||
namespace ruby {
|
||||
|
||||
auto Video::setExclusive(bool exclusive) -> bool {
|
||||
if(driver->exclusive == exclusive) return true;
|
||||
if(!driver->hasExclusive()) return false;
|
||||
if(!driver->setExclusive(driver->exclusive = exclusive)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto Video::setContext(uintptr context) -> bool {
|
||||
if(driver->context == context) return true;
|
||||
if(!driver->hasContext()) return false;
|
||||
if(!driver->setContext(driver->context = context)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto Video::setBlocking(bool blocking) -> bool {
|
||||
if(driver->blocking == blocking) return true;
|
||||
if(!driver->hasBlocking()) return false;
|
||||
if(!driver->setBlocking(driver->blocking = blocking)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto Video::setFlush(bool flush) -> bool {
|
||||
if(driver->flush == flush) return true;
|
||||
if(!driver->hasFlush()) return false;
|
||||
if(!driver->setFlush(driver->flush = flush)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto Video::setFormat(string format) -> bool {
|
||||
if(driver->format == format) return true;
|
||||
if(!driver->hasFormat(format)) return false;
|
||||
if(!driver->setFormat(driver->format = format)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto Video::setSmooth(bool smooth) -> bool {
|
||||
if(driver->smooth == smooth) return true;
|
||||
if(!driver->hasSmooth()) return false;
|
||||
if(!driver->setSmooth(driver->smooth = smooth)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto Video::setShader(string shader) -> bool {
|
||||
if(driver->shader == shader) return true;
|
||||
if(!driver->hasShader()) return false;
|
||||
if(!driver->setShader(driver->shader = shader)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
auto Video::clear() -> void {
|
||||
return driver->clear();
|
||||
}
|
||||
|
||||
auto Video::acquire(uint32_t*& data, uint& pitch, uint width, uint height) -> bool {
|
||||
return driver->acquire(data, pitch, width, height);
|
||||
}
|
||||
|
||||
auto Video::release() -> void {
|
||||
return driver->release();
|
||||
}
|
||||
|
||||
auto Video::output() -> void {
|
||||
return driver->output();
|
||||
}
|
||||
|
||||
auto Video::poll() -> void {
|
||||
return driver->poll();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
auto Video::onUpdate(const function<void (uint, uint)>& onUpdate) -> void {
|
||||
update = onUpdate;
|
||||
}
|
||||
|
||||
auto Video::doUpdate(uint width, uint height) -> void {
|
||||
if(update) return update(width, height);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
auto Video::create(string driver) -> bool {
|
||||
reset();
|
||||
if(!driver) driver = optimalDriver();
|
||||
|
||||
#if defined(VIDEO_CGL)
|
||||
if(driver == "OpenGL") self.driver = new VideoCGL(*this);
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_DIRECT3D)
|
||||
if(driver == "Direct3D") self.driver = new VideoDirect3D(*this);
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_DIRECTDRAW)
|
||||
if(driver == "DirectDraw") self.driver = new VideoDirectDraw(*this);
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_GDI)
|
||||
if(driver == "GDI") self.driver = new VideoGDI(*this);
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_GLX)
|
||||
if(driver == "OpenGL") self.driver = new VideoGLX(*this);
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_GLX2)
|
||||
if(driver == "OpenGL2") self.driver = new VideoGLX2(*this);
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_WGL)
|
||||
if(driver == "OpenGL") self.driver = new VideoWGL(*this);
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_XSHM)
|
||||
if(driver == "XShm") self.driver = new VideoXShm(*this);
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_XVIDEO)
|
||||
if(driver == "XVideo") self.driver = new VideoXVideo(*this);
|
||||
#endif
|
||||
|
||||
if(!self.driver) self.driver = new VideoDriver(*this);
|
||||
|
||||
return self.driver->create();
|
||||
}
|
||||
|
||||
auto Video::hasDrivers() -> vector<string> {
|
||||
return {
|
||||
|
||||
#if defined(VIDEO_WGL)
|
||||
"OpenGL",
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_DIRECT3D)
|
||||
"Direct3D",
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_DIRECTDRAW)
|
||||
"DirectDraw",
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_GDI)
|
||||
"GDI",
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_CGL)
|
||||
"OpenGL",
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_GLX)
|
||||
"OpenGL",
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_GLX2)
|
||||
"OpenGL2",
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_XVIDEO)
|
||||
"XVideo",
|
||||
#endif
|
||||
|
||||
#if defined(VIDEO_XSHM)
|
||||
"XShm",
|
||||
#endif
|
||||
|
||||
"None"};
|
||||
}
|
||||
|
||||
auto Video::optimalDriver() -> string {
|
||||
#if defined(VIDEO_WGL)
|
||||
return "OpenGL";
|
||||
#elif defined(VIDEO_DIRECT3D)
|
||||
return "Direct3D";
|
||||
#elif defined(VIDEO_DIRECTDRAW)
|
||||
return "DirectDraw";
|
||||
#elif defined(VIDEO_GDI)
|
||||
return "GDI";
|
||||
#elif defined(VIDEO_CGL)
|
||||
return "OpenGL";
|
||||
#elif defined(VIDEO_GLX)
|
||||
return "OpenGL";
|
||||
#elif defined(VIDEO_GLX2)
|
||||
return "OpenGL2";
|
||||
#elif defined(VIDEO_XVIDEO)
|
||||
return "XVideo";
|
||||
#elif defined(VIDEO_XSHM)
|
||||
return "XShm";
|
||||
#else
|
||||
return "None";
|
||||
#endif
|
||||
}
|
||||
|
||||
auto Video::safestDriver() -> string {
|
||||
#if defined(VIDEO_DIRECT3D)
|
||||
return "Direct3D";
|
||||
#elif defined(VIDEO_WGL)
|
||||
return "OpenGL";
|
||||
#elif defined(VIDEO_DIRECTDRAW)
|
||||
return "DirectDraw";
|
||||
#elif defined(VIDEO_GDI)
|
||||
return "GDI";
|
||||
#elif defined(VIDEO_CGL)
|
||||
return "OpenGL";
|
||||
#elif defined(VIDEO_XSHM)
|
||||
return "XShm";
|
||||
#elif defined(VIDEO_XVIDEO)
|
||||
return "XVideo";
|
||||
#elif defined(VIDEO_GLX2)
|
||||
return "OpenGL2";
|
||||
#elif defined(VIDEO_GLX)
|
||||
return "OpenGL";
|
||||
#else
|
||||
return "None";
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
100
ruby/video/video.hpp
Normal file
100
ruby/video/video.hpp
Normal file
@@ -0,0 +1,100 @@
|
||||
struct Video;
|
||||
|
||||
struct VideoDriver {
|
||||
VideoDriver(Video& super) : super(super) {}
|
||||
virtual ~VideoDriver() = default;
|
||||
|
||||
virtual auto create() -> bool { return true; }
|
||||
virtual auto driverName() -> string { return "None"; }
|
||||
virtual auto ready() -> bool { return true; }
|
||||
|
||||
virtual auto hasExclusive() -> bool { return false; }
|
||||
virtual auto hasContext() -> bool { return false; }
|
||||
virtual auto hasBlocking() -> bool { return false; }
|
||||
virtual auto hasFlush() -> bool { return false; }
|
||||
virtual auto hasFormats() -> vector<string> { return {"RGB24"}; }
|
||||
virtual auto hasSmooth() -> bool { return false; }
|
||||
virtual auto hasShader() -> bool { return false; }
|
||||
|
||||
auto hasFormat(string format) -> bool { return (bool)hasFormats().find(format); }
|
||||
|
||||
virtual auto setExclusive(bool exclusive) -> bool { return true; }
|
||||
virtual auto setContext(uintptr context) -> bool { return true; }
|
||||
virtual auto setBlocking(bool blocking) -> bool { return true; }
|
||||
virtual auto setFlush(bool flush) -> bool { return true; }
|
||||
virtual auto setFormat(string format) -> bool { return true; }
|
||||
virtual auto setSmooth(bool smooth) -> bool { return true; }
|
||||
virtual auto setShader(string shader) -> bool { return true; }
|
||||
|
||||
virtual auto clear() -> void {}
|
||||
virtual auto acquire(uint32_t*& data, uint& pitch, uint width, uint height) -> bool { return false; }
|
||||
virtual auto release() -> void {}
|
||||
virtual auto output() -> void {}
|
||||
virtual auto poll() -> void {}
|
||||
|
||||
protected:
|
||||
Video& super;
|
||||
friend class Video;
|
||||
|
||||
bool exclusive = false;
|
||||
uintptr context = 0;
|
||||
bool blocking = false;
|
||||
bool flush = false;
|
||||
string format = "RGB24";
|
||||
bool smooth = false;
|
||||
string shader = "";
|
||||
};
|
||||
|
||||
struct Video {
|
||||
static auto hasDrivers() -> vector<string>;
|
||||
static auto hasDriver(string driver) -> bool { return (bool)hasDrivers().find(driver); }
|
||||
static auto optimalDriver() -> string;
|
||||
static auto safestDriver() -> string;
|
||||
|
||||
Video() : self(*this) {}
|
||||
explicit operator bool() const { return (bool)driver; }
|
||||
auto reset() -> void { driver.reset(); }
|
||||
auto create(string driver = "") -> bool;
|
||||
auto driverName() -> string { return driver->driverName(); }
|
||||
auto ready() -> bool { return driver->ready(); }
|
||||
|
||||
auto hasExclusive() -> bool { return driver->hasExclusive(); }
|
||||
auto hasContext() -> bool { return driver->hasContext(); }
|
||||
auto hasBlocking() -> bool { return driver->hasBlocking(); }
|
||||
auto hasFlush() -> bool { return driver->hasFlush(); }
|
||||
auto hasFormats() -> vector<string> { return driver->hasFormats(); }
|
||||
auto hasSmooth() -> bool { return driver->hasSmooth(); }
|
||||
auto hasShader() -> bool { return driver->hasShader(); }
|
||||
|
||||
auto hasFormat(string format) -> bool { return driver->hasFormat(format); }
|
||||
|
||||
auto exclusive() -> bool { return driver->exclusive; }
|
||||
auto context() -> uintptr { return driver->context; }
|
||||
auto blocking() -> bool { return driver->blocking; }
|
||||
auto flush() -> bool { return driver->flush; }
|
||||
auto format() -> string { return driver->format; }
|
||||
auto smooth() -> bool { return driver->smooth; }
|
||||
auto shader() -> string { return driver->shader; }
|
||||
|
||||
auto setExclusive(bool exclusive) -> bool;
|
||||
auto setContext(uintptr context) -> bool;
|
||||
auto setBlocking(bool blocking) -> bool;
|
||||
auto setFlush(bool flush) -> bool;
|
||||
auto setFormat(string format) -> bool;
|
||||
auto setSmooth(bool smooth) -> bool;
|
||||
auto setShader(string shader) -> bool;
|
||||
|
||||
auto clear() -> void;
|
||||
auto acquire(uint32_t*& data, uint& pitch, uint width, uint height) -> bool;
|
||||
auto release() -> void;
|
||||
auto output() -> void;
|
||||
auto poll() -> void;
|
||||
|
||||
auto onUpdate(const function<void (uint, uint)>&) -> void;
|
||||
auto doUpdate(uint width, uint height) -> void;
|
||||
|
||||
protected:
|
||||
Video& self;
|
||||
unique_pointer<VideoDriver> driver;
|
||||
function<void (uint, uint)> update;
|
||||
};
|
@@ -8,38 +8,28 @@
|
||||
#include <sys/shm.h>
|
||||
#include <X11/extensions/XShm.h>
|
||||
|
||||
struct VideoXShm : Video {
|
||||
VideoXShm() { initialize(); }
|
||||
struct VideoXShm : VideoDriver {
|
||||
VideoXShm& self;
|
||||
|
||||
VideoXShm(Video& super) : VideoDriver(super), self(*this) {}
|
||||
~VideoXShm() { terminate(); }
|
||||
|
||||
auto driver() -> string override { return "XShm"; }
|
||||
auto create() -> bool {
|
||||
return initialize();
|
||||
}
|
||||
|
||||
auto driverName() -> string override { return "XShm"; }
|
||||
auto ready() -> bool override { return _ready; }
|
||||
|
||||
auto hasContext() -> bool override { return true; }
|
||||
auto hasSmooth() -> bool override { return true; }
|
||||
|
||||
auto availableFormats() -> vector<string> { return {"RGB24"}; }
|
||||
auto hasFormats() -> vector<string> override { return {"RGB24"}; }
|
||||
|
||||
auto exclusive() -> bool override { return false; }
|
||||
auto blocking() -> bool override { return false; }
|
||||
auto flush() -> bool override { return false; }
|
||||
auto format() -> string override { return "RGB24"; }
|
||||
auto shader() -> string override { return ""; }
|
||||
|
||||
auto setContext(uintptr context) -> bool override {
|
||||
if(context == this->context()) return true;
|
||||
if(!Video::setContext(context)) return false;
|
||||
return initialize();
|
||||
}
|
||||
|
||||
auto setSmooth(bool smooth) -> bool override {
|
||||
if(smooth == this->smooth()) return true;
|
||||
if(!Video::setSmooth(smooth)) return false;
|
||||
return true;
|
||||
}
|
||||
auto setContext(uintptr context) -> bool override { return initialize(); }
|
||||
auto setSmooth(bool smooth) -> bool override { return true; }
|
||||
|
||||
auto clear() -> void override {
|
||||
if(!ready()) return;
|
||||
auto dp = _inputBuffer;
|
||||
uint length = _inputWidth * _inputHeight;
|
||||
while(length--) *dp++ = 255u << 24;
|
||||
@@ -47,7 +37,6 @@ struct VideoXShm : Video {
|
||||
}
|
||||
|
||||
auto acquire(uint32_t*& data, uint& pitch, uint width, uint height) -> bool override {
|
||||
if(!ready()) return false;
|
||||
if(!_inputBuffer || _inputWidth != width || _inputHeight != height) {
|
||||
if(_inputBuffer) delete[] _inputBuffer;
|
||||
_inputWidth = width;
|
||||
@@ -61,11 +50,9 @@ struct VideoXShm : Video {
|
||||
}
|
||||
|
||||
auto release() -> void override {
|
||||
if(!ready()) return;
|
||||
}
|
||||
|
||||
auto output() -> void override {
|
||||
if(!ready()) return;
|
||||
size();
|
||||
|
||||
float xratio = (float)_inputWidth / (float)_outputWidth;
|
||||
@@ -79,7 +66,7 @@ struct VideoXShm : Video {
|
||||
uint32_t* sp = _inputBuffer + (uint)ystep * _inputWidth;
|
||||
uint32_t* dp = _outputBuffer + y * _outputWidth;
|
||||
|
||||
if(!_smooth) {
|
||||
if(!self.smooth) {
|
||||
for(uint x = 0; x < _outputWidth; x++) {
|
||||
*dp++ = 255u << 24 | sp[(uint)xstep];
|
||||
xstep += xratio;
|
||||
@@ -105,7 +92,7 @@ struct VideoXShm : Video {
|
||||
if(event.type == Expose) {
|
||||
XWindowAttributes attributes;
|
||||
XGetWindowAttributes(_display, _window, &attributes);
|
||||
doUpdate(attributes.width, attributes.height);
|
||||
super.doUpdate(attributes.width, attributes.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,13 +100,13 @@ struct VideoXShm : Video {
|
||||
private:
|
||||
auto initialize() -> bool {
|
||||
terminate();
|
||||
if(!_context) return false;
|
||||
if(!self.context) return false;
|
||||
|
||||
_display = XOpenDisplay(nullptr);
|
||||
_screen = DefaultScreen(_display);
|
||||
|
||||
XWindowAttributes getAttributes;
|
||||
XGetWindowAttributes(_display, (Window)_context, &getAttributes);
|
||||
XGetWindowAttributes(_display, (Window)self.context, &getAttributes);
|
||||
_depth = getAttributes.depth;
|
||||
_visual = getAttributes.visual;
|
||||
//driver only supports 32-bit pixels
|
||||
@@ -131,7 +118,7 @@ private:
|
||||
|
||||
XSetWindowAttributes setAttributes = {};
|
||||
setAttributes.border_pixel = 0;
|
||||
_window = XCreateWindow(_display, (Window)_context,
|
||||
_window = XCreateWindow(_display, (Window)self.context,
|
||||
0, 0, 256, 256, 0,
|
||||
getAttributes.depth, InputOutput, getAttributes.visual,
|
||||
CWBorderPixel, &setAttributes
|
||||
@@ -160,7 +147,7 @@ private:
|
||||
|
||||
auto size() -> bool {
|
||||
XWindowAttributes windowAttributes;
|
||||
XGetWindowAttributes(_display, (Window)_context, &windowAttributes);
|
||||
XGetWindowAttributes(_display, (Window)self.context, &windowAttributes);
|
||||
|
||||
if(_outputBuffer && _outputWidth == windowAttributes.width && _outputHeight == windowAttributes.height) return true;
|
||||
_outputWidth = windowAttributes.width;
|
||||
|
Reference in New Issue
Block a user