gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash/backend render_handler_ogl.cpp


From: Vitaly Alexeev
Subject: [Gnash-commit] gnash/backend render_handler_ogl.cpp
Date: Mon, 21 Aug 2006 13:28:34 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Vitaly Alexeev <alexeev>        06/08/21 13:28:33

Modified files:
        backend        : render_handler_ogl.cpp 

Log message:
        attempting to do multithread opengl

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/render_handler_ogl.cpp?cvsroot=gnash&r1=1.14&r2=1.15

Patches:
Index: render_handler_ogl.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/render_handler_ogl.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- render_handler_ogl.cpp      27 Jul 2006 14:54:43 -0000      1.14
+++ render_handler_ogl.cpp      21 Aug 2006 13:28:33 -0000      1.15
@@ -14,6 +14,10 @@
 
 #include <cstring>
 
+#if defined(_WIN32) || defined(WIN32)
+#      include <Windows.h>
+#endif
+
 using namespace gnash;
 
 // choose the resampling method:
@@ -45,6 +49,8 @@
            glDeleteTextures(1, (GLuint*) &m_texture_id);
        }
     }
+
+       virtual void layout_image(image::image_base* im);
 };
 
 struct render_handler_ogl : public gnash::render_handler
@@ -117,7 +123,7 @@
        };
        mode    m_mode;
        gnash::rgba     m_color;
-       const gnash::bitmap_info*       m_bitmap_info;
+       gnash::bitmap_info*     m_bitmap_info;
        gnash::matrix   m_bitmap_matrix;
        gnash::cxform   m_bitmap_color_transform;
        bool    m_has_nonzero_bitmap_additive_color;
@@ -160,6 +166,15 @@
                            );
                    }
                    
+                               if (m_bitmap_info->m_texture_id == 0 && 
m_bitmap_info->m_suspended_image != NULL)
+                               {
+                                       
m_bitmap_info->layout_image(m_bitmap_info->m_suspended_image);
+                                       delete m_bitmap_info->m_suspended_image;
+                                       m_bitmap_info->m_suspended_image = NULL;
+                               }
+
+                               assert(m_bitmap_info->m_texture_id);
+
                    glBindTexture(GL_TEXTURE_2D, m_bitmap_info->m_texture_id);
                    glEnable(GL_TEXTURE_2D);
                    glEnable(GL_TEXTURE_GEN_S);
@@ -243,7 +258,7 @@
        void    set_bitmap(const gnash::bitmap_info* bi, const gnash::matrix& 
m, bitmap_wrap_mode wm, const gnash::cxform& color_transform)
            {
                m_mode = (wm == WRAP_REPEAT) ? BITMAP_WRAP : BITMAP_CLAMP;
-               m_bitmap_info = bi;
+               m_bitmap_info = (gnash::bitmap_info*) bi;
                m_bitmap_matrix = m;
                m_bitmap_color_transform = color_transform;
                m_bitmap_color_transform.clamp();
@@ -685,6 +700,15 @@
            d.m_x = b.m_x + c.m_x - a.m_x;
            d.m_y = b.m_y + c.m_y - a.m_y;
 
+                       if (bi->m_texture_id == 0 && bi->m_suspended_image != 
NULL)
+                       {
+                               ((bitmap_info*) 
bi)->layout_image(bi->m_suspended_image);
+                               delete bi->m_suspended_image;
+                               ((bitmap_info*) bi)->m_suspended_image = NULL;
+                       }
+
+                       assert(bi->m_texture_id);
+
            glBindTexture(GL_TEXTURE_2D, bi->m_texture_id);
            glEnable(GL_TEXTURE_2D);
            glDisable(GL_TEXTURE_GEN_S);
@@ -954,61 +978,15 @@
     m_original_height = 0;
 }
 
-
-bitmap_info_ogl::bitmap_info_ogl(int width, int height, uint8_t* data)
-// Initialize this bitmap_info to an alpha image
-// containing the specified data (1 byte per texel).
-//
-// !! Munges *data in order to create mipmaps !!
+void bitmap_info_ogl::layout_image(image::image_base* im)
 {
-//    GNASH_REPORT_FUNCTION;
-    assert(width > 0);
-    assert(height > 0);
-    assert(data);
-
-    m_texture_id = 0;
-       
-    // Create the texture.
 
-    glEnable(GL_TEXTURE_2D);
-    glGenTextures(1, (GLuint*)&m_texture_id);
-    glBindTexture(GL_TEXTURE_2D, m_texture_id);
-
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  // 
GL_NEAREST ?
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
GL_LINEAR_MIPMAP_LINEAR);
-
-    m_original_width = width;
-    m_original_height = height;
-
-#ifndef NDEBUG
-    // You must use power-of-two dimensions!!
-    int        w = 1; while (w < width) { w <<= 1; }
-    int        h = 1; while (h < height) { h <<= 1; }
-    assert(w == width);
-    assert(h == height);
-#endif // not NDEBUG
-
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, 
GL_UNSIGNED_BYTE, data);
-
-    // Build mips.
-    int        level = 1;
-    while (width > 1 || height > 1)
-       {
-           render_handler_ogl::make_next_miplevel(&width, &height, data);
-           glTexImage2D(GL_TEXTURE_2D, level, GL_ALPHA, width, height, 0, 
GL_ALPHA, GL_UNSIGNED_BYTE, data);
-           level++;
-       }
-}
-
-
-bitmap_info_ogl::bitmap_info_ogl(image::rgb* im)
-// NOTE: This function destroys im's data in the process of making mipmaps.
-{
-//    GNASH_REPORT_FUNCTION;
     assert(im);
 
+       switch (im->m_type)
+       {
+               case image::image_base::RGB:
+               {
     // Create the texture.
 
     glEnable(GL_TEXTURE_2D);
@@ -1018,11 +996,11 @@
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-#if GENERATE_MIPMAPS
+       #if GENERATE_MIPMAPS
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
GL_LINEAR_MIPMAP_LINEAR);
-#else
+       #else
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-#endif
+       #endif
 
     m_original_width = im->m_width;
     m_original_height = im->m_height;
@@ -1030,10 +1008,9 @@
     int        w = 1; while (w < im->m_width) { w <<= 1; }
     int        h = 1; while (h < im->m_height) { h <<= 1; }
 
-    if (w != im->m_width
-       || h != im->m_height)
+                       if (w != im->m_width    || h != im->m_height)
        {
-#if (RESAMPLE_METHOD == 1)
+       #if (RESAMPLE_METHOD == 1)
            int viewport_dim[2] = { 0, 0 };
            glGetIntegerv(GL_MAX_VIEWPORT_DIMS, &viewport_dim[0]);
            if (w > viewport_dim[0]
@@ -1050,12 +1027,12 @@
                {
                    hardware_resample(3, im->m_width, im->m_height, im->m_data, 
w, h);
                }
-#elif (RESAMPLE_METHOD == 2)
+       #elif (RESAMPLE_METHOD == 2)
            {
                // Faster/simpler software bilinear rescale.
                software_resample(3, im->m_width, im->m_height, im->m_pitch, 
im->m_data, w, h);
            }
-#else
+       #else
            {
                // Fancy but slow software resampling.
                image::rgb*     rescaled = image::create_rgb(w, h);
@@ -1063,31 +1040,27 @@
                                im, 0, 0, (float) im->m_width, (float) 
im->m_height);
 
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, 
GL_UNSIGNED_BYTE, rescaled->m_data);
-#if GENERATE_MIPMAPS
+       #if GENERATE_MIPMAPS
                generate_mipmaps(GL_RGB, GL_RGB, 3, rescaled);
-#endif // GENERATE_MIPMAPS
+       #endif // GENERATE_MIPMAPS
 
                delete rescaled;
            }
-#endif
+       #endif
        }
     else
        {
            // Use original image directly.
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, 
GL_UNSIGNED_BYTE, im->m_data);
-#if GENERATE_MIPMAPS
+       #if GENERATE_MIPMAPS
            generate_mipmaps(GL_RGB, GL_RGB, 3, im);
-#endif // GENERATE_MIPMAPS
+       #endif // GENERATE_MIPMAPS
        }
-}
-
 
-bitmap_info_ogl::bitmap_info_ogl(image::rgba* im)
-// Version of the constructor that takes an image with alpha.
-// NOTE: This function destroys im's data in the process of making mipmaps.
-{
-//    GNASH_REPORT_FUNCTION;
-    assert(im);
+                       break;
+               }
+               case image::image_base::RGBA:
+               {
 
     // Create the texture.
 
@@ -1098,11 +1071,11 @@
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  // 
GL_NEAREST ?
-#if GENERATE_MIPMAPS
+       #if GENERATE_MIPMAPS
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
GL_LINEAR_MIPMAP_LINEAR);
-#else
+       #else
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-#endif
+       #endif
 
     m_original_width = im->m_width;
     m_original_height = im->m_height;
@@ -1110,10 +1083,9 @@
     int        w = 1; while (w < im->m_width) { w <<= 1; }
     int        h = 1; while (h < im->m_height) { h <<= 1; }
 
-    if (w != im->m_width
-       || h != im->m_height)
+                       if (w != im->m_width    || h != im->m_height)
        {
-#if (RESAMPLE_METHOD == 1)
+       #if (RESAMPLE_METHOD == 1)
            int viewport_dim[2] = { 0, 0 };
            glGetIntegerv(GL_MAX_VIEWPORT_DIMS, &viewport_dim[0]);
            if (w > viewport_dim[0]
@@ -1130,12 +1102,12 @@
                {
                    hardware_resample(4, im->m_width, im->m_height, im->m_data, 
w, h);
                }
-#elif (RESAMPLE_METHOD == 2)
+       #elif (RESAMPLE_METHOD == 2)
            {
                // Faster/simpler software bilinear rescale.
                software_resample(4, im->m_width, im->m_height, im->m_pitch, 
im->m_data, w, h);
            }
-#else
+       #else
            {
                // Fancy but slow software resampling.
                image::rgba*    rescaled = image::create_rgba(w, h);
@@ -1143,22 +1115,169 @@
                                im, 0, 0, (float) im->m_width, (float) 
im->m_height);
 
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, 
GL_UNSIGNED_BYTE, rescaled->m_data);
-#if GENERATE_MIPMAPS
+       #if GENERATE_MIPMAPS
                generate_mipmaps(GL_RGBA, GL_RGBA, 4, rescaled);
-#endif // GENERATE_MIPMAPS
+       #endif // GENERATE_MIPMAPS
 
                delete rescaled;
            }
-#endif
+       #endif
        }
     else
        {
            // Use original image directly.
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, 
GL_UNSIGNED_BYTE, im->m_data);
-#if GENERATE_MIPMAPS
+       #if GENERATE_MIPMAPS
            generate_mipmaps(GL_RGBA, GL_RGBA, 4, im);
-#endif // GENERATE_MIPMAPS
+       #endif // GENERATE_MIPMAPS
+               }
+
+                       break;
+               }
+               case image::image_base::ROW:
+               {
+
+                       // Create the texture.
+
+                       glEnable(GL_TEXTURE_2D);
+                       glGenTextures(1, (GLuint*)&m_texture_id);
+                       glBindTexture(GL_TEXTURE_2D, m_texture_id);
+
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, 
GL_CLAMP_TO_EDGE);
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 
GL_CLAMP_TO_EDGE);
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 
GL_LINEAR);       // GL_NEAREST ?
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
GL_LINEAR_MIPMAP_LINEAR);
+
+                       m_original_width = im->m_width;
+                       m_original_height = im->m_height;
+
+       #ifndef NDEBUG
+                       // You must use power-of-two dimensions!!
+                       int     w = 1; while (w < im->m_width) { w <<= 1; }
+                       int     h = 1; while (h < im->m_height) { h <<= 1; }
+                       assert(w == im->m_width);
+                       assert(h == im->m_height);
+       #endif // not NDEBUG
+
+                       glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA,
+                               im->m_width, im->m_height, 0, GL_ALPHA, 
GL_UNSIGNED_BYTE, im->m_data);
+
+                       // Build mips.
+                       int     level = 1;
+                       while (im->m_width > 1 || im->m_height > 1)
+               {
+                               
render_handler_ogl::make_next_miplevel(&im->m_width, &im->m_height, im->m_data);
+                               glTexImage2D(GL_TEXTURE_2D, level, GL_ALPHA, 
+                                       im->m_width, im->m_height, 0, GL_ALPHA, 
GL_UNSIGNED_BYTE, im->m_data);
+                               level++;
+               }
+
+                       break;
+               }
+
+               default:
+                       printf("unsupported image type\n");
+                       break;
+       }
+
+}
+
+bool opengl_accessible()
+{
+#if defined(_WIN32) || defined(WIN32)
+       return wglGetCurrentContext() != 0;
+#else
+       return true;    //todo for LINUX
+#endif
+       return false;
+}
+
+bitmap_info_ogl::bitmap_info_ogl(int width, int height, uint8_t* data)
+// Initialize this bitmap_info to an alpha image
+// containing the specified data (1 byte per texel).
+//
+// !! Munges *data in order to create mipmaps !!
+{
+//    GNASH_REPORT_FUNCTION;
+       assert(width > 0);
+       assert(height > 0);
+       assert(data);
+
+       if (opengl_accessible() == false) 
+       {
+               m_suspended_image = new image::image_base(data, width, height, 
1, image::image_base::ROW);
+               memcpy(m_suspended_image->m_data, data, width * height);
+               return;
+       }
+
+//     layout_image(width, height, data);
+                       // Create the texture.
+
+                       glEnable(GL_TEXTURE_2D);
+                       glGenTextures(1, (GLuint*)&m_texture_id);
+                       glBindTexture(GL_TEXTURE_2D, m_texture_id);
+
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, 
GL_CLAMP_TO_EDGE);
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 
GL_CLAMP_TO_EDGE);
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 
GL_LINEAR);       // GL_NEAREST ?
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
GL_LINEAR_MIPMAP_LINEAR);
+
+                       m_original_width = width;
+                       m_original_height = height;
+
+       #ifndef NDEBUG
+                       // You must use power-of-two dimensions!!
+                       int     w = 1; while (w < width) { w <<= 1; }
+                       int     h = 1; while (h < height) { h <<= 1; }
+                       assert(w == width);
+                       assert(h == height);
+       #endif // not NDEBUG
+
+                       glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA,
+                               width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, 
data);
+
+                       // Build mips.
+                       int     level = 1;
+                       while (width > 1 || height > 1)
+               {
+                               render_handler_ogl::make_next_miplevel(&width, 
&height, data);
+                               glTexImage2D(GL_TEXTURE_2D, level, GL_ALPHA, 
width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data);
+                               level++;
+               }
+
+}
+
+
+bitmap_info_ogl::bitmap_info_ogl(image::rgb* im)
+// NOTE: This function destroys im's data in the process of making mipmaps.
+{
+//    GNASH_REPORT_FUNCTION;
+       assert(im);
+
+       if (opengl_accessible() == false) 
+       {
+               m_suspended_image = image::create_rgb(im->m_width, 
im->m_height);
+               memcpy(m_suspended_image->m_data, im->m_data, im->m_pitch * 
im->m_height);
+               return;
+       }
+       layout_image(im);
+}
+
+
+bitmap_info_ogl::bitmap_info_ogl(image::rgba* im)
+// Version of the constructor that takes an image with alpha.
+// NOTE: This function destroys im's data in the process of making mipmaps.
+{
+//    GNASH_REPORT_FUNCTION;
+       assert(im);
+
+       if (opengl_accessible() == false) 
+       {
+               m_suspended_image = image::create_rgba(im->m_width, 
im->m_height);
+               memcpy(m_suspended_image->m_data, im->m_data, im->m_pitch * 
im->m_height);
+               return;
        }
+       layout_image(im);
 }
 
 




reply via email to

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