1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dx_winstuff.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _DXCANVAS_WINSTUFF_HXX
32 #define _DXCANVAS_WINSTUFF_HXX
36 #include <boost/shared_ptr.hpp>
38 #include <basegfx/numeric/ftools.hxx>
41 #error someone else included <windows.h>
44 // Enabling Direct3D Debug Information Further more, with registry key
45 // \\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Direct3D\D3D9Debugging\\EnableCreationStack
46 // set to 1, sets a backtrace each time an object is created to the
47 // following global variable: LPCWSTR CreationCallStack
48 #if OSL_DEBUG_LEVEL > 0
49 # define D3D_DEBUG_INFO
52 #ifndef DIRECTX_VERSION
53 #error please define for which directx version we should compile
57 #pragma warning(push,1)
61 #define BOOL win32BOOL
62 #define INT32 win32INT32
63 #define UINT32 win32UINT32
64 #define GradientStyle_RECT win32GradientStyle_RECT
65 #define Polygon win32Polygon
66 #define PolyPolygon win32PolyPolygon
70 #define WIN32_LEAN_AND_MEAN
71 #include <windows.h> // TODO(Q1): extract minimal set of required headers for gdiplus
73 #if DIRECTX_VERSION < 0x0900
77 // Be compatible with directdraw 3.0. Lets see how far this takes us
78 #define DIRECTDRAW_VERSION 0x0300
81 // Be compatible with direct3d 5.0. Lets see how far this takes us
82 #define DIRECT3D_VERSION 0x0500
86 typedef IDirectDrawSurface surface_type
;
93 #if _DXSDK_BUILD_MAJOR < 1734 /* Earlier than the August 2009 DXSDK */
99 typedef IDirect3DSurface9 surface_type
;
105 // Needed for #?$&/@ gdiplus header
107 #define max(a,b) (((a) > (b)) ? (a) : (b))
108 #define __WORKAROUND_MAX_DEFINED__
112 #define min(a,b) (((a) < (b)) ? (a) : (b))
113 #define __WORKAROUND_MIN_DEFINED__
118 #ifdef __WORKAROUND_MAX_DEFINED__
122 #ifdef __WORKAROUND_MIN_DEFINED__
128 // some shared pointer typedefs to Gdiplus objects
129 typedef ::boost::shared_ptr
< Gdiplus::Graphics
> GraphicsSharedPtr
;
130 typedef ::boost::shared_ptr
< Gdiplus::GraphicsPath
> GraphicsPathSharedPtr
;
131 typedef ::boost::shared_ptr
< Gdiplus::Bitmap
> BitmapSharedPtr
;
132 typedef ::boost::shared_ptr
< Gdiplus::CachedBitmap
> CachedBitmapSharedPtr
;
133 typedef ::boost::shared_ptr
< Gdiplus::Font
> FontSharedPtr
;
134 typedef ::boost::shared_ptr
< Gdiplus::Brush
> BrushSharedPtr
;
135 typedef ::boost::shared_ptr
< Gdiplus::TextureBrush
> TextureBrushSharedPtr
;
137 /** COM object RAII wrapper
139 This template wraps a Windows COM object, transparently
140 handling lifetime issues the C++ way (i.e. releasing the
141 reference when the object is destroyed)
143 template< typename T
> class COMReference
153 /** Create from raw pointer
155 @attention This constructor assumes the interface is
156 already acquired (unless p is NULL), no additional AddRef
159 This caters e.g. for all DirectX factory methods, which
160 return the created interfaces pre-acquired, into a raw
161 pointer. Simply pass the pointer to this class, but don't
162 call Release manually on it!
164 @example IDirectDrawSurface* pSurface;
165 pDD->CreateSurface(&aSurfaceDesc, &pSurface, NULL);
166 mpSurface = COMReference< IDirectDrawSurface >(pSurface);
169 explicit COMReference( T
* p
) :
174 COMReference( const COMReference
& rNew
) :
177 if( rNew
.mp
== NULL
)
180 rNew
.mp
->AddRef(); // do that _before_ assigning the
181 // pointer. Just in case...
185 COMReference
& operator=( const COMReference
& rRHS
)
187 COMReference
aTmp(rRHS
);
188 ::std::swap( mp
, aTmp
.mp
);
202 refcount
= mp
->Release();
208 bool is() const { return mp
!= NULL
; }
209 T
* get() const { return mp
; }
210 T
* operator->() const { return mp
; }
211 T
& operator*() const { return *mp
; }
217 // get_pointer() enables boost::mem_fn to recognize COMReference
218 template<class T
> inline T
* get_pointer(COMReference
<T
> const& p
)
234 #endif /* _DXCANVAS_WINSTUFF_HXX */