Remove timer from PreviewEngine #48

Merged
Bogdan Nagirniak merged 4 commits from BLEN-424 into hydra-render 2023-06-01 02:12:14 +02:00
3 changed files with 2 additions and 64 deletions
Showing only changes of commit 6d4acd8696 - Show all commits

View File

@ -3,48 +3,11 @@
#include "DEG_depsgraph_query.h"
#include "BLI_timer.h"
#include "camera.h"
#include "preview_engine.h"
namespace blender::render::hydra {
const double LIFETIME = 180.0;
std::unique_ptr<PreviewEngine> PreviewEngine::instance_;
PreviewEngine *PreviewEngine::create(RenderEngine *bl_engine,
const std::string &render_delegate_name)
{
if (!instance_) {
instance_ = std::make_unique<PreviewEngine>(bl_engine, render_delegate_name);
}
else if (instance_->render_delegate_name != render_delegate_name) {
instance_->render_delegate_->Stop();
instance_ = std::make_unique<PreviewEngine>(bl_engine, render_delegate_name);
}
else {
instance_->bl_engine_ = bl_engine;
}
instance_->scene_delegate_->clear();
if (BLI_timer_is_registered((uintptr_t)&instance_)) {
/* Unregister timer while PreviewEngine is working */
BLI_timer_unregister((uintptr_t)&instance_);
}
return instance_.get();
}
void PreviewEngine::free()
{
instance_->render_delegate_->Stop();
/* Register timer for schedule free PreviewEngine instance */
BLI_timer_register((uintptr_t)&instance_, free_instance, nullptr, nullptr, LIFETIME, true);
}
void PreviewEngine::render(Depsgraph *depsgraph)
{
prepare_for_render(depsgraph);
@ -74,18 +37,6 @@ void PreviewEngine::render(Depsgraph *depsgraph)
update_render_result(pixels);
}
double PreviewEngine::free_instance(uintptr_t uuid, void *user_data)
{
if (!instance_->render_task_delegate_->is_converged()) {
/* Restart timer if render isn't completed */
return LIFETIME;
}
CLOG_INFO(LOG_RENDER_HYDRA, 2, "");
instance_ = nullptr;
return -1;
}
void PreviewEngine::update_render_result(std::vector<float> &pixels)
{
RenderResult *result = RE_engine_begin_result(

View File

@ -9,19 +9,12 @@ namespace blender::render::hydra {
class PreviewEngine : public FinalEngine {
public:
static PreviewEngine *create(RenderEngine *bl_engine, const std::string &render_delegate_name);
static void free();
void render(Depsgraph *depsgraph) override;
private:
using FinalEngine::FinalEngine;
static double free_instance(uintptr_t uuid, void *user_data);
void update_render_result(std::vector<float> &pixels);
/* Singleton class instance */
static std::unique_ptr<PreviewEngine> instance_;
};
} // namespace blender::render::hydra

View File

@ -111,7 +111,7 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
engine = new ViewportEngine(bl_engine, render_delegate_id);
}
else if (STREQ(engine_type, "PREVIEW")) {
engine = PreviewEngine::create(bl_engine, render_delegate_id);
engine = new PreviewEngine(bl_engine, render_delegate_id);
}
else {
if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) {
@ -134,13 +134,7 @@ static PyObject *engine_free_func(PyObject * /*self*/, PyObject *args)
}
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
PreviewEngine *preview_engine = dynamic_cast<PreviewEngine *>(engine);
if (preview_engine) {
PreviewEngine::free();
}
else {
delete engine;
}
delete engine;
CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine);
Py_RETURN_NONE;