~ubuntu-branches/ubuntu/vivid/clutter-1.0/vivid-proposed

« back to all changes in this revision

Viewing changes to clutter/cex100/clutter-backend-cex100.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl
  • Date: 2012-05-01 23:50:39 UTC
  • mfrom: (4.1.22 experimental)
  • Revision ID: package-import@ubuntu.com-20120501235039-7wehcmtr33nqhv67
Tags: 1.10.4-2
Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Clutter.
 
3
 *
 
4
 * An OpenGL based 'interactive canvas' library.
 
5
 *
 
6
 * Copyright (C) 2010,2011  Intel Corporation.
 
7
 *               2011 Giovanni Campagna <scampa.giovanni@gmail.com>
 
8
 *
 
9
 * This library is free software; you can redistribute it and/or
 
10
 * modify it under the terms of the GNU Lesser 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
 * Lesser General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU Lesser General Public
 
20
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 
21
 
 
22
 * Authors:
 
23
 *  Matthew Allum
 
24
 *  Emmanuele Bassi
 
25
 *  Robert Bragg
 
26
 *  Neil Roberts
 
27
 */
 
28
 
 
29
#include "config.h"
 
30
 
 
31
#include <sys/types.h>
 
32
#include <sys/stat.h>
 
33
#include <fcntl.h>
 
34
#include <unistd.h>
 
35
 
 
36
#include <errno.h>
 
37
 
 
38
#include "clutter-backend-eglnative.h"
 
39
 
 
40
/* This is a Cogl based backend */
 
41
#include "cogl/clutter-stage-cogl.h"
 
42
 
 
43
#ifdef HAVE_EVDEV
 
44
#include "clutter-device-manager-evdev.h"
 
45
#endif
 
46
 
 
47
#include "clutter-debug.h"
 
48
#include "clutter-private.h"
 
49
#include "clutter-main.h"
 
50
#include "clutter-stage-private.h"
 
51
 
 
52
#ifdef COGL_HAS_EGL_SUPPORT
 
53
#include "clutter-egl.h"
 
54
#endif
 
55
 
 
56
#include "clutter-cex100.h"
 
57
 
 
58
static gdl_plane_id_t gdl_plane = GDL_PLANE_ID_UPP_C;
 
59
static guint gdl_n_buffers = CLUTTER_CEX100_TRIPLE_BUFFERING;
 
60
 
 
61
#define clutter_backend_cex100_get_type     _clutter_backend_cex100_get_type
 
62
 
 
63
G_DEFINE_TYPE (ClutterBackendCex100, clutter_backend_cex100, CLUTTER_TYPE_BACKEND);
 
64
 
 
65
static void
 
66
clutter_backend_cex100_dispose (GObject *gobject)
 
67
{
 
68
  ClutterBackendCex100 *backend_cex100 = CLUTTER_BACKEND_CEX100 (gobject);
 
69
 
 
70
  if (backend_cex100->event_timer != NULL)
 
71
    {
 
72
      g_timer_destroy (backend_cex100->event_timer);
 
73
      backend_cex100->event_timer = NULL;
 
74
    }
 
75
 
 
76
  G_OBJECT_CLASS (clutter_backend_cex100_parent_class)->dispose (gobject);
 
77
}
 
78
 
 
79
static CoglDisplay *
 
80
clutter_backend_cex100_get_display (ClutterBackend  *backend,
 
81
                                    CoglRenderer    *renderer,
 
82
                                    CoglSwapChain   *swap_chain,
 
83
                                    GError         **error)
 
84
{
 
85
  CoglOnscreenTemplate *onscreen_template = NULL;
 
86
  CoglDisplay *display;
 
87
 
 
88
  swap_chain = cogl_swap_chain_new ();
 
89
 
 
90
#if defined(COGL_HAS_GDL_SUPPORT)
 
91
  cogl_swap_chain_set_length (swap_chain, gdl_n_buffers);
 
92
#endif
 
93
 
 
94
  onscreen_template = cogl_onscreen_template_new (swap_chain);
 
95
 
 
96
  /* XXX: I have some doubts that this is a good design.
 
97
   * Conceptually should we be able to check an onscreen_template
 
98
   * without more details about the CoglDisplay configuration?
 
99
   */
 
100
  if (!cogl_renderer_check_onscreen_template (renderer,
 
101
                                              onscreen_template,
 
102
                                              error))
 
103
    goto error;
 
104
 
 
105
  display = cogl_display_new (renderer, onscreen_template);
 
106
 
 
107
#if defined(COGL_HAS_GDL_SUPPORT)
 
108
  cogl_gdl_display_set_plane (cogl_display, gdl_plane);
 
109
#endif
 
110
 
 
111
  return display;
 
112
}
 
113
 
 
114
static void
 
115
clutter_backend_cex100_class_init (ClutterBackendCex100Class *klass)
 
116
{
 
117
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
118
  ClutterBackendClass *backend_class = CLUTTER_BACKEND_CLASS (klass);
 
119
 
 
120
  gobject_class->dispose = clutter_backend_cex100_dispose;
 
121
 
 
122
  backend_class->stage_window_type = CLUTTER_TYPE_STAGE_COGL;
 
123
 
 
124
  backend_class->get_display = clutter_backend_cex100_get_display;
 
125
}
 
126
 
 
127
static void
 
128
clutter_backend_cex100_init (ClutterBackendCex100 *backend_cex100)
 
129
{
 
130
  backend_cex100->event_timer = g_timer_new ();
 
131
}
 
132
 
 
133
/**
 
134
 * clutter_cex100_set_plane:
 
135
 * @plane: a GDL plane
 
136
 *
 
137
 * Intel CE3100 and CE4100 have several planes (frame buffers) and a
 
138
 * hardware blender to blend the planes togeteher and produce the final
 
139
 * image.
 
140
 *
 
141
 * clutter_cex100_set_plane() let's you configure the GDL plane where
 
142
 * the stage will be drawn. By default Clutter will pick UPP_C
 
143
 * (GDL_PLANE_ID_UPP_C).
 
144
 *
 
145
 * <note>This function has to be called before clutter_init()</note>
 
146
 *
 
147
 * Since: 1.6
 
148
 */
 
149
void
 
150
clutter_cex100_set_plane (gdl_plane_id_t plane)
 
151
{
 
152
  g_return_if_fail (plane >= GDL_PLANE_ID_UPP_A && plane <= GDL_PLANE_ID_UPP_E);
 
153
 
 
154
  gdl_plane = plane;
 
155
}
 
156
 
 
157
/**
 
158
 * clutter_cex100_set_buffering_mode:
 
159
 * @mode: a #ClutterCex100BufferingMode
 
160
 *
 
161
 * Configure the buffering mode of the underlying GDL plane. The GDL
 
162
 * surface used by Clutter to draw can be backed up by either one or two
 
163
 * back buffers thus being double or triple buffered, respectively.
 
164
 *
 
165
 * Clutter defaults to %CLUTTER_CEX100_TRIPLE_BUFFERING.
 
166
 *
 
167
 * <note>This function has to be called before clutter_init()</note>
 
168
 *
 
169
 * Since: 1.6
 
170
 */
 
171
void
 
172
clutter_cex100_set_buffering_mode (ClutterCex100BufferingMode mode)
 
173
{
 
174
  g_return_if_fail (mode == CLUTTER_CEX100_DOUBLE_BUFFERING ||
 
175
                    mode == CLUTTER_CEX100_TRIPLE_BUFFERING);
 
176
 
 
177
  gdl_n_buffers = mode;
 
178
}
 
179
 
 
180
/**
 
181
 * clutter_cex100_get_egl_display:
 
182
 *
 
183
 * Retrieves the EGL display used by Clutter, if it supports the
 
184
 * EGL windowing system and if it is running using an EGL backend.
 
185
 *
 
186
 * Return value: the EGL display used by Clutter, or 0
 
187
 *
 
188
 * Since: 1.10
 
189
 */
 
190
EGLDisplay
 
191
clutter_cex100_get_egl_display (void)
 
192
{
 
193
  ClutterBackend *backend;
 
194
 
 
195
  if (!_clutter_context_is_initialized ())
 
196
    {
 
197
      g_critical ("The Clutter backend has not been initialized yet");
 
198
      return 0;
 
199
    }
 
200
 
 
201
  backend = clutter_get_default_backend ();
 
202
 
 
203
  if (!CLUTTER_IS_BACKEND_CEX100 (backend))
 
204
    {
 
205
      g_critical ("The Clutter backend is not a CEX100 backend");
 
206
      return 0;
 
207
    }
 
208
 
 
209
#if COGL_HAS_EGL_SUPPORT
 
210
  return cogl_egl_context_get_egl_display (backend->cogl_context);
 
211
#else
 
212
  return 0;
 
213
#endif
 
214
}