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