From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / OSX / XScreenSaverView.h
1 /* xscreensaver, Copyright (c) 2006-2017 Jamie Zawinski <jwz@jwz.org>
2  *
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 
9  * implied warranty.
10  */
11
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.
16  */
17
18 #ifdef USE_IPHONE
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
29 #else
30 # import <Cocoa/Cocoa.h>
31 # import <ScreenSaver/ScreenSaver.h>
32 #endif
33
34
35 #import "screenhackI.h"
36 #import "PrefsReader.h"
37
38 #ifdef USE_IPHONE
39
40 @class XScreenSaverView;
41
42 @protocol XScreenSaverViewDelegate
43 - (void) wantsFadeOut:(XScreenSaverView *)saverView;
44 - (void) didShake:(XScreenSaverView *)saverView;
45 - (void) openPreferences: (NSString *)which;
46 @end
47
48 @interface ScreenSaverView : NSView
49 - (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview;
50 - (NSTimeInterval)animationTimeInterval;
51 - (void)setAnimationTimeInterval:(NSTimeInterval)timeInterval;
52 - (void)startAnimation;
53 - (void)stopAnimation;
54 - (BOOL)isAnimating;
55 - (void)animateOneFrame;
56 - (BOOL)hasConfigureSheet;
57 //- (NSWindow*)configureSheet;
58 - (UIViewController*)configureView;
59 - (BOOL)isPreview;
60 @end
61
62 #endif // USE_IPHONE
63
64
65 // Currently only OpenGL backbuffers are supported (OSX and iOS).
66 # define BACKBUFFER_OPENGL
67
68 @interface XScreenSaverView : ScreenSaverView
69 # ifdef USE_IPHONE
70                               <UIAlertViewDelegate>
71 # endif
72 {
73   struct xscreensaver_function_table *xsft;
74   PrefsReader *prefsReader;
75
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
80
81   // Data used by the Xlib-flavored screensaver
82   Display *xdpy;
83   Window xwindow;
84   void *xdata;
85   fps_state *fpst;
86   void (*fps_cb) (Display *, Window, fps_state *, void *);
87
88 # ifdef USE_IPHONE
89   BOOL screenLocked;
90   BOOL _ignoreRotation;         // whether hack requested "always portrait".
91                                 // some want this, some do not.
92   NSTimer *crash_timer;
93
94   NSDictionary *function_tables;
95
96   id<XScreenSaverViewDelegate> _delegate;
97
98   UIView *closeBox;
99   NSTimer *closeBoxTimer;
100
101   CGAffineTransform pinch_transform;
102
103 # else // !USE_PHONE
104
105   NSOpenGLPixelFormat *pixfmt;
106
107 # endif // !USE_IPHONE
108
109   NSOpenGLContext *ogl_ctx;      // OpenGL rendering context
110
111 # ifdef JWXYZ_QUARTZ
112   CGContextRef backbuffer;
113   CGColorSpaceRef colorspace;
114
115 #  ifdef BACKBUFFER_OPENGL
116   void *backbuffer_data;
117   GLsizei backbuffer_len;
118
119   GLsizei gl_texture_w, gl_texture_h;
120
121   GLuint backbuffer_texture;
122   GLenum gl_texture_target;
123   GLenum gl_pixel_format, gl_pixel_type;
124 #   ifndef USE_IPHONE
125   BOOL double_buffered_p, gl_apple_client_storage_p;
126 #   else // USE_IPHONE
127   BOOL gl_limited_npot_p;
128   GLuint gl_framebuffer, gl_renderbuffer;
129 #   endif // USE_IPHONE
130 #  endif
131
132 # endif // JWXYZ_QUARTZ
133
134 # if defined JWXYZ_GL && defined USE_IPHONE
135   NSOpenGLContext *ogl_ctx_pixmap;
136 # endif // JWXYZ_GL && USE_IPHONE
137 }
138
139 - (id)initWithFrame:(NSRect)frame saverName:(NSString*)n isPreview:(BOOL)p;
140
141 - (void) render_x11;
142 - (NSOpenGLContext *) oglContext;
143 - (void) prepareContext;
144 - (NSUserDefaultsController *) userDefaultsController;
145 + (NSString *) decompressXML:(NSData *)xml;
146
147 #ifdef USE_IPHONE
148 - (CGFloat) hackedContentScaleFactor;
149 - (void)setScreenLocked:(BOOL)locked;
150 - (NSDictionary *)getGLProperties;
151 - (void)addExtraRenderbuffers:(CGSize)size;
152 - (NSString *)getCAGravity;
153 - (void)orientationChanged;
154 @property (nonatomic, assign) id<XScreenSaverViewDelegate> delegate;
155 @property (nonatomic) BOOL ignoreRotation;
156 - (BOOL)suppressRotationAnimation;
157 - (BOOL)rotateTouches;
158 #else // !USE_IPHONE
159 - (NSOpenGLPixelFormat *)getGLPixelFormat;
160 #endif // !USE_IPHONE
161
162 - (void)enableBackbuffer:(CGSize)new_backbuffer_size;
163 - (void)setViewport;
164 - (void)createBackbuffer:(CGSize)s;
165 - (void)reshape_x11;
166 #ifdef JWXYZ_QUARTZ
167 - (void)drawBackbuffer;
168 #endif // JWXYZ_QUARTZ
169 - (void)flushBackbuffer;
170
171 @end