• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22 
23 #ifndef _NINE_SWAPCHAIN9_H_
24 #define _NINE_SWAPCHAIN9_H_
25 
26 #include "iunknown.h"
27 #include "adapter9.h"
28 
29 #include "d3dadapter/d3dadapter9.h"
30 
31 #include "threadpool.h"
32 
33 struct NineDevice9;
34 struct NineSurface9;
35 struct nine_winsys_swapchain;
36 struct blit_state;
37 
38 #define DRI_SWAP_FENCES_MAX 4
39 #define DRI_SWAP_FENCES_MASK 3
40 
41 struct NineSwapChain9
42 {
43     struct NineUnknown base;
44 
45     /* G3D stuff */
46     struct pipe_screen *screen;
47 
48     /* presentation backend */
49     ID3DPresent *present;
50     D3DPRESENT_PARAMETERS params;
51     D3DDISPLAYMODEEX *mode;
52     struct d3dadapter9_context *actx;
53     BOOL implicit;
54     unsigned num_back_buffers;
55 
56     /* buffer handles */
57     struct NineSurface9 *buffers[D3DPRESENT_BACK_BUFFERS_MAX_EX + 1]; /* 0 to BackBufferCount-1 : the back buffers. BackBufferCount : additional buffer */
58     struct pipe_resource *present_buffers[D3DPRESENT_BACK_BUFFERS_MAX_EX + 1];
59     D3DWindowBuffer *present_handles[D3DPRESENT_BACK_BUFFERS_MAX_EX + 1];
60 
61     struct pipe_fence_handle *swap_fences[DRI_SWAP_FENCES_MAX];
62     unsigned int cur_fences;
63     unsigned int head;
64     unsigned int tail;
65     unsigned int desired_fences;
66 
67     BOOL rendering_done;
68 
69     struct NineSurface9 *zsbuf;
70 
71     D3DGAMMARAMP gamma;
72 
73     struct threadpool *pool;
74     struct threadpool_task *tasks[D3DPRESENT_BACK_BUFFERS_MAX_EX + 1];
75     BOOL enable_threadpool;
76 };
77 
78 static inline struct NineSwapChain9 *
NineSwapChain9(void * data)79 NineSwapChain9( void *data )
80 {
81     return (struct NineSwapChain9 *)data;
82 }
83 
84 HRESULT
85 NineSwapChain9_new( struct NineDevice9 *pDevice,
86                     BOOL implicit,
87                     ID3DPresent *pPresent,
88                     D3DPRESENT_PARAMETERS *pPresentationParameters,
89                     struct d3dadapter9_context *pCTX,
90                     HWND hFocusWindow,
91                     struct NineSwapChain9 **ppOut );
92 
93 HRESULT
94 NineSwapChain9_ctor( struct NineSwapChain9 *This,
95                      struct NineUnknownParams *pParams,
96                      BOOL implicit,
97                      ID3DPresent *pPresent,
98                      D3DPRESENT_PARAMETERS *pPresentationParameters,
99                      struct d3dadapter9_context *pCTX,
100                      HWND hFocusWindow,
101                      D3DDISPLAYMODEEX *mode );
102 
103 void
104 NineSwapChain9_dtor( struct NineSwapChain9 *This );
105 
106 HRESULT
107 NineSwapChain9_Resize( struct NineSwapChain9 *This,
108                        D3DPRESENT_PARAMETERS *pParams,
109                        D3DDISPLAYMODEEX *mode );
110 
111 HRESULT NINE_WINAPI
112 NineSwapChain9_Present( struct NineSwapChain9 *This,
113                         const RECT *pSourceRect,
114                         const RECT *pDestRect,
115                         HWND hDestWindowOverride,
116                         const RGNDATA *pDirtyRegion,
117                         DWORD dwFlags );
118 
119 HRESULT NINE_WINAPI
120 NineSwapChain9_GetFrontBufferData( struct NineSwapChain9 *This,
121                                    IDirect3DSurface9 *pDestSurface );
122 
123 HRESULT NINE_WINAPI
124 NineSwapChain9_GetBackBuffer( struct NineSwapChain9 *This,
125                               UINT iBackBuffer,
126                               D3DBACKBUFFER_TYPE Type,
127                               IDirect3DSurface9 **ppBackBuffer );
128 
129 HRESULT NINE_WINAPI
130 NineSwapChain9_GetRasterStatus( struct NineSwapChain9 *This,
131                                 D3DRASTER_STATUS *pRasterStatus );
132 
133 HRESULT NINE_WINAPI
134 NineSwapChain9_GetDisplayMode( struct NineSwapChain9 *This,
135                                D3DDISPLAYMODE *pMode );
136 
137 HRESULT NINE_WINAPI
138 NineSwapChain9_GetPresentParameters( struct NineSwapChain9 *This,
139                                      D3DPRESENT_PARAMETERS *pPresentationParameters );
140 
141 BOOL
142 NineSwapChain9_GetOccluded( struct NineSwapChain9 *This );
143 
144 BOOL
145 NineSwapChain9_ResolutionMismatch( struct NineSwapChain9 *This );
146 
147 HANDLE
148 NineSwapChain9_CreateThread( struct NineSwapChain9 *This,
149                                  void *pFuncAddress,
150                                  void *pParam );
151 
152 void
153 NineSwapChain9_WaitForThread( struct NineSwapChain9 *This,
154                                   HANDLE thread );
155 
156 #endif /* _NINE_SWAPCHAIN9_H_ */
157