1 /*!
2  * \copy
3  *     Copyright (c)  2010-2013, Cisco Systems
4  *     All rights reserved.
5  *
6  *     Redistribution and use in source and binary forms, with or without
7  *     modification, are permitted provided that the following conditions
8  *     are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *
13  *        * Redistributions in binary form must reproduce the above copyright
14  *          notice, this list of conditions and the following disclaimer in
15  *          the documentation and/or other materials provided with the
16  *          distribution.
17  *
18  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *     POSSIBILITY OF SUCH DAMAGE.
30  *
31  * \file    d3d9_utils.h
32  *
33  * \brief   interface of d3d9 render module
34  *
35  * \date    Created 12/14/2010
36  *
37  * \description : 1. Rendering in Vista and upper : D3D9Ex method, support host memory / shared surface input
38  *                2. Rendering in XP : D3D9 method w/o device lost handling, support host memory input
39  *                3. File Dump : support host memory / shared surface input
40  *
41  *************************************************************************************
42  */
43 #ifndef WELS_D3D9_UTILS_H__
44 #define WELS_D3D9_UTILS_H__
45 
46 #include <stdio.h>
47 #include "codec_def.h"
48 
49 #if defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008 and upper
50 #ifdef WINAPI_FAMILY
51 #include <winapifamily.h>
52 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
53 #define ENABLE_DISPLAY_MODULE // enable/disable the render feature
54 #endif
55 #else /* defined(WINAPI_FAMILY) */
56 #define ENABLE_DISPLAY_MODULE // enable/disable the render feature
57 #endif
58 #endif
59 
60 #ifdef ENABLE_DISPLAY_MODULE
61 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62 #include <d3d9.h>
63 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
64 
65 class CD3D9Utils {
66  public:
67   CD3D9Utils();
68   ~CD3D9Utils();
69 
70  public:
71   HRESULT Init (BOOL bWindowed);
72   HRESULT Uninit (void);
73   HRESULT Process (void* pDst[3], SBufferInfo* Info, FILE* pFile = NULL);
74 
75  private:
76   HRESULT InitResource (void* pSharedHandle, SBufferInfo* pInfo);
77   HRESULT Render (void* pDst[3], SBufferInfo* pInfo);
78   HRESULT Dump (void* pDst[3], SBufferInfo* pInfo, FILE* pFile);
79 
80  private:
81   HMODULE               m_hDll;
82   HWND                  m_hWnd;
83   unsigned char*        m_pDumpYUV;
84   BOOL                  m_bInitDone;
85   int                   m_nWidth;
86   int                   m_nHeight;
87 
88   LPDIRECT3D9           m_lpD3D9;
89   LPDIRECT3DDEVICE9     m_lpD3D9Device;
90 
91   D3DPRESENT_PARAMETERS m_d3dpp;
92   LPDIRECT3DSURFACE9    m_lpD3D9RawSurfaceShare;
93 };
94 
95 class CD3D9ExUtils {
96  public:
97   CD3D9ExUtils();
98   ~CD3D9ExUtils();
99 
100  public:
101   HRESULT Init (BOOL bWindowed);
102   HRESULT Uninit (void);
103   HRESULT Process (void* dst[3], SBufferInfo* Info, FILE* fp = NULL);
104 
105  private:
106   HRESULT InitResource (void* pSharedHandle, SBufferInfo* Info);
107   HRESULT Render (void* pDst[3], SBufferInfo* Info);
108   HRESULT Dump (void* pDst[3], SBufferInfo* Info, FILE* fp);
109 
110  private:
111   HMODULE               m_hDll;
112   HWND                  m_hWnd;
113   unsigned char*        m_pDumpYUV;
114   BOOL                  m_bInitDone;
115   int                   m_nWidth;
116   int                   m_nHeight;
117 
118   LPDIRECT3D9EX         m_lpD3D9;
119   LPDIRECT3DDEVICE9EX   m_lpD3D9Device;
120 
121   D3DPRESENT_PARAMETERS m_d3dpp;
122   LPDIRECT3DSURFACE9    m_lpD3D9RawSurfaceShare;
123 };
124 #endif
125 
126 enum {
127   OS_UNSUPPORTED = 0,
128   OS_XP,
129   OS_VISTA_UPPER
130 };
131 
132 class CUtils {
133  public:
134   CUtils();
135   ~CUtils();
136 
137   int Process (void* dst[3], SBufferInfo* Info, FILE* fp);
138 
139  private:
140   int CheckOS (void);
141 
142  private:
143   int iOSType;
144   void* hHandle;
145 };
146 
147 #endif//WELS_D3D9_UTILS_H__
148 
149