]> git.cworth.org Git - apitrace/blob - helpers/d3d9size.hpp
Use skiplist-based FastCallSet within trace::CallSet
[apitrace] / helpers / d3d9size.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 _D3D9SIZE_HPP_
34 #define _D3D9SIZE_HPP_
35
36
37 #include "d3dcommonsize.hpp"
38
39
40 static inline size_t
41 _declCount(const D3DVERTEXELEMENT9 *pVertexElements) {
42     size_t count = 0;
43     if (pVertexElements) {
44         while (pVertexElements[count++].Stream != 0xff)
45             ;
46     }
47     return count;
48 }
49
50 static inline void
51 _getMapInfo(IDirect3DVertexBuffer9 *pBuffer, UINT OffsetToLock, UINT SizeToLock, void ** ppbData,
52              void * & pLockedData, size_t & MappedSize) {
53     pLockedData = *ppbData;
54     MappedSize = 0;
55
56     if (SizeToLock == 0) {
57         D3DVERTEXBUFFER_DESC Desc;
58         HRESULT hr = pBuffer->GetDesc(&Desc);
59         if (FAILED(hr)) {
60             return;
61         }
62         MappedSize = Desc.Size;
63     } else {
64         MappedSize = SizeToLock;
65     }
66 }
67
68
69 static inline void
70 _getMapInfo(IDirect3DIndexBuffer9 *pBuffer, UINT OffsetToLock, UINT SizeToLock, void ** ppbData,
71              void * & pLockedData, size_t & MappedSize) {
72     pLockedData = *ppbData;
73     MappedSize = 0;
74
75     if (SizeToLock == 0) {
76         D3DINDEXBUFFER_DESC Desc;
77         HRESULT hr = pBuffer->GetDesc(&Desc);
78         if (FAILED(hr)) {
79             return;
80         }
81         MappedSize = Desc.Size;
82     } else {
83         MappedSize = SizeToLock;
84     }
85 }
86
87
88 static inline void
89 _getMapInfo(IDirect3DSurface9 *pSurface, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect,
90              void * & pLockedData, size_t & MappedSize) {
91     pLockedData = pLockedRect->pBits;
92     MappedSize = 0;
93
94     HRESULT hr;
95
96     D3DSURFACE_DESC Desc;
97     hr = pSurface->GetDesc(&Desc);
98     if (FAILED(hr)) {
99         return;
100     }
101
102     UINT Width;
103     UINT Height;
104     if (pRect) {
105         Width  = pRect->right  - pRect->left;
106         Height = pRect->bottom - pRect->top;
107     } else {
108         Width  = Desc.Width;
109         Height = Desc.Height;
110     }
111
112     MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
113 }
114
115
116 static inline void
117 _getMapInfo(IDirect3DTexture9 *pTexture, UINT Level, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect,
118              void * & pLockedData, size_t & MappedSize) {
119     pLockedData = pLockedRect->pBits;
120     MappedSize = 0;
121
122     HRESULT hr;
123
124     D3DSURFACE_DESC Desc;
125     hr = pTexture->GetLevelDesc(Level, &Desc);
126     if (FAILED(hr)) {
127         return;
128     }
129
130     UINT Width;
131     UINT Height;
132     if (pRect) {
133         Width  = pRect->right  - pRect->left;
134         Height = pRect->bottom - pRect->top;
135     } else {
136         Width  = Desc.Width;
137         Height = Desc.Height;
138     }
139
140     MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
141 }
142
143
144 static inline void
145 _getMapInfo(IDirect3DCubeTexture9 *pTexture, D3DCUBEMAP_FACES FaceType, UINT Level, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect,
146              void * & pLockedData, size_t & MappedSize) {
147     pLockedData = pLockedRect->pBits;
148     MappedSize = 0;
149
150     HRESULT hr;
151
152     (void)FaceType;
153
154     D3DSURFACE_DESC Desc;
155     hr = pTexture->GetLevelDesc(Level, &Desc);
156     if (FAILED(hr)) {
157         return;
158     }
159
160     UINT Width;
161     UINT Height;
162     if (pRect) {
163         Width  = pRect->right  - pRect->left;
164         Height = pRect->bottom - pRect->top;
165     } else {
166         Width  = Desc.Width;
167         Height = Desc.Height;
168     }
169
170     MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
171 }
172
173
174 static inline void
175 _getMapInfo(IDirect3DVolume9 *pVolume, const D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox,
176              void * & pLockedData, size_t & MappedSize) {
177     pLockedData = pLockedVolume->pBits;
178     MappedSize = 0;
179
180     HRESULT hr;
181
182     D3DVOLUME_DESC Desc;
183     hr = pVolume->GetDesc(&Desc);
184     if (FAILED(hr)) {
185         return;
186     }
187
188     UINT Width;
189     UINT Height;
190     UINT Depth;
191     if (pBox) {
192         Width  = pBox->Right  - pBox->Left;
193         Height = pBox->Bottom - pBox->Top;
194         Depth  = pBox->Back   - pBox->Front;
195     } else {
196         Width  = Desc.Width;
197         Height = Desc.Height;
198         Depth  = Desc.Depth;
199     }
200
201     MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedVolume->RowPitch, Depth, pLockedVolume->SlicePitch);
202 }
203
204
205 static inline void
206 _getMapInfo(IDirect3DVolumeTexture9 *pTexture, UINT Level, const D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox,
207              void * & pLockedData, size_t & MappedSize) {
208     pLockedData = pLockedVolume->pBits;
209     MappedSize = 0;
210
211     HRESULT hr;
212
213     D3DVOLUME_DESC Desc;
214     hr = pTexture->GetLevelDesc(Level, &Desc);
215     if (FAILED(hr)) {
216         return;
217     }
218
219     UINT Width;
220     UINT Height;
221     UINT Depth;
222     if (pBox) {
223         Width  = pBox->Right  - pBox->Left;
224         Height = pBox->Bottom - pBox->Top;
225         Depth  = pBox->Back   - pBox->Front;
226     } else {
227         Width  = Desc.Width;
228         Height = Desc.Height;
229         Depth  = Desc.Depth;
230     }
231
232     MappedSize = _getLockSize(Desc.Format, Width, Height, pLockedVolume->RowPitch, Depth, pLockedVolume->SlicePitch);
233 }
234
235
236 #endif /* _D3D9SIZE_HPP_ */