]> git.cworth.org Git - apitrace/commitdiff
Basic logging mechanism.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Sat, 5 Jul 2008 08:51:43 +0000 (17:51 +0900)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Sat, 5 Jul 2008 08:51:43 +0000 (17:51 +0900)
.gitignore
SConstruct
common/SConscript [new file with mode: 0644]
common/log.hpp [new file with mode: 0644]
d3d8/idirect3d_device8.cpp
d3d8/idirect3d_device8.hpp
d3dtrace.css [new file with mode: 0755]
d3dtrace.xsl [new file with mode: 0644]

index b79cb08e622225dcab7b681b3d39a473e225662d..55aae42576002273ab31dc717b45a29b7dd5f21b 100644 (file)
@@ -1,5 +1,7 @@
+.*.sw?
+.scons*
 *.obj
 *.dll
 *.lib
 *.exp
-.scons*
+*.xml
index 9313f4bb2e2ee7c837eccd28ec7f2fc310df7515..45585b2cfd7feb69bba4d926b83623a1ee0c2cbc 100644 (file)
@@ -49,20 +49,20 @@ else:
 #env['PDB'] = '${TARGET.base}.pdb'
 
 cflags = [
-        '/W3', # warning level
+    '/W3', # warning level
 ]
 if env['debug']:
-        cflags += [
-          '/Od', # disable optimizations
-          '/Oi', # enable intrinsic functions
-          '/Oy-', # disable frame pointer omission
-        ]
+    cflags += [
+      '/Od', # disable optimizations
+      '/Oi', # enable intrinsic functions
+      '/Oy-', # disable frame pointer omission
+    ]
 else:
-        cflags += [
-          '/Ox', # maximum optimizations
-          '/Oi', # enable intrinsic functions
-          '/Os', # favor code space
-        ]
+    cflags += [
+      '/Ox', # maximum optimizations
+      '/Oi', # enable intrinsic functions
+      '/Os', # favor code space
+    ]
 env.Append(CFLAGS = cflags)
 env.Append(CXXFLAGS = cflags)
 
@@ -70,22 +70,20 @@ env.Prepend(LIBS = [
     'kernel32',
     'user32',
     'gdi32',
-    'winspool',
     'comdlg32',
     'advapi32',
     'shell32',
-    'ole32',
-    'oleaut32',
-    'uuid',
-    'odbc32',
-    'odbccp32',
 ])
 
 env.Append(CPPPATH = [
     os.path.join(env['dxsdk'], 'Include'),
+    '#common',
 ])
 
 Export('env')
 
-SConscript('d3d8/SConscript')
-SConscript('d3d9/SConscript')
+SConscript([
+    'common/SConscript',
+    'd3d8/SConscript',
+    'd3d9/SConscript',
+])
diff --git a/common/SConscript b/common/SConscript
new file mode 100644 (file)
index 0000000..34525ce
--- /dev/null
@@ -0,0 +1,2 @@
+Import('env')
+
diff --git a/common/log.hpp b/common/log.hpp
new file mode 100644 (file)
index 0000000..e150072
--- /dev/null
@@ -0,0 +1,115 @@
+
+#ifndef LOG_HPP_
+#define LOG_HPP_
+
+#include <windows.h>
+
+#include <d3d8.h>
+
+#include <stdio.h>
+
+
+class Log
+{
+public:
+    Log(const char *filename) {
+        file = fopen(filename, "wt");
+        write("<?xml version='1.0' encoding='UTF-8'?>\n");
+        write("<?xml-stylesheet type='text/xsl' href='d3dtrace.xsl'?>\n");
+        write("<trace>\n");
+    }
+    
+    ~Log() {
+        write("</trace>\n");
+        fclose(file);
+    }
+    
+    void write(const char *s) {
+        fputs(s, file);
+    }
+    
+    void writef(const char *f, ...) {
+        va_list ap;
+        va_start(ap, f);
+        vfprintf(file, f, ap);
+        va_end(ap);
+    }
+    
+    void eol(void) {
+        fputs("\n", file);
+    }
+    
+    void tag(const char *name) {
+        write("<");
+        write(name);
+        write(">");
+    }
+    
+    void tag_begin(const char *name) {
+        write("<");
+        write(name);
+    }
+    
+    void tag_attr(const char *name, const char *value) {
+        write(" ");
+        write(name);
+        write("=\"");
+        write(value);
+        write("\"");
+    }
+    
+    void tag_end(void) {
+        write(">");
+    }
+    
+    void tag_close(const char *name) {
+        write("</");
+        write(name);
+        write(">");
+    }
+    
+    void call_begin(const char *function) {
+        write("\t");
+        tag_begin("call");
+        tag_attr("name", function);
+        tag_end();
+        eol();
+    }
+    
+    void call_end() {
+        write("\t");
+        tag_close("call");
+        eol();
+    }
+    
+    void param_begin(const char *type, const char *name) {
+        write("\t\t");
+        tag_begin("param");
+        tag_attr("type", type);
+        tag_attr("name", name);
+        tag_end();
+    }
+    
+    void param_end(void) {
+        tag_close("param");
+        eol();
+    }
+    
+    void param_uint(const char *name, UINT value) {
+        param_begin("UINT", name);
+        writef("%u", value);
+        param_end();
+    }
+    
+    void param_dword(const char *name, DWORD value) {
+        param_begin("DWORD", name);
+        writef("0x%08lx", value);
+        param_end();
+    }
+    
+protected:
+    FILE *file;
+};
+
+
+#endif /* LOG_HPP_ */
index d0d09bbf084977bc48c35b7c87597ae97b945a45..9783c0d31bcd0b95214c2fc1de7a970a0786f09a 100644 (file)
@@ -1,12 +1,14 @@
 // TraceDirect3DDevice8.cpp
 #include "stdafx.h"
+#include "log.hpp"
 
 TraceDirect3DDevice8::TraceDirect3DDevice8(IDirect3DDevice8* pOriginal) {
     m_pIDirect3DDevice8 = pOriginal; // store the pointer to original object
+    log = new Log("d3d8trace.xml"); 
 }
 
 TraceDirect3DDevice8::~TraceDirect3DDevice8() {
-
+    delete log;
 }
 
 HRESULT __stdcall TraceDirect3DDevice8::QueryInterface(REFIID riid, void** ppvObj) {
@@ -120,7 +122,17 @@ void __stdcall TraceDirect3DDevice8::GetGammaRamp(D3DGAMMARAMP* pRamp) {
 }
 
 HRESULT __stdcall TraceDirect3DDevice8::CreateTexture(UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8** ppTexture) {
-    return (m_pIDirect3DDevice8->CreateTexture(Width, Height, Levels, Usage, Format, Pool, ppTexture));
+    HRESULT hr;
+    log->call_begin("IDirect3DDevice9::CreateTexture");
+    log->param_uint("Width", Width);
+    log->param_uint("Height", Height);
+    log->param_uint("Levels", Levels);
+    log->param_dword("Usage", Usage);
+    log->param_dword("Format", Format);
+    log->param_dword("Pool", Pool);
+    hr = m_pIDirect3DDevice8->CreateTexture(Width, Height, Levels, Usage, Format, Pool, ppTexture);
+    log->call_end();
+    return hr;
 }
 
 HRESULT __stdcall TraceDirect3DDevice8::CreateVolumeTexture(UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture8** ppVolumeTexture) {
@@ -404,10 +416,10 @@ HRESULT __stdcall TraceDirect3DDevice8::GetPixelShaderFunction(DWORD Handle, voi
     return (m_pIDirect3DDevice8->GetPixelShaderFunction(Handle, pData, pSizeOfData));
 }
 
-HRESULT __stdcall TraceDirect3DDevice8::DrawRectPatch( UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo)
+HRESULT __stdcall TraceDirect3DDevice8::DrawRectPatch( UINT Handle, CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo)
 {   return (m_pIDirect3DDevice8->DrawRectPatch(Handle, pNumSegs, pRectPatchInfo) );}
 
-HRESULT __stdcall TraceDirect3DDevice8::DrawTriPatch( UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo)
+HRESULT __stdcall TraceDirect3DDevice8::DrawTriPatch( UINT Handle, CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo)
 {   return (m_pIDirect3DDevice8->DrawTriPatch(Handle, pNumSegs, pTriPatchInfo) );}
 
 HRESULT __stdcall TraceDirect3DDevice8::DeletePatch(UINT Handle) {
index d9c3d35150540cbde2d7bb5a7251c1710fbd3d6d..6708460aebfa8902f638185bc5b0f11f585bbaa3 100644 (file)
@@ -1,6 +1,8 @@
 // TraceDirect3DDevice8.h
 #pragma once
 
+class Log;
+
 class TraceDirect3DDevice8: public IDirect3DDevice8 {
 public:
 
@@ -110,6 +112,7 @@ public:
 private:
 
     IDirect3DDevice8 *m_pIDirect3DDevice8;
+    Log *log;
 
     // This is our test function
     void ShowWeAreHere(void);
diff --git a/d3dtrace.css b/d3dtrace.css
new file mode 100755 (executable)
index 0000000..e9662e7
--- /dev/null
@@ -0,0 +1,22 @@
+body {
+       font-family: sans;
+       font-size: 11px;
+       font-weight: normal;
+       text-align : left;
+}
+
+.fun {
+       font-weight: bold;
+}
+
+.var {
+       font-style: italic;
+}
+
+.typ {
+       display: none;
+}
+
+.lit {
+       color: #0000ff;
+}
diff --git a/d3dtrace.xsl b/d3dtrace.xsl
new file mode 100644 (file)
index 0000000..9528be7
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0"?>
+
+<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:output method="html" />
+
+       <xsl:template match="/trace">
+               <html>
+                       <head>
+                               <title>D3D Trace</title>
+                               <link rel="stylesheet" type="text/css" href="d3dtrace.css"/>
+                       </head>
+                       <body>
+                               <ul>
+                                       <xsl:apply-templates/>
+                               </ul>
+                       </body>
+               </html>
+       </xsl:template>
+
+       <xsl:template match="call">
+               <li>
+                       <span class="fun">
+                               <xsl:value-of select="@name"/>
+                       </span>
+                       <xsl:text>(</xsl:text>
+                       <xsl:apply-templates/>
+                       <xsl:text>)</xsl:text>
+               </li>
+       </xsl:template>
+
+       <xsl:template match="param">
+               <span class="typ">
+                       <xsl:value-of select="@type"/>
+                       <xsl:text> </xsl:text>
+               </span>
+               <span class="var">
+                       <xsl:value-of select="@name"/>
+               </span>
+               <xsl:text> = </xsl:text>
+               <span class="lit">
+                       <xsl:value-of select="."/>
+               </span>
+               <xsl:if test="position() != last()">
+                       <xsl:text>, </xsl:text>
+               </xsl:if>
+       </xsl:template>
+
+</xsl:transform>