gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash gui/gtk.cpp gui/gtksup.h gui/Makefile.am ...


From: Hannes Mayr
Subject: [Gnash-commit] gnash gui/gtk.cpp gui/gtksup.h gui/Makefile.am ...
Date: Fri, 13 Oct 2006 16:38:55 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Hannes Mayr <bik>       06/10/13 16:38:55

Modified files:
        gui            : gtk.cpp gtksup.h Makefile.am gtk_glue.h 
        .              : ChangeLog 
Added files:
        gui            : gtk_glue_agg.cpp gtk_glue_agg.h 

Log message:
        Added support for GTK with AGG renderer

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/gui/gtk.cpp?cvsroot=gnash&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/gnash/gui/gtksup.h?cvsroot=gnash&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/gnash/gui/Makefile.am?cvsroot=gnash&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/gnash/gui/gtk_glue.h?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/gui/gtk_glue_agg.cpp?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/gui/gtk_glue_agg.h?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1199&r2=1.1200

Patches:
Index: gui/gtk.cpp
===================================================================
RCS file: /sources/gnash/gnash/gui/gtk.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- gui/gtk.cpp 13 Oct 2006 11:21:28 -0000      1.32
+++ gui/gtk.cpp 13 Oct 2006 16:38:55 -0000      1.33
@@ -45,6 +45,7 @@
 
 #include "gui.h"
 #include "gtksup.h"
+#include "render_handler.h"
 
 #include <iostream>
 #include <X11/keysym.h>
@@ -112,7 +113,7 @@
     gtk_widget_show(_drawing_area);
     gtk_widget_show(_window);
 
-#ifdef RENDERER_CAIRO
+#if defined(RENDERER_CAIRO) || defined(RENDERER_AGG)
     // cairo needs the _drawing_area.window to prepare it ..
     glue.prepDrawingArea(_drawing_area);
 #endif
@@ -209,15 +210,66 @@
     _width = width;
     _height = height;
 
+               glue.setRenderHandlerSize(width, height);
+
     return true;
 }
 
 void
 GtkGui::renderBuffer()
 {
-    glue.render();
+               glue.render(m_draw_minx, m_draw_miny, m_draw_maxx, m_draw_maxy);
+}
+
+int
+GtkGui::valid_coord(int coord, int max)
+{
+       if (coord<0) return 0;
+       else if (coord>=max) return max;
+       return coord;
 }
 
+// for some reason this doesn't work as expected yet. Still working on it.
+#if 0
+void
+GtkGui::set_invalidated_region(const rect& bounds)
+{
+#ifdef RENDERER_AGG
+  // forward to renderer
+  _renderer->set_invalidated_region(bounds);
+
+       log_msg("GtkGui::set_invalidated_region: x1:%0.2f, y1:%0.2f, x2:%0.2f, 
y2:%0.2f\n", \
+               bounds.m_x_min, \
+       bounds.m_y_min, \
+               bounds.m_x_max, \
+               bounds.m_y_max \
+       );
+
+
+  if (bounds.m_x_max - bounds.m_x_min > 1e10f) {
+    // Region is entire screen. Don't convert to integer as this will overflow.
+
+    m_draw_minx=0;
+    m_draw_miny=0;
+    m_draw_maxx=_width-1;
+    m_draw_maxy=_height-1;
+
+  } else {
+
+    // remember for renderBuffer()
+    _renderer->world_to_pixel(&m_draw_minx, &m_draw_miny, bounds.m_x_min, 
bounds.m_y_min);
+    _renderer->world_to_pixel(&m_draw_maxx, &m_draw_maxy, bounds.m_x_max, 
bounds.m_y_max);
+
+    // add two pixels because of anti-aliasing...
+    m_draw_minx = valid_coord(m_draw_minx-2, _width);
+    m_draw_miny = valid_coord(m_draw_miny-2, _height);
+    m_draw_maxx = valid_coord(m_draw_maxx+2, _width);
+    m_draw_maxy = valid_coord(m_draw_maxy+2, _height);
+  }
+#endif
+}
+#endif
+
 void
 GtkGui::setTimeout(unsigned int timeout)
 {
@@ -452,8 +504,8 @@
 
 
 gboolean
-GtkGui::expose_event(GtkWidget *const widget,
-             GdkEventExpose *const event,
+GtkGui::expose_event(GtkWidget *const /*widget*/,
+             GdkEventExpose *const /*event*/,
              const gpointer data)
 {
        GNASH_REPORT_FUNCTION;
@@ -461,6 +513,15 @@
        GtkGui* gui = static_cast<GtkGui*>(data);
 
        // TODO: implement and use set_invalidated_region instead?
+       //gui->renderBuffer();
+       
+       // Set a invalidate region that contains the whole screen
+       rect draw_bounds;
+       draw_bounds.m_x_min = -1e10f;
+       draw_bounds.m_y_min = -1e10f;
+       draw_bounds.m_x_max = +1e10f;
+       draw_bounds.m_y_max = +1e10f;
+       //gui->set_invalidated_region(draw_bounds);
        gui->renderBuffer();
 
        return TRUE;
@@ -503,6 +564,8 @@
     GtkCairoGlue& glue = obj->glue;
 #elif defined(RENDERER_OPENGL)
     GtkGlExtGlue& glue = obj->glue;
+#elif defined(RENDERER_AGG)
+    GtkAggGlue& glue = obj->glue;
 #endif
 
     glue.configure(widget, event);

Index: gui/gtksup.h
===================================================================
RCS file: /sources/gnash/gnash/gui/gtksup.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- gui/gtksup.h        9 Oct 2006 21:00:04 -0000       1.20
+++ gui/gtksup.h        13 Oct 2006 16:38:55 -0000      1.21
@@ -42,6 +42,7 @@
 #include "config.h"
 #endif
 
+#include "gnash.h"
 #include "tu_config.h"
 
 #include <gdk/gdkx.h>
@@ -53,6 +54,8 @@
 #elif defined(RENDERER_CAIRO)
 #include <cairo.h>
 #include "gtk_glue_cairo.h"
+#elif defined(RENDERER_AGG)
+#include "gtk_glue_agg.h"
 #endif
 
 #include <gtk/gtk.h>
@@ -129,17 +132,28 @@
     gchar* find_pixmap_file(const gchar *filename);
 
     GdkPixbuf* create_pixbuf(const gchar     *filename);
+    
+    //void set_invalidated_region(const rect& bounds);
+    
  private:
     GtkWidget   *_window;
     GdkPixbuf *_window_icon_pixbuf;
     GtkWidget   *_drawing_area;    
     GtkMenu     *_popup_menu;
+    int                                m_draw_minx;
+    int                                m_draw_miny;
+    int                                m_draw_maxx;
+    int                                m_draw_maxy;
+    
+       int valid_coord(int coord, int max);
 #ifdef RENDERER_CAIRO
     cairo_t     *_cairo_handle;
     GtkCairoGlue glue;
 #elif defined(RENDERER_OPENGL)
     GdkGLConfig *_glconfig;
     GtkGlExtGlue glue;
+#elif defined(RENDERER_AGG)
+    GtkAggGlue  glue;
 #endif
 
     static gnash::key::code gdk_to_gnash_key(guint key);

Index: gui/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/gui/Makefile.am,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- gui/Makefile.am     11 Oct 2006 21:50:56 -0000      1.31
+++ gui/Makefile.am     13 Oct 2006 16:38:55 -0000      1.32
@@ -96,8 +96,16 @@
  KDE_CAIRO_SRCS =
 endif
 
+if USE_RENDERER_AGG
+  INCLUDES += $(AGG_CFLAGS)
+  AM_LDFLAGS += $(AGG_LIBS)
+  GTK_AGG_SRCS = gtk_glue_agg.cpp gtk_glue_agg.h
+else
+  GTK_AGG_SRCS =
+endif
+
 if USE_GUI_GTK
- GTK_SRCS = gtk.cpp gtksup.h gtk_glue.h $(GTK_CAIRO_SRCS) $(GTK_OPENGL_SRCS)
+ GTK_SRCS = gtk.cpp gtksup.h gtk_glue.h $(GTK_CAIRO_SRCS) $(GTK_OPENGL_SRCS)  
$(GTK_AGG_SRCS)
  AM_LDFLAGS += $(GTK2_LIBS) 
  INCLUDES += $(GTK2_CFLAGS)
 else

Index: gui/gtk_glue.h
===================================================================
RCS file: /sources/gnash/gnash/gui/gtk_glue.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- gui/gtk_glue.h      25 Aug 2006 18:27:01 -0000      1.3
+++ gui/gtk_glue.h      13 Oct 2006 16:38:55 -0000      1.4
@@ -51,7 +51,9 @@
 
     virtual void prepDrawingArea(GtkWidget *drawing_area) = 0;
     virtual render_handler* createRenderHandler() = 0;
+    virtual void setRenderHandlerSize(int width, int height) { };
     virtual void render() = 0;
+    virtual void render(int minx, int miny, int maxx, int maxy) { render(); };
     virtual void configure(GtkWidget *const widget,
                            GdkEventConfigure *const event) = 0;
   protected:

Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1199
retrieving revision 1.1200
diff -u -b -r1.1199 -r1.1200
--- ChangeLog   13 Oct 2006 15:56:33 -0000      1.1199
+++ ChangeLog   13 Oct 2006 16:38:55 -0000      1.1200
@@ -1,3 +1,7 @@
+2006-10-13 Hannes Mayr <address@hidden>
+       * gui/gtk.cpp, gui/gtksup.h, gui/gtk_glue.h, gui/gtk_glue_agg.cpp,
+    gtk_glue_agg.h, Makefile.am: Added support for GTK with AGG renderer.
+
 2006-10-13 Sandro Santilli <address@hidden>
 
        * gui/sdl.cpp, gui/sdlsup.h: added support for expose and

Index: gui/gtk_glue_agg.cpp
===================================================================
RCS file: gui/gtk_glue_agg.cpp
diff -N gui/gtk_glue_agg.cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gui/gtk_glue_agg.cpp        13 Oct 2006 16:38:55 -0000      1.1
@@ -0,0 +1,214 @@
+//
+//   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+// Linking Gnash statically or dynamically with other modules is making a
+// combined work based on Gnash. Thus, the terms and conditions of the GNU
+// General Public License cover the whole combination.
+//
+// As a special exception, the copyright holders of Gnash give you
+// permission to combine Gnash with free software programs or libraries
+// that are released under the GNU LGPL and with code included in any
+// release of Talkback distributed by the Mozilla Foundation. You may
+// copy and distribute such a system following the terms of the GNU GPL
+// for all but the LGPL-covered parts and Talkback, and following the
+// LGPL for the LGPL-covered parts.
+//
+// Note that people who make modified versions of Gnash are not obligated
+// to grant this special exception for their modified versions; it is their
+// choice whether to do so. The GNU General Public License gives permission
+// to release a modified version without this exception; this exception
+// also makes it possible to release a modified version which carries
+// forward this exception.
+//
+//
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <gtk/gtk.h>
+#include <gdk/gdk.h>
+
+#include "gnash.h"
+#include "log.h"
+#include "render_handler.h"
+#include "render_handler_agg.h"
+#include "gtk_glue_agg.h"
+
+namespace gnash
+{
+
+GtkAggGlue::GtkAggGlue()
+{
+}
+
+GtkAggGlue::~GtkAggGlue()
+{
+
+}
+
+bool
+GtkAggGlue::init(int argc, char **argv[])
+{
+    gdk_rgb_init();
+    
+               _offscreenbuf_size      = 0;
+               _offscreenbuf           = NULL;
+               _agg_renderer       = NULL;
+               _width                  = 0;
+               _height                 = 0;
+               _bpp                    = 0;
+    
+    return true;
+}
+
+void
+GtkAggGlue::prepDrawingArea(GtkWidget *drawing_area)
+{
+    _drawing_area = drawing_area;
+    
+    gtk_widget_get_size_request(_drawing_area, &_width, &_height);
+
+    _width     = (_width == -1) ? 0 : _width;
+    _height    = (_height == -1) ? 0 : _height;
+    _bpp               = gdk_visual_get_best_depth();
+
+}
+
+render_handler*
+GtkAggGlue::createRenderHandler()
+{
+    char bppformat[6] = {0,};
+
+               switch(_bpp) {
+       case 8:
+               strncpy(bppformat, "RGB8", sizeof(bppformat));
+               break;
+       case 16:
+               strncpy(bppformat, "RGB16", sizeof(bppformat));
+               break;
+       case 24:
+               strncpy(bppformat, "RGB24", sizeof(bppformat));
+               break;
+       case 32:
+               strncpy(bppformat, "RGB32", sizeof(bppformat));
+               break;
+       default:
+               log_error("%i bits per pixel not supported by the AGG 
renderer!\n", _bpp);
+               return NULL;
+    }
+
+               log_msg("GTK-AGG: Create renderer with pixelformat %s\n", 
bppformat);
+               _agg_renderer = create_render_handler_agg(
+       bppformat
+    );
+    return _agg_renderer;
+}
+
+void
+GtkAggGlue::setRenderHandlerSize(int width, int height)
+{
+       assert(width>0);
+       assert(height>0);
+       assert(_agg_renderer!=NULL);
+
+       #define CHUNK_SIZE (100*100*(_bpp/8))
+
+       if (width == _width && height == _height)
+          return;
+          
+       int new_bufsize = width*height*(_bpp/8);
+       
+       // TODO: At the moment we only increase the buffer and never decrease 
it. Should be
+       // changed sometime.
+       if (new_bufsize > _offscreenbuf_size) {
+               new_bufsize = (int)(new_bufsize / CHUNK_SIZE + 1) * CHUNK_SIZE;
+               _offscreenbuf   = (unsigned char *)realloc(_offscreenbuf, 
new_bufsize);
+          
+               if (!_offscreenbuf) {
+                 log_msg("Could not allocate %i bytes for offscreen buffer: 
%s\n",
+                               new_bufsize, strerror(errno)
+                       );
+                       return;
+               }
+               log_msg("GTK-AGG: %i bytes offscreen buffer allocated\n", 
new_bufsize);
+               _offscreenbuf_size = new_bufsize;
+       }
+
+  _width = width;
+       _height = height;
+
+       ((render_handler_agg_base *)_agg_renderer)->init_buffer(
+         _offscreenbuf,
+               _offscreenbuf_size,
+               _width,
+               _height
+       );
+}
+
+void
+GtkAggGlue::render()
+{
+       gdk_draw_rgb_image (
+               _drawing_area->window,
+               _drawing_area->style->fg_gc[GTK_STATE_NORMAL],
+               0,
+               0,
+               _width,
+               _height,
+               GDK_RGB_DITHER_MAX,
+               _offscreenbuf,
+               (int)(_width*_bpp/8)
+       );
+}
+
+void
+GtkAggGlue::render(int minx, int miny, int maxx, int maxy)
+{
+       render();
+
+       /*
+       log_msg("Gtk-AGG: render invalidated_region: x:%i, y:%i, w:%i, h:%i\n", 
\
+               minx, \
+       miny, \
+               maxx-minx, \
+               maxy-miny \
+       );
+
+       gdk_draw_rgb_image (
+               _drawing_area->window,
+               _drawing_area->style->fg_gc[GTK_STATE_NORMAL],
+               0,
+       miny,
+               _width,
+               maxy-miny,
+               GDK_RGB_DITHER_MAX,
+               _offscreenbuf + miny*(_width*_bpp/8),
+               (int)(_width*_bpp/8)
+       );
+       */
+}
+
+void
+GtkAggGlue::configure(GtkWidget *const widget, GdkEventConfigure *const event)
+{
+       if (_agg_renderer)
+               setRenderHandlerSize(event->width, event->height);
+}
+
+
+
+} // namespace gnash
+

Index: gui/gtk_glue_agg.h
===================================================================
RCS file: gui/gtk_glue_agg.h
diff -N gui/gtk_glue_agg.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gui/gtk_glue_agg.h  13 Oct 2006 16:38:55 -0000      1.1
@@ -0,0 +1,66 @@
+//
+//   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+// Linking Gnash statically or dynamically with other modules is making a
+// combined work based on Gnash. Thus, the terms and conditions of the GNU
+// General Public License cover the whole combination.
+//
+// As a special exception, the copyright holders of Gnash give you
+// permission to combine Gnash with free software programs or libraries
+// that are released under the GNU LGPL and with code included in any
+// release of Talkback distributed by the Mozilla Foundation. You may
+// copy and distribute such a system following the terms of the GNU GPL
+// for all but the LGPL-covered parts and Talkback, and following the
+// LGPL for the LGPL-covered parts.
+//
+// Note that people who make modified versions of Gnash are not obligated
+// to grant this special exception for their modified versions; it is their
+// choice whether to do so. The GNU General Public License gives permission
+// to release a modified version without this exception; this exception
+// also makes it possible to release a modified version which carries
+// forward this exception.
+//
+//
+
+#include "gtk_glue.h"
+
+#include <gtk/gtk.h>
+#include <gdk/gdk.h>
+
+namespace gnash
+{
+
+class GtkAggGlue : public GtkGlue
+{
+  public:
+    GtkAggGlue();
+    ~GtkAggGlue();
+
+    bool init(int argc, char **argv[]);
+    void prepDrawingArea(GtkWidget *drawing_area);
+    render_handler* createRenderHandler();
+    void setRenderHandlerSize(int width, int height);
+    void render();
+    void render(int minx, int miny, int maxx, int maxy);
+    void configure(GtkWidget *const widget, GdkEventConfigure *const event);
+  private:
+    unsigned char *_offscreenbuf;
+    int _offscreenbuf_size;
+    render_handler *_agg_renderer;
+    int _width, _height, _bpp;
+};
+
+} // namespace gnash




reply via email to

[Prev in Thread] Current Thread [Next in Thread]