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 
23 #include <com/sun/star/lang/NoSupportException.hpp>
24 #include <tools/diagnose_ex.h>
25 #include <vcl/canvastools.hxx>
26 #include <vcl/outdev.hxx>
27 #include <vcl/sysdata.hxx>
28 #include <vcl/window.hxx>
29 
30 #include <canvas/canvastools.hxx>
31 
32 #include "dx_canvasbitmap.hxx"
33 #include "dx_devicehelper.hxx"
34 #include "dx_linepolypolygon.hxx"
35 #include "dx_spritecanvas.hxx"
36 #include "dx_winstuff.hxx"
37 
38 using namespace ::com::sun::star;
39 
40 namespace dxcanvas
41 {
43  mpDevice( nullptr ),
44  mnHDC(nullptr),
45  mpOutDev(nullptr)
46  {
47  }
48 
50  {
51  }
52 
53  void DeviceHelper::init( HDC hdc, OutputDevice* pOutDev,
54  rendering::XGraphicDevice& rDevice )
55  {
56  mnHDC = hdc;
57  mpDevice = &rDevice;
58  mpOutDev = pOutDev;
59  }
60 
62  {
63  // release all references
64  mnHDC = nullptr;
65  mpDevice = nullptr;
66  mpOutDev = nullptr;
67  }
68 
69  geometry::RealSize2D DeviceHelper::getPhysicalResolution()
70  {
71  if( !mpDevice )
73 
74  HDC hDC = getHDC();
75  ENSURE_OR_THROW( hDC,
76  "DeviceHelper::getPhysicalResolution(): cannot retrieve HDC from window" );
77 
78  const int nHorzRes( GetDeviceCaps( hDC,
79  LOGPIXELSX ) );
80  const int nVertRes( GetDeviceCaps( hDC,
81  LOGPIXELSY ) );
82 
83  return geometry::RealSize2D( nHorzRes*25.4,
84  nVertRes*25.4 );
85  }
86 
87  geometry::RealSize2D DeviceHelper::getPhysicalSize()
88  {
89  if( !mpDevice )
91 
92  HDC hDC=getHDC();
93  ENSURE_OR_THROW( hDC,
94  "DeviceHelper::getPhysicalSize(): cannot retrieve HDC from window" );
95 
96  const int nHorzSize( GetDeviceCaps( hDC,
97  HORZSIZE ) );
98  const int nVertSize( GetDeviceCaps( hDC,
99  VERTSIZE ) );
100 
101  return geometry::RealSize2D( nHorzSize,
102  nVertSize );
103  }
104 
105  uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
106  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
107  const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
108  {
109  if( !mpDevice )
110  return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed
111 
112  return uno::Reference< rendering::XLinePolyPolygon2D >(
113  new LinePolyPolygon(
115  }
116 
117  uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
118  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
119  const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
120  {
121  if( !mpDevice )
122  return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed
123 
124  return uno::Reference< rendering::XBezierPolyPolygon2D >(
125  new LinePolyPolygon(
127  }
128 
129  uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
130  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
131  const geometry::IntegerSize2D& size )
132  {
133  if( !mpDevice )
134  return uno::Reference< rendering::XBitmap >(); // we're disposed
135 
136  DXBitmapSharedPtr pBitmap(
137  new DXBitmap(
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(
160  new DXBitmap(
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:82
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:168
::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()
::basegfx::B2IVector b2ISizeFromIntegerSize2D(const geometry::IntegerSize2D &rSize)
geometry::RealSize2D createInfiniteSize2D()
Create a RealSize2D with both coordinate values set to +infinity.
Definition: canvastools.cxx:67
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)