diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index 93dcd8dea492..955147f497fd 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -1,62 +1,21 @@ /* SPDX-License-Identifier: Apache-2.0 * Copyright 2011-2022 Blender Foundation */ -#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::instance_; - -PreviewEngine *PreviewEngine::create(RenderEngine *bl_engine, - const std::string &render_delegate_name) -{ - if (!instance_) { - instance_ = std::make_unique(bl_engine, render_delegate_name); - } - else if (instance_->render_delegate_name != render_delegate_name) { - instance_->render_delegate_->Stop(); - instance_ = std::make_unique(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); - std::vector &pixels = render_images_["Combined"]; - { /* Release the GIL before calling into hydra, in case any hydra plugins call into python. */ pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); engine_->Execute(render_index_.get(), &tasks_); } + std::vector &pixels = render_images_["Combined"]; while (true) { if (RE_engine_test_break(bl_engine_)) { break; @@ -74,18 +33,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 &pixels) { RenderResult *result = RE_engine_begin_result( diff --git a/source/blender/render/hydra/preview_engine.h b/source/blender/render/hydra/preview_engine.h index 986f88f69e83..4dfc88d80028 100644 --- a/source/blender/render/hydra/preview_engine.h +++ b/source/blender/render/hydra/preview_engine.h @@ -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(); + using FinalEngine::FinalEngine; 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 &pixels); - - /* Singleton class instance */ - static std::unique_ptr instance_; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index 335bbd283730..9ef8f00b3478 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -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(engine); - if (preview_engine) { - PreviewEngine::free(); - } - else { - delete engine; - } + delete engine; CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine); Py_RETURN_NONE;