1 /*
2 * Cogl
3 *
4 * A Low Level GPU Graphics and Utilities API
5 *
6 * Copyright (C) 2011 Intel Corporation.
7 *
8 * Permission is hereby granted, free of charge, to any person
9 * obtaining a copy of this software and associated documentation
10 * files (the "Software"), to deal in the Software without
11 * restriction, including without limitation the rights to use, copy,
12 * modify, merge, publish, distribute, sublicense, and/or sell copies
13 * of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
23 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 *
28 * Authors:
29 * Robert Bragg <robert@linux.intel.com>
30 */
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include "cogl-object.h"
37
38 #include "cogl-framebuffer-private.h"
39 #include "cogl-onscreen-template-private.h"
40 #include "cogl-gtype-private.h"
41
42 #include <stdlib.h>
43
44 static void _cogl_onscreen_template_free (CoglOnscreenTemplate *onscreen_template);
45
46 COGL_OBJECT_DEFINE (OnscreenTemplate, onscreen_template);
47 COGL_GTYPE_DEFINE_CLASS (OnscreenTemplate, onscreen_template);
48
49 static void
_cogl_onscreen_template_free(CoglOnscreenTemplate * onscreen_template)50 _cogl_onscreen_template_free (CoglOnscreenTemplate *onscreen_template)
51 {
52 g_slice_free (CoglOnscreenTemplate, onscreen_template);
53 }
54
55 CoglOnscreenTemplate *
cogl_onscreen_template_new(CoglSwapChain * swap_chain)56 cogl_onscreen_template_new (CoglSwapChain *swap_chain)
57 {
58 CoglOnscreenTemplate *onscreen_template = g_slice_new0 (CoglOnscreenTemplate);
59 char *user_config;
60
61 onscreen_template->config.swap_chain = swap_chain;
62 if (swap_chain)
63 cogl_object_ref (swap_chain);
64 else
65 onscreen_template->config.swap_chain = cogl_swap_chain_new ();
66
67 onscreen_template->config.swap_throttled = TRUE;
68 onscreen_template->config.need_stencil = TRUE;
69 onscreen_template->config.samples_per_pixel = 0;
70
71 user_config = getenv ("COGL_POINT_SAMPLES_PER_PIXEL");
72 if (user_config)
73 {
74 unsigned long samples_per_pixel = strtoul (user_config, NULL, 10);
75 if (samples_per_pixel != ULONG_MAX)
76 onscreen_template->config.samples_per_pixel =
77 samples_per_pixel;
78 }
79
80 return _cogl_onscreen_template_object_new (onscreen_template);
81 }
82
83 void
cogl_onscreen_template_set_samples_per_pixel(CoglOnscreenTemplate * onscreen_template,int samples_per_pixel)84 cogl_onscreen_template_set_samples_per_pixel (
85 CoglOnscreenTemplate *onscreen_template,
86 int samples_per_pixel)
87 {
88 onscreen_template->config.samples_per_pixel = samples_per_pixel;
89 }
90
91 void
cogl_onscreen_template_set_swap_throttled(CoglOnscreenTemplate * onscreen_template,CoglBool throttled)92 cogl_onscreen_template_set_swap_throttled (
93 CoglOnscreenTemplate *onscreen_template,
94 CoglBool throttled)
95 {
96 onscreen_template->config.swap_throttled = throttled;
97 }
98
99 void
cogl_onscreen_template_set_stereo_enabled(CoglOnscreenTemplate * onscreen_template,CoglBool enabled)100 cogl_onscreen_template_set_stereo_enabled (
101 CoglOnscreenTemplate *onscreen_template,
102 CoglBool enabled)
103 {
104 onscreen_template->config.stereo_enabled = enabled;
105 }
106