]> git.cworth.org Git - apitrace/blob - helpers/d3d8size.hpp
Use skiplist-based FastCallSet within trace::CallSet
[apitrace] / helpers / d3d8size.hpp
1 /**************************************************************************
2  *
3  * Copyright 2012 Jose Fonseca
4  * All Rights Reserved.
5  * 
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sub license,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  * 
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  * 
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
20  * AUTHORS,
21  * AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  *
26  **************************************************************************/
27
28
29 /*
30  * Auxiliary functions to compute the size of array/blob arguments.
31  */
32
33 #ifndef _D3D8SIZE_HPP_
34 #define _D3D8SIZE_HPP_
35
36
37 #include "d3dcommonsize.hpp"
38
39
40 static inline size_t
41 _declCount(const DWORD *pDeclaration) {
42     size_t count = 0;
43     while (pDeclaration[count++] != D3DVSD_END())
44         ;
45     return count;
46 }
47
48
49 static inline void
50 _getMapInfo(IDirect3DVertexBuffer8 *pBuffer, UINT OffsetToLock, UINT SizeToLock, BYTE ** ppbData,
51              void * & pLockedData, size_t & MappedSize) {
52     pLockedData = *ppbData;
53     MappedSize = 0;
54
55     if (SizeToLock == 0) {
56         D3DVERTEXBUFFER_DESC Desc;
57         HRESULT hr = pBuffer->GetDesc(&Desc);
58         if (FAILED(hr)) {
59             return;
60         }
61         MappedSize = Desc.Size;
62     } else {
63         MappedSize = SizeToLock;
64     }
65 }
66
67
68 static inline void
69 _getMapInfo(IDirect3DIndexBuffer8 *pBuffer, UINT OffsetToLock, UINT SizeToLock, BYTE ** ppbData,
70              void * & pLockedData, size_t & MappedSize) {
71     pLockedData = *ppbData;
72     MappedSize = 0;
73
74     if (SizeToLock == 0) {
75         D3DINDEXBUFFER_DESC Desc;
76         HRESULT hr = pBuffer->GetDesc(&Desc);
77         if (FAILED(hr)) {
78             return;
79         }
80         MappedSize = Desc.Size;
81     } else {
82         MappedSize = SizeToLock;
83     }
84 }
85
86
87 static inline void
88 _getMapInfo(IDirect3DSurface8 *pSurface, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect,
89              void * & pLockedData, size_t & MappedSize) {
90     pLockedData = pLockedRect->pBits;
91     MappedSize = 0;
92
93     HRESULT hr;
94
95     D3DSURFACE_DESC Desc;
96     hr = pSurface->GetDesc(&Desc);
97     if (FAILED(hr)) {
98         return;
99     }
100
101     UINT Width;
102     UINT Height;
103     if (pRect) {
104         Width  = pRect->right  - pRect->left;
105         Height = pRect->bottom - pRect->top;
106     } else {
107         Width  = Desc.Width;
108         Height = Desc.Height;
109     }
110
111     MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
112 }
113
114
115 static inline void
116 _getMapInfo(IDirect3DTexture8 *pTexture, UINT Level, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect,
117              void * & pLockedData, size_t & MappedSize) {
118     pLockedData = pLockedRect->pBits;
119     MappedSize = 0;
120
121     HRESULT hr;
122
123     D3DSURFACE_DESC Desc;
124     hr = pTexture->GetLevelDesc(Level, &Desc);
125     if (FAILED(hr)) {
126         return;
127     }
128
129     UINT Width;
130     UINT Height;
131     if (pRect) {
132         Width  = pRect->right  - pRect->left;
133         Height = pRect->bottom - pRect->top;
134     } else {
135         Width  = Desc.Width;
136         Height = Desc.Height;
137     }
138
139     MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
140 }
141
142
143 static inline void
144 _getMapInfo(IDirect3DCubeTexture8 *pTexture, D3DCUBEMAP_FACES FaceType, UINT Level, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect,
145              void * & pLockedData, size_t & MappedSize) {
146     pLockedData = pLockedRect->pBits;
147     MappedSize = 0;
148
149     HRESULT hr;
150
151     (void)FaceType;
152
153     D3DSURFACE_DESC Desc;
154     hr = pTexture->GetLevelDesc(Level, &Desc);
155     if (FAILED(hr)) {
156         return;
157     }
158
159     UINT Width;
160     UINT Height;
161     if (pRect) {
162         Width  = pRect->right  - pRect->left;
163         Height = pRect->bottom - pRect->top;
164     } else {
165         Width  = Desc.Width;
166         Height = Desc.Height;
167     }
168
169     MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
170 }
171
172
173 static inline void
174 _getMapInfo(IDirect3DVolume8 *pVolume, const D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox,
175              void * & pLockedData, size_t & MappedSize) {
176     pLockedData = pLockedVolume->pBits;
177     MappedSize = 0;
178
179     HRESULT hr;
180
181     D3DVOLUME_DESC Desc;
182     hr = pVolume->GetDesc(&Desc);
183     if (FAILED(hr)) {
184         return;
185     }
186
187     UINT Width;
188     UINT Height;
189     UINT Depth;
190     if (pBox) {
191         Width  = pBox->Right  - pBox->Left;
192         Height = pBox->Bottom - pBox->Top;
193         Depth  = pBox->Back   - pBox->Front;
194     } else {
195         Width  = Desc.Width;
196         Height = Desc.Height;
197         Depth  = Desc.Depth;
198     }
199
200     MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedVolume->RowPitch, Depth, pLockedVolume->SlicePitch);
201 }
202
203
204 static inline void
205 _getMapInfo(IDirect3DVolumeTexture8 *pTexture, UINT Level, const D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox,
206              void * & pLockedData, size_t & MappedSize) {
207     pLockedData = pLockedVolume->pBits;
208     MappedSize = 0;
209
210     HRESULT hr;
211
212     D3DVOLUME_DESC Desc;
213     hr = pTexture->GetLevelDesc(Level, &Desc);
214     if (FAILED(hr)) {
215         return;
216     }
217
218     UINT Width;
219     UINT Height;
220     UINT Depth;
221     if (pBox) {
222         Width  = pBox->Right  - pBox->Left;
223         Height = pBox->Bottom - pBox->Top;
224         Depth  = pBox->Back   - pBox->Front;
225     } else {
226         Width  = Desc.Width;
227         Height = Desc.Height;
228         Depth  = Desc.Depth;
229     }
230
231     MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedVolume->RowPitch, Depth, pLockedVolume->SlicePitch);
232 }
233
234
235 #endif /* _D3D8SIZE_HPP_ */