ladybird/Widgets/FrameBufferSDL.cpp

60 lines
1 KiB
C++
Raw Normal View History

2018-10-10 15:12:38 +02:00
#include "FrameBufferSDL.h"
#include <AK/Assertions.h>
2018-10-10 16:49:36 +02:00
FrameBufferSDL* s_the = nullptr;
FrameBufferSDL& FrameBufferSDL::the()
{
ASSERT(s_the);
return *s_the;
}
2018-10-10 15:12:38 +02:00
FrameBufferSDL::FrameBufferSDL(unsigned width, unsigned height)
: AbstractScreen(width, height)
{
2018-10-10 16:49:36 +02:00
ASSERT(!s_the);
s_the = this;
2018-10-10 15:12:38 +02:00
initializeSDL();
}
FrameBufferSDL::~FrameBufferSDL()
{
SDL_DestroyWindow(m_window);
m_surface = nullptr;
m_window = nullptr;
SDL_Quit();
}
void FrameBufferSDL::show()
{
}
void FrameBufferSDL::initializeSDL()
{
if (m_window)
return;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
ASSERT_NOT_REACHED();
}
m_window = SDL_CreateWindow(
"FrameBuffer",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
width(),
height(),
SDL_WINDOW_SHOWN);
ASSERT(m_window);
m_surface = SDL_GetWindowSurface(m_window);
ASSERT(m_surface);
SDL_FillRect(m_surface, nullptr, SDL_MapRGB(m_surface->format, 0xff, 0xff, 0xff));
SDL_UpdateWindowSurface(m_window);
}