Changeset - r24883:b624287d948b
[Not reviewed]
master
0 2 0
Michael Lutz - 3 years ago 2021-01-16 15:43:09
michi@icosahedron.de
Codechange: [Win32] Move the global video buffer pointer into the driver class.
2 files changed with 19 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/video/win32_v.cpp
Show inline comments
 
@@ -38,13 +38,12 @@
 

	
 
#ifndef PM_QS_INPUT
 
#define PM_QS_INPUT 0x20000
 
#endif
 

	
 
static struct {
 
	void *buffer_bits;    ///< Internal rendering buffer.
 
	int width;            ///< Width 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 height_org;       ///< Original monitor resolution height, before we changed it.
 
	bool has_focus;       ///< Does our window have system focus?
 
	bool running;         ///< Is the main loop running?
 
@@ -1109,13 +1108,15 @@ float VideoDriver_Win32Base::GetDPIScale
 
	return cur_dpi > 0 ? cur_dpi / 96.0f : 1.0f; // Default Windows DPI value is 96.
 
}
 

	
 
bool VideoDriver_Win32Base::LockVideoBuffer()
 
{
 
	if (_draw_threaded) this->draw_lock.lock();
 
	_screen.dst_ptr = _wnd.buffer_bits;
 

	
 
	_screen.dst_ptr = this->GetVideoPointer();
 

	
 
	return true;
 
}
 

	
 
void VideoDriver_Win32Base::UnlockVideoBuffer()
 
{
 
	if (_draw_threaded) this->draw_lock.unlock();
 
@@ -1169,20 +1170,20 @@ bool VideoDriver_Win32GDI::AllocateBacki
 
	bi->bmiHeader.biBitCount = bpp;
 
	bi->bmiHeader.biCompression = BI_RGB;
 

	
 
	if (this->dib_sect) DeleteObject(this->dib_sect);
 

	
 
	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");
 
	ReleaseDC(0, dc);
 

	
 
	_screen.width = w;
 
	_screen.pitch = (bpp == 8) ? Align(w, 4) : w;
 
	_screen.height = h;
 
	_screen.dst_ptr = _wnd.buffer_bits;
 
	_screen.dst_ptr = this->GetVideoPointer();
 

	
 
	return true;
 
}
 

	
 
bool VideoDriver_Win32GDI::AfterBlitterChange()
 
{
 
@@ -1304,17 +1305,17 @@ void VideoDriver_Win32GDI::PaintThread()
 
/* Keep this function here..
 
 * It allows you to redraw the screen from within the MSVC debugger */
 
/* static */ int VideoDriver_Win32GDI::RedrawScreenDebug()
 
{
 
	static int _fooctr;
 

	
 
	_screen.dst_ptr = _wnd.buffer_bits;
 
	VideoDriver_Win32GDI *drv = static_cast<VideoDriver_Win32GDI *>(VideoDriver::GetInstance());
 

	
 
	_screen.dst_ptr = drv->GetVideoPointer();
 
	UpdateWindows();
 

	
 
	VideoDriver_Win32GDI *drv = static_cast<VideoDriver_Win32GDI *>(VideoDriver::GetInstance());
 

	
 
	drv->Paint();
 
	GdiFlush();
 

	
 
	return _fooctr++;
 
}
 
#endif
 
@@ -1442,16 +1443,18 @@ bool VideoDriver_Win32OpenGL::AllocateBa
 
	_wnd.width = w = std::max(w, 64);
 
	_wnd.height = h = std::max(h, 64);
 

	
 
	if (this->gl_rc == nullptr) return false;
 

	
 
	this->dirty_rect = {};
 
	return OpenGLBackend::Get()->Resize(w, h, force);
 
}
 

	
 
	bool res = OpenGLBackend::Get()->Resize(w, h);
 
	_wnd.buffer_bits = OpenGLBackend::Get()->GetVideoBuffer();
 
	return res;
 
void *VideoDriver_Win32OpenGL::GetVideoPointer()
 
{
 
	return OpenGLBackend::Get()->GetVideoBuffer();
 
}
 

	
 
void VideoDriver_Win32OpenGL::Paint()
 
{
 
	PerformanceMeasurer framerate(PFE_VIDEO);
 

	
src/video/win32_v.h
Show inline comments
 
@@ -52,12 +52,14 @@ protected:
 
	void ClientSizeChanged(int w, int h);
 

	
 
	/** Get screen depth to use for fullscreen mode. */
 
	virtual uint8 GetFullscreenBpp();
 
	/** (Re-)create the backing store. */
 
	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. */
 
	virtual void PaletteChanged(HWND hWnd) = 0;
 

	
 
private:
 
	std::unique_lock<std::recursive_mutex> draw_lock;
 

	
 
@@ -65,27 +67,29 @@ private:
 

	
 
	friend LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
 
};
 
/** The GDI video driver for windows. */
 
class VideoDriver_Win32GDI : public VideoDriver_Win32Base {
 
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 &param) override;
 

	
 
	void Stop() override;
 

	
 
	bool AfterBlitterChange() override;
 

	
 
	const char *GetName() const override { return "win32"; }
 

	
 
protected:
 
	HBITMAP  dib_sect;      ///< System bitmap object referencing our rendering buffer.
 
	HPALETTE gdi_palette;   ///< Palette object for 8bpp blitter.
 
	void     *buffer_bits;  ///< Internal rendering buffer.
 

	
 
	void Paint() override;
 
	void *GetVideoPointer() override { return this->buffer_bits; }
 
	void PaintThread() override;
 

	
 
	bool AllocateBackingStore(int w, int h, bool force = false) override;
 
	void PaletteChanged(HWND hWnd) override;
 
	void MakePalette();
 
	void UpdatePalette(HDC dc, uint start, uint count);
 
@@ -127,12 +131,13 @@ protected:
 
	uint8 GetFullscreenBpp() override { return 32; } // OpenGL is always 32 bpp.
 

	
 
	void Paint() override;
 
	void PaintThread() override {}
 

	
 
	bool AllocateBackingStore(int w, int h, bool force = false) override;
 
	void *GetVideoPointer() override;
 
	void PaletteChanged(HWND hWnd) override {}
 

	
 
	const char *AllocateContext();
 
	void DestroyContext();
 
};
 

	
0 comments (0 inline, 0 general)