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