<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle"></style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">
<div>From da087e70822996ed0d8e2556a3bd9fda5a0b5d9d Mon Sep 17 00:00:00 2001</div>
<div>From: Henry Song <hsong@sisa.samsung.com></div>
<div>Date: Fri, 4 Jan 2013 18:05:53 -0800</div>
<div>Subject: [PATCH] gl: add test cases for nsgl-window</div>
<div><br>
</div>
<div>---</div>
<div> boilerplate/cairo-boilerplate-nsgl.m | 134 ++++++++++++++++++++++++++++++++++-</div>
<div> 1 file changed, 132 insertions(+), 2 deletions(-)</div>
<div><br>
</div>
<div>diff --git a/boilerplate/cairo-boilerplate-nsgl.m b/boilerplate/cairo-boilerplate-nsgl.m</div>
<div>index f6ead00..2247886 100644</div>
<div>--- a/boilerplate/cairo-boilerplate-nsgl.m</div>
<div>+++ b/boilerplate/cairo-boilerplate-nsgl.m</div>
<div>@@ -40,17 +40,50 @@</div>
<div> </div>
<div> #import <AppKit/NSOpenGL.h></div>
<div> #import <Foundation/NSAutoreleasePool.h></div>
<div>+#import <Cocoa/Cocoa.h></div>
<div> </div>
<div> static const cairo_user_data_key_t gl_closure_key;</div>
<div> </div>
<div> typedef struct _nsgl_target_closure {</div>
<div>     NSOpenGLContext *ctx;</div>
<div>     NSAutoreleasePool *pool;</div>
<div>+    NSOpenGLView *view;</div>
<div>+    NSWindow *window;</div>
<div> </div>
<div>     cairo_device_t *device;</div>
<div>     cairo_surface_t *surface;</div>
<div> } nsgl_target_closure_t;</div>
<div> </div>
<div>+@interface NSGLTestView : NSOpenGLView {</div>
<div>+}</div>
<div>+</div>
<div>+@end</div>
<div>+</div>
<div>+@implementation NSGLTestView</div>
<div>+</div>
<div>++ (NSOpenGLPixelFormat*)defaultPixelFormat</div>
<div>+{</div>
<div>+    NSOpenGLPixelFormatAttribute attrs[] =</div>
<div>+    {</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>NSOpenGLPFADoubleBuffer,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>NSOpenGLPFADepthSize, 24,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>NSOpenGLPFAStencilSize, 8,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>NSOpenGLPFAAlphaSize, 8,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>NSOpenGLPFASampleBuffers, 1,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>NSOpenGLPFASamples, 4,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>NSOpenGLPFAMultisample,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>0</div>
<div>+    };</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span></div>
<div>+    NSOpenGLPixelFormat *classPixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attrs] autorelease];</div>
<div>+    if (!classPixelFormat)</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>exit (-1);</div>
<div>+</div>
<div>+    return classPixelFormat;</div>
<div>+}</div>
<div>+</div>
<div>+@end</div>
<div>+</div>
<div> static void</div>
<div> _cairo_boilerplate_nsgl_cleanup (void *closure)</div>
<div> {</div>
<div>@@ -60,7 +93,15 @@ _cairo_boilerplate_nsgl_cleanup (void *closure)</div>
<div>     cairo_device_destroy (gltc->device);</div>
<div> </div>
<div>     [NSOpenGLContext clearCurrentContext];</div>
<div>-    [gltc->ctx release];</div>
<div>+    </div>
<div>+    if (gltc->window) {</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>[gltc->window orderOut: nil];</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>[gltc->window release];</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>[gltc->view release];</div>
<div>+    }</div>
<div>+    else</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>[gltc->ctx release];</div>
<div>+</div>
<div>     [gltc->pool release];</div>
<div> </div>
<div>     free (gltc);</div>
<div>@@ -88,6 +129,8 @@ _cairo_boilerplate_nsgl_create_surface (const char<span class="Apple-tab-span" style="white-space:pre">
</span>*name,</div>
<div>     };</div>
<div> </div>
<div>     gltc = xcalloc (1, sizeof (nsgl_target_closure_t));</div>
<div>+    gltc->window = nil;</div>
<div>+    gltc->view = nil;</div>
<div>     *closure = gltc;</div>
<div>     gltc->pool = [[NSAutoreleasePool alloc] init];</div>
<div> </div>
<div>@@ -119,6 +162,78 @@ _cairo_boilerplate_nsgl_create_surface (const char<span class="Apple-tab-span" style="white-space:pre">
</span>*name,</div>
<div>     return surface;</div>
<div> }</div>
<div> </div>
<div>+static cairo_surface_t *</div>
<div>+_cairo_boilerplate_nsgl_create_view (const char<span class="Apple-tab-span" style="white-space:pre">
</span>*name,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>    cairo_content_t<span class="Apple-tab-span" style="white-space:pre">
</span>content,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>    double<span class="Apple-tab-span" style="white-space:pre">
</span>width,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>    double<span class="Apple-tab-span" style="white-space:pre">
</span>height,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>    double<span class="Apple-tab-span" style="white-space:pre">
</span>max_width,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>    double<span class="Apple-tab-span" style="white-space:pre">
</span>max_height,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>    cairo_boilerplate_mode_t   mode,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>    void<span class="Apple-tab-span" style="white-space:pre">
</span>**closure)</div>
<div>+{</div>
<div>+    nsgl_target_closure_t *gltc;</div>
<div>+    cairo_surface_t *surface;</div>
<div>+    int style = NSTexturedBackgroundWindowMask;</div>
<div>+</div>
<div>+    NSWindow *win;</div>
<div>+    NSOpenGLView *view;</div>
<div>+</div>
<div>+    NSScreen *screen = [NSScreen mainScreen];</div>
<div>+    NSRect frame = [screen frame];</div>
<div>+    int screen_height = frame.size.height;</div>
<div>+</div>
<div>+    gltc = xcalloc (1, sizeof (nsgl_target_closure_t));</div>
<div>+    gltc->window = nil;</div>
<div>+    gltc->view = nil;</div>
<div>+    *closure = gltc;</div>
<div>+</div>
<div>+    gltc->pool = [[NSAutoreleasePool alloc] init];</div>
<div>+    [NSApplication sharedApplication];</div>
<div>+    </div>
<div>+    if (width < 1)</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>width = 1;</div>
<div>+    if (height < 1)</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>height = 1;</div>
<div>+</div>
<div>+    win = [[NSWindow alloc] initWithContentRect: NSMakeRect (0, screen_height - ceil (height), ceil (width), ceil (height))</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>   styleMask: style</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>   backing: NSBackingStoreBuffered</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>   defer: NO];</div>
<div>+</div>
<div>+    view = [[NSGLTestView alloc] initWithFrame: NSMakeRect (0, 0, ceil (width), ceil (height))];</div>
<div>+    [win setContentView: view];</div>
<div>+    </div>
<div>+    gltc->view = view;</div>
<div>+    gltc->window = win;</div>
<div>+</div>
<div>+    gltc->ctx = [gltc->view openGLContext];</div>
<div>+</div>
<div>+    if (!gltc->ctx)</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return NULL;</div>
<div>+</div>
<div>+    [gltc->ctx makeCurrentContext];</div>
<div>+    gltc->device = cairo_nsgl_device_create (gltc->ctx);</div>
<div>+</div>
<div>+    gltc->surface = surface = cairo_gl_surface_create_for_view (gltc->device,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>gltc->view,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>ceil (width),</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>ceil (height));</div>
<div>+    if (cairo_surface_status (surface))</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>_cairo_boilerplate_nsgl_cleanup (gltc);</div>
<div>+</div>
<div>+    [win orderFront: win];</div>
<div>+</div>
<div>+    return surface;</div>
<div>+}</div>
<div>+</div>
<div>+static cairo_status_t</div>
<div>+_cairo_boilerplate_nsgl_finish_window (cairo_surface_t *surface)</div>
<div>+{</div>
<div>+    cairo_gl_surface_swapbuffers (surface);</div>
<div>+    return CAIRO_STATUS_SUCCESS;</div>
<div>+}</div>
<div>+</div>
<div> static void</div>
<div> _cairo_boilerplate_nsgl_synchronize (void *closure)</div>
<div> {</div>
<div>@@ -136,7 +251,7 @@ static const cairo_boilerplate_target_t targets[] = {</div>
<div>     {</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>"nsgl", "gl", NULL, NULL,</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>CAIRO_SURFACE_TYPE_GL, CAIRO_CONTENT_COLOR_ALPHA, 1,</div>
<div>-<span class="Apple-tab-span" style="white-space:pre"> </span>"cairo_nsgl_device_create",</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>"cairo_nsgl_surface_create",</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>_cairo_boilerplate_nsgl_create_surface,</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>cairo_surface_create_similar,</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>NULL, NULL,</div>
<div>@@ -146,6 +261,21 @@ static const cairo_boilerplate_target_t targets[] = {</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>_cairo_boilerplate_nsgl_synchronize,</div>
<div>         NULL,</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>TRUE, FALSE, FALSE</div>
<div>+    },</div>
<div>+    {</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>"nsgl-window", "gl", NULL, NULL,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>CAIRO_SURFACE_TYPE_GL, CAIRO_CONTENT_COLOR_ALPHA, 1,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>"cairo_nsgl_surface_create_for_window",</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>_cairo_boilerplate_nsgl_create_view,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cairo_surface_create_similar,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>NULL,</div>
<div>+ <span class="Apple-tab-span" style="white-space:pre"></span>_cairo_boilerplate_nsgl_finish_window,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>_cairo_boilerplate_get_image_surface,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cairo_surface_write_to_png,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>_cairo_boilerplate_nsgl_cleanup,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>_cairo_boilerplate_nsgl_synchronize,</div>
<div>+        NULL,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>FALSE, FALSE, FALSE</div>
<div>     }</div>
<div> };</div>
<div> CAIRO_BOILERPLATE (nsgl, targets)</div>
<div>-- </div>
<div>1.8.0.1</div>
<div><br>
</div>
</div>
</body>
</html>