summaryrefslogtreecommitdiff
path: root/D148946.diff
blob: e4d9aa49c26a90471314a3463a8f00a902a438d9 (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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
diff -up firefox-101.0.1/gfx/gl/GLContextProviderEGL.cpp.D148946.diff firefox-101.0.1/gfx/gl/GLContextProviderEGL.cpp
--- firefox-101.0.1/gfx/gl/GLContextProviderEGL.cpp.D148946.diff	2022-06-14 14:25:07.290229683 +0200
+++ firefox-101.0.1/gfx/gl/GLContextProviderEGL.cpp	2022-06-14 14:25:07.313230450 +0200
@@ -1190,42 +1190,16 @@ RefPtr<GLContextEGL> GLContextEGL::Creat
 }
 
 /*static*/
-RefPtr<GLContextEGL> GLContextEGL::CreateEGLSurfacelessContext(
-    const std::shared_ptr<EglDisplay> display, const GLContextCreateDesc& desc,
-    nsACString* const out_failureId) {
-  const EGLConfig config = {};
-  auto fullDesc = GLContextDesc{desc};
-  fullDesc.isOffscreen = true;
-  RefPtr<GLContextEGL> gl = GLContextEGL::CreateGLContext(
-      display, fullDesc, config, EGL_NO_SURFACE, false, out_failureId);
-  if (!gl) {
-    NS_WARNING("Failed to create surfaceless GL context");
-    return nullptr;
-  }
-  return gl;
-}
-
-/*static*/
 already_AddRefed<GLContext> GLContextProviderEGL::CreateHeadless(
     const GLContextCreateDesc& desc, nsACString* const out_failureId) {
   const auto display = DefaultEglDisplay(out_failureId);
   if (!display) {
     return nullptr;
   }
-  RefPtr<GLContextEGL> gl;
-#ifdef MOZ_WAYLAND
-  if (!gdk_display_get_default() &&
-      display->IsExtensionSupported(EGLExtension::MESA_platform_surfaceless)) {
-    gl =
-        GLContextEGL::CreateEGLSurfacelessContext(display, desc, out_failureId);
-  } else
-#endif
-  {
-    mozilla::gfx::IntSize dummySize = mozilla::gfx::IntSize(16, 16);
-    gl = GLContextEGL::CreateEGLPBufferOffscreenContext(
-        display, desc, dummySize, out_failureId);
-  }
-  return gl.forget();
+  mozilla::gfx::IntSize dummySize = mozilla::gfx::IntSize(16, 16);
+  auto ret = GLContextEGL::CreateEGLPBufferOffscreenContext(
+      display, desc, dummySize, out_failureId);
+  return ret.forget();
 }
 
 // Don't want a global context on Android as 1) share groups across 2 threads
diff -up firefox-101.0.1/gfx/gl/GLDefs.h.D148946.diff firefox-101.0.1/gfx/gl/GLDefs.h
--- firefox-101.0.1/gfx/gl/GLDefs.h.D148946.diff	2022-06-14 14:25:07.290229683 +0200
+++ firefox-101.0.1/gfx/gl/GLDefs.h	2022-06-14 14:25:07.313230450 +0200
@@ -104,9 +104,6 @@ bool CheckContextLost(const GLContext* g
 // EGL_ANGLE_image_d3d11_texture
 #define LOCAL_EGL_D3D11_TEXTURE_ANGLE                   0x3484
 
-// EGL_MESA_platform_surfaceless
-#define LOCAL_EGL_PLATFORM_SURFACELESS_MESA             0x31DD
-
 // clang-format on
 
 #endif
diff -up firefox-101.0.1/gfx/gl/GLLibraryEGL.cpp.D148946.diff firefox-101.0.1/gfx/gl/GLLibraryEGL.cpp
--- firefox-101.0.1/gfx/gl/GLLibraryEGL.cpp.D148946.diff	2022-06-14 14:25:07.307230250 +0200
+++ firefox-101.0.1/gfx/gl/GLLibraryEGL.cpp	2022-06-14 14:27:03.477110994 +0200
@@ -53,9 +53,15 @@ StaticRefPtr<GLLibraryEGL> GLLibraryEGL:
 
 // should match the order of EGLExtensions, and be null-terminated.
 static const char* sEGLLibraryExtensionNames[] = {
-    "EGL_ANDROID_get_native_client_buffer", "EGL_ANGLE_device_creation",
-    "EGL_ANGLE_device_creation_d3d11",      "EGL_ANGLE_platform_angle",
-    "EGL_ANGLE_platform_angle_d3d",         "EGL_EXT_device_query"};
+    "EGL_ANDROID_get_native_client_buffer",
+    "EGL_ANGLE_device_creation",
+    "EGL_ANGLE_device_creation_d3d11",
+    "EGL_ANGLE_platform_angle",
+    "EGL_ANGLE_platform_angle_d3d",
+    "EGL_EXT_device_enumeration",
+    "EGL_EXT_device_query",
+    "EGL_EXT_platform_device",
+    "EGL_MESA_platform_surfaceless"};
 
 // should match the order of EGLExtensions, and be null-terminated.
 static const char* sEGLExtensionNames[] = {
@@ -83,7 +89,6 @@ static const char* sEGLExtensionNames[]
     "EGL_EXT_buffer_age",
     "EGL_KHR_partial_update",
     "EGL_NV_robustness_video_memory_purge",
-    "EGL_MESA_platform_surfaceless",
     "EGL_EXT_image_dma_buf_import",
     "EGL_EXT_image_dma_buf_import_modifiers",
     "EGL_MESA_image_dma_buf_export"};
@@ -156,8 +161,52 @@ static std::shared_ptr<EglDisplay> GetAn
 }
 
 #ifdef MOZ_WAYLAND
+static std::shared_ptr<EglDisplay> GetAndInitDeviceDisplay(
+    GLLibraryEGL& egl, const StaticMutexAutoLock& aProofOfLock) {
+  nsAutoCString drmRenderDevice(gfx::gfxVars::DrmRenderDevice());
+  if (drmRenderDevice.IsEmpty() ||
+      !egl.IsExtensionSupported(EGLLibExtension::EXT_platform_device) ||
+      !egl.IsExtensionSupported(EGLLibExtension::EXT_device_enumeration)) {
+    return nullptr;
+  }
+
+  EGLint maxDevices;
+  if (!egl.fQueryDevicesEXT(0, nullptr, &maxDevices)) {
+    return nullptr;
+  }
+
+  std::vector<EGLDeviceEXT> devices(maxDevices);
+  EGLint numDevices;
+  if (!egl.fQueryDevicesEXT(devices.size(), devices.data(), &numDevices)) {
+    return nullptr;
+  }
+  devices.resize(numDevices);
+
+  EGLDisplay display = EGL_NO_DISPLAY;
+  for (const auto& device : devices) {
+    const char* renderNodeString =
+        egl.fQueryDeviceStringEXT(device, LOCAL_EGL_DRM_RENDER_NODE_FILE_EXT);
+    if (renderNodeString &&
+        strcmp(renderNodeString, drmRenderDevice.get()) == 0) {
+      const EGLAttrib attrib_list[] = {LOCAL_EGL_NONE};
+      display = egl.fGetPlatformDisplay(LOCAL_EGL_PLATFORM_DEVICE_EXT, device,
+                                        attrib_list);
+      break;
+    }
+  }
+  if (!display) {
+    return nullptr;
+  }
+
+  return EglDisplay::Create(egl, display, true, aProofOfLock);
+}
+
 static std::shared_ptr<EglDisplay> GetAndInitSurfacelessDisplay(
     GLLibraryEGL& egl, const StaticMutexAutoLock& aProofOfLock) {
+  if (!egl.IsExtensionSupported(EGLLibExtension::MESA_platform_surfaceless)) {
+    return nullptr;
+  }
+
   const EGLAttrib attrib_list[] = {LOCAL_EGL_NONE};
   const EGLDisplay display = egl.fGetPlatformDisplay(
       LOCAL_EGL_PLATFORM_SURFACELESS_MESA, EGL_DEFAULT_DISPLAY, attrib_list);
@@ -610,9 +659,9 @@ bool GLLibraryEGL::Init(nsACString* cons
     (void)fnLoadSymbols(symbols);
   }
   {
-    const SymLoadStruct symbols[] = {SYMBOL(QueryDisplayAttribEXT),
-                                     SYMBOL(QueryDeviceAttribEXT),
-                                     END_OF_SYMBOLS};
+    const SymLoadStruct symbols[] = {
+        SYMBOL(QueryDisplayAttribEXT), SYMBOL(QueryDeviceAttribEXT),
+        SYMBOL(QueryDeviceStringEXT), END_OF_SYMBOLS};
     (void)fnLoadSymbols(symbols);
   }
   {
@@ -657,6 +706,10 @@ bool GLLibraryEGL::Init(nsACString* cons
                                      END_OF_SYMBOLS};
     (void)fnLoadSymbols(symbols);
   }
+  {
+    const SymLoadStruct symbols[] = {SYMBOL(QueryDevicesEXT), END_OF_SYMBOLS};
+    (void)fnLoadSymbols(symbols);
+  }
 
   return true;
 }
@@ -835,7 +888,10 @@ std::shared_ptr<EglDisplay> GLLibraryEGL
     // Some drivers doesn't support EGL_DEFAULT_DISPLAY
     GdkDisplay* gdkDisplay = gdk_display_get_default();
     if (!gdkDisplay) {
-      ret = GetAndInitSurfacelessDisplay(*this, aProofOfLock);
+      ret = GetAndInitDeviceDisplay(*this, aProofOfLock);
+      if (!ret) {
+        ret = GetAndInitSurfacelessDisplay(*this, aProofOfLock);
+      }
     } else if (widget::GdkIsWaylandDisplay(gdkDisplay)) {
       nativeDisplay = widget::WaylandDisplayGetWLDisplay(gdkDisplay);
       if (!nativeDisplay) {
diff -up firefox-101.0.1/gfx/gl/GLLibraryEGL.h.D148946.diff firefox-101.0.1/gfx/gl/GLLibraryEGL.h
--- firefox-101.0.1/gfx/gl/GLLibraryEGL.h.D148946.diff	2022-06-14 14:25:07.307230250 +0200
+++ firefox-101.0.1/gfx/gl/GLLibraryEGL.h	2022-06-14 14:25:07.313230450 +0200
@@ -71,7 +71,10 @@ enum class EGLLibExtension {
   ANGLE_device_creation_d3d11,
   ANGLE_platform_angle,
   ANGLE_platform_angle_d3d,
+  EXT_device_enumeration,
   EXT_device_query,
+  EXT_platform_device,
+  MESA_platform_surfaceless,
   Max
 };
 
@@ -107,7 +110,6 @@ enum class EGLExtension {
   EXT_buffer_age,
   KHR_partial_update,
   NV_robustness_video_memory_purge,
-  MESA_platform_surfaceless,
   EXT_image_dma_buf_import,
   EXT_image_dma_buf_import_modifiers,
   MESA_image_dma_buf_export,
@@ -436,6 +438,10 @@ class GLLibraryEGL final {
     WRAP(fQueryDeviceAttribEXT(device, attribute, value));
   }
 
+  const char* fQueryDeviceStringEXT(EGLDeviceEXT device, EGLint name) {
+    WRAP(fQueryDeviceStringEXT(device, name));
+  }
+
  private:
   // NV_stream_consumer_gltexture_yuv
   EGLBoolean fStreamConsumerGLTextureExternalAttribsNV(
@@ -478,6 +484,13 @@ class GLLibraryEGL final {
     WRAP(fExportDMABUFImageMESA(dpy, image, fds, strides, offsets));
   }
 
+ public:
+  // EGL_EXT_device_enumeration
+  EGLBoolean fQueryDevicesEXT(EGLint max_devices, EGLDeviceEXT* devices,
+                              EGLint* num_devices) {
+    WRAP(fQueryDevicesEXT(max_devices, devices, num_devices));
+  }
+
 #undef WRAP
 
 #undef WRAP
@@ -586,6 +599,9 @@ class GLLibraryEGL final {
     EGLBoolean(GLAPIENTRY* fQueryDeviceAttribEXT)(EGLDeviceEXT device,
                                                   EGLint attribute,
                                                   EGLAttrib* value);
+    const char*(GLAPIENTRY* fQueryDeviceStringEXT)(EGLDeviceEXT device,
+                                                   EGLint name);
+
     // NV_stream_consumer_gltexture_yuv
     EGLBoolean(GLAPIENTRY* fStreamConsumerGLTextureExternalAttribsNV)(
         EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib* attrib_list);
@@ -623,6 +639,10 @@ class GLLibraryEGL final {
                                                    EGLint* strides,
                                                    EGLint* offsets);
 
+    EGLBoolean(GLAPIENTRY* fQueryDevicesEXT)(EGLint max_devices,
+                                             EGLDeviceEXT* devices,
+                                             EGLint* num_devices);
+
   } mSymbols = {};
 };
 
bgstack15