]> git.sesse.net Git - casparcg/blob - accelerator/accelerator.cpp
Merge pull request #374 from hummelstrand/readme-2.1.0-update
[casparcg] / accelerator / accelerator.cpp
1 #include "StdAfx.h"
2
3 #include "accelerator.h"
4
5 #ifdef _MSC_VER
6 #include "cpu/image/image_mixer.h"
7 #endif
8 #include "ogl/image/image_mixer.h"
9
10 #include "ogl/util/device.h"
11
12 #include <common/env.h>
13
14 #include <tbb/mutex.h>
15
16 namespace caspar { namespace accelerator {
17         
18 struct accelerator::impl
19 {
20         const std::wstring                              path_;
21         tbb::mutex                                              mutex_;
22         std::shared_ptr<ogl::device>    ogl_device_;
23
24         impl(const std::wstring& path)
25                 : path_(path)
26         {
27         }
28
29         std::unique_ptr<core::image_mixer> create_image_mixer()
30         {
31                 try
32                 {
33                         if(path_ == L"gpu" || path_ == L"ogl" || path_ == L"auto" || path_ == L"default")
34                         {
35                                 tbb::mutex::scoped_lock lock(mutex_);
36
37                                 if(!ogl_device_)
38                                         ogl_device_.reset(new ogl::device());
39
40                                 return std::unique_ptr<core::image_mixer>(new ogl::image_mixer(spl::make_shared_ptr(ogl_device_), env::properties().get(L"configuration.mixer.blend-modes", false)));
41                         }
42                 }
43                 catch(...)
44                 {
45                         if(path_ == L"gpu" || path_ == L"ogl")
46                                 CASPAR_LOG_CURRENT_EXCEPTION();
47                 }
48 #ifdef _MSC_VER
49                 return std::unique_ptr<core::image_mixer>(new cpu::image_mixer());
50 #else
51                 CASPAR_THROW_EXCEPTION(not_supported());
52 #endif
53         }
54 };
55
56 accelerator::accelerator(const std::wstring& path)
57         : impl_(new impl(path))
58 {
59 }
60
61 accelerator::~accelerator()
62 {
63 }
64
65 std::unique_ptr<core::image_mixer> accelerator::create_image_mixer()
66 {
67         return impl_->create_image_mixer();
68 }
69
70 }}