Add Pacific Standard Time (PST) to TZ_INFO.
[wine] / dlls / wined3d / device.c
1 /*
2  * IWineD3DDevice implementation
3  *
4  * Copyright 2002-2004 Jason Edmeades
5  * Copyright 2003-2004 Raphael Junqueira
6  * Copyright 2004 Christian Costa
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "config.h"
24 #include "wined3d_private.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
27 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
28
29 /**********************************************************
30  * Utility functions follow
31  **********************************************************/
32
33
34 /**********************************************************
35  * IWineD3DDevice implementation follows
36  **********************************************************/
37 HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexBuffer(IWineD3DDevice *iface, UINT Size, DWORD Usage, 
38                              DWORD FVF, D3DPOOL Pool, IWineD3DVertexBuffer** ppVertexBuffer, HANDLE *sharedHandle) {
39
40     IWineD3DVertexBufferImpl *object;
41     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
42
43     /* Allocate the storage for the device */
44     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DVertexBufferImpl));
45     object->lpVtbl                = &IWineD3DVertexBuffer_Vtbl;
46     object->resource.wineD3DDevice= iface;
47     object->resource.resourceType = D3DRTYPE_VERTEXBUFFER;
48     object->resource.ref          = 1;
49     object->allocatedMemory       = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Size);
50     object->currentDesc.Usage     = Usage;
51     object->currentDesc.Pool      = Pool;
52     object->currentDesc.FVF       = FVF;
53     object->currentDesc.Size      = Size;
54
55     TRACE("(%p) : Size=%d, Usage=%ld, FVF=%lx, Pool=%d - Memory@%p, Iface@%p\n", This, Size, Usage, FVF, Pool, object->allocatedMemory, object);
56     *ppVertexBuffer = (IWineD3DVertexBuffer *)object;
57
58     return D3D_OK;
59 }
60
61 HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, D3DSTATEBLOCKTYPE Type, IWineD3DStateBlock** ppStateBlock) {
62   
63     IWineD3DDeviceImpl     *This = (IWineD3DDeviceImpl *)iface;
64     IWineD3DStateBlockImpl *object;
65   
66     /* Allocate Storage for the state block */
67     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DStateBlockImpl));
68     object->lpVtbl        = &IWineD3DStateBlock_Vtbl;
69     object->wineD3DDevice = iface;
70     object->ref           = 1;
71     object->blockType     = Type;
72     *ppStateBlock         = (IWineD3DStateBlock *)object;
73
74     /* Special case - Used during initialization to produce a placeholder stateblock
75           so other functions called can update a state block                         */
76     if (Type == (D3DSTATEBLOCKTYPE) 0) {
77         /* Don't bother increasing the reference count otherwise a device will never
78            be freed due to circular dependencies                                   */
79         return D3D_OK;
80     }
81
82     /* Otherwise, might as well set the whole state block to the appropriate values */
83     IWineD3DDevice_AddRef(iface);
84     memcpy(object, This->stateBlock, sizeof(IWineD3DStateBlockImpl));
85     FIXME("unfinished - needs to set up changed and set attributes\n");
86     return D3D_OK;
87 }
88
89 /*****
90  * Get / Set FVF
91  *****/
92 HRESULT WINAPI IWineD3DDeviceImpl_SetFVF(IWineD3DDevice *iface, DWORD fvf) {
93     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
94
95     /* Update the current statte block */
96     This->updateStateBlock->fvf              = fvf;
97     This->updateStateBlock->changed.fvf      = TRUE;
98     This->updateStateBlock->set.fvf          = TRUE;
99
100     TRACE("(%p) : FVF Shader FVF set to %lx\n", This, fvf);
101     
102     /* No difference if recording or not */
103     return D3D_OK;
104 }
105 HRESULT WINAPI IWineD3DDeviceImpl_GetFVF(IWineD3DDevice *iface, DWORD *pfvf) {
106     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
107     TRACE("(%p) : GetFVF returning %lx\n", This, This->stateBlock->fvf);
108     *pfvf = This->stateBlock->fvf;
109     return D3D_OK;
110 }
111
112 /**********************************************************
113  * IUnknown parts follows
114  **********************************************************/
115
116 HRESULT WINAPI IWineD3DDeviceImpl_QueryInterface(IWineD3DDevice *iface,REFIID riid,LPVOID *ppobj)
117 {
118     return E_NOINTERFACE;
119 }
120
121 ULONG WINAPI IWineD3DDeviceImpl_AddRef(IWineD3DDevice *iface) {
122     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
123     TRACE("(%p) : AddRef increasing from %ld\n", This, This->ref);
124     return InterlockedIncrement(&This->ref);
125 }
126
127 ULONG WINAPI IWineD3DDeviceImpl_Release(IWineD3DDevice *iface) {
128     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
129     ULONG ref;
130     TRACE("(%p) : Releasing from %ld\n", This, This->ref);
131     ref = InterlockedDecrement(&This->ref);
132     if (ref == 0) {
133         IWineD3D_Release(This->WineD3D);
134         HeapFree(GetProcessHeap(), 0, This);
135     }
136     return ref;
137 }
138
139 /**********************************************************
140  * IWineD3DDevice VTbl follows
141  **********************************************************/
142
143 IWineD3DDeviceVtbl IWineD3DDevice_Vtbl =
144 {
145     IWineD3DDeviceImpl_QueryInterface,
146     IWineD3DDeviceImpl_AddRef,
147     IWineD3DDeviceImpl_Release,
148     IWineD3DDeviceImpl_CreateVertexBuffer,
149     IWineD3DDeviceImpl_CreateStateBlock,
150     IWineD3DDeviceImpl_SetFVF,
151     IWineD3DDeviceImpl_GetFVF
152 };