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 INCLUDED_CANVAS_SOURCE_DIRECTX_DX_WINSTUFF_HXX
21 #define INCLUDED_CANVAS_SOURCE_DIRECTX_DX_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
42 #pragma warning(push,1)
46 #define ULONG win32ULONG
47 #define GradientStyle_RECT win32GradientStyle_RECT
48 #define Polygon win32Polygon
52 #define WIN32_LEAN_AND_MEAN
57 typedef IDirect3DSurface9 surface_type
;
78 // some shared pointer typedefs to Gdiplus objects
79 typedef ::boost::shared_ptr
< Gdiplus::Graphics
> GraphicsSharedPtr
;
80 typedef ::boost::shared_ptr
< Gdiplus::GraphicsPath
> GraphicsPathSharedPtr
;
81 typedef ::boost::shared_ptr
< Gdiplus::Bitmap
> BitmapSharedPtr
;
82 typedef ::boost::shared_ptr
< Gdiplus::CachedBitmap
> CachedBitmapSharedPtr
;
83 typedef ::boost::shared_ptr
< Gdiplus::Font
> FontSharedPtr
;
84 typedef ::boost::shared_ptr
< Gdiplus::Brush
> BrushSharedPtr
;
85 typedef ::boost::shared_ptr
< Gdiplus::TextureBrush
> TextureBrushSharedPtr
;
87 /** COM object RAII wrapper
89 This template wraps a Windows COM object, transparently
90 handling lifetime issues the C++ way (i.e. releasing the
91 reference when the object is destroyed)
93 template< typename T
> class COMReference
103 /** Create from raw pointer
105 @attention This constructor assumes the interface is
106 already acquired (unless p is NULL), no additional AddRef
109 This caters e.g. for all DirectX factory methods, which
110 return the created interfaces pre-acquired, into a raw
111 pointer. Simply pass the pointer to this class, but don't
112 call Release manually on it!
114 @example IDirectDrawSurface* pSurface;
115 pDD->CreateSurface(&aSurfaceDesc, &pSurface, NULL);
116 mpSurface = COMReference< IDirectDrawSurface >(pSurface);
119 explicit COMReference( T
* p
) :
124 COMReference( const COMReference
& rNew
) :
127 if( rNew
.mp
== NULL
)
130 rNew
.mp
->AddRef(); // do that _before_ assigning the
131 // pointer. Just in case...
135 COMReference
& operator=( const COMReference
& rRHS
)
137 COMReference
aTmp(rRHS
);
138 ::std::swap( mp
, aTmp
.mp
);
152 refcount
= mp
->Release();
158 bool is() const { return mp
!= NULL
; }
159 T
* get() const { return mp
; }
160 T
* operator->() const { return mp
; }
161 T
& operator*() const { return *mp
; }
167 // get_pointer() enables boost::mem_fn to recognize COMReference
168 template<class T
> inline T
* get_pointer(COMReference
<T
> const& p
)
179 #undef GradientStyle_RECT
182 #endif // INCLUDED_CANVAS_SOURCE_DIRECTX_DX_WINSTUFF_HXX
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */