<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 ed13470c39ad6806a5351d80a21415390183b4b4 Mon Sep 17 00:00:00 2001</div>
<div>From: Henry Song <hsong@sisa.samsung.com></div>
<div>Date: Fri, 4 Jan 2013 19:04:21 -0800</div>
<div>Subject: [PATCH 2/2] gl: add nsgl test case for nsgl-window&</div>
<div><br>
</div>
<div>---</div>
<div> boilerplate/cairo-boilerplate-nsgl.m | 133 +++++++++++++++++++++++++++++++++--</div>
<div> 1 file changed, 129 insertions(+), 4 deletions(-)</div>
<div><br>
</div>
<div>diff --git a/boilerplate/cairo-boilerplate-nsgl.m b/boilerplate/cairo-boilerplate-nsgl.m</div>
<div>index aea5c75..2b66eaa 100644</div>
<div>--- a/boilerplate/cairo-boilerplate-nsgl.m</div>
<div>+++ b/boilerplate/cairo-boilerplate-nsgl.m</div>
<div>@@ -180,7 +180,7 @@ _cairo_boilerplate_nsgl_create_view (const char<span class="Apple-tab-span" style="white-space:pre">
</span>*name,</div>
<div> NSOpenGLView *view;</div>
<div> </div>
<div> NSScreen *screen = [NSScreen mainScreen];</div>
<div>- NSRect frame = [screen frame];</div>
<div>+ NSRect frame = [screen visibleFrame];</div>
<div> int screen_height = frame.size.height;</div>
<div> </div>
<div> gltc = xcalloc (1, sizeof (nsgl_target_closure_t));</div>
<div>@@ -227,9 +227,98 @@ _cairo_boilerplate_nsgl_create_view (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_db (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><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><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><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>+ cairo_status_t status;</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 visibleFrame];</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 = 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>+ surface = cairo_surface_create_similar (gltc->surface, content, width, height);</div>
<div>+</div>
<div>+ status = cairo_surface_set_user_data (surface, &gl_closure_key, gltc, NULL);</div>
<div>+ </div>
<div>+ if (status == CAIRO_STATUS_SUCCESS) {</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>[win orderFront: win];</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return surface;</div>
<div>+ }</div>
<div>+</div>
<div>+ cairo_surface_destroy (surface);</div>
<div>+ _cairo_boilerplate_nsgl_cleanup (gltc);</div>
<div>+</div>
<div>+ return cairo_boilerplate_surface_create_in_error (status);</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>+ nsgl_target_closure_t *gltc = cairo_surface_get_user_data (surface,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span> &gl_closure_key);</div>
<div>+</div>
<div>+ if (gltc != NULL && gltc->surface != NULL) {</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cairo_t *cr;</div>
<div>+</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cr = cairo_create (gltc->surface);</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cairo_surface_set_device_offset (surface, 0, 0);</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cairo_set_source_surface (cr, surface, 0, 0);</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cairo_paint (cr);</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cairo_destroy (cr);</div>
<div>+</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>surface = gltc->surface;</div>
<div>+ }</div>
<div>+</div>
<div> cairo_gl_surface_swapbuffers (surface);</div>
<div> return CAIRO_STATUS_SUCCESS;</div>
<div> }</div>
<div>@@ -247,6 +336,27 @@ _cairo_boilerplate_nsgl_synchronize (void *closure)</div>
<div> cairo_device_release (gltc->device);</div>
<div> }</div>
<div> </div>
<div>+static char *</div>
<div>+_cairo_boilerplate_nsgl_describe (void *closure)</div>
<div>+{</div>
<div>+ nsgl_target_closure_t *gltc = closure;</div>
<div>+ char *s;</div>
<div>+ const GLubyte *vendor, *renderer, *version;</div>
<div>+</div>
<div>+ if (cairo_device_acquire (gltc->device))</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return NULL;</div>
<div>+</div>
<div>+ vendor = glGetString (GL_VENDOR);</div>
<div>+ renderer = glGetString (GL_RENDERER);</div>
<div>+ version = glGetString (GL_VERSION);</div>
<div>+</div>
<div>+ xasprintf (&s, "%s %s %s", vendor, renderer, version);</div>
<div>+</div>
<div>+ cairo_device_release (gltc->device);</div>
<div>+</div>
<div>+ return s;</div>
<div>+}</div>
<div>+</div>
<div> 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>@@ -259,7 +369,7 @@ static const cairo_boilerplate_target_t targets[] = {</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>+ _cairo_boilerplate_nsgl_describe,</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>TRUE, FALSE, FALSE</div>
<div> },</div>
<div> {</div>
<div>@@ -273,7 +383,7 @@ static const cairo_boilerplate_target_t targets[] = {</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>+ _cairo_boilerplate_nsgl_describe,</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>TRUE, FALSE, FALSE</div>
<div> },</div>
<div> {</div>
<div>@@ -288,7 +398,22 @@ static const cairo_boilerplate_target_t targets[] = {</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>+ _cairo_boilerplate_nsgl_describe,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>FALSE, FALSE, FALSE</div>
<div>+ },</div>
<div>+ {</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>"nsgl-windowi&", "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_db,</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>+ _cairo_boilerplate_nsgl_describe,</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>FALSE, FALSE, FALSE</div>
<div> }</div>
<div> };</div>
<div>-- </div>
<div>1.8.0.1</div>
<div><br>
</div>
</div>
</body>
</html>