• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "Direct3DVolume9.hpp"
16 
17 #include "Direct3DDevice9.hpp"
18 #include "Direct3DResource9.hpp"
19 #include "Direct3DVolumeTexture9.hpp"
20 #include "Direct3DSurface9.hpp"
21 #include "Resource.hpp"
22 #include "Debug.hpp"
23 
24 #include <assert.h>
25 
26 namespace D3D9
27 {
isLockable(D3DPOOL pool,unsigned long usage)28 	bool isLockable(D3DPOOL pool, unsigned long usage)
29 	{
30 		return (pool != D3DPOOL_DEFAULT) || (usage & D3DUSAGE_DYNAMIC);
31 	}
32 
Direct3DVolume9(Direct3DDevice9 * device,Direct3DVolumeTexture9 * container,int width,int height,int depth,D3DFORMAT format,D3DPOOL pool,unsigned long usage)33 	Direct3DVolume9::Direct3DVolume9(Direct3DDevice9 *device, Direct3DVolumeTexture9 *container, int width, int height, int depth, D3DFORMAT format, D3DPOOL pool, unsigned long usage)
34 		: device(device), Surface(container->getResource(), width, height, depth, 0, 1, translateFormat(format), isLockable(pool, usage), false), container(container), width(width), height(height), depth(depth), format(format), pool(pool), lockable(isLockable(pool, usage)), usage(usage)
35 	{
36 		resource = new Direct3DResource9(device, D3DRTYPE_VOLUME, pool, memoryUsage(width, height, depth, format));
37 		resource->bind();
38 	}
39 
~Direct3DVolume9()40 	Direct3DVolume9::~Direct3DVolume9()
41 	{
42 		resource->unbind();
43 	}
44 
lockInternal(int x,int y,int z,sw::Lock lock,sw::Accessor client)45 	void *Direct3DVolume9::lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client)
46 	{
47 		return Surface::lockInternal(x, y, z, lock, client);
48 	}
49 
unlockInternal()50 	void Direct3DVolume9::unlockInternal()
51 	{
52 		Surface::unlockInternal();
53 	}
54 
QueryInterface(const IID & iid,void ** object)55 	long __stdcall Direct3DVolume9::QueryInterface(const IID &iid, void **object)
56 	{
57 		CriticalSection cs(device);
58 
59 		TRACE("");
60 
61 		if(iid == IID_IDirect3DVolume9 ||
62 		   iid == IID_IUnknown)
63 		{
64 			AddRef();
65 			*object = this;
66 
67 			return S_OK;
68 		}
69 
70 		*object = 0;
71 
72 		return NOINTERFACE(iid);
73 	}
74 
AddRef()75 	unsigned long __stdcall Direct3DVolume9::AddRef()
76 	{
77 		TRACE("");
78 
79 		return container->AddRef();
80 	}
81 
Release()82 	unsigned long __stdcall Direct3DVolume9::Release()
83 	{
84 		TRACE("");
85 
86 		return container->Release();
87 	}
88 
FreePrivateData(const GUID & guid)89 	long Direct3DVolume9::FreePrivateData(const GUID &guid)
90 	{
91 		CriticalSection cs(device);
92 
93 		TRACE("");
94 
95 		return resource->FreePrivateData(guid);
96 	}
97 
GetContainer(const IID & iid,void ** container)98 	long Direct3DVolume9::GetContainer(const IID &iid, void **container)
99 	{
100 		CriticalSection cs(device);
101 
102 		TRACE("");
103 
104 		if(!container)
105 		{
106 			return INVALIDCALL();
107 		}
108 
109 		long result = this->container->QueryInterface(iid, container);
110 
111 		if(result == S_OK)
112 		{
113 			return D3D_OK;
114 		}
115 
116 		return INVALIDCALL();
117 	}
118 
GetDesc(D3DVOLUME_DESC * description)119 	long Direct3DVolume9::GetDesc(D3DVOLUME_DESC *description)
120 	{
121 		CriticalSection cs(device);
122 
123 		TRACE("");
124 
125 		if(!description)
126 		{
127 			return INVALIDCALL();
128 		}
129 
130 		description->Format = format;
131 		description->Type = D3DRTYPE_VOLUME;
132 		description->Usage = usage;
133 		description->Pool = pool;
134 		description->Width = width;
135 		description->Height = height;
136 		description->Depth = depth;
137 
138 		return D3D_OK;
139 	}
140 
GetDevice(IDirect3DDevice9 ** device)141 	long Direct3DVolume9::GetDevice(IDirect3DDevice9 **device)
142 	{
143 		CriticalSection cs(this->device);
144 
145 		TRACE("");
146 
147 		return resource->GetDevice(device);
148 	}
149 
GetPrivateData(const GUID & guid,void * data,unsigned long * size)150 	long Direct3DVolume9::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
151 	{
152 		CriticalSection cs(device);
153 
154 		TRACE("");
155 
156 		return resource->GetPrivateData(guid, data, size);
157 	}
158 
LockBox(D3DLOCKED_BOX * lockedVolume,const D3DBOX * box,unsigned long flags)159 	long Direct3DVolume9::LockBox(D3DLOCKED_BOX *lockedVolume, const D3DBOX *box, unsigned long flags)
160 	{
161 		CriticalSection cs(device);
162 
163 		TRACE("");
164 
165 		if(!lockedVolume)
166 		{
167 			return INVALIDCALL();
168 		}
169 
170 		lockedVolume->RowPitch = 0;
171 		lockedVolume->SlicePitch = 0;
172 		lockedVolume->pBits = 0;
173 
174 		if(!lockable)
175 		{
176 			return INVALIDCALL();
177 		}
178 
179 		lockedVolume->RowPitch = getExternalPitchB();
180 		lockedVolume->SlicePitch = getExternalSliceB();
181 
182 		sw::Lock lock = sw::LOCK_READWRITE;
183 
184 		if(flags & D3DLOCK_DISCARD)
185 		{
186 			lock = sw::LOCK_DISCARD;
187 		}
188 
189 		if(flags & D3DLOCK_READONLY)
190 		{
191 			lock = sw::LOCK_READONLY;
192 		}
193 
194 		if(box)
195 		{
196 			lockedVolume->pBits = lockExternal(box->Left, box->Top, box->Front, lock, sw::PUBLIC);
197 		}
198 		else
199 		{
200 			lockedVolume->pBits = lockExternal(0, 0, 0, lock, sw::PUBLIC);
201 		}
202 
203 		return D3D_OK;
204 	}
205 
SetPrivateData(const GUID & guid,const void * data,unsigned long size,unsigned long flags)206 	long Direct3DVolume9::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
207 	{
208 		CriticalSection cs(device);
209 
210 		TRACE("");
211 
212 		return resource->SetPrivateData(guid, data, size, flags);
213 	}
214 
UnlockBox()215 	long Direct3DVolume9::UnlockBox()
216 	{
217 		CriticalSection cs(device);
218 
219 		TRACE("");
220 
221 		unlockExternal();
222 
223 		return D3D_OK;
224 	}
225 
translateFormat(D3DFORMAT format)226 	sw::Format Direct3DVolume9::translateFormat(D3DFORMAT format)
227 	{
228 		return Direct3DSurface9::translateFormat(format);
229 	}
230 
memoryUsage(int width,int height,int depth,D3DFORMAT format)231 	unsigned int Direct3DVolume9::memoryUsage(int width, int height, int depth, D3DFORMAT format)
232 	{
233 		return Surface::size(width, height, depth, 0, 1, translateFormat(format));
234 	}
235 }
236