Skip to content

Commit fbd2c71

Browse files
committed
use std::unique_ptr
1 parent be6c29d commit fbd2c71

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

selfdrive/ui/qt/widgets/cameraview.cc

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ CameraViewWidget::~CameraViewWidget() {
106106
glDeleteVertexArrays(1, &frame_vao);
107107
glDeleteBuffers(1, &frame_vbo);
108108
glDeleteBuffers(1, &frame_ibo);
109-
for (auto sync : gl_fences) {
110-
if (glIsSync(sync)) {
111-
glDeleteSync(sync);
112-
}
113-
}
114109
}
115110
doneCurrent();
116111
}
@@ -210,13 +205,11 @@ void CameraViewWidget::paintGL() {
210205
int texture_id = latest_texture_id;
211206
if (texture_id == -1) return;
212207

213-
// sync with the PBO
214-
if (glIsSync(gl_fences[texture_id])) {
215-
glWaitSync(gl_fences[texture_id], 0, GL_TIMEOUT_IGNORED);
216-
}
217-
218208
glViewport(0, 0, width(), height());
219209

210+
// sync with the PBO
211+
glWaitSync(gl_fences[texture_id]->sync, 0, GL_TIMEOUT_IGNORED);
212+
220213
glBindVertexArray(frame_vao);
221214
glActiveTexture(GL_TEXTURE0);
222215
glBindTexture(GL_TEXTURE_2D, texture[texture_id]->frame_tex);
@@ -311,10 +304,7 @@ void CameraViewWidget::vipcThread() {
311304
glBindTexture(GL_TEXTURE_2D, 0);
312305
assert(glGetError() == GL_NO_ERROR);
313306

314-
if (glIsSync(gl_fences[buf->idx])) {
315-
glDeleteSync(gl_fences[buf->idx]);
316-
}
317-
gl_fences[buf->idx] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
307+
gl_fences[buf->idx].reset(new WaitFence());
318308
}
319309
latest_texture_id = buf->idx;
320310
// Schedule update. update() will be invoked on the gui thread.

selfdrive/ui/qt/widgets/cameraview.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ class CameraViewWidget : public QOpenGLWidget, protected QOpenGLFunctions {
3636
virtual void updateFrameMat(int w, int h);
3737
void vipcThread();
3838

39+
struct WaitFence {
40+
WaitFence() { sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); }
41+
~WaitFence() { glDeleteSync(sync); }
42+
GLsync sync;
43+
};
44+
3945
bool zoomed_view;
4046
std::atomic<int> latest_texture_id = -1;
4147
GLuint frame_vao, frame_vbo, frame_ibo;
4248
mat4 frame_mat;
4349
std::unique_ptr<EGLImageTexture> texture[UI_BUF_COUNT];
44-
GLsync gl_fences[UI_BUF_COUNT] = {};
50+
std::unique_ptr<WaitFence> gl_fences[UI_BUF_COUNT];
4551
std::unique_ptr<QOpenGLShaderProgram> program;
4652
QColor bg = QColor("#000000");
4753

0 commit comments

Comments
 (0)