Files
libreoffice/canvas/source/cairo/cairo_devicehelper.cxx
Kurt Zenker 3df4281a02 INTEGRATION: CWS canvas05 (1.7.24); FILE MERGED
2008/05/13 14:51:48 thb 1.7.24.10: removed redundant extra surface from spritecanvas; removed silly conditional that always resolved to true from X11Surface ctor
2008/04/21 07:32:43 thb 1.7.24.9: RESYNC: (1.9-1.10); FILE MERGED
2008/04/07 14:34:15 thb 1.7.24.8: RESYNC: (1.7-1.9); FILE MERGED
2008/04/04 22:08:34 thb 1.7.24.7: Fixed output of bezier polygons for cairo; fixed missing surfaces here and there; removed useless refcounted SurfaceProvider arguments (that lead to premature canvas death, as called during ctor)
2008/04/03 20:12:36 thb 1.7.24.6: Improved the system-dependent passing-around of the OS handles - now much more opaque
2008/04/02 23:07:06 thb 1.7.24.5: And now with all missing functions
2008/04/02 22:56:27 thb 1.7.24.4: Reworked Surface class to abstract interface; changed all manual refcount handling to RAII
2008/03/18 22:00:56 thb 1.7.24.3: Implementing non-backbuffered canvas for cairocanvas as well - reworked to share most of the code
2007/12/20 22:18:56 thb 1.7.24.2: #i81092# #i78888# #i78925# #i79258# #i79437# #i84784# Large canvas rework, completing various areas such as color spaces, bitmap data access, true sprite and non-sprite implementations, and upstreaming the canvas parts of rodos emf+ rendering
2007/12/18 10:05:52 thb 1.7.24.1: #i84049# Applying patch from jnavrati to fix a crash when xrender is not available
2008-06-24 09:21:51 +00:00

306 lines
10 KiB
C++

/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: cairo_devicehelper.cxx,v $
* $Revision: 1.11 $
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org 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 version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_canvas.hxx"
#include <canvas/debug.hxx>
#include <canvas/verbosetrace.hxx>
#include <canvas/canvastools.hxx>
#include <osl/mutex.hxx>
#include <cppuhelper/compbase1.hxx>
#include <com/sun/star/lang/NoSupportException.hpp>
#include <toolkit/helper/vclunohelper.hxx>
#include <basegfx/tools/canvastools.hxx>
#include <basegfx/tools/unopolypolygon.hxx>
#include <vcl/canvastools.hxx>
#include <tools/stream.hxx>
#include "cairo_spritecanvas.hxx"
#include "cairo_canvasbitmap.hxx"
#include "cairo_devicehelper.hxx"
using namespace ::cairo;
using namespace ::com::sun::star;
namespace cairocanvas
{
DeviceHelper::DeviceHelper() :
mpSurfaceProvider( NULL ),
mpRefDevice( NULL ),
mpSurface()
{
}
void DeviceHelper::implInit( SurfaceProvider& rSurfaceProvider,
OutputDevice& rRefDevice )
{
mpSurfaceProvider = &rSurfaceProvider;
mpRefDevice = &rRefDevice;
// no own surface, this is handled by derived classes
}
void DeviceHelper::init( SurfaceProvider& rSurfaceProvider,
OutputDevice& rRefDevice )
{
implInit(rSurfaceProvider, rRefDevice);
OutputDevice* pOutDev=getOutputDevice();
mpSurface = cairo::createSurface( *pOutDev,
pOutDev->GetOutOffXPixel(),
pOutDev->GetOutOffYPixel(),
pOutDev->GetOutputWidthPixel(),
pOutDev->GetOutputHeightPixel() );
}
void DeviceHelper::disposing()
{
// release all references
mpSurface.reset();
mpRefDevice = NULL;
mpSurfaceProvider = NULL;
}
void DeviceHelper::setSize( const ::basegfx::B2ISize& rSize )
{
OSL_TRACE("DeviceHelper::setSize(): device size %d x %d", rSize.getX(), rSize.getY() );
if( !mpRefDevice )
return; // disposed
OutputDevice* pOutDev=getOutputDevice();
#if defined (UNX) && !defined (QUARTZ)
// X11 only
if( mpSurface )
mpSurface->Resize( rSize.getX() + pOutDev->GetOutOffXPixel(),
rSize.getY() + pOutDev->GetOutOffYPixel() );
else
#endif
mpSurface = cairo::createSurface(
*pOutDev,
pOutDev->GetOutOffXPixel(),
pOutDev->GetOutOffYPixel(),
rSize.getX(), rSize.getY() );
}
geometry::RealSize2D DeviceHelper::getPhysicalResolution()
{
// Map a one-by-one millimeter box to pixel
const MapMode aOldMapMode( mpRefDevice->GetMapMode() );
mpRefDevice->SetMapMode( MapMode(MAP_MM) );
const Size aPixelSize( mpRefDevice->LogicToPixel(Size(1,1)) );
mpRefDevice->SetMapMode( aOldMapMode );
return ::vcl::unotools::size2DFromSize( aPixelSize );
}
geometry::RealSize2D DeviceHelper::getPhysicalSize()
{
if( !mpRefDevice )
return ::canvas::tools::createInfiniteSize2D(); // we're disposed
// Map the pixel dimensions of the output window to millimeter
const MapMode aOldMapMode( mpRefDevice->GetMapMode() );
mpRefDevice->SetMapMode( MapMode(MAP_MM) );
const Size aLogSize( mpRefDevice->PixelToLogic(mpRefDevice->GetOutputSizePixel()) );
mpRefDevice->SetMapMode( aOldMapMode );
return ::vcl::unotools::size2DFromSize( aLogSize );
}
uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
const uno::Reference< rendering::XGraphicDevice >& ,
const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
{
// disposed?
if( !mpSurfaceProvider )
return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed
return uno::Reference< rendering::XLinePolyPolygon2D >(
new ::basegfx::unotools::UnoPolyPolygon(
::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
}
uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
const uno::Reference< rendering::XGraphicDevice >& ,
const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
{
// disposed?
if( !mpSurfaceProvider )
return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed
return uno::Reference< rendering::XBezierPolyPolygon2D >(
new ::basegfx::unotools::UnoPolyPolygon(
::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
}
uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
const uno::Reference< rendering::XGraphicDevice >& rDevice,
const geometry::IntegerSize2D& size )
{
// disposed?
if( !mpSurfaceProvider )
return uno::Reference< rendering::XBitmap >(); // we're disposed
return uno::Reference< rendering::XBitmap >(
new CanvasBitmap(
::basegfx::unotools::b2ISizeFromIntegerSize2D( size ),
SurfaceProviderRef(mpSurfaceProvider),
rDevice.get(),
false ));
}
uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
const uno::Reference< rendering::XGraphicDevice >& ,
const geometry::IntegerSize2D& /*size*/ )
{
return uno::Reference< rendering::XVolatileBitmap >();
}
uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
const uno::Reference< rendering::XGraphicDevice >& rDevice,
const geometry::IntegerSize2D& size )
{
// disposed?
if( !mpSurfaceProvider )
return uno::Reference< rendering::XBitmap >(); // we're disposed
return uno::Reference< rendering::XBitmap >(
new CanvasBitmap(
::basegfx::unotools::b2ISizeFromIntegerSize2D( size ),
SurfaceProviderRef(mpSurfaceProvider),
rDevice.get(),
true ));
}
uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
const uno::Reference< rendering::XGraphicDevice >& ,
const geometry::IntegerSize2D& /*size*/ )
{
return uno::Reference< rendering::XVolatileBitmap >();
}
sal_Bool DeviceHelper::hasFullScreenMode()
{
// TODO(F3): offer fullscreen mode the XCanvas way
return false;
}
sal_Bool DeviceHelper::enterFullScreenMode( sal_Bool /*bEnter*/ )
{
// TODO(F3): offer fullscreen mode the XCanvas way
return false;
}
uno::Any DeviceHelper::isAccelerated() const
{
return ::com::sun::star::uno::makeAny(false);
}
uno::Any DeviceHelper::getDeviceHandle() const
{
return uno::makeAny( reinterpret_cast< sal_Int64 >(mpRefDevice) );
}
uno::Any DeviceHelper::getSurfaceHandle() const
{
return uno::Any();
}
namespace
{
struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
DeviceColorSpace>
{
uno::Reference<rendering::XColorSpace> operator()()
{
return vcl::unotools::createStandardColorSpace();
}
};
}
uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
{
// always the same
return DeviceColorSpace::get();
}
void DeviceHelper::dumpScreenContent() const
{
static sal_uInt32 nFilePostfixCount(0);
if( mpRefDevice )
{
String aFilename( String::CreateFromAscii("dbg_frontbuffer") );
aFilename += String::CreateFromInt32(nFilePostfixCount);
aFilename += String::CreateFromAscii(".bmp");
SvFileStream aStream( aFilename, STREAM_STD_READWRITE );
const ::Point aEmptyPoint;
bool bOldMap( mpRefDevice->IsMapModeEnabled() );
mpRefDevice->EnableMapMode( FALSE );
aStream << mpRefDevice->GetBitmap(aEmptyPoint,
mpRefDevice->GetOutputSizePixel());
mpRefDevice->EnableMapMode( bOldMap );
++nFilePostfixCount;
}
}
SurfaceSharedPtr DeviceHelper::getSurface()
{
return mpSurface;
}
SurfaceSharedPtr DeviceHelper::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
{
if( mpSurface )
return mpSurface->getSimilar( aContent, rSize.getX(), rSize.getY() );
return SurfaceSharedPtr();
}
SurfaceSharedPtr DeviceHelper::createSurface( BitmapSystemData& rData, const Size& rSize )
{
if( mpRefDevice )
return createBitmapSurface( *mpRefDevice, rData, rSize );
return SurfaceSharedPtr();
}
}