From c1a509910dc2499cf6b4aba69f2f5de28cd52b73 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 16 Nov 2016 13:15:50 +0800 Subject: [PATCH] Documented this interface, albeit that the English could do with a second pass, and very sightly simplified inline with current usage. --- Outputs/CRT/Internals/CRTOpenGL.hpp | 3 +-- Outputs/CRT/Internals/InputTextureBuilder.cpp | 12 +++++------- Outputs/CRT/Internals/InputTextureBuilder.hpp | 10 +++++++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Outputs/CRT/Internals/CRTOpenGL.hpp b/Outputs/CRT/Internals/CRTOpenGL.hpp index b7a8b86e7..3a7035e36 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.hpp +++ b/Outputs/CRT/Internals/CRTOpenGL.hpp @@ -183,8 +183,7 @@ class OpenGLOutputBuilder { inline uint8_t *allocate_write_area(size_t required_length) { - _texture_builder->allocate_write_area(required_length); - return _texture_builder->get_write_target(); + return _texture_builder->allocate_write_area(required_length); } inline void reduce_previous_allocation_to(size_t actual_length) diff --git a/Outputs/CRT/Internals/InputTextureBuilder.cpp b/Outputs/CRT/Internals/InputTextureBuilder.cpp index 8b3d6103b..2a027ffaa 100644 --- a/Outputs/CRT/Internals/InputTextureBuilder.cpp +++ b/Outputs/CRT/Internals/InputTextureBuilder.cpp @@ -20,7 +20,7 @@ InputTextureBuilder::InputTextureBuilder(size_t bytes_per_pixel) : _image.resize(bytes_per_pixel * InputBufferBuilderWidth * InputBufferBuilderHeight); } -void InputTextureBuilder::allocate_write_area(size_t required_length) +uint8_t *InputTextureBuilder::allocate_write_area(size_t required_length) { if(_next_write_y_position != InputBufferBuilderHeight) { @@ -32,7 +32,7 @@ void InputTextureBuilder::allocate_write_area(size_t required_length) _next_write_y_position++; if(_next_write_y_position == InputBufferBuilderHeight) - return; + return nullptr; } _write_x_position = _next_write_x_position + 1; @@ -40,6 +40,9 @@ void InputTextureBuilder::allocate_write_area(size_t required_length) _write_target_pointer = (_write_y_position * InputBufferBuilderWidth) + _write_x_position; _next_write_x_position += required_length + 2; } + else return nullptr; + + return &_image[_write_target_pointer * _bytes_per_pixel]; } bool InputTextureBuilder::is_full() @@ -90,11 +93,6 @@ uint16_t InputTextureBuilder::get_and_finalise_current_line() return result; } -uint8_t *InputTextureBuilder::get_write_target() -{ - return (_next_write_y_position == InputBufferBuilderHeight) ? nullptr : &_image[_write_target_pointer * _bytes_per_pixel]; -} - uint16_t InputTextureBuilder::get_last_write_x_position() { return _write_x_position; diff --git a/Outputs/CRT/Internals/InputTextureBuilder.hpp b/Outputs/CRT/Internals/InputTextureBuilder.hpp index a42081b9a..5dc930dd5 100644 --- a/Outputs/CRT/Internals/InputTextureBuilder.hpp +++ b/Outputs/CRT/Internals/InputTextureBuilder.hpp @@ -31,7 +31,8 @@ class InputTextureBuilder { /// Finds the first available space of at least @c required_length pixels in size. Calls must be paired off /// with calls to @c reduce_previous_allocation_to. - void allocate_write_area(size_t required_length); + /// @returns a pointer to the allocated space if any was available; @c nullptr otherwise. + uint8_t *allocate_write_area(size_t required_length); /// Announces that the owner is finished with the region created by the most recent @c allocate_write_area /// and indicates that its actual final size was @c actual_length. @@ -44,14 +45,17 @@ class InputTextureBuilder { /// @returns a pointer to the image data for this texture. uint8_t *get_image_pointer(); - uint8_t *get_write_target(); - + /// @returns the start column for the most recent allocated write area. uint16_t get_last_write_x_position(); + /// @returns the row of the most recent allocated write area. uint16_t get_last_write_y_position(); + /// @returns the number of bytes per pixel as supplied to the constructor. size_t get_bytes_per_pixel(); + /// @returns @c true if all future calls to @c allocate_write_area will fail on account of the input texture + /// being full; @c false if calls may succeed. bool is_full(); private: