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
72 # elif defined(USE_TOUCHBAR)
76 struct xscreensaver_function_table *xsft;
77 PrefsReader *prefsReader;
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
84 // Data used by the Xlib-flavored screensaver
89 void (*fps_cb) (Display *, Window, fps_state *, void *);
91 BOOL _lowrez_p; // Whether the saver prefers 1990s pixels.
95 BOOL _ignoreRotation; // whether hack requested "always portrait".
96 // some want this, some do not.
99 NSDictionary *function_tables;
101 id<XScreenSaverViewDelegate> _delegate;
104 NSTimer *closeBoxTimer;
106 CGAffineTransform pinch_transform;
110 NSOpenGLPixelFormat *pixfmt;
112 # endif // !USE_IPHONE
115 XScreenSaverView *touchbar_view;
119 NSOpenGLContext *ogl_ctx; // OpenGL rendering context
122 CGContextRef backbuffer;
123 CGColorSpaceRef colorspace;
125 # ifdef BACKBUFFER_OPENGL
126 void *backbuffer_data;
127 GLsizei backbuffer_len;
129 GLsizei gl_texture_w, gl_texture_h;
131 GLuint backbuffer_texture;
132 GLenum gl_texture_target;
133 GLenum gl_pixel_format, gl_pixel_type;
135 BOOL double_buffered_p, gl_apple_client_storage_p;
137 BOOL gl_limited_npot_p;
138 GLuint gl_framebuffer, gl_renderbuffer;
139 # endif // USE_IPHONE
142 # endif // JWXYZ_QUARTZ
144 # if defined JWXYZ_GL && defined USE_IPHONE
145 NSOpenGLContext *ogl_ctx_pixmap;
146 # endif // JWXYZ_GL && USE_IPHONE
149 - (id)initWithFrame:(NSRect)frame saverName:(NSString*)n isPreview:(BOOL)p;
152 - (NSOpenGLContext *) oglContext;
153 - (void) prepareContext;
154 - (NSUserDefaultsController *) userDefaultsController;
155 + (NSString *) decompressXML:(NSData *)xml;
157 - (CGFloat) hackedContentScaleFactor;
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;
170 - (NSOpenGLPixelFormat *)getGLPixelFormat;
171 #endif // !USE_IPHONE
173 - (void)enableBackbuffer:(CGSize)new_backbuffer_size;
175 - (void)createBackbuffer:(CGSize)s;
178 - (void)drawBackbuffer;
179 #endif // JWXYZ_QUARTZ
180 - (void)flushBackbuffer;