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