=== modified file 'gui/sdl.cpp'
--- gui/sdl.cpp	2009-02-25 22:33:03 +0000
+++ gui/sdl.cpp	2009-05-17 17:07:23 +0000
@@ -223,6 +223,12 @@
 }
 
 void
+SDLGui::setInvalidatedRegions(const InvalidatedRanges& ranges)
+{
+    _glue.setInvalidatedRegions(ranges);
+}
+
+void
 SDLGui::renderBuffer()
 {
     //GNASH_REPORT_FUNCTION;

=== modified file 'gui/sdl_agg_glue.cpp'
--- gui/sdl_agg_glue.cpp	2009-02-25 22:33:03 +0000
+++ gui/sdl_agg_glue.cpp	2009-05-17 17:20:49 +0000
@@ -143,21 +143,42 @@
     _sdl_surface = SDL_CreateRGBSurfaceFrom((void *) _offscreenbuf, width, height,
                                            _bpp, stride, rmask, gmask, bmask, amask);
     assert(_sdl_surface);
-
+    
+    _validbounds.setTo(0, 0, width-1, height-1);
+    
     return true;
 }
 
+/// Modified from fb_gui
+void
+SdlAggGlue::setInvalidatedRegions(const InvalidatedRanges& ranges)
+{
+    _agg_renderer->set_invalidated_regions(ranges);
+    _drawbounds.clear();
+    
+    for (unsigned int rno=0; rno<ranges.size(); rno++) {
+        geometry::Range2d<int> bounds = Intersection(
+            // twips changed to pixels here
+            _agg_renderer->world_to_pixel(ranges.getRange(rno)),
+            _validbounds);
+            
+        // it may happen that a particular range is out of the screen, which
+        // will lead to bounds==null.
+        if (bounds.isNull()) continue;
+        _drawbounds.push_back(bounds);
+    }
+}
+
 void
 SdlAggGlue::render()
 {
-    rect bounds;
-    bounds.set_world();
+    if ( _drawbounds.size() == 0 ) return; // nothing to do..
     
-    _agg_renderer->set_invalidated_region(bounds);
-
-	// Update the entire screen
-	SDL_BlitSurface(_sdl_surface, 0, _screen, 0);
-	SDL_UpdateRect(_screen, 0, 0, 0, 0);
+    for (unsigned int bno=0; bno < _drawbounds.size(); bno++) {
+        geometry::Range2d<int>& bounds = _drawbounds[bno];
+        render(bounds.getMinX(), bounds.getMinY(),
+            bounds.getMaxX(), bounds.getMaxY() );
+    }
 }
 
 void
@@ -167,7 +188,7 @@
 	SDL_Rect clip = { minx, miny, maxx - minx, maxy - miny };
 	SDL_SetClipRect(_screen, &clip);
 	SDL_BlitSurface(_sdl_surface, 0, _screen, 0);
-	SDL_UpdateRect(_sdl_surface, clip.x, clip.y, clip.w, clip.h);
+	SDL_UpdateRect(_screen, clip.x, clip.y, clip.w, clip.h);
 }
 
 } // namespace gnash

=== modified file 'gui/sdl_agg_glue.h'
--- gui/sdl_agg_glue.h	2009-02-25 22:33:03 +0000
+++ gui/sdl_agg_glue.h	2009-05-17 17:11:13 +0000
@@ -31,6 +31,7 @@
 
     bool init(int argc, char **argv[]);
     render_handler* createRenderHandler(int depth);
+    void setInvalidatedRegions(const InvalidatedRanges& ranges);
     bool prepDrawingArea(int width, int height, boost::uint32_t sdl_flags);
     boost::uint32_t maskFlags(boost::uint32_t sdl_flags);
     void render();
@@ -40,6 +41,9 @@
     unsigned char   *_offscreenbuf;
     SDL_Surface     *_screen;
     render_handler  *_agg_renderer;
+    
+    geometry::Range2d<int> _validbounds;
+    std::vector< geometry::Range2d<int> > _drawbounds;
 };
 
 }

=== modified file 'gui/sdl_cairo_glue.cpp'
--- gui/sdl_cairo_glue.cpp	2009-02-25 22:33:03 +0000
+++ gui/sdl_cairo_glue.cpp	2009-05-17 17:11:34 +0000
@@ -58,6 +58,11 @@
 
 }
 
+/// Not implemented, Fixme
+void
+SdlCairoGlue::setInvalidatedRegions(const InvalidatedRanges& ranges)
+{
+}
 
 bool
 SdlCairoGlue::prepDrawingArea(int width, int height, boost::uint32_t sdl_flags)

=== modified file 'gui/sdl_cairo_glue.h'
--- gui/sdl_cairo_glue.h	2009-02-25 22:33:03 +0000
+++ gui/sdl_cairo_glue.h	2009-05-17 17:11:50 +0000
@@ -31,6 +31,7 @@
 
     bool init(int argc, char **argv[]);
     render_handler* createRenderHandler( int depth);
+    void setInvalidatedRegions(const InvalidatedRanges& ranges);
     bool prepDrawingArea(int width, int height, boost::uint32_t sdl_flags);
     boost::uint32_t maskFlags(boost::uint32_t sdl_flags);
     void render();

=== modified file 'gui/sdl_glue.h'
--- gui/sdl_glue.h	2009-02-25 22:33:03 +0000
+++ gui/sdl_glue.h	2009-05-17 17:12:09 +0000
@@ -16,6 +16,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include "gnash.h"
+#include "gui.h"
 
 #include <boost/cstdint.hpp> // for boost::?int??_t 
 
@@ -27,7 +28,8 @@
   public:
     virtual ~SdlGlue() { }
     virtual bool init(int argc, char **argv[]) = 0;
-
+    
+    virtual void setInvalidatedRegions(const InvalidatedRanges& ranges) = 0;
     virtual bool prepDrawingArea(int width, int height, boost::uint32_t sdl_flags) = 0;
     virtual render_handler* createRenderHandler(int depth) = 0;
     virtual void render() = 0;

=== modified file 'gui/sdl_ogl_glue.cpp'
--- gui/sdl_ogl_glue.cpp	2009-02-25 22:33:03 +0000
+++ gui/sdl_ogl_glue.cpp	2009-05-17 17:12:36 +0000
@@ -78,6 +78,12 @@
     return renderer;
 }
 
+/// Not implemented, Fixme
+void
+SdlOglGlue::setInvalidatedRegions(const InvalidatedRanges& ranges)
+{
+}
+
 bool
 SdlOglGlue::prepDrawingArea(int width, int height, boost::uint32_t sdl_flags)
 {

=== modified file 'gui/sdl_ogl_glue.h'
--- gui/sdl_ogl_glue.h	2009-02-25 22:33:03 +0000
+++ gui/sdl_ogl_glue.h	2009-05-17 17:12:47 +0000
@@ -30,6 +30,7 @@
 
     bool init(int argc, char ***argv);
     render_handler* createRenderHandler( int depth);
+    void setInvalidatedRegions(const InvalidatedRanges& ranges);
     bool prepDrawingArea(int width, int height, boost::uint32_t sdl_flags);
     void render();
   private:

=== modified file 'gui/sdlsup.h'
--- gui/sdlsup.h	2009-02-25 22:33:03 +0000
+++ gui/sdlsup.h	2009-05-17 17:13:02 +0000
@@ -54,6 +54,7 @@
     virtual bool run();
     virtual bool createMenu();
     virtual bool setupEvents();
+    virtual void setInvalidatedRegions(const InvalidatedRanges& ranges);
     virtual void renderBuffer();
     virtual void setInterval(unsigned int interval);
     virtual void disableCoreTrap();

