Switch to hardware bitmap in reader only if device can handle it

Closes #1460

(cherry picked from commit e6d96bd348ea5d18a005d6465222ad5f5123103e)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/data/coil/TachiyomiImageDecoder.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderPageImageView.kt
This commit is contained in:
AntsyLich 2024-11-17 03:04:38 +06:00 committed by Jobobby04
parent 1a28c7fb35
commit d286cf3267
4 changed files with 39 additions and 33 deletions

View File

@ -15,7 +15,6 @@ import coil3.request.bitmapConfig
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.util.storage.CbzCrypto import eu.kanade.tachiyomi.util.storage.CbzCrypto
import eu.kanade.tachiyomi.util.storage.CbzCrypto.getCoverStream import eu.kanade.tachiyomi.util.storage.CbzCrypto.getCoverStream
import eu.kanade.tachiyomi.util.system.GLUtil
import mihon.core.common.archive.archiveReader import mihon.core.common.archive.archiveReader
import okio.BufferedSource import okio.BufferedSource
import tachiyomi.core.common.util.system.ImageUtil import tachiyomi.core.common.util.system.ImageUtil
@ -71,7 +70,7 @@ class TachiyomiImageDecoder(private val resources: ImageSource, private val opti
if ( if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
options.bitmapConfig == Bitmap.Config.HARDWARE && options.bitmapConfig == Bitmap.Config.HARDWARE &&
maxOf(bitmap.width, bitmap.height) <= GLUtil.maxTextureSize ImageUtil.canUseHardwareBitmap(bitmap)
) { ) {
val hwBitmap = bitmap.copy(Bitmap.Config.HARDWARE, false) val hwBitmap = bitmap.copy(Bitmap.Config.HARDWARE, false)
if (hwBitmap != null) { if (hwBitmap != null) {

View File

@ -42,8 +42,6 @@ import eu.kanade.tachiyomi.util.system.animatorDurationScale
import eu.kanade.tachiyomi.util.view.isVisibleOnScreen import eu.kanade.tachiyomi.util.view.isVisibleOnScreen
import okio.BufferedSource import okio.BufferedSource
import tachiyomi.core.common.util.system.ImageUtil import tachiyomi.core.common.util.system.ImageUtil
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
/** /**
* A wrapper view for showing page image. * A wrapper view for showing page image.
@ -61,8 +59,6 @@ open class ReaderPageImageView @JvmOverloads constructor(
private val isWebtoon: Boolean = false, private val isWebtoon: Boolean = false,
) : FrameLayout(context, attrs, defStyleAttrs, defStyleRes) { ) : FrameLayout(context, attrs, defStyleAttrs, defStyleRes) {
private val alwaysUseSSIVToDecode by lazy { Injekt.get<BasePreferences>().alwaysUseSSIVToDecode().get() }
private var pageView: View? = null private var pageView: View? = null
private var config: Config? = null private var config: Config? = null
@ -300,11 +296,14 @@ open class ReaderPageImageView @JvmOverloads constructor(
isVisible = true isVisible = true
} }
is BufferedSource -> { is BufferedSource -> {
if (alwaysUseSSIVToDecode || !isWebtoon || !ImageUtil.canUseCoilToDecode(data)) { if (!isWebtoon) {
setHardwareConfig(ImageUtil.canUseHardwareBitmap(data))
setImage(ImageSource.inputStream(data.inputStream())) setImage(ImageSource.inputStream(data.inputStream()))
isVisible = true isVisible = true
} else { return@apply
val request = ImageRequest.Builder(context) }
ImageRequest.Builder(context)
.data(data) .data(data)
.memoryCachePolicy(CachePolicy.DISABLED) .memoryCachePolicy(CachePolicy.DISABLED)
.diskCachePolicy(CachePolicy.DISABLED) .diskCachePolicy(CachePolicy.DISABLED)
@ -315,7 +314,7 @@ open class ReaderPageImageView @JvmOverloads constructor(
isVisible = true isVisible = true
}, },
onError = { onError = {
this@ReaderPageImageView.onImageLoadError() onImageLoadError()
}, },
) )
.size(ViewSizeResolver(this@ReaderPageImageView)) .size(ViewSizeResolver(this@ReaderPageImageView))
@ -324,8 +323,7 @@ open class ReaderPageImageView @JvmOverloads constructor(
.customDecoder(true) .customDecoder(true)
.crossfade(false) .crossfade(false)
.build() .build()
context.imageLoader.enqueue(request) .let(context.imageLoader::enqueue)
}
} }
else -> { else -> {
throw IllegalArgumentException("Not implemented for class ${data::class.simpleName}") throw IllegalArgumentException("Not implemented for class ${data::class.simpleName}")

View File

@ -360,9 +360,18 @@ object ImageUtil {
val bottomOffset = topOffset + splitHeight val bottomOffset = topOffset + splitHeight
} }
fun canUseCoilToDecode(imageSource: BufferedSource): Boolean { fun canUseHardwareBitmap(bitmap: Bitmap): Boolean {
val options = extractImageOptions(imageSource) return canUseHardwareBitmap(bitmap.width, bitmap.height)
return maxOf(options.outWidth, options.outHeight) <= GLUtil.maxTextureSize }
fun canUseHardwareBitmap(imageSource: BufferedSource): Boolean {
return with(extractImageOptions(imageSource)) {
canUseHardwareBitmap(outWidth, outHeight)
}
}
private fun canUseHardwareBitmap(width: Int, height: Int): Boolean {
return maxOf(width, height) <= GLUtil.maxTextureSize
} }
/** /**

View File

@ -48,7 +48,7 @@ coil-gif = { module = "io.coil-kt.coil3:coil-gif" }
coil-compose = { module = "io.coil-kt.coil3:coil-compose" } coil-compose = { module = "io.coil-kt.coil3:coil-compose" }
coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp" } coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp" }
subsamplingscaleimageview = "com.github.tachiyomiorg:subsampling-scale-image-view:b8e1b0ed2b" subsamplingscaleimageview = "com.github.tachiyomiorg:subsampling-scale-image-view:66e0db195d"
image-decoder = "com.github.tachiyomiorg:image-decoder:41c059e540" image-decoder = "com.github.tachiyomiorg:image-decoder:41c059e540"
natural-comparator = "com.github.gpanther:java-nat-sort:natural-comparator-1.1" natural-comparator = "com.github.gpanther:java-nat-sort:natural-comparator-1.1"