Profiling fix C: Tonight's Pick card painted once. Ported from release-0.108
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,8 @@ import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.text.font.Font
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
@@ -100,9 +102,20 @@ internal fun WhatsOnScreen(session: EmbySampleSession, plans: Map<Int, ChannelPl
|
||||
return@FocusCard
|
||||
}
|
||||
val picture = rememberFilmPicture(session, pick.entry.media.item.id)
|
||||
Box(Modifier.fillMaxSize().background(Panel)) {
|
||||
if (picture != null) Image(picture.asImageBitmap(), null, Modifier.fillMaxSize(), contentScale = ContentScale.Crop)
|
||||
Box(Modifier.fillMaxSize().background(Brush.horizontalGradient(0f to Navy.copy(alpha = .97f), .45f to Navy.copy(alpha = .88f), .75f to Navy.copy(alpha = .35f), 1f to Navy.copy(alpha = .15f))))
|
||||
// Profiling fix C (8 November 2026): the panel, the picture and the fade are put together once, off the drawing
|
||||
// thread, at the card's own size, so the graphics chip paints one picture each frame instead of three layers.
|
||||
var size by remember { mutableStateOf(androidx.compose.ui.unit.IntSize.Zero) }
|
||||
val card by produceState<android.graphics.Bitmap?>(null, picture, size) {
|
||||
value = if (picture == null || size.width <= 0 || size.height <= 0) null
|
||||
else kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.Default) { runCatching { pickCard(picture, size.width, size.height) }.getOrNull() }
|
||||
}
|
||||
Box(Modifier.fillMaxSize().onSizeChanged { size = it }.background(Panel)) {
|
||||
val baked = card
|
||||
if (baked != null) Image(baked.asImageBitmap(), null, Modifier.fillMaxSize(), contentScale = ContentScale.FillBounds)
|
||||
else {
|
||||
if (picture != null) Image(picture.asImageBitmap(), null, Modifier.fillMaxSize(), contentScale = ContentScale.Crop)
|
||||
Box(Modifier.fillMaxSize().background(Brush.horizontalGradient(0f to Navy.copy(alpha = .97f), .45f to Navy.copy(alpha = .88f), .75f to Navy.copy(alpha = .35f), 1f to Navy.copy(alpha = .15f))))
|
||||
}
|
||||
Column(Modifier.fillMaxSize().padding(16.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Tag("TONIGHT'S PICK", Yellow, 11)
|
||||
Logo(pick.channel, 96, 30)
|
||||
@@ -222,3 +235,25 @@ internal fun ProgrammeReminderCard(reminder: ProgrammeReminder, nowMs: Long, onW
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tonight's Pick's card, painted once (profiling fix C): the panel colour, the picture cropped to fill the card as
|
||||
* ContentScale.Crop does, and the same left-to-right navy fade, all in one bitmap of the card's size.
|
||||
*/
|
||||
internal fun pickCard(picture: android.graphics.Bitmap, width: Int, height: Int): android.graphics.Bitmap {
|
||||
val out = android.graphics.Bitmap.createBitmap(width, height, android.graphics.Bitmap.Config.ARGB_8888)
|
||||
val canvas = android.graphics.Canvas(out)
|
||||
canvas.drawColor(Panel.toArgb())
|
||||
val scale = maxOf(width.toFloat() / picture.width, height.toFloat() / picture.height)
|
||||
val w = picture.width * scale; val h = picture.height * scale
|
||||
val dst = android.graphics.RectF((width - w) / 2f, (height - h) / 2f, (width + w) / 2f, (height + h) / 2f)
|
||||
canvas.drawBitmap(picture, null, dst, android.graphics.Paint(android.graphics.Paint.FILTER_BITMAP_FLAG))
|
||||
val fade = android.graphics.Paint().apply {
|
||||
shader = android.graphics.LinearGradient(0f, 0f, width.toFloat(), 0f,
|
||||
intArrayOf(Navy.copy(alpha = .97f).toArgb(), Navy.copy(alpha = .88f).toArgb(), Navy.copy(alpha = .35f).toArgb(), Navy.copy(alpha = .15f).toArgb()),
|
||||
floatArrayOf(0f, .45f, .75f, 1f), android.graphics.Shader.TileMode.CLAMP)
|
||||
}
|
||||
canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), fade)
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user