LibreOffice Module canvas (master)  1
dx_spritedevicehelper.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 #include <sal/log.hxx>
22 
24 #include <canvas/canvastools.hxx>
25 #include <com/sun/star/lang/NoSupportException.hpp>
27 #include <tools/diagnose_ex.h>
28 #include <vcl/sysdata.hxx>
29 #include <vcl/window.hxx>
30 
31 #include "dx_canvasbitmap.hxx"
32 #include "dx_linepolypolygon.hxx"
33 #include "dx_spritecanvas.hxx"
35 #include "dx_winstuff.hxx"
36 
37 
38 using namespace ::com::sun::star;
39 
40 namespace dxcanvas
41 {
43  DeviceHelper(),
44  mpSpriteCanvas( nullptr ),
45  mpBackBuffer(),
46  mpSurfaceProxyManager(),
47  mpRenderModule()
48  {
49  }
50 
52  SpriteCanvas& rSpriteCanvas,
53  const awt::Rectangle& rRect,
54  bool /*bFullscreen*/ )
55  {
56  // #i60490# ensure backbuffer has sensible minimal size
57  const sal_Int32 w( std::max(sal_Int32(1),sal_Int32(rRect.Width)));
58  const sal_Int32 h( std::max(sal_Int32(1),sal_Int32(rRect.Height)));
59 
60  rSpriteCanvas.setWindow(
61  uno::Reference<awt::XWindow2>(
63  uno::UNO_QUERY_THROW) );
64 
65  const SystemEnvData *pData = rWindow.GetSystemData();
66  const HWND hWnd = reinterpret_cast<HWND>(pData->hWnd);
67  if( !IsWindow( hWnd ) )
68  throw lang::NoSupportException( "Passed window has invalid system window, or canvas out-of-process!" );
69 
70  mpSpriteCanvas = &rSpriteCanvas;
71 
72  try
73  {
74  // setup directx rendermodule
76  }
77  catch (...) {
78 
79  throw lang::NoSupportException( "Could not create DirectX device!",
80  static_cast< ::cppu::OWeakObject* >(&rSpriteCanvas) );
81  }
82 
83  // create the surfaceproxy manager
85 
86  // #i60490# ensure backbuffer has sensible minimal size
87  mpBackBuffer.reset(new DXSurfaceBitmap(
88  ::basegfx::B2ISize(w,h),
91  false));
92 
93  // Assumes: SystemChildWindow() has CS_OWNDC
94  DeviceHelper::init(GetDC(mpRenderModule->getHWND()),rWindow.GetOutDev(), rSpriteCanvas);
95  }
96 
98  {
99  // release all references
100  mpBackBuffer.reset();
101  mpSurfaceProxyManager.reset();
102  mpRenderModule.reset();
103  mpSpriteCanvas = nullptr;
104 
106  }
107 
108  uno::Reference< rendering::XBitmap > SpriteDeviceHelper::createCompatibleBitmap(
109  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
110  const geometry::IntegerSize2D& size )
111  {
112  if( !getDevice() )
113  return uno::Reference< rendering::XBitmap >(); // we're disposed
114 
115  DXSurfaceBitmapSharedPtr pBitmap(
116  new DXSurfaceBitmap(
120  false));
121 
122  // create a 24bit RGB system memory surface
123  return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,getDevice()));
124  }
125 
126  uno::Reference< rendering::XVolatileBitmap > SpriteDeviceHelper::createVolatileBitmap(
127  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
128  const geometry::IntegerSize2D& /*size*/ )
129  {
130  return uno::Reference< rendering::XVolatileBitmap >();
131  }
132 
133  uno::Reference< rendering::XBitmap > SpriteDeviceHelper::createCompatibleAlphaBitmap(
134  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
135  const geometry::IntegerSize2D& size )
136  {
137  if( !getDevice() )
138  return uno::Reference< rendering::XBitmap >(); // we're disposed
139 
140  DXSurfaceBitmapSharedPtr pBitmap(
141  new DXSurfaceBitmap(
145  true));
146 
147  // create a 32bit ARGB system memory surface
148  return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,getDevice()));
149  }
150 
151  uno::Reference< rendering::XVolatileBitmap > SpriteDeviceHelper::createVolatileAlphaBitmap(
152  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
153  const geometry::IntegerSize2D& /*size*/ )
154  {
155  return uno::Reference< rendering::XVolatileBitmap >();
156  }
157 
159  {
160  // TODO(F3): implement XBufferStrategy interface. For now, we
161  // _always_ will have exactly one backbuffer
162  }
163 
165  {
166  SAL_WARN("canvas.directx", "Not supposed to be called, handled by SpriteCanvas");
167  return false;
168  }
169 
171  {
172  SAL_WARN("canvas.directx", "Not supposed to be called, handled by SpriteCanvas");
173  return false;
174  }
175 
177  {
178  return css::uno::Any(true);
179  }
180 
181  void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle& rBounds )
182  {
183  // #i60490# ensure backbuffer has sensible minimal size
184  const sal_Int32 x(rBounds.X);
185  const sal_Int32 y(rBounds.Y);
186  const sal_Int32 w(std::max(sal_Int32(1),sal_Int32(rBounds.Width)));
187  const sal_Int32 h(std::max(sal_Int32(1),sal_Int32(rBounds.Height)));
188 
189  if( mpRenderModule )
190  mpRenderModule->resize(::basegfx::B2IRange(x,y,x+w,y+h));
191 
193  }
194 
195  void SpriteDeviceHelper::resizeBackBuffer( const ::basegfx::B2ISize& rNewSize )
196  {
197  // disposed?
198  if(!mpBackBuffer)
199  return;
200 
201  mpBackBuffer->resize(rNewSize);
202  mpBackBuffer->clear();
203  }
204 
206  {
207  if( mpRenderModule )
208  return mpRenderModule->getHWND();
209  else
210  return nullptr;
211  }
212 
214  {
215  if( mpRenderModule )
216  mpRenderModule->screenShot();
217  }
218 }
219 
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< canvas::ISurfaceProxyManager > mpSurfaceProxyManager
Instance passing out HW textures.
std::unique_ptr< ContentProperties > pData
void init(vcl::Window &rWindow, SpriteCanvas &rSpriteCanvas, const css::awt::Rectangle &rRect, bool bFullscreen)
css::uno::Reference< css::rendering::XBitmap > createCompatibleAlphaBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
const cppcanvas::SpriteCanvasSharedPtr mpSpriteCanvas
#define max(a, b)
Definition: dx_winstuff.hxx:46
float x
Definition: dx_9rm.cxx:189
bool switchBuffer(bool bIsVisible, bool bUpdateAll)
float y
Definition: dx_9rm.cxx:189
IDXRenderModuleSharedPtr mpRenderModule
Our encapsulation interface to DirectX.
std::shared_ptr< ISurfaceProxyManager > createSurfaceProxyManager(const std::shared_ptr< IRenderModule > &rRenderModule)
Create a surface proxy for the given render module.
IDXRenderModuleSharedPtr createRenderModule(const vcl::Window &rParent)
Factory method, to create an IRenderModule instance for the given VCL window instance.
Definition: dx_9rm.cxx:1206
css::uno::Reference< css::rendering::XVolatileBitmap > createVolatileAlphaBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
bool showBuffer(bool bIsVisible, bool bUpdateAll)
sal_Int32 w
css::uno::Reference< css::rendering::XVolatileBitmap > createVolatileBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
std::shared_ptr< DXSurfaceBitmap > DXSurfaceBitmapSharedPtr
virtual const SystemEnvData * GetSystemData() const
void dumpScreenContent() const
called when DumpScreenContent property is enabled on XGraphicDevice, and writes out bitmaps of curren...
DXSurfaceBitmapSharedPtr mpBackBuffer
void resizeBackBuffer(const ::basegfx::B2ISize &rNewSize)
::basegfx::B2IVector b2ISizeFromIntegerSize2D(const geometry::IntegerSize2D &rSize)
css::uno::Reference< css::rendering::XBitmap > createCompatibleBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
void notifySizeUpdate(const css::awt::Rectangle &rBounds)
::OutputDevice const * GetOutDev() const
void disposing()
Dispose all internal references.
SpriteCanvas * mpSpriteCanvas
Pointer to sprite canvas (owner of this helper), needed to create bitmaps.
void disposing()
Dispose all internal references.
#define SAL_WARN(area, stream)
Product of this component's factory.
void init(HDC hdc, OutputDevice *pOutputDev, css::rendering::XGraphicDevice &rDevice)
Init the device helper.
css::rendering::XGraphicDevice * getDevice() const
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
sal_Int32 h
css::uno::Any isAccelerated() const