-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve automatic OpenGL/ES detection
Use a temporary GLValidationSurface to ensure that the Skia GRGl content can be completely validated with an active OpenGL context.
- Loading branch information
1 parent
3ebb40b
commit f614a88
Showing
4 changed files
with
282 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Gtk; | ||
using Uno.Foundation.Logging; | ||
|
||
namespace Uno.UI.Runtime.Skia | ||
{ | ||
/// <summary> | ||
/// Validation surface for OpenGL rendering, as CreateGRGLContext | ||
/// needs to be invoked with an active OpenGL context, and that Skia | ||
/// does additional validation that cannot be extracted at an earlier stage. | ||
/// </summary> | ||
internal class GLValidationSurface : GLArea | ||
{ | ||
private TaskCompletionSource<RenderSurfaceType> _result = new(); | ||
|
||
public GLValidationSurface() | ||
{ | ||
HasDepthBuffer = false; | ||
HasStencilBuffer = false; | ||
AutoRender = true; | ||
|
||
Render += GLValidationSurface_Render; | ||
} | ||
|
||
private void GLValidationSurface_Render(object o, RenderArgs args) | ||
{ | ||
if (typeof(GLValidationSurface).Log().IsEnabled(LogLevel.Debug)) | ||
{ | ||
typeof(GLValidationSurface).Log().Debug($"GLValidationSurface: UseEs={UseEs}"); | ||
} | ||
|
||
args.Context.MakeCurrent(); | ||
|
||
ValidateOpenGLSupport(); | ||
} | ||
|
||
private void ValidateOpenGLSupport() | ||
{ | ||
try | ||
{ | ||
if (OpenGLESRenderSurface.IsSupported) | ||
{ | ||
using var ctx = OpenGLESRenderSurface.CreateGRGLContext(); | ||
|
||
if (ctx != null) | ||
{ | ||
_result.TrySetResult(RenderSurfaceType.OpenGLES); | ||
return; | ||
} | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
if (typeof(GLValidationSurface).Log().IsEnabled(LogLevel.Debug)) | ||
{ | ||
typeof(GLValidationSurface).Log().Debug($"OpenGL ES cannot be used ({e.Message})"); | ||
} | ||
} | ||
|
||
try | ||
{ | ||
if (OpenGLRenderSurface.IsSupported) | ||
{ | ||
using var ctx = OpenGLRenderSurface.CreateGRGLContext(); | ||
|
||
if (ctx != null) | ||
{ | ||
_result.TrySetResult(RenderSurfaceType.OpenGL); | ||
return; | ||
} | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
if (typeof(GLValidationSurface).Log().IsEnabled(LogLevel.Debug)) | ||
{ | ||
typeof(GLValidationSurface).Log().Debug($"OpenGL cannot be used ({e.Message})"); | ||
} | ||
} | ||
|
||
_result.TrySetResult(RenderSurfaceType.Software); | ||
} | ||
|
||
internal Task<RenderSurfaceType> GetSurfaceTypeAsync() | ||
=> _result.Task; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.