Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test v0.5.3 #14

Merged
merged 6 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
fail-fast: false
matrix:
version:
- '1.7'
- '1.8'
- '1.9'
- 'nightly'
os:
- ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ project(JlQML)

cmake_minimum_required(VERSION 3.16.0)

set(JlQML_VERSION 0.5.2)
set(JlQML_VERSION 0.5.3)
message(STATUS "Project version: v${JlQML_VERSION}")

set(CMAKE_MACOSX_RPATH 1)
Expand Down Expand Up @@ -49,6 +49,8 @@ qt6_add_qml_module(jlqml
SOURCES
application_manager.hpp
application_manager.cpp
foreign_thread_manager.hpp
foreign_thread_manager.cpp
julia_api.hpp
julia_api.cpp
julia_canvas.hpp
Expand Down
8 changes: 5 additions & 3 deletions application_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "application_manager.hpp"
#include "jlcxx/functions.hpp"

#include "foreign_thread_manager.hpp"
#include "application_manager.hpp"

namespace qmlwrap
{

Expand All @@ -11,11 +13,9 @@ void julia_message_output(QtMsgType type, const QMessageLogContext &context, con
case QtDebugMsg:
jl_safe_printf("Qt Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
case QtInfoMsg:
jl_safe_printf("Qt Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
#endif
case QtWarningMsg:
jl_safe_printf("Qt Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
Expand Down Expand Up @@ -96,6 +96,7 @@ void ApplicationManager::exec()
stoptimer();
app->exit(status);
});
ForeignThreadManager::instance().clear(QThread::currentThread());
const int status = app->exec();
if (status != 0)
{
Expand All @@ -112,6 +113,7 @@ ApplicationManager::ApplicationManager()

QSurfaceFormat format = QSurfaceFormat::defaultFormat();
format.setProfile(QSurfaceFormat::CoreProfile);
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setMajorVersion(3);
format.setMinorVersion(3);
//format.setOption(QSurfaceFormat::DebugContext); // note: this needs OpenGL 4.3
Expand Down
39 changes: 39 additions & 0 deletions foreign_thread_manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "jlcxx/jlcxx.hpp"

#include "foreign_thread_manager.hpp"

ForeignThreadManager& ForeignThreadManager::instance()
{
static ForeignThreadManager instance;
return instance;
}

void ForeignThreadManager::add_thread(QThread *t)
{
m_mutex.lock();
if(!m_threads.contains(t))
{
m_threads.insert(t);
#if (JULIA_VERSION_MAJOR * 100 + JULIA_VERSION_MINOR) >= 109
jl_adopt_thread();
#else
if(m_threads.size() > 1)
{
std::cout << "Warning: using multiple threads in Julia versions older than 1.9 will probably crash" << std::endl;
}
#endif
}
m_mutex.unlock();
}

void ForeignThreadManager::clear(QThread* main_thread)
{
m_mutex.lock();
m_threads.clear();
m_threads.insert(main_thread);
m_mutex.unlock();
}

ForeignThreadManager::ForeignThreadManager()
{
}
17 changes: 17 additions & 0 deletions foreign_thread_manager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <QSet>
#include <QMutex>
#include <QThread>

class ForeignThreadManager
{
public:
static ForeignThreadManager& instance();

void add_thread(QThread* t);
void clear(QThread* main_thread);

private:
ForeignThreadManager();
QSet<QThread*> m_threads;
QMutex m_mutex;
};
4 changes: 4 additions & 0 deletions julia_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
#include <QPainter>
#include <QQuickWindow>

#include "foreign_thread_manager.hpp"

#include "julia_canvas.hpp"

namespace qmlwrap
{

Expand All @@ -12,6 +15,7 @@ JuliaCanvas::JuliaCanvas(QQuickItem *parent) : QQuickPaintedItem(parent)

void JuliaCanvas::paint(QPainter *painter)
{
ForeignThreadManager::instance().add_thread(QThread::currentThread());
// allocate buffer for julia callback to draw on
int iwidth = width();
int iheight = height();
Expand Down
4 changes: 0 additions & 4 deletions opengl_viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ OpenGLViewport::OpenGLViewport(QQuickItem *parent, RenderFunction* render_func)
qFatal("QSG_RENDER_LOOP must be set to basic to use OpenGLViewport or MakieViewport. Add the line\nENV[\"QSG_RENDER_LOOP\"] = \"basic\"\nat the top of your Julia program");
}
QObject::connect(this, &OpenGLViewport::renderFunctionChanged, this, &OpenGLViewport::update);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
setMirrorVertically(true);
#else
qWarning() << "setMirrorVertically not available before Qt 5.6, OpenGLViewport image will be upside-down";
#endif
}

void OpenGLViewport::render()
Expand Down
12 changes: 0 additions & 12 deletions test/setup-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ function libcxxwrap_jll_version()
return VersionNumber(baseversion)
end

@static if Sys.isapple()
jllversion = libcxxwrap_jll_version()
cd(joinpath(cxxwrap_root, "lib")) do
expected_dylib = "libcxxwrap_julia.$jllversion.dylib"
if !isfile(expected_dylib)
compiled_dylib = readlink("libcxxwrap_julia.dylib")
symlink(compiled_dylib, expected_dylib)
println("linked $expected_dylib to $compiled_dylib")
end
end
end

envdir = mktempdir()
import Pkg
Pkg.activate(envdir)
Expand Down
10 changes: 5 additions & 5 deletions wrap_qml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)

qml_module.method("effectiveDevicePixelRatio", [] (QQuickWindow& w)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
return w.effectiveDevicePixelRatio();
#else
return 1.0;
#endif
return w.effectiveDevicePixelRatio();
});

qml_module.add_type<QQuickView>("QQuickView", julia_base_type<QQuickWindow>())
Expand Down Expand Up @@ -513,7 +509,11 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
}
});

#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
qml_module.method("qputenv", [] (const char* varName, QByteArray value) { qputenv(varName, value); });
#else
qml_module.method("qputenv", qputenv);
#endif
qml_module.method("qgetenv", qgetenv);
qml_module.method("qunsetenv", qunsetenv);

Expand Down
Loading