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>
26 #include <tools/diagnose_ex.h>
27 #include <vcl/canvastools.hxx>
28 #include <vcl/outdev.hxx>
29 #include <vcl/sysdata.hxx>
30 #include <vcl/window.hxx>
31 
32 #include <canvas/canvastools.hxx>
33 
34 #include "dx_canvasbitmap.hxx"
35 #include "dx_devicehelper.hxx"
36 #include "dx_linepolypolygon.hxx"
37 #include "dx_spritecanvas.hxx"
38 #include "dx_winstuff.hxx"
39 
40 using namespace ::com::sun::star;
41 
42 namespace dxcanvas
43 {
45  mpDevice( nullptr ),
46  mnHDC(nullptr),
47  mpOutDev(nullptr)
48  {
49  }
50 
52  {
53  }
54 
55  void DeviceHelper::init( HDC hdc, OutputDevice* pOutDev,
56  rendering::XGraphicDevice& rDevice )
57  {
58  mnHDC = hdc;
59  mpDevice = &rDevice;
60  mpOutDev = pOutDev;
61  }
62 
64  {
65  // release all references
66  mnHDC = nullptr;
67  mpDevice = nullptr;
68  mpOutDev = nullptr;
69  }
70 
71  geometry::RealSize2D DeviceHelper::getPhysicalResolution()
72  {
73  if( !mpDevice )
75 
76  HDC hDC = getHDC();
77  ENSURE_OR_THROW( hDC,
78  "DeviceHelper::getPhysicalResolution(): cannot retrieve HDC from window" );
79 
80  const int nHorzRes( GetDeviceCaps( hDC,
81  LOGPIXELSX ) );
82  const int nVertRes( GetDeviceCaps( hDC,
83  LOGPIXELSY ) );
84 
85  return geometry::RealSize2D( nHorzRes*25.4,
86  nVertRes*25.4 );
87  }
88 
89  geometry::RealSize2D DeviceHelper::getPhysicalSize()
90  {
91  if( !mpDevice )
93 
94  HDC hDC=getHDC();
95  ENSURE_OR_THROW( hDC,
96  "DeviceHelper::getPhysicalSize(): cannot retrieve HDC from window" );
97 
98  const int nHorzSize( GetDeviceCaps( hDC,
99  HORZSIZE ) );
100  const int nVertSize( GetDeviceCaps( hDC,
101  VERTSIZE ) );
102 
103  return geometry::RealSize2D( nHorzSize,
104  nVertSize );
105  }
106 
107  uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
108  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
109  const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
110  {
111  if( !mpDevice )
112  return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed
113 
114  return uno::Reference< rendering::XLinePolyPolygon2D >(
115  new LinePolyPolygon(
117  }
118 
119  uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
120  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
121  const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
122  {
123  if( !mpDevice )
124  return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed
125 
126  return uno::Reference< rendering::XBezierPolyPolygon2D >(
127  new LinePolyPolygon(
129  }
130 
131  uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
132  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
133  const geometry::IntegerSize2D& size )
134  {
135  if( !mpDevice )
136  return uno::Reference< rendering::XBitmap >(); // we're disposed
137 
138  DXBitmapSharedPtr pBitmap = std::make_shared<DXBitmap>(
139  ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
140  false);
141 
142  // create a 24bit RGB system memory surface
143  return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice));
144  }
145 
146  uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
147  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
148  const geometry::IntegerSize2D& /*size*/ )
149  {
150  return uno::Reference< rendering::XVolatileBitmap >();
151  }
152 
153  uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
154  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
155  const geometry::IntegerSize2D& size )
156  {
157  if( !mpDevice )
158  return uno::Reference< rendering::XBitmap >(); // we're disposed
159 
160  DXBitmapSharedPtr pBitmap = std::make_shared<DXBitmap>(
161  ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
162  true);
163 
164  // create a 32bit ARGB system memory surface
165  return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice));
166  }
167 
168  uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
169  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
170  const geometry::IntegerSize2D& /*size*/ )
171  {
172  return uno::Reference< rendering::XVolatileBitmap >();
173  }
174 
176  {
177  return css::uno::Any(false);
178  }
179 
181  {
182  return uno::Any( reinterpret_cast< sal_Int64 >(mpOutDev.get()) );
183  }
184 
186  {
187  // TODO(F1): expose DirectDraw object
188  //return mpBackBuffer->getBitmap().get();
189  return uno::Any();
190  }
191 
192  namespace
193  {
194  struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
195  DeviceColorSpace>
196  {
197  uno::Reference<rendering::XColorSpace> operator()()
198  {
200  }
201  };
202  }
203 
204  uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
205  {
206  // always the same
207  return DeviceColorSpace::get();
208  }
209 }
210 
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
VclPtr< OutputDevice > mpOutDev
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::Any isAccelerated() const
std::shared_ptr< DXBitmap > DXBitmapSharedPtr
Definition: dx_bitmap.hxx:81
css::geometry::RealSize2D getPhysicalSize()
css::geometry::RealSize2D getPhysicalResolution()
::basegfx::B2DPolyPolygon polyPolygonFromPoint2DSequenceSequence(const uno::Sequence< uno::Sequence< geometry::RealPoint2D > > &points)
css::uno::Reference< css::rendering::XVolatileBitmap > createVolatileAlphaBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
COMReference< IDirect3DDevice9 > mpDevice
Definition: dx_9rm.cxx:169
::basegfx::B2DPolyPolygon polyPolygonFromBezier2DSequenceSequence(const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > &curves)
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)
css::uno::Reference< css::rendering::XBitmap > createCompatibleAlphaBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
#define ENSURE_OR_THROW(c, m)
uno::Reference< rendering::XColorSpace > createStandardColorSpace()
geometry::RealSize2D createInfiniteSize2D()
Create a RealSize2D with both coordinate values set to +infinity.
Definition: canvastools.cxx:68
css::uno::Reference< css::rendering::XBitmap > createCompatibleBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
css::rendering::XGraphicDevice * mpDevice
Phyical output device.
void disposing()
Dispose all internal references.
css::uno::Reference< css::rendering::XColorSpace > getColorSpace() const
css::uno::Any getDeviceHandle() const
css::uno::Any getSurfaceHandle() const
OutputDevice * get() const
void init(HDC hdc, OutputDevice *pOutputDev, css::rendering::XGraphicDevice &rDevice)
Init the device helper.
css::uno::Reference< css::rendering::XVolatileBitmap > createVolatileBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)