Files
@ r24883:b624287d948b
Branch filter:
Location: cpp/openttd-patchpack/source/src/video/win32_v.h
r24883:b624287d948b
4.8 KiB
text/x-c
Codechange: [Win32] Move the global video buffer pointer into the driver class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | /*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file win32_v.h Base of the Windows video driver. */
#ifndef VIDEO_WIN32_H
#define VIDEO_WIN32_H
#include "video_driver.hpp"
/** Base class for Windows video drivers. */
class VideoDriver_Win32Base : public VideoDriver {
public:
VideoDriver_Win32Base() : main_wnd(nullptr), fullscreen(false) {}
void Stop() override;
void MakeDirty(int left, int top, int width, int height) override;
void MainLoop() override;
bool ChangeResolution(int w, int h) override;
bool ToggleFullscreen(bool fullscreen) override;
void AcquireBlitterLock() override;
void ReleaseBlitterLock() override;
bool ClaimMousePointer() override;
void EditBoxLostFocus() override;
protected:
HWND main_wnd; ///< Handle to system window.
bool fullscreen; ///< Whether to use (true) fullscreen mode.
Rect dirty_rect; ///< Region of the screen that needs redrawing.
Dimension GetScreenSize() const override;
float GetDPIScale() override;
void InputLoop() override;
bool LockVideoBuffer() override;
void UnlockVideoBuffer() override;
void CheckPaletteAnim() override;
void Initialize();
bool MakeWindow(bool full_screen);
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;
static void PaintThreadThunk(VideoDriver_Win32Base *drv);
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), buffer_bits(nullptr) {}
const char *Start(const StringList ¶m) 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);
#ifdef _DEBUG
public:
static int RedrawScreenDebug();
#endif
};
/** The factory for Windows' video driver. */
class FVideoDriver_Win32GDI : public DriverFactoryBase {
public:
FVideoDriver_Win32GDI() : DriverFactoryBase(Driver::DT_VIDEO, 10, "win32", "Win32 GDI Video Driver") {}
Driver *CreateInstance() const override { return new VideoDriver_Win32GDI(); }
};
#ifdef WITH_OPENGL
/** The OpenGL video driver for windows. */
class VideoDriver_Win32OpenGL : public VideoDriver_Win32Base {
public:
VideoDriver_Win32OpenGL() : dc(nullptr), gl_rc(nullptr) {}
const char *Start(const StringList ¶m) override;
void Stop() override;
bool ToggleFullscreen(bool fullscreen) override;
bool AfterBlitterChange() override;
const char *GetName() const override { return "win32-opengl"; }
protected:
HDC dc; ///< Window device context.
HGLRC gl_rc; ///< OpenGL context.
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();
};
/** The factory for Windows' OpenGL video driver. */
class FVideoDriver_Win32OpenGL : public DriverFactoryBase {
public:
FVideoDriver_Win32OpenGL() : DriverFactoryBase(Driver::DT_VIDEO, 9, "win32-opengl", "Win32 OpenGL Video Driver") {}
/* virtual */ Driver *CreateInstance() const override { return new VideoDriver_Win32OpenGL(); }
};
#endif /* WITH_OPENGL */
#endif /* VIDEO_WIN32_H */
|