1 /* xscreensaver, Copyright (c) 2006-2015 Jamie Zawinski <jwz@jwz.org>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
12 /* This is a subclass of Apple's ScreenSaverView that knows how to run
13 xscreensaver programs without X11 via the dark magic of the "jwxyz"
14 library. In xscreensaver terminology, this is the replacement for
15 the "screenhack.c" module.
19 # import <Foundation/Foundation.h>
20 # import <UIKit/UIKit.h>
21 # define NSView UIView
22 # define NSRect CGRect
23 # define NSSize CGSize
24 # define NSColor UIColor
25 # define NSImage UIImage
26 # define NSEvent UIEvent
27 # define NSWindow UIWindow
28 # define NSOpenGLContext EAGLContext
30 # import <Cocoa/Cocoa.h>
31 # import <ScreenSaver/ScreenSaver.h>
35 #import "screenhackI.h"
36 #import "PrefsReader.h"
40 @class XScreenSaverView;
42 @protocol XScreenSaverViewDelegate
43 - (void) wantsFadeOut:(XScreenSaverView *)saverView;
44 - (void) didShake:(XScreenSaverView *)saverView;
47 @interface ScreenSaverView : NSView
48 - (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview;
49 - (NSTimeInterval)animationTimeInterval;
50 - (void)setAnimationTimeInterval:(NSTimeInterval)timeInterval;
51 - (void)startAnimation;
52 - (void)stopAnimation;
54 - (void)animateOneFrame;
55 - (BOOL)hasConfigureSheet;
56 //- (NSWindow*)configureSheet;
57 - (UIViewController*)configureView;
64 #define USE_BACKBUFFER // must be in sync with jwxyz.m
65 // Currently only OpenGL backbuffers are supported (OSX and iOS).
66 # define BACKBUFFER_OPENGL
68 @interface XScreenSaverView : ScreenSaverView
73 struct xscreensaver_function_table *xsft;
74 PrefsReader *prefsReader;
76 BOOL setup_p; // whether xsft->setup_cb() has been run
77 BOOL initted_p; // whether xsft->init_cb() has been run
78 BOOL resized_p; // whether to run the xsft->reshape_cb() soon
79 double next_frame_time; // time_t in milliseconds of when to tick the frame
81 // Data used by the Xlib-flavored screensaver
88 UIDeviceOrientation orientation, new_orientation;
91 CGSize initial_bounds; // portrait-mode size (pixels, not points).
93 GLfloat rotation_ratio; // ratio [0-1] thru rotation anim, or -1
94 NSSize rot_current_size; // intermediate or at-rest orientation.
95 NSSize rot_from, rot_to; // start/end size rect (pixels, not points)
96 GLfloat rot_current_angle; // only right angles when rotation complete.
97 GLfloat angle_from, angle_to; // start angle, end angle (degrees)
98 double rot_start_time;
100 BOOL ignore_rotation_p; // whether hack requested "always portrait".
101 // some want this, some do not.
103 NSTimer *crash_timer;
105 NSDictionary *function_tables;
107 id<XScreenSaverViewDelegate> _delegate;
109 # endif // USE_IPHONE
111 # ifdef USE_BACKBUFFER
112 CGContextRef backbuffer;
113 CGSize backbuffer_size; // pixels, not points.
114 CGColorSpaceRef colorspace;
116 # ifdef BACKBUFFER_OPENGL
117 void *backbuffer_data;
118 size_t backbuffer_len;
120 GLsizei gl_texture_w, gl_texture_h;
122 NSOpenGLContext *ogl_ctx; // OpenGL rendering context
123 GLuint backbuffer_texture;
124 GLenum gl_texture_target;
125 GLenum gl_pixel_format, gl_pixel_type;
127 BOOL double_buffered_p, gl_apple_client_storage_p;
129 BOOL gl_limited_npot_p;
130 GLuint gl_framebuffer, gl_renderbuffer;
131 # endif // USE_IPHONE
134 # endif // USE_BACKBUFFER
137 - (id)initWithFrame:(NSRect)frame saverName:(NSString*)n isPreview:(BOOL)p;
140 - (void) prepareContext;
141 - (NSUserDefaultsController *) userDefaultsController;
142 + (NSString *) decompressXML:(NSData *)xml;
145 - (BOOL)reshapeRotatedWindow;
146 - (void)setScreenLocked:(BOOL)locked;
147 - (NSDictionary *)getGLProperties;
148 - (void)addExtraRenderbuffers:(CGSize)size;
149 @property (nonatomic, assign) id<XScreenSaverViewDelegate> delegate;
151 - (NSOpenGLPixelFormat *)getGLPixelFormat;
152 #endif // !USE_IPHONE
154 #ifdef USE_BACKBUFFER
155 - (void)enableBackbuffer:(CGSize)new_backbuffer_size;
156 - (void)createBackbuffer:(CGSize)s;
157 - (void)drawBackbuffer;
158 - (void)flushBackbuffer;
159 #endif // USE_BACKBUFFER