2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 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
19 #ifndef GNASH_SCREENSHOT_H
20 #define GNASH_SCREENSHOT_H
24 #include <boost/shared_ptr.hpp>
27 #include <boost/lexical_cast.hpp>
29 #include "GnashEnums.h"
37 /// Handles screen dumps.
42 typedef std::vector
<size_t> FrameList
;
44 /// Create a ScreenShotter with output type selected from filename
45 ScreenShotter(const std::string
& fileName
, int quality
= 100);
47 /// Create a ScreenShotter, specifying the output type.
48 ScreenShotter(const std::string
& fileName
, FileType f
, int quality
= 100);
52 /// Take a screenshot at the next possible moment.
57 /// Take a screenshot when the last frame is reached.
62 struct NoAction
{ void operator()() const {} };
64 /// To be called on the last frame before exit.
66 /// @param r The renderer to use to render the image.
68 /// Which frame is last depends on the execution path of the SWF, whether
69 /// the SWF loops, whether a timeout was requested or a maximum number of
70 /// advances set. Those conditions are not knowable in advance, so
71 /// the last frame is a special case.
72 void last(const Renderer
& r
) const {
76 /// To be called on the last frame before exit.
78 /// @tparam Action The functor to call only when a screenshot is
80 /// @param r The renderer to use to render the image.
82 /// Which frame is last depends on the execution path of the SWF, whether
83 /// the SWF loops, whether a timeout was requested or a maximum number of
84 /// advances set. Those conditions are not knowable in advance, so
85 /// the last frame is a special case.
86 template<typename Action
>
87 void last(const Renderer
& r
, Action
* t
= 0) const
95 /// Takes a screenshot if required.
97 /// Called on each advance.
99 /// @param frameAdvance used to check whether a screenshot is required
100 /// as well as to construct the filename.
101 /// @param r The renderer to use to render the image.
102 void screenShot(const Renderer
& r
, size_t frameAdvance
) {
103 screenShot
<NoAction
>(r
, frameAdvance
);
106 /// Takes a screenshot if required.
108 /// Called on each advance, invoking a functor before any screenshot is
111 /// @tparam Action The functor to call only when a screenshot is
113 /// @param frameAdvance used to check whether a screenshot is required
114 /// as well as to construct the filename.
115 /// @param r The renderer to use to render the image.
116 template<typename Action
>
117 void screenShot(const Renderer
& r
, size_t frameAdvance
, Action
* t
= 0) {
118 // Save an image if a spontaneous screenshot was requested or the
119 // frame is in the list of requested frames.
120 if (_immediate
|| std::binary_search(_frames
.begin(), _frames
.end(),
123 // Check whether we've rendered an image for this frame.
124 if (_done
.find(frameAdvance
) != _done
.end()) {
128 _done
.insert(frameAdvance
);
130 saveImage(r
, boost::lexical_cast
<std::string
>(frameAdvance
));
136 /// Request a list of frames to be rendered to image files.
137 void setFrames(const FrameList
& frames
);
141 /// Take the screenshot.
142 void saveImage(const Renderer
& r
, const std::string
& filename
) const;
144 /// If true, the next call to screenshot will take a screenshot
147 /// Name used to generate output file.
148 const std::string _fileName
;
150 /// Whether to take a screenshot on the last frame.
155 const FileType _type
;
163 } // end of gnash namespace
169 // indent-tabs-mode: nil