1*25ea7f45SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*25ea7f45SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*25ea7f45SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*25ea7f45SAndrew Rist * distributed with this work for additional information 6*25ea7f45SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*25ea7f45SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*25ea7f45SAndrew Rist * "License"); you may not use this file except in compliance 9*25ea7f45SAndrew Rist * with the License. You may obtain a copy of the License at 10*25ea7f45SAndrew Rist * 11*25ea7f45SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*25ea7f45SAndrew Rist * 13*25ea7f45SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*25ea7f45SAndrew Rist * software distributed under the License is distributed on an 15*25ea7f45SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*25ea7f45SAndrew Rist * KIND, either express or implied. See the License for the 17*25ea7f45SAndrew Rist * specific language governing permissions and limitations 18*25ea7f45SAndrew Rist * under the License. 19*25ea7f45SAndrew Rist * 20*25ea7f45SAndrew Rist *************************************************************/ 21*25ea7f45SAndrew Rist 22*25ea7f45SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_canvas.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <canvas/debug.hxx> 28cdf0e10cSrcweir #include <tools/diagnose_ex.h> 29cdf0e10cSrcweir #include <canvas/canvastools.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <rtl/instance.hxx> 32cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 33cdf0e10cSrcweir #include <vcl/canvastools.hxx> 34cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 35cdf0e10cSrcweir #include <basegfx/tools/unopolypolygon.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include "devicehelper.hxx" 38cdf0e10cSrcweir #include "spritecanvas.hxx" 39cdf0e10cSrcweir #include "spritecanvashelper.hxx" 40cdf0e10cSrcweir #include "canvasbitmap.hxx" 41cdf0e10cSrcweir 42cdf0e10cSrcweir 43cdf0e10cSrcweir using namespace ::com::sun::star; 44cdf0e10cSrcweir 45cdf0e10cSrcweir namespace vclcanvas 46cdf0e10cSrcweir { 47cdf0e10cSrcweir DeviceHelper::DeviceHelper() : 48cdf0e10cSrcweir mpOutDev() 49cdf0e10cSrcweir {} 50cdf0e10cSrcweir 51cdf0e10cSrcweir void DeviceHelper::init( const OutDevProviderSharedPtr& rOutDev ) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir mpOutDev = rOutDev; 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir geometry::RealSize2D DeviceHelper::getPhysicalResolution() 57cdf0e10cSrcweir { 58cdf0e10cSrcweir if( !mpOutDev ) 59cdf0e10cSrcweir return ::canvas::tools::createInfiniteSize2D(); // we're disposed 60cdf0e10cSrcweir 61cdf0e10cSrcweir // Map a one-by-one millimeter box to pixel 62cdf0e10cSrcweir OutputDevice& rOutDev = mpOutDev->getOutDev(); 63cdf0e10cSrcweir const MapMode aOldMapMode( rOutDev.GetMapMode() ); 64cdf0e10cSrcweir rOutDev.SetMapMode( MapMode(MAP_MM) ); 65cdf0e10cSrcweir const Size aPixelSize( rOutDev.LogicToPixel(Size(1,1)) ); 66cdf0e10cSrcweir rOutDev.SetMapMode( aOldMapMode ); 67cdf0e10cSrcweir 68cdf0e10cSrcweir return ::vcl::unotools::size2DFromSize( aPixelSize ); 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir geometry::RealSize2D DeviceHelper::getPhysicalSize() 72cdf0e10cSrcweir { 73cdf0e10cSrcweir if( !mpOutDev ) 74cdf0e10cSrcweir return ::canvas::tools::createInfiniteSize2D(); // we're disposed 75cdf0e10cSrcweir 76cdf0e10cSrcweir // Map the pixel dimensions of the output window to millimeter 77cdf0e10cSrcweir OutputDevice& rOutDev = mpOutDev->getOutDev(); 78cdf0e10cSrcweir const MapMode aOldMapMode( rOutDev.GetMapMode() ); 79cdf0e10cSrcweir rOutDev.SetMapMode( MapMode(MAP_MM) ); 80cdf0e10cSrcweir const Size aLogSize( rOutDev.PixelToLogic(rOutDev.GetOutputSizePixel()) ); 81cdf0e10cSrcweir rOutDev.SetMapMode( aOldMapMode ); 82cdf0e10cSrcweir 83cdf0e10cSrcweir return ::vcl::unotools::size2DFromSize( aLogSize ); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon( 87cdf0e10cSrcweir const uno::Reference< rendering::XGraphicDevice >& , 88cdf0e10cSrcweir const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir uno::Reference< rendering::XLinePolyPolygon2D > xPoly; 91cdf0e10cSrcweir if( !mpOutDev ) 92cdf0e10cSrcweir return xPoly; // we're disposed 93cdf0e10cSrcweir 94cdf0e10cSrcweir xPoly.set( new ::basegfx::unotools::UnoPolyPolygon( 95cdf0e10cSrcweir ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) ); 96cdf0e10cSrcweir // vcl only handles even_odd polygons 97cdf0e10cSrcweir xPoly->setFillRule(rendering::FillRule_EVEN_ODD); 98cdf0e10cSrcweir 99cdf0e10cSrcweir return xPoly; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon( 103cdf0e10cSrcweir const uno::Reference< rendering::XGraphicDevice >& , 104cdf0e10cSrcweir const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir uno::Reference< rendering::XBezierPolyPolygon2D > xPoly; 107cdf0e10cSrcweir if( !mpOutDev ) 108cdf0e10cSrcweir return xPoly; // we're disposed 109cdf0e10cSrcweir 110cdf0e10cSrcweir xPoly.set( new ::basegfx::unotools::UnoPolyPolygon( 111cdf0e10cSrcweir ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) ); 112cdf0e10cSrcweir // vcl only handles even_odd polygons 113cdf0e10cSrcweir xPoly->setFillRule(rendering::FillRule_EVEN_ODD); 114cdf0e10cSrcweir 115cdf0e10cSrcweir return xPoly; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap( 119cdf0e10cSrcweir const uno::Reference< rendering::XGraphicDevice >& rDevice, 120cdf0e10cSrcweir const geometry::IntegerSize2D& size ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir if( !mpOutDev ) 123cdf0e10cSrcweir return uno::Reference< rendering::XBitmap >(); // we're disposed 124cdf0e10cSrcweir 125cdf0e10cSrcweir return uno::Reference< rendering::XBitmap >( 126cdf0e10cSrcweir new CanvasBitmap( ::vcl::unotools::sizeFromIntegerSize2D(size), 127cdf0e10cSrcweir false, 128cdf0e10cSrcweir *rDevice.get(), 129cdf0e10cSrcweir mpOutDev ) ); 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap( 133cdf0e10cSrcweir const uno::Reference< rendering::XGraphicDevice >& , 134cdf0e10cSrcweir const geometry::IntegerSize2D& ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir return uno::Reference< rendering::XVolatileBitmap >(); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap( 140cdf0e10cSrcweir const uno::Reference< rendering::XGraphicDevice >& rDevice, 141cdf0e10cSrcweir const geometry::IntegerSize2D& size ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir if( !mpOutDev ) 144cdf0e10cSrcweir return uno::Reference< rendering::XBitmap >(); // we're disposed 145cdf0e10cSrcweir 146cdf0e10cSrcweir return uno::Reference< rendering::XBitmap >( 147cdf0e10cSrcweir new CanvasBitmap( ::vcl::unotools::sizeFromIntegerSize2D(size), 148cdf0e10cSrcweir true, 149cdf0e10cSrcweir *rDevice.get(), 150cdf0e10cSrcweir mpOutDev ) ); 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap( 154cdf0e10cSrcweir const uno::Reference< rendering::XGraphicDevice >& , 155cdf0e10cSrcweir const geometry::IntegerSize2D& ) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir return uno::Reference< rendering::XVolatileBitmap >(); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir sal_Bool DeviceHelper::hasFullScreenMode() 161cdf0e10cSrcweir { 162cdf0e10cSrcweir return false; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir sal_Bool DeviceHelper::enterFullScreenMode( sal_Bool bEnter ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir (void)bEnter; 168cdf0e10cSrcweir return false; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir void DeviceHelper::disposing() 172cdf0e10cSrcweir { 173cdf0e10cSrcweir // release all references 174cdf0e10cSrcweir mpOutDev.reset(); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir uno::Any DeviceHelper::isAccelerated() const 178cdf0e10cSrcweir { 179cdf0e10cSrcweir return ::com::sun::star::uno::makeAny(false); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir uno::Any DeviceHelper::getDeviceHandle() const 183cdf0e10cSrcweir { 184cdf0e10cSrcweir if( !mpOutDev ) 185cdf0e10cSrcweir return uno::Any(); 186cdf0e10cSrcweir 187cdf0e10cSrcweir return uno::makeAny( 188cdf0e10cSrcweir reinterpret_cast< sal_Int64 >(&mpOutDev->getOutDev()) ); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir uno::Any DeviceHelper::getSurfaceHandle() const 192cdf0e10cSrcweir { 193cdf0e10cSrcweir return getDeviceHandle(); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir 196cdf0e10cSrcweir namespace 197cdf0e10cSrcweir { 198cdf0e10cSrcweir struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>, 199cdf0e10cSrcweir DeviceColorSpace> 200cdf0e10cSrcweir { 201cdf0e10cSrcweir uno::Reference<rendering::XColorSpace> operator()() 202cdf0e10cSrcweir { 203cdf0e10cSrcweir return vcl::unotools::createStandardColorSpace(); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir }; 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const 209cdf0e10cSrcweir { 210cdf0e10cSrcweir // always the same 211cdf0e10cSrcweir return DeviceColorSpace::get(); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir void DeviceHelper::dumpScreenContent() const 215cdf0e10cSrcweir { 216cdf0e10cSrcweir static sal_uInt32 nFilePostfixCount(0); 217cdf0e10cSrcweir 218cdf0e10cSrcweir if( mpOutDev ) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir String aFilename( String::CreateFromAscii("dbg_frontbuffer") ); 221cdf0e10cSrcweir aFilename += String::CreateFromInt32(nFilePostfixCount); 222cdf0e10cSrcweir aFilename += String::CreateFromAscii(".bmp"); 223cdf0e10cSrcweir 224cdf0e10cSrcweir SvFileStream aStream( aFilename, STREAM_STD_READWRITE ); 225cdf0e10cSrcweir 226cdf0e10cSrcweir const ::Point aEmptyPoint; 227cdf0e10cSrcweir OutputDevice& rOutDev = mpOutDev->getOutDev(); 228cdf0e10cSrcweir bool bOldMap( rOutDev.IsMapModeEnabled() ); 229cdf0e10cSrcweir rOutDev.EnableMapMode( sal_False ); 230cdf0e10cSrcweir aStream << rOutDev.GetBitmap(aEmptyPoint, 231cdf0e10cSrcweir rOutDev.GetOutputSizePixel()); 232cdf0e10cSrcweir rOutDev.EnableMapMode( bOldMap ); 233cdf0e10cSrcweir 234cdf0e10cSrcweir ++nFilePostfixCount; 235cdf0e10cSrcweir } 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir } 239