1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _DXCANVAS_WINSTUFF_HXX
21 #define _DXCANVAS_WINSTUFF_HXX
25 #include <boost/shared_ptr.hpp>
27 #include <basegfx/numeric/ftools.hxx>
30 #error someone else included <windows.h>
33 // Enabling Direct3D Debug Information Further more, with registry key
34 // \\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Direct3D\D3D9Debugging\\EnableCreationStack
35 // set to 1, sets a backtrace each time an object is created to the
36 // following global variable: LPCWSTR CreationCallStack
37 #if OSL_DEBUG_LEVEL > 0
38 # define D3D_DEBUG_INFO
41 #ifndef DIRECTX_VERSION
42 #error please define for which directx version we should compile
46 #pragma warning(push,1)
50 #define ULONG win32ULONG
51 #define GradientStyle_RECT win32GradientStyle_RECT
52 #define Polygon win32Polygon
53 #define PolyPolygon win32PolyPolygon
57 #define WIN32_LEAN_AND_MEAN
58 #include <windows.h> // TODO(Q1): extract minimal set of required headers for gdiplus
60 #if DIRECTX_VERSION < 0x0900
64 // Be compatible with directdraw 3.0. Lets see how far this takes us
65 #define DIRECTDRAW_VERSION 0x0300
68 // Be compatible with direct3d 5.0. Lets see how far this takes us
69 #define DIRECT3D_VERSION 0x0500
73 typedef IDirectDrawSurface surface_type
;
75 #elif WIN8_SDK == 1 || defined(_USING_V110_SDK71_)
79 typedef IDirect3DSurface9 surface_type
;
86 #if _DXSDK_BUILD_MAJOR < 1734 /* Earlier than the August 2009 DXSDK */
92 typedef IDirect3DSurface9 surface_type
;
114 // some shared pointer typedefs to Gdiplus objects
115 typedef ::boost::shared_ptr
< Gdiplus::Graphics
> GraphicsSharedPtr
;
116 typedef ::boost::shared_ptr
< Gdiplus::GraphicsPath
> GraphicsPathSharedPtr
;
117 typedef ::boost::shared_ptr
< Gdiplus::Bitmap
> BitmapSharedPtr
;
118 typedef ::boost::shared_ptr
< Gdiplus::CachedBitmap
> CachedBitmapSharedPtr
;
119 typedef ::boost::shared_ptr
< Gdiplus::Font
> FontSharedPtr
;
120 typedef ::boost::shared_ptr
< Gdiplus::Brush
> BrushSharedPtr
;
121 typedef ::boost::shared_ptr
< Gdiplus::TextureBrush
> TextureBrushSharedPtr
;
123 /** COM object RAII wrapper
125 This template wraps a Windows COM object, transparently
126 handling lifetime issues the C++ way (i.e. releasing the
127 reference when the object is destroyed)
129 template< typename T
> class COMReference
139 /** Create from raw pointer
141 @attention This constructor assumes the interface is
142 already acquired (unless p is NULL), no additional AddRef
145 This caters e.g. for all DirectX factory methods, which
146 return the created interfaces pre-acquired, into a raw
147 pointer. Simply pass the pointer to this class, but don't
148 call Release manually on it!
150 @example IDirectDrawSurface* pSurface;
151 pDD->CreateSurface(&aSurfaceDesc, &pSurface, NULL);
152 mpSurface = COMReference< IDirectDrawSurface >(pSurface);
155 explicit COMReference( T
* p
) :
160 COMReference( const COMReference
& rNew
) :
163 if( rNew
.mp
== NULL
)
166 rNew
.mp
->AddRef(); // do that _before_ assigning the
167 // pointer. Just in case...
171 COMReference
& operator=( const COMReference
& rRHS
)
173 COMReference
aTmp(rRHS
);
174 ::std::swap( mp
, aTmp
.mp
);
188 refcount
= mp
->Release();
194 bool is() const { return mp
!= NULL
; }
195 T
* get() const { return mp
; }
196 T
* operator->() const { return mp
; }
197 T
& operator*() const { return *mp
; }
203 // get_pointer() enables boost::mem_fn to recognize COMReference
204 template<class T
> inline T
* get_pointer(COMReference
<T
> const& p
)
217 #endif /* _DXCANVAS_WINSTUFF_HXX */
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */