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