1 // VaapiImage.cpp: VA image abstraction
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
20 #include <boost/format.hpp>
24 #include "VaapiImage.h"
25 #include "VaapiSurface.h"
26 #include "VaapiGlobalContext.h"
27 #include "VaapiException.h"
28 #include "vaapi_utils.h"
32 VaapiImage::VaapiImage(unsigned int width
,
34 VaapiImageFormat format
)
38 log_debug("VaapiImage::VaapiImage(): format '%s'\n", string_of_FOURCC(format
));
40 memset(&_image
, 0, sizeof(_image
));
41 _image
.image_id
= VA_INVALID_ID
;
43 if (!create(width
, height
)) {
45 msg
= boost::format("Could not create %s image")
46 % string_of_FOURCC(_format
);
47 throw VaapiException(msg
.str());
51 VaapiImage::~VaapiImage()
54 GNASH_REPORT_FUNCTION
;
60 bool VaapiImage::create(unsigned int width
, unsigned int height
)
62 GNASH_REPORT_FUNCTION
;
64 VaapiGlobalContext
* const gvactx
= VaapiGlobalContext::get();
68 const VAImageFormat
*va_format
= gvactx
->getImageFormat(_format
);
74 _image
.image_id
= VA_INVALID_ID
;
75 status
= vaCreateImage(gvactx
->display(),
76 const_cast<VAImageFormat
*>(va_format
),
79 if (!vaapi_check_status(status
, "vaCreateImage()"))
82 log_debug(" image 0x%08x, format '%s'\n", get(), string_of_FOURCC(_format
));
88 void VaapiImage::destroy()
92 if (_image
.image_id
== VA_INVALID_ID
) {
96 VaapiGlobalContext
* const gvactx
= VaapiGlobalContext::get();
102 status
= vaDestroyImage(gvactx
->display(), _image
.image_id
);
103 if (!vaapi_check_status(status
, "vaDestroyImage()")) {
109 bool VaapiImage::map()
115 if (_image
.image_id
== VA_INVALID_ID
) {
119 VaapiGlobalContext
* const gvactx
= VaapiGlobalContext::get();
125 status
= vaMapBuffer(gvactx
->display(), _image
.buf
, (void **)&_image_data
);
126 if (!vaapi_check_status(status
, "vaMapBuffer()")) {
134 bool VaapiImage::unmap()
142 VaapiGlobalContext
* const gvactx
= VaapiGlobalContext::get();
148 status
= vaUnmapBuffer(gvactx
->display(), _image
.buf
);
149 if (!vaapi_check_status(status
, "vaUnmapBuffer()")) {
155 // Get pixels for the specified plane
156 boost::uint8_t *VaapiImage::getPlane(int plane
) const
159 throw VaapiException("VaapiImage::getPixels(): unmapped image");
162 return _image_data
+ _image
.offsets
[plane
];
165 // Get scanline pitch for the specified plane
166 unsigned int VaapiImage::getPitch(int plane
) const
169 throw VaapiException("VaapiImage::getPitch(): unmapped image");
172 return _image
.pitches
[plane
];
175 } // end of gnash namespace
179 // indent-tabs-mode: nil