1 /* xscreensaver, Copyright (c) 1991-2015 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 #ifndef __JWXYZ_COCOA_H__ 13 #define __JWXYZ_COCOA_H__ 14 15 #import "XScreenSaverView.h" 16 17 #ifdef USE_IPHONE 18 # import <UIKit/UIKit.h> 19 # define NSView UIView 20 # define NSOpenGLContext EAGLContext 21 #endif 22 23 #ifdef JWXYZ_QUARTZ 24 25 struct jwxyz_Drawable { 26 enum { WINDOW, PIXMAP } type; 27 CGContextRef cgc; 28 CGImageRef cgi; 29 XRectangle frame; 30 union { 31 struct { 32 XScreenSaverView *view; 33 int last_mouse_x, last_mouse_y; 34 } window; 35 struct { 36 int depth; 37 void *cgc_buffer; // the bits to which CGContextRef renders 38 } pixmap; 39 }; 40 }; 41 42 #elif defined JWXYZ_GL 43 44 struct jwxyz_Drawable { 45 enum { WINDOW, PIXMAP } type; 46 /* OS X: Contexts are unique for each pixmap, 'cause life is hectic. (OS X 47 appears to dislike it when you attach different pbuffers to the 48 same context one after the other, apparently.) The Window has this 49 CFRetained because of garbage collection. For both Pixmaps and 50 Windows, CFRelease this when done. 51 iOS: ogl_ctx here is set to either XScreenSaverView.ogl_ctx or 52 XRootWindow()->window.ogl_ctx_pixmap. No garbage collection antics 53 here, so no need to CFRetain anything. Plus, if a screenhack leaks 54 a Pixmap (and they do that all the time), ogl_ctx_pixmap will also 55 get leaked if a Pixmap CFRetains this. 56 */ 57 NSOpenGLContext *ogl_ctx; // OpenGL rendering context (OS X) 58 # ifdef USE_IPHONE 59 // TODO: Also on OS X as extensions. 60 GLuint gl_framebuffer, gl_renderbuffer; 61 # endif // USE_IPHONE 62 CGImageRef cgi; 63 XRectangle frame; 64 union { 65 struct { 66 XScreenSaverView *view; 67 int last_mouse_x, last_mouse_y; 68 struct jwxyz_Drawable *current_drawable; 69 # ifndef USE_IPHONE 70 NSOpenGLPixelFormat *pixfmt; 71 GLint virtual_screen; 72 # else // USE_IPHONE 73 NSOpenGLContext *ogl_ctx_pixmap; 74 # endif 75 } window; 76 struct { 77 int depth; 78 # ifndef USE_IPHONE 79 NSOpenGLPixelBuffer *gl_pbuffer; 80 // GLuint blit_texture; // TODO: For blitting from Pbuffers 81 # endif 82 } pixmap; 83 }; 84 }; 85 86 #endif // JWXYZ_GL 87 88 extern NSString *nsstring_from(const char *str, size_t len, int utf8_p); 89 90 #ifdef USE_IPHONE 91 extern void create_framebuffer (GLuint *gl_framebuffer, 92 GLuint *gl_renderbuffer); 93 extern void check_framebuffer_status (void); 94 #endif // USE_IPHONE 95 96 #define jwxyz_window_view(w) ((w)->window.view) 97 98 #endif 99