blob: c1cadb67e49b10d39d6619992d6fb6acceb73977 [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é Fonseca112a1322012-04-27 17:15:32 +010028from specs.d3d9 import d3d9, D3DSHADER9
José Fonseca4106eb42011-09-21 08:12:39 +010029
José Fonseca12ac4282012-07-25 20:47:20 +010030import specs.d3d9dxva2
31
José Fonseca4106eb42011-09-21 08:12:39 +010032
33class D3D9Tracer(DllTracer):
34
José Fonseca54f304a2012-01-14 19:33:08 +000035 def serializeArgValue(self, function, arg):
José Fonseca4106eb42011-09-21 08:12:39 +010036 # Dump shaders as strings
José Fonseca112a1322012-04-27 17:15:32 +010037 if arg.type is D3DSHADER9:
José Fonsecab4a3d142011-10-27 07:43:19 +010038 print ' DumpShader(trace::localWriter, %s);' % (arg.name)
José Fonseca4106eb42011-09-21 08:12:39 +010039 return
40
José Fonseca54f304a2012-01-14 19:33:08 +000041 DllTracer.serializeArgValue(self, function, arg)
José Fonseca4106eb42011-09-21 08:12:39 +010042
José Fonsecaacc90622012-05-02 13:10:07 +010043 def enumWrapperInterfaceVariables(self, interface):
44 variables = DllTracer.enumWrapperInterfaceVariables(self, interface)
José Fonseca0423d2c2012-01-20 19:16:17 +000045
José Fonseca3dfd4572012-11-03 16:58:34 +000046 # Add additional members to track locks
José Fonseca6d5372b2012-04-30 23:33:02 +010047 if interface.getMethodByName('Lock') is not None or \
José Fonseca93fa73a2012-05-01 22:28:28 +010048 interface.getMethodByName('LockRect') is not None or \
49 interface.getMethodByName('LockBox') is not None:
José Fonsecaacc90622012-05-02 13:10:07 +010050 variables += [
José Fonseca2b4fc3f2012-11-11 00:39:53 +000051 ('size_t', '_MappedSize', '0'),
José Fonsecaacc90622012-05-02 13:10:07 +010052 ('VOID *', 'm_pbData', '0'),
53 ]
José Fonseca0423d2c2012-01-20 19:16:17 +000054
José Fonsecaacc90622012-05-02 13:10:07 +010055 return variables
José Fonsecad275d0a2012-04-30 23:18:05 +010056
José Fonseca4220b1b2012-02-03 19:05:29 +000057 def implementWrapperInterfaceMethodBody(self, interface, base, method):
José Fonseca93fa73a2012-05-01 22:28:28 +010058 if method.name in ('Unlock', 'UnlockRect', 'UnlockBox'):
José Fonseca2b4fc3f2012-11-11 00:39:53 +000059 print ' if (_MappedSize && m_pbData) {'
60 self.emit_memcpy('(LPBYTE)m_pbData', '(LPBYTE)m_pbData', '_MappedSize')
José Fonseca0423d2c2012-01-20 19:16:17 +000061 print ' }'
62
José Fonseca4220b1b2012-02-03 19:05:29 +000063 DllTracer.implementWrapperInterfaceMethodBody(self, interface, base, method)
José Fonseca0423d2c2012-01-20 19:16:17 +000064
José Fonseca6c77bd02012-05-02 13:15:39 +010065 if method.name in ('Lock', 'LockRect', 'LockBox'):
José Fonseca945dff12012-05-08 23:23:38 +010066 # FIXME: handle recursive locks
José Fonsecad275d0a2012-04-30 23:18:05 +010067 print ' if (SUCCEEDED(_result) && !(Flags & D3DLOCK_READONLY)) {'
José Fonseca2b4fc3f2012-11-11 00:39:53 +000068 print ' _getMapInfo(_this, %s, m_pbData, _MappedSize);' % ', '.join(method.argNames()[:-1])
José Fonseca0423d2c2012-01-20 19:16:17 +000069 print ' } else {'
70 print ' m_pbData = NULL;'
José Fonseca2b4fc3f2012-11-11 00:39:53 +000071 print ' _MappedSize = 0;'
José Fonseca0423d2c2012-01-20 19:16:17 +000072 print ' }'
73
José Fonseca4106eb42011-09-21 08:12:39 +010074
75if __name__ == '__main__':
José Fonsecaccf250c2012-02-03 19:06:31 +000076 print '#define INITGUID'
77 print
José Fonsecaa0e612d2011-12-27 19:02:57 +000078 print '#include "trace_writer_local.hpp"'
José Fonseca4106eb42011-09-21 08:12:39 +010079 print '#include "os.hpp"'
80 print
81 print '#include "d3d9imports.hpp"'
José Fonseca3dfd4572012-11-03 16:58:34 +000082 print '#include "d3d9size.hpp"'
José Fonseca41a6d892012-05-13 11:41:08 +010083 print '#include "d3d9shader.hpp"'
José Fonseca12ac4282012-07-25 20:47:20 +010084 print '#include "dxvaint.h"'
José Fonseca4106eb42011-09-21 08:12:39 +010085 print
José Fonsecaf5417542011-10-28 00:15:09 +010086 print '''
87static inline size_t
88_declCount(const D3DVERTEXELEMENT9 *pVertexElements) {
89 size_t count = 0;
90 if (pVertexElements) {
91 while (pVertexElements[count++].Stream != 0xff)
92 ;
93 }
94 return count;
95}
96'''
José Fonseca4106eb42011-09-21 08:12:39 +010097 tracer = D3D9Tracer('d3d9.dll')
José Fonseca81301932012-11-11 00:10:20 +000098 tracer.traceModule(d3d9)
José Fonseca4106eb42011-09-21 08:12:39 +010099