Skip to content

Commit

Permalink
Revert "gl: simplify tls"
Browse files Browse the repository at this point in the history
This reverts commit e7413c2.
rendering thread can have multiple contexts, OpenGLVideo in each context
should not share the same tls one.
  • Loading branch information
wang-bin committed Jun 18, 2017
1 parent c47be1f commit 0e3b93e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/opengl/OpenGLVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,24 @@ void OpenGLVideoPrivate::updateGeometry(VideoShader* shader, const QRectF &t, co
tex_target = shader->textureTarget();
update_geo = true;
}
// unlike thread_local, QThreadStorage<T*> will delete ptr at thread exit, so we store quintptr
static QThreadStorage<quintptr> tls_gr; // TODO: only update VAO, not the whole GeometryRenderer
if (!tls_gr.hasLocalData()) {
qDebug("creating GeometryRenderer...");
GeometryRenderer* tls_gr_ptr = new GeometryRenderer(); // local var is captured by lambda
tls_gr.setLocalData(quintptr(tls_gr_ptr));
bool update_gr = false;
static QThreadStorage<bool> new_thread;
if (!new_thread.hasLocalData())
new_thread.setLocalData(true);

update_gr = new_thread.localData();
if (!gr || update_gr) { // TODO: only update VAO, not the whole GeometryRenderer
update_geo = true;
new_thread.setLocalData(false);
GeometryRenderer *r = new GeometryRenderer(); // local var is captured by lambda
gr = r;
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) && defined(Q_COMPILER_LAMBDA)
QObject::connect(QOpenGLContext::currentContext(), &QOpenGLContext::aboutToBeDestroyed, [tls_gr_ptr]{
qDebug("destroy GeometryRenderer %p", tls_gr_ptr);
delete tls_gr_ptr;
QObject::connect(QOpenGLContext::currentContext(), &QOpenGLContext::aboutToBeDestroyed, [r]{
qDebug("destroy GeometryRenderer %p", r);
delete r;
});
#endif
}
gr = reinterpret_cast<GeometryRenderer*>(tls_gr.localData());
// (-1, -1, 2, 2) must flip y
QRectF target_rect = norm_viewport ? QRectF(-1, 1, 2, -2) : rect;
if (target.isValid()) {
Expand Down

0 comments on commit 0e3b93e

Please sign in to comment.