]> git.sesse.net Git - casparcg/blobdiff - core/frame/gpu_frame_processor.cpp
2.0.0.2:
[casparcg] / core / frame / gpu_frame_processor.cpp
index 73183644a0f663056efe98ae576887d973f8b582..bbc3ec359e7d4baf2a964085ea60bcc3ef4e178a 100644 (file)
@@ -2,6 +2,7 @@
 \r
 #include "gpu_frame_processor.h"\r
 \r
+#include "gpu_frame_transform.h"\r
 #include "gpu_frame.h"\r
 #include "gpu_composite_frame.h"\r
 #include "frame_format.h"\r
@@ -29,6 +30,7 @@
 #include <functional>\r
 #include <unordered_map>\r
 #include <numeric>\r
+#include <math.h>\r
 \r
 namespace caspar { namespace core {\r
        \r
@@ -60,6 +62,8 @@ struct gpu_frame_processor::implementation : boost::noncopyable
                        // Fill pipeline\r
                        for(int n = 0; n < 2; ++n)\r
                                composite(std::vector<gpu_frame_ptr>());\r
+\r
+                       transform_ = std::make_shared<gpu_frame_transform>();\r
                });\r
        }\r
 \r
@@ -105,7 +109,7 @@ struct gpu_frame_processor::implementation : boost::noncopyable
 \r
                                // 2. Draw to framebuffer and start asynchronous DMA transfer \r
                                // to page-locked memory.\r
-                               writing_[next_index]->draw();\r
+                               writing_[next_index]->draw(transform_);\r
                                \r
                                // Create an output frame\r
                                auto temp_frame = create_output_frame();\r
@@ -140,9 +144,8 @@ struct gpu_frame_processor::implementation : boost::noncopyable
                });\r
        }\r
                        \r
-       gpu_frame_ptr create_frame(size_t width, size_t height)\r
+       gpu_frame_ptr do_create_frame(size_t key, const std::function<gpu_frame*()>& constructor)\r
        {\r
-               size_t key = width | (height << 16);\r
                auto& pool = writing_pools_[key];\r
                \r
                gpu_frame_ptr frame;\r
@@ -150,7 +153,7 @@ struct gpu_frame_processor::implementation : boost::noncopyable
                {\r
                        frame = executor_.invoke([&]\r
                        {\r
-                               return std::shared_ptr<gpu_frame>(new gpu_frame(width, height));\r
+                               return std::shared_ptr<gpu_frame>(constructor());\r
                        });\r
                }\r
                \r
@@ -165,12 +168,35 @@ struct gpu_frame_processor::implementation : boost::noncopyable
                        executor_.begin_invoke(destructor);\r
                });\r
        }\r
+\r
+       gpu_frame_ptr create_frame(size_t width, size_t height, void* tag)\r
+       {\r
+               size_t key = reinterpret_cast<size_t>(tag);\r
+               return do_create_frame(key, [&]\r
+               {\r
+                       return new gpu_frame(width, height);\r
+               });\r
+       }\r
+       \r
+       gpu_frame_ptr create_frame(const planar_frame_dimension& data_size, void* tag)\r
+       {\r
+               size_t key = reinterpret_cast<size_t>(tag);\r
+               return do_create_frame(key, [&]\r
+               {\r
+                       return new gpu_frame(data_size);\r
+               });\r
+       }\r
        \r
        void pop(gpu_frame_ptr& frame)\r
        {\r
                output_.pop(frame);\r
        }\r
-                       \r
+\r
+       void release_frames(void* tag)\r
+       {\r
+               writing_pools_[reinterpret_cast<size_t>(tag)].clear();\r
+       }\r
+                               \r
        typedef tbb::concurrent_bounded_queue<gpu_frame_ptr> gpu_frame_queue;\r
        tbb::concurrent_unordered_map<size_t, gpu_frame_queue> writing_pools_;\r
        gpu_frame_queue reading_pool_;  \r
@@ -189,11 +215,14 @@ struct gpu_frame_processor::implementation : boost::noncopyable
        common::executor executor_;\r
 \r
        common::gl::frame_buffer_object fbo_;\r
+\r
+       gpu_frame_transform_ptr transform_;\r
 };\r
        \r
 gpu_frame_processor::gpu_frame_processor(const frame_format_desc& format_desc) : impl_(new implementation(format_desc)){}\r
 void gpu_frame_processor::push(const std::vector<gpu_frame_ptr>& frames){ impl_->composite(frames);}\r
 void gpu_frame_processor::pop(gpu_frame_ptr& frame){impl_->pop(frame);}\r
-gpu_frame_ptr gpu_frame_processor::create_frame(size_t width, size_t height){return impl_->create_frame(width, height);}\r
-\r
+gpu_frame_ptr gpu_frame_processor::create_frame(size_t width, size_t height, void* tag){return impl_->create_frame(width, height, tag);}\r
+gpu_frame_ptr gpu_frame_processor::create_frame(const planar_frame_dimension& data_size, void* tag){return impl_->create_frame(data_size, tag);}\r
+void gpu_frame_processor::release_frames(void* tag){impl_->release_frames(tag);}\r
 }}
\ No newline at end of file