1 /* xscreensaver, Copyright (c) 2006-2017 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>
32 //# define USE_TOUCHBAR
36 #import "screenhackI.h"
37 #import "PrefsReader.h"
41 @class XScreenSaverView;
43 @protocol XScreenSaverViewDelegate
44 - (void) wantsFadeOut:(XScreenSaverView *)saverView;
45 - (void) didShake:(XScreenSaverView *)saverView;
46 - (void) openPreferences: (NSString *)which;
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;
56 - (void)animateOneFrame;
57 - (BOOL)hasConfigureSheet;
58 //- (NSWindow*)configureSheet;
59 - (UIViewController*)configureView;
66 // Currently only OpenGL backbuffers are supported (OSX and iOS).
67 # define BACKBUFFER_OPENGL
69 @interface XScreenSaverView : ScreenSaverView
74 struct xscreensaver_function_table *xsft;
75 PrefsReader *prefsReader;
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
82 // Data used by the Xlib-flavored screensaver
87 void (*fps_cb) (Display *, Window, fps_state *, void *);
89 BOOL _lowrez_p; // Whether the saver prefers 1990s pixels.
93 BOOL _ignoreRotation; // whether hack requested "always portrait".
94 // some want this, some do not.
97 NSDictionary *function_tables;
99 id<XScreenSaverViewDelegate> _delegate;
102 NSTimer *closeBoxTimer;
104 CGAffineTransform pinch_transform;
108 NSOpenGLPixelFormat *pixfmt;
110 # endif // !USE_IPHONE
113 NSWindow *touchbar_window;
114 XScreenSaverView *touchbar_view;
117 NSOpenGLContext *ogl_ctx; // OpenGL rendering context
120 CGContextRef backbuffer;
121 CGColorSpaceRef colorspace;
123 # ifdef BACKBUFFER_OPENGL
124 void *backbuffer_data;
125 GLsizei backbuffer_len;
127 GLsizei gl_texture_w, gl_texture_h;
129 GLuint backbuffer_texture;
130 GLenum gl_texture_target;
131 GLenum gl_pixel_format, gl_pixel_type;
133 BOOL double_buffered_p, gl_apple_client_storage_p;
135 BOOL gl_limited_npot_p;
136 GLuint gl_framebuffer, gl_renderbuffer;
137 # endif // USE_IPHONE
140 # endif // JWXYZ_QUARTZ
142 # if defined JWXYZ_GL && defined USE_IPHONE
143 NSOpenGLContext *ogl_ctx_pixmap;
144 # endif // JWXYZ_GL && USE_IPHONE
147 - (id)initWithFrame:(NSRect)frame saverName:(NSString*)n isPreview:(BOOL)p;
150 - (NSOpenGLContext *) oglContext;
151 - (void) prepareContext;
152 - (NSUserDefaultsController *) userDefaultsController;
153 + (NSString *) decompressXML:(NSData *)xml;
155 - (CGFloat) hackedContentScaleFactor;
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;
168 - (NSOpenGLPixelFormat *)getGLPixelFormat;
169 #endif // !USE_IPHONE
171 - (void)enableBackbuffer:(CGSize)new_backbuffer_size;
173 - (void)createBackbuffer:(CGSize)s;
176 - (void)drawBackbuffer;
177 #endif // JWXYZ_QUARTZ
178 - (void)flushBackbuffer;