LibreOffice Module canvas (master) 1
dx_devicehelper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include <memory>
23
25#include <com/sun/star/lang/NoSupportException.hpp>
27#include <vcl/canvastools.hxx>
28#include <vcl/outdev.hxx>
29#include <vcl/sysdata.hxx>
30
32
33#include "dx_canvasbitmap.hxx"
34#include "dx_devicehelper.hxx"
36#include "dx_spritecanvas.hxx"
37#include "dx_winstuff.hxx"
38
39using namespace ::com::sun::star;
40
41namespace dxcanvas
42{
44 mpDevice( nullptr ),
45 mnHDC(nullptr),
46 mpOutDev(nullptr)
47 {
48 }
49
51 {
52 }
53
54 void DeviceHelper::init( HDC hdc, OutputDevice* pOutDev,
55 rendering::XGraphicDevice& rDevice )
56 {
57 mnHDC = hdc;
58 mpDevice = &rDevice;
59 mpOutDev = pOutDev;
60 }
61
63 {
64 // release all references
65 mnHDC = nullptr;
66 mpDevice = nullptr;
67 mpOutDev = nullptr;
68 }
69
71 {
72 if( !mpDevice )
74
75 HDC hDC = getHDC();
76 ENSURE_OR_THROW( hDC,
77 "DeviceHelper::getPhysicalResolution(): cannot retrieve HDC from window" );
78
79 const int nHorzRes( GetDeviceCaps( hDC,
80 LOGPIXELSX ) );
81 const int nVertRes( GetDeviceCaps( hDC,
82 LOGPIXELSY ) );
83
84 return geometry::RealSize2D( nHorzRes*25.4,
85 nVertRes*25.4 );
86 }
87
88 geometry::RealSize2D DeviceHelper::getPhysicalSize()
89 {
90 if( !mpDevice )
92
93 HDC hDC=getHDC();
94 ENSURE_OR_THROW( hDC,
95 "DeviceHelper::getPhysicalSize(): cannot retrieve HDC from window" );
96
97 const int nHorzSize( GetDeviceCaps( hDC,
98 HORZSIZE ) );
99 const int nVertSize( GetDeviceCaps( hDC,
100 VERTSIZE ) );
101
102 return geometry::RealSize2D( nHorzSize,
103 nVertSize );
104 }
105
106 uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
107 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
108 const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
109 {
110 if( !mpDevice )
111 return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed
112
113 return uno::Reference< rendering::XLinePolyPolygon2D >(
114 new LinePolyPolygon(
115 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
116 }
117
118 uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
119 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
120 const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
121 {
122 if( !mpDevice )
123 return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed
124
125 return uno::Reference< rendering::XBezierPolyPolygon2D >(
126 new LinePolyPolygon(
127 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
128 }
129
130 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
131 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
132 const geometry::IntegerSize2D& size )
133 {
134 if( !mpDevice )
135 return uno::Reference< rendering::XBitmap >(); // we're disposed
136
137 DXBitmapSharedPtr pBitmap = std::make_shared<DXBitmap>(
138 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
139 false);
140
141 // create a 24bit RGB system memory surface
142 return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice));
143 }
144
145 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
146 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
147 const geometry::IntegerSize2D& /*size*/ )
148 {
149 return uno::Reference< rendering::XVolatileBitmap >();
150 }
151
152 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
153 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
154 const geometry::IntegerSize2D& size )
155 {
156 if( !mpDevice )
157 return uno::Reference< rendering::XBitmap >(); // we're disposed
158
159 DXBitmapSharedPtr pBitmap = std::make_shared<DXBitmap>(
160 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
161 true);
162
163 // create a 32bit ARGB system memory surface
164 return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice));
165 }
166
167 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
168 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
169 const geometry::IntegerSize2D& /*size*/ )
170 {
171 return uno::Reference< rendering::XVolatileBitmap >();
172 }
173
175 {
176 return css::uno::Any(false);
177 }
178
180 {
181 return uno::Any( reinterpret_cast< sal_Int64 >(mpOutDev.get()) );
182 }
183
185 {
186 // TODO(F1): expose DirectDraw object
187 //return mpBackBuffer->getBitmap().get();
188 return uno::Any();
189 }
190
191 uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
192 {
193 // always the same
194 static uno::Reference<rendering::XColorSpace> theSpace = vcl::unotools::createStandardColorSpace();
195 return theSpace;
196 }
197}
198
199/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
reference_type * get() const
css::uno::Reference< css::rendering::XVolatileBitmap > createVolatileAlphaBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
css::geometry::RealSize2D getPhysicalSize()
css::uno::Any getSurfaceHandle() const
css::uno::Reference< css::rendering::XBitmap > createCompatibleBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
css::uno::Reference< css::rendering::XVolatileBitmap > createVolatileBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
css::uno::Reference< css::rendering::XLinePolyPolygon2D > createCompatibleLinePolyPolygon(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::uno::Sequence< css::uno::Sequence< css::geometry::RealPoint2D > > &points)
css::uno::Reference< css::rendering::XBitmap > createCompatibleAlphaBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
void disposing()
Dispose all internal references.
css::uno::Reference< css::rendering::XBezierPolyPolygon2D > createCompatibleBezierPolyPolygon(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::uno::Sequence< css::uno::Sequence< css::geometry::RealBezierSegment2D > > &points)
VclPtr< OutputDevice > mpOutDev
void init(HDC hdc, OutputDevice *pOutputDev, css::rendering::XGraphicDevice &rDevice)
Init the device helper.
css::rendering::XGraphicDevice * mpDevice
Phyical output device.
css::uno::Any getDeviceHandle() const
css::uno::Any isAccelerated() const
css::uno::Reference< css::rendering::XColorSpace > getColorSpace() const
css::geometry::RealSize2D getPhysicalResolution()
#define ENSURE_OR_THROW(c, m)
sal::systools::COMReference< IDirect3DDevice9 > mpDevice
Definition: dx_9rm.cxx:169
geometry::RealSize2D createInfiniteSize2D()
Create a RealSize2D with both coordinate values set to +infinity.
Definition: canvastools.cxx:67
std::shared_ptr< DXBitmap > DXBitmapSharedPtr
Definition: dx_bitmap.hxx:79
uno::Reference< rendering::XColorSpace > createStandardColorSpace()