1 // gui.cpp: Top level GUI for SWF player, for Gnash.
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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
22 #include "gnashconfig.h"
25 #include "MovieClip.h"
28 #include "sound_handler.h"
29 #include "movie_root.h"
31 #include "DisplayObject.h"
34 #include "RunResources.h"
36 #ifdef GNASH_FPS_DEBUG
37 #include "ClockTime.h"
38 #include <boost/format.hpp>
45 #include <boost/algorithm/string/replace.hpp>
46 #include <boost/lexical_cast.hpp>
48 /// Define this to make sure each frame is fully rendered from ground up
49 /// even if no motion has been detected in the movie.
50 //#define FORCE_REDRAW 1
52 /// Define this if you want to debug the *detection* of region updates only.
53 /// This will disable region updates for the backend (GUI+renderer) completely
54 /// so that only the last region (red frame) will be visible. However, this
55 /// slows down rendering as each frame is fully re-rendered. If you want to
56 /// debug the GUI part, however (see if blitting the region works), then you
57 /// probably won't define this.
58 #ifndef DISABLE_REGION_UPDATES_DEBUGGING
59 //#define REGION_UPDATES_DEBUGGING_FULL_REDRAW 1
62 #ifndef DISABLE_REGION_UPDATES_DEBUGGING
63 // a runtime check would make the { x; } block conditionally executed
64 #define IF_DEBUG_REGION_UPDATES(x) { if (_showUpdatedRegions) { x } }
66 #define IF_DEBUG_REGION_UPDATES(x)
69 // Define this to have gnash print the mouse pointer coordinates
70 // as the mouse moves. See also ENABLE_KEYBOARD_MOUSE_MOVEMENTS
71 // to have more control over mouse pointer.
73 //#define DEBUG_MOUSE_COORDINATES 1
75 // Define the following macro if you want to skip rendering
76 // when late on FPS time.
77 // This is an experimental feature, so it's off by default
78 //#define SKIP_RENDERING_IF_LATE 1
83 Gui::Gui(RunResources
& r
) :
99 #ifdef GNASH_FPS_DEBUG
101 ,fps_counter_total(0)
103 ,fps_timer_interval(0.0)
110 ,_showUpdatedRegions(false)
112 // NOTE: it's important that _systemClock is constructed
113 // before and destroyed after _virtualClock !
115 ,_virtualClock(_systemClock
)
116 #ifdef ENABLE_KEYBOARD_MOUSE_MOVEMENTS
119 ,_keyboardMouseMovements(true) // TODO: base default on gnashrc or always false and provide menu item to toggle
120 ,_keyboardMouseMovementsStep(1)
126 Gui::Gui(unsigned long xid
, float scale
, bool loop
, RunResources
& r
)
141 _xoffset(0), // TODO: x and y offset will need update !
143 #ifdef GNASH_FPS_DEBUG
145 ,fps_counter_total(0)
147 ,fps_timer_interval(0.0)
154 ,_showUpdatedRegions(false)
156 // NOTE: it's important that _systemClock is constructed
157 // before and destroyed after _virtualClock !
159 ,_virtualClock(_systemClock
)
160 #ifdef ENABLE_KEYBOARD_MOUSE_MOVEMENTS
163 ,_keyboardMouseMovements(true) // TODO: base default on gnashrc or always false and provide menu item to toggle
164 ,_keyboardMouseMovementsStep(1)
171 if ( _movieDef
.get() ) log_debug("~Gui - _movieDef refcount: %d", _movieDef
->get_ref_count());
173 #ifdef GNASH_FPS_DEBUG
174 if ( fps_timer_interval
) {
175 std::cerr
<< "Total frame advances/drops: "
176 << fps_counter_total
<< "/" << frames_dropped
<< std::endl
;
184 log_unimpl(_("Fullscreen not yet supported in this GUI"));
188 Gui::resizeWindow(int /*width*/, int /*height*/)
190 log_unimpl(_("Window resize not yet supported in this GUI"));
194 Gui::unsetFullscreen()
196 log_unimpl(_("Fullscreen not yet supported in this GUI"));
202 log_debug(__PRETTY_FUNCTION__
);
204 // Take a screenshot of the last frame if required.
205 if (_screenShotter
.get()) {
206 _screenShotter
->last();
215 log_unimpl(_("Menu hiding not yet supported in this GUI"));
219 Gui::showMouse(bool /* show */)
221 LOG_ONCE(log_unimpl(_("Mouse show/hide not yet supported in this GUI")));
226 Gui::showMenu(bool /* show */)
228 LOG_ONCE(log_unimpl(_("menushow not yet supported in this GUI")));
232 Gui::allowScale(bool allow
)
235 log_error("Gui::allowScale called before a movie_root was available");
239 if (allow
) _stage
->setStageScaleMode(movie_root::SCALEMODE_SHOWALL
);
240 else _stage
->setStageScaleMode(movie_root::SCALEMODE_NOSCALE
);
244 Gui::toggleFullscreen()
246 /// Sends request to Gnash core to change display state.
248 _stage
->setStageDisplayState(movie_root::DISPLAYSTATE_NORMAL
);
251 _stage
->setStageDisplayState(movie_root::DISPLAYSTATE_FULLSCREEN
);
264 Gui::updateStageMatrix()
266 if ( ! VM::isInitialized() ) {
267 // When VM initializes, we'll get a call to resize_view, which
268 // would call us again.
269 //log_debug("Can't update stage matrix till VM is initialized");
273 assert(_stage
); // when VM is initialized this should hold
275 float swfwidth
= _movieDef
->get_width_pixels();
276 float swfheight
= _movieDef
->get_height_pixels();
279 movie_root::ScaleMode scaleMode
= _stage
->getStageScaleMode();
282 case movie_root::SCALEMODE_NOSCALE
:
283 _xscale
= _yscale
= 1.0f
;
286 case movie_root::SCALEMODE_SHOWALL
:
287 // set new scale value ( user-pixel / pseudo-pixel ). Do
288 // not divide by zero, or we end up with an invalid
289 // stage matrix that returns nan values.
290 _xscale
= (swfwidth
== 0.0f
) ? 1.0f
: _width
/ swfwidth
;
291 _yscale
= (swfheight
== 0.0f
) ? 1.0f
: _height
/ swfheight
;
293 // Scale proportionally, using smallest scale
294 if (_xscale
< _yscale
) {
297 else if (_yscale
< _xscale
) {
302 case movie_root::SCALEMODE_NOBORDER
:
303 // set new scale value ( user-pixel / pseudo-pixel )
304 _xscale
= (swfwidth
== 0.0f
) ? 1.0f
: _width
/ swfwidth
;
305 _yscale
= (swfheight
== 0.0f
) ? 1.0f
: _height
/ swfheight
;
307 // Scale proportionally, using biggest scale
308 if (_xscale
> _yscale
) {
311 else if (_yscale
> _xscale
) {
316 case movie_root::SCALEMODE_EXACTFIT
:
317 // NOTE: changing aspect ratio is valid!
318 _xscale
= (swfwidth
== 0.0f
) ? 1.0f
: _width
/ swfwidth
;
319 _yscale
= (swfheight
== 0.0f
) ? 1.0f
: _height
/ swfheight
;
323 log_error("Invalid scaleMode %d", scaleMode
);
331 movie_root::StageAlign align
= _stage
->getStageAlignment();
332 movie_root::StageHorizontalAlign halign
= align
.first
;
333 movie_root::StageVerticalAlign valign
= align
.second
;
335 // Handle horizontal alignment
337 case movie_root::STAGE_H_ALIGN_L
:
339 // _xoffset=0 is fine
343 case movie_root::STAGE_H_ALIGN_R
:
346 float defWidth
= swfwidth
*= _xscale
;
347 float diffWidth
= _width
-defWidth
;
348 _xoffset
= diffWidth
;
352 case movie_root::STAGE_V_ALIGN_C
:
355 float defWidth
= swfwidth
*= _xscale
;
356 float diffWidth
= _width
-defWidth
;
357 _xoffset
= diffWidth
/2.0;
363 log_error("Invalid horizontal align %d", valign
);
368 // Handle vertical alignment
370 case movie_root::STAGE_V_ALIGN_T
:
372 // _yoffset=0 is fine
376 case movie_root::STAGE_V_ALIGN_B
:
378 float defHeight
= swfheight
*= _yscale
;
379 float diffHeight
= _height
-defHeight
;
380 _yoffset
= diffHeight
;
384 case movie_root::STAGE_V_ALIGN_C
:
386 float defHeight
= swfheight
*= _yscale
;
387 float diffHeight
= _height
-defHeight
;
388 _yoffset
= diffHeight
/2.0;
394 log_error("Invalid vertical align %d", valign
);
399 //log_debug("updateStageMatrix: scaleMode:%d, valign:%d, halign:%d",
400 //scaleMode, valign, halign);
402 // TODO: have a generic set_matrix ?
403 if (_renderer
.get()) {
404 _renderer
->set_scale(_xscale
, _yscale
);
405 _renderer
->set_translation(_xoffset
, _yoffset
);
407 //log_debug("updateStageMatrix: could not signal updated stage
408 //matrix to renderer (no renderer registered)");
412 //_redraw_flag |= (_width!=width) || (_height!=height);
413 _redraw_flag
= true; // this fixes bug #21971
418 Gui::resize_view(int width
, int height
)
424 if ( VM::isInitialized() )
427 if (_stage
&& _started
) {
428 _stage
->setDimensions(width
, height
);
435 _validbounds
.setTo(0, 0, _width
, _height
);
439 if ( _stage
&& _started
) display(_stage
);
447 // @todo since we registered the sound handler, shouldn't we know
448 // already what it is ?!
449 sound::sound_handler
* s
= _stage
->runResources().soundHandler();
453 if (s
->is_muted()) s
->unmute();
459 Gui::notifyMouseMove(int ux
, int uy
)
461 movie_root
* m
= _stage
;
463 if ( ! _started
) return;
465 if ( _stopped
) return;
467 // A stage pseudopixel is user pixel / _xscale wide
468 boost::int32_t x
= (ux
-_xoffset
) / _xscale
;
470 // A stage pseudopixel is user pixel / _xscale high
471 boost::int32_t y
= (uy
-_yoffset
) / _yscale
;
473 #ifdef DEBUG_MOUSE_COORDINATES
474 log_debug(_("mouse @ %d,%d"), x
, y
);
477 if ( m
->mouseMoved(x
, y
) )
479 // any action triggered by the
480 // event required screen refresh
484 DisplayObject
* activeEntity
= m
->getActiveEntityUnderPointer();
487 if ( activeEntity
->isSelectableTextField() )
489 setCursor(CURSOR_INPUT
);
491 else if ( activeEntity
->allowHandCursor() )
493 setCursor(CURSOR_HAND
);
497 setCursor(CURSOR_NORMAL
);
502 setCursor(CURSOR_NORMAL
);
505 #ifdef ENABLE_KEYBOARD_MOUSE_MOVEMENTS
514 Gui::notifyMouseWheel(int delta
)
516 movie_root
* m
= _stage
;
519 if (!_started
) return;
520 if (_stopped
) return;
522 if (m
->mouseWheel(delta
)) {
523 // any action triggered by the
524 // event required screen refresh
530 Gui::notifyMouseClick(bool mouse_pressed
)
532 movie_root
* m
= _stage
;
535 if (!_started
) return;
536 if (_stopped
) return;
538 if (m
->mouseClick(mouse_pressed
)) {
539 // any action triggered by the
540 // event required screen refresh
548 movie_root
* m
= _stage
;
550 if ( ! _started
) return;
559 Gui::notify_key_event(gnash::key::code k
, int modifier
, bool pressed
)
562 /* Handle GUI shortcuts */
564 if (k
== gnash::key::ESCAPE
) {
565 if (isFullscreen()) {
566 _stage
->setStageDisplayState(movie_root::DISPLAYSTATE_NORMAL
);
570 if (modifier
& gnash::key::GNASH_MOD_CONTROL
) {
600 showUpdatedRegions(!showUpdatedRegions());
602 case gnash::key::MINUS
:
604 // Max interval allowed: 1 second (1FPS)
605 const size_t ni
= std::min
<size_t>(_interval
+ 2, 1000u);
609 case gnash::key::PLUS
:
611 // Min interval allowed: 1/100 second (100FPS)
612 const size_t ni
= std::max
<size_t>(_interval
- 2, 10u);
616 case gnash::key::EQUALS
:
619 const float fps
= _stage
->frameRate();
620 // Min interval allowed: 1/100 second (100FPS)
621 const size_t ni
= 1000.0/fps
;
630 #ifdef ENABLE_KEYBOARD_MOUSE_MOVEMENTS
631 if ( _keyboardMouseMovements
) {
632 int step
= _keyboardMouseMovementsStep
;
633 // x5 if SHIFT is pressed
634 if (modifier
& gnash::key::GNASH_MOD_SHIFT
) step
*= 5;
638 int newx
= _xpointer
;
639 int newy
= _ypointer
-step
;
640 if ( newy
< 0 ) newy
=0;
641 notifyMouseMove(newx
, newy
);
644 case gnash::key::DOWN
:
646 int newx
= _xpointer
;
647 int newy
= _ypointer
+step
;
648 if ( newy
>= _height
) newy
= _height
-1;
649 notifyMouseMove(newx
, newy
);
652 case gnash::key::LEFT
:
654 int newx
= _xpointer
-step
;
655 int newy
= _ypointer
;
656 if ( newx
< 0 ) newx
= 0;
657 notifyMouseMove(newx
, newy
);
660 case gnash::key::RIGHT
:
662 const int newy
= _ypointer
;
663 int newx
= _xpointer
+ step
;
664 if ( newx
>= _width
) newx
= _width
-1;
665 notifyMouseMove(newx
, newy
);
672 #endif // ENABLE_KEYBOARD_MOUSE_MOVEMENTS
676 if (!_started
) return;
678 if (_stopped
) return;
680 if (_stage
->keyEvent(k
, pressed
)) {
681 // any action triggered by the
682 // event required screen refresh
689 Gui::display(movie_root
* m
)
691 assert(m
== _stage
); // why taking this arg ??
695 InvalidatedRanges changed_ranges
;
698 // Should the frame be rendered completely, even if it did not change?
702 redraw_flag
= _redraw_flag
|| want_redraw();
705 // reset class member if we do a redraw now
706 if (redraw_flag
) _redraw_flag
=false;
708 // Find out the surrounding frame of all characters which
709 // have been updated. This just checks what region of the stage has changed
710 // due to ActionScript code, the timeline or user events. The GUI can still
711 // choose to render a different part of the stage.
715 // choose snapping ranges factor
716 changed_ranges
.setSnapFactor(1.3f
);
718 // Use multi ranges only when GUI/Renderer supports it
719 // (Useless CPU overhead, otherwise)
720 changed_ranges
.setSingleMode(!want_multiple_regions());
722 // scan through all sprites to compute invalidated bounds
723 m
->add_invalidated_bounds(changed_ranges
, false);
725 // grow ranges by a 2 pixels to avoid anti-aliasing issues
726 changed_ranges
.growBy(40.0f
/ _xscale
);
729 changed_ranges
.combineRanges();
733 // TODO: Remove this and want_redraw to avoid confusion!?
735 changed_ranges
.setWorld();
739 // This is a good place to inspect the invalidated bounds state. Enable
740 // the following block (and parts of it) if you need to.
743 // This may print a huge amount of information, but is useful to analyze
744 // the (visible) object structure of the movie and the flags of the
745 // characters. For example, a characters should have set the
746 // m_child_invalidated flag if at least one of it's childs has the
747 // invalidated flag set.
748 log_debug("DUMPING CHARACTER TREE");
751 InfoTree::iterator top
= tr
.begin();
752 _stage
->getMovieInfo(tr
, top
);
754 for (InfoTree::iterator i
= tr
.begin(), e
= tr
.end();
756 std::cout
<< std::string(tr
.depth(i
) * 2, ' ') << i
->first
<< ": " <<
757 i
->second
<< std::endl
;
761 // less verbose, and often necessary: see the exact coordinates of the
762 // invalidated bounds (mainly to see if it's NULL or something else).
763 std::cout
<< "Calculated changed ranges: " << changed_ranges
<< "\n";
767 // Avoid drawing of stopped movies
768 if ( ! changed_ranges
.isNull() ) // use 'else'?
770 // Tell the GUI(!) that we only need to update this
771 // region. Note the GUI can do whatever it wants with
772 // this information. It may simply ignore the bounds
773 // (which will normally lead into a complete redraw),
774 // or it may extend or shrink the bounds as it likes. So,
775 // by calling set_invalidated_bounds we have no guarantee
776 // that only this part of the stage is rendered again.
777 #ifdef REGION_UPDATES_DEBUGGING_FULL_REDRAW
778 // redraw the full screen so that only the
779 // *new* invalidated region is visible
781 InvalidatedRanges world_ranges
;
782 world_ranges
.setWorld();
783 setInvalidatedRegions(world_ranges
);
785 setInvalidatedRegions(changed_ranges
);
788 // TODO: should this be called even if we're late ?
791 // Render the frame, if not late.
792 // It's up to the GUI/renderer combination
793 // to do any clipping, if desired.
796 // show invalidated region using a red rectangle
797 // (Flash debug style)
798 IF_DEBUG_REGION_UPDATES (
799 if (_renderer
.get() && !changed_ranges
.isWorld())
802 for (size_t rno
= 0; rno
< changed_ranges
.size(); rno
++) {
804 const geometry::Range2d
<int>& bounds
=
805 changed_ranges
.getRange(rno
);
808 float xmin
= bounds
.getMinX();
809 float xmax
= bounds
.getMaxX();
810 float ymin
= bounds
.getMinY();
811 float ymax
= bounds
.getMaxY();
821 SWFMatrix no_transform
;
822 _renderer
->draw_poly(corners
, 4,
823 rgba(0,0,0,0), rgba(255,0,0,255), no_transform
, false);
829 // show frame on screen
840 if ( ! _stopped
) return;
843 if ( ! _started
) start();
847 // @todo since we registered the sound handler, shouldn't we know
848 // already what it is ?!
849 sound::sound_handler
* s
= _stage
->runResources().soundHandler();
850 if ( s
) s
->unpause();
852 log_debug("Starting virtual clock");
853 _virtualClock
.resume();
862 // _stage must be registered before this is called.
865 if ( _stopped
) return;
866 if ( isFullscreen() ) unsetFullscreen();
870 // @todo since we registered the sound handler, shouldn't we know
871 // already what it is ?!
872 sound::sound_handler
* s
= _stage
->runResources().soundHandler();
875 log_debug("Pausing virtual clock");
876 _virtualClock
.pause();
889 // TODO: call stop() instead ?
890 // The only thing I see is that ::stop exits full-screen,
891 // but I'm not sure that's intended behaviour
893 // @todo since we registered the sound handler, shouldn't we know
894 // already what it is ?!
895 sound::sound_handler
* s
= _stage
->runResources().soundHandler();
899 log_debug("Pausing virtual clock");
900 _virtualClock
.pause();
908 assert ( ! _started
);
910 log_debug("Gui is in stop mode, won't start application");
914 // Initializes the stage with a Movie and the passed flash vars and
915 // Scriptable vars for ExternalInterface.
916 _stage
->init(_movieDef
.get(), _flashVars
, _scriptableVars
);
918 bool background
= true; // ??
919 _stage
->set_background_alpha(background
? 1.0f
: 0.05f
);
921 // @todo since we registered the sound handler, shouldn't we know
922 // already what it is ?!
923 sound::sound_handler
* s
= _stage
->runResources().soundHandler();
924 if ( s
) s
->unpause();
927 // to properly update stageMatrix if scaling is given
928 resize_view(_width
, _height
);
930 log_debug("Starting virtual clock");
931 _virtualClock
.resume();
947 gnash::movie_root
* m
= _stage
;
949 // Define REVIEW_ALL_FRAMES to have *all* frames
950 // consequentially displayed. Useful for debugging.
951 //#define REVIEW_ALL_FRAMES 1
953 #ifndef REVIEW_ALL_FRAMES
954 // Advance movie by one frame
955 bool advanced
= m
->advance();
957 const size_t cur_frame
= m
->getRootMovie()->get_current_frame();
958 const size_t tot_frames
= m
->getRootMovie()->get_frame_count();
959 const bool advanced
= m
->advance();
961 m
->getRootMovie
.ensureFrameLoaded(tot_frames
);
962 m
->goto_frame(cur_frame
+ 1);
963 m
->set_play_state(gnash::MovieClip::PLAYSTATE_PLAY
);
964 log_debug(_("Frame %d"), m
->get_current_frame());
967 #ifdef GNASH_FPS_DEBUG
968 // will be a no-op if fps_timer_interval is zero
975 // TODO: ask stage about doDisplay ?
976 // - if it didn't advance might need to check updateAfterEvent
977 bool doDisplay
= true;
979 #ifdef SKIP_RENDERING_IF_LATE
980 // We want to skip rendering IFF it's time to advance again.
981 // We'll ask the stage about it
982 if (_stage
->timeToNextFrame() <= 0) {
984 // or should it be if advanced ?
986 // TODO: take note of a frame drop (count them)
987 //log_debug("Frame rendering dropped due to being late");
988 #ifdef GNASH_FPS_DEBUG
994 #endif // ndef SKIP_RENDERING_IF_LATE
996 if (doDisplay
) display(m
);
999 size_t curframe
= m
->get_current_frame(); // can be 0 on malformed SWF
1000 const gnash::MovieClip
& si
= m
->getRootMovie();
1001 if (curframe
+ 1 >= si
.get_frame_count()) {
1006 if (_screenShotter
.get()) {
1007 _screenShotter
->screenShot(_advances
);
1010 // Only increment advances and check for exit condition when we've
1011 // really changed frame.
1013 /// Quit if we've reached the frame advance limit.
1014 if (_maxAdvances
&& (_advances
> _maxAdvances
)) {
1024 Gui::takeScreenShot()
1026 if (!_screenShotter
.get()) {
1027 // If no ScreenShotter exists, none was requested at startup.
1028 // We use a default filename pattern.
1029 URL
url(_runResources
.baseURL());
1030 std::string::size_type p
= url
.path().rfind('/');
1031 const std::string
& name
= (p
== std::string::npos
) ? url
.path() :
1032 url
.path().substr(p
+ 1);
1033 const std::string
& filename
= "screenshot-" + name
+ "-%f";
1034 _screenShotter
.reset(new ScreenShotter(_renderer
, filename
));
1036 assert (_screenShotter
.get());
1037 _screenShotter
->now();
1041 Gui::requestScreenShots(const ScreenShotter::FrameList
& l
, bool last
,
1042 const std::string
& filename
)
1044 // Nothing to do if there is no renderer or if no frames should be
1046 if (!_renderer
.get() || (l
.empty() && !last
)) {
1050 _screenShotter
.reset(new ScreenShotter(_renderer
, filename
));
1051 if (last
) _screenShotter
->lastFrame();
1052 _screenShotter
->setFrames(l
);
1057 Gui::setCursor(gnash_cursor_type
/*newcursor*/)
1069 Gui::setInvalidatedRegion(const SWFRect
& /*bounds*/)
1075 Gui::setInvalidatedRegions(const InvalidatedRanges
& ranges
)
1077 // fallback to single regions
1078 geometry::Range2d
<int> full
= ranges
.getFullArea();
1082 if (full
.isFinite()) {
1083 bounds
= SWFRect(full
.getMinX(), full
.getMinY(),
1084 full
.getMaxX(), full
.getMaxY());
1086 else if (full
.isWorld()) {
1090 setInvalidatedRegion(bounds
);
1095 std::auto_ptr
<Gui::InfoTree
>
1096 Gui::getMovieInfo() const
1098 std::auto_ptr
<InfoTree
> tr
;
1100 if (! VM::isInitialized()) {
1104 tr
.reset(new InfoTree());
1106 // Top nodes for the tree:
1107 // 1. VM information
1108 // 2. "Stage" information
1111 InfoTree::iterator topIter
= tr
->begin();
1112 InfoTree::iterator firstLevelIter
;
1114 VM
& vm
= _stage
->getVM();
1116 std::ostringstream os
;
1121 os
<< "SWF " << vm
.getSWFVersion();
1122 topIter
= tr
->insert(topIter
, StringPair("VM version", os
.str()));
1124 // This short-cut is to avoid a bug in movie_root's getMovieInfo,
1125 // which relies on the availability of a _rootMovie for doing
1126 // it's work, while we don't set it if we didn't start..
1129 topIter
= tr
->insert(topIter
, StringPair("Stage properties",
1130 "not constructed yet"));
1134 movie_root
& stage
= vm
.getRoot();
1135 stage
.getMovieInfo(*tr
, topIter
);
1140 topIter
= tr
->insert(topIter
, StringPair("Mouse Entities", ""));
1142 const DisplayObject
* ch
;
1143 ch
= stage
.getActiveEntityUnderPointer();
1145 std::stringstream ss
;
1146 ss
<< ch
->getTarget() << " (" + typeName(*ch
)
1147 << " - depth:" << ch
->get_depth()
1148 << " - useHandCursor:" << ch
->allowHandCursor()
1150 firstLevelIter
= tr
->append_child(topIter
, StringPair("Active entity under mouse pointer", ss
.str()));
1153 ch
= stage
.getEntityUnderPointer();
1155 std::stringstream ss
;
1156 ss
<< ch
->getTarget() << " (" + typeName(*ch
)
1157 << " - depth:" << ch
->get_depth()
1159 firstLevelIter
= tr
->append_child(topIter
, StringPair("Topmost entity under mouse pointer", ss
.str()));
1162 ch
= stage
.getDraggingCharacter();
1164 std::stringstream ss
;
1165 ss
<< ch
->getTarget() << " (" + typeName(*ch
)
1166 << " - depth:" << ch
->get_depth() << ")";
1167 firstLevelIter
= tr
->append_child(topIter
, StringPair("Dragging character: ", ss
.str()));
1173 topIter
= tr
->insert(topIter
, StringPair("GC Statistics", ""));
1174 GC::CollectablesCount cc
;
1175 GC::get().countCollectables(cc
);
1177 const std::string lbl
= "GC managed ";
1178 for (GC::CollectablesCount::iterator i
=cc
.begin(), e
=cc
.end(); i
!=e
; ++i
) {
1179 const std::string
& typ
= i
->first
;
1180 std::ostringstream ss
;
1182 firstLevelIter
= tr
->append_child(topIter
,
1183 StringPair(lbl
+ typ
, ss
.str()));
1186 tr
->sort(firstLevelIter
.begin(), firstLevelIter
.end());
1193 #ifdef GNASH_FPS_DEBUG
1195 Gui::fpsCounterTick()
1198 // increment this *before* the early return so that
1199 // frame count on exit is still valid
1200 ++fps_counter_total
;
1202 if (! fps_timer_interval
) {
1206 boost::uint64_t current_timer
= clocktime::getTicks();
1208 // TODO: keep fps_timer_interval in milliseconds to avoid the multiplication
1209 // at each fpsCounterTick call...
1210 boost::uint64_t interval_ms
= (boost::uint64_t)(fps_timer_interval
* 1000.0);
1212 if (fps_counter_total
==1) {
1213 fps_timer
= current_timer
;
1214 fps_start_timer
= current_timer
;
1219 if (current_timer
- fps_timer
>= interval_ms
) {
1221 float secs
= (current_timer
- fps_timer
) / 1000.0;
1222 float secs_total
= (current_timer
- fps_start_timer
)/1000.0;
1224 float rate
= fps_counter
/secs
;
1226 if (secs
> 10000000) {
1227 // the timers are unsigned, so when the clock runs "backwards" it leads
1228 // to a very high difference value. In theory, this should never happen
1229 // with ticks, but it does on my machine (which may have a hw problem?).
1230 std::cerr
<< "Time glitch detected, need to restart FPS counters, sorry..." << std::endl
;
1232 fps_timer
= current_timer
;
1233 fps_start_timer
= current_timer
;
1234 fps_counter_total
= 0;
1239 // first FPS message?
1240 if (fps_timer
== fps_start_timer
) { // they're ints, so we can compare
1241 fps_rate_min
= rate
;
1242 fps_rate_max
= rate
;
1244 fps_rate_min
= std::min
<float>(fps_rate_min
, rate
);
1245 fps_rate_max
= std::max
<float>(fps_rate_max
, rate
);
1248 float avg
= fps_counter_total
/ secs_total
;
1250 //log_debug("Effective frame rate: %0.2f fps", (float)(fps_counter/secs));
1251 std::cerr
<< boost::format("Effective frame rate: %0.2f fps "
1252 "(min %0.2f, avg %0.2f, max %0.2f, "
1253 "%u frames in %0.1f secs total, "
1254 "dropped %u)") % rate
%
1255 fps_rate_min
% avg
% fps_rate_max
%
1256 fps_counter_total
% secs_total
%
1257 frames_dropped
<< std::endl
;
1260 fps_timer
= current_timer
;
1268 Gui::addFlashVars(Gui::VariableMap
& from
)
1270 for (VariableMap::iterator i
=from
.begin(), ie
=from
.end(); i
!=ie
; ++i
) {
1271 _flashVars
[i
->first
] = i
->second
;
1276 Gui::addScriptableVar(const std::string
&name
, const std::string
&value
)
1278 log_debug("Adding scriptable variable \"%s\" = %s",
1280 _scriptableVars
[name
] = value
;
1284 Gui::setMovieDefinition(movie_definition
* md
)
1291 Gui::setStage(movie_root
* stage
)
1299 Gui::yesno(const std::string
& question
)
1301 log_error("This gui didn't override 'yesno', assuming 'yes' answer to "
1302 "question: %s", question
);
1307 Gui::setQuality(Quality q
)
1310 log_error("Gui::setQuality called before a movie_root was available");
1313 _stage
->setQuality(q
);
1317 Gui::getQuality() const
1320 log_error("Gui::getQuality called before a movie_root was available");
1322 return QUALITY_HIGH
;
1324 return _stage
->getQuality();
1328 Gui::setFDCallback(int fd
, boost::function
<void ()> callback
)
1330 log_debug("Setting callback for fd #%d", fd
);
1332 _fd_callbacks
[fd
] = callback
;
1339 Gui::callCallback(int fd
)
1341 std::map
<int, boost::function
<void ()> >::iterator it
= _fd_callbacks
.find(fd
);
1343 if (it
== _fd_callbacks
.end()) {
1344 log_error("Attempted to call a callback for an unregistered fd.");
1348 boost::function
<void()>& f
= it
->second
;
1354 ScreenShotter::saveImage(const std::string
& id
) const
1356 // Replace all "%f" in the filename with the frameAdvance.
1357 std::string
outfile(_fileName
);
1358 boost::replace_all(outfile
, "%f", id
);
1360 FILE* f
= std::fopen(outfile
.c_str(), "wb");
1362 boost::shared_ptr
<IOChannel
> t(new tu_file(f
, true));
1363 _renderer
->renderToImage(t
, GNASH_FILETYPE_PNG
);
1365 log_error("Failed to open screenshot file \"%s\"!", outfile
);
1370 ScreenShotter::screenShot(size_t frameAdvance
)
1372 // Save an image if an spontaneous screenshot was requested or the
1373 // frame is in the list of requested frames.
1374 if (_immediate
|| std::binary_search(_frames
.begin(), _frames
.end(),
1376 saveImage(boost::lexical_cast
<std::string
>(frameAdvance
));
1382 ScreenShotter::last() const
1390 ScreenShotter::setFrames(const FrameList
& frames
)
1393 std::sort(_frames
.begin(), _frames
.end());
1401 // indent-tabs-mode: nil