]> git.sesse.net Git - casparcg/commitdiff
Merged GL GC command from 2.0.
authorHelge Norberg <helge.norberg@svt.se>
Wed, 18 Nov 2015 17:50:28 +0000 (18:50 +0100)
committerHelge Norberg <helge.norberg@svt.se>
Wed, 18 Nov 2015 17:50:28 +0000 (18:50 +0100)
accelerator/ogl/util/device.cpp
accelerator/ogl/util/device.h
protocol/amcp/AMCPCommandsImpl.cpp

index ac2159b78da56b51dc42eeac07b4097a80de86d2..1e41ceb7a0eb637fd0571b9a73fe16d66d86f97b 100644 (file)
@@ -351,6 +351,32 @@ struct device::impl : public std::enable_shared_from_this<impl>
                };
                return std::async(std::launch::deferred, std::move(cmd));
        }
+
+       std::future<void> gc()
+       {
+               return executor_.begin_invoke([=]
+               {
+                       CASPAR_LOG(info) << " ogl: Running GC.";
+
+                       try
+                       {
+                               for (auto& pools : device_pools_)
+                               {
+                                       for (auto& pool : pools)
+                                               pool.second.clear();
+                               }
+                               for (auto& pools : host_pools_)
+                               {
+                                       for (auto& pool : pools)
+                                               pool.second.clear();
+                               }
+                       }
+                       catch (...)
+                       {
+                               CASPAR_LOG_CURRENT_EXCEPTION();
+                       }
+               }, task_priority::high_priority);
+       }
 };
 
 device::device() 
@@ -362,6 +388,7 @@ array<std::uint8_t>                                                 device::create_array(int size){return impl_->create_ar
 std::future<std::shared_ptr<texture>>          device::copy_async(const array<const std::uint8_t>& source, int width, int height, int stride, bool mipmapped){return impl_->copy_async(source, width, height, stride, mipmapped);}
 std::future<std::shared_ptr<texture>>          device::copy_async(const array<std::uint8_t>& source, int width, int height, int stride, bool mipmapped){ return impl_->copy_async(source, width, height, stride, mipmapped); }
 std::future<array<const std::uint8_t>>         device::copy_async(const spl::shared_ptr<texture>& source){return impl_->copy_async(source);}
+std::future<void>                                                      device::gc() { return impl_->gc(); }
 boost::property_tree::wptree                           device::info() const { return impl_->info(); }
 std::wstring                                                           device::version() const{return impl_->version();}
 
index 0907b01d53a7069d00ac694de399392456e29870..bda7af81997104b8c36df06493870bb709275349 100644 (file)
@@ -70,6 +70,8 @@ public:
                return executor_.invoke(std::forward<Func>(func), priority);
        }
 
+       std::future<void> gc();
+
        // Properties
        
        boost::property_tree::wptree    info() const;
index 75aefeee658d250134ae6171e0a0b4a00724dd27..f33a269a3aa6fd2b99fb3a461708021546f17479 100644 (file)
@@ -2554,6 +2554,25 @@ std::wstring gl_info_command(command_context& ctx)
        return result.str();
 }
 
+void gl_gc_describer(core::help_sink& sink, const core::help_repository& repo)
+{
+       sink.short_description(L"Release pooled OpenGL resources.");
+       sink.syntax(L"GL GC");
+       sink.para()->text(L"Releases all the pooled OpenGL resources. ")->strong(L"May cause a pause on all video channels.");
+}
+
+std::wstring gl_gc_command(command_context& ctx)
+{
+       auto device = ctx.ogl_device;
+
+       if (!device)
+               CASPAR_THROW_EXCEPTION(not_supported() << msg_info("GL command only supported with OpenGL accelerator."));
+
+       device->gc().wait();
+
+       return L"202 GL GC OK\r\n";
+}
+
 static const int WIDTH = 80;
 
 struct max_width_sink : public core::help_sink
@@ -2911,6 +2930,7 @@ void register_commands(amcp_command_repository& repo)
        repo.register_channel_command(  L"Query Commands",              L"INFO DELAY",                                  info_delay_describer,                           info_delay_command,                             0);
        repo.register_command(                  L"Query Commands",              L"DIAG",                                                diag_describer,                                         diag_command,                                   0);
        repo.register_command(                  L"Query Commands",              L"GL INFO",                                             gl_info_describer,                                      gl_info_command,                                0);
+       repo.register_command(                  L"Query Commands",              L"GL GC",                                               gl_gc_describer,                                        gl_gc_command,                                  0);
        repo.register_command(                  L"Query Commands",              L"BYE",                                                 bye_describer,                                          bye_command,                                    0);
        repo.register_command(                  L"Query Commands",              L"KILL",                                                kill_describer,                                         kill_command,                                   0);
        repo.register_command(                  L"Query Commands",              L"RESTART",                                             restart_describer,                                      restart_command,                                0);