ooo-build r15054 - in trunk: . patches/test



Author: thorstenb
Date: Mon Jan 12 14:30:19 2009
New Revision: 15054
URL: http://svn.gnome.org/viewvc/ooo-build?rev=15054&view=rev

Log:
    * patches/test/opengl-canvas.diff: added texture caching



Modified:
   trunk/ChangeLog
   trunk/patches/test/opengl-canvas.diff

Modified: trunk/patches/test/opengl-canvas.diff
==============================================================================
--- trunk/patches/test/opengl-canvas.diff	(original)
+++ trunk/patches/test/opengl-canvas.diff	Mon Jan 12 14:30:19 2009
@@ -12,23 +12,25 @@
  canvas/source/null/null_canvashelper.hxx           |    1 
  canvas/source/opengl/exports.dxp                   |    3 
  canvas/source/opengl/exports.map                   |    8 
- canvas/source/opengl/makefile.mk                   |   65 +
+ canvas/source/opengl/makefile.mk                   |   66 +
  canvas/source/opengl/ogl_bitmapcanvashelper.cxx    |  108 ++
  canvas/source/opengl/ogl_bitmapcanvashelper.hxx    |  107 ++
  canvas/source/opengl/ogl_canvasbitmap.cxx          |   63 +
- canvas/source/opengl/ogl_canvasbitmap.hxx          |   82 +
+ canvas/source/opengl/ogl_canvasbitmap.hxx          |   82 ++
  canvas/source/opengl/ogl_canvascustomsprite.cxx    |  154 +++
  canvas/source/opengl/ogl_canvascustomsprite.hxx    |  101 ++
  canvas/source/opengl/ogl_canvasfont.cxx            |   88 ++
  canvas/source/opengl/ogl_canvasfont.hxx            |   72 +
- canvas/source/opengl/ogl_canvashelper.cxx          | 1101 ++++++++++++++++++++
+ canvas/source/opengl/ogl_canvashelper.cxx          | 1092 ++++++++++++++++++++
  canvas/source/opengl/ogl_canvashelper.hxx          |  238 ++++
  canvas/source/opengl/ogl_spritecanvas.cxx          |  202 ++++
  canvas/source/opengl/ogl_spritecanvas.hxx          |  126 ++
- canvas/source/opengl/ogl_spritedevicehelper.cxx    |  760 ++++++++++++++
- canvas/source/opengl/ogl_spritedevicehelper.hxx    |  146 +++
+ canvas/source/opengl/ogl_spritedevicehelper.cxx    |  774 ++++++++++++++
+ canvas/source/opengl/ogl_spritedevicehelper.hxx    |  152 +++
  canvas/source/opengl/ogl_textlayout.cxx            |  222 ++++
  canvas/source/opengl/ogl_textlayout.hxx            |   83 ++
+ canvas/source/opengl/ogl_texturecache.cxx          |   95 ++
+ canvas/source/opengl/ogl_texturecache.hxx          |   45 +
  canvas/source/opengl/ogl_tools.hxx                 |   35 +
  canvas/source/tools/canvastools.cxx                |   10 
  canvas/source/vcl/canvashelper.hxx                 |    1 
@@ -50,7 +52,7 @@
  sdext/source/presenter/PresenterSlideShowView.cxx  |   48 +
  sdext/source/presenter/PresenterSlideShowView.hxx  |    7 
  slideshow/source/engine/waitsymbol.cxx             |   13 
- 45 files changed, 3885 insertions(+), 64 deletions(-)
+ 47 files changed, 4037 insertions(+), 64 deletions(-)
  create mode 100644 canvas/source/opengl/exports.dxp
  create mode 100644 canvas/source/opengl/exports.map
  create mode 100644 canvas/source/opengl/makefile.mk
@@ -70,6 +72,8 @@
  create mode 100644 canvas/source/opengl/ogl_spritedevicehelper.hxx
  create mode 100644 canvas/source/opengl/ogl_textlayout.cxx
  create mode 100644 canvas/source/opengl/ogl_textlayout.hxx
+ create mode 100644 canvas/source/opengl/ogl_texturecache.cxx
+ create mode 100644 canvas/source/opengl/ogl_texturecache.hxx
  create mode 100644 canvas/source/opengl/ogl_tools.hxx
  create mode 100644 scp2/source/canvas/openglcanvas.scp
 
@@ -166,10 +170,10 @@
 +};
 diff --git canvas/source/opengl/makefile.mk canvas/source/opengl/makefile.mk
 new file mode 100644
-index 0000000..59973e6
+index 0000000..c446e16
 --- /dev/null
 +++ canvas/source/opengl/makefile.mk
-@@ -0,0 +1,65 @@
+@@ -0,0 +1,66 @@
 +#*************************************************************************
 +#
 +#    OpenOffice.org - a multi-platform office productivity suite
@@ -209,7 +213,8 @@
 +			$(SLO)$/ogl_canvasbitmap.obj \
 +			$(SLO)$/ogl_bitmapcanvashelper.obj \
 +			$(SLO)$/ogl_canvascustomsprite.obj \
-+			$(SLO)$/ogl_textlayout.obj
++			$(SLO)$/ogl_textlayout.obj \
++			$(SLO)$/ogl_texturecache.obj
 +
 +
 +SHL1TARGET=$(TARGET).uno
@@ -1060,10 +1065,10 @@
 +#endif
 diff --git canvas/source/opengl/ogl_canvashelper.cxx canvas/source/opengl/ogl_canvashelper.cxx
 new file mode 100644
-index 0000000..0e34ca4
+index 0000000..93673db
 --- /dev/null
 +++ canvas/source/opengl/ogl_canvashelper.cxx
-@@ -0,0 +1,1101 @@
+@@ -0,0 +1,1092 @@
 +/*************************************************************************
 + *
 + *    OpenOffice.org - a multi-platform office productivity suite
@@ -1087,6 +1092,7 @@
 +
 +#include "ogl_canvashelper.hxx"
 +
++#include <rtl/crc.h>
 +#include <canvas/debug.hxx>
 +#include <tools/diagnose_ex.h>
 +#include <basegfx/tools/canvastools.hxx>
@@ -1107,6 +1113,7 @@
 +#include "ogl_canvasfont.hxx"
 +#include "ogl_canvasbitmap.hxx"
 +#include "ogl_spritecanvas.hxx"
++#include "ogl_texturecache.hxx"
 +#include "ogl_tools.hxx"
 +
 +#include <GL/gl.h>
@@ -1144,6 +1151,10 @@
 +       server, or even better, vertex buffers, which copy geometry
 +       data over en bloc.
 +
++       Next todo: put polygon geometry into vertex buffer (LRU cache
++       necessary?) - or, rather, buffer objects! prune entries older
++       than one updateScreen() call)
++
 +       Text: http://www.opengl.org/resources/features/fontsurvey/
 +     */
 +
@@ -1405,34 +1416,22 @@
 +            return rBitmap.renderRecordedActions();
 +        }
 +
-+        bool lcl_drawGenericBitmap( const CanvasHelper&              /*rHelper*/,
++        bool lcl_drawGenericBitmap( const CanvasHelper&              rHelper,
 +                                    const ::basegfx::B2DHomMatrix&   rTransform,
 +                                    GLenum                           eSrcBlend,
 +                                    GLenum                           eDstBlend,
 +                                    const rendering::ARGBColor&      rColor,
 +                                    const geometry::IntegerSize2D&   rPixelSize,
-+                                    const uno::Sequence<sal_Int8>&   rPixelData )
++                                    const uno::Sequence<sal_Int8>&   rPixelData,
++                                    sal_uInt32                       nPixelCrc32 )
 +        {
 +            TransformationPreserver aPreserver;
 +            setupState(rTransform, eSrcBlend, eDstBlend, rColor);
 +
-+            // TODO(P3): reuse the texture next time
-+            unsigned int nTexture;
-+            glGenTextures(1, &nTexture);
-+            glBindTexture(GL_TEXTURE_2D, nTexture);
-+
-+            // TODO(E3): handle limited texture sizes -
-+            // glGetIntegerv(GL_MAX_TEXTURE_SIZE)
++            const unsigned int nTexId=rHelper.getDeviceHelper()->getTextureCache().getTexture(
++                rPixelSize, rPixelData.getConstArray(), nPixelCrc32);
 +
-+            glTexImage2D(GL_TEXTURE_2D,
-+                         0,
-+                         4,
-+                         rPixelSize.Width, 
-+                         rPixelSize.Height, 
-+                         0,
-+                         GL_RGBA, 
-+                         GL_UNSIGNED_INT_8_8_8_8_REV,
-+                         &rPixelData[0]);
++            glBindTexture(GL_TEXTURE_2D, nTexId);
 +            glEnable(GL_TEXTURE_2D);
 +            glTexParameteri(GL_TEXTURE_2D,
 +                            GL_TEXTURE_MIN_FILTER,
@@ -1454,40 +1453,29 @@
 +            glTexCoord2f(1,1); glVertex2d(rPixelSize.Width,rPixelSize.Height);
 +            glEnd();
 +
-+            glDeleteTextures(1, &nTexture);
++            glBindTexture(GL_TEXTURE_2D, 0);
++            glDisable(GL_TEXTURE_2D);
 +
 +            return true;
 +        }
 +
-+        bool lcl_fillBitmappedPolyPolygon( const CanvasHelper&                    /*rHelper*/,
-+                                           const ::basegfx::B2DHomMatrix&         rTransform,
-+                                           GLenum                                 eSrcBlend,
-+                                           GLenum                                 eDstBlend,
-+                                           const rendering::Texture&              rTexture,
-+                                           const geometry::IntegerSize2D&         rPixelSize,
-+                                           const uno::Sequence<sal_Int8>&         rPixelData,
-+                                           const ::basegfx::B2DPolyPolygonVector& rPolyPolygons )
++        bool lcl_fillTexturedPolyPolygon( const CanvasHelper&                    rHelper,
++                                          const ::basegfx::B2DHomMatrix&         rTransform,
++                                          GLenum                                 eSrcBlend,
++                                          GLenum                                 eDstBlend,
++                                          const rendering::Texture&              rTexture,
++                                          const geometry::IntegerSize2D&         rPixelSize,
++                                          const uno::Sequence<sal_Int8>&         rPixelData,
++                                          sal_uInt32                             nPixelCrc32,
++                                          const ::basegfx::B2DPolyPolygonVector& rPolyPolygons )
 +        {
 +            TransformationPreserver aPreserver;
 +            setupState(rTransform, eSrcBlend, eDstBlend, rendering::ARGBColor());
 +
-+            // TODO(P3): reuse the texture next time
-+            unsigned int nTexture;
-+            glGenTextures(1, &nTexture);
-+            glBindTexture(GL_TEXTURE_2D, nTexture);
-+
-+            // TODO(E3): handle limited texture sizes -
-+            // glGetIntegerv(GL_MAX_TEXTURE_SIZE)
++            const unsigned int nTexId=rHelper.getDeviceHelper()->getTextureCache().getTexture(
++                rPixelSize, rPixelData.getConstArray(), nPixelCrc32);
 +
-+            glTexImage2D(GL_TEXTURE_2D,
-+                         0,
-+                         4,
-+                         rPixelSize.Width, 
-+                         rPixelSize.Height, 
-+                         0,
-+                         GL_RGBA, 
-+                         GL_UNSIGNED_INT_8_8_8_8_REV,
-+                         &rPixelData[0]);
++            glBindTexture(GL_TEXTURE_2D, nTexId);
 +            glEnable(GL_TEXTURE_2D);
 +            glTexParameteri(GL_TEXTURE_2D,
 +                            GL_TEXTURE_MIN_FILTER,
@@ -1534,10 +1522,12 @@
 +                glEnd();
 +            }
 +
-+            glDeleteTextures(1, &nTexture);
 +            glLoadIdentity();
 +            glMatrixMode(GL_MODELVIEW);
 +
++            glBindTexture(GL_TEXTURE_2D, 0);
++            glDisable(GL_TEXTURE_2D);
++
 +            return true;
 +        }
 +    }
@@ -1823,11 +1813,14 @@
 +                                aPixelData,
 +                                canvas::tools::getStdColorSpace()));
 +
-+                        rAct.maFunction = ::boost::bind(&lcl_fillBitmappedPolyPolygon,
++                        rAct.maFunction = ::boost::bind(&lcl_fillTexturedPolyPolygon,
 +                                                        _1,_2,_3,_4,
 +                                                        textures[0],
 +                                                        aSize, 
 +                                                        aARGBBytes,
++                                                        rtl_crc32(0,
++                                                                  aARGBBytes.getConstArray(),
++                                                                  aARGBBytes.getLength()),
 +                                                        _6);
 +                    }
 +                    // TODO(F1): handle non-integer case
@@ -2033,7 +2026,10 @@
 +                    setupGraphicsState( rAct, viewState, renderState );
 +                    rAct.maFunction = ::boost::bind(&lcl_drawGenericBitmap,
 +                                                    _1,_2,_3,_4,_5,
-+                                                    aSize, aARGBBytes);
++                                                    aSize, aARGBBytes, 
++                                                    rtl_crc32(0,
++                                                              aARGBBytes.getConstArray(),
++                                                              aARGBBytes.getLength()));
 +                }
 +                // TODO(F1): handle non-integer case
 +            }
@@ -2167,7 +2163,7 @@
 +}
 diff --git canvas/source/opengl/ogl_canvashelper.hxx canvas/source/opengl/ogl_canvashelper.hxx
 new file mode 100644
-index 0000000..ea70584
+index 0000000..fafd450
 --- /dev/null
 +++ canvas/source/opengl/ogl_canvashelper.hxx
 @@ -0,0 +1,238 @@
@@ -2375,14 +2371,14 @@
 +        SpriteDeviceHelper* getDeviceHelper() const { return mpDeviceHelper; }
 +        ::com::sun::star::rendering::XGraphicDevice* getDevice() const { return mpDevice; }
 +
-+    private:
-+        // declared, but not defined
-+        CanvasHelper( const CanvasHelper& );
-+
 +        struct Action;
 +        typedef o3tl::cow_wrapper< std::vector<Action>,
 +                                   o3tl::ThreadSafeRefCountingPolicy > RecordVectorT;
 +
++    private:
++        // declared, but not defined
++        CanvasHelper( const CanvasHelper& );
++
 +        void setupGraphicsState( Action&                                         o_action,
 +                                 const ::com::sun::star::rendering::ViewState&   viewState, 
 +                                 const ::com::sun::star::rendering::RenderState& renderState );
@@ -2395,7 +2391,7 @@
 +        ::com::sun::star::rendering::XGraphicDevice* mpDevice;
 +
 +        /** Internal helper - used for a few global GL objects,
-+            e.g. shader programs
++            e.g. shader programs; and caches
 +         */
 +        SpriteDeviceHelper*                          mpDeviceHelper;
 +
@@ -2751,10 +2747,10 @@
 +#endif
 diff --git canvas/source/opengl/ogl_spritedevicehelper.cxx canvas/source/opengl/ogl_spritedevicehelper.cxx
 new file mode 100644
-index 0000000..24e38f5
+index 0000000..2ac2122
 --- /dev/null
 +++ canvas/source/opengl/ogl_spritedevicehelper.cxx
-@@ -0,0 +1,760 @@
+@@ -0,0 +1,774 @@
 +/*************************************************************************
 + *
 + *    OpenOffice.org - a multi-platform office productivity suite
@@ -2778,6 +2774,7 @@
 +#include "ogl_spritecanvas.hxx"
 +#include "ogl_canvasbitmap.hxx"
 +#include "ogl_canvascustomsprite.hxx"
++#include "ogl_texturecache.hxx"
 +
 +#include <canvas/verbosetrace.hxx>
 +#include <basegfx/tools/canvastools.hxx>
@@ -2954,6 +2951,7 @@
 +        mpChildWindow(),
 +        mpDisplay(NULL),
 +        mpGLContext(NULL),
++        mpTextureCache(new TextureCache()),
 +        mnDummyVertexProgram(0),
 +        mnLinearGradientFragmentProgram(0),
 +        mnRadialGradientFragmentProgram(0),
@@ -3182,6 +3180,7 @@
 +        // release all references
 +        mpSpriteCanvas = NULL;
 +        mpDevice = NULL;
++        mpTextureCache.reset();
 +
 +        if( mpGLContext )
 +        {
@@ -3400,6 +3399,12 @@
 +        unx::glXWaitGL();
 +        XSync( reinterpret_cast<unx::Display*>(mpDisplay), false );
 +
++        // flush texture cache, such that it does not build up
++        // indefinitely.
++        // TODO: have max cache size/LRU time in config, prune only on
++        // demand
++        mpTextureCache->flush();
++
 +        return true;
 +    }
 +
@@ -3514,13 +3519,18 @@
 +
 +        setupUniforms(mnLinearGradientProgram, rStartColor, rEndColor, rTexTransform);
 +    }
++
++    TextureCache& SpriteDeviceHelper::getTextureCache() const
++    {
++        return *mpTextureCache;
++    }
 +}
 diff --git canvas/source/opengl/ogl_spritedevicehelper.hxx canvas/source/opengl/ogl_spritedevicehelper.hxx
 new file mode 100644
-index 0000000..578d71e
+index 0000000..bd4dfa1
 --- /dev/null
 +++ canvas/source/opengl/ogl_spritedevicehelper.hxx
-@@ -0,0 +1,146 @@
+@@ -0,0 +1,152 @@
 +/*************************************************************************
 + *
 + *    OpenOffice.org - a multi-platform office productivity suite
@@ -3557,6 +3567,7 @@
 +
 +namespace oglcanvas
 +{
++    class TextureCache;
 +    class SpriteCanvas;
 +    class CanvasCustomSprite;
 +
@@ -3628,6 +3639,9 @@
 +                                           const ::com::sun::star::rendering::ARGBColor& rEndColor,
 +                                           const ::basegfx::B2DHomMatrix&                rTexTransform );
 +
++        /// Get instance of internal texture cache
++        TextureCache& getTextureCache() const;
++
 +    private:
 +        void resize( const ::basegfx::B2IVector& rNewSize );
 +
@@ -3655,6 +3669,8 @@
 +        void*                                              mpDisplay;
 +        void*                                              mpGLContext;
 +
++        boost::shared_ptr<TextureCache>                    mpTextureCache;
++
 +        unsigned int                                       mnDummyVertexProgram;
 +
 +        unsigned int                                       mnLinearGradientFragmentProgram;
@@ -3984,6 +4000,158 @@
 +}
 +
 +#endif
+diff --git canvas/source/opengl/ogl_texturecache.cxx canvas/source/opengl/ogl_texturecache.cxx
+new file mode 100644
+index 0000000..d65cef2
+--- /dev/null
++++ canvas/source/opengl/ogl_texturecache.cxx
+@@ -0,0 +1,95 @@
++/*************************************************************************
++ *
++ *    OpenOffice.org - a multi-platform office productivity suite
++ *
++ *    Author:
++ *      Thorsten Behrens <tbehrens novell com>      
++ *
++ *      Copyright (C) 2008, Novell Inc.
++ *      Parts copyright 2005 by Sun Microsystems, Inc.
++ *      Parts copyright 2004 David Reveman, Peter Nilsson
++ *
++ *   The Contents of this file are made available subject to
++ *   the terms of GNU Lesser General Public License Version 2.1.
++ *
++ ************************************************************************/
++
++// MARKER(update_precomp.py): autogen include statement, do not remove
++#include "precompiled_canvas.hxx"
++
++#define GL_GLEXT_PROTOTYPES
++
++#include "ogl_texturecache.hxx"
++
++#include <com/sun/star/geometry/IntegerSize2D.hpp>
++
++#include <GL/gl.h>
++#include <GL/glu.h>
++#include <GL/glext.h>
++
++using namespace ::com::sun::star;
++
++namespace oglcanvas
++{
++    TextureCache::TextureCache() : maCache(101) 
++    {}
++
++    TextureCache::~TextureCache()
++    {
++        flush();
++    }
++        
++    void TextureCache::flush()
++    {
++        // un-bind any texture
++        glBindTexture(GL_TEXTURE_2D, 0);
++
++        // delete all cached textures
++        TextureCacheMapT::const_iterator aCurr=maCache.begin();
++        const TextureCacheMapT::const_iterator aEnd=maCache.end();
++        while( aCurr != aEnd )
++        {
++            glDeleteTextures(1, &aCurr->second);
++            ++aCurr;
++        }
++
++        maCache.clear();
++    }
++
++    unsigned int TextureCache::getTexture( const geometry::IntegerSize2D& rPixelSize,
++                                           const sal_Int8*                pPixel, 
++                                           sal_uInt32                     nPixelCrc32) const
++    {
++        unsigned int nTexture(0);
++
++        // texture already cached?
++        TextureCacheMapT::const_iterator aCacheEntry;
++        if( (aCacheEntry=maCache.find(nPixelCrc32)) == maCache.end() )
++        {
++            // nope, insert new entry
++            glGenTextures(1, &nTexture);
++            glBindTexture(GL_TEXTURE_2D, nTexture);
++
++            // TODO(E3): handle limited texture sizes -
++            // glGetIntegerv(GL_MAX_TEXTURE_SIZE)
++            glTexImage2D(GL_TEXTURE_2D,
++                         0,
++                         4,
++                         rPixelSize.Width, 
++                         rPixelSize.Height, 
++                         0,
++                         GL_RGBA, 
++                         GL_UNSIGNED_INT_8_8_8_8_REV,
++                         pPixel);
++
++            maCache[nPixelCrc32] = nTexture;
++            return nTexture;
++        }
++        else
++        {
++            nTexture = aCacheEntry->second;
++        }
++
++        return nTexture;        
++    }
++}
+diff --git canvas/source/opengl/ogl_texturecache.hxx canvas/source/opengl/ogl_texturecache.hxx
+new file mode 100644
+index 0000000..b24436f
+--- /dev/null
++++ canvas/source/opengl/ogl_texturecache.hxx
+@@ -0,0 +1,45 @@
++/*************************************************************************
++ *
++ *    OpenOffice.org - a multi-platform office productivity suite
++ *
++ *    Author:
++ *      Thorsten Behrens <tbehrens novell com>      
++ *
++ *      Copyright (C) 2008, Novell Inc.
++ *      Parts copyright 2005 by Sun Microsystems, Inc.
++ *
++ *   The Contents of this file are made available subject to
++ *   the terms of GNU Lesser General Public License Version 2.1.
++ *
++ ************************************************************************/
++
++#ifndef OGL_TEXTURECACHE_HXX
++#define OGL_TEXTURECACHE_HXX
++
++#include <sal/types.h>
++#include <hash_map>
++
++namespace com { namespace sun { namespace star { 
++    namespace geometry { struct IntegerSize2D; }
++}}}
++
++namespace oglcanvas
++{
++    class TextureCache
++    {
++    public:
++        TextureCache();
++        ~TextureCache();
++        
++        /// clear whole cache
++        void flush();
++        unsigned int getTexture( const ::com::sun::star::geometry::IntegerSize2D& rPixelSize,
++                                 const sal_Int8*                                  pPixel, 
++                                 sal_uInt32                                       nPixelCrc32) const;
++    private:
++        typedef std::hash_map<sal_uInt32,unsigned int> TextureCacheMapT;
++        mutable TextureCacheMapT maCache;
++    };
++}
++
++#endif
 diff --git canvas/source/opengl/ogl_tools.hxx canvas/source/opengl/ogl_tools.hxx
 new file mode 100644
 index 0000000..e7575d4



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