comctl32/monthcal: After notification safely free buffer allocated on heap.
[wine/multimedia.git] / dlls / wined3d / clipper.c
blob0829cde1717eb9b41c56586f3bc3f11cdba9d41b
1 /*
2 * Copyright 2000 (c) Marcus Meissner
3 * Copyright 2000 (c) TransGaming Technologies Inc.
4 * Copyright 2006 (c) Stefan Dösinger
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include <stdio.h>
23 #ifdef HAVE_FLOAT_H
24 # include <float.h>
25 #endif
26 #include "wined3d_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
30 ULONG CDECL wined3d_clipper_incref(struct wined3d_clipper *clipper)
32 ULONG refcount = InterlockedIncrement(&clipper->ref);
34 TRACE("%p increasing refcount to %u.\n", clipper, refcount);
36 return refcount;
39 ULONG CDECL wined3d_clipper_decref(struct wined3d_clipper *clipper)
41 ULONG refcount = InterlockedDecrement(&clipper->ref);
43 TRACE("%p decreasing refcount to %u.\n", clipper, refcount);
45 if (!refcount)
46 HeapFree(GetProcessHeap(), 0, clipper);
48 return refcount;
51 HRESULT CDECL wined3d_clipper_set_window(struct wined3d_clipper *clipper, DWORD flags, HWND window)
53 TRACE("clipper %p, flags %#x, window %p.\n", clipper, flags, window);
55 if (flags)
57 FIXME("flags %#x, not supported.\n", flags);
58 return WINED3DERR_INVALIDCALL;
61 clipper->hWnd = window;
63 return WINED3D_OK;
66 HRESULT CDECL wined3d_clipper_get_clip_list(const struct wined3d_clipper *clipper, const RECT *rect,
67 RGNDATA *clip_list, DWORD *clip_list_size)
69 TRACE("clipper %p, rect %s, clip_list %p, clip_list_size %p.\n",
70 clipper, wine_dbgstr_rect(rect), clip_list, clip_list_size);
72 if (clipper->hWnd)
74 HDC hDC = GetDCEx(clipper->hWnd, NULL, DCX_WINDOW);
75 if (hDC)
77 HRGN hRgn = CreateRectRgn(0,0,0,0);
78 if (GetRandomRgn(hDC, hRgn, SYSRGN))
80 if (GetVersion() & 0x80000000)
82 /* map region to screen coordinates */
83 POINT org;
84 GetDCOrgEx(hDC, &org);
85 OffsetRgn(hRgn, org.x, org.y);
87 if (rect)
89 HRGN hRgnClip = CreateRectRgn(rect->left, rect->top,
90 rect->right, rect->bottom);
91 CombineRgn(hRgn, hRgn, hRgnClip, RGN_AND);
92 DeleteObject(hRgnClip);
94 *clip_list_size = GetRegionData(hRgn, *clip_list_size, clip_list);
96 DeleteObject(hRgn);
97 ReleaseDC(clipper->hWnd, hDC);
99 return WINED3D_OK;
101 else
103 static unsigned int once;
105 if (!once++)
106 FIXME("clipper %p, rect %s, clip_list %p, clip_list_size %p stub!\n",
107 clipper, wine_dbgstr_rect(rect), clip_list, clip_list_size);
109 if (clip_list_size)
110 *clip_list_size = 0;
112 return WINEDDERR_NOCLIPLIST;
116 HRESULT CDECL wined3d_clipper_set_clip_list(struct wined3d_clipper *clipper, const RGNDATA *region, DWORD flags)
118 static unsigned int once;
120 if (!once++ || !region)
121 FIXME("clipper %p, region %p, flags %#x stub!\n", clipper, region, flags);
123 return WINED3D_OK;
126 HRESULT CDECL wined3d_clipper_get_window(const struct wined3d_clipper *clipper, HWND *window)
128 TRACE("clipper %p, window %p.\n", clipper, window);
130 *window = clipper->hWnd;
132 return WINED3D_OK;
135 HRESULT CDECL wined3d_clipper_is_clip_list_changed(const struct wined3d_clipper *clipper, BOOL *changed)
137 FIXME("clipper %p, changed %p stub!\n", clipper, changed);
139 /* XXX What is safest? */
140 *changed = FALSE;
142 return WINED3D_OK;
145 struct wined3d_clipper * CDECL wined3d_clipper_create(void)
147 struct wined3d_clipper *clipper;
149 TRACE("\n");
151 clipper = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*clipper));
152 if (!clipper)
154 ERR("Out of memory when trying to allocate a WineD3D Clipper\n");
155 return NULL;
158 wined3d_clipper_incref(clipper);
160 return clipper;