-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add InitTools class for visualizing overdraw, batches, and clip (…
…#136) * feat: Add InitTools class for visualizing overdraw, batches, and clip - Added InitTools class with functions to visualize overdraw, batches, and clip - Created init_tools.cpp and init_tools.h files - Updated CMakeLists.txt to include init_tools.cpp and init_tools.h - Added canExecute and execute functions to InitTools class - Added visualizeOverdraw, visualizeBatches, and visualizeClip functions to InitTools class - Created qml_engine_controller.cpp and qml_engine_controller.h files - Added canExecute and execute functions to QmlEngineController class - Added initQmlEngine function to QmlEngineController class - Updated main.cpp to include init_tools.h and qml_engine_controller.h - Added InitTools and QmlEngineController instances to main.cpp - Added QTimer to main.cpp to send qtLoaded signal to extension * Update Changelog
- Loading branch information
1 parent
0d7d30a
commit 542b321
Showing
11 changed files
with
219 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "init_tools.h" | ||
|
||
#include <QJsonDocument> | ||
|
||
void InitTools::visualizeOverdraw() { qputenv("QSG_VISUALIZE", "overdraw"); } | ||
|
||
void InitTools::visualizeBatches() { qputenv("QSG_VISUALIZE", "batches"); } | ||
|
||
void InitTools::visualizeClip() { qputenv("QSG_VISUALIZE", "clip"); } | ||
|
||
bool InitTools::canExecute(QString command_name) { | ||
return command_name == "qt.setVisualizeMode"; | ||
} | ||
|
||
void InitTools::execute(QJsonObject command) { | ||
const auto method = command["method"].toString(); | ||
assert(method == "qt.setVisualizeMode"); | ||
|
||
const auto mode = command["params"].toString(); | ||
if (mode == "overdraw") { | ||
visualizeOverdraw(); | ||
} else if (mode == "batches") { | ||
visualizeBatches(); | ||
} else if (mode == "clip") { | ||
visualizeClip(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include "emscripten_api.h" | ||
|
||
class InitTools : public CommandExecutor { | ||
|
||
public: | ||
void visualizeOverdraw(); | ||
void visualizeBatches(); | ||
void visualizeClip(); | ||
|
||
private: | ||
bool canExecute(QString command_name) final; | ||
void execute(QJsonObject command) final; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,26 @@ | ||
#include <QGuiApplication> | ||
#include <QQmlApplicationEngine> | ||
#include <QTimer> | ||
|
||
#include "init_tools.h" | ||
#include "emscripten_api.h" | ||
#include "qml_engine_controller.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QGuiApplication app(argc, argv); | ||
QQmlApplicationEngine engine; | ||
auto &api = EmscriptenApi::getInstance(); | ||
|
||
engine.loadFromModule("QmlSandboxModule", "QmlSandboxMain"); | ||
InitTools initTools; | ||
api.addExecutor(&initTools); | ||
|
||
auto &engineController = QmlEngineController::getInstance(); | ||
api.addExecutor(&engineController); | ||
|
||
QTimer::singleShot(0, []() { | ||
auto &api = EmscriptenApi::getInstance(); | ||
api.sendJRpcToExtension({{"method", "ext.qtLoaded"}, {"params", ""}}); | ||
}); | ||
|
||
return app.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "qml_engine_controller.h" | ||
|
||
#include <QJsonDocument> | ||
|
||
bool QmlEngineController::canExecute(QString command_name) { | ||
return command_name == "qt.initQml"; | ||
} | ||
|
||
void QmlEngineController::execute(QJsonObject command) { | ||
const auto method = command["method"].toString(); | ||
assert(method == "qt.initQml"); | ||
initQmlEngine(); | ||
} | ||
|
||
void QmlEngineController::initQmlEngine() { | ||
qml_engine = std::make_unique<QQmlApplicationEngine>(); | ||
qml_engine->loadFromModule("QmlSandboxModule", "QmlSandboxMain"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include <QQmlApplicationEngine> | ||
|
||
#include "emscripten_api.h" | ||
|
||
class QmlEngineController : public CommandExecutor { | ||
public: | ||
static QmlEngineController &getInstance() { | ||
static QmlEngineController instance; | ||
return instance; | ||
} | ||
|
||
private: | ||
bool canExecute(QString command_name) final; | ||
void execute(QJsonObject command) final; | ||
|
||
void initQmlEngine(); | ||
|
||
std::unique_ptr<QQmlApplicationEngine> qml_engine; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.