Add opengl canvas implementation.

Adds opengl canvas implementation - display-list-based, all
rendering done as textured geometry. Needs shader support.

Currently compiles and works on Linux, Mac should be ~easy to
add, win32 eventually.

Change-Id: Ibf3eb88d6a36a91b2960a3a6320d708160e4fc14
This commit is contained in:
Thorsten Behrens 2012-01-31 01:07:48 +01:00
parent 21ec9beae2
commit e52f1bd7b3
29 changed files with 4657 additions and 1 deletions

View File

@ -229,6 +229,7 @@ $(eval $(call gb_Helper_register_libraries_for_install,OOOLIBS,ooo, \
$(if $(filter unx,$(GUIBASE)),desktop_detector) \
$(if $(DISABLE_SCRIPTING),,dlgprov) \
$(if $(ENABLE_DIRECTX),directx9canvas) \
$(if $(ENABLE_OPENGL),oglcanvas) \
drawinglayer \
editeng \
egi \

View File

@ -0,0 +1,69 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_Library_Library,oglcanvas))
$(eval $(call gb_Library_set_componentfile,oglcanvas,canvas/source/opengl/oglcanvas))
$(eval $(call gb_Library_use_sdk_api,oglcanvas))
$(eval $(call gb_Library_use_libraries,oglcanvas,\
sal \
cppu \
basegfx \
cppuhelper \
comphelper \
vcl \
tk \
tl \
i18nlangtag \
canvastools \
$(gb_UWINAPI) \
))
$(eval $(call gb_Library_add_exception_objects,oglcanvas,\
canvas/source/opengl/ogl_bitmapcanvashelper \
canvas/source/opengl/ogl_canvasbitmap \
canvas/source/opengl/ogl_canvascustomsprite \
canvas/source/opengl/ogl_canvasfont \
canvas/source/opengl/ogl_canvashelper \
canvas/source/opengl/ogl_canvastools \
canvas/source/opengl/ogl_spritecanvas \
canvas/source/opengl/ogl_spritedevicehelper \
canvas/source/opengl/ogl_textlayout \
canvas/source/opengl/ogl_texturecache \
))
$(eval $(call gb_Library_use_externals,oglcanvas,\
boost_headers \
))
ifeq ($(strip $(OS)),MACOSX)
$(eval $(call gb_Library_use_system_darwin_frameworks,oglcanvas,\
Cocoa \
GLUT \
OpenGL \
))
else ifeq ($(strip $(OS)),WNT)
$(eval $(call gb_Library_use_system_win32_libs,oglcanvas,\
gdi32 \
glu32 \
opengl32 \
))
else
$(eval $(call gb_Library_add_libs,oglcanvas,\
-lGL \
-lGLU \
-lX11 \
))
endif
# vim: set noet sw=4 ts=4:

View File

@ -32,6 +32,12 @@ $(eval $(call gb_Module_add_targets,canvas,\
))
endif
ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Module_add_targets,canvas,\
Library_oglcanvas \
))
endif
ifneq ($(ENABLE_DIRECTX),)
$(eval $(call gb_Module_add_targets,canvas,\
Library_directx9canvas \

View File

@ -0,0 +1,101 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "ogl_bitmapcanvashelper.hxx"
#include <canvas/debug.hxx>
#include <canvas/canvastools.hxx>
#include <tools/diagnose_ex.h>
using namespace ::com::sun::star;
namespace oglcanvas
{
BitmapCanvasHelper::BitmapCanvasHelper()
{}
void BitmapCanvasHelper::disposing()
{
CanvasHelper::disposing();
}
void BitmapCanvasHelper::init( rendering::XGraphicDevice& rDevice,
SpriteDeviceHelper& rDeviceHelper,
const geometry::IntegerSize2D& rSize )
{
maSize = rSize;
CanvasHelper::init(rDevice,rDeviceHelper);
}
void BitmapCanvasHelper::copyRect( const rendering::XCanvas* /*pCanvas*/,
const uno::Reference< rendering::XBitmapCanvas >& /*sourceCanvas*/,
const geometry::RealRectangle2D& /*sourceRect*/,
const rendering::ViewState& /*sourceViewState*/,
const rendering::RenderState& /*sourceRenderState*/,
const geometry::RealRectangle2D& /*destRect*/,
const rendering::ViewState& /*destViewState*/,
const rendering::RenderState& /*destRenderState*/ )
{
// TODO(F2): copyRect NYI
}
geometry::IntegerSize2D BitmapCanvasHelper::getSize()
{
return maSize;
}
uno::Reference< rendering::XBitmap > BitmapCanvasHelper::getScaledBitmap( const geometry::RealSize2D& /*newSize*/,
sal_Bool /*beFast*/ )
{
// TODO(F1):
return uno::Reference< rendering::XBitmap >();
}
uno::Sequence< sal_Int8 > BitmapCanvasHelper::getData( rendering::IntegerBitmapLayout& /*bitmapLayout*/,
const geometry::IntegerRectangle2D& /*rect*/ )
{
// TODO(F2): NYI - and improbable to ever be
return uno::Sequence< sal_Int8 >();
}
void BitmapCanvasHelper::setData( const uno::Sequence< sal_Int8 >& /*data*/,
const rendering::IntegerBitmapLayout& /*bitmapLayout*/,
const geometry::IntegerRectangle2D& /*rect*/ )
{
// TODO(F2): NYI - and improbable to ever be
}
void BitmapCanvasHelper::setPixel( const uno::Sequence< sal_Int8 >& /*color*/,
const rendering::IntegerBitmapLayout& /*bitmapLayout*/,
const geometry::IntegerPoint2D& /*pos*/ )
{
// TODO(F2): NYI - and improbable to ever be
}
uno::Sequence< sal_Int8 > BitmapCanvasHelper::getPixel( rendering::IntegerBitmapLayout& /*bitmapLayout*/,
const geometry::IntegerPoint2D& /*pos*/ )
{
// TODO(F2): NYI - and improbable to ever be
return uno::Sequence< sal_Int8 >();
}
rendering::IntegerBitmapLayout BitmapCanvasHelper::getMemoryLayout()
{
return ::canvas::tools::getStdMemoryLayout(getSize());
}
bool BitmapCanvasHelper::hasAlpha() const
{
return true;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,103 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef OGL_BITMAPCANVASHELPER_HXX_
#define OGL_BITMAPCANVASHELPER_HXX_
#include <com/sun/star/rendering/XBitmapCanvas.hpp>
#include <com/sun/star/rendering/XIntegerBitmap.hpp>
#include <basegfx/vector/b2isize.hxx>
#include <basegfx/vector/b2dsize.hxx>
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
#include <vector>
#include "ogl_canvashelper.hxx"
namespace oglcanvas
{
/** Helper class for basic canvas functionality. */
class BitmapCanvasHelper : public CanvasHelper
{
public:
BitmapCanvasHelper();
/// Release all references
void disposing();
/** Initialize canvas helper
This method late-initializes the canvas helper, providing
it with the necessary device and output objects. Note that
the CanvasHelper does <em>not</em> take ownership of the
passed rDevice reference, nor does it perform any
reference counting. Thus, to prevent the reference counted
SpriteCanvas object from deletion, the user of this class
is responsible for holding ref-counted references itself!
@param rDevice
Reference device this canvas is associated with
*/
void init( ::com::sun::star::rendering::XGraphicDevice& rDevice,
SpriteDeviceHelper& rDeviceHelper,
const ::com::sun::star::geometry::IntegerSize2D& rSize );
// BitmapCanvasHelper functionality
// ================================
void copyRect( const ::com::sun::star::rendering::XCanvas* rCanvas,
const ::com::sun::star::uno::Reference<
::com::sun::star::rendering::XBitmapCanvas >& sourceCanvas,
const ::com::sun::star::geometry::RealRectangle2D& sourceRect,
const ::com::sun::star::rendering::ViewState& sourceViewState,
const ::com::sun::star::rendering::RenderState& sourceRenderState,
const ::com::sun::star::geometry::RealRectangle2D& destRect,
const ::com::sun::star::rendering::ViewState& destViewState,
const ::com::sun::star::rendering::RenderState& destRenderState );
::com::sun::star::geometry::IntegerSize2D getSize();
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > queryBitmapCanvas();
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >
getScaledBitmap( const ::com::sun::star::geometry::RealSize2D& newSize,
sal_Bool beFast );
::com::sun::star::uno::Sequence< sal_Int8 >
getData( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
const ::com::sun::star::geometry::IntegerRectangle2D& rect );
void setData( const ::com::sun::star::uno::Sequence< sal_Int8 >& data,
const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
const ::com::sun::star::geometry::IntegerRectangle2D& rect );
void setPixel( const ::com::sun::star::uno::Sequence< sal_Int8 >& color,
const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
const ::com::sun::star::geometry::IntegerPoint2D& pos );
::com::sun::star::uno::Sequence< sal_Int8 >
getPixel( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
const ::com::sun::star::geometry::IntegerPoint2D& pos );
::com::sun::star::rendering::IntegerBitmapLayout getMemoryLayout();
bool hasAlpha() const;
private:
::com::sun::star::geometry::IntegerSize2D maSize;
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,34 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef OGL_BUFFERCONTEXT_HXX_
#define OGL_BUFFERCONTEXT_HXX_
#include <sal/config.h>
#include <boost/shared_ptr.hpp>
namespace oglcanvas
{
struct IBufferContext
{
virtual ~IBufferContext() {}
/// start render to buffer. changes gl current context
virtual bool startBufferRendering() = 0;
/// end render to buffer. switches to window context, and selects rendered texture
virtual bool endBufferRendering() = 0;
};
typedef ::boost::shared_ptr<IBufferContext> IBufferContextSharedPtr;
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,55 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "ogl_canvasbitmap.hxx"
#include <canvas/debug.hxx>
#include <canvas/canvastools.hxx>
#include <tools/diagnose_ex.h>
using namespace ::com::sun::star;
namespace oglcanvas
{
CanvasBitmap::CanvasBitmap( const geometry::IntegerSize2D& rSize,
const SpriteCanvasRef& rDevice,
SpriteDeviceHelper& rDeviceHelper,
bool bHasAlpha ) :
mpDevice( rDevice ),
mbHasAlpha( bHasAlpha )
{
ENSURE_OR_THROW( mpDevice.is(),
"CanvasBitmap::CanvasBitmap(): Invalid surface or device" );
maCanvasHelper.init( *mpDevice.get(), rDeviceHelper, rSize );
}
CanvasBitmap::CanvasBitmap( const CanvasBitmap& rSrc ) :
mpDevice( rSrc.mpDevice ),
mbHasAlpha( rSrc.mbHasAlpha )
{
maCanvasHelper = rSrc.maCanvasHelper;
}
void SAL_CALL CanvasBitmap::disposeThis()
{
mpDevice.clear();
// forward to parent
CanvasBitmapBaseT::disposeThis();
}
bool CanvasBitmap::renderRecordedActions() const
{
return maCanvasHelper.renderRecordedActions();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,78 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef OGL_CANVASBITMAP_HXX
#define OGL_CANVASBITMAP_HXX
#include <cppuhelper/compbase2.hxx>
#include <com/sun/star/rendering/XBitmapCanvas.hpp>
#include <com/sun/star/rendering/XIntegerBitmap.hpp>
#include <canvas/base/integerbitmapbase.hxx>
#include <canvas/base/disambiguationhelper.hxx>
#include <basegfx/vector/b2isize.hxx>
#include <boost/shared_ptr.hpp>
#include "ogl_bitmapcanvashelper.hxx"
#include "ogl_spritecanvas.hxx"
/* Definition of CanvasBitmap class */
namespace oglcanvas
{
typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::rendering::XBitmapCanvas,
::com::sun::star::rendering::XIntegerBitmap > CanvasBitmapBase_Base;
typedef ::canvas::IntegerBitmapBase<
::canvas::DisambiguationHelper< CanvasBitmapBase_Base >,
BitmapCanvasHelper,
::osl::MutexGuard,
::cppu::OWeakObject > CanvasBitmapBaseT;
class CanvasBitmap : public CanvasBitmapBaseT
{
public:
/** Create a canvas bitmap for the given surface
@param rSize
Size of the bitmap
@param rDevice
Reference device, with which bitmap should be compatible
*/
CanvasBitmap( const ::com::sun::star::geometry::IntegerSize2D& rSize,
const SpriteCanvasRef& rDevice,
SpriteDeviceHelper& rDeviceHelper,
bool bHasAlpha );
/** Create verbatim copy (including all recorded actions)
*/
CanvasBitmap( const CanvasBitmap& rSrc );
/// Dispose all internal references
virtual void disposeThis();
/** Write out recorded actions
*/
bool renderRecordedActions() const;
private:
/** MUST hold here, too, since CanvasHelper only contains a
raw pointer (without refcounting)
*/
SpriteCanvasRef mpDevice;
bool mbHasAlpha;
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,261 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "ogl_canvascustomsprite.hxx"
#include "ogl_canvastools.hxx"
#include "ogl_tools.hxx"
#include <canvas/debug.hxx>
#include <canvas/verbosetrace.hxx>
#include <canvas/verifyinput.hxx>
#include <tools/diagnose_ex.h>
#include <canvas/canvastools.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/point/b2dpoint.hxx>
#include <basegfx/tools/canvastools.hxx>
#include <basegfx/polygon/b2dpolygonclipper.hxx>
#include <basegfx/polygon/b2dpolygontriangulator.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
using namespace ::com::sun::star;
namespace oglcanvas
{
CanvasCustomSprite::CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& rSpriteSize,
const SpriteCanvasRef& rRefDevice,
SpriteDeviceHelper& rDeviceHelper ) :
mpSpriteCanvas( rRefDevice ),
maSize(rSpriteSize),
mxClip(),
maTransformation(),
maPosition(),
mfAlpha(0.0),
mfPriority(0.0)
{
ENSURE_OR_THROW( rRefDevice.get(),
"CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
::canvas::tools::setIdentityAffineMatrix2D(maTransformation);
maCanvasHelper.init( *rRefDevice.get(),
rDeviceHelper );
}
void SAL_CALL CanvasCustomSprite::disposeThis()
{
::osl::MutexGuard aGuard( m_aMutex );
mpSpriteCanvas.clear();
// forward to parent
CanvasCustomSpriteBaseT::disposeThis();
}
void SAL_CALL CanvasCustomSprite::setAlpha( double alpha ) throw (lang::IllegalArgumentException,
uno::RuntimeException)
{
canvas::tools::verifyRange( alpha, 0.0, 1.0 );
::osl::MutexGuard aGuard( m_aMutex );
mfAlpha = alpha;
}
void SAL_CALL CanvasCustomSprite::move( const geometry::RealPoint2D& aNewPos,
const rendering::ViewState& viewState,
const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException,
uno::RuntimeException)
{
canvas::tools::verifyArgs(aNewPos, viewState, renderState,
BOOST_CURRENT_FUNCTION,
static_cast< ::cppu::OWeakObject* >(this));
::osl::MutexGuard aGuard( m_aMutex );
::basegfx::B2DHomMatrix aTransform;
::canvas::tools::mergeViewAndRenderTransform(aTransform,
viewState,
renderState);
// convert position to device pixel
maPosition = ::basegfx::unotools::b2DPointFromRealPoint2D(aNewPos);
maPosition *= aTransform;
}
void SAL_CALL CanvasCustomSprite::transform( const geometry::AffineMatrix2D& aTransformation ) throw (lang::IllegalArgumentException,
uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
maTransformation = aTransformation;
}
void SAL_CALL CanvasCustomSprite::clip( const uno::Reference< rendering::XPolyPolygon2D >& xClip ) throw (uno::RuntimeException)
{
mxClip = xClip;
}
void SAL_CALL CanvasCustomSprite::setPriority( double nPriority ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
mfPriority = nPriority;
}
void SAL_CALL CanvasCustomSprite::show() throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
if( mpSpriteCanvas.is() )
mpSpriteCanvas->show(this);
}
void SAL_CALL CanvasCustomSprite::hide() throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
if( mpSpriteCanvas.is() )
mpSpriteCanvas->hide(this);
}
uno::Reference< rendering::XCanvas > SAL_CALL CanvasCustomSprite::getContentCanvas() throw (uno::RuntimeException)
{
return this;
}
bool CanvasCustomSprite::renderSprite() const
{
if( ::basegfx::fTools::equalZero( mfAlpha ) )
return true;
TransformationPreserver aPreserver1;
const ::basegfx::B2IVector aSpriteSizePixel(
::canvas::tools::roundUp( maSize.Width ),
::canvas::tools::roundUp( maSize.Height ));
// translate sprite to output position
glTranslated(maPosition.getX(), maPosition.getY(), 0);
{
TransformationPreserver aPreserver2;
// apply sprite content transformation matrix
double aGLTransform[] =
{
maTransformation.m00, maTransformation.m10, 0, 0,
maTransformation.m01, maTransformation.m11, 0, 0,
0, 0, 1, 0,
maTransformation.m02, maTransformation.m12, 0, 1
};
glMultMatrixd(aGLTransform);
IBufferContextSharedPtr pBufferContext;
if( mfAlpha != 1.0 || mxClip.is() )
{
// drats. need to render to temp surface before, and then
// composite that to screen
// TODO(P3): buffer pbuffer, maybe even keep content
// (in a texture?)
pBufferContext=maCanvasHelper.getDeviceHelper()->createBufferContext(aSpriteSizePixel);
pBufferContext->startBufferRendering();
}
// this ends up in pBufferContext, if that one's "current"
if( !maCanvasHelper.renderRecordedActions() )
return false;
if( pBufferContext )
{
// content ended up in background buffer - compose to
// screen now. Calls below switches us back to window
// context, and binds to generated, dynamic texture
pBufferContext->endBufferRendering();
glEnable(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA);
// blend against fixed vertex color; texture alpha is multiplied in
glColor4f(1,1,1,mfAlpha);
if( mxClip.is() )
{
const double fWidth=maSize.Width;
const double fHeight=maSize.Height;
// TODO(P3): buffer triangulation
const ::basegfx::B2DPolygon& rTriangulatedPolygon(
::basegfx::triangulator::triangulate(
::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(mxClip)));
basegfx::B2DPolygon rTriangleList(
basegfx::tools::clipTriangleListOnRange(
rTriangulatedPolygon,
basegfx::B2DRange(
0,0,
aSpriteSizePixel.getX(),
aSpriteSizePixel.getY())));
glBegin(GL_TRIANGLES);
for( sal_uInt32 i=0; i<rTriangulatedPolygon.count(); i++ )
{
const ::basegfx::B2DPoint& rPt( rTriangulatedPolygon.getB2DPoint(i) );
const double s(rPt.getX()/fWidth);
const double t(rPt.getY()/fHeight);
glTexCoord2f(s,t); glVertex2d(rPt.getX(), rPt.getY());
}
glEnd();
}
else
{
const double fWidth=maSize.Width/aSpriteSizePixel.getX();
const double fHeight=maSize.Height/aSpriteSizePixel.getY();
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0,0); glVertex2d(0,0);
glTexCoord2f(0,fHeight); glVertex2d(0, aSpriteSizePixel.getY());
glTexCoord2f(fWidth,0); glVertex2d(aSpriteSizePixel.getX(),0);
glTexCoord2f(fWidth,fHeight); glVertex2d(aSpriteSizePixel.getX(),aSpriteSizePixel.getY());
glEnd();
}
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
}
}
glColor4f(1,0,0,1);
glBegin(GL_LINE_STRIP);
glVertex2d(-2,-2);
glVertex2d(-2,maSize.Height+4);
glVertex2d(maSize.Width+4,maSize.Height+4);
glVertex2d(maSize.Width+4,-2);
glVertex2d(-2,-2);
glVertex2d(maSize.Width+4,maSize.Height+4);
glEnd();
std::vector<double> aVec;
aVec.push_back(mfAlpha);
aVec.push_back(mfPriority);
aVec.push_back(maCanvasHelper.getRecordedActionCount());
renderOSD( aVec, 10 );
return true;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,100 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef OGL_CANVASCUSTOMSPRITE_HXX
#define OGL_CANVASCUSTOMSPRITE_HXX
#include <cppuhelper/compbase2.hxx>
#include <comphelper/uno3.hxx>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/rendering/XCustomSprite.hpp>
#include <com/sun/star/rendering/XPolyPolygon2D.hpp>
#include <basegfx/point/b2dpoint.hxx>
#include <basegfx/vector/b2isize.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <canvas/base/disambiguationhelper.hxx>
#include "ogl_spritecanvas.hxx"
#include "ogl_canvashelper.hxx"
namespace oglcanvas
{
typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::rendering::XCustomSprite,
::com::sun::star::rendering::XCanvas > CanvasCustomSpriteBase_Base;
typedef ::canvas::CanvasBase<
::canvas::DisambiguationHelper< CanvasCustomSpriteBase_Base >,
CanvasHelper,
::osl::MutexGuard,
::cppu::OWeakObject > CanvasCustomSpriteBaseT;
/* Definition of CanvasCustomSprite class */
class CanvasCustomSprite : public CanvasCustomSpriteBaseT
{
public:
/** Create a custom sprite
@param rSpriteSize
Size of the sprite in pixel
@param rRefDevice
Associated output device
@param rSpriteCanvas
Target canvas
@param rDevice
Target DX device
*/
CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& rSpriteSize,
const SpriteCanvasRef& rRefDevice,
SpriteDeviceHelper& rDeviceHelper );
virtual void disposeThis();
// XSprite
virtual void SAL_CALL setAlpha( double alpha ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL move( const ::com::sun::star::geometry::RealPoint2D& aNewPos, const ::com::sun::star::rendering::ViewState& viewState, const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL transform( const ::com::sun::star::geometry::AffineMatrix2D& aTransformation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL clip( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& aClip ) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL setPriority( double nPriority ) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL show() throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL hide() throw (::com::sun::star::uno::RuntimeException);
// XCustomSprite
virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvas > SAL_CALL getContentCanvas() throw (::com::sun::star::uno::RuntimeException);
double getPriority() const { return mfPriority; }
/// Render sprite content at sprite position
bool renderSprite() const;
private:
/** MUST hold here, too, since CanvasHelper only contains a
raw pointer (without refcounting)
*/
SpriteCanvasRef mpSpriteCanvas;
const ::com::sun::star::geometry::RealSize2D maSize;
::com::sun::star::uno::Reference<
::com::sun::star::rendering::XPolyPolygon2D > mxClip;
::com::sun::star::geometry::AffineMatrix2D maTransformation;
::basegfx::B2DPoint maPosition;
double mfAlpha;
double mfPriority;
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,81 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "ogl_canvasfont.hxx"
#include "ogl_textlayout.hxx"
#include <com/sun/star/rendering/XSpriteCanvas.hpp>
#include <com/sun/star/rendering/PanoseWeight.hpp>
using namespace ::com::sun::star;
namespace oglcanvas
{
CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest,
const uno::Sequence< beans::PropertyValue >& /*extraFontProperties*/,
const geometry::Matrix2D& fontMatrix ) :
CanvasFontBaseT( m_aMutex ),
maFontRequest( rFontRequest ),
maFontMatrix( fontMatrix )
{
}
void SAL_CALL CanvasFont::disposing()
{
::osl::MutexGuard aGuard( m_aMutex );
}
uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText,
sal_Int8 nDirection,
sal_Int64 nRandomSeed ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
return new TextLayout( aText, nDirection, nRandomSeed, ImplRef( this ) );
}
uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return uno::Sequence< double >();
}
uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return uno::Sequence< beans::PropertyValue >();
}
rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
return maFontRequest;
}
rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return rendering::FontMetrics();
}
const ::com::sun::star::geometry::Matrix2D& CanvasFont::getFontMatrix() const
{
return maFontMatrix;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,68 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef OGL_CANVASFONT_HXX
#define OGL_CANVASFONT_HXX
#include <comphelper/implementationreference.hxx>
#include <cppuhelper/compbase1.hxx>
#include <comphelper/broadcasthelper.hxx>
#include <com/sun/star/rendering/XCanvas.hpp>
#include <com/sun/star/rendering/XCanvasFont.hpp>
#include <rtl/ref.hxx>
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
/* Definition of CanvasFont class */
namespace oglcanvas
{
class SpriteCanvas;
typedef ::cppu::WeakComponentImplHelper1< ::com::sun::star::rendering::XCanvasFont > CanvasFontBaseT;
class CanvasFont : public ::comphelper::OBaseMutex,
public CanvasFontBaseT,
private ::boost::noncopyable
{
public:
typedef ::comphelper::ImplementationReference<
CanvasFont,
::com::sun::star::rendering::XCanvasFont > ImplRef;
CanvasFont( const ::com::sun::star::rendering::FontRequest& fontRequest,
const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& extraFontProperties,
const ::com::sun::star::geometry::Matrix2D& fontMatrix );
/// Dispose all internal references
virtual void SAL_CALL disposing();
// XCanvasFont
virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XTextLayout > SAL_CALL createTextLayout( const ::com::sun::star::rendering::StringContext& aText, sal_Int8 nDirection, sal_Int64 nRandomSeed ) throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::rendering::FontRequest SAL_CALL getFontRequest( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::rendering::FontMetrics SAL_CALL getFontMetrics( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Sequence< double > SAL_CALL getAvailableSizes( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getExtraFontProperties( ) throw (::com::sun::star::uno::RuntimeException);
const ::com::sun::star::geometry::Matrix2D& getFontMatrix() const;
private:
::com::sun::star::rendering::FontRequest maFontRequest;
::com::sun::star::geometry::Matrix2D maFontMatrix;
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,238 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef OGL_CANVASHELPER_HXX_
#define OGL_CANVASHELPER_HXX_
#include <com/sun/star/rendering/XCanvas.hpp>
#include <basegfx/vector/b2isize.hxx>
#include <basegfx/vector/b2dsize.hxx>
#include <o3tl/cow_wrapper.hxx>
#include <vector>
namespace oglcanvas
{
class SpriteDeviceHelper;
/** Helper class for basic canvas functionality. */
class CanvasHelper
{
public:
CanvasHelper();
// outline because of incomplete type Action
~CanvasHelper();
CanvasHelper& operator=( const CanvasHelper& );
/// Release all references
void disposing();
/** Initialize canvas helper
This method late-initializes the canvas helper, providing
it with the necessary device and output objects. Note that
the CanvasHelper does <em>not</em> take ownership of the
passed rDevice reference, nor does it perform any
reference counting. Thus, to prevent the reference counted
SpriteCanvas object from deletion, the user of this class
is responsible for holding ref-counted references itself!
@param rDevice
Reference device this canvas is associated with
*/
void init( ::com::sun::star::rendering::XGraphicDevice& rDevice,
SpriteDeviceHelper& rDeviceHelper );
// CanvasHelper functionality
// ==========================
// XCanvas (only providing, not implementing the
// interface. Also note subtle method parameter differences)
void clear();
void drawPoint( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::geometry::RealPoint2D& aPoint,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState );
void drawLine( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::geometry::RealPoint2D& aStartPoint,
const ::com::sun::star::geometry::RealPoint2D& aEndPoint,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState );
void drawBezier( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment,
const ::com::sun::star::geometry::RealPoint2D& aEndPoint,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
drawPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::uno::Reference<
::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
strokePolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::uno::Reference<
::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState,
const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
strokeTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::uno::Reference<
::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState,
const ::com::sun::star::uno::Sequence<
::com::sun::star::rendering::Texture >& textures,
const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
strokeTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::uno::Reference<
::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState,
const ::com::sun::star::uno::Sequence<
::com::sun::star::rendering::Texture >& textures,
const ::com::sun::star::uno::Reference<
::com::sun::star::geometry::XMapping2D >& xMapping,
const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >
queryStrokeShapes( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::uno::Reference<
::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState,
const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
fillPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::uno::Reference<
::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
fillTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::uno::Reference<
::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState,
const ::com::sun::star::uno::Sequence<
::com::sun::star::rendering::Texture >& textures );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
fillTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::uno::Reference<
::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState,
const ::com::sun::star::uno::Sequence<
::com::sun::star::rendering::Texture >& textures,
const ::com::sun::star::uno::Reference<
::com::sun::star::geometry::XMapping2D >& xMapping );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont > SAL_CALL
createFont( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::rendering::FontRequest& fontRequest,
const ::com::sun::star::uno::Sequence<
::com::sun::star::beans::PropertyValue >& extraFontProperties,
const ::com::sun::star::geometry::Matrix2D& fontMatrix );
::com::sun::star::uno::Sequence< ::com::sun::star::rendering::FontInfo >
queryAvailableFonts( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::rendering::FontInfo& aFilter,
const ::com::sun::star::uno::Sequence<
::com::sun::star::beans::PropertyValue >& aFontProperties );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
drawText( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::rendering::StringContext& text,
const ::com::sun::star::uno::Reference<
::com::sun::star::rendering::XCanvasFont >& xFont,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState,
sal_Int8 textDirection );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
drawTextLayout( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::uno::Reference<
::com::sun::star::rendering::XTextLayout >& layoutetText,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
drawBitmap( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::uno::Reference<
::com::sun::star::rendering::XBitmap >& xBitmap,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
drawBitmapModulated( const ::com::sun::star::rendering::XCanvas* pCanvas,
const ::com::sun::star::uno::Reference<
::com::sun::star::rendering::XBitmap >& xBitmap,
const ::com::sun::star::rendering::ViewState& viewState,
const ::com::sun::star::rendering::RenderState& renderState );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >
getDevice();
// Flush drawing queue to screen
void flush() const;
/** Called from XCanvas base classes, to notify that content
is _about_ to change
*/
void modifying() {}
/** Write out recorded actions
*/
bool renderRecordedActions() const;
/** Retrieve number of recorded actions
*/
size_t getRecordedActionCount() const;
SpriteDeviceHelper* getDeviceHelper() const { return mpDeviceHelper; }
::com::sun::star::rendering::XGraphicDevice* getDevice() const { return mpDevice; }
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 );
/** Phyical output device
Deliberately not a refcounted reference, because of
potential circular references for spritecanvas.
*/
::com::sun::star::rendering::XGraphicDevice* mpDevice;
/** Internal helper - used for a few global GL objects,
e.g. shader programs; and caches
*/
SpriteDeviceHelper* mpDeviceHelper;
/** Ptr to array of recorded render calls
Gets shared copy-on-write, when this CanvasHelper is
copied (used e.g. for CanvasBitmap)
*/
RecordVectorT mpRecordedActions;
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,139 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#define GL_GLEXT_PROTOTYPES
#include "ogl_canvastools.hxx"
#include <canvas/debug.hxx>
#include <tools/diagnose_ex.h>
#include <basegfx/tools/canvastools.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/tools/tools.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <basegfx/polygon/b2dpolygontriangulator.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <com/sun/star/rendering/ARGBColor.hpp>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
using namespace ::com::sun::star;
namespace oglcanvas
{
/// triangulates polygon before
void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly )
{
::basegfx::B2DPolyPolygon aPolyPoly(rPolyPoly);
if( aPolyPoly.areControlPointsUsed() )
aPolyPoly = rPolyPoly.getDefaultAdaptiveSubdivision();
const ::basegfx::B2DRange& rBounds(aPolyPoly.getB2DRange());
const double nWidth=rBounds.getWidth();
const double nHeight=rBounds.getHeight();
const ::basegfx::B2DPolygon& rTriangulatedPolygon(
::basegfx::triangulator::triangulate(aPolyPoly));
for( sal_uInt32 i=0; i<rTriangulatedPolygon.count(); i++ )
{
const ::basegfx::B2DPoint& rPt( rTriangulatedPolygon.getB2DPoint(i) );
const double s(rPt.getX()/nWidth);
const double t(rPt.getY()/nHeight);
glTexCoord2f(s,t); glVertex2d(rPt.getX(), rPt.getY());
}
}
/** only use this for line polygons.
better not leave triangulation to OpenGL. also, ignores texturing
*/
void renderPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly )
{
::basegfx::B2DPolyPolygon aPolyPoly(rPolyPoly);
if( aPolyPoly.areControlPointsUsed() )
aPolyPoly = rPolyPoly.getDefaultAdaptiveSubdivision();
for( sal_uInt32 i=0; i<aPolyPoly.count(); i++ )
{
glBegin(GL_LINE_STRIP);
const ::basegfx::B2DPolygon& rPolygon( aPolyPoly.getB2DPolygon(i) );
const sal_uInt32 nPts=rPolygon.count();
const sal_uInt32 nExtPts=nPts + rPolygon.isClosed();
for( sal_uInt32 j=0; j<nExtPts; j++ )
{
const ::basegfx::B2DPoint& rPt( rPolygon.getB2DPoint( j % nPts ) );
glVertex2d(rPt.getX(), rPt.getY());
}
glEnd();
}
}
void setupState( const ::basegfx::B2DHomMatrix& rTransform,
GLenum eSrcBlend,
GLenum eDstBlend,
const rendering::ARGBColor& rColor )
{
double aGLTransform[] =
{
rTransform.get(0,0), rTransform.get(1,0), 0, 0,
rTransform.get(0,1), rTransform.get(1,1), 0, 0,
0, 0, 1, 0,
rTransform.get(0,2), rTransform.get(1,2), 0, 1
};
glMultMatrixd(aGLTransform);
glEnable(GL_BLEND);
glBlendFunc(eSrcBlend, eDstBlend);
glColor4d(rColor.Red,
rColor.Green,
rColor.Blue,
rColor.Alpha);
// GL 1.2:
// glBlendEquation( GLenum mode );
// glBlendColor( GLclampf red, GLclampf green,GLclampf blue, GLclampf alpha );
// glConvolutionFilter1D
// glConvolutionFilter2D
// glSeparableFilter2D
}
void renderOSD( const std::vector<double>& rNumbers, double scale )
{
double y=4.0;
basegfx::B2DHomMatrix aTmp;
basegfx::B2DHomMatrix aScaleShear;
aScaleShear.shearX(-0.1);
aScaleShear.scale(scale,scale);
for( size_t i=0; i<rNumbers.size(); ++i )
{
aTmp.identity();
aTmp.translate(0,y);
y += 1.2*scale;
basegfx::B2DPolyPolygon aPoly=
basegfx::tools::number2PolyPolygon(rNumbers[i],10,3);
aTmp=aTmp*aScaleShear;
aPoly.transform(aTmp);
glColor4f(0,1,0,1);
renderPolyPolygon(aPoly);
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,38 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef OGL_CANVASTOOLS_HXX
#define OGL_CANVASTOOLS_HXX
#include <sal/config.h>
#include <vector>
namespace com { namespace sun { namespace star { namespace rendering {
struct ARGBColor;
}}}}
namespace basegfx {
class B2DPolyPolygon;
class B2DHomMatrix;
}
namespace oglcanvas
{
void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly );
void renderPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly );
void setupState( const ::basegfx::B2DHomMatrix& rTransform,
unsigned int eSrcBlend,
unsigned int eDstBlend,
const ::com::sun::star::rendering::ARGBColor& rColor );
void renderOSD( const std::vector<double>& rNumbers, double scale );
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,195 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "ogl_spritecanvas.hxx"
#include <canvas/debug.hxx>
#include <canvas/verbosetrace.hxx>
#include <tools/diagnose_ex.h>
#include <osl/mutex.hxx>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/registry/XRegistryKey.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/lang/NoSupportException.hpp>
#include <toolkit/helper/vclunohelper.hxx>
#include <cppuhelper/factory.hxx>
#include <cppuhelper/implementationentry.hxx>
#include <comphelper/servicedecl.hxx>
#include "ogl_canvascustomsprite.hxx"
#include <GL/gl.h>
#include <GL/glext.h>
#define SPRITECANVAS_SERVICE_NAME "com.sun.star.rendering.SpriteCanvas.OGL"
#define SPRITECANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.SpriteCanvas.OGL"
using namespace ::com::sun::star;
namespace oglcanvas
{
SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
const uno::Reference< uno::XComponentContext >& rxContext ) :
maArguments(aArguments),
mxComponentContext( rxContext )
{
}
void SpriteCanvas::initialize()
{
// Only call initialize when not in probe mode
if( maArguments.getLength() == 0 )
return;
VERBOSE_TRACE( "SpriteCanvas::initialize called" );
/* aArguments:
0: ptr to creating instance (Window or VirtualDevice)
1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
2: current bounds of creating instance
3: bool, denoting always on top state for Window (always false for VirtualDevice)
4: XWindow for creating Window (or empty for VirtualDevice)
5: SystemGraphicsData as a streamed Any
*/
ENSURE_ARG_OR_THROW( maArguments.getLength() >= 5 &&
maArguments[4].getValueTypeClass() == uno::TypeClass_INTERFACE,
"OpenGL SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
uno::Reference< awt::XWindow > xParentWindow;
maArguments[4] >>= xParentWindow;
Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
if( !pParentWindow )
throw lang::NoSupportException(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
"Parent window not VCL window, or canvas out-of-process!")),
NULL);
awt::Rectangle aRect;
maArguments[2] >>= aRect;
// setup helper
maDeviceHelper.init( *pParentWindow,
*this,
aRect );
maCanvasHelper.init( *this, maDeviceHelper );
maArguments.realloc(0);
}
void SAL_CALL SpriteCanvas::disposeThis()
{
::osl::MutexGuard aGuard( m_aMutex );
mxComponentContext.clear();
// forward to parent
SpriteCanvasBaseT::disposeThis();
}
::sal_Bool SAL_CALL SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// avoid repaints on hidden window (hidden: not mapped to
// screen). Return failure, since the screen really has _not_
// been updated (caller should try again later)
return !mbIsVisible ? false : SpriteCanvasBaseT::showBuffer( bUpdateAll );
}
::sal_Bool SAL_CALL SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// avoid repaints on hidden window (hidden: not mapped to
// screen). Return failure, since the screen really has _not_
// been updated (caller should try again later)
return !mbIsVisible ? false : SpriteCanvasBaseT::switchBuffer( bUpdateAll );
}
uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromAnimation(
const uno::Reference< rendering::XAnimation >& /*animation*/ ) throw (lang::IllegalArgumentException,
uno::RuntimeException)
{
return uno::Reference< rendering::XAnimatedSprite >();
}
uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromBitmaps(
const uno::Sequence< uno::Reference< rendering::XBitmap > >& /*animationBitmaps*/,
::sal_Int8 /*interpolationMode*/ ) throw (lang::IllegalArgumentException,
rendering::VolatileContentDestroyedException,
uno::RuntimeException)
{
return uno::Reference< rendering::XAnimatedSprite >();
}
uno::Reference< rendering::XCustomSprite > SAL_CALL SpriteCanvas::createCustomSprite(
const geometry::RealSize2D& spriteSize ) throw (lang::IllegalArgumentException,
uno::RuntimeException)
{
return uno::Reference< rendering::XCustomSprite >(
new CanvasCustomSprite(spriteSize, this, maDeviceHelper) );
}
uno::Reference< rendering::XSprite > SAL_CALL SpriteCanvas::createClonedSprite(
const uno::Reference< rendering::XSprite >& /*original*/ ) throw (lang::IllegalArgumentException,
uno::RuntimeException)
{
return uno::Reference< rendering::XSprite >();
}
sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
return maDeviceHelper.showBuffer(mbIsVisible, bUpdateAll);
}
::rtl::OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (uno::RuntimeException)
{
return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SPRITECANVAS_SERVICE_NAME ) );
}
void SpriteCanvas::show( const ::rtl::Reference< CanvasCustomSprite >& xSprite )
{
::osl::MutexGuard aGuard( m_aMutex );
maDeviceHelper.show(xSprite);
}
void SpriteCanvas::hide( const ::rtl::Reference< CanvasCustomSprite >& xSprite )
{
::osl::MutexGuard aGuard( m_aMutex );
maDeviceHelper.hide(xSprite);
}
bool SpriteCanvas::renderRecordedActions() const
{
return maCanvasHelper.renderRecordedActions();
}
static uno::Reference<uno::XInterface> initCanvas( SpriteCanvas* pCanvas )
{
uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas));
pCanvas->initialize();
return xRet;
}
namespace sdecl = comphelper::service_decl;
sdecl::class_<SpriteCanvas, sdecl::with_args<true> > serviceImpl(&initCanvas);
const sdecl::ServiceDecl oglSpriteCanvasDecl(
serviceImpl,
SPRITECANVAS_IMPLEMENTATION_NAME,
SPRITECANVAS_SERVICE_NAME );
}
// The C shared lib entry points
COMPHELPER_SERVICEDECL_EXPORTS1(oglcanvas, oglcanvas::oglSpriteCanvasDecl);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,118 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef OGL_SPRITECANVAS_HXX_
#define OGL_SPRITECANVAS_HXX_
#include <rtl/ref.hxx>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/lang/XServiceName.hpp>
#include <com/sun/star/awt/XWindowListener.hpp>
#include <com/sun/star/util/XUpdatable.hpp>
#include <com/sun/star/rendering/XSpriteCanvas.hpp>
#include <com/sun/star/rendering/XGraphicDevice.hpp>
#include <com/sun/star/rendering/XBufferController.hpp>
#include <cppuhelper/compbase8.hxx>
#include <comphelper/uno3.hxx>
#include <canvas/base/spritecanvasbase.hxx>
#include <canvas/base/disambiguationhelper.hxx>
#include <canvas/base/bufferedgraphicdevicebase.hxx>
#include "ogl_spritedevicehelper.hxx"
#include "ogl_canvashelper.hxx"
namespace oglcanvas
{
class CanvasCustomSprite;
typedef ::cppu::WeakComponentImplHelper8< ::com::sun::star::rendering::XSpriteCanvas,
::com::sun::star::rendering::XGraphicDevice,
::com::sun::star::lang::XMultiServiceFactory,
::com::sun::star::rendering::XBufferController,
::com::sun::star::awt::XWindowListener,
::com::sun::star::util::XUpdatable,
::com::sun::star::beans::XPropertySet,
::com::sun::star::lang::XServiceName > WindowGraphicDeviceBase_Base;
typedef ::canvas::BufferedGraphicDeviceBase<
::canvas::DisambiguationHelper< WindowGraphicDeviceBase_Base >,
SpriteDeviceHelper,
::osl::MutexGuard,
::cppu::OWeakObject > SpriteCanvasDeviceBaseT;
typedef ::canvas::CanvasBase< SpriteCanvasDeviceBaseT,
CanvasHelper,
::osl::MutexGuard,
::cppu::OWeakObject > SpriteCanvasBaseT;
/** Product of this component's factory.
The SpriteCanvas object combines the actual Window canvas with
the XGraphicDevice interface. This is because there's a
one-to-one relation between them, anyway, since each window
can have exactly one canvas and one associated
XGraphicDevice. And to avoid messing around with circular
references, this is implemented as one single object.
*/
class SpriteCanvas : public SpriteCanvasBaseT
{
public:
SpriteCanvas( const ::com::sun::star::uno::Sequence<
::com::sun::star::uno::Any >& aArguments,
const ::com::sun::star::uno::Reference<
::com::sun::star::uno::XComponentContext >& rxContext );
void initialize();
/// Dispose all internal references
virtual void disposeThis();
// Forwarding the XComponent implementation to the
// cppu::ImplHelper templated base
// Classname Base doing refcounting Base implementing the XComponent interface
// | | |
// V V V
DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( SpriteCanvas, WindowGraphicDeviceBase_Base, ::cppu::WeakComponentImplHelperBase );
// XBufferController (partial)
virtual ::sal_Bool SAL_CALL showBuffer( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Bool SAL_CALL switchBuffer( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
// XSpriteCanvas
virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XAnimatedSprite > SAL_CALL createSpriteFromAnimation( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XAnimation >& animation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XAnimatedSprite > SAL_CALL createSpriteFromBitmaps( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > >& animationBitmaps, ::sal_Int8 interpolationMode ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::rendering::VolatileContentDestroyedException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCustomSprite > SAL_CALL createCustomSprite( const ::com::sun::star::geometry::RealSize2D& spriteSize ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XSprite > SAL_CALL createClonedSprite( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XSprite >& original ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
virtual ::sal_Bool SAL_CALL updateScreen( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
// XServiceName
virtual ::rtl::OUString SAL_CALL getServiceName( ) throw (::com::sun::star::uno::RuntimeException);
void show( const ::rtl::Reference< CanvasCustomSprite >& );
void hide( const ::rtl::Reference< CanvasCustomSprite >& );
/** Write out recorded actions
*/
bool renderRecordedActions() const;
private:
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > maArguments;
::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxComponentContext;
};
typedef ::rtl::Reference< SpriteCanvas > SpriteCanvasRef;
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,179 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef OGL_SPRITEDEVICEHELPER_HXX
#define OGL_SPRITEDEVICEHELPER_HXX
#include <rtl/ref.hxx>
#include <canvas/elapsedtime.hxx>
#include <com/sun/star/rendering/XGraphicDevice.hpp>
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
#include "ogl_buffercontext.hxx"
#include <set>
class Window;
class SystemChildWindow;
namespace basegfx{ class B2IVector; class B2DHomMatrix; }
namespace com { namespace sun { namespace star {
namespace awt { struct Rectangle; }
namespace geometry { struct AffineMatrix2D; }
}}}
namespace oglcanvas
{
class TextureCache;
class SpriteCanvas;
class CanvasCustomSprite;
class CanvasHelper;
class SpriteDeviceHelper : private ::boost::noncopyable
{
public:
SpriteDeviceHelper();
void init( Window& rWindow,
SpriteCanvas& rSpriteCanvas,
const ::com::sun::star::awt::Rectangle& rViewArea );
/// Dispose all internal references
void disposing();
// XWindowGraphicDevice
::com::sun::star::geometry::RealSize2D getPhysicalResolution();
::com::sun::star::geometry::RealSize2D getPhysicalSize();
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XLinePolyPolygon2D > createCompatibleLinePolyPolygon(
const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >& rDevice,
const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealPoint2D > >& points );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBezierPolyPolygon2D > createCompatibleBezierPolyPolygon(
const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >& rDevice,
const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealBezierSegment2D > >& points );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > createCompatibleBitmap(
const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >& rDevice,
const ::com::sun::star::geometry::IntegerSize2D& size );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XVolatileBitmap > createVolatileBitmap(
const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >& rDevice,
const ::com::sun::star::geometry::IntegerSize2D& size );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > createCompatibleAlphaBitmap(
const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >& rDevice,
const ::com::sun::star::geometry::IntegerSize2D& size );
::com::sun::star::uno::Reference< ::com::sun::star::rendering::XVolatileBitmap > createVolatileAlphaBitmap(
const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >& rDevice,
const ::com::sun::star::geometry::IntegerSize2D& size );
sal_Bool hasFullScreenMode( );
sal_Bool enterFullScreenMode( sal_Bool bEnter );
::sal_Int32 createBuffers( ::sal_Int32 nBuffers );
void destroyBuffers( );
::sal_Bool showBuffer( bool bIsVisible, ::sal_Bool bUpdateAll );
::sal_Bool switchBuffer( bool bIsVisible, ::sal_Bool bUpdateAll );
::com::sun::star::uno::Any isAccelerated() const;
::com::sun::star::uno::Any getDeviceHandle() const;
::com::sun::star::uno::Any getSurfaceHandle() const;
::com::sun::star::uno::Reference<
::com::sun::star::rendering::XColorSpace > getColorSpace() const;
void notifySizeUpdate( const ::com::sun::star::awt::Rectangle& rBounds );
/** called when DumpScreenContent property is enabled on
XGraphicDevice, and writes out bitmaps of current screen.
*/
void dumpScreenContent() const;
void show( const ::rtl::Reference< CanvasCustomSprite >& );
void hide( const ::rtl::Reference< CanvasCustomSprite >& );
/// enable linear gradient shader "texture" with given parameters
void useLinearGradientShader( const ::com::sun::star::rendering::ARGBColor* pColors,
const ::com::sun::star::uno::Sequence< double >& rStops,
const ::basegfx::B2DHomMatrix& rTexTransform );
/// enable radial gradient shader "texture" with given parameters
void useRadialGradientShader( const ::com::sun::star::rendering::ARGBColor* pColors,
const ::com::sun::star::uno::Sequence< double >& rStops,
const ::basegfx::B2DHomMatrix& rTexTransform );
/// enable rectangular gradient shader "texture" with given parameters
void useRectangularGradientShader( const ::com::sun::star::rendering::ARGBColor* pColors,
const ::com::sun::star::uno::Sequence< double >& rStops,
const ::basegfx::B2DHomMatrix& rTexTransform );
/// create a pbuffer context (for rendering into background surface)
IBufferContextSharedPtr createBufferContext(const ::basegfx::B2IVector& rSize) const;
/// Get instance of internal texture cache
TextureCache& getTextureCache() const;
////////////////////////////////////////////////////////
// nobody except IBufferContext implementations are supposed
// to use this
bool activatePBufferContext(const ::basegfx::B2IVector& rSize,
unsigned int PBuffer) const;
bool activateWindowContext() const;
bool updatePBufferTexture( const ::basegfx::B2IVector&,
unsigned int ) const;
private:
void resize( const ::basegfx::B2IVector& rNewSize );
void compileShader(unsigned int& o_rShaderHandle,
unsigned int eShaderType,
const char* pShaderSourceCode);
void linkShaders(unsigned int& o_rProgramHandle,
unsigned int nVertexProgramId,
unsigned int nFragmentProgramId);
/** Phyical output device
Deliberately not a refcounted reference, because of
potential circular references for canvas. Needed to
create bitmaps
*/
com::sun::star::rendering::XGraphicDevice* mpDevice;
/// Pointer to sprite canvas (owner of this helper), needed to create bitmaps
SpriteCanvas* mpSpriteCanvas;
std::set< ::rtl::Reference< CanvasCustomSprite > > maActiveSprites;
/// For the frame counter timings
::canvas::tools::ElapsedTime maLastUpdate;
boost::shared_ptr<SystemChildWindow> mpChildWindow;
void* mpDisplay;
void* mpGLContext;
void* mpGLPBufContext;
void* mpFBConfig;
boost::shared_ptr<TextureCache> mpTextureCache;
unsigned int mnDummyVertexProgram;
unsigned int mnLinearTwoColorGradientFragmentProgram;
unsigned int mnLinearMultiColorGradientFragmentProgram;
unsigned int mnRadialTwoColorGradientFragmentProgram;
unsigned int mnRadialMultiColorGradientFragmentProgram;
unsigned int mnRectangularTwoColorGradientFragmentProgram;
unsigned int mnRectangularMultiColorGradientFragmentProgram;
unsigned int mnLinearTwoColorGradientProgram;
unsigned int mnLinearMultiColorGradientProgram;
unsigned int mnRadialTwoColorGradientProgram;
unsigned int mnRadialMultiColorGradientProgram;
unsigned int mnRectangularTwoColorGradientProgram;
unsigned int mnRectangularMultiColorGradientProgram;
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,215 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "ogl_textlayout.hxx"
#include <canvas/debug.hxx>
#include <canvas/verbosetrace.hxx>
#include <tools/diagnose_ex.h>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/numeric/ftools.hxx>
using namespace ::com::sun::star;
namespace oglcanvas
{
TextLayout::TextLayout( const rendering::StringContext& aText,
sal_Int8 nDirection,
sal_Int64 /*nRandomSeed*/,
const CanvasFont::ImplRef& rFont ) :
TextLayoutBaseT( m_aMutex ),
maText( aText ),
maLogicalAdvancements(),
mpFont( rFont ),
mnTextDirection( nDirection )
{
}
void SAL_CALL TextLayout::disposing()
{
mpFont.reset();
}
// XTextLayout
uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes( ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >();
}
uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures( ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return uno::Sequence< geometry::RealRectangle2D >();
}
uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures( ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return uno::Sequence< geometry::RealRectangle2D >();
}
uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements( ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
return maLogicalAdvancements;
}
void SAL_CALL TextLayout::applyLogicalAdvancements( const uno::Sequence< double >& aAdvancements ) throw (lang::IllegalArgumentException, uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
if( aAdvancements.getLength() != maText.Length )
{
SAL_INFO("canvas.ogl", "TextLayout::applyLogicalAdvancements(): mismatching number of advancements");
throw lang::IllegalArgumentException();
}
maLogicalAdvancements = aAdvancements;
}
geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
ENSURE_OR_THROW( mpFont.get(),
"TextLayout::queryTextBounds(): invalid font" );
// fake text bounds by either taking the advancement values,
// or assuming square glyph boxes (width similar to height)
const rendering::FontRequest& rFontRequest( mpFont->getFontRequest() );
const double nFontSize( ::std::max( rFontRequest.CellSize,
rFontRequest.ReferenceAdvancement ) );
if( maLogicalAdvancements.getLength() )
{
return geometry::RealRectangle2D( 0, -nFontSize/2,
maLogicalAdvancements[ maLogicalAdvancements.getLength()-1 ],
nFontSize/2 );
}
else
{
return geometry::RealRectangle2D( 0, -nFontSize/2,
nFontSize * maText.Length,
nFontSize/2 );
}
}
double SAL_CALL TextLayout::justify( double /*nSize*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return 0.0;
}
double SAL_CALL TextLayout::combinedJustify( const uno::Sequence< uno::Reference< rendering::XTextLayout > >& /*aNextLayouts*/,
double /*nSize*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return 0.0;
}
rendering::TextHit SAL_CALL TextLayout::getTextHit( const geometry::RealPoint2D& /*aHitPoint*/ ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return rendering::TextHit();
}
rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 /*nInsertionIndex*/,
sal_Bool /*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return rendering::Caret();
}
sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 /*nStartIndex*/,
sal_Int32 /*nCaretAdvancement*/,
sal_Bool /*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return 0;
}
uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 /*nStartIndex*/,
sal_Int32 /*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return uno::Reference< rendering::XPolyPolygon2D >();
}
uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 /*nStartIndex*/,
sal_Int32 /*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return uno::Reference< rendering::XPolyPolygon2D >();
}
double SAL_CALL TextLayout::getBaselineOffset( ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return 0.0;
}
sal_Int8 SAL_CALL TextLayout::getMainTextDirection( ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
return mnTextDirection;
}
uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
return mpFont.getRef();
}
rendering::StringContext SAL_CALL TextLayout::getText( ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
return maText;
}
bool TextLayout::draw( const rendering::ViewState& /*rViewState*/,
const rendering::RenderState& /*rRenderState*/,
const uno::Reference< rendering::XGraphicDevice >& /*xGraphicDevice*/ ) const
{
::osl::MutexGuard aGuard( m_aMutex );
// TODO
return true;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef OGL_TEXTLAYOUT_HXX
#define OGL_TEXTLAYOUT_HXX
#include <cppuhelper/compbase1.hxx>
#include <comphelper/broadcasthelper.hxx>
#include <com/sun/star/rendering/XTextLayout.hpp>
#include <basegfx/vector/b2isize.hxx>
#include <boost/utility.hpp>
#include "ogl_canvasfont.hxx"
/* Definition of TextLayout class */
namespace oglcanvas
{
typedef ::cppu::WeakComponentImplHelper1< ::com::sun::star::rendering::XTextLayout > TextLayoutBaseT;
class TextLayout : public ::comphelper::OBaseMutex,
public TextLayoutBaseT,
private ::boost::noncopyable
{
public:
TextLayout( const ::com::sun::star::rendering::StringContext& aText,
sal_Int8 nDirection,
sal_Int64 nRandomSeed,
const CanvasFont::ImplRef& rFont );
/// Dispose all internal references
virtual void SAL_CALL disposing();
// XTextLayout
virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D > > SAL_CALL queryTextShapes( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealRectangle2D > SAL_CALL queryInkMeasures( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealRectangle2D > SAL_CALL queryMeasures( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Sequence< double > SAL_CALL queryLogicalAdvancements( ) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL applyLogicalAdvancements( const ::com::sun::star::uno::Sequence< double >& aAdvancements ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::geometry::RealRectangle2D SAL_CALL queryTextBounds( ) throw (::com::sun::star::uno::RuntimeException);
virtual double SAL_CALL justify( double nSize ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
virtual double SAL_CALL combinedJustify( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XTextLayout > >& aNextLayouts, double nSize ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::rendering::TextHit SAL_CALL getTextHit( const ::com::sun::star::geometry::RealPoint2D& aHitPoint ) throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::rendering::Caret SAL_CALL getCaret( sal_Int32 nInsertionIndex, sal_Bool bExcludeLigatures ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
virtual sal_Int32 SAL_CALL getNextInsertionIndex( sal_Int32 nStartIndex, sal_Int32 nCaretAdvancement, sal_Bool bExcludeLigatures ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D > SAL_CALL queryVisualHighlighting( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D > SAL_CALL queryLogicalHighlighting( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
virtual double SAL_CALL getBaselineOffset( ) throw (::com::sun::star::uno::RuntimeException);
virtual sal_Int8 SAL_CALL getMainTextDirection( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont > SAL_CALL getFont( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::rendering::StringContext SAL_CALL getText( ) throw (::com::sun::star::uno::RuntimeException);
bool draw( const ::com::sun::star::rendering::ViewState& rViewState,
const ::com::sun::star::rendering::RenderState& rRenderState,
const ::com::sun::star::uno::Reference<
::com::sun::star::rendering::XGraphicDevice >& xGraphicDevice ) const;
private:
::com::sun::star::rendering::StringContext maText;
::com::sun::star::uno::Sequence< double > maLogicalAdvancements;
CanvasFont::ImplRef mpFont;
sal_Int8 mnTextDirection;
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,124 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#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),
mnMissCount(0),
mnHitCount(0)
{}
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.nTexture);
++aCurr;
}
maCache.clear();
mnMissCount = 0;
mnHitCount = 0;
}
void TextureCache::prune()
{
// un-bind any texture
glBindTexture(GL_TEXTURE_2D, 0);
// delete already "old" textures, mark "new" entries "old"
TextureCacheMapT::iterator aNext;
TextureCacheMapT::iterator aCurr=maCache.begin();
const TextureCacheMapT::iterator aEnd=maCache.end();
while( aCurr != aEnd )
{
aNext=aCurr; ++aNext;
if( aCurr->second.bOld )
{
glDeleteTextures(1, &aCurr->second.nTexture);
maCache.erase(aCurr);
}
else
{
aCurr->second.bOld = true;
}
aCurr=aNext;
}
mnMissCount = 0;
mnHitCount = 0;
}
unsigned int TextureCache::getTexture( const geometry::IntegerSize2D& rPixelSize,
const sal_Int8* pPixel,
sal_uInt32 nPixelCrc32) const
{
unsigned int nTexture(0);
// texture already cached?
TextureCacheMapT::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 = nTexture;
++mnMissCount;
return nTexture;
}
else
{
nTexture = aCacheEntry->second.nTexture;
aCacheEntry->second.bOld = false;
++mnHitCount;
}
return nTexture;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,64 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef OGL_TEXTURECACHE_HXX
#define OGL_TEXTURECACHE_HXX
#include <sal/types.h>
#include <unordered_map>
namespace com { namespace sun { namespace star {
namespace geometry { struct IntegerSize2D; }
}}}
namespace oglcanvas
{
class TextureCache
{
public:
TextureCache();
~TextureCache();
/// clear whole cache, reset statistic counters
void flush();
/** prune old entries from cache
Everytime this method is called, all cache entries are set
to "old". If subsequently not used by getTexture(),
they'll be entitled for expunge on the next prune()
call. Resets statistic counters.
*/
void prune();
/// Statistics
size_t getCacheSize() const { return maCache.size(); };
sal_uInt32 getCacheMissCount() const { return mnMissCount; }
sal_uInt32 getCacheHitCount() const { return mnHitCount; }
unsigned int getTexture( const ::com::sun::star::geometry::IntegerSize2D& rPixelSize,
const sal_Int8* pPixel,
sal_uInt32 nPixelCrc32) const;
private:
struct CacheEntry
{
CacheEntry() : nTexture(0), bOld(false) {}
unsigned int nTexture;
bool bOld;
};
typedef std::unordered_map<sal_uInt32,CacheEntry> TextureCacheMapT;
mutable TextureCacheMapT maCache;
mutable sal_uInt32 mnMissCount;
mutable sal_uInt32 mnHitCount;
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,31 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef OGL_CANVAS_TOOLS_HXX
#define OGL_CANVAS_TOOLS_HXX
#include <sal/config.h>
#include <GL/gl.h>
namespace oglcanvas
{
struct TransformationPreserver
{
TransformationPreserver()
{ glPushMatrix(); }
~TransformationPreserver()
{ glPopMatrix(); }
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
-->
<component loader="com.sun.star.loader.SharedLibrary" prefix="oglcanvas"
xmlns="http://openoffice.org/2010/uno-components">
<implementation name="com.sun.star.comp.rendering.SpriteCanvas.OGL">
<service name="com.sun.star.rendering.SpriteCanvas.OGL"/>
</implementation>
</component>

View File

@ -978,7 +978,7 @@ AC_ARG_ENABLE(cairo-canvas,
AC_ARG_ENABLE(opengl,
AS_HELP_STRING([--disable-opengl],
[Determines whether to build the OpenGL 3D slide transitions component.]))
[Determines whether to build the OpenGL 3D slide transitions and canvas component.]))
AC_ARG_ENABLE(opencl,
AS_HELP_STRING([--disable-opencl],

View File

@ -45,6 +45,8 @@ certain functionality.
@li @c canvas.cairo
@li @c canvas.directx
@li @c canvas.vcl
@li @c canvas.null
@li @c canvas.ogl
@section chart2

View File

@ -54,6 +54,7 @@
<prop oor:name="PreferredImplementations" oor:type="oor:string-list">
<value oor:separator=",">com.sun.star.comp.rendering.SpriteCanvas.DX9,
com.sun.star.comp.rendering.SpriteCanvas.DX5,
com.sun.star.comp.rendering.SpriteCanvas.OGL,
com.sun.star.comp.rendering.SpriteCanvas.Cairo,
com.sun.star.comp.rendering.SpriteCanvas.GL,
com.sun.star.comp.rendering.SpriteCanvas.Java,