-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the GPU views for Uno Platform (#1429)
* Add the GPU views for the platforms * Add the render loop for the platforms * Fix the samples for infinite recursion * Added the GL views to the gallery
- Loading branch information
1 parent
1fa3dad
commit b3f5975
Showing
22 changed files
with
828 additions
and
14 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
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
2 changes: 1 addition & 1 deletion
2
samples/Gallery/Uno/SkiaSharpSample.Android/Properties/AndroidManifest.xml
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" package="com.companyname.skiasharpsample" android:versionCode="1"> | ||
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" /> | ||
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:label="@string/app_name" android:theme="@style/Theme.AppCompat" android:hardwareAccelerated="true"></application> | ||
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:label="@string/app_name" android:theme="@style/AppTheme" android:hardwareAccelerated="true"></application> | ||
</manifest> |
12 changes: 12 additions & 0 deletions
12
samples/Gallery/Uno/SkiaSharpSample.Android/Resources/values/styles.xml
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,12 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<resources> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light"> | ||
|
||
<!-- This removes the ActionBar --> | ||
<item name="windowActionBar">false</item> | ||
<item name="android:windowActionBar">false</item> | ||
<item name="windowNoTitle">true</item> | ||
<item name="android:windowNoTitle">true</item> | ||
|
||
</style> | ||
</resources> |
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
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
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
57 changes: 57 additions & 0 deletions
57
source/SkiaSharp.Views.Uno/SkiaSharp.Views.Uno.Android/SKSwapChainPanel.Android.cs
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,57 @@ | ||
using Android.Opengl; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
|
||
namespace SkiaSharp.Views.UWP | ||
{ | ||
public partial class SKSwapChainPanel : FrameworkElement | ||
{ | ||
private SKGLTextureView glTextureView; | ||
|
||
public SKSwapChainPanel() | ||
{ | ||
Initialize(); | ||
} | ||
|
||
private SKSize GetCanvasSize() => | ||
glTextureView?.CanvasSize ?? SKSize.Empty; | ||
|
||
private GRContext GetGRContext() => | ||
glTextureView?.GRContext; | ||
|
||
partial void DoLoaded() | ||
{ | ||
glTextureView = new SKGLTextureView(Context); | ||
DoEnableRenderLoop(EnableRenderLoop); | ||
glTextureView.PaintSurface += OnPaintSurface; | ||
AddView(glTextureView); | ||
} | ||
|
||
partial void DoUnloaded() | ||
{ | ||
if (glTextureView == null) | ||
return; | ||
|
||
RemoveView(glTextureView); | ||
glTextureView.PaintSurface -= OnPaintSurface; | ||
glTextureView.Dispose(); | ||
glTextureView = null; | ||
} | ||
|
||
partial void DoEnableRenderLoop(bool enable) | ||
{ | ||
if (glTextureView == null) | ||
return; | ||
|
||
glTextureView.RenderMode = enable | ||
? Rendermode.Continuously | ||
: Rendermode.WhenDirty; | ||
} | ||
|
||
private void DoInvalidate() => | ||
glTextureView?.RequestRender(); | ||
|
||
private void OnPaintSurface(object sender, SKPaintGLSurfaceEventArgs e) => | ||
OnPaintSurface(e); | ||
} | ||
} |
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
83 changes: 83 additions & 0 deletions
83
source/SkiaSharp.Views.Uno/SkiaSharp.Views.Uno.Mac/SKSwapChainPanel.macOS.cs
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,83 @@ | ||
using CoreVideo; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
|
||
namespace SkiaSharp.Views.UWP | ||
{ | ||
public partial class SKSwapChainPanel : FrameworkElement | ||
{ | ||
private SKGLView glView; | ||
private CVDisplayLink displayLink; | ||
|
||
public SKSwapChainPanel() | ||
{ | ||
Initialize(); | ||
} | ||
|
||
private SKSize GetCanvasSize() => | ||
glView?.CanvasSize ?? SKSize.Empty; | ||
|
||
private GRContext GetGRContext() => | ||
glView?.GRContext; | ||
|
||
partial void DoLoaded() | ||
{ | ||
glView = new SKGLView(Bounds); | ||
glView.PaintSurface += OnPaintSurface; | ||
AddSubview(glView); | ||
} | ||
|
||
partial void DoUnloaded() | ||
{ | ||
DoEnableRenderLoop(false); | ||
|
||
if (glView != null) | ||
{ | ||
glView.RemoveFromSuperview(); | ||
glView.PaintSurface -= OnPaintSurface; | ||
glView.Dispose(); | ||
glView = null; | ||
} | ||
} | ||
|
||
private void DoInvalidate() => | ||
DoEnableRenderLoop(true); | ||
|
||
private void OnPaintSurface(object sender, SKPaintGLSurfaceEventArgs e) => | ||
OnPaintSurface(e); | ||
|
||
partial void DoEnableRenderLoop(bool enable) | ||
{ | ||
// stop the render loop | ||
if (!enable) | ||
{ | ||
if (displayLink != null) | ||
{ | ||
displayLink.Stop(); | ||
displayLink.Dispose(); | ||
displayLink = null; | ||
} | ||
return; | ||
} | ||
|
||
// only start if we haven't already | ||
if (displayLink != null) | ||
return; | ||
|
||
// create the loop | ||
displayLink = new CVDisplayLink(); | ||
displayLink.SetOutputCallback(delegate | ||
{ | ||
// redraw the view | ||
glView?.BeginInvokeOnMainThread(() => glView?.Display()); | ||
|
||
// stop the render loop if it has been disabled or the views are disposed | ||
if (glView == null || !EnableRenderLoop) | ||
DoEnableRenderLoop(false); | ||
|
||
return CVReturn.Success; | ||
}); | ||
displayLink.Start(); | ||
} | ||
} | ||
} |
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.