Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 6 additions & 22 deletions libGraphite/data/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <fstream>
#include <iostream>
#include <cassert>
#include <cstring>
#include "libGraphite/data/data.hpp"
#include "libGraphite/data/simd.hpp"

Expand Down Expand Up @@ -291,45 +292,28 @@ __attribute__((optnone)) auto graphite::data::block::copy_from(const block &sour
m_extended = source.m_extended;

std::size_t len = std::min(source.size(), size());
std::size_t n = 0;
while (n < len) {
if ((reinterpret_cast<uintptr_t>(source_ptr) & simd::alignment_width) || (len - n) < simd::fields_length) {
*dest_ptr = *source_ptr;
++dest_ptr;
++source_ptr;
n += simd::field_size;
}
else {
*reinterpret_cast<simd::wide_type *>(dest_ptr) = *reinterpret_cast<simd::wide_type *>(source_ptr);
dest_ptr += simd::field_count;
source_ptr += simd::field_count;
n += simd::alignment_width;
}
}
memcpy(dest_ptr, source_ptr, len);
}

// MARK: - Operations

auto graphite::data::block::increase_size_to(std::size_t new_size) -> void
{
if (new_size > m_raw_size) {
throw std::runtime_error("Attempted to increase size of data::block beyond allowed range.");
m_raw_size = std::max(m_data_size * 2, new_size);
m_raw = m_data = realloc(m_raw, m_raw_size);
}
m_data_size = new_size;
}

auto graphite::data::block::clear() -> void
{
set((uint32_t)0);
set((uint8_t)0, size());
}

auto graphite::data::block::set(uint8_t value, std::size_t bytes, block::position start) -> void
{
union simd::value v;
for (unsigned char & byte : v.bytes) {
byte = value;
}
simd::set(get<std::uint32_t *>(start), size() - start, v, bytes);
memset(get<std::uint8_t *>(start), value, bytes);
}

__attribute__((optnone)) auto graphite::data::block::set(uint16_t value, std::size_t bytes, block::position start) -> void
Expand Down
18 changes: 2 additions & 16 deletions libGraphite/data/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,7 @@ auto graphite::data::writer::expand_storage(std::size_t amount) -> void
// NOTE: We only allow resizing of data objects that we own.
assert(m_owns_data);

// Construct a new data object with the appropriate new size, and copy in the old data.
auto required_size = size() + amount;
if (required_size < m_data->raw_size()) {
const_cast<class block *>(m_data)->increase_size_to(required_size);
}
else {
auto allocation_size = size() + std::max(size(), amount);
auto new_data = new class block(required_size, std::max(allocation_size, required_size), m_data->byte_order());
new_data->set(static_cast<uint32_t>(0), allocation_size);
new_data->copy_from(*m_data);

// Replace the old data with the new object.
delete m_data;
m_data = new_data;
}
const_cast<class block *>(m_data)->increase_size_to(size() + amount);

}

Expand Down Expand Up @@ -232,4 +218,4 @@ auto graphite::data::writer::save(const std::string &path, std::size_t size) con
std::ofstream file { path, std::ios::out | std::ios::binary };
file.write(m_data->get<char *>(), size == 0 ? m_data->size() : size);
file.close();
}
}
8 changes: 4 additions & 4 deletions libGraphite/quickdraw/support/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ graphite::quickdraw::surface::surface(const quickdraw::size<std::int16_t> &size)
m_row_bytes(size.width * constants::color_width),
m_data(new data::block(size.width * size.height * constants::color_width))
{
m_data->set(static_cast<std::uint32_t>(0), m_data->size());
m_data->clear();
}

graphite::quickdraw::surface::surface(std::int16_t width, std::int16_t height)
: m_size(width, height),
m_row_bytes(width * constants::color_width),
m_data(new data::block(width * height * constants::color_width))
{
m_data->set(static_cast<std::uint32_t>(0), m_data->size());
m_data->clear();
}

graphite::quickdraw::surface::surface(const quickdraw::size<std::int16_t>& size, union color color)
Expand Down Expand Up @@ -157,5 +157,5 @@ auto graphite::quickdraw::surface::set(std::uint32_t offset, union color color)

auto graphite::quickdraw::surface::clear() -> void
{
m_data->set(colors::clear().value, m_data->size());
}
m_data->clear();
}
4 changes: 2 additions & 2 deletions libGraphite/spriteworld/rleD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ auto graphite::spriteworld::rleD::decode(data::reader &reader) -> void

// Create the surface in which all frame will be draw to, and other working variables required to parse and decode
// the RLE data correctly.
m_surface = quickdraw::surface(m_grid_size.width * m_frame_size.width, m_grid_size.height * m_frame_size.height, quickdraw::colors::clear());
m_surface = quickdraw::surface(m_grid_size.width * m_frame_size.width, m_grid_size.height * m_frame_size.height);

rleD::opcode opcode = opcode::eof;
std::uint64_t position = 0;
Expand Down Expand Up @@ -383,4 +383,4 @@ auto graphite::spriteworld::rleD::encode(data::writer &writer) -> void
writer.write_enum(opcode::eof);
writer.write_triple(0);
}
}
}
2 changes: 1 addition & 1 deletion libGraphite/spriteworld/rleX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ auto graphite::spriteworld::rleX::decode(data::reader &reader) -> void

// Create the surface in which all frames will be drawn to, and other working variables required to parse and
// decode the RLE data correctly.
m_surface = quickdraw::surface(dim * m_frame_size.width, dim * m_frame_size.height, quickdraw::colors::clear());
m_surface = quickdraw::surface(dim * m_frame_size.width, dim * m_frame_size.height);

std::uint32_t current_frame = 0;
std::uint32_t count = 0;
Expand Down