1 // GnashVaapiImage.cpp: GnashImage class used with VA API
3 // Copyright (C) 2007, 2008, 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
23 #include "GnashVaapiImage.h"
24 #include "VaapiSurface.h"
28 /// Get current value of microsecond timer
29 static boost::uint64_t get_ticks_usec(void)
31 #ifdef HAVE_CLOCK_GETTIME
33 clock_gettime(CLOCK_REALTIME
, &t
);
34 return (boost::uint64_t)t
.tv_sec
* 1000000 + t
.tv_nsec
/ 1000;
37 gettimeofday(&t
, NULL
);
38 return (boost::uint64_t)t
.tv_sec
* 1000000 + t
.tv_usec
;
42 GnashVaapiImage::GnashVaapiImage(boost::shared_ptr
<VaapiSurface
> surface
,
43 image::ImageType type
)
45 image::GnashImage(NULL
, surface
->width(), surface
->height(), type
,
46 image::GNASH_IMAGE_GPU
),
48 _creation_time(get_ticks_usec())
50 log_debug("GnashVaapiImage::GnashVaapiImage(): surface 0x%08x, size %dx%d\n",
51 _surface
->get(), _width
, _height
);
54 GnashVaapiImage::~GnashVaapiImage()
56 log_debug("GnashVaapiImage::~GnashVaapiImage(): surface 0x%08x\n",
60 void GnashVaapiImage::update(boost::shared_ptr
<VaapiSurface
> surface
)
63 _creation_time
= get_ticks_usec();
66 void GnashVaapiImage::update(boost::uint8_t* data
)
68 log_debug("GnashVaapi::update(): data %p\n", data
);
70 // XXX: use vaPutImage()
71 _creation_time
= get_ticks_usec();
74 void GnashVaapiImage::update(const image::GnashImage
& from
)
76 assert(stride() == from
.stride());
77 assert(size() <= from
.size());
78 assert(type() == from
.type());
80 switch (from
.location()) {
81 case image::GNASH_IMAGE_CPU
:
82 this->update(const_cast<boost::uint8_t*>(from
.begin()));
84 case image::GNASH_IMAGE_GPU
:
85 this->update(static_cast<const GnashVaapiImage
&>(from
).surface());
93 // Transfer (and convert) VA surface to CPU image data
94 bool GnashVaapiImage::transfer()
96 // NOTE: if VAAPI is used, we have a dedicated backend, so we
97 // should not have to retrieve the VA surface underlying pixels.
98 // Mark this usage scenario as a fatal error and fix the code
100 log_error("GnashVaapiImage: VA surface to SW pixels are not supported\n");
104 return _data
.get() != NULL
;
107 // Get access to the underlying data
108 image::GnashImage::iterator
109 GnashVaapiImage::begin()
111 log_debug("GnashVaapiImage::data(): surface 0x%08x\n", _surface
->get());
112 log_debug(" -> %u usec from creation\n",
113 (boost::uint32_t)(get_ticks_usec() - _creation_time
));
122 // Get read-only access to the underlying data
123 image::GnashImage::const_iterator
124 GnashVaapiImage::begin() const
126 log_debug("GnashVaapiImage::data() const: surface 0x%08x\n", _surface
->get());
127 log_debug(" -> %u usec from creation\n",
128 (boost::uint32_t)(get_ticks_usec() - _creation_time
));
130 /* XXX: awful hack... */
131 if (!const_cast<GnashVaapiImage
*>(this)->transfer()) {
142 // indent-tabs-mode: t