17ec681f3Smrg/*
27ec681f3Smrg * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg * to deal in the Software without restriction, including without limitation
77ec681f3Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub
87ec681f3Smrg * license, and/or sell copies of the Software, and to permit persons to whom
97ec681f3Smrg * the Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg * The above copyright notice and this permission notice (including the next
127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg * Software.
147ec681f3Smrg *
157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
187ec681f3Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
197ec681f3Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
207ec681f3Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
217ec681f3Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. */
227ec681f3Smrg
237ec681f3Smrg#ifndef _NINE_SWAPCHAIN9_H_
247ec681f3Smrg#define _NINE_SWAPCHAIN9_H_
257ec681f3Smrg
267ec681f3Smrg#include "iunknown.h"
277ec681f3Smrg#include "adapter9.h"
287ec681f3Smrg
297ec681f3Smrg#include "d3dadapter/d3dadapter9.h"
307ec681f3Smrg
317ec681f3Smrg#include "threadpool.h"
327ec681f3Smrg
337ec681f3Smrgstruct NineDevice9;
347ec681f3Smrgstruct NineSurface9;
357ec681f3Smrgstruct nine_winsys_swapchain;
367ec681f3Smrgstruct blit_state;
377ec681f3Smrg
387ec681f3Smrg#define DRI_SWAP_FENCES_MAX 4
397ec681f3Smrg#define DRI_SWAP_FENCES_MASK 3
407ec681f3Smrg
417ec681f3Smrgstruct NineSwapChain9
427ec681f3Smrg{
437ec681f3Smrg    struct NineUnknown base;
447ec681f3Smrg
457ec681f3Smrg    /* G3D stuff */
467ec681f3Smrg    struct pipe_screen *screen;
477ec681f3Smrg
487ec681f3Smrg    /* presentation backend */
497ec681f3Smrg    ID3DPresent *present;
507ec681f3Smrg    D3DPRESENT_PARAMETERS params;
517ec681f3Smrg    D3DDISPLAYMODEEX *mode;
527ec681f3Smrg    struct d3dadapter9_context *actx;
537ec681f3Smrg    BOOL implicit;
547ec681f3Smrg    unsigned num_back_buffers;
557ec681f3Smrg
567ec681f3Smrg    /* buffer handles */
577ec681f3Smrg    struct NineSurface9 *buffers[D3DPRESENT_BACK_BUFFERS_MAX_EX + 1]; /* 0 to BackBufferCount-1 : the back buffers. BackBufferCount : additional buffer */
587ec681f3Smrg    struct pipe_resource *present_buffers[D3DPRESENT_BACK_BUFFERS_MAX_EX + 1];
597ec681f3Smrg    D3DWindowBuffer *present_handles[D3DPRESENT_BACK_BUFFERS_MAX_EX + 1];
607ec681f3Smrg    D3DWindowBuffer *present_handles_pending_release[D3DPRESENT_BACK_BUFFERS_MAX_EX + 1];
617ec681f3Smrg
627ec681f3Smrg    struct pipe_fence_handle *swap_fences[DRI_SWAP_FENCES_MAX];
637ec681f3Smrg    unsigned int cur_fences;
647ec681f3Smrg    unsigned int head;
657ec681f3Smrg    unsigned int tail;
667ec681f3Smrg    unsigned int desired_fences;
677ec681f3Smrg
687ec681f3Smrg    BOOL rendering_done;
697ec681f3Smrg
707ec681f3Smrg    struct NineSurface9 *zsbuf;
717ec681f3Smrg
727ec681f3Smrg    D3DGAMMARAMP gamma;
737ec681f3Smrg
747ec681f3Smrg    struct threadpool *pool;
757ec681f3Smrg    struct threadpool_task *tasks[D3DPRESENT_BACK_BUFFERS_MAX_EX + 1];
767ec681f3Smrg    BOOL *pending_presentation[D3DPRESENT_BACK_BUFFERS_MAX_EX + 1];
777ec681f3Smrg    BOOL enable_threadpool;
787ec681f3Smrg};
797ec681f3Smrg
807ec681f3Smrgstatic inline struct NineSwapChain9 *
817ec681f3SmrgNineSwapChain9( void *data )
827ec681f3Smrg{
837ec681f3Smrg    return (struct NineSwapChain9 *)data;
847ec681f3Smrg}
857ec681f3Smrg
867ec681f3SmrgHRESULT
877ec681f3SmrgNineSwapChain9_new( struct NineDevice9 *pDevice,
887ec681f3Smrg                    BOOL implicit,
897ec681f3Smrg                    ID3DPresent *pPresent,
907ec681f3Smrg                    D3DPRESENT_PARAMETERS *pPresentationParameters,
917ec681f3Smrg                    struct d3dadapter9_context *pCTX,
927ec681f3Smrg                    HWND hFocusWindow,
937ec681f3Smrg                    struct NineSwapChain9 **ppOut );
947ec681f3Smrg
957ec681f3SmrgHRESULT
967ec681f3SmrgNineSwapChain9_ctor( struct NineSwapChain9 *This,
977ec681f3Smrg                     struct NineUnknownParams *pParams,
987ec681f3Smrg                     BOOL implicit,
997ec681f3Smrg                     ID3DPresent *pPresent,
1007ec681f3Smrg                     D3DPRESENT_PARAMETERS *pPresentationParameters,
1017ec681f3Smrg                     struct d3dadapter9_context *pCTX,
1027ec681f3Smrg                     HWND hFocusWindow,
1037ec681f3Smrg                     D3DDISPLAYMODEEX *mode );
1047ec681f3Smrg
1057ec681f3Smrgvoid
1067ec681f3SmrgNineSwapChain9_dtor( struct NineSwapChain9 *This );
1077ec681f3Smrg
1087ec681f3SmrgHRESULT
1097ec681f3SmrgNineSwapChain9_Resize( struct NineSwapChain9 *This,
1107ec681f3Smrg                       D3DPRESENT_PARAMETERS *pParams,
1117ec681f3Smrg                       D3DDISPLAYMODEEX *mode );
1127ec681f3Smrg
1137ec681f3SmrgHRESULT NINE_WINAPI
1147ec681f3SmrgNineSwapChain9_Present( struct NineSwapChain9 *This,
1157ec681f3Smrg                        const RECT *pSourceRect,
1167ec681f3Smrg                        const RECT *pDestRect,
1177ec681f3Smrg                        HWND hDestWindowOverride,
1187ec681f3Smrg                        const RGNDATA *pDirtyRegion,
1197ec681f3Smrg                        DWORD dwFlags );
1207ec681f3Smrg
1217ec681f3SmrgHRESULT NINE_WINAPI
1227ec681f3SmrgNineSwapChain9_GetFrontBufferData( struct NineSwapChain9 *This,
1237ec681f3Smrg                                   IDirect3DSurface9 *pDestSurface );
1247ec681f3Smrg
1257ec681f3SmrgHRESULT NINE_WINAPI
1267ec681f3SmrgNineSwapChain9_GetBackBuffer( struct NineSwapChain9 *This,
1277ec681f3Smrg                              UINT iBackBuffer,
1287ec681f3Smrg                              D3DBACKBUFFER_TYPE Type,
1297ec681f3Smrg                              IDirect3DSurface9 **ppBackBuffer );
1307ec681f3Smrg
1317ec681f3SmrgHRESULT NINE_WINAPI
1327ec681f3SmrgNineSwapChain9_GetRasterStatus( struct NineSwapChain9 *This,
1337ec681f3Smrg                                D3DRASTER_STATUS *pRasterStatus );
1347ec681f3Smrg
1357ec681f3SmrgHRESULT NINE_WINAPI
1367ec681f3SmrgNineSwapChain9_GetDisplayMode( struct NineSwapChain9 *This,
1377ec681f3Smrg                               D3DDISPLAYMODE *pMode );
1387ec681f3Smrg
1397ec681f3SmrgHRESULT NINE_WINAPI
1407ec681f3SmrgNineSwapChain9_GetPresentParameters( struct NineSwapChain9 *This,
1417ec681f3Smrg                                     D3DPRESENT_PARAMETERS *pPresentationParameters );
1427ec681f3Smrg
1437ec681f3SmrgBOOL
1447ec681f3SmrgNineSwapChain9_GetOccluded( struct NineSwapChain9 *This );
1457ec681f3Smrg
1467ec681f3SmrgBOOL
1477ec681f3SmrgNineSwapChain9_ResolutionMismatch( struct NineSwapChain9 *This );
1487ec681f3Smrg
1497ec681f3SmrgHANDLE
1507ec681f3SmrgNineSwapChain9_CreateThread( struct NineSwapChain9 *This,
1517ec681f3Smrg                                 void *pFuncAddress,
1527ec681f3Smrg                                 void *pParam );
1537ec681f3Smrg
1547ec681f3Smrgvoid
1557ec681f3SmrgNineSwapChain9_WaitForThread( struct NineSwapChain9 *This,
1567ec681f3Smrg                                  HANDLE thread );
1577ec681f3Smrg
1587ec681f3Smrg#endif /* _NINE_SWAPCHAIN9_H_ */
159