openMSX
RawFrame.cc
Go to the documentation of this file.
1 #include "RawFrame.hh"
2 #include <cstdint>
3 #include <SDL.h>
4 
5 namespace openmsx {
6 
8  const SDL_PixelFormat& format, unsigned maxWidth_, unsigned height)
9  : FrameSource(format)
10  , lineWidths(height)
11  , maxWidth(maxWidth_)
12 {
13  setHeight(height);
14  unsigned bytesPerPixel = format.BytesPerPixel;
15 
16  // Allocate memory, make sure each line starts at a 64 byte boundary:
17  // - SSE instructions need 16 byte aligned data
18  // - cache line size on many CPUs is 64 bytes
19  pitch = ((bytesPerPixel * maxWidth) + 63) & ~63;
20  data.resize(pitch * height);
21 
22  maxWidth = pitch / bytesPerPixel; // adjust maxWidth
23 
24  // Start with a black frame.
26  for (unsigned line = 0; line < height; line++) {
27  if (bytesPerPixel == 2) {
28  setBlank(line, static_cast<uint16_t>(0));
29  } else {
30  setBlank(line, static_cast<uint32_t>(0));
31  }
32  }
33 }
34 
35 unsigned RawFrame::getLineWidth(unsigned line) const
36 {
37  assert(line < getHeight());
38  return lineWidths[line];
39 }
40 
42  unsigned line, unsigned& width,
43  void* /*buf*/, unsigned /*bufWidth*/) const
44 {
45  assert(line < getHeight());
46  width = lineWidths[line];
47  return data.data() + line * pitch;
48 }
49 
50 unsigned RawFrame::getRowLength() const
51 {
52  return maxWidth; // in pixels (not in bytes)
53 }
54 
56 {
57  return true;
58 }
59 
60 } // namespace openmsx
void init(FieldType fieldType_)
(Re)initialize an existing FrameSource.
Definition: FrameSource.hh:35
unsigned getLineWidth(unsigned line) const override
Gets the number of display pixels on the given line.
Definition: RawFrame.cc:35
const void * getLineInfo(unsigned line, unsigned &width, void *buf, unsigned bufWidth) const override
Abstract implementation of getLinePtr().
Definition: RawFrame.cc:41
Interface for getting lines from a video frame.
Definition: FrameSource.hh:15
void resize(size_t size)
Grow or shrink the memory block.
Definition: MemBuffer.hh:121
RawFrame(const SDL_PixelFormat &format, unsigned maxWidth, unsigned height)
Definition: RawFrame.cc:7
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
bool hasContiguousStorage() const override
Returns true when two consecutive rows are also consecutive in memory.
Definition: RawFrame.cc:55
Interlacing is off for this frame.
Definition: FrameSource.hh:23
unsigned getRowLength() const override
Returns the distance (in pixels) between two consecutive lines.
Definition: RawFrame.cc:50
void setBlank(unsigned line, Pixel color)
Definition: RawFrame.hh:46
unsigned getHeight() const
Gets the number of lines in this frame.
Definition: FrameSource.hh:45
void setHeight(unsigned height_)
Definition: FrameSource.hh:201
const T * data() const
Returns pointer to the start of the memory buffer.
Definition: MemBuffer.hh:91