2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-10-08 10:00:18 +01:00
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2006-02-28 09:35:26 +00:00
|
|
|
|
|
|
|
#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>
|
|
|
|
|
2006-12-13 13:40:11 +00:00
|
|
|
#include <toolkit/helper/vclunohelper.hxx>
|
2006-02-28 09:35:26 +00:00
|
|
|
#include <basegfx/tools/canvastools.hxx>
|
2008-06-24 09:21:51 +00:00
|
|
|
#include <basegfx/tools/unopolypolygon.hxx>
|
2006-02-28 09:35:26 +00:00
|
|
|
|
|
|
|
#include <vcl/canvastools.hxx>
|
2013-01-10 16:28:40 +00:00
|
|
|
#include <vcl/dibtools.hxx>
|
2006-02-28 09:35:26 +00:00
|
|
|
|
|
|
|
#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() :
|
2008-06-24 09:21:51 +00:00
|
|
|
mpSurfaceProvider( NULL ),
|
|
|
|
mpRefDevice( NULL ),
|
|
|
|
mpSurface()
|
2006-02-28 09:35:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
void DeviceHelper::implInit( SurfaceProvider& rSurfaceProvider,
|
|
|
|
OutputDevice& rRefDevice )
|
2006-02-28 09:35:26 +00:00
|
|
|
{
|
2008-06-24 09:21:51 +00:00
|
|
|
mpSurfaceProvider = &rSurfaceProvider;
|
|
|
|
mpRefDevice = &rRefDevice;
|
2006-02-28 09:35:26 +00:00
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
// no own surface, this is handled by derived classes
|
|
|
|
}
|
2006-02-28 09:35:26 +00:00
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
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() );
|
2006-02-28 09:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceHelper::disposing()
|
|
|
|
{
|
|
|
|
// release all references
|
2008-06-24 09:21:51 +00:00
|
|
|
mpSurface.reset();
|
|
|
|
mpRefDevice = NULL;
|
|
|
|
mpSurfaceProvider = NULL;
|
|
|
|
}
|
2006-02-28 09:35:26 +00:00
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
void DeviceHelper::setSize( const ::basegfx::B2ISize& rSize )
|
|
|
|
{
|
2015-03-13 18:20:18 +01:00
|
|
|
SAL_INFO(
|
|
|
|
"canvas.cairo",
|
|
|
|
"device size " << rSize.getX() << " x " << rSize.getY());
|
2006-02-28 09:35:26 +00:00
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
if( !mpRefDevice )
|
|
|
|
return; // disposed
|
2006-02-28 09:35:26 +00:00
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
OutputDevice* pOutDev=getOutputDevice();
|
|
|
|
|
2015-03-18 13:38:11 +00:00
|
|
|
if (mpSurface && pOutDev->CanResizeCairoSurface())
|
|
|
|
{
|
|
|
|
// X11 only
|
2008-06-24 09:21:51 +00:00
|
|
|
mpSurface->Resize( rSize.getX() + pOutDev->GetOutOffXPixel(),
|
|
|
|
rSize.getY() + pOutDev->GetOutOffYPixel() );
|
2015-03-18 13:38:11 +00:00
|
|
|
}
|
2008-06-24 09:21:51 +00:00
|
|
|
else
|
2015-03-18 13:38:11 +00:00
|
|
|
{
|
2008-06-24 09:21:51 +00:00
|
|
|
mpSurface = cairo::createSurface(
|
|
|
|
*pOutDev,
|
|
|
|
pOutDev->GetOutOffXPixel(),
|
|
|
|
pOutDev->GetOutOffYPixel(),
|
|
|
|
rSize.getX(), rSize.getY() );
|
2015-03-18 13:38:11 +00:00
|
|
|
}
|
2006-02-28 09:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
geometry::RealSize2D DeviceHelper::getPhysicalResolution()
|
|
|
|
{
|
|
|
|
// Map a one-by-one millimeter box to pixel
|
2008-06-24 09:21:51 +00:00
|
|
|
const MapMode aOldMapMode( mpRefDevice->GetMapMode() );
|
|
|
|
mpRefDevice->SetMapMode( MapMode(MAP_MM) );
|
|
|
|
const Size aPixelSize( mpRefDevice->LogicToPixel(Size(1,1)) );
|
|
|
|
mpRefDevice->SetMapMode( aOldMapMode );
|
2006-02-28 09:35:26 +00:00
|
|
|
|
|
|
|
return ::vcl::unotools::size2DFromSize( aPixelSize );
|
|
|
|
}
|
|
|
|
|
|
|
|
geometry::RealSize2D DeviceHelper::getPhysicalSize()
|
|
|
|
{
|
2008-06-24 09:21:51 +00:00
|
|
|
if( !mpRefDevice )
|
2006-02-28 09:35:26 +00:00
|
|
|
return ::canvas::tools::createInfiniteSize2D(); // we're disposed
|
|
|
|
|
|
|
|
// Map the pixel dimensions of the output window to millimeter
|
2008-06-24 09:21:51 +00:00
|
|
|
const MapMode aOldMapMode( mpRefDevice->GetMapMode() );
|
|
|
|
mpRefDevice->SetMapMode( MapMode(MAP_MM) );
|
|
|
|
const Size aLogSize( mpRefDevice->PixelToLogic(mpRefDevice->GetOutputSizePixel()) );
|
|
|
|
mpRefDevice->SetMapMode( aOldMapMode );
|
2006-02-28 09:35:26 +00:00
|
|
|
|
|
|
|
return ::vcl::unotools::size2DFromSize( aLogSize );
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
|
2008-06-24 09:21:51 +00:00
|
|
|
const uno::Reference< rendering::XGraphicDevice >& ,
|
2006-02-28 09:35:26 +00:00
|
|
|
const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
|
|
|
|
{
|
|
|
|
// disposed?
|
2008-06-24 09:21:51 +00:00
|
|
|
if( !mpSurfaceProvider )
|
2006-02-28 09:35:26 +00:00
|
|
|
return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed
|
|
|
|
|
|
|
|
return uno::Reference< rendering::XLinePolyPolygon2D >(
|
2008-06-24 09:21:51 +00:00
|
|
|
new ::basegfx::unotools::UnoPolyPolygon(
|
2006-02-28 09:35:26 +00:00
|
|
|
::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
|
2008-06-24 09:21:51 +00:00
|
|
|
const uno::Reference< rendering::XGraphicDevice >& ,
|
2006-02-28 09:35:26 +00:00
|
|
|
const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
|
|
|
|
{
|
|
|
|
// disposed?
|
2008-06-24 09:21:51 +00:00
|
|
|
if( !mpSurfaceProvider )
|
2006-02-28 09:35:26 +00:00
|
|
|
return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed
|
|
|
|
|
|
|
|
return uno::Reference< rendering::XBezierPolyPolygon2D >(
|
2008-06-24 09:21:51 +00:00
|
|
|
new ::basegfx::unotools::UnoPolyPolygon(
|
2006-02-28 09:35:26 +00:00
|
|
|
::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
|
2008-06-24 09:21:51 +00:00
|
|
|
const uno::Reference< rendering::XGraphicDevice >& rDevice,
|
2006-02-28 09:35:26 +00:00
|
|
|
const geometry::IntegerSize2D& size )
|
|
|
|
{
|
|
|
|
// disposed?
|
2008-06-24 09:21:51 +00:00
|
|
|
if( !mpSurfaceProvider )
|
2006-02-28 09:35:26 +00:00
|
|
|
return uno::Reference< rendering::XBitmap >(); // we're disposed
|
|
|
|
|
|
|
|
return uno::Reference< rendering::XBitmap >(
|
|
|
|
new CanvasBitmap(
|
|
|
|
::basegfx::unotools::b2ISizeFromIntegerSize2D( size ),
|
2008-06-24 09:21:51 +00:00
|
|
|
SurfaceProviderRef(mpSurfaceProvider),
|
|
|
|
rDevice.get(),
|
2006-02-28 09:35:26 +00:00
|
|
|
false ));
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
|
2008-06-24 09:21:51 +00:00
|
|
|
const uno::Reference< rendering::XGraphicDevice >& ,
|
2007-07-17 13:21:10 +00:00
|
|
|
const geometry::IntegerSize2D& /*size*/ )
|
2006-02-28 09:35:26 +00:00
|
|
|
{
|
|
|
|
return uno::Reference< rendering::XVolatileBitmap >();
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
|
2008-06-24 09:21:51 +00:00
|
|
|
const uno::Reference< rendering::XGraphicDevice >& rDevice,
|
2006-02-28 09:35:26 +00:00
|
|
|
const geometry::IntegerSize2D& size )
|
|
|
|
{
|
|
|
|
// disposed?
|
2008-06-24 09:21:51 +00:00
|
|
|
if( !mpSurfaceProvider )
|
2006-02-28 09:35:26 +00:00
|
|
|
return uno::Reference< rendering::XBitmap >(); // we're disposed
|
|
|
|
|
|
|
|
return uno::Reference< rendering::XBitmap >(
|
|
|
|
new CanvasBitmap(
|
|
|
|
::basegfx::unotools::b2ISizeFromIntegerSize2D( size ),
|
2008-06-24 09:21:51 +00:00
|
|
|
SurfaceProviderRef(mpSurfaceProvider),
|
|
|
|
rDevice.get(),
|
2006-02-28 09:35:26 +00:00
|
|
|
true ));
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
|
2008-06-24 09:21:51 +00:00
|
|
|
const uno::Reference< rendering::XGraphicDevice >& ,
|
2007-07-17 13:21:10 +00:00
|
|
|
const geometry::IntegerSize2D& /*size*/ )
|
2006-02-28 09:35:26 +00:00
|
|
|
{
|
|
|
|
return uno::Reference< rendering::XVolatileBitmap >();
|
|
|
|
}
|
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
uno::Any DeviceHelper::isAccelerated() const
|
2006-02-28 09:35:26 +00:00
|
|
|
{
|
2008-06-24 09:21:51 +00:00
|
|
|
return ::com::sun::star::uno::makeAny(false);
|
2006-02-28 09:35:26 +00:00
|
|
|
}
|
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
uno::Any DeviceHelper::getDeviceHandle() const
|
2006-02-28 09:35:26 +00:00
|
|
|
{
|
2008-06-24 09:21:51 +00:00
|
|
|
return uno::makeAny( reinterpret_cast< sal_Int64 >(mpRefDevice) );
|
2006-02-28 09:35:26 +00:00
|
|
|
}
|
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
uno::Any DeviceHelper::getSurfaceHandle() const
|
2006-02-28 09:35:26 +00:00
|
|
|
{
|
2008-06-24 09:21:51 +00:00
|
|
|
return uno::Any();
|
2006-02-28 09:35:26 +00:00
|
|
|
}
|
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
namespace
|
2006-02-28 09:35:26 +00:00
|
|
|
{
|
2008-06-24 09:21:51 +00:00
|
|
|
struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
|
|
|
|
DeviceColorSpace>
|
|
|
|
{
|
|
|
|
uno::Reference<rendering::XColorSpace> operator()()
|
|
|
|
{
|
|
|
|
return vcl::unotools::createStandardColorSpace();
|
|
|
|
}
|
|
|
|
};
|
2006-02-28 09:35:26 +00:00
|
|
|
}
|
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
|
2006-02-28 09:35:26 +00:00
|
|
|
{
|
2008-06-24 09:21:51 +00:00
|
|
|
// always the same
|
|
|
|
return DeviceColorSpace::get();
|
2006-02-28 09:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceHelper::dumpScreenContent() const
|
|
|
|
{
|
2012-04-04 21:30:30 +01:00
|
|
|
static sal_Int32 nFilePostfixCount(0);
|
2006-02-28 09:35:26 +00:00
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
if( mpRefDevice )
|
2006-02-28 09:35:26 +00:00
|
|
|
{
|
2012-11-27 13:53:06 -02:00
|
|
|
OUString aFilename("dbg_frontbuffer");
|
2013-08-21 15:07:31 +02:00
|
|
|
aFilename += OUString::number(nFilePostfixCount);
|
2013-03-19 14:16:55 +01:00
|
|
|
aFilename += ".bmp";
|
2006-02-28 09:35:26 +00:00
|
|
|
|
|
|
|
SvFileStream aStream( aFilename, STREAM_STD_READWRITE );
|
|
|
|
|
|
|
|
const ::Point aEmptyPoint;
|
2008-06-24 09:21:51 +00:00
|
|
|
bool bOldMap( mpRefDevice->IsMapModeEnabled() );
|
2014-02-21 12:53:51 +01:00
|
|
|
mpRefDevice->EnableMapMode( false );
|
2013-01-16 09:02:17 +00:00
|
|
|
const ::Bitmap aTempBitmap(mpRefDevice->GetBitmap(aEmptyPoint, mpRefDevice->GetOutputSizePixel()));
|
|
|
|
WriteDIB(aTempBitmap, aStream, false, true);
|
2008-06-24 09:21:51 +00:00
|
|
|
mpRefDevice->EnableMapMode( bOldMap );
|
2006-02-28 09:35:26 +00:00
|
|
|
|
|
|
|
++nFilePostfixCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
SurfaceSharedPtr DeviceHelper::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
|
2006-02-28 09:35:26 +00:00
|
|
|
{
|
2008-06-24 09:21:51 +00:00
|
|
|
if( mpSurface )
|
|
|
|
return mpSurface->getSimilar( aContent, rSize.getX(), rSize.getY() );
|
2006-02-28 09:35:26 +00:00
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
return SurfaceSharedPtr();
|
2006-02-28 09:35:26 +00:00
|
|
|
}
|
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
SurfaceSharedPtr DeviceHelper::createSurface( BitmapSystemData& rData, const Size& rSize )
|
2006-02-28 09:35:26 +00:00
|
|
|
{
|
2008-06-24 09:21:51 +00:00
|
|
|
if( mpRefDevice )
|
|
|
|
return createBitmapSurface( *mpRefDevice, rData, rSize );
|
2006-02-28 09:35:26 +00:00
|
|
|
|
2008-06-24 09:21:51 +00:00
|
|
|
return SurfaceSharedPtr();
|
2006-02-28 09:35:26 +00:00
|
|
|
}
|
2008-06-24 09:21:51 +00:00
|
|
|
}
|
2010-10-14 08:27:31 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|