gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog backend/render_handler_ogl.cpp ...


From: Bastiaan Jacques
Subject: [Gnash-commit] gnash ChangeLog backend/render_handler_ogl.cpp ...
Date: Fri, 02 Nov 2007 20:18:36 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Bastiaan Jacques <bjacques>     07/11/02 20:18:35

Modified files:
        .              : ChangeLog 
        backend        : render_handler_ogl.cpp render_handler_ogl.h 
        server         : gnash.h 
        testsuite      : MovieTester.cpp 

Log message:
                * backend/render_handler_ogl.cpp: Add OSRenderMesa, a class
                implementing OSMesa's offscreen rendering system. Move
                ogl_accessible() to the render_handler_ogl class because it
                now needs access to members of that class. Remove the unused
                get_whole_shapes method. Implement getPixel and friends.
                Please note that this offscreen code is only enabled when
                OSMESA_TESTING is defined, which the build system currently
                does not yet do due to issues described in
                http://gnashdev.org/?q=node/46 .
                * server/gnash.h: Add an optional boolean argument to
                create_render_handler_ogl, which specifies whether the
                factory should immediately run OpenGL initialization code.
                This code should not be run immediately in the OSMesa case,
                since OpenGL calls should not be made until a context is
                available, which is not the case until initTestBuffer is
                called. initTestBuffer, in turn, cannot be called until
                renderer instantiation.
                * testsuite/MovieTester.cpp: Add support for OpenGL renderer
                testing.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4762&r2=1.4763
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/render_handler_ogl.cpp?cvsroot=gnash&r1=1.86&r2=1.87
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/render_handler_ogl.h?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/server/gnash.h?cvsroot=gnash&r1=1.109&r2=1.110
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/MovieTester.cpp?cvsroot=gnash&r1=1.58&r2=1.59

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.4762
retrieving revision 1.4763
diff -u -b -r1.4762 -r1.4763
--- ChangeLog   2 Nov 2007 18:25:33 -0000       1.4762
+++ ChangeLog   2 Nov 2007 20:18:34 -0000       1.4763
@@ -1,3 +1,25 @@
+2007-11-02 Bastiaan Jacques <address@hidden>
+
+       * backend/render_handler_ogl.cpp: Add OSRenderMesa, a class
+       implementing OSMesa's offscreen rendering system. Move
+       ogl_accessible() to the render_handler_ogl class because it
+       now needs access to members of that class. Remove the unused
+       get_whole_shapes method. Implement getPixel and friends.
+       Please note that this offscreen code is only enabled when
+       OSMESA_TESTING is defined, which the build system currently
+       does not yet do due to issues described in 
+       http://gnashdev.org/?q=node/46 .
+       * server/gnash.h: Add an optional boolean argument to
+       create_render_handler_ogl, which specifies whether the
+       factory should immediately run OpenGL initialization code.
+       This code should not be run immediately in the OSMesa case,
+       since OpenGL calls should not be made until a context is
+       available, which is not the case until initTestBuffer is
+       called. initTestBuffer, in turn, cannot be called until
+       renderer instantiation.
+       * testsuite/MovieTester.cpp: Add support for OpenGL renderer
+       testing.
+
 2007-11-02 Sandro Santilli <address@hidden>
 
        * gui/gui.cpp (getMovieInfo): add info about the current active

Index: backend/render_handler_ogl.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/render_handler_ogl.cpp,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -b -r1.86 -r1.87
--- backend/render_handler_ogl.cpp      1 Nov 2007 20:21:55 -0000       1.86
+++ backend/render_handler_ogl.cpp      2 Nov 2007 20:18:35 -0000       1.87
@@ -101,6 +101,76 @@
 
 namespace gnash {
 
+#ifdef OSMESA_TESTING
+
+class OSRenderMesa : public boost::noncopyable
+{
+public:
+  OSRenderMesa(size_t width, size_t height)
+    : _width(width),
+      _height(height),
+      _buffer(new uint8_t[width * height * 3]), 
+#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
+      _context(OSMesaCreateContextExt(OSMESA_RGB, 0, 2, 0, NULL))
+#else
+      _context(OSMesaCreateContext(OSMESA_RGB, NULL))
+#endif
+  {
+    if (!_context) {
+      log_error("OSMesaCreateContext failed!");
+      return; // FIXME: throw an exception?
+    }
+
+    if (!OSMesaMakeCurrent(_context, _buffer.get(), GL_UNSIGNED_BYTE, width,
+                           height)) {
+      log_error("OSMesaMakeCurrent failed!");
+      return;
+    }
+   
+    // FIXME: is there any reason to do this?
+    OSMesaColorClamp(GL_TRUE);
+
+    log_msg("OSMesa handle successfully created. with width " SIZET_FMT \
+            " and height " SIZET_FMT ".", width, height);  
+  }
+  
+  ~OSRenderMesa()
+  {
+    if (!_context) {
+      return;
+    }
+    OSMesaDestroyContext(_context);
+  }
+  
+  bool getPixel(rgba& color_out, int x, int y) const
+  {  
+    glFinish(); // Force pending commands out (and wait until they're done).   
 
+
+    if (x > _width || y > _height) {
+      return false;
+    }
+    
+    ptrdiff_t offset = (_height - y) * (_width * 3) + x * 3;
+    color_out.set(_buffer[offset], _buffer[offset+1], _buffer[offset+2], 255);
+
+    return true;
+  }
+  
+  unsigned int getBitsPerPixel() const
+  {
+    return 24;
+  }
+
+private:
+  size_t _width;
+  size_t _height;
+  boost::scoped_array<uint8_t> _buffer;
+  OSMesaContext _context;  
+};
+
+#endif // OSMESA_TESTING
+
+
 typedef std::vector<path> PathVec;
 
 class oglScopeEnable : public boost::noncopyable
@@ -316,12 +386,13 @@
 }
 
 
-bitmap_info_ogl::bitmap_info_ogl(image::image_base* image, GLenum pixelformat)
+bitmap_info_ogl::bitmap_info_ogl(image::image_base* image, GLenum pixelformat,
+                                 bool ogl_accessible)
 :
   _img(image->clone()),
   _pixel_format(pixelformat),
   _ogl_img_type(_img->height() == 1 ? GL_TEXTURE_1D : GL_TEXTURE_2D),
-  _ogl_accessible(ogl_accessible()),
+  _ogl_accessible(ogl_accessible),
   _texture_id(0),
   _orig_width(_img->width()),
   _orig_height(_img->height())
@@ -339,18 +410,6 @@
   glDisable(_ogl_img_type);
 }
       
-inline bool
-bitmap_info_ogl::ogl_accessible() const
-{
-#if defined(_WIN32) || defined(WIN32)
-  return wglGetCurrentContext();
-#elif defined(__APPLE_CC__)
-  return aglGetCurrentContext();
-#else
-  return glXGetCurrentContext();
-#endif
-}    
-
 void
 bitmap_info_ogl::setup()
 {      
@@ -477,6 +536,10 @@
     : _xscale(1.0),
       _yscale(1.0)
   {
+  }
+  
+  void init()
+  {
     // Turn on alpha blending.
     // FIXME: do this when it's actually used?
     glEnable(GL_BLEND);
@@ -525,6 +588,23 @@
   {
   }
 
+  inline bool
+  ogl_accessible() const
+  {
+#if defined(_WIN32) || defined(WIN32)
+    return wglGetCurrentContext();
+#elif defined(__APPLE_CC__)
+    return aglGetCurrentContext();
+#else
+# ifdef OSMESA_TESTING
+    if (_offscreen.get()) {
+      return OSMesaGetCurrentContext();
+    }
+# endif
+    return glXGetCurrentContext();
+#endif
+  }    
+
 
   virtual bitmap_info*  create_bitmap_info_alpha(int w, int h, unsigned char* 
data)
   {
@@ -534,12 +614,12 @@
 
   virtual bitmap_info*  create_bitmap_info_rgb(image::rgb* im)
   {
-    return new bitmap_info_ogl(im, GL_RGB);
+    return new bitmap_info_ogl(im, GL_RGB, ogl_accessible());
   }
 
   virtual bitmap_info*  create_bitmap_info_rgba(image::rgba* im)
   {
-    return new bitmap_info_ogl(im, GL_RGBA);
+    return new bitmap_info_ogl(im, GL_RGBA, ogl_accessible());
   }
 
   virtual void  delete_bitmap_info(bitmap_info* bi)
@@ -1113,60 +1193,6 @@
     }
   }
 
-
-  std::list<WholeShape> get_whole_shapes(const PathPtrVec &paths)
-  {
-    // First, we create a vector of pointers to the individual paths. This is
-    // intended to allow us to keep track of which paths have already been
-    // used inside a shape.
-    
-    std::list<const path*> path_refs;
-    std::list<WholeShape> shapes;
-
-    for (PathPtrVec::const_iterator it = paths.begin(), end = paths.end();
-         it != end; ++it) {
-      const path* cur_path = *it;
-      path_refs.push_back(cur_path);
-    }
-
-    for (std::list<const path*>::const_iterator it = path_refs.begin(), end = 
path_refs.end();
-         it != end; ++it) {
-      const path* cur_path = *it;
-      
-      if (cur_path->m_edges.empty()) {
-        continue;
-      }
-      
-      if (!cur_path->m_fill0 && !cur_path->m_fill1) {
-        continue;
-      }
-      
-      WholeShape shape;      
-      
-      shape.newPath(*cur_path);    
-        
-      const path* connector = find_connecting_path(*cur_path, path_refs);
-
-      while (connector) {
-        shape.addPath(*connector);        
-        
-        std::list<const path*>::const_iterator iter = it;
-        iter++;
-        
-        connector = find_connecting_path(*connector, std::list<const 
path*>(iter, end));
-  
-        // make sure we don't iterate over the connecting path in the for loop.
-        path_refs.remove(connector);        
-      }
-      
-      shapes.push_back(shape);     
-    }
-    
-    return shapes;
-  }
-  
-  
-  
   std::list<PathPtrVec> get_contours(const PathPtrVec &paths)
   {
     std::list<const path*> path_refs;
@@ -1430,17 +1456,47 @@
     scale.m_y = _yscale;
   }
     
+#ifdef OSMESA_TESTING
+  bool getPixel(rgba& color_out, int x, int y)
+  {  
+    return _offscreen->getPixel(color_out, x, y);
+  }
+  
+  bool initTestBuffer(unsigned width, unsigned height)
+  {
+    GNASH_REPORT_FUNCTION;
+
+    _offscreen.reset(new OSRenderMesa(width, height));
+
+    init();
+    
+    return true;
+  }
+
+  unsigned int getBitsPerPixel() const
+  {
+    return _offscreen->getBitsPerPixel();
+  }
+#endif // OSMESA_TESTING
+    
 
 private:
   Tesselator _tesselator;
   float _xscale;
   float _yscale;
+#ifdef OSMESA_TESTING
+  std::auto_ptr<OSRenderMesa> _offscreen;
+#endif
 }; // class render_handler_ogl
   
-render_handler* create_render_handler_ogl()
+render_handler* create_render_handler_ogl(bool init)
 // Factory.
 {
-  return new render_handler_ogl;
+  render_handler_ogl* renderer = new render_handler_ogl;
+  if (init) {
+    renderer->init();
+  }
+  return renderer;
 }
   
   

Index: backend/render_handler_ogl.h
===================================================================
RCS file: /sources/gnash/gnash/backend/render_handler_ogl.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- backend/render_handler_ogl.h        1 Nov 2007 20:21:55 -0000       1.2
+++ backend/render_handler_ogl.h        2 Nov 2007 20:18:35 -0000       1.3
@@ -30,6 +30,9 @@
 #  define GL_CLAMP_TO_EDGE 0x812F
 # else
 # include <GL/glx.h>
+# ifdef OSMESA_TESTING
+#  include <GL/osmesa.h>
+# endif // OSMESA_TESTING
 # endif
 # include <GL/glu.h>
 # ifndef APIENTRY
@@ -137,7 +140,8 @@
 class bitmap_info_ogl : public bitmap_info
 {
   public:
-    bitmap_info_ogl(image::image_base* image, GLenum pixelformat);
+    bitmap_info_ogl(image::image_base* image, GLenum pixelformat,
+                    bool ogl_accessible);
     ~bitmap_info_ogl();
 
     void apply(const gnash::matrix& bitmap_matrix,

Index: server/gnash.h
===================================================================
RCS file: /sources/gnash/gnash/server/gnash.h,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -b -r1.109 -r1.110
--- server/gnash.h      25 Sep 2007 13:17:58 -0000      1.109
+++ server/gnash.h      2 Nov 2007 20:18:35 -0000       1.110
@@ -153,7 +153,7 @@
 // Some helpers that may or may not be compiled into your
 // version of the library, depending on platform etc.
 DSOEXPORT render_handler*   create_render_handler_xbox();
-DSOEXPORT render_handler*   create_render_handler_ogl();
+DSOEXPORT render_handler*   create_render_handler_ogl(bool init = true);
 //DSOEXPORT render_handler* create_render_handler_cairo(void* cairohandle);
 
 class font;

Index: testsuite/MovieTester.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/MovieTester.cpp,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- testsuite/MovieTester.cpp   29 Oct 2007 20:21:51 -0000      1.58
+++ testsuite/MovieTester.cpp   2 Nov 2007 20:18:35 -0000       1.59
@@ -435,6 +435,8 @@
 
 #ifdef RENDERER_OPENGL
        // Initialize opengl renderer
+       handler.reset(create_render_handler_ogl(false));
+       addTestingRenderer(handler, "OpenGL");
 #endif
 }
 




reply via email to

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