mirror of https://github.com/OpenTTD/OpenTTD
Codechange: [Win32] Move the global video buffer pointer into the driver class.
parent
5ad545dcc1
commit
73ed748deb
|
@ -41,7 +41,6 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
void *buffer_bits; ///< Internal rendering buffer.
|
|
||||||
int width; ///< Width in pixels of our display surface.
|
int width; ///< Width in pixels of our display surface.
|
||||||
int height; ///< Height in pixels of our display surface.
|
int height; ///< Height in pixels of our display surface.
|
||||||
int width_org; ///< Original monitor resolution width, before we changed it.
|
int width_org; ///< Original monitor resolution width, before we changed it.
|
||||||
|
@ -1112,7 +1111,9 @@ float VideoDriver_Win32Base::GetDPIScale()
|
||||||
bool VideoDriver_Win32Base::LockVideoBuffer()
|
bool VideoDriver_Win32Base::LockVideoBuffer()
|
||||||
{
|
{
|
||||||
if (_draw_threaded) this->draw_lock.lock();
|
if (_draw_threaded) this->draw_lock.lock();
|
||||||
_screen.dst_ptr = _wnd.buffer_bits;
|
|
||||||
|
_screen.dst_ptr = this->GetVideoPointer();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1172,14 +1173,14 @@ bool VideoDriver_Win32GDI::AllocateBackingStore(int w, int h, bool force)
|
||||||
if (this->dib_sect) DeleteObject(this->dib_sect);
|
if (this->dib_sect) DeleteObject(this->dib_sect);
|
||||||
|
|
||||||
HDC dc = GetDC(0);
|
HDC dc = GetDC(0);
|
||||||
this->dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID **)&_wnd.buffer_bits, nullptr, 0);
|
this->dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID **)&this->buffer_bits, nullptr, 0);
|
||||||
if (this->dib_sect == nullptr) usererror("CreateDIBSection failed");
|
if (this->dib_sect == nullptr) usererror("CreateDIBSection failed");
|
||||||
ReleaseDC(0, dc);
|
ReleaseDC(0, dc);
|
||||||
|
|
||||||
_screen.width = w;
|
_screen.width = w;
|
||||||
_screen.pitch = (bpp == 8) ? Align(w, 4) : w;
|
_screen.pitch = (bpp == 8) ? Align(w, 4) : w;
|
||||||
_screen.height = h;
|
_screen.height = h;
|
||||||
_screen.dst_ptr = _wnd.buffer_bits;
|
_screen.dst_ptr = this->GetVideoPointer();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1307,11 +1308,11 @@ void VideoDriver_Win32GDI::PaintThread()
|
||||||
{
|
{
|
||||||
static int _fooctr;
|
static int _fooctr;
|
||||||
|
|
||||||
_screen.dst_ptr = _wnd.buffer_bits;
|
|
||||||
UpdateWindows();
|
|
||||||
|
|
||||||
VideoDriver_Win32GDI *drv = static_cast<VideoDriver_Win32GDI *>(VideoDriver::GetInstance());
|
VideoDriver_Win32GDI *drv = static_cast<VideoDriver_Win32GDI *>(VideoDriver::GetInstance());
|
||||||
|
|
||||||
|
_screen.dst_ptr = drv->GetVideoPointer();
|
||||||
|
UpdateWindows();
|
||||||
|
|
||||||
drv->Paint();
|
drv->Paint();
|
||||||
GdiFlush();
|
GdiFlush();
|
||||||
|
|
||||||
|
@ -1445,10 +1446,12 @@ bool VideoDriver_Win32OpenGL::AllocateBackingStore(int w, int h, bool force)
|
||||||
if (this->gl_rc == nullptr) return false;
|
if (this->gl_rc == nullptr) return false;
|
||||||
|
|
||||||
this->dirty_rect = {};
|
this->dirty_rect = {};
|
||||||
|
return OpenGLBackend::Get()->Resize(w, h, force);
|
||||||
|
}
|
||||||
|
|
||||||
bool res = OpenGLBackend::Get()->Resize(w, h);
|
void *VideoDriver_Win32OpenGL::GetVideoPointer()
|
||||||
_wnd.buffer_bits = OpenGLBackend::Get()->GetVideoBuffer();
|
{
|
||||||
return res;
|
return OpenGLBackend::Get()->GetVideoBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoDriver_Win32OpenGL::Paint()
|
void VideoDriver_Win32OpenGL::Paint()
|
||||||
|
|
|
@ -55,6 +55,8 @@ protected:
|
||||||
virtual uint8 GetFullscreenBpp();
|
virtual uint8 GetFullscreenBpp();
|
||||||
/** (Re-)create the backing store. */
|
/** (Re-)create the backing store. */
|
||||||
virtual bool AllocateBackingStore(int w, int h, bool force = false) = 0;
|
virtual bool AllocateBackingStore(int w, int h, bool force = false) = 0;
|
||||||
|
/** Get a pointer to the video buffer. */
|
||||||
|
virtual void *GetVideoPointer() = 0;
|
||||||
/** Palette of the window has changed. */
|
/** Palette of the window has changed. */
|
||||||
virtual void PaletteChanged(HWND hWnd) = 0;
|
virtual void PaletteChanged(HWND hWnd) = 0;
|
||||||
|
|
||||||
|
@ -68,7 +70,7 @@ private:
|
||||||
/** The GDI video driver for windows. */
|
/** The GDI video driver for windows. */
|
||||||
class VideoDriver_Win32GDI : public VideoDriver_Win32Base {
|
class VideoDriver_Win32GDI : public VideoDriver_Win32Base {
|
||||||
public:
|
public:
|
||||||
VideoDriver_Win32GDI() : dib_sect(nullptr), gdi_palette(nullptr) {}
|
VideoDriver_Win32GDI() : dib_sect(nullptr), gdi_palette(nullptr), buffer_bits(nullptr) {}
|
||||||
|
|
||||||
const char *Start(const StringList ¶m) override;
|
const char *Start(const StringList ¶m) override;
|
||||||
|
|
||||||
|
@ -81,8 +83,10 @@ public:
|
||||||
protected:
|
protected:
|
||||||
HBITMAP dib_sect; ///< System bitmap object referencing our rendering buffer.
|
HBITMAP dib_sect; ///< System bitmap object referencing our rendering buffer.
|
||||||
HPALETTE gdi_palette; ///< Palette object for 8bpp blitter.
|
HPALETTE gdi_palette; ///< Palette object for 8bpp blitter.
|
||||||
|
void *buffer_bits; ///< Internal rendering buffer.
|
||||||
|
|
||||||
void Paint() override;
|
void Paint() override;
|
||||||
|
void *GetVideoPointer() override { return this->buffer_bits; }
|
||||||
void PaintThread() override;
|
void PaintThread() override;
|
||||||
|
|
||||||
bool AllocateBackingStore(int w, int h, bool force = false) override;
|
bool AllocateBackingStore(int w, int h, bool force = false) override;
|
||||||
|
@ -130,6 +134,7 @@ protected:
|
||||||
void PaintThread() override {}
|
void PaintThread() override {}
|
||||||
|
|
||||||
bool AllocateBackingStore(int w, int h, bool force = false) override;
|
bool AllocateBackingStore(int w, int h, bool force = false) override;
|
||||||
|
void *GetVideoPointer() override;
|
||||||
void PaletteChanged(HWND hWnd) override {}
|
void PaletteChanged(HWND hWnd) override {}
|
||||||
|
|
||||||
const char *AllocateContext();
|
const char *AllocateContext();
|
||||||
|
|
Loading…
Reference in New Issue