rename dir

This commit is contained in:
pengfei.zhou
2019-12-21 21:55:53 +08:00
parent 15d3a1cbf7
commit f21732f551
35 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
#include "context_manager.h"
#include "native_bridge.h"
#include "plugin/shader_plugin.h"
Q_INVOKABLE void NativeBridge::function(int contextId, QString module, QString methodName, QString callbackId, QJSValue jsValue) {
qDebug() << "contextId: " + QString::number(contextId) + ", " +
"module: " + module + ", " +
"methodName: " + methodName + ", " +
"callbackId: " + callbackId + ", " +
"arguments: " + jsValue.toString();
Context *context = ContextManager::getInstance()->getContext(contextId);
QString value = context->driver->getRegistry()->acquirePluginInfo(module);
qDebug() << value;
if (value.contains("ShaderPlugin")) {
ShaderPlugin shaderPlugin(context);
QMetaObject::invokeMethod(
&shaderPlugin,
methodName.toStdString().c_str(),
Qt::AutoConnection,
Q_ARG(QJSValue, jsValue));
}
}

View File

@@ -0,0 +1,16 @@
#ifndef NATIVE_BRIDGE_H
#define NATIVE_BRIDGE_H
#include <QJSValue>
#include <QObject>
class NativeBridge : public QObject {
Q_OBJECT
public:
NativeBridge(QObject *parent = nullptr) : QObject(parent) {}
Q_INVOKABLE void function(int contextId, QString module, QString methodName, QString callbackId, QJSValue jsValue);
};
#endif // NATIVE_BRIDGE_H

View File

@@ -0,0 +1,7 @@
#include <QDebug>
#include "native_empty.h"
Q_INVOKABLE void NativeEmpty::function() {
qDebug() << "nativeEmpty";
}

View File

@@ -0,0 +1,15 @@
#ifndef NATIVE_EMPTY_H
#define NATIVE_EMPTY_H
#include <QObject>
class NativeEmpty : public QObject {
Q_OBJECT
public:
NativeEmpty(QObject *parent = nullptr) : QObject(parent) {}
Q_INVOKABLE void function();
};
#endif // NATIVE_EMPTY_H

View File

@@ -0,0 +1,13 @@
#include <QDebug>
#include "native_log.h"
Q_INVOKABLE void NativeLog::function(QString level, QString content) {
if (level == 'w') {
qWarning() << content;
} else if (level == 'd') {
qDebug() << content;
} else if (level == 'e') {
qCritical() << content;
}
}

View File

@@ -0,0 +1,15 @@
#ifndef NATIVELOG_H
#define NATIVELOG_H
#include <QObject>
class NativeLog : public QObject {
Q_OBJECT
public:
NativeLog(QObject *parent = nullptr) : QObject(parent) {}
Q_INVOKABLE void function(QString level, QString content);
};
#endif // NATIVELOG_H

View File

@@ -0,0 +1,30 @@
#include <QTimer>
#include "native_timer.h"
Q_INVOKABLE void NativeTimer::setTimer(long timerId, int time, bool repeat) {
QTimer *timer = new QTimer(this);
timer->setSingleShot(!repeat);
connect(timer, &QTimer::timeout, this, [=] () {
if (deletedTimerIds->contains(timerId)) {
deletedTimerIds->remove(timerId);
delete timer;
} else {
engine->evaluate(
Constant::GLOBAL_DORIC + "." +
Constant::DORIC_TIMER_CALLBACK + "(" +
QString::number(timerId) + ")"
);
if (!repeat) {
deletedTimerIds->remove(timerId);
delete timer;
}
}
});
timer->start(time);
}
void NativeTimer::clearTimer(long timerId) {
deletedTimerIds->insert(timerId);
}

View File

@@ -0,0 +1,27 @@
#ifndef NATIVE_TIMER_H
#define NATIVE_TIMER_H
#include <QJSEngine>
#include <QObject>
#include <QSet>
#include "constant.h"
class NativeTimer : public QObject {
Q_OBJECT
private:
QSet<long> *deletedTimerIds = new QSet<long>();
QJSEngine *engine;
public:
NativeTimer(QJSEngine *engine, QObject *parent = nullptr) : QObject(parent) {
this->engine = engine;
}
Q_INVOKABLE void setTimer(long timerId, int time, bool repeat);
Q_INVOKABLE void clearTimer(long timerId);
};
#endif // NATIVE_TIMER_H