Gnash  0.8.11dev
ScreenShotter.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software Foundation, Inc
4 //
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.
9 //
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.
14 //
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
18 
19 #ifndef GNASH_SCREENSHOT_H
20 #define GNASH_SCREENSHOT_H
21 
22 #include <vector>
23 #include <string>
24 #include <set>
25 #include <algorithm>
26 
27 #include "GnashEnums.h"
28 
29 namespace gnash {
30  class Renderer;
31 }
32 
33 namespace gnash {
34 
37 {
38 public:
39 
40  typedef std::vector<size_t> FrameList;
41 
43  ScreenShotter(const std::string& fileName, int quality = 100);
44 
46  ScreenShotter(std::string fileName, FileType f, int quality = 100);
47 
49 
51  void now() {
52  _immediate = true;
53  }
54 
56  void lastFrame() {
57  _last = true;
58  }
59 
60  struct NoAction { void operator()() const {} };
61 
63  //
65  //
70  void last(const Renderer& r) const {
71  last<NoAction>(r);
72  }
73 
75  //
79  //
84  template<typename Action>
85  void last(const Renderer& r, Action* t = 0) const
86  {
87  if (_last) {
88  if (t) (*t)();
89  saveImage(r, "last");
90  }
91  }
92 
94  //
96  //
100  void screenShot(const Renderer& r, size_t frameAdvance) {
101  screenShot<NoAction>(r, frameAdvance);
102  }
103 
105  //
108  //
114  template<typename Action>
115  void screenShot(const Renderer& r, size_t frameAdvance, Action* t = 0) {
116  // Save an image if a spontaneous screenshot was requested or the
117  // frame is in the list of requested frames.
118  if (_immediate || std::binary_search(_frames.begin(), _frames.end(),
119  frameAdvance)) {
120 
121  // Check whether we've rendered an image for this frame.
122  if (_done.find(frameAdvance) != _done.end()) {
123  return;
124  }
125  if (t) (*t)();
126  _done.insert(frameAdvance);
127 
128  saveImage(r, std::to_string(frameAdvance));
129  _immediate = false;
130  }
131 
132  }
133 
135  void setFrames(const FrameList& frames);
136 
137 private:
138 
140  void saveImage(const Renderer& r, const std::string& filename) const;
141 
143  bool _immediate;
144 
146  const std::string _fileName;
147 
149  bool _last;
150 
151  FrameList _frames;
152 
153  const FileType _type;
154 
155  const int _quality;
156 
157  std::set<int> _done;
158 
159 };
160 
161 } // end of gnash namespace
162 
163 #endif
164 
165 // Local Variables:
166 // mode: C++
167 // indent-tabs-mode: nil
168 // End:
FileType
Definition: GnashEnums.h:25
Definition: ScreenShotter.h:60
void lastFrame()
Take a screenshot when the last frame is reached.
Definition: ScreenShotter.h:56
ScreenShotter(const std::string &fileName, int quality=100)
Create a ScreenShotter with output type selected from filename.
Definition: ScreenShotter.cpp:61
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
Definition: GnashKey.h:152
void setFrames(const FrameList &frames)
Request a list of frames to be rendered to image files.
Definition: ScreenShotter.cpp:104
Base class for render handlers.
Definition: Renderer.h:188
std::vector< size_t > FrameList
Definition: ScreenShotter.h:40
void now()
Take a screenshot at the next possible moment.
Definition: ScreenShotter.h:51
void last(const Renderer &r, Action *t=0) const
To be called on the last frame before exit.
Definition: ScreenShotter.h:85
Definition: GnashKey.h:164
Definition: GnashKey.h:166
void screenShot(const Renderer &r, size_t frameAdvance)
Takes a screenshot if required.
Definition: ScreenShotter.h:100
Handles screen dumps.
Definition: ScreenShotter.h:36
void last(const Renderer &r) const
To be called on the last frame before exit.
Definition: ScreenShotter.h:70
~ScreenShotter()
Definition: ScreenShotter.cpp:82
void operator()() const
Definition: ScreenShotter.h:60
void screenShot(const Renderer &r, size_t frameAdvance, Action *t=0)
Takes a screenshot if required.
Definition: ScreenShotter.h:115