openMSX
RawFrame.cc
Go to the documentation of this file.
1#include "RawFrame.hh"
2
3namespace openmsx {
4
5[[nodiscard]] static unsigned calcMaxWidth(unsigned maxWidth)
6{
7 unsigned bytes = maxWidth * sizeof(RawFrame::Pixel);
8 bytes = (bytes + 63) & ~63; // round up to cache-line size
9 return bytes / sizeof(RawFrame::Pixel);
10}
11
12RawFrame::RawFrame(unsigned maxWidth_, unsigned height_)
13 : lineWidths(height_)
14 , maxWidth(calcMaxWidth(maxWidth_))
15{
16 setHeight(height_);
17
18 // Allocate memory, make sure each line starts at a 64 byte boundary:
19 // - SSE instructions need 16 byte aligned data
20 // - cache line size on many CPUs is 64 bytes
21 data.resize(size_t(maxWidth) * height_);
22
23 // Start with a black frame.
25 for (auto line : xrange(height_)) {
26 setBlank(line, Pixel(0));
27 }
28}
29
30unsigned RawFrame::getLineWidth(unsigned line) const
31{
32 assert(line < getHeight());
33 return lineWidths[line];
34}
35
36std::span<const RawFrame::Pixel> RawFrame::getUnscaledLine(
37 unsigned line, std::span<Pixel> /*helpBuf*/) const
38{
39 return getLineDirect(line).subspan(0, lineWidths[line]);
40}
41
42bool RawFrame::hasContiguousStorage() const
43{
44 return true;
45}
46
47} // namespace openmsx
void setHeight(unsigned height_)
void init(FieldType fieldType_)
(Re)initialize an existing FrameSource.
unsigned getHeight() const
Gets the number of lines in this frame.
@ NONINTERLACED
Interlacing is off for this frame.
void resize(size_t size)
Grow or shrink the memory block.
Definition MemBuffer.hh:111
std::span< Pixel > getLineDirect(unsigned y)
Definition RawFrame.hh:20
RawFrame(unsigned maxWidth, unsigned height)
Definition RawFrame.cc:12
void setBlank(unsigned line, Pixel color)
Definition RawFrame.hh:39
This file implemented 3 utility functions:
Definition Autofire.cc:11
constexpr auto xrange(T e)
Definition xrange.hh:132