myanmarking
09/01/2023, 11:26 AMsvenjacobs
09/01/2023, 11:29 AMmyanmarking
09/01/2023, 11:30 AMsvenjacobs
09/01/2023, 11:32 AMmyanmarking
09/01/2023, 11:32 AMsvenjacobs
09/01/2023, 11:34 AMmyanmarking
09/01/2023, 11:34 AMsvenjacobs
09/01/2023, 11:35 AM<http://Dispatcher.IO|Dispatcher.IO>
?myanmarking
09/01/2023, 11:35 AMsvenjacobs
09/01/2023, 11:36 AMmyanmarking
09/01/2023, 11:37 AMcoroutineScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
val bitmap = createBitmapFromPicture(picture)
val uri = bitmap.saveToDisk(context)
shareBitmap(context, uri)
}
svenjacobs
09/01/2023, 11:38 AMmyanmarking
09/01/2023, 11:38 AMsvenjacobs
09/01/2023, 11:39 AMmyanmarking
09/01/2023, 11:40 AMZach Klippenstein (he/him) [MOD]
09/01/2023, 1:21 PMmyanmarking
09/01/2023, 1:55 PMprivate val pictureMutex = Mutex()
private val picture = Picture()
fun record(
scope: ContentDrawScope,
width: Int,
height: Int
) {
val locked = pictureMutex.tryLock()
if (locked) {
try {
with(scope) {
val canvas = Canvas(picture.beginRecording(width, height))
draw(scope, scope.layoutDirection, canvas, scope.size) {
this@with.drawContent()
}
picture.endRecording()
drawIntoCanvas { drawCanvas ->
drawCanvas.nativeCanvas.drawPicture(picture)
}
}
} finally {
pictureMutex.unlock()
}
} else {
scope.drawContent()
}
}
fun capture() {
scope.launch {
try {
val bitmap = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
pictureMutex.withLock {
createBitmapFromPicture(picture)
}
}
}
}
}
It will suspend while trying to create the bitmap until the recording is finished. If it is attempting to record while saving is happening, it will skip recording. I think it is a better solution, since it does not mess with the drawing phase. Feedback from @Rebecca Franks is needed!svenjacobs
09/01/2023, 1:58 PMRebecca Franks
09/01/2023, 2:06 PMNader Jawad
09/07/2023, 7:42 PMmyanmarking
09/07/2023, 7:46 PMNader Jawad
09/07/2023, 7:48 PMmyanmarking
09/07/2023, 7:49 PMNader Jawad
09/07/2023, 7:50 PMmyanmarking
09/07/2023, 7:51 PMRebecca Franks
09/11/2023, 11:34 AM