<commit_before>/* Clutter -  An OpenGL based 'interactive canvas' library.
 * OSX backend - initial entry point
 *
 * Copyright (C) 2007-2008  <NAME> <<EMAIL>>
 * Copyright (C) 2007  OpenedHand Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 *
 */
#include "config.h"

#include "clutter-osx.h"
#include "clutter-backend-osx.h"
#include "clutter-stage-osx.h"
#include "../clutter-private.h"
#include "cogl/cogl.h"

#include <clutter/clutter-debug.h>
#import <AppKit/AppKit.h>

G_DEFINE_TYPE (ClutterBackendOSX, clutter_backend_osx, CLUTTER_TYPE_BACKEND)

/*************************************************************************/
static gboolean
clutter_backend_osx_post_parse (ClutterBackend  *backend,
                                GError         **error)
{
  ClutterBackendOSX *self = CLUTTER_BACKEND_OSX (backend);

  CLUTTER_NOTE (BACKEND, "post_parse");

  CLUTTER_OSX_POOL_ALLOC();

  /* Bring our app to foreground, background apps don't appear in dock or
   * accept keyboard focus.
   */
  const ProcessSerialNumber psn = { 0, kCurrentProcess };
  TransformProcessType (&psn, kProcessTransformToForegroundApplication);

  /* Also raise our app to front, otherwise our window will remain under the
   * terminal.
   */
  SetFrontProcess (&psn);

  [NSApplication sharedApplication];

  /* Allocate ourselves a GL context. Since we're supposed to have only one per
   * backend we can just as well create it now.
   */
  NSOpenGLPixelFormatAttribute attrs[] = {
    NSOpenGLPFADoubleBuffer,
    NSOpenGLPFADepthSize, 24,
    NSOpenGLPFAStencilSize, 8,
    0
  };
  self->pixel_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
  self->context = [[NSOpenGLContext alloc]
                   initWithFormat: self->pixel_format
                     shareContext: nil];

  /* Enable vblank sync - http://developer.apple.com/qa/qa2007/qa1521.html */
  #ifdef MAC_OS_X_VERSION_10_5
	const int sw = 1;
  #else
    const long sw = 1;
  #endif
  [self->context setValues:&sw forParameter: NSOpenGLCPSwapInterval];

  /* FIXME: move the debugging bits to cogl */
  [self->context makeCurrentContext];
  CLUTTER_NOTE(BACKEND, "GL information\n"
               "    GL_VENDOR: %s\n"
               "  GL_RENDERER: %s\n"
               "   GL_VERSION: %s\n"
               "GL_EXTENSIONS: %s\n",
               glGetString (GL_VENDOR),
               glGetString (GL_RENDERER),
               glGetString (GL_VERSION),
               glGetString (GL_EXTENSIONS));
  [NSOpenGLContext clearCurrentContext];

  CLUTTER_OSX_POOL_RELEASE();<commit_msg>osx: Fixed crash while features initialization<commit_after>/* Clutter -  An OpenGL based 'interactive canvas' library.
 * OSX backend - initial entry point
 *
 * Copyright (C) 2007-2008  <NAME> <<EMAIL>>
 * Copyright (C) 2007  OpenedHand Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 *
 */
#include "config.h"

#include "clutter-osx.h"
#include "clutter-backend-osx.h"
#include "clutter-stage-osx.h"
#include "../clutter-private.h"
#include "cogl/cogl.h"

#include <clutter/clutter-debug.h>
#import <AppKit/AppKit.h>

G_DEFINE_TYPE (ClutterBackendOSX, clutter_backend_osx, CLUTTER_TYPE_BACKEND)

/*************************************************************************/
static gboolean
clutter_backend_osx_post_parse (ClutterBackend  *backend,
                                GError         **error)
{
  ClutterBackendOSX *self = CLUTTER_BACKEND_OSX (backend);

  CLUTTER_NOTE (BACKEND, "post_parse");

  CLUTTER_OSX_POOL_ALLOC();

  /* Bring our app to foreground, background apps don't appear in dock or
   * accept keyboard focus.
   */
  const ProcessSerialNumber psn = { 0, kCurrentProcess };
  TransformProcessType (&psn, kProcessTransformToForegroundApplication);

  /* Also raise our app to front, otherwise our window will remain under the
   * terminal.
   */
  SetFrontProcess (&psn);

  [NSApplication sharedApplication];

  /* Allocate ourselves a GL context. Since we're supposed to have only one per
   * backend we can just as well create it now.
   */
  NSOpenGLPixelFormatAttribute attrs[] = {
    NSOpenGLPFADoubleBuffer,
    NSOpenGLPFADepthSize, 24,
    NSOpenGLPFAStencilSize, 8,
    0
  };
  self->pixel_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
  self->context = [[NSOpenGLContext alloc]
                   initWithFormat: self->pixel_format
                     shareContext: nil];

  /* Enable vblank sync - http://developer.apple.com/qa/qa2007/qa1521.html */
  #ifdef MAC_OS_X_VERSION_10_5
	const int sw = 1;
  #else
    const long sw = 1;
  #endif
  [self->context setValues:&sw forParameter: NSOpenGLCPSwapInterval];

  /* FIXME: move the debugging bits to cogl */
  [self->context makeCurrentContext];
  CLUTTER_NOTE(BACKEND, "GL information\n"
               "    GL_VENDOR: %s\n"
               "  GL_RENDERER: %s\n"
               "   GL_VERSION: %s\n"
               "GL_EXTENSIONS: %s\n",
               glGetString (GL_VENDOR),
               glGetString (GL_RENDERER),
               glGetString (GL_VERSION),
               glGetString (GL_EXTENSIONS));

  CLUTTER_OSX_POOL_RELEASE();
{'fraction_non_alphanumeric': 0.11494974874371859, 'fraction_numerical': 0.009736180904522614, 'mean_word_length': 3.2403462050599203, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3376983', 'n_tokens_mistral': 2005, 'n_tokens_neox': 1900, 'n_words': 588}