-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change: add layer for backdrop filter
- Loading branch information
Showing
23 changed files
with
437 additions
and
83 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
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/muedsa/snapshot/rendering/BackdropFilterLayer.kt
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,23 @@ | ||
package com.muedsa.snapshot.rendering | ||
|
||
import org.jetbrains.skia.BlendMode | ||
import org.jetbrains.skia.ImageFilter | ||
import org.jetbrains.skia.Paint | ||
import org.jetbrains.skia.Rect | ||
|
||
class BackdropFilterLayer( | ||
val bounds: Rect, | ||
val filter: ImageFilter, | ||
val blendMode: BlendMode = BlendMode.SRC_OVER, | ||
) : ContainerLayer() { | ||
|
||
override fun paint(context: LayerPaintContext) { | ||
context.pictures.lastOrNull()?.also { | ||
context.canvas.drawPicture(it, paint = Paint().apply { | ||
this@apply.imageFilter = this@BackdropFilterLayer.filter | ||
this@apply.blendMode = this@BackdropFilterLayer.blendMode | ||
}) | ||
} | ||
super.paint(context) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/muedsa/snapshot/rendering/ClipPathLayer.kt
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,17 @@ | ||
package com.muedsa.snapshot.rendering | ||
|
||
import org.jetbrains.skia.Path | ||
|
||
class ClipPathLayer( | ||
val clipPath: Path, | ||
val clipBehavior: ClipBehavior = ClipBehavior.ANTI_ALIAS, | ||
) : ContainerLayer() { | ||
|
||
|
||
override fun paint(context: LayerPaintContext) { | ||
context.canvas.save() | ||
context.canvas.clipPath(clipPath, antiAlias = clipBehavior == ClipBehavior.ANTI_ALIAS) | ||
super.paint(context) | ||
context.canvas.restore() | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/muedsa/snapshot/rendering/ClipRRectLayer.kt
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,17 @@ | ||
package com.muedsa.snapshot.rendering | ||
|
||
import org.jetbrains.skia.RRect | ||
|
||
class ClipRRectLayer( | ||
val clipRRect: RRect, | ||
val clipBehavior: ClipBehavior = ClipBehavior.HARD_EDGE, | ||
) : ContainerLayer() { | ||
|
||
|
||
override fun paint(context: LayerPaintContext) { | ||
context.canvas.save() | ||
context.canvas.clipRRect(clipRRect, antiAlias = clipBehavior == ClipBehavior.ANTI_ALIAS) | ||
super.paint(context) | ||
context.canvas.restore() | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/muedsa/snapshot/rendering/ClipRectLayer.kt
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,17 @@ | ||
package com.muedsa.snapshot.rendering | ||
|
||
import org.jetbrains.skia.Rect | ||
|
||
class ClipRectLayer( | ||
val clipRect: Rect, | ||
val clipBehavior: ClipBehavior = ClipBehavior.HARD_EDGE, | ||
) : ContainerLayer() { | ||
|
||
|
||
override fun paint(context: LayerPaintContext) { | ||
context.canvas.save() | ||
context.canvas.clipRect(clipRect, antiAlias = clipBehavior == ClipBehavior.ANTI_ALIAS) | ||
super.paint(context) | ||
context.canvas.restore() | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/com/muedsa/snapshot/rendering/ContainerLayer.kt
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,18 @@ | ||
package com.muedsa.snapshot.rendering | ||
|
||
open class ContainerLayer : Layer() { | ||
|
||
private val _children: MutableList<Layer> = mutableListOf() | ||
val children: List<Layer> = _children | ||
|
||
override fun paint(context: LayerPaintContext) { | ||
children.forEach { | ||
it.paint(context) | ||
} | ||
} | ||
|
||
fun append(child: Layer) { | ||
_children.add(child) | ||
child.parent = this | ||
} | ||
} |
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,8 @@ | ||
package com.muedsa.snapshot.rendering | ||
|
||
abstract class Layer { | ||
|
||
var parent: Layer? = null | ||
|
||
abstract fun paint(context: LayerPaintContext) | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/muedsa/snapshot/rendering/LayerPaintContext.kt
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,10 @@ | ||
package com.muedsa.snapshot.rendering | ||
|
||
import org.jetbrains.skia.Canvas | ||
import org.jetbrains.skia.Picture | ||
|
||
class LayerPaintContext( | ||
val canvas: Canvas, | ||
) { | ||
val pictures: MutableList<Picture> = mutableListOf() | ||
} |
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.