blob: 2a4c1a93d824503164d15e36b0796a7c105cec59 [file] [log] [blame]
José Fonseca4106eb42011-09-21 08:12: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é Fonseca54f304a2012-01-14 19:33:08 +000027from dlltrace import DllTracer
José Fonseca72fb9ca2012-11-13 08:21:15 +000028from specs.stdapi import API
José Fonseca112a1322012-04-27 17:15:32 +010029from specs.d3d9 import d3d9, D3DSHADER9
José Fonseca4106eb42011-09-21 08:12:39 +010030
José Fonseca12ac4282012-07-25 20:47:20 +010031import specs.d3d9dxva2
32
José Fonseca4106eb42011-09-21 08:12:39 +010033
34class D3D9Tracer(DllTracer):
35
José Fonseca54f304a2012-01-14 19:33:08 +000036 def serializeArgValue(self, function, arg):
José Fonseca4106eb42011-09-21 08:12:39 +010037 # Dump shaders as strings
José Fonseca112a1322012-04-27 17:15:32 +010038 if arg.type is D3DSHADER9:
José Fonsecab4a3d142011-10-27 07:43:19 +010039 print ' DumpShader(trace::localWriter, %s);' % (arg.name)
José Fonseca4106eb42011-09-21 08:12:39 +010040 return
41
José Fonseca54f304a2012-01-14 19:33:08 +000042 DllTracer.serializeArgValue(self, function, arg)
José Fonseca4106eb42011-09-21 08:12:39 +010043
José Fonsecaacc90622012-05-02 13:10:07 +010044 def enumWrapperInterfaceVariables(self, interface):
45 variables = DllTracer.enumWrapperInterfaceVariables(self, interface)
José Fonseca0423d2c2012-01-20 19:16:17 +000046
José Fonseca3dfd4572012-11-03 16:58:34 +000047 # Add additional members to track locks
José Fonseca6d5372b2012-04-30 23:33:02 +010048 if interface.getMethodByName('Lock') is not None or \
José Fonseca93fa73a2012-05-01 22:28:28 +010049 interface.getMethodByName('LockRect') is not None or \
50 interface.getMethodByName('LockBox') is not None:
José Fonsecaacc90622012-05-02 13:10:07 +010051 variables += [
José Fonseca2b4fc3f2012-11-11 00:39:53 +000052 ('size_t', '_MappedSize', '0'),
José Fonsecaacc90622012-05-02 13:10:07 +010053 ('VOID *', 'm_pbData', '0'),
54 ]
José Fonseca0423d2c2012-01-20 19:16:17 +000055
José Fonsecaacc90622012-05-02 13:10:07 +010056 return variables
José Fonsecad275d0a2012-04-30 23:18:05 +010057
José Fonseca4220b1b2012-02-03 19:05:29 +000058 def implementWrapperInterfaceMethodBody(self, interface, base, method):
José Fonseca93fa73a2012-05-01 22:28:28 +010059 if method.name in ('Unlock', 'UnlockRect', 'UnlockBox'):
José Fonseca2b4fc3f2012-11-11 00:39:53 +000060 print ' if (_MappedSize && m_pbData) {'
61 self.emit_memcpy('(LPBYTE)m_pbData', '(LPBYTE)m_pbData', '_MappedSize')
José Fonseca0423d2c2012-01-20 19:16:17 +000062 print ' }'
63
José Fonseca4220b1b2012-02-03 19:05:29 +000064 DllTracer.implementWrapperInterfaceMethodBody(self, interface, base, method)
José Fonseca0423d2c2012-01-20 19:16:17 +000065
José Fonseca6c77bd02012-05-02 13:15:39 +010066 if method.name in ('Lock', 'LockRect', 'LockBox'):
José Fonseca945dff12012-05-08 23:23:38 +010067 # FIXME: handle recursive locks
José Fonsecad275d0a2012-04-30 23:18:05 +010068 print ' if (SUCCEEDED(_result) && !(Flags & D3DLOCK_READONLY)) {'
José Fonseca2b4fc3f2012-11-11 00:39:53 +000069 print ' _getMapInfo(_this, %s, m_pbData, _MappedSize);' % ', '.join(method.argNames()[:-1])
José Fonseca0423d2c2012-01-20 19:16:17 +000070 print ' } else {'
71 print ' m_pbData = NULL;'
José Fonseca2b4fc3f2012-11-11 00:39:53 +000072 print ' _MappedSize = 0;'
José Fonseca0423d2c2012-01-20 19:16:17 +000073 print ' }'
74
José Fonseca4106eb42011-09-21 08:12:39 +010075
76if __name__ == '__main__':
José Fonsecaccf250c2012-02-03 19:06:31 +000077 print '#define INITGUID'
78 print
José Fonsecaa0e612d2011-12-27 19:02:57 +000079 print '#include "trace_writer_local.hpp"'
José Fonseca4106eb42011-09-21 08:12:39 +010080 print '#include "os.hpp"'
81 print
82 print '#include "d3d9imports.hpp"'
José Fonseca3dfd4572012-11-03 16:58:34 +000083 print '#include "d3d9size.hpp"'
José Fonseca41a6d892012-05-13 11:41:08 +010084 print '#include "d3d9shader.hpp"'
José Fonseca12ac4282012-07-25 20:47:20 +010085 print '#include "dxvaint.h"'
José Fonseca4106eb42011-09-21 08:12:39 +010086 print
José Fonsecaf5417542011-10-28 00:15:09 +010087 print '''
88static inline size_t
89_declCount(const D3DVERTEXELEMENT9 *pVertexElements) {
90 size_t count = 0;
91 if (pVertexElements) {
92 while (pVertexElements[count++].Stream != 0xff)
93 ;
94 }
95 return count;
96}
97'''
José Fonseca4106eb42011-09-21 08:12:39 +010098
José Fonseca72fb9ca2012-11-13 08:21:15 +000099 api = API()
100 api.addModule(d3d9)
101 tracer = D3D9Tracer()
102 tracer.traceApi(api)