OXYGENHUB
◆ main openmsx / src / video / RawFrame.cc
1.1 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#include "RawFrame.hh"
2
3
namespace 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
12
RawFrame::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.
24
	init(FieldType::NONINTERLACED);
25
	for (auto line : xrange(height_)) {
26
		setBlank(line, Pixel(0));
27
	}
28
}
29
30
unsigned RawFrame::getLineWidth(unsigned line) const
31
{
32
	assert(line < getHeight());
33
	return lineWidths[line];
34
}
35
36
std::span<const RawFrame::Pixel> RawFrame::getUnscaledLine(
37
	unsigned line, std::span<Pixel> /*helpBuf*/) const
38
{
39
	return getLineDirect(line).first(lineWidths[line]);
40
}
41
42
bool RawFrame::hasContiguousStorage() const
43
{
44
	return true;
45
}
46
47
} // namespace openmsx