From 915d3d9984dcaa0696fdd805854bd79d668ba15e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sat, 5 Jul 2008 17:51:43 +0900 Subject: [PATCH] Basic logging mechanism. --- .gitignore | 4 +- SConstruct | 36 ++++++------ common/SConscript | 2 + common/log.hpp | 115 +++++++++++++++++++++++++++++++++++++ d3d8/idirect3d_device8.cpp | 20 +++++-- d3d8/idirect3d_device8.hpp | 3 + d3dtrace.css | 22 +++++++ d3dtrace.xsl | 49 ++++++++++++++++ 8 files changed, 227 insertions(+), 24 deletions(-) create mode 100644 common/SConscript create mode 100644 common/log.hpp create mode 100755 d3dtrace.css create mode 100644 d3dtrace.xsl diff --git a/.gitignore b/.gitignore index b79cb08..55aae42 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ +.*.sw? +.scons* *.obj *.dll *.lib *.exp -.scons* +*.xml diff --git a/SConstruct b/SConstruct index 9313f4b..45585b2 100644 --- a/SConstruct +++ b/SConstruct @@ -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 index 0000000..34525ce --- /dev/null +++ b/common/SConscript @@ -0,0 +1,2 @@ +Import('env') + diff --git a/common/log.hpp b/common/log.hpp new file mode 100644 index 0000000..e150072 --- /dev/null +++ b/common/log.hpp @@ -0,0 +1,115 @@ + +#ifndef LOG_HPP_ +#define LOG_HPP_ + +#include + +#include + +#include + + +class Log +{ +public: + Log(const char *filename) { + file = fopen(filename, "wt"); + write("\n"); + write("\n"); + write("\n"); + } + + ~Log() { + write("\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(""); + } + + 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_ */ diff --git a/d3d8/idirect3d_device8.cpp b/d3d8/idirect3d_device8.cpp index d0d09bb..9783c0d 100644 --- a/d3d8/idirect3d_device8.cpp +++ b/d3d8/idirect3d_device8.cpp @@ -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) { diff --git a/d3d8/idirect3d_device8.hpp b/d3d8/idirect3d_device8.hpp index d9c3d35..6708460 100644 --- a/d3d8/idirect3d_device8.hpp +++ b/d3d8/idirect3d_device8.hpp @@ -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 index 0000000..e9662e7 --- /dev/null +++ b/d3dtrace.css @@ -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 index 0000000..9528be7 --- /dev/null +++ b/d3dtrace.xsl @@ -0,0 +1,49 @@ + + + + + + + + + + D3D Trace + + + +
    + +
+ + +
+ + +
  • + + + + ( + + ) +
  • +
    + + + + + + + + + + = + + + + + , + + + +
    -- 2.45.2