Changeset - r16830:bc75a402323c
[Not reviewed]
master
0 4 0
planetmaker - 14 years ago 2010-12-21 15:56:02
planetmaker@openttd.org
(svn r21574) -Codechange: [OSX] Move the variable declaration of the screen drivers to the generic class, deduplicating code
4 files changed with 38 insertions and 73 deletions:
0 comments (0 inline, 0 general)
src/video/cocoa/cocoa_v.h
Show inline comments
 
@@ -39,15 +39,47 @@ public:
 
	/* virtual */ const char *GetName() { return "cocoa"; }
 
	/* virtual */ const char *GetDescription() { return "Cocoa Video Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new VideoDriver_Cocoa(); }
 
};
 

	
 

	
 

	
 
/**
 
 * Generic display driver for cocoa
 
 * On grounds to not duplicate some code, it contains a few variables
 
 * which are not used by all device drivers.
 
 */
 
class CocoaSubdriver {
 
public:
 
	int device_width;
 
	int device_height;
 
	int device_depth;
 

	
 
	int window_width;
 
	int window_height;
 
	int window_pitch;
 

	
 
	int buffer_depth;
 
	void *pixel_buffer;   // used for direct pixel access
 
	void *window_buffer;  // has colour translation from palette to screen
 
	id window;            // pointer to window object
 

	
 
#	define MAX_DIRTY_RECTS 100
 
	Rect dirty_rects[MAX_DIRTY_RECTS];
 
	int num_dirty_rects;
 
	uint32 palette[256];
 

	
 
	bool active;
 
	bool setup;
 

	
 
	id cocoaview;         // pointer to view object
 

	
 
	/* Separate driver vars for Quarz
 
	 * Needed here in order to avoid much code duplication */
 
	CGContextRef cgcontext;
 

	
 
	/* Driver methods */
 
	virtual ~CocoaSubdriver() {}
 

	
 
	virtual void Draw(bool force_update = false) = 0;
 
	virtual void MakeDirty(int left, int top, int width, int height) = 0;
 
	virtual void UpdatePalette(uint first_color, uint num_colors) = 0;
 

	
src/video/cocoa/fullscreen.mm
Show inline comments
 
@@ -146,28 +146,17 @@ bool QZ_CanDisplay8bpp()
 
	 * resolutions. Because of this we want to fill a list of 1 resolution of 8 bpp
 
	 * on display 0 (main) and return if we found one. */
 
	return QZ_ListModes(&p, 1, 0, 8);
 
}
 

	
 
class FullscreenSubdriver: public CocoaSubdriver {
 
	int                device_width;
 
	int                device_height;
 
	int                device_depth;
 
	int                window_pitch;
 
	void              *window_buffer;
 
	void              *pixel_buffer;
 

	
 
	CGDirectDisplayID  display_id;         ///< 0 == main display (only support single display)
 
	CFDictionaryRef    cur_mode;           ///< current mode of the display
 
	CFDictionaryRef    save_mode;          ///< original mode of the display
 
	CGDirectPaletteRef palette;            ///< palette of an 8-bit display
 

	
 
	#define MAX_DIRTY_RECTS 100
 
	Rect dirty_rects[MAX_DIRTY_RECTS];
 
	int num_dirty_rects;
 

	
 

	
 
	/* Gamma functions to try to hide the flash from a res switch
 
	 * Fade the display from normal to black
 
	 * Save gamma tables for fade back to normal
 
	 */
 
	uint32 FadeGammaOut(OTTD_QuartzGammaTable *table)
src/video/cocoa/wnd_quartz.mm
Show inline comments
 
@@ -81,53 +81,26 @@ class WindowQuartzSubdriver;
 

	
 
- (void)drawRect:(NSRect)rect;
 
- (BOOL)isOpaque;
 
@end
 

	
 
class WindowQuartzSubdriver: public CocoaSubdriver {
 
	int device_width;
 
	int device_height;
 

	
 
	int window_width;
 
	int window_height;
 

	
 
	int buffer_depth;
 

	
 
	void *pixel_buffer;
 
	void *window_buffer;
 

	
 
	id window;
 

	
 
	#define MAX_DIRTY_RECTS 100
 
	Rect dirty_rects[MAX_DIRTY_RECTS];
 
	int num_dirty_rects;
 

	
 
	uint32 palette[256];
 

	
 
public:
 
	bool active;
 
	bool setup;
 

	
 
	id cocoaview;
 
	CGContextRef cgcontext;
 

	
 
private:
 
	void GetDeviceInfo();
 

	
 
	bool SetVideoMode(int width, int height);
 

	
 
	/**
 
	 * This function copies 8bpp pixels from the screen buffer in 32bpp windowed mode.
 
	 *
 
	 * @param left The x coord for the left edge of the box to blit.
 
	 * @param top The y coord for the top edge of the box to blit.
 
	 * @param right The x coord for the right edge of the box to blit.
 
	 * @param bottom The y coord for the bottom edge of the box to blit.
 
	 */
 
	void BlitIndexedToView32(int left, int top, int right, int bottom);
 

	
 
	virtual void GetDeviceInfo();
 
	virtual bool SetVideoMode(int width, int height);
 

	
 
public:
 
	WindowQuartzSubdriver(int bpp);
 
	virtual ~WindowQuartzSubdriver();
 

	
 
	virtual void Draw(bool force_update);
 
	virtual void MakeDirty(int left, int top, int width, int height);
src/video/cocoa/wnd_quickdraw.mm
Show inline comments
 
@@ -70,44 +70,13 @@ class WindowQuickdrawSubdriver;
 
- (void)setDriver:(WindowQuickdrawSubdriver*)drv;
 

	
 
- (BOOL)windowShouldClose:(id)sender;
 
@end
 

	
 
class WindowQuickdrawSubdriver: public CocoaSubdriver {
 
	int device_width;
 
	int device_height;
 
	int device_depth;
 

	
 
	int window_width;
 
	int window_height;
 
	int window_pitch;
 

	
 
	int buffer_depth;
 

	
 
	void *pixel_buffer;
 
	void *window_buffer;
 

	
 
	id window;
 

	
 
	#define MAX_DIRTY_RECTS 100
 
	Rect dirty_rects[MAX_DIRTY_RECTS];
 
	int num_dirty_rects;
 

	
 
	uint32 palette[256];
 

	
 
public:
 
	bool active;
 
	bool setup;
 

	
 
	id cocoaview;
 

	
 
private:
 
	void GetDeviceInfo();
 

	
 
	bool SetVideoMode(int width, int height);
 

	
 
	/**
 
	 * This function copies 32bpp pixels from the screen buffer in 16bpp windowed mode.
 
	 *
 
	 * @param left The x coord for the left edge of the box to blit.
 
	 * @param top The y coord for the top edge of the box to blit.
 
	 * @param right The x coord for the right edge of the box to blit.
 
@@ -135,12 +104,14 @@ private:
 
	 */
 
	void BlitIndexedToView16(int left, int top, int right, int bottom);
 

	
 
	inline void BlitToView(int left, int top, int right, int bottom);
 
	void DrawResizeIcon();
 

	
 
	virtual void GetDeviceInfo();
 
	virtual bool SetVideoMode(int width, int height);
 

	
 
public:
 
	WindowQuickdrawSubdriver(int bpp);
 
	virtual ~WindowQuickdrawSubdriver();
 

	
 
	virtual void Draw(bool force_update);
0 comments (0 inline, 0 general)