frontend: Refactor ScreenshotObj options

This commit is contained in:
Warchamp7
2026-09-22 14:16:46 -04:00
committed by Ryan Foster
parent 4044a1a142
commit 13d5c007b0
3 changed files with 39 additions and 46 deletions
+21 -34
View File
@@ -32,25 +32,15 @@
#include "moc_ScreenshotObj.cpp"
namespace {
void renderTick(void *param, float)
{
ScreenshotObj *self = static_cast<ScreenshotObj *>(param);
if (self->stage() == ScreenshotObj::Stage::Finished) {
return;
}
obs_enter_graphics();
self->processStage();
obs_leave_graphics();
}
} // namespace
ScreenshotObj::ScreenshotObj(obs_source_t *source) : weakSource(OBSGetWeakRef(source))
ScreenshotObj::ScreenshotObj(obs_source_t *source, const Options &options)
: weakSource(OBSGetWeakRef(source)),
options(options)
{
obs_add_tick_callback(renderTick, this);
}
ScreenshotObj::ScreenshotObj(obs_source_t *source) : ScreenshotObj(source, {}) {}
ScreenshotObj::~ScreenshotObj()
{
obs_enter_graphics();
@@ -61,6 +51,18 @@ ScreenshotObj::~ScreenshotObj()
obs_remove_tick_callback(renderTick, this);
}
void ScreenshotObj::renderTick(void *param, float)
{
ScreenshotObj *self = static_cast<ScreenshotObj *>(param);
if (self->stage() == ScreenshotObj::Stage::Finished) {
return;
}
obs_enter_graphics();
self->processStage();
obs_leave_graphics();
}
void ScreenshotObj::renderScreenshot()
{
OBSSourceAutoRelease source = OBSGetStrongRef(weakSource);
@@ -94,8 +96,8 @@ void ScreenshotObj::renderScreenshot()
#endif
const enum gs_color_format format = gs_get_format_from_space(space);
outputWidth = customSize.isValid() ? customSize.width() : sourceWidth;
outputHeight = customSize.isValid() ? customSize.height() : sourceHeight;
outputWidth = options.size.isValid() ? options.size.width() : sourceWidth;
outputHeight = options.size.isValid() ? options.size.height() : sourceHeight;
texrender = gs_texrender_create(format, GS_ZS_NONE);
stagesurf = gs_stagesurface_create(outputWidth, outputHeight, format);
@@ -198,7 +200,7 @@ void ScreenshotObj::copyData()
void ScreenshotObj::saveToFile()
{
if (!outputToFile) {
if (!options.outputToFile) {
QMetaObject::invokeMethod(this, &ScreenshotObj::onFinished, Qt::QueuedConnection);
return;
}
@@ -352,7 +354,7 @@ void ScreenshotObj::onFinished()
}
if (outputWidth > 0 && outputHeight > 0) {
if (outputToFile) {
if (options.outputToFile) {
emit imageSaved(path);
}
@@ -362,21 +364,6 @@ void ScreenshotObj::onFinished()
this->deleteLater();
}
void ScreenshotObj::setSize(QSize size)
{
customSize = size;
}
void ScreenshotObj::setSize(int width, int height)
{
setSize(QSize(width, height));
}
void ScreenshotObj::setSaveToFile(bool save)
{
outputToFile = save;
}
void ScreenshotObj::handleSave()
{
saveToFile();
+13 -9
View File
@@ -29,6 +29,12 @@ class ScreenshotObj : public QObject {
Q_OBJECT
public:
struct Options {
QSize size{};
bool outputToFile{true};
};
ScreenshotObj(obs_source_t *source, const Options &options);
ScreenshotObj(obs_source_t *source);
~ScreenshotObj() override;
@@ -36,13 +42,10 @@ public:
Stage stage() { return stage_; }
void setSize(QSize size);
void setSize(int width, int height);
void setSaveToFile(bool save);
private:
static void renderTick(void *param, float seconds);
void processStage();
private:
void renderScreenshot();
void downloadData();
void copyData();
@@ -50,23 +53,24 @@ private:
void muxFile();
void onFinished();
OBSWeakSource weakSource;
Stage stage_ = Stage::Render;
Options options;
gs_texrender_t *texrender = nullptr;
gs_stagesurf_t *stagesurf = nullptr;
OBSWeakSource weakSource;
std::string path;
QImage image;
std::vector<uint8_t> half_bytes;
QSize customSize;
uint32_t sourceWidth = 0;
uint32_t sourceHeight = 0;
uint32_t outputWidth = 0;
uint32_t outputHeight = 0;
std::thread thread;
std::shared_ptr<QImage> imagePtr;
bool outputToFile = true;
signals:
void imageSaved(std::string path);
+5 -3
View File
@@ -185,9 +185,11 @@ bool ThumbnailItem::update()
return false;
}
auto *obj = new ScreenshotObj(source);
obj->setSaveToFile(false);
obj->setSize(kDefaultWidth, kDefaultHeight);
ScreenshotObj::Options options;
options.outputToFile = false;
options.size = {kDefaultWidth, kDefaultHeight};
auto *obj = new ScreenshotObj(source, options);
connect(obj, &ScreenshotObj::imageReady, this, &ThumbnailItem::updatePixmapFromImage);
}