Fixed a race condition on RPC worker thread creation, and a typo.
[wine] / dlls / d3d8 / surface.c
1 /*
2  * IDirect3DSurface8 implementation
3  *
4  * Copyright 2002 Jason Edmeades
5  *
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.
10  *
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.
15  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
27 #include "wine/debug.h"
28
29 #include "d3d8_private.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
32
33 /* IDirect3DVolume IUnknown parts follow: */
34 HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(LPDIRECT3DSURFACE8 iface,REFIID riid,LPVOID *ppobj)
35 {
36     ICOM_THIS(IDirect3DSurface8Impl,iface);
37
38     if (IsEqualGUID(riid, &IID_IUnknown)
39         || IsEqualGUID(riid, &IID_IDirect3DSurface8)) {
40         IDirect3DSurface8Impl_AddRef(iface);
41         *ppobj = This;
42         return D3D_OK;
43     }
44
45     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
46     return E_NOINTERFACE;
47 }
48
49 ULONG WINAPI IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface) {
50     ICOM_THIS(IDirect3DSurface8Impl,iface);
51     TRACE("(%p) : AddRef from %ld\n", This, This->ref);
52     return ++(This->ref);
53 }
54
55 ULONG WINAPI IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface) {
56     ICOM_THIS(IDirect3DSurface8Impl,iface);
57     ULONG ref = --This->ref;
58     TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
59     if (ref == 0) {
60         HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
61         HeapFree(GetProcessHeap(), 0, This);
62     }
63     return ref;
64 }
65
66 /* IDirect3DSurface8: */
67 HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(LPDIRECT3DSURFACE8 iface, IDirect3DDevice8** ppDevice) {
68     ICOM_THIS(IDirect3DSurface8Impl,iface);
69     TRACE("(%p) : returning %p\n", This, This->Device);
70     *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
71     /**
72      * Note  Calling this method will increase the internal reference count 
73      * on the IDirect3DDevice8 interface. 
74      */
75     IDirect3DDevice8Impl_AddRef(*ppDevice);
76     return D3D_OK;
77 }
78 HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
79     ICOM_THIS(IDirect3DSurface8Impl,iface);
80     FIXME("(%p) : stub\n", This);    return D3D_OK;
81 }
82 HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
83     ICOM_THIS(IDirect3DSurface8Impl,iface);
84     FIXME("(%p) : stub\n", This);    return D3D_OK;
85 }
86 HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid) {
87     ICOM_THIS(IDirect3DSurface8Impl,iface);
88     FIXME("(%p) : stub\n", This);    return D3D_OK;
89 }
90 HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid, void** ppContainer) {
91     ICOM_THIS(IDirect3DSurface8Impl,iface);
92     HRESULT res;
93     /*
94     TRACE("(%p) : returning %p\n", This, This->Container);
95     *ppContainer = This->Container;
96     return D3D_OK;
97     */
98     res = IUnknown_QueryInterface(This->Container, riid, ppContainer);
99     if (E_NOINTERFACE == res) { 
100       /**
101        * If the surface is created using CreateImageSurface, CreateRenderTarget, 
102        * or CreateDepthStencilSurface, the surface is considered stand alone. In this case, 
103        * GetContainer will return the Direct3D device used to create the surface. 
104        */
105       res = IUnknown_QueryInterface(This->Container, &IID_IDirect3DDevice8, ppContainer);
106     }
107     TRACE("(%p) : returning %p\n", This, *ppContainer);
108     return res;
109 }
110 HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(LPDIRECT3DSURFACE8 iface, D3DSURFACE_DESC *pDesc) {
111     ICOM_THIS(IDirect3DSurface8Impl,iface);
112
113     TRACE("(%p) : copying into %p\n", This, pDesc);
114     memcpy(pDesc, &This->myDesc, sizeof(D3DSURFACE_DESC));
115     return D3D_OK;
116 }
117 HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect,DWORD Flags) {
118     ICOM_THIS(IDirect3DSurface8Impl,iface);
119     /* fixme: should we really lock as such? */
120     TRACE("(%p) : rect=%p, output prect=%p, allMem=%p\n", This, pRect, pLockedRect, This->allocatedMemory);
121
122     pLockedRect->Pitch = This->bytesPerPixel * This->myDesc.Width;  /* Bytes / row */
123     if (!pRect) {
124         pLockedRect->pBits = This->allocatedMemory;
125     } else {
126         TRACE("Lock Rect (%p) = l %ld, t %ld, r %ld, b %ld\n", pRect, pRect->left, pRect->top, pRect->right, pRect->bottom);
127         pLockedRect->pBits = This->allocatedMemory + (pLockedRect->Pitch * pRect->top) + (pRect->left * This->bytesPerPixel);
128     }
129     TRACE("returning pBits=%p, pitch=%d\n", pLockedRect->pBits, pLockedRect->Pitch);
130     return D3D_OK;
131 }
132 HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) {
133     ICOM_THIS(IDirect3DSurface8Impl,iface);
134     TRACE("(%p) : stub\n", This);
135     if (This->Container) {
136         IDirect3DBaseTexture8 *cont = (IDirect3DBaseTexture8*) This->Container;
137
138         /* Now setup the texture appropraitly */
139         int containerType = IDirect3DBaseTexture8Impl_GetType(cont);
140         if (containerType == D3DRTYPE_TEXTURE) {
141             IDirect3DTexture8Impl *pTexture = (IDirect3DTexture8Impl *)cont;
142             pTexture->Dirty = TRUE;
143         } else if (containerType == D3DRTYPE_CUBETEXTURE) {
144             IDirect3DCubeTexture8Impl *pTexture = (IDirect3DCubeTexture8Impl *)cont;
145             pTexture->Dirty = TRUE;
146
147         } else {
148             FIXME("Set dirty on container type %d\n", containerType);
149         }
150     }
151     return D3D_OK;
152 }
153
154
155 ICOM_VTABLE(IDirect3DSurface8) Direct3DSurface8_Vtbl =
156 {
157     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
158     IDirect3DSurface8Impl_QueryInterface,
159     IDirect3DSurface8Impl_AddRef,
160     IDirect3DSurface8Impl_Release,
161     IDirect3DSurface8Impl_GetDevice,
162     IDirect3DSurface8Impl_SetPrivateData,
163     IDirect3DSurface8Impl_GetPrivateData,
164     IDirect3DSurface8Impl_FreePrivateData,
165     IDirect3DSurface8Impl_GetContainer,
166     IDirect3DSurface8Impl_GetDesc,
167     IDirect3DSurface8Impl_LockRect,
168     IDirect3DSurface8Impl_UnlockRect,
169 };