1 /* xscreensaver, Copyright (c) 2006-2016 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>
35 #import "screenhackI.h"
36 #import "PrefsReader.h"
40 @class XScreenSaverView;
42 @protocol XScreenSaverViewDelegate
43 - (void) wantsFadeOut:(XScreenSaverView *)saverView;
44 - (void) didShake:(XScreenSaverView *)saverView;
47 @interface ScreenSaverView : NSView
48 - (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview;
49 - (NSTimeInterval)animationTimeInterval;
50 - (void)setAnimationTimeInterval:(NSTimeInterval)timeInterval;
51 - (void)startAnimation;
52 - (void)stopAnimation;
54 - (void)animateOneFrame;
55 - (BOOL)hasConfigureSheet;
56 //- (NSWindow*)configureSheet;
57 - (UIViewController*)configureView;
64 // Currently only OpenGL backbuffers are supported (OSX and iOS).
65 # define BACKBUFFER_OPENGL
67 @interface XScreenSaverView : ScreenSaverView
72 struct xscreensaver_function_table *xsft;
73 PrefsReader *prefsReader;
75 BOOL setup_p; // whether xsft->setup_cb() has been run
76 BOOL initted_p; // whether xsft->init_cb() has been run
77 BOOL resized_p; // whether to run the xsft->reshape_cb() soon
78 double next_frame_time; // time_t in milliseconds of when to tick the frame
80 // Data used by the Xlib-flavored screensaver
88 BOOL _ignoreRotation; // whether hack requested "always portrait".
89 // some want this, some do not.
92 NSDictionary *function_tables;
94 id<XScreenSaverViewDelegate> _delegate;
98 NSOpenGLPixelFormat *pixfmt;
100 # endif // !USE_IPHONE
102 NSOpenGLContext *ogl_ctx; // OpenGL rendering context
105 CGContextRef backbuffer;
106 CGColorSpaceRef colorspace;
108 # ifdef BACKBUFFER_OPENGL
109 void *backbuffer_data;
110 size_t backbuffer_len;
112 GLsizei gl_texture_w, gl_texture_h;
114 GLuint backbuffer_texture;
115 GLenum gl_texture_target;
116 GLenum gl_pixel_format, gl_pixel_type;
118 BOOL double_buffered_p, gl_apple_client_storage_p;
120 BOOL gl_limited_npot_p;
121 GLuint gl_framebuffer, gl_renderbuffer;
122 # endif // USE_IPHONE
125 # endif // JWXYZ_QUARTZ
127 # if defined JWXYZ_GL && defined USE_IPHONE
128 NSOpenGLContext *ogl_ctx_pixmap;
129 # endif // JWXYZ_GL && USE_IPHONE
132 - (id)initWithFrame:(NSRect)frame saverName:(NSString*)n isPreview:(BOOL)p;
135 - (NSOpenGLContext *) oglContext;
136 - (void) prepareContext;
137 - (NSUserDefaultsController *) userDefaultsController;
138 + (NSString *) decompressXML:(NSData *)xml;
141 - (CGFloat) hackedContentScaleFactor;
142 - (void)setScreenLocked:(BOOL)locked;
143 - (NSDictionary *)getGLProperties;
144 - (void)addExtraRenderbuffers:(CGSize)size;
145 - (NSString *)getCAGravity;
146 - (void)orientationChanged;
147 @property (nonatomic, assign) id<XScreenSaverViewDelegate> delegate;
148 @property (nonatomic) BOOL ignoreRotation;
149 - (BOOL)suppressRotationAnimation;
150 - (BOOL)rotateTouches;
152 - (NSOpenGLPixelFormat *)getGLPixelFormat;
153 #endif // !USE_IPHONE
155 - (void)enableBackbuffer:(CGSize)new_backbuffer_size;
157 - (void)createBackbuffer:(CGSize)s;
160 - (void)drawBackbuffer;
161 #endif // JWXYZ_QUARTZ
162 - (void)flushBackbuffer;