CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / canvas / source / directx / dx_devicehelper.cxx
blob731e28e2700fc73e4eb26f551c149591c3e8d933
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
31 #include <ctype.h> // don't ask. msdev breaks otherwise...
32 #include <vcl/window.hxx>
33 #include <vcl/canvastools.hxx>
34 #include <canvas/debug.hxx>
35 #include <canvas/verbosetrace.hxx>
36 #include <canvas/canvastools.hxx>
37 #include <tools/diagnose_ex.h>
39 #include <osl/mutex.hxx>
40 #include <cppuhelper/compbase1.hxx>
42 #include <com/sun/star/lang/NoSupportException.hpp>
43 #include <toolkit/helper/vclunohelper.hxx>
44 #include <basegfx/tools/canvastools.hxx>
45 #include "dx_linepolypolygon.hxx"
46 #include "dx_spritecanvas.hxx"
47 #include "dx_canvasbitmap.hxx"
48 #include "dx_devicehelper.hxx"
51 #undef WB_LEFT
52 #undef WB_RIGHT
53 #include "dx_winstuff.hxx"
56 #include <vcl/sysdata.hxx>
58 using namespace ::com::sun::star;
60 namespace dxcanvas
62 DeviceHelper::DeviceHelper() :
63 mpDevice( NULL ),
64 mnHDC(0)
68 void DeviceHelper::init( HDC hdc,
69 rendering::XGraphicDevice& rDevice )
71 mnHDC = hdc;
72 mpDevice = &rDevice;
75 void DeviceHelper::disposing()
77 // release all references
78 mnHDC = 0;
79 mpDevice = NULL;
82 geometry::RealSize2D DeviceHelper::getPhysicalResolution()
84 if( !mpDevice )
85 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
87 HDC hDC = getHDC();
88 ENSURE_OR_THROW( hDC,
89 "DeviceHelper::getPhysicalResolution(): cannot retrieve HDC from window" );
91 const int nHorzRes( GetDeviceCaps( hDC,
92 LOGPIXELSX ) );
93 const int nVertRes( GetDeviceCaps( hDC,
94 LOGPIXELSY ) );
96 return geometry::RealSize2D( nHorzRes*25.4,
97 nVertRes*25.4 );
100 geometry::RealSize2D DeviceHelper::getPhysicalSize()
102 if( !mpDevice )
103 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
105 HDC hDC=getHDC();
106 ENSURE_OR_THROW( hDC,
107 "DeviceHelper::getPhysicalSize(): cannot retrieve HDC from window" );
109 const int nHorzSize( GetDeviceCaps( hDC,
110 HORZSIZE ) );
111 const int nVertSize( GetDeviceCaps( hDC,
112 VERTSIZE ) );
114 return geometry::RealSize2D( nHorzSize,
115 nVertSize );
118 uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
119 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
120 const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
122 if( !mpDevice )
123 return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed
125 return uno::Reference< rendering::XLinePolyPolygon2D >(
126 new LinePolyPolygon(
127 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
130 uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
131 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
132 const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
134 if( !mpDevice )
135 return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed
137 return uno::Reference< rendering::XBezierPolyPolygon2D >(
138 new LinePolyPolygon(
139 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
142 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
143 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
144 const geometry::IntegerSize2D& size )
146 if( !mpDevice )
147 return uno::Reference< rendering::XBitmap >(); // we're disposed
149 DXBitmapSharedPtr pBitmap(
150 new DXBitmap(
151 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
152 false));
154 // create a 24bit RGB system memory surface
155 return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice));
158 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
159 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
160 const geometry::IntegerSize2D& /*size*/ )
162 return uno::Reference< rendering::XVolatileBitmap >();
165 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
166 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
167 const geometry::IntegerSize2D& size )
169 if( !mpDevice )
170 return uno::Reference< rendering::XBitmap >(); // we're disposed
172 DXBitmapSharedPtr pBitmap(
173 new DXBitmap(
174 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
175 true));
177 // create a 32bit ARGB system memory surface
178 return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice));
181 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
182 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
183 const geometry::IntegerSize2D& /*size*/ )
185 return uno::Reference< rendering::XVolatileBitmap >();
188 sal_Bool DeviceHelper::hasFullScreenMode()
190 return false;
193 sal_Bool DeviceHelper::enterFullScreenMode( sal_Bool /*bEnter*/ )
195 return false;
198 uno::Any DeviceHelper::isAccelerated() const
200 return ::com::sun::star::uno::makeAny(false);
203 uno::Any DeviceHelper::getDeviceHandle() const
205 HDC hdc( getHDC() );
206 if( hdc )
207 return uno::makeAny( reinterpret_cast< sal_Int64 >(hdc) );
208 else
209 return uno::Any();
212 uno::Any DeviceHelper::getSurfaceHandle() const
214 // TODO(F1): expose DirectDraw object
215 //return mpBackBuffer->getBitmap().get();
216 return uno::Any();
219 namespace
221 struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
222 DeviceColorSpace>
224 uno::Reference<rendering::XColorSpace> operator()()
226 return vcl::unotools::createStandardColorSpace();
231 uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
233 // always the same
234 return DeviceColorSpace::get();