Skip to content

Commit

Permalink
update capi and remove qt dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Oct 18, 2015
1 parent 12e6b67 commit e0d3556
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 64 deletions.
72 changes: 24 additions & 48 deletions src/capi/egl_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#define DEBUG_LOAD
//#define CAPI_IS_LAZY_RESOLVE 0
#ifndef CAPI_LINK_EGL
#include <QtCore/QLibrary>
#include "capi.h"
#endif //CAPI_LINK_EGL
#include "egl_api.h" //include last to avoid covering types later
Expand All @@ -36,73 +35,50 @@ api::~api(){}
bool api::loaded() const{return true;}
#else
static const char* names[] = {
"EGL",
#ifdef Q_OS_WIN
#ifndef QT_NO_DEBUG
#ifdef CAPI_TARGET_OS_WIN
#if defined(QT_CORE_LIB) && !defined(QT_NO_DEBUG)
"libEGLd",
"libEGL",
#else
"libEGL",
"libEGLd",
#endif //QT_NO_DEBUG
#endif //defined(QT_CORE_LIB) && !defined(QT_NO_DEBUG)
#else
"libEGL",
"EGL",
#endif
NULL
};

class EGLLib
class EGLLib : public ::capi::dso
{
QLibrary m_lib;
public:
explicit EGLLib() : m_lib() {}
explicit EGLLib(const QString& fileName) : m_lib(fileName) {}
explicit EGLLib(const QString& fileName, int verNum) : m_lib(fileName, verNum) {}
void* resolve(const char *symbol) {
// from qwindowseglcontext.cpp
#ifdef __MINGW32__
QString baseNameStr = QString::fromLatin1(symbol);
QString nameStr;
virtual void* resolve(const char *symbol) {
#ifndef __MINGW32__
return (void*)dso::resolve(symbol);
#endif
// from qwindowseglcontext.cpp. Play nice with 32-bit mingw: Try func first, then func@0, func@4, ..., func@64.
// The def file does not provide any aliases in libEGL and libGLESv2 in these builds which results in exporting function names like eglInitialize@12.
// This cannot be fixed without breaking binary compatibility. So be flexible here instead.
void *proc = 0;

// Play nice with 32-bit mingw: Try func first, then func@0, func@4,
// func@8, func@12, ..., func@64. The def file does not provide any aliases
// in libEGL and libGLESv2 in these builds which results in exporting
// function names like eglInitialize@12. This cannot be fixed without
// breaking binary compatibility. So be flexible here instead.

int argSize = -1;
while (!proc && argSize <= 64) {
nameStr = baseNameStr;
if (argSize >= 0)
nameStr += QLatin1Char('@') + QString::number(argSize);
argSize = argSize < 0 ? 0 : argSize + 4;
proc = (void*)m_lib.resolve(nameStr.toLatin1().constData());
for (int n = -4; !proc && n <= 64; n += 4) {
if (n < 0) {
proc = (void*)dso::resolve(symbol);
continue;
}
char name[512];
CAPI_SNPRINTF(name, sizeof(name), "%s@%d", symbol, n);
proc = (void*)dso::resolve(name);
if (proc)
fprintf(stderr, "%s=>%s\n", symbol, name);
}
if (argSize > 0)
fprintf(stderr, "%s=>%s\n", symbol, nameStr.toLatin1().constData());
return proc;
#else
return (void*)m_lib.resolve(symbol);
#endif
}

bool load() {return m_lib.load();}
bool unload() {return m_lib.unload();}
bool isLoaded() const {return m_lib.isLoaded();}

void setFileName(const QString &fileName) {m_lib.setFileName(fileName);}
QString fileName() const {return m_lib.fileName();}

void setFileNameAndVersion(const QString &fileName, int verNum) {m_lib.setFileNameAndVersion(fileName, verNum);}
QString errorString() const {return m_lib.errorString();}
};

# if CAPI_HAS_EGL_VERSION
# if 1
static const int versions[] = {
::capi::NoVersion,
// the following line will be replaced by the content of config/egl/version if exists
%VERSIONS%
1
, ::capi::EndVersion
};
CAPI_BEGIN_DLL_VER(names, versions, EGLLib)
Expand Down
27 changes: 13 additions & 14 deletions src/subtitle/ass_api.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
mkapi dynamic load code generation for capi template
Copyright (C) 2014 Wang Bin <[email protected]>
Copyright (C) 2014-2015 Wang Bin <[email protected]>
https://github.com/wang-bin/mkapi
https://github.com/wang-bin/capi
Expand All @@ -23,7 +23,6 @@
//#define DEBUG_LOAD
//#define CAPI_IS_LAZY_RESOLVE 0
#ifndef CAPI_LINK_ASS
#include <QtCore/QLibrary>
#include "capi.h"
#endif
#include "ass_api.h" //include last to avoid covering types later
Expand All @@ -46,18 +45,18 @@ static const int versions[] = {
5, 4
, ::capi::EndVersion
};
CAPI_BEGIN_DLL_VER(names, versions, QLibrary)
CAPI_BEGIN_DLL_VER(names, versions, ::capi::dso)
# else
CAPI_BEGIN_DLL(names, QLibrary)
CAPI_BEGIN_DLL(names, ::capi::dso)
# endif //1
// CAPI_DEFINE_RESOLVER(argc, return_type, name, argv_no_name)
// mkapi code generation BEGIN
//CAPI_DEFINE_ENTRY(int, ass_library_version, CAPI_ARG0())
CAPI_DEFINE_ENTRY(ASS_Library *, ass_library_init, CAPI_ARG0())
CAPI_DEFINE_ENTRY(void, ass_library_done, CAPI_ARG1(ASS_Library *))
CAPI_DEFINE_ENTRY(void, ass_set_fonts_dir, CAPI_ARG2(ASS_Library *, const char *))
//CAPI_DEFINE_ENTRY(void, ass_set_extract_fonts, CAPI_ARG2(ASS_Library *, int))
//CAPI_DEFINE_ENTRY(void, ass_set_style_overrides, CAPI_ARG2(ASS_Library *, char **))
CAPI_DEFINE_ENTRY(void, ass_set_extract_fonts, CAPI_ARG2(ASS_Library *, int))
CAPI_DEFINE_ENTRY(void, ass_set_style_overrides, CAPI_ARG2(ASS_Library *, char **))
//CAPI_DEFINE_ENTRY(void, ass_process_force_style, CAPI_ARG1(ASS_Track *))
CAPI_DEFINE_ENTRY(void, ass_set_message_cb, CAPI_ARG3(ASS_Library *, void (*msg_cb)
(int level, const char *fmt, va_list args, void *data), void *))
Expand All @@ -66,11 +65,11 @@ CAPI_DEFINE_ENTRY(void, ass_renderer_done, CAPI_ARG1(ASS_Renderer *))
CAPI_DEFINE_ENTRY(void, ass_set_frame_size, CAPI_ARG3(ASS_Renderer *, int, int))
//CAPI_DEFINE_ENTRY(void, ass_set_storage_size, CAPI_ARG3(ASS_Renderer *, int, int))
CAPI_DEFINE_ENTRY(void, ass_set_shaper, CAPI_ARG2(ASS_Renderer *, ASS_ShapingLevel))
//CAPI_DEFINE_ENTRY(void, ass_set_margins, CAPI_ARG5(ASS_Renderer *, int, int, int, int))
//CAPI_DEFINE_ENTRY(void, ass_set_use_margins, CAPI_ARG2(ASS_Renderer *, int))
CAPI_DEFINE_ENTRY(void, ass_set_margins, CAPI_ARG5(ASS_Renderer *, int, int, int, int))
CAPI_DEFINE_ENTRY(void, ass_set_use_margins, CAPI_ARG2(ASS_Renderer *, int))
//CAPI_DEFINE_ENTRY(void, ass_set_pixel_aspect, CAPI_ARG2(ASS_Renderer *, double))
//CAPI_DEFINE_ENTRY(void, ass_set_aspect_ratio, CAPI_ARG3(ASS_Renderer *, double, double))
//CAPI_DEFINE_ENTRY(void, ass_set_font_scale, CAPI_ARG2(ASS_Renderer *, double))
CAPI_DEFINE_ENTRY(void, ass_set_font_scale, CAPI_ARG2(ASS_Renderer *, double))
//CAPI_DEFINE_ENTRY(void, ass_set_hinting, CAPI_ARG2(ASS_Renderer *, ASS_Hinting))
//CAPI_DEFINE_ENTRY(void, ass_set_line_spacing, CAPI_ARG2(ASS_Renderer *, double))
//CAPI_DEFINE_ENTRY(void, ass_set_line_position, CAPI_ARG2(ASS_Renderer *, double))
Expand Down Expand Up @@ -107,20 +106,20 @@ typedef void (*ass_set_message_cb_msg_cb1)
CAPI_DEFINE(ASS_Library *, ass_library_init, CAPI_ARG0())
CAPI_DEFINE(void, ass_library_done, CAPI_ARG1(ASS_Library *))
CAPI_DEFINE(void, ass_set_fonts_dir, CAPI_ARG2(ASS_Library *, const char *))
//CAPI_DEFINE(void, ass_set_extract_fonts, CAPI_ARG2(ASS_Library *, int))
//CAPI_DEFINE(void, ass_set_style_overrides, CAPI_ARG2(ASS_Library *, char **))
CAPI_DEFINE(void, ass_set_extract_fonts, CAPI_ARG2(ASS_Library *, int))
CAPI_DEFINE(void, ass_set_style_overrides, CAPI_ARG2(ASS_Library *, char **))
//CAPI_DEFINE(void, ass_process_force_style, CAPI_ARG1(ASS_Track *))
CAPI_DEFINE(void, ass_set_message_cb, CAPI_ARG3(ASS_Library *, ass_set_message_cb_msg_cb1, void *))
CAPI_DEFINE(ASS_Renderer *, ass_renderer_init, CAPI_ARG1(ASS_Library *))
CAPI_DEFINE(void, ass_renderer_done, CAPI_ARG1(ASS_Renderer *))
CAPI_DEFINE(void, ass_set_frame_size, CAPI_ARG3(ASS_Renderer *, int, int))
//CAPI_DEFINE(void, ass_set_storage_size, CAPI_ARG3(ASS_Renderer *, int, int))
CAPI_DEFINE(void, ass_set_shaper, CAPI_ARG2(ASS_Renderer *, ASS_ShapingLevel))
//CAPI_DEFINE(void, ass_set_margins, CAPI_ARG5(ASS_Renderer *, int, int, int, int))
//CAPI_DEFINE(void, ass_set_use_margins, CAPI_ARG2(ASS_Renderer *, int))
CAPI_DEFINE(void, ass_set_margins, CAPI_ARG5(ASS_Renderer *, int, int, int, int))
CAPI_DEFINE(void, ass_set_use_margins, CAPI_ARG2(ASS_Renderer *, int))
//CAPI_DEFINE(void, ass_set_pixel_aspect, CAPI_ARG2(ASS_Renderer *, double))
//CAPI_DEFINE(void, ass_set_aspect_ratio, CAPI_ARG3(ASS_Renderer *, double, double))
//CAPI_DEFINE(void, ass_set_font_scale, CAPI_ARG2(ASS_Renderer *, double))
CAPI_DEFINE(void, ass_set_font_scale, CAPI_ARG2(ASS_Renderer *, double))
//CAPI_DEFINE(void, ass_set_hinting, CAPI_ARG2(ASS_Renderer *, ASS_Hinting))
//CAPI_DEFINE(void, ass_set_line_spacing, CAPI_ARG2(ASS_Renderer *, double))
//CAPI_DEFINE(void, ass_set_line_position, CAPI_ARG2(ASS_Renderer *, double))
Expand Down
2 changes: 1 addition & 1 deletion src/subtitle/ass_api.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
mkapi dynamic load code generation for capi template
Copyright (C) 2014 Wang Bin <[email protected]>
Copyright (C) 2014-2015 Wang Bin <[email protected]>
https://github.com/wang-bin/mkapi
https://github.com/wang-bin/capi
Expand Down

0 comments on commit e0d3556

Please sign in to comment.