summarylogtreecommitdiffstats
path: root/0002-gl-renderer-Refactor-gl_renderer_output_window_creat.patch
blob: 2c4528b9499862fc217ec2b19946ac07eff5c153 (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
From 1a6f5e3586cf62029a8bed8072bd41e845746bad Mon Sep 17 00:00:00 2001
From: "Miguel A. Vico" <mvicomoya@nvidia.com>
Date: Mon, 21 Mar 2016 17:37:32 +0100
Subject: [PATCH 2/7] gl-renderer: Refactor gl_renderer_output_window_create()
X-NVConfidentiality: public

In preparation for follow-on changes to support frame presentation
through EGLDevice+EGLOutput, this change refactors
gl_renderer_output_window_create() to separate out window surface
creation code from output common creation code.

Bonus: Fix EGLSurface leakage upon gl_renderer_setup() failure.

Signed-off-by: Miguel A Vico Moya <mvicomoya@nvidia.com>
Reviewed-by: Andy Ritger <aritger@nvidia.com>
---
 src/gl-renderer.c | 91 +++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 62 insertions(+), 29 deletions(-)

diff --git a/src/gl-renderer.c b/src/gl-renderer.c
index 0c55e0b9ebd2..1d6d98c9b86b 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -1,6 +1,7 @@
 /*
  * Copyright © 2012 Intel Corporation
  * Copyright © 2015 Collabora, Ltd.
+ * Copyright © 2016 NVIDIA Corporation
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -2546,24 +2547,21 @@ gl_renderer_output_set_border(struct weston_output *output,
 static int
 gl_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface);
 
-static int
-gl_renderer_output_window_create(struct weston_output *output,
+static EGLSurface
+gl_renderer_create_window_surface(struct gl_renderer *gr,
 			  EGLNativeWindowType window_for_legacy,
 			  void *window_for_platform,
 			  const EGLint *config_attribs,
 			  const EGLint *visual_id,
 			  int n_ids)
 {
-	struct weston_compositor *ec = output->compositor;
-	struct gl_renderer *gr = get_renderer(ec);
-	struct gl_output_state *go;
+	EGLSurface egl_surface = EGL_NO_SURFACE;
 	EGLConfig egl_config;
-	int i;
 
 	if (egl_choose_config(gr, config_attribs, visual_id,
 			      n_ids, &egl_config) == -1) {
 		weston_log("failed to choose EGL config for output\n");
-		return -1;
+		return EGL_NO_SURFACE;
 	}
 
 	if (egl_config != gr->egl_config &&
@@ -2571,48 +2569,83 @@ gl_renderer_output_window_create(struct weston_output *output,
 		weston_log("attempted to use a different EGL config for an "
 			   "output but EGL_MESA_configless_context is not "
 			   "supported\n");
-		return -1;
+		return EGL_NO_SURFACE;
 	}
 
-	go = zalloc(sizeof *go);
-	if (go == NULL)
-		return -1;
+	log_egl_config_info(gr->egl_display, egl_config);
 
-	if (gr->create_platform_window) {
-		go->egl_surface =
-			gr->create_platform_window(gr->egl_display,
-						   egl_config,
-						   window_for_platform,
-						   NULL);
-	} else {
-		go->egl_surface =
-			eglCreateWindowSurface(gr->egl_display,
-					       egl_config,
-					       window_for_legacy, NULL);
-	}
+	if (gr->create_platform_window)
+		egl_surface = gr->create_platform_window(gr->egl_display,
+		                                         egl_config,
+		                                         window_for_platform,
+		                                         NULL);
+	else
+		egl_surface = eglCreateWindowSurface(gr->egl_display,
+		                                     egl_config,
+		                                     window_for_legacy, NULL);
+
+	return egl_surface;
+}
+
+static int
+gl_renderer_output_create(struct weston_output *output,
+                          EGLSurface surface)
+{
+	struct weston_compositor *ec = output->compositor;
+	struct gl_renderer *gr = get_renderer(ec);
+	struct gl_output_state *go;
+	int i;
 
-	if (go->egl_surface == EGL_NO_SURFACE) {
+	if (surface == EGL_NO_SURFACE) {
 		weston_log("failed to create egl surface\n");
-		free(go);
 		return -1;
 	}
 
 	if (gr->egl_context == NULL)
-		if (gl_renderer_setup(ec, go->egl_surface) < 0) {
-			free(go);
+		if (gl_renderer_setup(ec, surface) < 0) {
 			return -1;
 		}
 
+	go = zalloc(sizeof *go);
+	if (go == NULL)
+		return -1;
+
+	go->egl_surface = surface;
+
 	for (i = 0; i < BUFFER_DAMAGE_COUNT; i++)
 		pixman_region32_init(&go->buffer_damage[i]);
 
 	output->renderer_state = go;
 
-	log_egl_config_info(gr->egl_display, egl_config);
-
 	return 0;
 }
 
+static int
+gl_renderer_output_window_create(struct weston_output *output,
+                                 EGLNativeWindowType window_for_legacy,
+                                 void *window_for_platform,
+                                 const EGLint *config_attribs,
+                                 const EGLint *visual_id,
+                                 int n_ids)
+{
+	struct weston_compositor *ec = output->compositor;
+	struct gl_renderer *gr = get_renderer(ec);
+	EGLSurface egl_surface = EGL_NO_SURFACE;
+	int ret = 0;
+
+	egl_surface = gl_renderer_create_window_surface(gr,
+	                                                window_for_legacy,
+	                                                window_for_platform,
+	                                                config_attribs,
+	                                                visual_id, n_ids);
+
+	ret = gl_renderer_output_create(output, egl_surface);
+	if (ret < 0 && egl_surface != EGL_NO_SURFACE)
+		eglDestroySurface(gr->egl_display, egl_surface);
+
+	return ret;
+}
+
 static void
 gl_renderer_output_destroy(struct weston_output *output)
 {
-- 
2.7.4