-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
PictureFilterCanvas
native bindings and add tests (#1011)
- Loading branch information
1 parent
c22b0fc
commit 0e03962
Showing
4 changed files
with
58 additions
and
11 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
45 changes: 45 additions & 0 deletions
45
skiko/src/commonTest/kotlin/org/jetbrains/skia/PictureFilterCanvasTest.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,45 @@ | ||
package org.jetbrains.skia | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class PictureFilterCanvasTest { | ||
@Test | ||
fun canOverrideOnDrawPicture() { | ||
val surface = Surface.makeRasterN32Premul(16, 16) | ||
val bounds = Rect(0f, 0f, 16f, 16f) | ||
var callCount = 0 | ||
|
||
// Prepare picture | ||
val recorder = PictureRecorder() | ||
val recordingCanvas = recorder.beginRecording(bounds) | ||
val placeholder = Picture.makePlaceholder(bounds) | ||
recordingCanvas.drawPicture(placeholder) | ||
val picture = recorder.finishRecordingAsPicture() | ||
|
||
// Filtering | ||
val filterCanvas = object : PictureFilterCanvas(surface.canvas) { | ||
override fun onDrawPicture(picture: Picture, matrix: Matrix33?, paint: Paint?): Boolean { | ||
callCount++ | ||
drawRect( | ||
Rect(0f, 0f, 8f, 8f), | ||
Paint().apply { color = Color.RED } | ||
) | ||
return true | ||
} | ||
} | ||
filterCanvas.drawPicture(picture) | ||
filterCanvas.close() | ||
|
||
// Render result | ||
val pixels = Bitmap.makeFromImage(surface.makeImageSnapshot()) | ||
|
||
assertEquals(1, callCount) | ||
assertEquals(Color.RED, pixels.getColor(2, 2)) | ||
|
||
placeholder.close() | ||
picture.close() | ||
recorder.close() | ||
surface.close() | ||
} | ||
} |
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