LibreOffice Module canvas (master)  1
dx_winstuff.hxx
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 #ifndef INCLUDED_CANVAS_SOURCE_DIRECTX_DX_WINSTUFF_HXX
21 #define INCLUDED_CANVAS_SOURCE_DIRECTX_DX_WINSTUFF_HXX
22 
23 #include <algorithm>
24 #include <memory>
25 
27 
28 
29 #define WIN32_LEAN_AND_MEAN
30 #include <prewin.h>
31 
32 // Enabling Direct3D Debug Information Further more, with registry key
33 // \\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Direct3D\D3D9Debugging\\EnableCreationStack
34 // set to 1, sets a backtrace each time an object is created to the
35 // following global variable: LPCWSTR CreationCallStack
36 #if OSL_DEBUG_LEVEL > 0
37 # define D3D_DEBUG_INFO
38 #endif
39 
40 #include <d3d9.h>
41 
42 typedef IDirect3DSurface9 surface_type;
43 
44 
45 #ifndef max
46 #define max(a,b) (((a) > (b)) ? (a) : (b))
47 #endif
48 #ifndef min
49 #define min(a,b) (((a) < (b)) ? (a) : (b))
50 #endif
51 
52 #include <gdiplus.h>
53 
54 #undef max
55 #undef min
56 
57 
58 namespace dxcanvas
59 {
60  // some shared pointer typedefs to Gdiplus objects
61  typedef std::shared_ptr< Gdiplus::Graphics > GraphicsSharedPtr;
62  typedef std::shared_ptr< Gdiplus::GraphicsPath > GraphicsPathSharedPtr;
63  typedef std::shared_ptr< Gdiplus::Bitmap > BitmapSharedPtr;
64  typedef std::shared_ptr< Gdiplus::Font > FontSharedPtr;
65  typedef std::shared_ptr< Gdiplus::TextureBrush > TextureBrushSharedPtr;
66 
73  template< typename T > class COMReference
74  {
75  public:
76  typedef T Wrappee;
77 
79  mp( nullptr )
80  {
81  }
82 
99  explicit COMReference( T* p ) :
100  mp( p )
101  {
102  }
103 
104  COMReference( const COMReference& rNew ) :
105  mp( nullptr )
106  {
107  if( rNew.mp == nullptr )
108  return;
109 
110  rNew.mp->AddRef(); // do that _before_ assigning the
111  // pointer. Just in case...
112  mp = rNew.mp;
113  }
114 
116  {
117  COMReference aTmp(rRHS);
118  std::swap( mp, aTmp.mp );
119 
120  return *this;
121  }
122 
124  {
125  reset();
126  }
127 
128  int reset()
129  {
130  int refcount = 0;
131  if( mp )
132  refcount = mp->Release();
133 
134  mp = nullptr;
135  return refcount;
136  }
137 
138  bool is() const { return mp != nullptr; }
139  T* get() const { return mp; }
140  T* operator->() const { return mp; }
141  T& operator*() const { return *mp; }
142 
143  private:
144  T* mp;
145  };
146 
147 }
148 
149 
150 #include <postwin.h>
151 
152 #endif // INCLUDED_CANVAS_SOURCE_DIRECTX_DX_WINSTUFF_HXX
153 
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< Gdiplus::TextureBrush > TextureBrushSharedPtr
Definition: dx_winstuff.hxx:65
COMReference(const COMReference &rNew)
std::shared_ptr< Gdiplus::Font > FontSharedPtr
COM object RAII wrapper.
Definition: dx_winstuff.hxx:73
IDirect3DSurface9 surface_type
Definition: dx_winstuff.hxx:42
std::shared_ptr< Gdiplus::Bitmap > BitmapSharedPtr
Definition: dx_winstuff.hxx:63
std::shared_ptr< Gdiplus::GraphicsPath > GraphicsPathSharedPtr
Definition: dx_winstuff.hxx:62
COMReference & operator=(const COMReference &rRHS)
std::shared_ptr< Gdiplus::Graphics > GraphicsSharedPtr
Definition: dx_winstuff.hxx:61