File: XGCairoGlitzSurface.m

package info (click to toggle)
gnustep-back 0.18.0-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,920 kB
  • ctags: 1,015
  • sloc: objc: 36,805; ansic: 6,054; makefile: 218; sh: 151
file content (105 lines) | stat: -rw-r--r-- 2,978 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
   Copyright (C) 2002 Free Software Foundation, Inc.

   Author:  Alexander Malmberg <alexander@malmberg.org>
   Author: Banlu Kemiyatorn <object at gmail dot com>

   This file is part of GNUstep.

   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; see the file COPYING.LIB.
   If not, see <http://www.gnu.org/licenses/> or write to the 
   Free Software Foundation, 51 Franklin Street, Fifth Floor, 
   Boston, MA 02110-1301, USA.
*/

#include "cairo/XGCairoGlitzSurface.h"
#include <cairo-glitz.h>
#include <glitz-glx.h>

#define GSWINDEVICE ((gswindow_device_t *)gsDevice)

@implementation XGCairoGlitzSurface

- (id) initWithDevice: (void *)device
{
  glitz_drawable_format_t templ;
  glitz_drawable_format_t *dformat = NULL;
  glitz_drawable_t *drawable = NULL;
  glitz_format_t *format = NULL;
  glitz_surface_t *surface = NULL;

  gsDevice = device;

  /*
    if (GSWINDEVICE->type != NSBackingStoreNonretained)
    {
    XSetWindowBackgroundPixmap(GSWINDEVICE->display,
    GSWINDEVICE->ident,
    GSWINDEVICE->buffer);
    }
  */

  templ.doublebuffer = 0;
  dformat = glitz_glx_find_drawable_format_for_visual(GSWINDEVICE->display,
						      GSWINDEVICE->screen,
						      XVisualIDFromVisual(DefaultVisual(GSWINDEVICE->display, GSWINDEVICE->screen)));
  
  if (!dformat)
    {
      NSLog(@"XGCairoGlitzSurface : %d : no format",__LINE__);
      exit(1);
    }

  drawable = glitz_glx_create_drawable_for_window(GSWINDEVICE->display,
						  GSWINDEVICE->screen,
						  dformat,
						  GSWINDEVICE->ident,
						  GSWINDEVICE->xframe.size.width,
						  GSWINDEVICE->xframe.size.height);
  if (!drawable)
    {
      NSLog(@"XGCairoGlitzSurface : %d : no glitz drawable", __LINE__);
      exit(1);
    }

  format = glitz_find_standard_format(drawable, GLITZ_STANDARD_ARGB32);
  if (!format)
    {
      NSLog(@"XGCairoGlitzSurface : %d : couldn't find ARGB32 surface format", __LINE__);
      exit(1);
    }

  surface = glitz_surface_create(drawable, format,
				 GSWINDEVICE->xframe.size.width,
				 GSWINDEVICE->xframe.size.height,
				 0, NULL);
  if (!surface)
    {
      NSLog(@"XGCairoGlitzSurface : %d : couldn't create glitz surface", __LINE__);
      exit(1);
    }

  glitz_surface_attach(surface, drawable, GLITZ_DRAWABLE_BUFFER_FRONT_COLOR);
  _surface = cairo_glitz_surface_create(surface);
  
  return self;
}

- (NSSize) size
{
  return GSWINDEVICE->xframe.size;
}

@end