Skip to content

Commit

Permalink
wgltrace: Emit fake glBitmap on wglUseFontBitmapsA.
Browse files Browse the repository at this point in the history
Basic implementation.
  • Loading branch information
jrfonseca committed Jan 28, 2016
1 parent eb25879 commit 10ab22a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions wrappers/trace.py
Expand Up @@ -965,6 +965,7 @@ def emit_memcpy(self, ptr, size):
print ' trace::fakeMemcpy(%s, %s);' % (ptr, size)

def fake_call(self, function, args):
print ' {'
print ' unsigned _fake_call = trace::localWriter.beginEnter(&_%s_sig, true);' % (function.name,)
for arg, instance in zip(function.args, args):
assert not arg.output
Expand All @@ -974,4 +975,5 @@ def fake_call(self, function, args):
print ' trace::localWriter.endEnter();'
print ' trace::localWriter.beginLeave(_fake_call);'
print ' trace::localWriter.endLeave();'
print ' }'

57 changes: 57 additions & 0 deletions wrappers/wgltrace.py
Expand Up @@ -97,6 +97,63 @@ def traceFunctionImplBody(self, function):
print ' gltrace::clearContext();'
print ' }'

# Emit fake glBitmap calls in the trace on wglUseFontBitmapsA.
# This enables to capture the real bitmaps and replay them outside Windows.
#
# XXX: In spite what
# https://msdn.microsoft.com/en-us/library/windows/desktop/dd374392.aspx
# implies, GetGlyphOutline(GGO_BITMAP) does not seem to work with
# certain fonts. The only solution is to draw the font charactors with
# a HBITMAP like the old Mesa fxwgl.c code used to do. That too, seems
# to be the way that opengl32.dll implements wglUseFontBitmaps.
#
if function.name == 'wglUseFontBitmapsA':
glNewList = glapi.getFunctionByName('glNewList')
glBitmap = glapi.getFunctionByName('glBitmap')
glEndList = glapi.getFunctionByName('glEndList')

print r' bool warned = false;'
print r' for (DWORD i = 0; i < count; ++i) {'
self.fake_call(glNewList, ['listBase + i', 'GL_COMPILE'])

print r' UINT uChar = first + i;'
print r' GLYPHMETRICS gm;'
print r' ZeroMemory(&gm, sizeof gm);'
print r' static const MAT2 mat2 = {{0, 1}, {0, 0}, {0, 0}, {0, -1}};'
print r' DWORD cbBuffer = GetGlyphOutlineA(hdc, uChar, GGO_BITMAP, &gm, 0, NULL, &mat2);'
print r' if (cbBuffer == GDI_ERROR) {'
print r' if (!warned) {'
print r' os::log("apitrace: warning: wglUseFontBitmapsA: GetGlyphOutlineA failed\n");'
print r' warned = true;'
print r' }'
print r' } else {'
print r' LPVOID lpvBuffer = NULL;'
print r' if (cbBuffer) {'
print r' lpvBuffer = malloc(cbBuffer);'
print r' DWORD dwRet;'
print r' dwRet = GetGlyphOutlineA(hdc, uChar, GGO_BITMAP, &gm, cbBuffer, lpvBuffer, &mat2);'
print r' assert(dwRet != GDI_ERROR);'
print r' assert(dwRet > 0);'
print r' }'
print r' GLsizei width = gm.gmBlackBoxX;'
print r' GLfloat height = gm.gmBlackBoxY;'
print r' GLfloat xorig = -gm.gmptGlyphOrigin.x;'
print r' GLfloat yorig = gm.gmptGlyphOrigin.y;'
print r' GLfloat xmove = gm.gmCellIncX;'
print r' GLfloat ymove = gm.gmCellIncY;'
print r' if (cbBuffer == 0) {'
print r' // We still need to emit an empty glBitmap for empty characters like spaces;'
print r' width = height = xorig = yorig = 0;'
print r' }'
print r' const GLubyte *bitmap = (const GLubyte *)lpvBuffer;'

self.fake_call(glBitmap, ['width', 'height', 'xorig', 'yorig', 'xmove', 'ymove', 'bitmap'])

print r' free(lpvBuffer);'
print r' }'
self.fake_call(glEndList, [])
print r' }'


if __name__ == '__main__':
print
Expand Down

0 comments on commit 10ab22a

Please sign in to comment.