~ubuntu-branches/ubuntu/hoary/gnustep-back/hoary

« back to all changes in this revision

Viewing changes to Source/cairo/XGCairoGlitzSurface.m

  • Committer: Bazaar Package Importer
  • Author(s): Eric Heintzmann
  • Date: 2004-11-18 20:18:30 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041118201830-h8fv5qdh4drqengh
Tags: 0.9.4-2
Rebuild using latest GNUstep libs (closes: #281007).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2002 Free Software Foundation, Inc.
 
3
 
 
4
   Author:  Alexander Malmberg <alexander@malmberg.org>
 
5
   Author: Banlu Kemiyatorn <object at gmail dot com>
 
6
 
 
7
   This file is part of GNUstep.
 
8
 
 
9
   This library is free software; you can redistribute it and/or
 
10
   modify it under the terms of the GNU Library General Public
 
11
   License as published by the Free Software Foundation; either
 
12
   version 2 of the License, or (at your option) any later version.
 
13
   
 
14
   This library is distributed in the hope that it will be useful,
 
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
   Library General Public License for more details.
 
18
   
 
19
   You should have received a copy of the GNU Library General Public
 
20
   License along with this library; if not, write to the Free
 
21
   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
22
*/
 
23
 
 
24
#include <Foundation/NSUserDefaults.h>
 
25
#include <math.h>
 
26
#include "cairo/XGCairoGlitzSurface.h"
 
27
 
 
28
#define GSWINDEVICE ((gswindow_device_t *)gsDevice)
 
29
 
 
30
@implementation XGCairoGlitzSurface
 
31
 
 
32
+ (CairoSurface *) createSurfaceForDevice: (void *)device
 
33
                                depthInfo: (CairoInfo *)cairoInfo
 
34
{
 
35
#define NEWGSWINDEVICE ((gswindow_device_t *)device)
 
36
  XGCairoGlitzSurface *surface;
 
37
 
 
38
  surface = [[self alloc] initWithDevice:NEWGSWINDEVICE];
 
39
  
 
40
  
 
41
  NSAssert(NEWGSWINDEVICE->buffer, @"FIXME! CairoSurface: Strange, a window doesn't have buffer");
 
42
 
 
43
  return surface;
 
44
#undef NEWGSWINDEVICE
 
45
}
 
46
 
 
47
 
 
48
- (NSString *) description
 
49
{
 
50
  return [NSString stringWithFormat: @"<XGCairoSurface %p xr:%p>", self, NULL];
 
51
}
 
52
 
 
53
- (id) initWithDevice: (void *)device
 
54
{
 
55
  /* FIXME format is ignore when Visual isn't NULL
 
56
   * Cairo may change this API
 
57
   */
 
58
  gsDevice = device;
 
59
 
 
60
  /*
 
61
    if (GSWINDEVICE->type != NSBackingStoreNonretained)
 
62
    {
 
63
    XSetWindowBackgroundPixmap(GSWINDEVICE->display,
 
64
    GSWINDEVICE->ident,
 
65
    GSWINDEVICE->buffer);
 
66
    }
 
67
  */
 
68
  
 
69
  return self;
 
70
}
 
71
 
 
72
- (void) setAsTargetOfCairo: (cairo_t *)ct
 
73
{
 
74
  glitz_surface_t *glsurface;
 
75
  glitz_format_t *format;
 
76
  Colormap cm;
 
77
  XVisualInfo *vi;
 
78
  unsigned long format_options = GLITZ_FORMAT_OPTION_ONSCREEN_MASK;
 
79
 
 
80
  format_options |= GLITZ_FORMAT_OPTION_NO_MULTISAMPLE_MASK;
 
81
  format_options |= GLITZ_FORMAT_OPTION_SINGLEBUFFER_MASK;
 
82
  
 
83
  format = glitz_glx_find_standard_format(GSWINDEVICE->display,
 
84
                                          GSWINDEVICE->screen,
 
85
                                          format_options,
 
86
                                          GLITZ_STANDARD_RGB24);
 
87
  
 
88
  if (!format)
 
89
    {
 
90
      NSLog(@"XGCairoGlitzSurface : %d : no format",__LINE__);
 
91
      exit(1);
 
92
    }
 
93
 
 
94
  vi = glitz_glx_get_visual_info_from_format(GSWINDEVICE->display,
 
95
                                             GSWINDEVICE->screen,
 
96
                                             format);
 
97
  
 
98
  if (!vi)
 
99
    {
 
100
      NSLog(@"XGCairoGlitzSurface : %d : no visual info",__LINE__);
 
101
      exit(1);
 
102
    }
 
103
  
 
104
  /*
 
105
    cm = XCreateColormap(GSWINDEVICE->display,
 
106
    GSWINDEVICE->root, vi->visual, AllocNone);
 
107
    
 
108
    XSetWindowColormap(GSWINDEVICE->display,GSWINDEVICE->ident,cm);
 
109
  */
 
110
 
 
111
  glsurface = glitz_glx_surface_create(GSWINDEVICE->display,
 
112
                                       GSWINDEVICE->screen,
 
113
                                       format,
 
114
                                       GSWINDEVICE->ident);
 
115
//      glitz_surface_update_size(glsurface);
 
116
  
 
117
  cairo_set_target_gl(ct, glsurface);
 
118
}
 
119
 
 
120
- (NSSize) size
 
121
{
 
122
  return GSWINDEVICE->xframe.size;
 
123
}
 
124
 
 
125
@end
 
126