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
;
121 // some shared pointer typedefs to Gdiplus objects
122 typedef ::boost::shared_ptr
< Gdiplus::Graphics
> GraphicsSharedPtr
;
123 typedef ::boost::shared_ptr
< Gdiplus::GraphicsPath
> GraphicsPathSharedPtr
;
124 typedef ::boost::shared_ptr
< Gdiplus::Bitmap
> BitmapSharedPtr
;
125 typedef ::boost::shared_ptr
< Gdiplus::CachedBitmap
> CachedBitmapSharedPtr
;
126 typedef ::boost::shared_ptr
< Gdiplus::Font
> FontSharedPtr
;
127 typedef ::boost::shared_ptr
< Gdiplus::Brush
> BrushSharedPtr
;
128 typedef ::boost::shared_ptr
< Gdiplus::TextureBrush
> TextureBrushSharedPtr
;
130 /** COM object RAII wrapper
132 This template wraps a Windows COM object, transparently
133 handling lifetime issues the C++ way (i.e. releasing the
134 reference when the object is destroyed)
136 template< typename T
> class COMReference
146 /** Create from raw pointer
148 @attention This constructor assumes the interface is
149 already acquired (unless p is NULL), no additional AddRef
152 This caters e.g. for all DirectX factory methods, which
153 return the created interfaces pre-acquired, into a raw
154 pointer. Simply pass the pointer to this class, but don't
155 call Release manually on it!
157 @example IDirectDrawSurface* pSurface;
158 pDD->CreateSurface(&aSurfaceDesc, &pSurface, NULL);
159 mpSurface = COMReference< IDirectDrawSurface >(pSurface);
162 explicit COMReference( T
* p
) :
167 COMReference( const COMReference
& rNew
) :
170 if( rNew
.mp
== NULL
)
173 rNew
.mp
->AddRef(); // do that _before_ assigning the
174 // pointer. Just in case...
178 COMReference
& operator=( const COMReference
& rRHS
)
180 COMReference
aTmp(rRHS
);
181 ::std::swap( mp
, aTmp
.mp
);
195 refcount
= mp
->Release();
201 bool is() const { return mp
!= NULL
; }
202 T
* get() const { return mp
; }
203 T
* operator->() const { return mp
; }
204 T
& operator*() const { return *mp
; }
210 // get_pointer() enables boost::mem_fn to recognize COMReference
211 template<class T
> inline T
* get_pointer(COMReference
<T
> const& p
)
227 #endif /* _DXCANVAS_WINSTUFF_HXX */