Stefan Oltmann
09/09/2022, 12:24 PMStefan Oltmann
09/09/2022, 12:38 PMswiftshader_indirect
).Igor Demin
09/09/2022, 1:19 PMStefan Oltmann
09/09/2022, 1:21 PMIgor Demin
09/09/2022, 1:22 PMImageComposeScene
, that is always rendered with software renderer.Stefan Oltmann
09/09/2022, 1:22 PMStefan Oltmann
09/09/2022, 1:23 PMStefan Oltmann
09/09/2022, 2:43 PMprivate val imageVectorCache = mutableMapOf<VectorRes, ImageVector>()
@Composable
actual fun painter(res: VectorRes): Painter {
val imageVector = imageVectorCache.getOrPut(res) {
val inputSource = object : InputSource() {
override fun getByteStream() = openResource(res.path)
}
loadXmlImageVector(inputSource, LocalDensity.current)
}
return rememberVectorPainter(imageVector)
}
private fun openResource(resourcePath: String): InputStream {
val classLoader = Thread.currentThread().contextClassLoader!!
return requireNotNull(classLoader.getResourceAsStream(resourcePath)) {
"Resource $resourcePath not found"
}
}
Igor Demin
09/09/2022, 3:03 PMSystem preferences -> Display
Also, Skia can use some platform API’s for rasterisation. For example, for antialiasing. But I am not sure about it too.
Also, different platforms/versions can do math differently, and we can have some round error for colors (+-1)Stefan Oltmann
09/09/2022, 3:40 PMsaket
09/11/2022, 7:24 AMStefan Oltmann
09/12/2022, 8:06 AMStefan Oltmann
09/12/2022, 8:15 AMStefan Oltmann
09/12/2022, 8:16 AMAlso, different platforms/versions can do math differently, and we can have some round error for colors (+-1)
Stefan Oltmann
09/12/2022, 8:17 AMStefan Oltmann
09/13/2022, 6:29 AMskia.Bitmap.getColor()
on CI.
I take that as the final sign that I'm just not supposed to compare screenshots on CI. 🙈
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x000000012f6949dd, pid=23658, tid=6147
#
# JRE version: OpenJDK Runtime Environment Temurin-17.0.4+8 (17.0.4+8) (build 17.0.4+8)
# Java VM: OpenJDK 64-Bit Server VM Temurin-17.0.4+8 (17.0.4+8, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, bsd-amd64)
# Problematic frame:
# C [libskiko-macos-x64.dylib+0xf69dd] _ZNK8SkPixmap8getColorEii+0x2cd
Compiled method (n/a) 19811 2768 n 0 org.jetbrains.skia.BitmapKt::Bitmap_nGetColor (native)
Stefan Oltmann
09/13/2022, 6:32 AMval expectedBitmap = Bitmap.makeFromImage(Image.makeFromEncoded(expectedImageBytes))
val actualBitmap = Bitmap.makeFromImage(Image.makeFromEncoded(actualImageBytes))
if (!expectedBitmap.isEquals(actualBitmap, tolerance = 3)) {
fail("Image $fileName is not equal to reference image.")
}
private fun Bitmap.isEquals(other: Bitmap, tolerance: Int = 0): Boolean {
if (this.width != other.width || this.height != other.height)
return false
for (x in 0..width) {
for (y in 0..height) {
val thisColor = this.getColor(x, y)
val otherColor = other.getColor(x, y)
if (thisColor != otherColor) {
val redDelta = abs(getRed(thisColor) - getRed(otherColor))
val greenDelta = abs(getGreen(thisColor) - getGreen(otherColor))
val blueDelta = abs(getBlue(thisColor) - getBlue(otherColor))
if (redDelta > tolerance || greenDelta > tolerance || blueDelta > tolerance)
return false
}
}
}
return true
}
private fun getRed(pixelValue: Int) =
pixelValue and (255 shl 16) shr 16
private fun getGreen(pixelValue: Int) =
pixelValue and (255 shl 8) shr 8
private fun getBlue(pixelValue: Int) =
pixelValue and 255