mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
fix: use glReadnPixels for X11 copying to be more memory safe
This commit is contained in:
parent
b7735298be
commit
aee622da6c
@ -219,7 +219,7 @@ void CWallpaperApplication::setupProperties () {
|
|||||||
this->setupPropertiesForProject (info);
|
this->setupPropertiesForProject (info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWallpaperApplication::takeScreenshot (const std::filesystem::path& filename) {
|
void CWallpaperApplication::takeScreenshot (const std::filesystem::path& filename) const {
|
||||||
// this should be getting called at the end of the frame, so the right thing should be bound already
|
// this should be getting called at the end of the frame, so the right thing should be bound already
|
||||||
const int width = this->m_renderContext->getOutput ().getFullWidth ();
|
const int width = this->m_renderContext->getOutput ().getFullWidth ();
|
||||||
const int height = this->m_renderContext->getOutput ().getFullHeight ();
|
const int height = this->m_renderContext->getOutput ().getFullHeight ();
|
||||||
@ -238,7 +238,6 @@ void CWallpaperApplication::takeScreenshot (const std::filesystem::path& filenam
|
|||||||
const uint8_t* pixel = buffer;
|
const uint8_t* pixel = buffer;
|
||||||
|
|
||||||
// read the viewport data into the pixel buffer
|
// read the viewport data into the pixel buffer
|
||||||
glPixelStorei (GL_PACK_ALIGNMENT, 1);
|
|
||||||
glReadnPixels (viewport->viewport.x, viewport->viewport.y, viewport->viewport.z, viewport->viewport.w, GL_RGB,
|
glReadnPixels (viewport->viewport.x, viewport->viewport.y, viewport->viewport.z, viewport->viewport.w, GL_RGB,
|
||||||
GL_UNSIGNED_BYTE, bufferSize, buffer);
|
GL_UNSIGNED_BYTE, bufferSize, buffer);
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ class CWallpaperApplication {
|
|||||||
*
|
*
|
||||||
* @param filename
|
* @param filename
|
||||||
*/
|
*/
|
||||||
void takeScreenshot (const std::filesystem::path& filename);
|
void takeScreenshot (const std::filesystem::path& filename) const;
|
||||||
|
|
||||||
/** The application context that contains the current app settings */
|
/** The application context that contains the current app settings */
|
||||||
CApplicationContext& m_context;
|
CApplicationContext& m_context;
|
||||||
|
@ -132,9 +132,16 @@ void CGLFWOpenGLDriver::dispatchEventQueue () {
|
|||||||
this->getApp ().update (viewport);
|
this->getApp ().update (viewport);
|
||||||
|
|
||||||
// read the full texture into the image
|
// read the full texture into the image
|
||||||
if (this->m_output->haveImageBuffer ())
|
if (this->m_output->haveImageBuffer ()) {
|
||||||
glReadPixels (0, 0, this->m_output->getFullWidth (), this->m_output->getFullHeight (), GL_BGRA,
|
glReadnPixels (0, 0, this->m_output->getFullWidth (), this->m_output->getFullHeight (), GL_BGRA,
|
||||||
GL_UNSIGNED_BYTE, this->m_output->getImageBuffer ());
|
GL_UNSIGNED_BYTE, this->m_output->getImageBufferSize(), this->m_output->getImageBuffer ());
|
||||||
|
|
||||||
|
GLenum error = glGetError();
|
||||||
|
|
||||||
|
if (error != GL_NO_ERROR) {
|
||||||
|
sLog.exception("OpenGL error when reading texture ", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: FRAMETIME CONTROL SHOULD GO BACK TO THE CWALLPAPAERAPPLICATION ONCE ACTUAL PARTICLES ARE IMPLEMENTED
|
// TODO: FRAMETIME CONTROL SHOULD GO BACK TO THE CWALLPAPAERAPPLICATION ONCE ACTUAL PARTICLES ARE IMPLEMENTED
|
||||||
// TODO: AS THOSE, MORE THAN LIKELY, WILL REQUIRE OF A DIFFERENT PROCESSING RATE
|
// TODO: AS THOSE, MORE THAN LIKELY, WILL REQUIRE OF A DIFFERENT PROCESSING RATE
|
||||||
|
@ -56,6 +56,10 @@ void* CGLFWWindowOutput::getImageBuffer () const {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t CGLFWWindowOutput::getImageBufferSize () const {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void CGLFWWindowOutput::updateRender () const {
|
void CGLFWWindowOutput::updateRender () const {
|
||||||
if (this->m_context.settings.render.mode != Application::CApplicationContext::NORMAL_WINDOW)
|
if (this->m_context.settings.render.mode != Application::CApplicationContext::NORMAL_WINDOW)
|
||||||
return;
|
return;
|
||||||
|
@ -13,6 +13,7 @@ class CGLFWWindowOutput final : public COutput {
|
|||||||
bool renderMultiple () const override;
|
bool renderMultiple () const override;
|
||||||
bool haveImageBuffer () const override;
|
bool haveImageBuffer () const override;
|
||||||
void* getImageBuffer () const override;
|
void* getImageBuffer () const override;
|
||||||
|
uint32_t getImageBufferSize () const override;
|
||||||
void updateRender () const override;
|
void updateRender () const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -38,6 +38,7 @@ class COutput {
|
|||||||
virtual bool haveImageBuffer () const = 0;
|
virtual bool haveImageBuffer () const = 0;
|
||||||
const std::map<std::string, COutputViewport*>& getViewports () const;
|
const std::map<std::string, COutputViewport*>& getViewports () const;
|
||||||
virtual void* getImageBuffer () const = 0;
|
virtual void* getImageBuffer () const = 0;
|
||||||
|
virtual uint32_t getImageBufferSize () const = 0;
|
||||||
virtual void updateRender () const = 0;
|
virtual void updateRender () const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -51,4 +51,8 @@ void* CWaylandOutput::getImageBuffer () const {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t CWaylandOutput::getImageBufferSize () const {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void CWaylandOutput::updateRender () const {}
|
void CWaylandOutput::updateRender () const {}
|
@ -24,6 +24,7 @@ class CWaylandOutput final : public COutput {
|
|||||||
bool renderMultiple () const override;
|
bool renderMultiple () const override;
|
||||||
bool haveImageBuffer () const override;
|
bool haveImageBuffer () const override;
|
||||||
void* getImageBuffer () const override;
|
void* getImageBuffer () const override;
|
||||||
|
uint32_t getImageBufferSize () const override;
|
||||||
void updateRender () const override;
|
void updateRender () const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -83,6 +83,10 @@ bool CX11Output::haveImageBuffer () const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t CX11Output::getImageBufferSize () const {
|
||||||
|
return this->m_imageSize;
|
||||||
|
}
|
||||||
|
|
||||||
void CX11Output::loadScreenInfo () {
|
void CX11Output::loadScreenInfo () {
|
||||||
// reset the viewports
|
// reset the viewports
|
||||||
this->m_viewports.clear ();
|
this->m_viewports.clear ();
|
||||||
@ -163,6 +167,7 @@ void CX11Output::loadScreenInfo () {
|
|||||||
// set the window background as our pixmap
|
// set the window background as our pixmap
|
||||||
XSetWindowBackgroundPixmap (this->m_display, this->m_root, this->m_pixmap);
|
XSetWindowBackgroundPixmap (this->m_display, this->m_root, this->m_pixmap);
|
||||||
// allocate space for the image's data
|
// allocate space for the image's data
|
||||||
|
this->m_imageSize = this->m_fullWidth * this->m_fullHeight * 4;
|
||||||
this->m_imageData = new char [this->m_fullWidth * this->m_fullHeight * 4];
|
this->m_imageData = new char [this->m_fullWidth * this->m_fullHeight * 4];
|
||||||
// create an image so we can copy it over
|
// create an image so we can copy it over
|
||||||
this->m_image = XCreateImage (this->m_display, CopyFromParent, 24, ZPixmap, 0, this->m_imageData, this->m_fullWidth,
|
this->m_image = XCreateImage (this->m_display, CopyFromParent, 24, ZPixmap, 0, this->m_imageData, this->m_fullWidth,
|
||||||
|
@ -21,6 +21,7 @@ class CX11Output final : public COutput {
|
|||||||
bool renderMultiple () const override;
|
bool renderMultiple () const override;
|
||||||
bool haveImageBuffer () const override;
|
bool haveImageBuffer () const override;
|
||||||
void* getImageBuffer () const override;
|
void* getImageBuffer () const override;
|
||||||
|
uint32_t getImageBufferSize () const override;
|
||||||
void updateRender () const override;
|
void updateRender () const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -32,6 +33,7 @@ class CX11Output final : public COutput {
|
|||||||
Window m_root;
|
Window m_root;
|
||||||
GC m_gc;
|
GC m_gc;
|
||||||
char* m_imageData;
|
char* m_imageData;
|
||||||
|
uint32_t m_imageSize;
|
||||||
XImage* m_image;
|
XImage* m_image;
|
||||||
std::vector<COutputViewport*> m_screens;
|
std::vector<COutputViewport*> m_screens;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user