ws2_32: Define sipx_network / sipx_node for DragonFly BSD.
[wine] / dlls / wined3d / clipper.c
1 /* IWineD3DClipper implementation
2  *
3  * Copyright 2000 (c) Marcus Meissner
4  * Copyright 2000 (c) TransGaming Technologies Inc.
5  * Copyright 2006 (c) Stefan Dösinger
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23 #include <stdio.h>
24 #ifdef HAVE_FLOAT_H
25 # include <float.h>
26 #endif
27 #include "wined3d_private.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
30
31 ULONG CDECL wined3d_clipper_incref(struct wined3d_clipper *clipper)
32 {
33     ULONG refcount = InterlockedIncrement(&clipper->ref);
34
35     TRACE("%p increasing refcount to %u.\n", clipper, refcount);
36
37     return refcount;
38 }
39
40 ULONG CDECL wined3d_clipper_decref(struct wined3d_clipper *clipper)
41 {
42     ULONG refcount = InterlockedDecrement(&clipper->ref);
43
44     TRACE("%p decreasing refcount to %u.\n", clipper, refcount);
45
46     if (!refcount)
47         HeapFree(GetProcessHeap(), 0, clipper);
48
49     return refcount;
50 }
51
52 HRESULT CDECL wined3d_clipper_set_window(struct wined3d_clipper *clipper, DWORD flags, HWND window)
53 {
54     TRACE("clipper %p, flags %#x, window %p.\n", clipper, flags, window);
55
56     if (flags)
57     {
58         FIXME("flags %#x, not supported.\n", flags);
59         return WINED3DERR_INVALIDCALL;
60     }
61
62     clipper->hWnd = window;
63
64     return WINED3D_OK;
65 }
66
67 HRESULT CDECL wined3d_clipper_get_clip_list(const struct wined3d_clipper *clipper, const RECT *rect,
68         RGNDATA *clip_list, DWORD *clip_list_size)
69 {
70     TRACE("clipper %p, rect %s, clip_list %p, clip_list_size %p.\n",
71             clipper, wine_dbgstr_rect(rect), clip_list, clip_list_size);
72
73     if (clipper->hWnd)
74     {
75         HDC hDC = GetDCEx(clipper->hWnd, NULL, DCX_WINDOW);
76         if (hDC)
77         {
78             HRGN hRgn = CreateRectRgn(0,0,0,0);
79             if (GetRandomRgn(hDC, hRgn, SYSRGN))
80             {
81                 if (GetVersion() & 0x80000000)
82                 {
83                     /* map region to screen coordinates */
84                     POINT org;
85                     GetDCOrgEx(hDC, &org);
86                     OffsetRgn(hRgn, org.x, org.y);
87                 }
88                 if (rect)
89                 {
90                     HRGN hRgnClip = CreateRectRgn(rect->left, rect->top,
91                             rect->right, rect->bottom);
92                     CombineRgn(hRgn, hRgn, hRgnClip, RGN_AND);
93                     DeleteObject(hRgnClip);
94                 }
95                 *clip_list_size = GetRegionData(hRgn, *clip_list_size, clip_list);
96             }
97             DeleteObject(hRgn);
98             ReleaseDC(clipper->hWnd, hDC);
99         }
100         return WINED3D_OK;
101     }
102     else
103     {
104         static unsigned int once;
105
106         if (!once++)
107             FIXME("clipper %p, rect %s, clip_list %p, clip_list_size %p stub!\n",
108                     clipper, wine_dbgstr_rect(rect), clip_list, clip_list_size);
109
110         if (clip_list_size)
111             *clip_list_size = 0;
112
113         return WINEDDERR_NOCLIPLIST;
114     }
115 }
116
117 HRESULT CDECL wined3d_clipper_set_clip_list(struct wined3d_clipper *clipper, const RGNDATA *region, DWORD flags)
118 {
119     static unsigned int once;
120
121     if (!once++ || !region)
122         FIXME("clipper %p, region %p, flags %#x stub!\n", clipper, region, flags);
123
124     return WINED3D_OK;
125 }
126
127 HRESULT CDECL wined3d_clipper_get_window(const struct wined3d_clipper *clipper, HWND *window)
128 {
129     TRACE("clipper %p, window %p.\n", clipper, window);
130
131     *window = clipper->hWnd;
132
133     return WINED3D_OK;
134 }
135
136 HRESULT CDECL wined3d_clipper_is_clip_list_changed(const struct wined3d_clipper *clipper, BOOL *changed)
137 {
138     FIXME("clipper %p, changed %p stub!\n", clipper, changed);
139
140     /* XXX What is safest? */
141     *changed = FALSE;
142
143     return WINED3D_OK;
144 }
145
146 struct wined3d_clipper * CDECL wined3d_clipper_create(void)
147 {
148     struct wined3d_clipper *clipper;
149
150     TRACE("\n");
151
152     clipper = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*clipper));
153     if (!clipper)
154     {
155         ERR("Out of memory when trying to allocate a WineD3D Clipper\n");
156         return NULL;
157     }
158
159     wined3d_clipper_incref(clipper);
160
161     return clipper;
162 }