1 /* $Id$
2  *
3  * COPYRIGHT:            See COPYING in the top level directory
4  * PROJECT:              ReactOS DirectX
5  * FILE:                 ddraw/clipper/clipper_stubs.c
6  * PURPOSE:              IDirectDrawClipper Implementation
7  * PROGRAMMER:           Maarten Bosma
8  *
9  */
10 
11 #include "rosdraw.h"
12 
13 HRESULT WINAPI
14 DirectDrawClipper_QueryInterface (LPDIRECTDRAWCLIPPER iface,
15                                 REFIID id,  LPVOID *obj)
16 {
17     if(!iface)
18         return DDERR_INVALIDOBJECT;
19 
20     return E_NOINTERFACE;
21 }
22 
23 HRESULT WINAPI
24 DirectDrawClipper_Initialize (LPDIRECTDRAWCLIPPER iface,
25                                LPDIRECTDRAW lpDD,  DWORD dwFlags)
26 {
27     LPDDRAWI_DDRAWCLIPPER_INT This = (LPDDRAWI_DDRAWCLIPPER_INT)iface;
28     LPDDRAWI_DIRECTDRAW_INT DDraw = (LPDDRAWI_DIRECTDRAW_INT)lpDD;
29 
30     DX_WINDBG_trace();
31 
32     if(!This)
33         return DDERR_INVALIDOBJECT;
34 
35     if(This->dwIntRefCnt)
36         return DDERR_ALREADYINITIALIZED;
37 
38     This->lpVtbl = (LPVOID)&DirectDrawClipper_Vtable;
39     This->dwIntRefCnt = 1;
40 
41     DxHeapMemAlloc(This->lpLcl, sizeof(DDRAWI_DDRAWCLIPPER_LCL));
42     //This->lpLcl->lpClipMore
43     This->lpLcl->lpDD_int = DDraw;
44     This->lpLcl->lpGbl->dwRefCnt = 1;
45     This->lpLcl->pAddrefedThisOwner = (IUnknown*)DDraw;
46 
47     // FIXME: Implement Linking and share global object
48     DxHeapMemAlloc(This->lpLcl->lpGbl, sizeof(DDRAWI_DDRAWCLIPPER_GBL));
49     This->lpLcl->lpGbl->dwProcessId = GetCurrentProcessId();
50 
51     return DD_OK;
52 }
53 
54 ULONG WINAPI
55 DirectDrawClipper_Release(LPDIRECTDRAWCLIPPER iface)
56 {
57     LPDDRAWI_DDRAWCLIPPER_INT This = (LPDDRAWI_DDRAWCLIPPER_INT)iface;
58     if(!This)
59         return DDERR_INVALIDOBJECT;
60 
61     DX_WINDBG_trace();
62 
63     if (iface!=NULL)
64     {
65         This->lpLcl->dwLocalRefCnt--;
66         This->dwIntRefCnt--;
67 
68         if (This->lpLcl->lpGbl)
69             This->lpLcl->lpGbl->dwRefCnt--;
70     }
71 
72     return This->dwIntRefCnt;
73 }
74 
75 ULONG WINAPI
76 DirectDrawClipper_AddRef (LPDIRECTDRAWCLIPPER iface)
77 {
78     LPDDRAWI_DDRAWCLIPPER_INT This = (LPDDRAWI_DDRAWCLIPPER_INT)iface;
79     if(!This)
80         return DDERR_INVALIDOBJECT;
81 
82     DX_WINDBG_trace();
83 
84     if (iface!=NULL)
85     {
86         This->dwIntRefCnt++;
87         This->lpLcl->dwLocalRefCnt++;
88         if (This->lpLcl->lpGbl)
89             This->lpLcl->lpGbl->dwRefCnt++;
90     }
91     return This->dwIntRefCnt;
92 }
93 
94 HRESULT WINAPI
95 DirectDrawClipper_SetHwnd( LPDIRECTDRAWCLIPPER iface,
96                            DWORD dwFlags,
97                            HWND hWnd)
98 {
99     LPDDRAWI_DDRAWCLIPPER_INT This = (LPDDRAWI_DDRAWCLIPPER_INT)iface;
100 
101     if(!This)
102         return DDERR_INVALIDOBJECT;
103 
104     if(!IsWindow(hWnd))
105         return DDERR_INVALIDPARAMS;
106 
107     // TODO: check flags
108 
109     This->lpLcl->lpGbl->hWnd = (ULONG_PTR)hWnd;
110     This->lpLcl->lpGbl->dwFlags = dwFlags;
111 
112     return DD_OK;
113 }
114 
115 HRESULT WINAPI
116 DirectDrawClipper_GetHWnd( LPDIRECTDRAWCLIPPER iface,
117                            HWND* hWndPtr)
118 {
119     LPDDRAWI_DDRAWCLIPPER_INT This = (LPDDRAWI_DDRAWCLIPPER_INT)iface;
120 
121     if(!This)
122         return DDERR_INVALIDOBJECT;
123 
124     if(!hWndPtr)
125         return DDERR_INVALIDPARAMS;
126 
127     *hWndPtr = (HWND)This->lpLcl->lpGbl->hWnd;
128 
129     return DD_OK;
130 }
131 
132 IDirectDrawClipperVtbl DirectDrawClipper_Vtable =
133 {
134     DirectDrawClipper_QueryInterface,
135     DirectDrawClipper_AddRef,
136     DirectDrawClipper_Release,
137     DirectDrawClipper_GetClipList,
138     DirectDrawClipper_GetHWnd,
139     DirectDrawClipper_Initialize,
140     DirectDrawClipper_IsClipListChanged,
141     DirectDrawClipper_SetClipList,
142     DirectDrawClipper_SetHwnd
143 };
144