HoverRace  2.0
VideoBuffer.h
Go to the documentation of this file.
1 
2 // VideoBuffer.h
3 //
4 // Copyright (c) 2013, 2014 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 //
22 
23 #pragma once
24 
25 #include "../Util/MR_Types.h"
26 #include "../Util/OS.h"
27 #include "ColorPalette.h"
28 
29 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
30 # ifdef MR_ENGINE
31 # define MR_DllDeclare __declspec( dllexport )
32 # else
33 # define MR_DllDeclare __declspec( dllimport )
34 # endif
35 #else
36 # define MR_DllDeclare
37 #endif
38 
39 struct SDL_Surface;
40 
41 namespace HoverRace {
42  namespace Display {
43  class Display;
44  }
45 }
46 
47 namespace HoverRace {
48 namespace VideoServices {
49 
55 {
56 public:
57  class Lock {
59  public:
60  Lock(VideoBuffer &videoBuffer) : videoBuffer(videoBuffer)
61  {
62  videoBuffer.LockLegacySurface();
63  }
64 
65  Lock(const Lock&) = delete;
66 
68  {
69  videoBuffer.UnlockLegacySurface();
70  }
71 
72  Lock &operator=(const Lock&) = delete;
73  };
74 
75 public:
76  VideoBuffer(Display::Display &display);
77  virtual ~VideoBuffer();
78 
79  // Signals from ClientApp that certain settings have changed.
80  void OnDesktopModeChange(int width, int height);
81 protected:
82  virtual void OnWindowResChange();
83 
84 public:
85  const ColorPalette::paletteEntry_t *GetPalette() const { return palette; }
86  void AssignPalette();
87  void CreatePalette();
88  void SetBackgroundPalette(std::unique_ptr<MR_UInt8[]> &palette);
89  typedef boost::signals2::signal<void()> paletteChangedSignal_t;
90  paletteChangedSignal_t &GetPaletteChangedSignal() { return paletteChangedSignal; }
91 
92 protected:
93  void LockLegacySurface();
94  void UnlockLegacySurface();
95  virtual void Flip() = 0;
96 
97 public:
98  int GetWidth() const { return width; }
99  int GetHeight() const { return height; }
100  int GetPitch() const { return pitch; }
101  int GetZPitch() const { return width; }
102 
103 protected:
104  SDL_Surface *GetLegacySurface() const { return legacySurface; }
105 
106 public:
107  MR_UInt8 *GetBuffer() const { return vbuf; }
108  MR_UInt16 *GetZBuffer() const { return zbuf; }
109 
110  void Clear(MR_UInt8 color = 0);
111 
112  typedef std::pair<int,int> pixelMeter_t;
113  pixelMeter_t GetPixelMeter() const;
114 
115  void DrawPoint(int pX, int pY, MR_UInt8 pColor);
116  void DrawLine(int pX0, int pY0, int pX1, int pY1, MR_UInt8 pColor);
117  void DrawHorizontalLine(int pY, int pX0, int pX1, MR_UInt8 pColor);
118 
119 private:
120  int desktopWidth, desktopHeight;
121  int width, height, pitch;
123 
124  SDL_Surface *legacySurface;
127 
128  std::unique_ptr<MR_UInt8[]> bgPalette;
129 
131  paletteChangedSignal_t paletteChangedSignal;
132 };
133 
134 } // namespace VideoServices
135 } // namespace HoverRace
136 
137 #undef MR_DllDeclare
int GetPitch() const
Definition: VideoBuffer.h:100
int GetHeight() const
Definition: VideoBuffer.h:99
SDL_Surface * legacySurface
Definition: VideoBuffer.h:124
paletteChangedSignal_t & GetPaletteChangedSignal()
Definition: VideoBuffer.h:90
int GetZPitch() const
Definition: VideoBuffer.h:101
#define MR_DllDeclare
Definition: VideoBuffer.h:36
uint16_t MR_UInt16
Definition: MR_Types.h:42
~Lock()
Definition: VideoBuffer.h:67
void UnlockLegacySurface()
Definition: VideoBuffer.cpp:175
paletteChangedSignal_t paletteChangedSignal
Definition: VideoBuffer.h:131
SDL_Color paletteEntry_t
Definition: ColorPalette.h:63
Lock(VideoBuffer &videoBuffer)
Definition: VideoBuffer.h:60
bool fullscreen
Definition: VideoBuffer.h:122
MR_UInt16 * GetZBuffer() const
Definition: VideoBuffer.h:108
Base class for display managers.
Definition: Display.h:73
Video framebuffer for legacy (8-bit, palettized) rendering.
Definition: VideoBuffer.h:54
MR_UInt8 * vbuf
Definition: VideoBuffer.h:125
MR_UInt8 * GetBuffer() const
Definition: VideoBuffer.h:107
MR_UInt16 * zbuf
Definition: VideoBuffer.h:126
std::pair< int, int > pixelMeter_t
Definition: VideoBuffer.h:112
void LockLegacySurface()
Definition: VideoBuffer.cpp:166
std::unique_ptr< MR_UInt8[]> bgPalette
Definition: VideoBuffer.h:128
Definition: Announcement.h:24
int width
Definition: VideoBuffer.h:121
VideoBuffer & videoBuffer
Definition: VideoBuffer.h:58
int desktopWidth
Definition: VideoBuffer.h:120
uint8_t MR_UInt8
Definition: MR_Types.h:40
SDL_Surface * GetLegacySurface() const
Definition: VideoBuffer.h:104
boost::signals2::signal< void()> paletteChangedSignal_t
Definition: VideoBuffer.h:89
int GetWidth() const
Definition: VideoBuffer.h:98
const ColorPalette::paletteEntry_t * GetPalette() const
Definition: VideoBuffer.h:85