1 // GnashVaapiImage.cpp: GnashImage class used with VA API
3 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc.
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "GnashVaapiImage.h"
25 #include "VaapiSurface.h"
29 /// Get current value of microsecond timer
30 static std::uint64_t get_ticks_usec(void)
32 #ifdef HAVE_CLOCK_GETTIME
34 clock_gettime(CLOCK_REALTIME
, &t
);
35 return (std::uint64_t)t
.tv_sec
* 1000000 + t
.tv_nsec
/ 1000;
38 gettimeofday(&t
, NULL
);
39 return (std::uint64_t)t
.tv_sec
* 1000000 + t
.tv_usec
;
43 GnashVaapiImage::GnashVaapiImage(std::shared_ptr
<VaapiSurface
> surface
,
44 image::ImageType type
)
46 image::GnashImage(NULL
, surface
->width(), surface
->height(), type
,
47 image::GNASH_IMAGE_GPU
),
49 _creation_time(get_ticks_usec())
51 log_debug(_("GnashVaapiImage::GnashVaapiImage(): surface 0x%08x, size %dx%d\n"),
52 _surface
->get(), _width
, _height
);
55 GnashVaapiImage::~GnashVaapiImage()
57 log_debug(_("GnashVaapiImage::~GnashVaapiImage(): surface 0x%08x\n"),
61 void GnashVaapiImage::update(std::shared_ptr
<VaapiSurface
> surface
)
64 _creation_time
= get_ticks_usec();
67 void GnashVaapiImage::update(std::uint8_t* data
)
69 log_debug(_("GnashVaapi::update(): data %p\n"), data
);
71 // XXX: use vaPutImage()
72 _creation_time
= get_ticks_usec();
75 void GnashVaapiImage::update(const image::GnashImage
& from
)
77 assert(stride() == from
.stride());
78 assert(size() <= from
.size());
79 assert(type() == from
.type());
81 switch (from
.location()) {
82 case image::GNASH_IMAGE_CPU
:
83 this->update(const_cast<std::uint8_t*>(from
.begin()));
85 case image::GNASH_IMAGE_GPU
:
86 this->update(static_cast<const GnashVaapiImage
&>(from
).surface());
94 // Transfer (and convert) VA surface to CPU image data
95 bool GnashVaapiImage::transfer()
97 // NOTE: if VAAPI is used, we have a dedicated backend, so we
98 // should not have to retrieve the VA surface underlying pixels.
99 // Mark this usage scenario as a fatal error and fix the code
101 log_error(_("GnashVaapiImage: VA surface to SW pixels are not supported\n"));
105 return _data
.get() != NULL
;
108 // Get access to the underlying data
109 image::GnashImage::iterator
110 GnashVaapiImage::begin()
112 log_debug(_("GnashVaapiImage::data(): surface 0x%08x\n"), _surface
->get());
113 log_debug(_(" -> %u usec from creation\n"),
114 (std::uint32_t)(get_ticks_usec() - _creation_time
));
123 // Get read-only access to the underlying data
124 image::GnashImage::const_iterator
125 GnashVaapiImage::begin() const
127 log_debug(_("GnashVaapiImage::data() const: surface 0x%08x\n"),
129 log_debug(_(" -> %u usec from creation\n"),
130 (std::uint32_t)(get_ticks_usec() - _creation_time
));
132 /* XXX: awful hack... */
133 if (!const_cast<GnashVaapiImage
*>(this)->transfer()) {
144 // indent-tabs-mode: nil