blob: 0ecaed254217ad23c54af84a9043cba3c40cbd4e [file] [log] [blame]
José Fonsecaff0b1ee2012-10-25 12:17:39 +01001##########################################################################
2#
3# Copyright 2008-2009 VMware, Inc.
4# All Rights Reserved.
5#
6# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to deal
8# in the Software without restriction, including without limitation the rights
9# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10# copies of the Software, and to permit persons to whom the Software is
11# furnished to do so, subject to the following conditions:
12#
13# The above copyright notice and this permission notice shall be included in
14# all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22# THE SOFTWARE.
23#
24##########################################################################/
25
26
José Fonseca20aa9352012-11-23 14:34:29 +000027import sys
José Fonsecaff0b1ee2012-10-25 12:17:39 +010028from dlltrace import DllTracer
29from specs import stdapi
José Fonseca20aa9352012-11-23 14:34:29 +000030from specs.stdapi import API
31from specs.dxgi import dxgi
32from specs.d3d10 import d3d10
33from specs.d3d10_1 import d3d10_1
34from specs.d3d11 import d3d11
José Fonsecaff0b1ee2012-10-25 12:17:39 +010035
36
37class D3DCommonTracer(DllTracer):
38
39 def serializeArgValue(self, function, arg):
40 # Dump shaders as strings
41 if isinstance(arg.type, stdapi.Blob) and arg.name.startswith('pShaderBytecode'):
42 print ' DumpShader(trace::localWriter, %s, %s);' % (arg.name, arg.type.size)
43 return
44
José Fonseca419d7682013-02-22 10:24:31 +000045 # Serialize the swapchain dimensions
José Fonseca2b6d24e2013-02-22 15:00:26 +000046 if function.name == 'CreateSwapChain' and arg.name == 'pDesc' \
47 or arg.name == 'pSwapChainDesc':
48 print r' DXGI_SWAP_CHAIN_DESC *_pSwapChainDesc = NULL;'
49 print r' DXGI_SWAP_CHAIN_DESC _SwapChainDesc;'
50 print r' if (%s) {' % arg.name
51 print r' _SwapChainDesc = *%s;' % arg.name
52 if function.name != 'CreateSwapChain' or not self.interface.name.endswith('DWM'):
José Fonseca419d7682013-02-22 10:24:31 +000053 # Obtain size from the window
54 print r' RECT _rect;'
José Fonseca2b6d24e2013-02-22 15:00:26 +000055 print r' if (GetClientRect(%s->OutputWindow, &_rect)) {' % arg.name
56 print r' if (%s->BufferDesc.Width == 0) {' % arg.name
57 print r' _SwapChainDesc.BufferDesc.Width = _rect.right - _rect.left;'
José Fonseca419d7682013-02-22 10:24:31 +000058 print r' }'
José Fonseca2b6d24e2013-02-22 15:00:26 +000059 print r' if (%s->BufferDesc.Height == 0) {' % arg.name
60 print r' _SwapChainDesc.BufferDesc.Height = _rect.bottom - _rect.top;'
José Fonseca419d7682013-02-22 10:24:31 +000061 print r' }'
62 print r' }'
63 else:
64 # Obtain size from the output
65 print r' DXGI_OUTPUT_DESC _OutputDesc;'
66 print r' if (SUCCEEDED(pOutput->GetDesc(&_OutputDesc))) {'
José Fonseca2b6d24e2013-02-22 15:00:26 +000067 print r' _SwapChainDesc.BufferDesc.Width = _OutputDesc.DesktopCoordinates.right - _OutputDesc.DesktopCoordinates.left;'
68 print r' _SwapChainDesc.BufferDesc.Height = _OutputDesc.DesktopCoordinates.bottom - _OutputDesc.DesktopCoordinates.top;'
José Fonseca419d7682013-02-22 10:24:31 +000069 print r' }'
José Fonseca2b6d24e2013-02-22 15:00:26 +000070 print r' _pSwapChainDesc = &_SwapChainDesc;'
José Fonseca419d7682013-02-22 10:24:31 +000071 print r' }'
José Fonseca2b6d24e2013-02-22 15:00:26 +000072 self.serializeValue(arg.type, '_pSwapChainDesc')
José Fonseca419d7682013-02-22 10:24:31 +000073 return
74
José Fonsecaff0b1ee2012-10-25 12:17:39 +010075 DllTracer.serializeArgValue(self, function, arg)
José Fonseca0168b512012-11-03 18:44:36 +000076
77 def enumWrapperInterfaceVariables(self, interface):
78 variables = DllTracer.enumWrapperInterfaceVariables(self, interface)
79
80 # Add additional members to track maps
81 if interface.getMethodByName('Map') is not None:
82 variables += [
83 ('VOID *', '_pMappedData', '0'),
84 ('size_t', '_MappedSize', '0'),
85 ]
86
87 return variables
88
89 def implementWrapperInterfaceMethodBody(self, interface, base, method):
90 if method.name == 'Unmap':
91 print ' if (_MappedSize && _pMappedData) {'
92 self.emit_memcpy('_pMappedData', '_pMappedData', '_MappedSize')
93 print ' }'
94
95 DllTracer.implementWrapperInterfaceMethodBody(self, interface, base, method)
96
97 if method.name == 'Map':
98 # NOTE: recursive locks are explicitely forbidden
99 print ' if (SUCCEEDED(_result)) {'
100 print ' _getMapInfo(_this, %s, _pMappedData, _MappedSize);' % ', '.join(method.argNames())
101 print ' } else {'
102 print ' _pMappedData = NULL;'
103 print ' _MappedSize = 0;'
104 print ' }'
105
106
José Fonseca20aa9352012-11-23 14:34:29 +0000107if __name__ == '__main__':
108 print '#define INITGUID'
109 print
110 print '#include "trace_writer_local.hpp"'
111 print '#include "os.hpp"'
112 print
113 print '#include "d3dcommonshader.hpp"'
114 print
115
116 moduleNames = sys.argv[1:]
117
118 api = API()
119
120 if moduleNames:
121 api.addModule(dxgi)
122
123 if 'd3d10' in moduleNames:
124 if 'd3d10_1' in moduleNames:
125 print r'#include "d3d10_1imports.hpp"'
José Fonseca20aa9352012-11-23 14:34:29 +0000126 api.addModule(d3d10_1)
127 else:
128 print r'#include "d3d10imports.hpp"'
129 print r'#include "d3d10size.hpp"'
130 api.addModule(d3d10)
131
132 if 'd3d11' in moduleNames:
133 print r'#include "d3d11imports.hpp"'
134 if 'd3d11_1' in moduleNames:
135 print '#include <d3d11_1.h>'
136 import specs.d3d11_1
137 print r'#include "d3d11size.hpp"'
138 api.addModule(d3d11)
139
140 tracer = D3DCommonTracer()
141 tracer.traceApi(api)