]> git.cworth.org Git - apitrace/commitdiff
Merge branch 'master' into d2d
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 7 Nov 2012 07:20:06 +0000 (07:20 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 7 Nov 2012 07:20:06 +0000 (07:20 +0000)
1  2 
wrappers/.gitignore
wrappers/CMakeLists.txt
wrappers/trace.py

diff --combined wrappers/.gitignore
index 38fd57f7c4b28767e7889bd76e8d8ee1ddec0cff,eeacd9f1a0e8dcfa1217a5f1dc123acde6b20302..cc5f074b65f5017f7ec6a52e5d9304c5d3c128a6
@@@ -1,5 -1,5 +1,6 @@@
+ OpenGL
  cgltrace.cpp
 +d2d1trace.cpp
  d3d10_1trace.cpp
  d3d10trace.cpp
  d3d11trace.cpp
@@@ -7,7 -7,6 +8,7 @@@ d3d8trace.cp
  d3d9trace.cpp
  ddrawtrace.cpp
  dlltrace.cpp
 +dwritetrace.cpp
  egltrace.cpp
  gltrace.cpp
  glxtrace.cpp
diff --combined wrappers/CMakeLists.txt
index cc817d51399f0262896b0ceac2ba2b5ef0721c9c,6fa615c5bc07e173db9a9f4bba63281c7c0b621b..01cbdea4ac42af18c4d86d8cf011414b019bcb55
@@@ -101,6 -101,7 +101,7 @@@ if (WIN32
                  ${CMAKE_SOURCE_DIR}/specs/d3d9.py
                  ${CMAKE_SOURCE_DIR}/specs/d3d9types.py
                  ${CMAKE_SOURCE_DIR}/specs/d3d9caps.py
+                 ${CMAKE_SOURCE_DIR}/specs/d3d9dxva2.py
                  ${CMAKE_SOURCE_DIR}/specs/winapi.py
                  ${CMAKE_SOURCE_DIR}/specs/stdapi.py
          )
              COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10trace.cpp
              DEPENDS
                  d3d10trace.py
+                 d3dcommontrace.py
                  dlltrace.py
                  trace.py
                  ${CMAKE_SOURCE_DIR}/dispatch/dispatch.py
              COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10_1trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10_1trace.cpp
              DEPENDS
                  d3d10_1trace.py
+                 d3dcommontrace.py
                  dlltrace.py
                  trace.py
                  ${CMAKE_SOURCE_DIR}/dispatch/dispatch.py
                  ${CMAKE_SOURCE_DIR}/specs/winapi.py
                  ${CMAKE_SOURCE_DIR}/specs/stdapi.py
          )
-         add_library (d3d10_1trace MODULE d3d10_1.def d3d10_1trace.cpp)
+         add_library (d3d10_1trace MODULE d3d10_1.def d3d10_1trace.cpp d3d10shader.cpp)
          target_link_libraries (d3d10_1trace
              common_trace
              common
          install (TARGETS d3d11trace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
      endif ()
  
 +    # d2d1.dll, dwrite.dll
 +    if (DirectX_D2D1_INCLUDE_DIR)
 +        include_directories (SYSTEM ${DirectX_D2D1_INCLUDE_DIR})
 +
 +        add_custom_command (
 +            OUTPUT d2d1trace.cpp
 +            COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d2d1trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d2d1trace.cpp
 +            DEPENDS
 +                d2d1trace.py
 +                trace.py
 +                ${CMAKE_SOURCE_DIR}/specs/d2d1.py
 +                ${CMAKE_SOURCE_DIR}/specs/d2d1.py
 +                ${CMAKE_SOURCE_DIR}/specs/d2dbasetypes.py
 +                ${CMAKE_SOURCE_DIR}/specs/d2derr.py
 +                ${CMAKE_SOURCE_DIR}/specs/dwrite.py
 +                ${CMAKE_SOURCE_DIR}/specs/dcommon.py
 +                ${CMAKE_SOURCE_DIR}/specs/dxgi.py
 +                ${CMAKE_SOURCE_DIR}/specs/dxgitype.py
 +                ${CMAKE_SOURCE_DIR}/specs/dxgiformat.py
 +                ${CMAKE_SOURCE_DIR}/specs/winapi.py
 +                ${CMAKE_SOURCE_DIR}/specs/stdapi.py
 +        )
 +        add_library (d2d1 MODULE d2d1.def d2d1trace.cpp)
 +        target_link_libraries (d2d1
 +            common_trace
 +            common
 +            ${ZLIB_LIBRARIES}
 +            ${SNAPPY_LIBRARIES}
 +        )
 +        set_target_properties (d2d1
 +            PROPERTIES PREFIX ""
 +            OUTPUT_NAME d2d1
 +        )
 +        install (TARGETS d2d1 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
 +
 +        add_custom_command (
 +            OUTPUT dwritetrace.cpp
 +            COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/dwritetrace.py > ${CMAKE_CURRENT_BINARY_DIR}/dwritetrace.cpp
 +            DEPENDS
 +                dwritetrace.py
 +                trace.py
 +                ${CMAKE_SOURCE_DIR}/specs/d2d1.py
 +                ${CMAKE_SOURCE_DIR}/specs/d2d1.py
 +                ${CMAKE_SOURCE_DIR}/specs/d2dbasetypes.py
 +                ${CMAKE_SOURCE_DIR}/specs/d2derr.py
 +                ${CMAKE_SOURCE_DIR}/specs/dwrite.py
 +                ${CMAKE_SOURCE_DIR}/specs/dcommon.py
 +                ${CMAKE_SOURCE_DIR}/specs/dxgi.py
 +                ${CMAKE_SOURCE_DIR}/specs/dxgitype.py
 +                ${CMAKE_SOURCE_DIR}/specs/dxgiformat.py
 +                ${CMAKE_SOURCE_DIR}/specs/winapi.py
 +                ${CMAKE_SOURCE_DIR}/specs/stdapi.py
 +        )
 +        add_library (dwrite MODULE dwrite.def dwritetrace.cpp)
 +        target_link_libraries (dwrite
 +            common_trace
 +            common
 +            ${ZLIB_LIBRARIES}
 +            ${SNAPPY_LIBRARIES}
 +        )
 +        set_target_properties (dwrite
 +            PROPERTIES PREFIX ""
 +            OUTPUT_NAME dwrite
 +        )
 +        install (TARGETS dwrite LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
 +    endif (DirectX_D2D1_INCLUDE_DIR)
 +
      # opengl32.dll
      add_custom_command (
          OUTPUT wgltrace.cpp
@@@ -413,7 -349,6 +416,6 @@@ elseif (X11_FOUND
          common
          ${ZLIB_LIBRARIES}
          ${SNAPPY_LIBRARIES}
-         ${X11_X11_LIB}
          ${CMAKE_THREAD_LIBS_INIT}
          dl
      )
diff --combined wrappers/trace.py
index 4e52cf652a661fab24931ec65508280e3d84f91e,5d0a566f413b77119cf26ccf8b4831d038e88090..4563f454f710822887ad9bd5eaa4de5606db7d4f
@@@ -39,6 -39,45 +39,45 @@@ def getWrapperInterfaceName(interface)
      return "Wrap" + interface.expr
  
  
+ class ExpanderMixin:
+     '''Mixin class that provides a bunch of methods to expand C expressions
+     from the specifications.'''
+     __structs = None
+     __indices = None
+     def expand(self, expr):
+         # Expand a C expression, replacing certain variables
+         if not isinstance(expr, basestring):
+             return expr
+         variables = {}
+         if self.__structs is not None:
+             variables['self'] = '(%s)' % self.__structs[0]
+         if self.__indices is not None:
+             variables['i'] = self.__indices[0]
+         expandedExpr = expr.format(**variables)
+         if expandedExpr != expr and 0:
+             sys.stderr.write("  %r -> %r\n" % (expr, expandedExpr))
+         return expandedExpr
+     def visitMember(self, structInstance, member_type, *args, **kwargs):
+         self.__structs = (structInstance, self.__structs)
+         try:
+             return self.visit(member_type, *args, **kwargs)
+         finally:
+             _, self.__structs = self.__structs
+     def visitElement(self, element_index, element_type, *args, **kwargs):
+         self.__indices = (element_index, self.__indices)
+         try:
+             return self.visit(element_type, *args, **kwargs)
+         finally:
+             _, self.__indices = self.__indices
  class ComplexValueSerializer(stdapi.OnceVisitor):
      '''Type visitors which generates serialization functions for
      complex types.
          self.visit(const.type)
  
      def visitStruct(self, struct):
-         for type, name in struct.members:
-             self.visit(type)
-         print 'static void _write__%s(const %s &value) {' % (struct.tag, struct.expr)
-         print '    static const char * members[%u] = {' % (len(struct.members),)
+         print 'static const char * _struct%s_members[%u] = {' % (struct.tag, len(struct.members))
          for type, name,  in struct.members:
-             print '        "%s",' % (name,)
-         print '    };'
-         print '    static const trace::StructSig sig = {'
-         print '       %u, "%s", %u, members' % (struct.id, struct.name, len(struct.members))
-         print '    };'
-         print '    trace::localWriter.beginStruct(&sig);'
-         for type, name in struct.members:
-             self.serializer.visit(type, 'value.%s' % (name,))
-         print '    trace::localWriter.endStruct();'
-         print '}'
+             print '    "%s",' % (name,)
+         print '};'
+         print 'static const trace::StructSig _struct%s_sig = {' % (struct.tag,)
+         print '   %u, "%s", %u, _struct%s_members' % (struct.id, struct.name, len(struct.members), struct.tag)
+         print '};'
          print
  
      def visitArray(self, array):
          print
  
  
- class ValueSerializer(stdapi.Visitor):
+ class ValueSerializer(stdapi.Visitor, ExpanderMixin):
      '''Visitor which generates code to serialize any type.
      
      Simple types are serialized inline here, whereas the serialization of
      ComplexValueSerializer visitor above.
      '''
  
+     def __init__(self):
+         #stdapi.Visitor.__init__(self)
+         self.indices = []
+         self.instances = []
      def visitLiteral(self, literal, instance):
          print '    trace::localWriter.write%s(%s);' % (literal.kind, instance)
  
          self.visit(const.type, instance)
  
      def visitStruct(self, struct, instance):
-         print '    _write__%s(%s);' % (struct.tag, instance)
+         print '    trace::localWriter.beginStruct(&_struct%s_sig);' % (struct.tag,)
+         for type, name in struct.members:
+             self.visitMember(instance, type, '(%s).%s' % (instance, name,))
+         print '    trace::localWriter.endStruct();'
  
      def visitArray(self, array, instance):
          length = '_c' + array.type.tag
          index = '_i' + array.type.tag
+         array_length = self.expand(array.length)
          print '    if (%s) {' % instance
-         print '        size_t %s = %s > 0 ? %s : 0;' % (length, array.length, array.length)
+         print '        size_t %s = %s > 0 ? %s : 0;' % (length, array_length, array_length)
          print '        trace::localWriter.beginArray(%s);' % length
          print '        for (size_t %s = 0; %s < %s; ++%s) {' % (index, index, length, index)
          print '            trace::localWriter.beginElement();'
-         self.visit(array.type, '(%s)[%s]' % (instance, index))
+         self.visitElement(index, array.type, '(%s)[%s]' % (instance, index))
          print '            trace::localWriter.endElement();'
          print '        }'
          print '        trace::localWriter.endArray();'
          print '    }'
  
      def visitBlob(self, blob, instance):
-         print '    trace::localWriter.writeBlob(%s, %s);' % (instance, blob.size)
+         print '    trace::localWriter.writeBlob(%s, %s);' % (instance, self.expand(blob.size))
  
      def visitEnum(self, enum, instance):
          print '    trace::localWriter.writeEnum(&_enum%s_sig, %s);' % (enum.tag, instance)
@@@ -272,7 -312,7 +312,7 @@@ class WrapDecider(stdapi.Traverser)
          self.needsWrapping = True
  
  
- class ValueWrapper(stdapi.Traverser):
+ class ValueWrapper(stdapi.Traverser, ExpanderMixin):
      '''Type visitor which will generate the code to wrap an instance.
      
      Wrapping is necessary mostly for interfaces, however interface pointers can
  
      def visitStruct(self, struct, instance):
          for type, name in struct.members:
-             self.visit(type, "(%s).%s" % (instance, name))
+             self.visitMember(instance, type, "(%s).%s" % (instance, name))
  
      def visitArray(self, array, instance):
+         array_length = self.expand(array.length)
          print "    if (%s) {" % instance
-         print "        for (size_t _i = 0, _s = %s; _i < _s; ++_i) {" % array.length
-         self.visit(array.type, instance + "[_i]")
+         print "        for (size_t _i = 0, _s = %s; _i < _s; ++_i) {" % array_length
+         self.visitElement('_i', array.type, instance + "[_i]")
          print "        }"
          print "    }"
  
          elem_type = pointer.type.mutable()
          if isinstance(elem_type, stdapi.Interface):
              self.visitInterfacePointer(elem_type, instance)
 +        elif isinstance(elem_type, stdapi.Alias) and isinstance(elem_type.type, stdapi.Interface):
 +            self.visitInterfacePointer(elem_type.type, instance)
          else:
              self.visitPointer(pointer, instance)
      
@@@ -322,30 -361,14 +363,31 @@@ class ValueUnwrapper(ValueWrapper)
  
      allocated = False
  
 +    def visitStruct(self, struct, instance):
 +        if not self.allocated:
 +            # Argument is constant. We need to create a non const
 +            print '    {'
 +            print "        %s * _t = static_cast<%s *>(alloca(sizeof *_t));" % (struct, struct)
 +            print '        *_t = %s;' % (instance,)
 +            assert instance.startswith('*')
 +            print '        %s = _t;' % (instance[1:],)
 +            instance = '*_t'
 +            self.allocated = True
 +            try:
 +                return ValueWrapper.visitStruct(self, struct, instance)
 +            finally:
 +                print '    }'
 +        else:
 +            return ValueWrapper.visitStruct(self, struct, instance)
 +
      def visitArray(self, array, instance):
          if self.allocated or isinstance(instance, stdapi.Interface):
              return ValueWrapper.visitArray(self, array, instance)
+         array_length = self.expand(array.length)
          elem_type = array.type.mutable()
-         print "    if (%s && %s) {" % (instance, array.length)
-         print "        %s * _t = static_cast<%s *>(alloca(%s * sizeof *_t));" % (elem_type, elem_type, array.length)
-         print "        for (size_t _i = 0, _s = %s; _i < _s; ++_i) {" % array.length
+         print "    if (%s && %s) {" % (instance, array_length)
+         print "        %s * _t = static_cast<%s *>(alloca(%s * sizeof *_t));" % (elem_type, elem_type, array_length)
+         print "        for (size_t _i = 0, _s = %s; _i < _s; ++_i) {" % array_length
          print "            _t[_i] = %s[_i];" % instance 
          self.allocated = True
          self.visit(array.type, "_t[_i]")