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