Simplify a bit
[LibreOffice.git] / canvas / source / directx / dx_devicehelper.cxx
blobdada6238e0ebd76fd9fda6efd0675ca970be34b0
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 .
20 #include <sal/config.h>
22 #include <memory>
24 #include <basegfx/utils/canvastools.hxx>
25 #include <com/sun/star/lang/NoSupportException.hpp>
26 #include <comphelper/diagnose_ex.hxx>
27 #include <vcl/canvastools.hxx>
28 #include <vcl/outdev.hxx>
29 #include <vcl/sysdata.hxx>
31 #include <canvas/canvastools.hxx>
33 #include "dx_canvasbitmap.hxx"
34 #include "dx_devicehelper.hxx"
35 #include "dx_linepolypolygon.hxx"
36 #include "dx_spritecanvas.hxx"
37 #include "dx_winstuff.hxx"
39 using namespace ::com::sun::star;
41 namespace dxcanvas
43 DeviceHelper::DeviceHelper() :
44 mpDevice( nullptr ),
45 mnHDC(nullptr),
46 mpOutDev(nullptr)
50 DeviceHelper::~DeviceHelper()
54 void DeviceHelper::init( HDC hdc, OutputDevice* pOutDev,
55 rendering::XGraphicDevice& rDevice )
57 mnHDC = hdc;
58 mpDevice = &rDevice;
59 mpOutDev = pOutDev;
62 void DeviceHelper::disposing()
64 // release all references
65 mnHDC = nullptr;
66 mpDevice = nullptr;
67 mpOutDev = nullptr;
70 geometry::RealSize2D DeviceHelper::getPhysicalResolution()
72 if( !mpDevice )
73 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
75 HDC hDC = getHDC();
76 ENSURE_OR_THROW( hDC,
77 "DeviceHelper::getPhysicalResolution(): cannot retrieve HDC from window" );
79 const int nHorzRes( GetDeviceCaps( hDC,
80 LOGPIXELSX ) );
81 const int nVertRes( GetDeviceCaps( hDC,
82 LOGPIXELSY ) );
84 return geometry::RealSize2D( nHorzRes*25.4,
85 nVertRes*25.4 );
88 geometry::RealSize2D DeviceHelper::getPhysicalSize()
90 if( !mpDevice )
91 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
93 HDC hDC=getHDC();
94 ENSURE_OR_THROW( hDC,
95 "DeviceHelper::getPhysicalSize(): cannot retrieve HDC from window" );
97 const int nHorzSize( GetDeviceCaps( hDC,
98 HORZSIZE ) );
99 const int nVertSize( GetDeviceCaps( hDC,
100 VERTSIZE ) );
102 return geometry::RealSize2D( nHorzSize,
103 nVertSize );
106 uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
107 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
108 const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
110 if( !mpDevice )
111 return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed
113 return uno::Reference< rendering::XLinePolyPolygon2D >(
114 new LinePolyPolygon(
115 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
118 uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
119 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
120 const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
122 if( !mpDevice )
123 return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed
125 return uno::Reference< rendering::XBezierPolyPolygon2D >(
126 new LinePolyPolygon(
127 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
130 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
131 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
132 const geometry::IntegerSize2D& size )
134 if( !mpDevice )
135 return uno::Reference< rendering::XBitmap >(); // we're disposed
137 DXBitmapSharedPtr pBitmap = std::make_shared<DXBitmap>(
138 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
139 false);
141 // create a 24bit RGB system memory surface
142 return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice));
145 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
146 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
147 const geometry::IntegerSize2D& /*size*/ )
149 return uno::Reference< rendering::XVolatileBitmap >();
152 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
153 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
154 const geometry::IntegerSize2D& size )
156 if( !mpDevice )
157 return uno::Reference< rendering::XBitmap >(); // we're disposed
159 DXBitmapSharedPtr pBitmap = std::make_shared<DXBitmap>(
160 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
161 true);
163 // create a 32bit ARGB system memory surface
164 return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice));
167 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
168 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
169 const geometry::IntegerSize2D& /*size*/ )
171 return uno::Reference< rendering::XVolatileBitmap >();
174 uno::Any DeviceHelper::isAccelerated() const
176 return css::uno::Any(false);
179 uno::Any DeviceHelper::getDeviceHandle() const
181 return uno::Any( reinterpret_cast< sal_Int64 >(mpOutDev.get()) );
184 uno::Any DeviceHelper::getSurfaceHandle() const
186 // TODO(F1): expose DirectDraw object
187 //return mpBackBuffer->getBitmap().get();
188 return uno::Any();
191 uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
193 // always the same
194 static uno::Reference<rendering::XColorSpace> theSpace = vcl::unotools::createStandardColorSpace();
195 return theSpace;
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */