From http://www.jwz.org/xscreensaver/xscreensaver-5.39.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 # elif defined(USE_TOUCHBAR)
73                               <NSTouchBarDelegate>
74 # endif
75 {
76   struct xscreensaver_function_table *xsft;
77   PrefsReader *prefsReader;
78
79   BOOL setup_p;            // whether xsft->setup_cb() has been run
80   BOOL initted_p;          // whether xsft->init_cb() has been run
81   BOOL resized_p;          // whether to run the xsft->reshape_cb() soon
82   double next_frame_time;  // time_t in milliseconds of when to tick the frame
83
84   // Data used by the Xlib-flavored screensaver
85   Display *xdpy;
86   Window xwindow;
87   void *xdata;
88   fps_state *fpst;
89   void (*fps_cb) (Display *, Window, fps_state *, void *);
90
91   BOOL _lowrez_p;               // Whether the saver prefers 1990s pixels.
92
93 # ifdef USE_IPHONE
94   BOOL screenLocked;
95   BOOL _ignoreRotation;         // whether hack requested "always portrait".
96                                 // some want this, some do not.
97   NSTimer *crash_timer;
98
99   NSDictionary *function_tables;
100
101   id<XScreenSaverViewDelegate> _delegate;
102
103   UIView *closeBox;
104   NSTimer *closeBoxTimer;
105
106   CGAffineTransform pinch_transform;
107
108 # else // !USE_PHONE
109
110   NSOpenGLPixelFormat *pixfmt;
111
112 # endif // !USE_IPHONE
113
114 # ifdef USE_TOUCHBAR
115   XScreenSaverView *touchbar_view;
116   BOOL touchbar_p;
117 # endif
118
119   NSOpenGLContext *ogl_ctx;      // OpenGL rendering context
120
121 # ifdef JWXYZ_QUARTZ
122   CGContextRef backbuffer;
123   CGColorSpaceRef colorspace;
124
125 #  ifdef BACKBUFFER_OPENGL
126   void *backbuffer_data;
127   GLsizei backbuffer_len;
128
129   GLsizei gl_texture_w, gl_texture_h;
130
131   GLuint backbuffer_texture;
132   GLenum gl_texture_target;
133   GLenum gl_pixel_format, gl_pixel_type;
134 #   ifndef USE_IPHONE
135   BOOL double_buffered_p, gl_apple_client_storage_p;
136 #   else // USE_IPHONE
137   BOOL gl_limited_npot_p;
138   GLuint gl_framebuffer, gl_renderbuffer;
139 #   endif // USE_IPHONE
140 #  endif
141
142 # endif // JWXYZ_QUARTZ
143
144 # if defined JWXYZ_GL && defined USE_IPHONE
145   NSOpenGLContext *ogl_ctx_pixmap;
146 # endif // JWXYZ_GL && USE_IPHONE
147 }
148
149 - (id)initWithFrame:(NSRect)frame saverName:(NSString*)n isPreview:(BOOL)p;
150
151 - (void) render_x11;
152 - (NSOpenGLContext *) oglContext;
153 - (void) prepareContext;
154 - (NSUserDefaultsController *) userDefaultsController;
155 + (NSString *) decompressXML:(NSData *)xml;
156
157 - (CGFloat) hackedContentScaleFactor;
158
159 #ifdef USE_IPHONE
160 - (void)setScreenLocked:(BOOL)locked;
161 - (NSDictionary *)getGLProperties;
162 - (void)addExtraRenderbuffers:(CGSize)size;
163 - (NSString *)getCAGravity;
164 - (void)orientationChanged;
165 @property (nonatomic, assign) id<XScreenSaverViewDelegate> delegate;
166 @property (nonatomic) BOOL ignoreRotation;
167 - (BOOL)suppressRotationAnimation;
168 - (BOOL)rotateTouches;
169 #else // !USE_IPHONE
170 - (NSOpenGLPixelFormat *)getGLPixelFormat;
171 #endif // !USE_IPHONE
172
173 - (void)enableBackbuffer:(CGSize)new_backbuffer_size;
174 - (void)setViewport;
175 - (void)createBackbuffer:(CGSize)s;
176 - (void)reshape_x11;
177 #ifdef JWXYZ_QUARTZ
178 - (void)drawBackbuffer;
179 #endif // JWXYZ_QUARTZ
180 - (void)flushBackbuffer;
181
182 @end