Table of Contents

Class SkiaShaderEffect

Namespace
DrawnUi.Draw
Assembly
DrawnUi.Maui.dll

IPostRendererEffect — XAML-bindable shader effect that uses SkiaShader as its engine.

public class SkiaShaderEffect : SkiaEffect, INotifyPropertyChanged, IDisposable, IPostRendererEffect, ISkiaEffect, ICanBeUpdatedWithContext, ICanBeUpdated, IComparable, IComparable<SkiaShaderEffect>, IEquatable<SkiaShaderEffect>
Inheritance
SkiaShaderEffect
Implements
Derived
Inherited Members
Extension Methods

Fields

AutoCreateInputTextureProperty

public static readonly BindableProperty AutoCreateInputTextureProperty

Field Value

BindableProperty

FilterModeProperty

public static readonly BindableProperty FilterModeProperty

Field Value

BindableProperty

MipmapModeProperty

public static readonly BindableProperty MipmapModeProperty

Field Value

BindableProperty

ShaderCodeProperty

public static readonly BindableProperty ShaderCodeProperty

Field Value

BindableProperty

ShaderSourceProperty

public static readonly BindableProperty ShaderSourceProperty

Field Value

BindableProperty

ShaderTemplateProperty

public static readonly BindableProperty ShaderTemplateProperty

Field Value

BindableProperty

TileModeProperty

public static readonly BindableProperty TileModeProperty

Field Value

BindableProperty

UseContextProperty

public static readonly BindableProperty UseContextProperty

Field Value

BindableProperty

_template

protected string _template

Field Value

string

_templatePlacehodler

protected string _templatePlacehodler

Field Value

string

Properties

AquiredBackground

True once the Once-mode snapshot has been captured. Reset to false to re-capture.

public bool AquiredBackground { get; set; }

Property Value

bool

AutoCreateInputTexture

Should create a texture from the current drawing to pass to shader as uniform shader iImage1, default is True. You need this set to False only if your shader is output-only.

public bool AutoCreateInputTexture { get; set; }

Property Value

bool

BlendMode

Blend mode used when drawing the shader effect on the canvas. Default is SrcOver. For generative overlay effects (UseBackground = Never), use Plus for additive blending.

public SKBlendMode BlendMode { get; set; }

Property Value

SKBlendMode

CompiledShader

Backward-compatible access to the compiled shader.

protected SKRuntimeEffect CompiledShader { get; }

Property Value

SKRuntimeEffect

Engine

The shader engine. Override CreateEngine() to provide a subclassed SkiaShader with custom uniforms or children.

protected SkiaShader Engine { get; set; }

Property Value

SkiaShader

FilterMode

public SKFilterMode FilterMode { get; set; }

Property Value

SKFilterMode

LoadedCode

public string LoadedCode { get; set; }

Property Value

string

MipmapMode

public SKMipmapMode MipmapMode { get; set; }

Property Value

SKMipmapMode

MouseCurrent

Shadertoy conventions current mouse position (or drag position)

public PointF MouseCurrent { get; set; }

Property Value

PointF

MouseInitial

Shadertoy conventions where click/drag started. If zero could mean not dragging.

public PointF MouseInitial { get; set; }

Property Value

PointF

NeedApply

public override bool NeedApply { get; }

Property Value

bool

ShaderCode

Changing this directly will force the shader to recompile

public string ShaderCode { get; set; }

Property Value

string

ShaderSource

FIlename from resources, ex: @"Shaders\blit.sksl"

public string ShaderSource { get; set; }

Property Value

string

ShaderTemplate

public string ShaderTemplate { get; set; }

Property Value

string

TileMode

Tile mode for input textures

public SKShaderTileMode TileMode { get; set; }

Property Value

SKShaderTileMode

TimeSeconds

Normally will be automatically set in Render method from context FrameTimeNanos

public float TimeSeconds { get; set; }

Property Value

float

UseBackground

Controls how/when the background texture is captured. Default is Always.

public PostRendererEffectUseBackgroud UseBackground { get; set; }

Property Value

PostRendererEffectUseBackgroud

UseContext

Use either context or global Superview background, default is True.

public bool UseContext { get; set; }

Property Value

bool

Methods

ApplyShaderSource()

protected virtual void ApplyShaderSource()

CompareTo(SkiaShaderEffect)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

public int CompareTo(SkiaShaderEffect other)

Parameters

other SkiaShaderEffect

An object to compare with this instance.

Returns

int

A value that indicates the relative order of the objects being compared. The return value has these meanings:

Value Meaning
Less than zero This instance precedes other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in the sort order.

CompareTo(object)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

public int CompareTo(object obj)

Parameters

obj object

An object to compare with this instance.

Returns

int

A value that indicates the relative order of the objects being compared. The return value has these meanings:

Value Meaning
Less than zero This instance precedes obj in the sort order.
Zero This instance occurs in the same position in the sort order as obj.
Greater than zero This instance follows obj in the sort order.

Exceptions

ArgumentException

obj is not the same type as this instance.

CompileShader()

Compiles the shader code from resource

protected virtual void CompileShader()

CompileShader(string, bool, Action<string>)

protected virtual void CompileShader(string shaderCode, bool useCache = true, Action<string> onError = null)

Parameters

shaderCode string
useCache bool
onError Action<string>

CreateEngine()

Override to return a subclassed SkiaShader with custom uniforms/children.

protected virtual SkiaShader CreateEngine()

Returns

SkiaShader

CreateShader(DrawingContext, SKImage)

Creates shader fresh each time - no caching of GPU resources

public virtual SKShader CreateShader(DrawingContext ctx, SKImage source)

Parameters

ctx DrawingContext
source SKImage

Returns

SKShader

CreateSnapshot(SkiaDrawingContext, SKRect)

Create snapshot from the current parent control drawing state to use as input texture for the shader

protected virtual SKImage CreateSnapshot(SkiaDrawingContext ctx, SKRect destination)

Parameters

ctx SkiaDrawingContext
destination SKRect

Returns

SKImage

CreateTexturesUniforms(SkiaDrawingContext, SKRect, SKShader)

Creates texture children via engine. Override to add additional textures.

protected virtual SKRuntimeEffectChildren CreateTexturesUniforms(SkiaDrawingContext ctx, SKRect destination, SKShader primaryTexture)

Parameters

ctx SkiaDrawingContext
destination SKRect
primaryTexture SKShader

Returns

SKRuntimeEffectChildren

CreateUniforms(SKRect)

Creates standard uniforms via engine. Override to add custom uniforms.

protected virtual SKRuntimeEffectUniforms CreateUniforms(SKRect destination)

Parameters

destination SKRect

Returns

SKRuntimeEffectUniforms

Equals(SkiaShaderEffect)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(SkiaShaderEffect other)

Parameters

other SkiaShaderEffect

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object)

Determines whether the specified object is equal to the current object.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

Flush(SkiaDrawingContext)

protected void Flush(SkiaDrawingContext ctx)

Parameters

ctx SkiaDrawingContext

GetEngine()

protected SkiaShader GetEngine()

Returns

SkiaShader

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

GetPrimaryTextureImage(SkiaDrawingContext, SKRect)

Returns the background texture according to the current UseBackground mode. Always — live snapshot (or parent cache) every frame. Once — snapshot taken on first call, frozen thereafter; reset AquiredBackground to re-capture. Never — returns null; shader must not require iImage1.

protected virtual SKImage GetPrimaryTextureImage(SkiaDrawingContext ctx, SKRect destination)

Parameters

ctx SkiaDrawingContext
destination SKRect

Returns

SKImage

NeedChangeSource(BindableObject, object, object)

protected static void NeedChangeSource(BindableObject bindable, object oldvalue, object newvalue)

Parameters

bindable BindableObject
oldvalue object
newvalue object

OnDisposing()

protected override void OnDisposing()

ReleaseFrozenSnapshot()

public void ReleaseFrozenSnapshot()

Render(DrawingContext)

EffectPostRenderer

public virtual void Render(DrawingContext ctx)

Parameters

ctx DrawingContext

SendError(string)

protected void SendError(string error)

Parameters

error string

ShouldDisposePreviousTexture(SKImage)

Checks if image is a new snapshot that needs disposal this frame. Frozen snapshots are managed by ReleaseFrozenSnapshot; parent cache is never owned.

protected virtual bool ShouldDisposePreviousTexture(SKImage image)

Parameters

image SKImage

Returns

bool

SyncEngineState(SKRect)

Syncs Effect properties to the engine before uniform creation.

protected virtual void SyncEngineState(SKRect destination)

Parameters

destination SKRect

Events

OnCompilationError

public event EventHandler<string> OnCompilationError

Event Type

EventHandler<string>

Operators

operator ==(SkiaShaderEffect, SkiaShaderEffect)

public static bool operator ==(SkiaShaderEffect left, SkiaShaderEffect right)

Parameters

left SkiaShaderEffect
right SkiaShaderEffect

Returns

bool

operator !=(SkiaShaderEffect, SkiaShaderEffect)

public static bool operator !=(SkiaShaderEffect left, SkiaShaderEffect right)

Parameters

left SkiaShaderEffect
right SkiaShaderEffect

Returns

bool