mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-28 22:29:36 +00:00
Sought to shift locking back up to the CRT. And to be a bit more RAII-ish.
This commit is contained in:
parent
60f9ddfde8
commit
4ff33254e1
@ -110,6 +110,7 @@ Flywheel::SyncEvent CRT::get_next_horizontal_sync_event(bool hsync_is_requested,
|
|||||||
|
|
||||||
void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divider, bool hsync_requested, bool vsync_requested, const bool vsync_charging, const Scan::Type type, uint16_t tex_x, uint16_t tex_y)
|
void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divider, bool hsync_requested, bool vsync_requested, const bool vsync_charging, const Scan::Type type, uint16_t tex_x, uint16_t tex_y)
|
||||||
{
|
{
|
||||||
|
std::unique_lock<std::mutex> output_lock = openGL_output_builder_.get_output_lock();
|
||||||
number_of_cycles *= time_multiplier_;
|
number_of_cycles *= time_multiplier_;
|
||||||
|
|
||||||
bool is_output_run = ((type == Scan::Type::Level) || (type == Scan::Type::Data));
|
bool is_output_run = ((type == Scan::Type::Level) || (type == Scan::Type::Data));
|
||||||
@ -189,8 +190,6 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
openGL_output_builder_.lock_output();
|
|
||||||
|
|
||||||
// Get and write all those previously unwritten output ys
|
// Get and write all those previously unwritten output ys
|
||||||
const uint16_t output_y = openGL_output_builder_.get_composite_output_y();
|
const uint16_t output_y = openGL_output_builder_.get_composite_output_y();
|
||||||
|
|
||||||
@ -221,8 +220,6 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi
|
|||||||
(*(uint16_t *)&input_buffer[position + SourceVertexOffsetOfOutputStart + 2]) = output_y;
|
(*(uint16_t *)&input_buffer[position + SourceVertexOffsetOfOutputStart + 2]) = output_y;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
openGL_output_builder_.unlock_output();
|
|
||||||
}
|
}
|
||||||
is_writing_composite_run_ ^= true;
|
is_writing_composite_run_ ^= true;
|
||||||
}
|
}
|
||||||
@ -320,24 +317,11 @@ void CRT::output_blank(unsigned int number_of_cycles)
|
|||||||
|
|
||||||
void CRT::output_level(unsigned int number_of_cycles)
|
void CRT::output_level(unsigned int number_of_cycles)
|
||||||
{
|
{
|
||||||
if(!openGL_output_builder_.array_builder.is_full())
|
Scan scan {
|
||||||
{
|
.type = Scan::Type::Level,
|
||||||
Scan scan {
|
.number_of_cycles = number_of_cycles,
|
||||||
.type = Scan::Type::Level,
|
};
|
||||||
.number_of_cycles = number_of_cycles,
|
output_scan(&scan);
|
||||||
// .tex_x = openGL_output_builder_.texture_builder.get_last_write_x_position(),
|
|
||||||
// .tex_y = openGL_output_builder_.texture_builder.get_last_write_y_position()
|
|
||||||
};
|
|
||||||
output_scan(&scan);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Scan scan {
|
|
||||||
.type = Scan::Type::Blank,
|
|
||||||
.number_of_cycles = number_of_cycles
|
|
||||||
};
|
|
||||||
output_scan(&scan);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRT::output_colour_burst(unsigned int number_of_cycles, uint8_t phase, uint8_t amplitude)
|
void CRT::output_colour_burst(unsigned int number_of_cycles, uint8_t phase, uint8_t amplitude)
|
||||||
@ -353,26 +337,13 @@ void CRT::output_colour_burst(unsigned int number_of_cycles, uint8_t phase, uint
|
|||||||
|
|
||||||
void CRT::output_data(unsigned int number_of_cycles, unsigned int source_divider)
|
void CRT::output_data(unsigned int number_of_cycles, unsigned int source_divider)
|
||||||
{
|
{
|
||||||
if(!openGL_output_builder_.array_builder.is_full())
|
openGL_output_builder_.texture_builder.reduce_previous_allocation_to(number_of_cycles / source_divider);
|
||||||
{
|
Scan scan {
|
||||||
openGL_output_builder_.texture_builder.reduce_previous_allocation_to(number_of_cycles / source_divider);
|
.type = Scan::Type::Data,
|
||||||
Scan scan {
|
.number_of_cycles = number_of_cycles,
|
||||||
.type = Scan::Type::Data,
|
.source_divider = source_divider
|
||||||
.number_of_cycles = number_of_cycles,
|
};
|
||||||
// .tex_x = openGL_output_builder_.texture_builder.get_last_write_x_position(),
|
output_scan(&scan);
|
||||||
// .tex_y = openGL_output_builder_.texture_builder.get_last_write_y_position(),
|
|
||||||
.source_divider = source_divider
|
|
||||||
};
|
|
||||||
output_scan(&scan);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Scan scan {
|
|
||||||
.type = Scan::Type::Blank,
|
|
||||||
.number_of_cycles = number_of_cycles
|
|
||||||
};
|
|
||||||
output_scan(&scan);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Outputs::CRT::Rect CRT::get_rect_for_area(int first_line_after_sync, int number_of_lines, int first_cycle_after_sync, int number_of_cycles, float aspect_ratio)
|
Outputs::CRT::Rect CRT::get_rect_for_area(int first_line_after_sync, int number_of_lines, int first_cycle_after_sync, int number_of_cycles, float aspect_ratio)
|
||||||
|
@ -192,6 +192,7 @@ class CRT {
|
|||||||
*/
|
*/
|
||||||
inline uint8_t *allocate_write_area(size_t required_length)
|
inline uint8_t *allocate_write_area(size_t required_length)
|
||||||
{
|
{
|
||||||
|
std::unique_lock<std::mutex> output_lock = openGL_output_builder_.get_output_lock();
|
||||||
return openGL_output_builder_.texture_builder.allocate_write_area(required_length);
|
return openGL_output_builder_.texture_builder.allocate_write_area(required_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@ ArrayBuilder::ArrayBuilder(size_t input_size, size_t output_size, std::function<
|
|||||||
bool ArrayBuilder::is_full()
|
bool ArrayBuilder::is_full()
|
||||||
{
|
{
|
||||||
bool was_full;
|
bool was_full;
|
||||||
std::lock_guard<std::mutex> guard(buffer_mutex_);
|
|
||||||
was_full = is_full_;
|
was_full = is_full_;
|
||||||
return was_full;
|
return was_full;
|
||||||
}
|
}
|
||||||
@ -40,7 +39,6 @@ uint8_t *ArrayBuilder::get_output_storage(size_t size)
|
|||||||
|
|
||||||
void ArrayBuilder::flush(const std::function<void(uint8_t *input, size_t input_size, uint8_t *output, size_t output_size)> &function)
|
void ArrayBuilder::flush(const std::function<void(uint8_t *input, size_t input_size, uint8_t *output, size_t output_size)> &function)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(buffer_mutex_);
|
|
||||||
if(!is_full_)
|
if(!is_full_)
|
||||||
{
|
{
|
||||||
size_t input_size, output_size;
|
size_t input_size, output_size;
|
||||||
@ -67,7 +65,6 @@ ArrayBuilder::Submission ArrayBuilder::submit()
|
|||||||
{
|
{
|
||||||
ArrayBuilder::Submission submission;
|
ArrayBuilder::Submission submission;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> guard(buffer_mutex_);
|
|
||||||
submission.input_size = input_.submit(true);
|
submission.input_size = input_.submit(true);
|
||||||
submission.output_size = output_.submit(false);
|
submission.output_size = output_.submit(false);
|
||||||
if(is_full_)
|
if(is_full_)
|
||||||
@ -102,7 +99,6 @@ ArrayBuilder::Buffer::~Buffer()
|
|||||||
|
|
||||||
uint8_t *ArrayBuilder::get_storage(size_t size, Buffer &buffer)
|
uint8_t *ArrayBuilder::get_storage(size_t size, Buffer &buffer)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(buffer_mutex_);
|
|
||||||
uint8_t *pointer = buffer.get_storage(size);
|
uint8_t *pointer = buffer.get_storage(size);
|
||||||
if(!pointer) is_full_ = true;
|
if(!pointer) is_full_ = true;
|
||||||
return pointer;
|
return pointer;
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
#ifndef ArrayBuilder_hpp
|
#ifndef ArrayBuilder_hpp
|
||||||
#define ArrayBuilder_hpp
|
#define ArrayBuilder_hpp
|
||||||
|
|
||||||
#include <vector>
|
#include <functional>
|
||||||
#include <mutex>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "OpenGL.hpp"
|
#include "OpenGL.hpp"
|
||||||
|
|
||||||
@ -92,7 +92,6 @@ class ArrayBuilder {
|
|||||||
} output_, input_;
|
} output_, input_;
|
||||||
uint8_t *get_storage(size_t size, Buffer &buffer);
|
uint8_t *get_storage(size_t size, Buffer &buffer);
|
||||||
|
|
||||||
std::mutex buffer_mutex_;
|
|
||||||
bool is_full_;
|
bool is_full_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -90,6 +90,7 @@ class OpenGLOutputBuilder {
|
|||||||
GLsync fence_;
|
GLsync fence_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// These two are protected by output_mutex_.
|
||||||
TextureBuilder texture_builder;
|
TextureBuilder texture_builder;
|
||||||
ArrayBuilder array_builder;
|
ArrayBuilder array_builder;
|
||||||
|
|
||||||
@ -98,12 +99,11 @@ class OpenGLOutputBuilder {
|
|||||||
|
|
||||||
inline void set_colour_format(ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator)
|
inline void set_colour_format(ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator)
|
||||||
{
|
{
|
||||||
output_mutex_.lock();
|
std::lock_guard<std::mutex> output_guard(output_mutex_);
|
||||||
colour_space_ = colour_space;
|
colour_space_ = colour_space;
|
||||||
colour_cycle_numerator_ = colour_cycle_numerator;
|
colour_cycle_numerator_ = colour_cycle_numerator;
|
||||||
colour_cycle_denominator_ = colour_cycle_denominator;
|
colour_cycle_denominator_ = colour_cycle_denominator;
|
||||||
set_colour_space_uniforms();
|
set_colour_space_uniforms();
|
||||||
output_mutex_.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void set_visible_area(Rect visible_area)
|
inline void set_visible_area(Rect visible_area)
|
||||||
@ -111,14 +111,9 @@ class OpenGLOutputBuilder {
|
|||||||
visible_area_ = visible_area;
|
visible_area_ = visible_area;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void lock_output()
|
inline std::unique_lock<std::mutex> get_output_lock()
|
||||||
{
|
{
|
||||||
output_mutex_.lock();
|
return std::unique_lock<std::mutex>(output_mutex_);
|
||||||
}
|
|
||||||
|
|
||||||
inline void unlock_output()
|
|
||||||
{
|
|
||||||
output_mutex_.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline OutputDevice get_output_device()
|
inline OutputDevice get_output_device()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user