1 // VaapiGlobalContext.cpp: VA API global context
3 // Copyright (C) 2009, 2010 Free Software Foundation, Inc.
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "gnashconfig.h"
25 #include "VaapiGlobalContext.h"
26 #include "VaapiDisplayX11.h"
27 #ifdef HAVE_VA_VA_GLX_H
28 #include "VaapiDisplayGLX.h"
30 #include "VaapiException.h"
31 #include "vaapi_utils.h"
35 VaapiGlobalContext::VaapiGlobalContext(std::auto_ptr
<VaapiDisplay
> display
)
38 GNASH_REPORT_FUNCTION
;
41 throw VaapiException("could not initialize VA-API global context");
44 VaapiGlobalContext::~VaapiGlobalContext()
49 VaapiGlobalContext::init()
51 GNASH_REPORT_FUNCTION
;
53 VADisplay dpy
= display();
57 _profiles
.resize(vaMaxNumProfiles(dpy
));
58 status
= vaQueryConfigProfiles(dpy
, &_profiles
[0], &num_profiles
);
59 if (!vaapi_check_status(status
, "vaQueryConfigProfiles()")) {
62 _profiles
.resize(num_profiles
);
64 int num_image_formats
= 0;
65 _image_formats
.resize(vaMaxNumImageFormats(dpy
));
66 status
= vaQueryImageFormats(dpy
, &_image_formats
[0], &num_image_formats
);
67 if (!vaapi_check_status(status
, "vaQueryImageFormats()")) {
70 _image_formats
.resize(num_image_formats
);
72 unsigned int num_subpicture_formats
= 0;
73 std::vector
<unsigned int> flags
;
74 flags
.resize(vaMaxNumSubpictureFormats(dpy
));
75 _subpicture_formats
.resize(vaMaxNumSubpictureFormats(dpy
));
76 status
= vaQuerySubpictureFormats(dpy
, &_subpicture_formats
[0], &flags
[0], &num_subpicture_formats
);
77 if (!vaapi_check_status(status
, "vaQuerySubpictureFormats()")) {
80 _subpicture_formats
.resize(num_subpicture_formats
);
85 VaapiGlobalContext::hasProfile(VAProfile profile
) const
87 for (unsigned int i
= 0; i
< _profiles
.size(); i
++) {
88 if (_profiles
[i
] == profile
) {
96 VaapiGlobalContext::getImageFormat(VaapiImageFormat format
) const
98 for (unsigned int i
= 0; i
< _image_formats
.size(); i
++) {
99 if (vaapi_get_image_format(_image_formats
[i
]) == format
)
100 return &_image_formats
[i
];
105 static std::vector
<VaapiImageFormat
>
106 get_formats(std::vector
<VAImageFormat
> const &vaFormats
)
108 std::vector
<VaapiImageFormat
> formats
;
109 for (unsigned int i
= 0; i
< vaFormats
.size(); i
++) {
110 VaapiImageFormat format
= vaapi_get_image_format(vaFormats
[i
]);
111 if (format
!= VAAPI_IMAGE_NONE
)
112 formats
.push_back(format
);
117 std::vector
<VaapiImageFormat
>
118 VaapiGlobalContext::getImageFormats() const
120 return get_formats(_image_formats
);
123 std::vector
<VaapiImageFormat
>
124 VaapiGlobalContext::getSubpictureFormats() const
126 return get_formats(_subpicture_formats
);
129 /// A wrapper around a VaapiGlobalContext to ensure it's free'd on destruction.
130 VaapiGlobalContext
*VaapiGlobalContext::get()
132 LOG_ONCE(GNASH_REPORT_FUNCTION
);
134 static std::auto_ptr
<VaapiGlobalContext
> vaapi_global_context
;
136 if (!vaapi_global_context
.get()) {
137 std::auto_ptr
<VaapiDisplay
> dpy
;
138 /* XXX: this won't work with multiple renders built-in */
141 dpy
.reset(new VaapiDisplayGLX());
143 dpy
.reset(new VaapiDisplayX11());
148 vaapi_global_context
.reset(new VaapiGlobalContext(dpy
));
151 vaapi_set_is_enabled(false);
155 return vaapi_global_context
.get();
158 } // end of gnash namespace
162 // indent-tabs-mode: nil