2006-02-28 09:38:09 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
|
|
*
|
|
|
|
* $RCSfile: cairo_spritecanvas.cxx,v $
|
|
|
|
*
|
2008-04-02 08:43:24 +00:00
|
|
|
* $Revision: 1.9 $
|
2006-02-28 09:38:09 +00:00
|
|
|
*
|
2008-04-02 08:43:24 +00:00
|
|
|
* last change: $Author: kz $ $Date: 2008-04-02 09:43:24 $
|
2006-02-28 09:38:09 +00:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 02:21:04 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_canvas.hxx"
|
|
|
|
|
2006-02-28 09:38:09 +00:00
|
|
|
#include <canvas/debug.hxx>
|
|
|
|
#include <canvas/verbosetrace.hxx>
|
|
|
|
#include <canvas/canvastools.hxx>
|
|
|
|
|
|
|
|
#include <osl/mutex.hxx>
|
|
|
|
|
|
|
|
#include <com/sun/star/registry/XRegistryKey.hpp>
|
|
|
|
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
|
|
|
|
#include <com/sun/star/uno/XComponentContext.hpp>
|
|
|
|
|
|
|
|
#include <cppuhelper/factory.hxx>
|
|
|
|
#include <cppuhelper/implementationentry.hxx>
|
2006-12-13 13:43:15 +00:00
|
|
|
#include <comphelper/servicedecl.hxx>
|
2006-02-28 09:38:09 +00:00
|
|
|
|
|
|
|
#include <basegfx/matrix/b2dhommatrix.hxx>
|
|
|
|
#include <basegfx/point/b2dpoint.hxx>
|
|
|
|
#include <basegfx/tools/canvastools.hxx>
|
|
|
|
#include <basegfx/numeric/ftools.hxx>
|
|
|
|
|
|
|
|
#include "cairo_spritecanvas.hxx"
|
2008-01-29 07:01:49 +00:00
|
|
|
#include "cairo_devicehelper.hxx"
|
2006-02-28 09:38:09 +00:00
|
|
|
|
|
|
|
using namespace ::cairo;
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
|
|
|
#define SERVICE_NAME "com.sun.star.rendering.CairoCanvas"
|
|
|
|
|
2006-12-13 13:43:15 +00:00
|
|
|
namespace cairocanvas
|
2006-02-28 09:38:09 +00:00
|
|
|
{
|
2006-12-13 13:43:15 +00:00
|
|
|
SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
|
|
|
|
const uno::Reference< uno::XComponentContext >& rxContext ) :
|
|
|
|
mxComponentContext( rxContext ),
|
2007-07-17 13:21:38 +00:00
|
|
|
mpBackgroundSurface( NULL ),
|
|
|
|
mpBackgroundCairo( NULL )
|
2006-02-28 09:38:09 +00:00
|
|
|
{
|
2006-12-13 13:43:15 +00:00
|
|
|
// #i64742# Only call initialize when not in probe mode
|
|
|
|
if( aArguments.getLength() != 0 )
|
|
|
|
initialize( aArguments );
|
2006-02-28 09:38:09 +00:00
|
|
|
}
|
|
|
|
|
2006-12-13 13:43:15 +00:00
|
|
|
void SpriteCanvas::initialize( const uno::Sequence< uno::Any >& aArguments )
|
2006-02-28 09:38:09 +00:00
|
|
|
{
|
2006-12-13 13:43:15 +00:00
|
|
|
VERBOSE_TRACE("SpriteCanvas created %p\n", this);
|
2006-02-28 09:38:09 +00:00
|
|
|
|
2006-12-13 13:43:15 +00:00
|
|
|
// At index 1, we expect a system window handle here,
|
|
|
|
// containing a pointer to a valid window, on which to output
|
|
|
|
// At index 2, we expect the current window bound rect
|
2008-04-02 08:43:24 +00:00
|
|
|
// NOTE: type is derived from vcl/source/window/window.cxx (XCanvas setup)
|
|
|
|
#ifdef QUARTZ
|
|
|
|
CHECK_AND_THROW( aArguments.getLength() >= 4 &&
|
|
|
|
aArguments[1].getValueTypeClass() == uno::TypeClass_UNSIGNED_HYPER,
|
|
|
|
"SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
|
|
|
|
#else
|
2006-12-13 13:43:15 +00:00
|
|
|
CHECK_AND_THROW( aArguments.getLength() >= 4 &&
|
|
|
|
aArguments[1].getValueTypeClass() == uno::TypeClass_LONG,
|
|
|
|
"SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
|
2008-04-02 08:43:24 +00:00
|
|
|
#endif
|
2006-02-28 09:38:09 +00:00
|
|
|
|
2006-12-13 13:43:15 +00:00
|
|
|
awt::Rectangle aRect;
|
|
|
|
aArguments[2] >>= aRect;
|
2006-02-28 09:38:09 +00:00
|
|
|
|
2006-12-13 13:43:15 +00:00
|
|
|
sal_Bool bIsFullscreen( sal_False );
|
|
|
|
aArguments[3] >>= bIsFullscreen;
|
|
|
|
|
2007-11-09 10:32:38 +00:00
|
|
|
sal_Int64 nWindowPtr = 0;
|
|
|
|
aArguments[0] >>= nWindowPtr;
|
|
|
|
Window* pOutputWindow = reinterpret_cast<Window*>(nWindowPtr);
|
|
|
|
|
|
|
|
CHECK_AND_THROW( pOutputWindow != NULL,
|
|
|
|
"SpriteCanvas::SpriteCanvas: invalid Window pointer" );
|
2006-12-13 13:43:15 +00:00
|
|
|
|
2008-04-02 08:43:24 +00:00
|
|
|
#if defined(CAIRO_HAS_XLIB_SURFACE) && !defined (QUARTZ)
|
2008-01-29 07:01:49 +00:00
|
|
|
bool bHasXRender = HasXRender( cairocanvas::GetSysData(pOutputWindow) );
|
|
|
|
CHECK_AND_THROW( bHasXRender == true,
|
|
|
|
"SpriteCanvas::SpriteCanvas: No RENDER extension" );
|
2008-04-02 08:43:24 +00:00
|
|
|
#endif
|
2008-01-29 07:01:49 +00:00
|
|
|
|
2006-12-13 13:43:15 +00:00
|
|
|
Size aPixelSize( pOutputWindow->GetOutputSizePixel() );
|
|
|
|
const ::basegfx::B2ISize aSize( aPixelSize.Width(),
|
|
|
|
aPixelSize.Height() );
|
|
|
|
|
|
|
|
// setup helper
|
|
|
|
maDeviceHelper.init( *pOutputWindow,
|
|
|
|
*this,
|
|
|
|
aSize,
|
|
|
|
bIsFullscreen );
|
|
|
|
|
|
|
|
maCanvasHelper.init( maRedrawManager,
|
|
|
|
*this,
|
|
|
|
aSize );
|
2006-02-28 09:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL SpriteCanvas::disposing()
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
|
|
|
mxComponentContext.clear();
|
|
|
|
|
|
|
|
if( mpBackgroundCairo ) {
|
|
|
|
cairo_destroy( mpBackgroundCairo );
|
|
|
|
mpBackgroundCairo = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( mpBackgroundSurface ) {
|
|
|
|
mpBackgroundSurface->Unref();
|
|
|
|
mpBackgroundSurface = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// forward to parent
|
|
|
|
SpriteCanvasBaseT::disposing();
|
|
|
|
}
|
|
|
|
|
|
|
|
::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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL SpriteCanvas::updateScreen( 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 : maCanvasHelper.updateScreen(
|
|
|
|
::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds),
|
|
|
|
bUpdateAll,
|
|
|
|
mbSurfaceDirty );
|
|
|
|
}
|
|
|
|
|
|
|
|
::rtl::OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
Surface* SpriteCanvas::getSurface( const ::basegfx::B2ISize& rSize, Content aContent )
|
|
|
|
{
|
2006-12-13 13:43:15 +00:00
|
|
|
return maDeviceHelper.getSurface( rSize, aContent );
|
2006-02-28 09:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Surface* SpriteCanvas::getSurface( Content aContent )
|
|
|
|
{
|
2006-12-13 13:43:15 +00:00
|
|
|
return maDeviceHelper.getSurface( aContent );
|
2006-02-28 09:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Surface* SpriteCanvas::getSurface( Bitmap& rBitmap )
|
|
|
|
{
|
2006-12-13 13:43:15 +00:00
|
|
|
Surface *pSurface = NULL;
|
2006-02-28 09:38:09 +00:00
|
|
|
|
2006-12-13 13:43:15 +00:00
|
|
|
BitmapSystemData aData;
|
|
|
|
if( rBitmap.GetSystemData( aData ) ) {
|
|
|
|
const Size& rSize = rBitmap.GetSizePixel();
|
2006-02-28 09:38:09 +00:00
|
|
|
|
2006-12-13 13:43:15 +00:00
|
|
|
pSurface = maDeviceHelper.getSurface( aData, rSize );
|
|
|
|
}
|
2006-02-28 09:38:09 +00:00
|
|
|
|
2006-12-13 13:43:15 +00:00
|
|
|
return pSurface;
|
2006-02-28 09:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Surface* SpriteCanvas::getBufferSurface()
|
|
|
|
{
|
2006-12-13 13:43:15 +00:00
|
|
|
return maDeviceHelper.getBufferSurface();
|
2006-02-28 09:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Surface* SpriteCanvas::getWindowSurface()
|
|
|
|
{
|
2006-12-13 13:43:15 +00:00
|
|
|
return maDeviceHelper.getWindowSurface();
|
2006-02-28 09:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Surface* SpriteCanvas::getBackgroundSurface()
|
|
|
|
{
|
2006-12-13 13:43:15 +00:00
|
|
|
return mpBackgroundSurface;
|
2006-02-28 09:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const ::basegfx::B2ISize& SpriteCanvas::getSizePixel()
|
|
|
|
{
|
2006-12-13 13:43:15 +00:00
|
|
|
return maDeviceHelper.getSizePixel();
|
2006-02-28 09:38:09 +00:00
|
|
|
}
|
|
|
|
|
2007-11-09 09:14:15 +00:00
|
|
|
void SpriteCanvas::setSizePixel( const ::basegfx::B2ISize& rSize )
|
2006-02-28 09:38:09 +00:00
|
|
|
{
|
|
|
|
if( mpBackgroundSurface )
|
|
|
|
{
|
|
|
|
mpBackgroundSurface->Unref();
|
|
|
|
}
|
|
|
|
mpBackgroundSurface = maDeviceHelper.getSurface( CAIRO_CONTENT_COLOR );
|
|
|
|
|
|
|
|
if( mpBackgroundCairo )
|
|
|
|
{
|
|
|
|
cairo_destroy( mpBackgroundCairo );
|
|
|
|
}
|
|
|
|
mpBackgroundCairo = mpBackgroundSurface->getCairo();
|
|
|
|
|
2007-11-09 09:14:15 +00:00
|
|
|
maCanvasHelper.setSize( rSize );
|
2006-02-28 09:38:09 +00:00
|
|
|
maCanvasHelper.setSurface( mpBackgroundSurface, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteCanvas::flush()
|
|
|
|
{
|
2006-12-13 13:43:15 +00:00
|
|
|
maDeviceHelper.flush();
|
2006-02-28 09:38:09 +00:00
|
|
|
}
|
|
|
|
|
2006-12-13 13:43:15 +00:00
|
|
|
bool SpriteCanvas::repaint( Surface* pSurface,
|
|
|
|
const rendering::ViewState& viewState,
|
|
|
|
const rendering::RenderState& renderState )
|
2006-02-28 09:38:09 +00:00
|
|
|
{
|
2006-12-13 13:43:15 +00:00
|
|
|
return maCanvasHelper.repaint( pSurface, viewState, renderState );
|
2006-02-28 09:38:09 +00:00
|
|
|
}
|
|
|
|
|
2006-12-13 13:43:15 +00:00
|
|
|
namespace sdecl = comphelper::service_decl;
|
|
|
|
#if defined (__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ <= 3)
|
|
|
|
sdecl::class_<SpriteCanvas, sdecl::with_args<true> > serviceImpl;
|
|
|
|
const sdecl::ServiceDecl cairoCanvasDecl(
|
|
|
|
serviceImpl,
|
|
|
|
#else
|
|
|
|
const sdecl::ServiceDecl cairoCanvasDecl(
|
|
|
|
sdecl::class_<SpriteCanvas, sdecl::with_args<true> >(),
|
|
|
|
#endif
|
|
|
|
"com.sun.star.comp.rendering.CairoCanvas",
|
|
|
|
SERVICE_NAME );
|
2006-02-28 09:38:09 +00:00
|
|
|
}
|
|
|
|
|
2006-12-13 13:43:15 +00:00
|
|
|
// The C shared lib entry points
|
|
|
|
COMPHELPER_SERVICEDECL_EXPORTS1(cairocanvas::cairoCanvasDecl)
|