Branch libreoffice-5-0-4
[LibreOffice.git] / canvas / source / directx / dx_devicehelper.cxx
blob759bb0b70f17c1e6ec7345012deacfd769d84860
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <ctype.h>
22 #include <vcl/window.hxx>
23 #include <vcl/canvastools.hxx>
24 #include <canvas/debug.hxx>
25 #include <canvas/verbosetrace.hxx>
26 #include <canvas/canvastools.hxx>
27 #include <tools/diagnose_ex.h>
29 #include <osl/mutex.hxx>
30 #include <cppuhelper/compbase1.hxx>
32 #include <com/sun/star/lang/NoSupportException.hpp>
33 #include <toolkit/helper/vclunohelper.hxx>
34 #include <basegfx/tools/canvastools.hxx>
35 #include "dx_linepolypolygon.hxx"
36 #include "dx_spritecanvas.hxx"
37 #include "dx_canvasbitmap.hxx"
38 #include "dx_devicehelper.hxx"
39 #include "dx_winstuff.hxx"
41 #include <vcl/sysdata.hxx>
42 #include <vcl/outdev.hxx>
44 using namespace ::com::sun::star;
46 namespace dxcanvas
48 DeviceHelper::DeviceHelper() :
49 mpDevice( NULL ),
50 mnHDC(0),
51 mpOutDev(0)
55 DeviceHelper::~DeviceHelper()
59 void DeviceHelper::init( HDC hdc, OutputDevice* pOutDev,
60 rendering::XGraphicDevice& rDevice )
62 mnHDC = hdc;
63 mpDevice = &rDevice;
64 mpOutDev = pOutDev;
67 void DeviceHelper::disposing()
69 // release all references
70 mnHDC = 0;
71 mpDevice = NULL;
72 mpOutDev = 0;
75 geometry::RealSize2D DeviceHelper::getPhysicalResolution()
77 if( !mpDevice )
78 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
80 HDC hDC = getHDC();
81 ENSURE_OR_THROW( hDC,
82 "DeviceHelper::getPhysicalResolution(): cannot retrieve HDC from window" );
84 const int nHorzRes( GetDeviceCaps( hDC,
85 LOGPIXELSX ) );
86 const int nVertRes( GetDeviceCaps( hDC,
87 LOGPIXELSY ) );
89 return geometry::RealSize2D( nHorzRes*25.4,
90 nVertRes*25.4 );
93 geometry::RealSize2D DeviceHelper::getPhysicalSize()
95 if( !mpDevice )
96 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
98 HDC hDC=getHDC();
99 ENSURE_OR_THROW( hDC,
100 "DeviceHelper::getPhysicalSize(): cannot retrieve HDC from window" );
102 const int nHorzSize( GetDeviceCaps( hDC,
103 HORZSIZE ) );
104 const int nVertSize( GetDeviceCaps( hDC,
105 VERTSIZE ) );
107 return geometry::RealSize2D( nHorzSize,
108 nVertSize );
111 uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
112 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
113 const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
115 if( !mpDevice )
116 return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed
118 return uno::Reference< rendering::XLinePolyPolygon2D >(
119 new LinePolyPolygon(
120 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
123 uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
124 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
125 const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
127 if( !mpDevice )
128 return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed
130 return uno::Reference< rendering::XBezierPolyPolygon2D >(
131 new LinePolyPolygon(
132 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
135 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
136 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
137 const geometry::IntegerSize2D& size )
139 if( !mpDevice )
140 return uno::Reference< rendering::XBitmap >(); // we're disposed
142 DXBitmapSharedPtr pBitmap(
143 new DXBitmap(
144 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
145 false));
147 // create a 24bit RGB system memory surface
148 return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice));
151 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
152 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
153 const geometry::IntegerSize2D& /*size*/ )
155 return uno::Reference< rendering::XVolatileBitmap >();
158 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
159 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
160 const geometry::IntegerSize2D& size )
162 if( !mpDevice )
163 return uno::Reference< rendering::XBitmap >(); // we're disposed
165 DXBitmapSharedPtr pBitmap(
166 new DXBitmap(
167 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
168 true));
170 // create a 32bit ARGB system memory surface
171 return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice));
174 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
175 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
176 const geometry::IntegerSize2D& /*size*/ )
178 return uno::Reference< rendering::XVolatileBitmap >();
181 bool DeviceHelper::hasFullScreenMode()
183 return false;
186 bool DeviceHelper::enterFullScreenMode( bool /*bEnter*/ )
188 return false;
191 uno::Any DeviceHelper::isAccelerated() const
193 return ::com::sun::star::uno::makeAny(false);
196 uno::Any DeviceHelper::getDeviceHandle() const
198 return uno::makeAny( reinterpret_cast< sal_Int64 >(mpOutDev.get()) );
201 uno::Any DeviceHelper::getSurfaceHandle() const
203 // TODO(F1): expose DirectDraw object
204 //return mpBackBuffer->getBitmap().get();
205 return uno::Any();
208 namespace
210 struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
211 DeviceColorSpace>
213 uno::Reference<rendering::XColorSpace> operator()()
215 return vcl::unotools::createStandardColorSpace();
220 uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
222 // always the same
223 return DeviceColorSpace::get();
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */