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 
22 #include <memory>
23 
24 #include <sal/log.hxx>
25 
27 #include <canvas/canvastools.hxx>
28 #include <com/sun/star/lang/NoSupportException.hpp>
30 #include <tools/diagnose_ex.h>
31 #include <vcl/sysdata.hxx>
32 #include <vcl/window.hxx>
33 
34 #include "dx_canvasbitmap.hxx"
35 #include "dx_linepolypolygon.hxx"
36 #include "dx_spritecanvas.hxx"
38 #include "dx_winstuff.hxx"
39 
40 
41 using namespace ::com::sun::star;
42 
43 namespace dxcanvas
44 {
46  DeviceHelper(),
47  mpSpriteCanvas( nullptr ),
48  mpBackBuffer(),
49  mpSurfaceProxyManager(),
50  mpRenderModule()
51  {
52  }
53 
55  SpriteCanvas& rSpriteCanvas,
56  const awt::Rectangle& rRect,
57  bool /*bFullscreen*/ )
58  {
59  // #i60490# ensure backbuffer has sensible minimal size
60  const sal_Int32 w( std::max(sal_Int32(1),sal_Int32(rRect.Width)));
61  const sal_Int32 h( std::max(sal_Int32(1),sal_Int32(rRect.Height)));
62 
63  rSpriteCanvas.setWindow(
64  uno::Reference<awt::XWindow2>(
66  uno::UNO_QUERY_THROW) );
67 
68  const SystemEnvData *pData = rWindow.GetSystemData();
69  const HWND hWnd = reinterpret_cast<HWND>(pData->hWnd);
70  if( !IsWindow( hWnd ) )
71  throw lang::NoSupportException( "Passed window has invalid system window, or canvas out-of-process!" );
72 
73  mpSpriteCanvas = &rSpriteCanvas;
74 
75  try
76  {
77  // setup directx rendermodule
79  }
80  catch (...) {
81 
82  throw lang::NoSupportException( "Could not create DirectX device!",
83  static_cast< ::cppu::OWeakObject* >(&rSpriteCanvas) );
84  }
85 
86  // create the surfaceproxy manager
88 
89  // #i60490# ensure backbuffer has sensible minimal size
90  mpBackBuffer = std::make_shared<DXSurfaceBitmap>(
91  ::basegfx::B2ISize(w,h),
94  false);
95 
96  // Assumes: SystemChildWindow() has CS_OWNDC
97  DeviceHelper::init(GetDC(mpRenderModule->getHWND()),rWindow.GetOutDev(), rSpriteCanvas);
98  }
99 
101  {
102  // release all references
103  mpBackBuffer.reset();
104  mpSurfaceProxyManager.reset();
105  mpRenderModule.reset();
106  mpSpriteCanvas = nullptr;
107 
109  }
110 
111  uno::Reference< rendering::XBitmap > SpriteDeviceHelper::createCompatibleBitmap(
112  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
113  const geometry::IntegerSize2D& size )
114  {
115  if( !getDevice() )
116  return uno::Reference< rendering::XBitmap >(); // we're disposed
117 
118  DXSurfaceBitmapSharedPtr pBitmap = std::make_shared<DXSurfaceBitmap>(
119  ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
122  false);
123 
124  // create a 24bit RGB system memory surface
125  return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,getDevice()));
126  }
127 
128  uno::Reference< rendering::XVolatileBitmap > SpriteDeviceHelper::createVolatileBitmap(
129  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
130  const geometry::IntegerSize2D& /*size*/ )
131  {
132  return uno::Reference< rendering::XVolatileBitmap >();
133  }
134 
135  uno::Reference< rendering::XBitmap > SpriteDeviceHelper::createCompatibleAlphaBitmap(
136  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
137  const geometry::IntegerSize2D& size )
138  {
139  if( !getDevice() )
140  return uno::Reference< rendering::XBitmap >(); // we're disposed
141 
142  DXSurfaceBitmapSharedPtr pBitmap = std::make_shared<DXSurfaceBitmap>(
143  ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
146  true);
147 
148  // create a 32bit ARGB system memory surface
149  return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,getDevice()));
150  }
151 
152  uno::Reference< rendering::XVolatileBitmap > SpriteDeviceHelper::createVolatileAlphaBitmap(
153  const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
154  const geometry::IntegerSize2D& /*size*/ )
155  {
156  return uno::Reference< rendering::XVolatileBitmap >();
157  }
158 
160  {
161  // TODO(F3): implement XBufferStrategy interface. For now, we
162  // _always_ will have exactly one backbuffer
163  }
164 
166  {
167  SAL_WARN("canvas.directx", "Not supposed to be called, handled by SpriteCanvas");
168  return false;
169  }
170 
172  {
173  SAL_WARN("canvas.directx", "Not supposed to be called, handled by SpriteCanvas");
174  return false;
175  }
176 
178  {
179  return css::uno::Any(true);
180  }
181 
182  void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle& rBounds )
183  {
184  // #i60490# ensure backbuffer has sensible minimal size
185  const sal_Int32 x(rBounds.X);
186  const sal_Int32 y(rBounds.Y);
187  const sal_Int32 w(std::max(sal_Int32(1),sal_Int32(rBounds.Width)));
188  const sal_Int32 h(std::max(sal_Int32(1),sal_Int32(rBounds.Height)));
189 
190  if( mpRenderModule )
191  mpRenderModule->resize(::basegfx::B2IRange(x,y,x+w,y+h));
192 
194  }
195 
196  void SpriteDeviceHelper::resizeBackBuffer( const ::basegfx::B2ISize& rNewSize )
197  {
198  // disposed?
199  if(!mpBackBuffer)
200  return;
201 
202  mpBackBuffer->resize(rNewSize);
203  mpBackBuffer->clear();
204  }
205 
207  {
208  if( mpRenderModule )
209  return mpRenderModule->getHWND();
210  else
211  return nullptr;
212  }
213 
215  {
216  if( mpRenderModule )
217  mpRenderModule->screenShot();
218  }
219 }
220 
221 /* 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:190
bool switchBuffer(bool bIsVisible, bool bUpdateAll)
float y
Definition: dx_9rm.cxx:190
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:1207
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)
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