diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-02-22 15:03:12 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-02-22 15:03:12 +0100 |
| commit | a6473e956c95448974f3cd867c7fefa90f56b425 (patch) | |
| tree | 47a7fe59175afa34b5f574206cbfbdae5ae88cba | |
| parent | 596963e5474eddf9fc67c67e3ffcad4e28dc04c0 (diff) | |
White space: gl_video_view.{cc,h}
| -rw-r--r-- | src/wx/gl_video_view.cc | 390 | ||||
| -rw-r--r-- | src/wx/gl_video_view.h | 56 |
2 files changed, 223 insertions, 223 deletions
diff --git a/src/wx/gl_video_view.cc b/src/wx/gl_video_view.cc index 05fedd936..1ac949759 100644 --- a/src/wx/gl_video_view.cc +++ b/src/wx/gl_video_view.cc @@ -67,22 +67,22 @@ using namespace boost::placeholders; static void -check_gl_error (char const * last) +check_gl_error(char const * last) { - GLenum const e = glGetError (); + GLenum const e = glGetError(); if (e != GL_NO_ERROR) { - throw GLError (last, e); + throw GLError(last, e); } } -GLVideoView::GLVideoView (FilmViewer* viewer, wxWindow *parent) - : VideoView (viewer) - , _context (nullptr) +GLVideoView::GLVideoView(FilmViewer* viewer, wxWindow *parent) + : VideoView(viewer) + , _context(nullptr) , _rec2020(false) - , _vsync_enabled (false) - , _playing (false) - , _one_shot (false) + , _vsync_enabled(false) + , _playing(false) + , _one_shot(false) { wxGLAttributes attributes; /* We don't need a depth buffer, and indeed there is apparently a bug with Windows/Intel HD 630 @@ -90,60 +90,60 @@ GLVideoView::GLVideoView (FilmViewer* viewer, wxWindow *parent) * https://community.intel.com/t5/Graphics/Request-for-details-on-Intel-HD-630-green-lines-in-OpenGL-apps/m-p/1202179 */ attributes.PlatformDefaults().MinRGBA(8, 8, 8, 8).DoubleBuffer().Depth(0).EndList(); - _canvas = new wxGLCanvas ( + _canvas = new wxGLCanvas( parent, attributes, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE ); - _canvas->Bind (wxEVT_PAINT, boost::bind(&GLVideoView::update, this)); - _canvas->Bind (wxEVT_SIZE, boost::bind(&GLVideoView::size_changed, this, _1)); + _canvas->Bind(wxEVT_PAINT, boost::bind(&GLVideoView::update, this)); + _canvas->Bind(wxEVT_SIZE, boost::bind(&GLVideoView::size_changed, this, _1)); - _canvas->Bind (wxEVT_TIMER, boost::bind(&GLVideoView::check_for_butler_errors, this)); - _timer.reset (new wxTimer(_canvas)); - _timer->Start (2000); + _canvas->Bind(wxEVT_TIMER, boost::bind(&GLVideoView::check_for_butler_errors, this)); + _timer.reset(new wxTimer(_canvas)); + _timer->Start(2000); } void -GLVideoView::size_changed (wxSizeEvent const& ev) +GLVideoView::size_changed(wxSizeEvent const& ev) { auto const scale = _canvas->GetDPIScaleFactor(); int const width = std::round(ev.GetSize().GetWidth() * scale); int const height = std::round(ev.GetSize().GetHeight() * scale); _canvas_size = { width, height }; LOG_GENERAL("GLVideoView canvas size changed to %1x%2", width, height); - Sized (); + Sized(); } -GLVideoView::~GLVideoView () +GLVideoView::~GLVideoView() { boost::this_thread::disable_interruption dis; try { - _thread.interrupt (); - _thread.join (); + _thread.interrupt(); + _thread.join(); } catch (...) {} } void -GLVideoView::check_for_butler_errors () +GLVideoView::check_for_butler_errors() { if (!_viewer->butler()) { return; } try { - _viewer->butler()->rethrow (); + _viewer->butler()->rethrow(); } catch (DecodeError& e) { error_dialog(get(), std_to_wx(e.what())); } catch (dcp::ReadError& e) { - error_dialog (get(), wxString::Format(_("Could not read DCP: %s"), std_to_wx(e.what()))); + error_dialog(get(), wxString::Format(_("Could not read DCP: %s"), std_to_wx(e.what()))); } } /** Called from the UI thread */ void -GLVideoView::update () +GLVideoView::update() { if (!_canvas->IsShownOnScreen()) { return; @@ -153,23 +153,23 @@ GLVideoView::update () * on Linux we get strange failures to create the context for any version of GL higher * than 3.2. */ - ensure_context (); + ensure_context(); #ifdef DCPOMATIC_OSX /* macOS gives errors if we don't do this (and therefore [NSOpenGLContext setView:]) from the main thread */ if (!_setup_shaders_done) { - setup_shaders (); + setup_shaders(); _setup_shaders_done = true; } #endif if (!_thread.joinable()) { - _thread = boost::thread (boost::bind(&GLVideoView::thread, this)); + _thread = boost::thread(boost::bind(&GLVideoView::thread, this)); } - request_one_shot (); + request_one_shot(); - rethrow (); + rethrow(); } @@ -245,10 +245,10 @@ static constexpr char fragment_source[] = " vec4 xcubic = cubic(fxy.x);\n" " vec4 ycubic = cubic(fxy.y);\n" "\n" -" vec4 c = tex_coords.xxyy + vec2 (-0.5, +1.5).xyxy;\n" +" vec4 c = tex_coords.xxyy + vec2(-0.5, +1.5).xyxy;\n" "\n" " vec4 s = vec4(xcubic.xz + xcubic.yw, ycubic.xz + ycubic.yw);\n" -" vec4 offset = c + vec4 (xcubic.yw, ycubic.yw) / s;\n" +" vec4 offset = c + vec4(xcubic.yw, ycubic.yw) / s;\n" "\n" " offset *= inv_tex_size.xxyy;\n" "\n" @@ -321,14 +321,14 @@ enum class FragmentType void -GLVideoView::ensure_context () +GLVideoView::ensure_context() { if (!_context) { wxGLContextAttrs attrs; attrs.PlatformDefaults().CoreProfile().OGLVersion(4, 1).EndList(); - _context = new wxGLContext (_canvas, nullptr, &attrs); + _context = new wxGLContext(_canvas, nullptr, &attrs); if (!_context->IsOK()) { - throw GLError ("Making GL context", -1); + throw GLError("Making GL context", -1); } } } @@ -367,12 +367,12 @@ static constexpr int array_buffer_crop_guess_offset = array_buffer_outline_conte void -GLVideoView::setup_shaders () +GLVideoView::setup_shaders() { - DCPOMATIC_ASSERT (_canvas); - DCPOMATIC_ASSERT (_context); - auto r = _canvas->SetCurrent (*_context); - DCPOMATIC_ASSERT (r); + DCPOMATIC_ASSERT(_canvas); + DCPOMATIC_ASSERT(_context); + auto r = _canvas->SetCurrent(*_context); + DCPOMATIC_ASSERT(r); #ifdef DCPOMATIC_WINDOWS r = glewInit(); @@ -382,36 +382,36 @@ GLVideoView::setup_shaders () #endif auto get_information = [this](GLenum name) { - auto s = glGetString (name); + auto s = glGetString(name); if (s) { - _information[name] = std::string (reinterpret_cast<char const *>(s)); + _information[name] = std::string(reinterpret_cast<char const *>(s)); } }; - get_information (GL_VENDOR); - get_information (GL_RENDERER); - get_information (GL_VERSION); - get_information (GL_SHADING_LANGUAGE_VERSION); + get_information(GL_VENDOR); + get_information(GL_RENDERER); + get_information(GL_VERSION); + get_information(GL_SHADING_LANGUAGE_VERSION); glGenVertexArrays(1, &_vao); - check_gl_error ("glGenVertexArrays"); + check_gl_error("glGenVertexArrays"); GLuint vbo; glGenBuffers(1, &vbo); - check_gl_error ("glGenBuffers"); + check_gl_error("glGenBuffers"); GLuint ebo; glGenBuffers(1, &ebo); - check_gl_error ("glGenBuffers"); + check_gl_error("glGenBuffers"); glBindVertexArray(_vao); - check_gl_error ("glBindVertexArray"); + check_gl_error("glBindVertexArray"); glBindBuffer(GL_ARRAY_BUFFER, vbo); - check_gl_error ("glBindBuffer"); + check_gl_error("glBindBuffer"); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); - check_gl_error ("glBindBuffer"); + check_gl_error("glBindBuffer"); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); - check_gl_error ("glBufferData"); + check_gl_error("glBufferData"); /* position attribute to vertex shader (location = 0) */ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), nullptr); @@ -419,16 +419,16 @@ GLVideoView::setup_shaders () /* texture coord attribute to vertex shader (location = 1) */ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), reinterpret_cast<void*>(3 * sizeof(float))); glEnableVertexAttribArray(1); - check_gl_error ("glEnableVertexAttribArray"); + check_gl_error("glEnableVertexAttribArray"); auto compile = [](GLenum type, char const* source) -> GLuint { auto shader = glCreateShader(type); - DCPOMATIC_ASSERT (shader); + DCPOMATIC_ASSERT(shader); GLchar const * src[] = { static_cast<GLchar const *>(source) }; glShaderSource(shader, 1, src, nullptr); - check_gl_error ("glShaderSource"); + check_gl_error("glShaderSource"); glCompileShader(shader); - check_gl_error ("glCompileShader"); + check_gl_error("glCompileShader"); GLint ok; glGetShaderiv(shader, GL_COMPILE_STATUS, &ok); if (!ok) { @@ -446,19 +446,19 @@ GLVideoView::setup_shaders () return shader; }; - auto vertex_shader = compile (GL_VERTEX_SHADER, vertex_source); - auto fragment_shader = compile (GL_FRAGMENT_SHADER, fragment_source); + auto vertex_shader = compile(GL_VERTEX_SHADER, vertex_source); + auto fragment_shader = compile(GL_FRAGMENT_SHADER, fragment_source); auto program = glCreateProgram(); - check_gl_error ("glCreateProgram"); - glAttachShader (program, vertex_shader); - check_gl_error ("glAttachShader"); - glAttachShader (program, fragment_shader); - check_gl_error ("glAttachShader"); - glLinkProgram (program); - check_gl_error ("glLinkProgram"); + check_gl_error("glCreateProgram"); + glAttachShader(program, vertex_shader); + check_gl_error("glAttachShader"); + glAttachShader(program, fragment_shader); + check_gl_error("glAttachShader"); + glLinkProgram(program); + check_gl_error("glLinkProgram"); GLint ok; - glGetProgramiv (program, GL_LINK_STATUS, &ok); + glGetProgramiv(program, GL_LINK_STATUS, &ok); if (!ok) { GLint log_length; glGetProgramiv(program, GL_INFO_LOG_LENGTH, &log_length); @@ -468,13 +468,13 @@ GLVideoView::setup_shaders () glGetProgramInfoLog(program, log_length, nullptr, log_char.data()); log = string(log_char.data()); } - glDeleteProgram (program); + glDeleteProgram(program); throw GLError(String::compose("Could not link shader (%1)", log).c_str(), -1); } - glDeleteShader (vertex_shader); - glDeleteShader (fragment_shader); + glDeleteShader(vertex_shader); + glDeleteShader(fragment_shader); - glUseProgram (program); + glUseProgram(program); auto texture_0 = glGetUniformLocation(program, "texture_sampler_0"); check_gl_error("glGetUniformLocation"); glUniform1i(texture_0, 0); @@ -492,10 +492,10 @@ GLVideoView::setup_shaders () glUniform1i(texture_3, 3); check_gl_error("glUniform1i"); - _fragment_type = glGetUniformLocation (program, "type"); - check_gl_error ("glGetUniformLocation"); - set_outline_content_colour (program); - set_crop_guess_colour (program); + _fragment_type = glGetUniformLocation(program, "type"); + check_gl_error("glGetUniformLocation"); + set_outline_content_colour(program); + set_crop_guess_colour(program); auto ublas_to_gl = [](boost::numeric::ublas::matrix<double> const& ublas, GLfloat* gl) { gl[0] = static_cast<float>(ublas(0, 0)); @@ -518,12 +518,12 @@ GLVideoView::setup_shaders () { auto conversion = dcp::ColourConversion::rec709_to_xyz(); - boost::numeric::ublas::matrix<double> matrix = conversion.xyz_to_rgb (); + boost::numeric::ublas::matrix<double> matrix = conversion.xyz_to_rgb(); GLfloat gl_matrix[16]; ublas_to_gl(matrix, gl_matrix); auto xyz_rec709_colour_conversion = glGetUniformLocation(program, "xyz_rec709_colour_conversion"); - check_gl_error ("glGetUniformLocation"); + check_gl_error("glGetUniformLocation"); glUniformMatrix4fv(xyz_rec709_colour_conversion, 1, GL_TRUE, gl_matrix); } @@ -540,48 +540,48 @@ GLVideoView::setup_shaders () glUniformMatrix4fv(rec2020_rec709_colour_conversion, 1, GL_TRUE, gl_matrix); } - glLineWidth (1.0f); - check_gl_error ("glLineWidth"); - glEnable (GL_BLEND); - check_gl_error ("glEnable"); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - check_gl_error ("glBlendFunc"); + glLineWidth(1.0f); + check_gl_error("glLineWidth"); + glEnable(GL_BLEND); + check_gl_error("glEnable"); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + check_gl_error("glBlendFunc"); /* Reserve space for the GL_ARRAY_BUFFER */ glBufferData(GL_ARRAY_BUFFER, 16 * 5 * sizeof(float), nullptr, GL_STATIC_DRAW); - check_gl_error ("glBufferData"); + check_gl_error("glBufferData"); } void -GLVideoView::set_outline_content_colour (GLuint program) +GLVideoView::set_outline_content_colour(GLuint program) { - auto uniform = glGetUniformLocation (program, "outline_content_colour"); - check_gl_error ("glGetUniformLocation"); - auto colour = outline_content_colour (); - glUniform4f (uniform, colour.Red() / 255.0f, colour.Green() / 255.0f, colour.Blue() / 255.0f, 1.0f); - check_gl_error ("glUniform4f"); + auto uniform = glGetUniformLocation(program, "outline_content_colour"); + check_gl_error("glGetUniformLocation"); + auto colour = outline_content_colour(); + glUniform4f(uniform, colour.Red() / 255.0f, colour.Green() / 255.0f, colour.Blue() / 255.0f, 1.0f); + check_gl_error("glUniform4f"); } void -GLVideoView::set_crop_guess_colour (GLuint program) +GLVideoView::set_crop_guess_colour(GLuint program) { - auto uniform = glGetUniformLocation (program, "crop_guess_colour"); - check_gl_error ("glGetUniformLocation"); - auto colour = crop_guess_colour (); - glUniform4f (uniform, colour.Red() / 255.0f, colour.Green() / 255.0f, colour.Blue() / 255.0f, 1.0f); - check_gl_error ("glUniform4f"); + auto uniform = glGetUniformLocation(program, "crop_guess_colour"); + check_gl_error("glGetUniformLocation"); + auto colour = crop_guess_colour(); + glUniform4f(uniform, colour.Red() / 255.0f, colour.Green() / 255.0f, colour.Blue() / 255.0f, 1.0f); + check_gl_error("glUniform4f"); } void -GLVideoView::draw () +GLVideoView::draw() { auto pad = pad_colour(); glClearColor(pad.Red() / 255.0, pad.Green() / 255.0, pad.Blue() / 255.0, 1.0); - glClear (GL_COLOR_BUFFER_BIT); - check_gl_error ("glClear"); + glClear(GL_COLOR_BUFFER_BIT); + check_gl_error("glClear"); auto const size = _canvas_size.load(); int const width = size.GetWidth(); @@ -591,11 +591,11 @@ GLVideoView::draw () return; } - glViewport (0, 0, width, height); - check_gl_error ("glViewport"); + glViewport(0, 0, width, height); + check_gl_error("glViewport"); glBindVertexArray(_vao); - check_gl_error ("glBindVertexArray"); + check_gl_error("glBindVertexArray"); if (_optimisation == Optimisation::MPEG2) { glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::YUV420P_IMAGE)); } else if (_optimisation == Optimisation::JPEG2000) { @@ -608,32 +608,32 @@ GLVideoView::draw () for (auto& texture: _video_textures) { texture->bind(); } - glDrawElements (GL_TRIANGLES, indices_video_texture_number, GL_UNSIGNED_INT, reinterpret_cast<void*>(indices_video_texture_offset * sizeof(int))); + glDrawElements(GL_TRIANGLES, indices_video_texture_number, GL_UNSIGNED_INT, reinterpret_cast<void*>(indices_video_texture_offset * sizeof(int))); if (_have_subtitle_to_render) { glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::REC709_SUBTITLE)); _subtitle_texture->bind(); - glDrawElements (GL_TRIANGLES, indices_subtitle_texture_number, GL_UNSIGNED_INT, reinterpret_cast<void*>(indices_subtitle_texture_offset * sizeof(int))); + glDrawElements(GL_TRIANGLES, indices_subtitle_texture_number, GL_UNSIGNED_INT, reinterpret_cast<void*>(indices_subtitle_texture_offset * sizeof(int))); } if (_viewer->outline_content()) { glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::OUTLINE_CONTENT)); - glDrawElements (GL_LINES, indices_outline_content_number, GL_UNSIGNED_INT, reinterpret_cast<void*>(indices_outline_content_offset * sizeof(int))); - check_gl_error ("glDrawElements"); + glDrawElements(GL_LINES, indices_outline_content_number, GL_UNSIGNED_INT, reinterpret_cast<void*>(indices_outline_content_offset * sizeof(int))); + check_gl_error("glDrawElements"); } if (auto guess = _viewer->crop_guess()) { glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::CROP_GUESS)); - glDrawElements (GL_LINES, indices_crop_guess_number, GL_UNSIGNED_INT, reinterpret_cast<void*>(indices_crop_guess_offset * sizeof(int))); - check_gl_error ("glDrawElements"); + glDrawElements(GL_LINES, indices_crop_guess_number, GL_UNSIGNED_INT, reinterpret_cast<void*>(indices_crop_guess_offset * sizeof(int))); + check_gl_error("glDrawElements"); } glFlush(); - check_gl_error ("glFlush"); + check_gl_error("glFlush"); _canvas->SwapBuffers(); } void -GLVideoView::set_image (shared_ptr<const PlayerVideo> pv) +GLVideoView::set_image(shared_ptr<const PlayerVideo> pv) { shared_ptr<const Image> video; @@ -650,7 +650,7 @@ GLVideoView::set_image (shared_ptr<const PlayerVideo> pv) /* Only the player's black frames should be aligned at this stage, so this should * almost always have no work to do. */ - video = Image::ensure_alignment (video, Image::Alignment::COMPACT); + video = Image::ensure_alignment(video, Image::Alignment::COMPACT); /** If _optimisation is J2K we render a XYZ image, doing the colourspace * conversion, scaling and video range conversion in the GL shader. @@ -670,8 +670,8 @@ GLVideoView::set_image (shared_ptr<const PlayerVideo> pv) _have_subtitle_to_render = static_cast<bool>(text) && _optimisation != Optimisation::NONE; if (_have_subtitle_to_render) { /* opt: only do this if it's a new subtitle? */ - DCPOMATIC_ASSERT (text->image->alignment() == Image::Alignment::COMPACT); - _subtitle_texture->set (text->image); + DCPOMATIC_ASSERT(text->image->alignment() == Image::Alignment::COMPACT); + _subtitle_texture->set(text->image); } auto const canvas_size = _canvas_size.load(); @@ -685,18 +685,18 @@ GLVideoView::set_image (shared_ptr<const PlayerVideo> pv) auto x_offset = std::max(0, (canvas_width - out_size.width) / 2); auto y_offset = std::max(0, (canvas_height - out_size.height) / 2); - _last_canvas_size.set_next (canvas_size); - _last_video_size.set_next (video->size()); - _last_inter_position.set_next (inter_position); - _last_inter_size.set_next (inter_size); - _last_out_size.set_next (out_size); - _last_crop_guess.set_next (crop_guess); + _last_canvas_size.set_next(canvas_size); + _last_video_size.set_next(video->size()); + _last_inter_position.set_next(inter_position); + _last_inter_size.set_next(inter_size); + _last_out_size.set_next(out_size); + _last_crop_guess.set_next(crop_guess); class Rectangle { public: - Rectangle (wxSize canvas_size, float x, float y, dcp::Size size) - : _canvas_size (canvas_size) + Rectangle(wxSize canvas_size, float x, float y, dcp::Size size) + : _canvas_size(canvas_size) { auto const x1 = x_pixels_to_gl(x); auto const y1 = y_pixels_to_gl(y); @@ -737,11 +737,11 @@ GLVideoView::set_image (shared_ptr<const PlayerVideo> pv) _vertices[19] = 1.0f; } - float const * vertices () const { + float const * vertices() const { return _vertices; } - int const size () const { + int const size() const { return sizeof(_vertices); } @@ -767,12 +767,12 @@ GLVideoView::set_image (shared_ptr<const PlayerVideo> pv) ? Rectangle(canvas_size, x_offset, y_offset, out_size) : Rectangle(canvas_size, inter_position.x + x_offset, inter_position.y + y_offset, inter_size); - glBufferSubData (GL_ARRAY_BUFFER, array_buffer_video_offset, video.size(), video.vertices()); - check_gl_error ("glBufferSubData (video)"); + glBufferSubData(GL_ARRAY_BUFFER, array_buffer_video_offset, video.size(), video.vertices()); + check_gl_error("glBufferSubData (video)"); const auto outline_content = Rectangle(canvas_size, inter_position.x + x_offset, inter_position.y + y_offset, inter_size); - glBufferSubData (GL_ARRAY_BUFFER, array_buffer_outline_content_offset, outline_content.size(), outline_content.vertices()); - check_gl_error ("glBufferSubData (outline_content)"); + glBufferSubData(GL_ARRAY_BUFFER, array_buffer_outline_content_offset, outline_content.size(), outline_content.vertices()); + check_gl_error("glBufferSubData (outline_content)"); } if ((sizing_changed || _last_crop_guess.changed()) && crop_guess) { @@ -782,14 +782,14 @@ GLVideoView::set_image (shared_ptr<const PlayerVideo> pv) inter_position.y + y_offset + inter_size.height * crop_guess->y, dcp::Size(inter_size.width * crop_guess->width, inter_size.height * crop_guess->height) ); - glBufferSubData (GL_ARRAY_BUFFER, array_buffer_crop_guess_offset, crop_guess_rectangle.size(), crop_guess_rectangle.vertices()); - check_gl_error ("glBufferSubData (crop_guess_rectangle)"); + glBufferSubData(GL_ARRAY_BUFFER, array_buffer_crop_guess_offset, crop_guess_rectangle.size(), crop_guess_rectangle.vertices()); + check_gl_error("glBufferSubData (crop_guess_rectangle)"); } if (_have_subtitle_to_render) { const auto subtitle = Rectangle(canvas_size, inter_position.x + x_offset + text->position.x, inter_position.y + y_offset + text->position.y, text->image->size()); - glBufferSubData (GL_ARRAY_BUFFER, array_buffer_subtitle_offset, subtitle.size(), subtitle.vertices()); - check_gl_error ("glBufferSubData (subtitle)"); + glBufferSubData(GL_ARRAY_BUFFER, array_buffer_subtitle_offset, subtitle.size(), subtitle.vertices()); + check_gl_error("glBufferSubData (subtitle)"); } _rec2020 = pv->colour_conversion() && pv->colour_conversion()->about_equal(dcp::ColourConversion::rec2020_to_xyz(), 1e-6); @@ -797,57 +797,57 @@ GLVideoView::set_image (shared_ptr<const PlayerVideo> pv) /* opt: where should these go? */ for (auto i = 0; i < 3; ++i) { _video_textures[i]->bind(); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - check_gl_error ("glTexParameteri"); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + check_gl_error("glTexParameteri"); - glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - check_gl_error ("glTexParameterf"); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + check_gl_error("glTexParameterf"); } _subtitle_texture->bind(); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - check_gl_error ("glTexParameteri"); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + check_gl_error("glTexParameteri"); - glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - check_gl_error ("glTexParameterf"); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + check_gl_error("glTexParameterf"); } void -GLVideoView::start () +GLVideoView::start() { - VideoView::start (); + VideoView::start(); - boost::mutex::scoped_lock lm (_playing_mutex); + boost::mutex::scoped_lock lm(_playing_mutex); _playing = true; - _thread_work_condition.notify_all (); + _thread_work_condition.notify_all(); } void -GLVideoView::stop () +GLVideoView::stop() { - boost::mutex::scoped_lock lm (_playing_mutex); + boost::mutex::scoped_lock lm(_playing_mutex); _playing = false; } void -GLVideoView::thread_playing () +GLVideoView::thread_playing() { if (length() != dcpomatic::DCPTime()) { auto const next = position() + one_video_frame(); if (next >= length()) { - _viewer->finished (); + _viewer->finished(); return; } - get_next_frame (false); - set_image_and_draw (); + get_next_frame(false); + set_image_and_draw(); } while (true) { @@ -855,42 +855,42 @@ GLVideoView::thread_playing () if (!n || *n > 5) { break; } - get_next_frame (true); - add_dropped (); + get_next_frame(true); + add_dropped(); } } void -GLVideoView::set_image_and_draw () +GLVideoView::set_image_and_draw() { auto pv = player_video().first; if (pv) { - set_image (pv); + set_image(pv); } - draw (); + draw(); if (pv) { - _viewer->image_changed (pv); + _viewer->image_changed(pv); } } void -GLVideoView::thread () +GLVideoView::thread() try { - start_of_thread ("GLVideoView"); + start_of_thread("GLVideoView"); #if defined(DCPOMATIC_OSX) /* Without this we see errors like * ../src/osx/cocoa/glcanvas.mm(194): assert ""context"" failed in SwapBuffers(): should have current context [in thread 700006970000] */ - WXGLSetCurrentContext (_context->GetWXGLContext()); + WXGLSetCurrentContext(_context->GetWXGLContext()); #else if (!_setup_shaders_done) { - setup_shaders (); + setup_shaders(); _setup_shaders_done = true; } #endif @@ -899,7 +899,7 @@ try if (_canvas->IsExtensionSupported("GLX_EXT_swap_control")) { /* Enable vsync */ Display* dpy = wxGetX11Display(); - glXSwapIntervalEXT (dpy, DefaultScreen(dpy), 1); + glXSwapIntervalEXT(dpy, DefaultScreen(dpy), 1); _vsync_enabled = true; } #endif @@ -909,7 +909,7 @@ try /* Enable vsync */ PFNWGLSWAPINTERVALEXTPROC swap = (PFNWGLSWAPINTERVALEXTPROC) wglGetProcAddress("wglSwapIntervalEXT"); if (swap) { - swap (1); + swap(1); _vsync_enabled = true; } } @@ -919,7 +919,7 @@ try #ifdef DCPOMATIC_OSX /* Enable vsync */ GLint swapInterval = 1; - CGLSetParameter (CGLGetCurrentContext(), kCGLCPSwapInterval, &swapInterval); + CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &swapInterval); _vsync_enabled = true; #endif @@ -930,21 +930,21 @@ try _subtitle_texture.reset(new Texture(1, 3)); while (true) { - boost::mutex::scoped_lock lm (_playing_mutex); + boost::mutex::scoped_lock lm(_playing_mutex); while (!_playing && !_one_shot) { - _thread_work_condition.wait (lm); + _thread_work_condition.wait(lm); } - lm.unlock (); + lm.unlock(); if (_playing) { - thread_playing (); + thread_playing(); } else if (_one_shot) { _one_shot = false; - set_image_and_draw (); + set_image_and_draw(); } - boost::this_thread::interruption_point (); - dcpomatic_sleep_milliseconds (time_until_next_frame().get_value_or(0)); + boost::this_thread::interruption_point(); + dcpomatic_sleep_milliseconds(time_until_next_frame().get_value_or(0)); } /* XXX: leaks _context, but that seems preferable to deleting it here @@ -953,50 +953,50 @@ try } catch (...) { - store_current (); + store_current(); } VideoView::NextFrameResult -GLVideoView::display_next_frame (bool non_blocking) +GLVideoView::display_next_frame(bool non_blocking) { - NextFrameResult const r = get_next_frame (non_blocking); - request_one_shot (); + NextFrameResult const r = get_next_frame(non_blocking); + request_one_shot(); return r; } void -GLVideoView::request_one_shot () +GLVideoView::request_one_shot() { - boost::mutex::scoped_lock lm (_playing_mutex); + boost::mutex::scoped_lock lm(_playing_mutex); _one_shot = true; - _thread_work_condition.notify_all (); + _thread_work_condition.notify_all(); } Texture::Texture(GLint unpack_alignment, int unit) - : _unpack_alignment (unpack_alignment) + : _unpack_alignment(unpack_alignment) , _unit(unit) { - glGenTextures (1, &_name); - check_gl_error ("glGenTextures"); + glGenTextures(1, &_name); + check_gl_error("glGenTextures"); } -Texture::~Texture () +Texture::~Texture() { - glDeleteTextures (1, &_name); + glDeleteTextures(1, &_name); } void -Texture::bind () +Texture::bind() { glActiveTexture(GL_TEXTURE0 + _unit); check_gl_error("glActiveTexture"); glBindTexture(GL_TEXTURE_2D, _name); - check_gl_error ("glBindTexture"); + check_gl_error("glBindTexture"); } @@ -1006,10 +1006,10 @@ Texture::set(shared_ptr<const Image> image, int component) auto const create = !_size || image->size() != _size; _size = image->size(); - glPixelStorei (GL_UNPACK_ALIGNMENT, _unpack_alignment); - check_gl_error ("glPixelStorei"); + glPixelStorei(GL_UNPACK_ALIGNMENT, _unpack_alignment); + check_gl_error("glPixelStorei"); - DCPOMATIC_ASSERT (image->alignment() == Image::Alignment::COMPACT); + DCPOMATIC_ASSERT(image->alignment() == Image::Alignment::COMPACT); GLint internal_format; GLenum format; @@ -1044,17 +1044,17 @@ Texture::set(shared_ptr<const Image> image, int component) type = GL_UNSIGNED_SHORT; break; default: - throw PixelFormatError ("Texture::set", image->pixel_format()); + throw PixelFormatError("Texture::set", image->pixel_format()); } - bind (); + bind(); if (create) { - glTexImage2D (GL_TEXTURE_2D, 0, internal_format, _size->width / subsample, _size->height / subsample, 0, format, type, image->data()[component]); - check_gl_error ("glTexImage2D"); + glTexImage2D(GL_TEXTURE_2D, 0, internal_format, _size->width / subsample, _size->height / subsample, 0, format, type, image->data()[component]); + check_gl_error("glTexImage2D"); } else { - glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, _size->width / subsample, _size->height / subsample, format, type, image->data()[component]); - check_gl_error ("glTexSubImage2D"); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _size->width / subsample, _size->height / subsample, format, type, image->data()[component]); + check_gl_error("glTexSubImage2D"); } } diff --git a/src/wx/gl_video_view.h b/src/wx/gl_video_view.h index 25750b64b..dc048e6b0 100644 --- a/src/wx/gl_video_view.h +++ b/src/wx/gl_video_view.h @@ -52,12 +52,12 @@ class Texture { public: Texture(GLint unpack_alignment, int unit = 0); - ~Texture (); + ~Texture(); - Texture (Texture const&) = delete; - Texture& operator= (Texture const&) = delete; + Texture(Texture const&) = delete; + Texture& operator=(Texture const&) = delete; - void bind (); + void bind(); void set(std::shared_ptr<const Image> image, int component = 0); private: @@ -71,39 +71,39 @@ private: class GLVideoView : public VideoView { public: - GLVideoView (FilmViewer* viewer, wxWindow* parent); - ~GLVideoView (); + GLVideoView(FilmViewer* viewer, wxWindow* parent); + ~GLVideoView(); - wxWindow* get () const override { + wxWindow* get() const override { return _canvas; } - void update () override; - void start () override; - void stop () override; + void update() override; + void start() override; + void stop() override; - NextFrameResult display_next_frame (bool) override; + NextFrameResult display_next_frame(bool) override; - bool vsync_enabled () const { + bool vsync_enabled() const { return _vsync_enabled; } - std::map<GLenum, std::string> information () const { + std::map<GLenum, std::string> information() const { return _information; } private: - void set_image (std::shared_ptr<const PlayerVideo> pv); - void set_image_and_draw (); - void draw (); - void thread (); - void thread_playing (); - void request_one_shot (); - void check_for_butler_errors (); - void ensure_context (); - void size_changed (wxSizeEvent const &); - void setup_shaders (); - void set_outline_content_colour (GLuint program); - void set_crop_guess_colour (GLuint program); + void set_image(std::shared_ptr<const PlayerVideo> pv); + void set_image_and_draw(); + void draw(); + void thread(); + void thread_playing(); + void request_one_shot(); + void check_for_butler_errors(); + void ensure_context(); + void size_changed(wxSizeEvent const &); + void setup_shaders(); + void set_outline_content_colour(GLuint program); + void set_crop_guess_colour(GLuint program); wxGLCanvas* _canvas; wxGLContext* _context; @@ -112,15 +112,15 @@ private: class Last { public: - void set_next (T const& next) { + void set_next(T const& next) { _next = next; } - bool changed () const { + bool changed() const { return !_value || *_value != _next; } - void update () { + void update() { _value = _next; } |
