Skip to content

Commit

Permalink
Improve hardware bitmap threshold option
Browse files Browse the repository at this point in the history
Also `spotlessApply`
  • Loading branch information
AntsyLich committed Nov 21, 2024
1 parent 88aff2c commit d6dfd24
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,21 +332,26 @@ object SettingsAdvancedScreen : SearchableSettings {
basePreferences.displayProfile().set(uri.toString())
}
}
val hardwareBitmapThresholdPref = basePreferences.hardwareBitmapThreshold()
val hardwareBitmapThreshold by hardwareBitmapThresholdPref.collectAsState()
return Preference.PreferenceGroup(
title = stringResource(MR.strings.pref_category_reader),
preferenceItems = persistentListOf(
Preference.PreferenceItem.ListPreference(
pref = hardwareBitmapThresholdPref,
pref = basePreferences.hardwareBitmapThreshold(),
title = stringResource(MR.strings.pref_hardware_bitmap_threshold),
subtitle = stringResource(
MR.strings.pref_hardware_bitmap_threshold_summary,
hardwareBitmapThreshold,
),
subtitleProvider = { value, options ->
stringResource(MR.strings.pref_hardware_bitmap_threshold_summary, options[value].orEmpty())
},
enabled = GLUtil.DEVICE_TEXTURE_LIMIT > GLUtil.SAFE_TEXTURE_LIMIT,
entries = GLUtil.CUSTOM_TEXTURE_LIMIT_OPTIONS
.associateWith { it.toString() }
.mapIndexed { index, option ->
val display = if (index == 0) {
stringResource(MR.strings.pref_hardware_bitmap_threshold_default, option)
} else {
option.toString()
}
option to display
}
.toMap()
.toImmutableMap(),
),
Preference.PreferenceItem.TextPreference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.util.system
import javax.microedition.khronos.egl.EGL10
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.egl.EGLContext
import kotlin.math.max

object GLUtil {
val DEVICE_TEXTURE_LIMIT: Int by lazy {
Expand Down Expand Up @@ -38,18 +39,21 @@ object GLUtil {
egl.eglTerminate(display)

// Return largest texture size found (after making it a multiplier of [Multiplier]), or default
if (maximumTextureSize > SAFE_TEXTURE_LIMIT) {
(maximumTextureSize / MULTIPLIER) * MULTIPLIER
} else {
SAFE_TEXTURE_LIMIT
}
max(maximumTextureSize, SAFE_TEXTURE_LIMIT)
}

const val SAFE_TEXTURE_LIMIT: Int = 2048

val CUSTOM_TEXTURE_LIMIT_OPTIONS: List<Int> by lazy {
val steps = ((DEVICE_TEXTURE_LIMIT / MULTIPLIER) - 1)
List(steps) { (it + 2) * MULTIPLIER }.asReversed()
val steps = DEVICE_TEXTURE_LIMIT / MULTIPLIER
buildList(steps) {
add(DEVICE_TEXTURE_LIMIT)
for (step in steps downTo 2) {
val value = step * MULTIPLIER
if (value >= DEVICE_TEXTURE_LIMIT) continue
add(value)
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions i18n/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@
<string name="pref_show_reading_mode_summary">Briefly show current mode when reader is opened</string>
<string name="pref_display_profile">Custom display profile</string>
<string name="pref_hardware_bitmap_threshold">Custom hardware bitmap threshold</string>
<string name="pref_hardware_bitmap_threshold_default">Default (%d)</string>
<string name="pref_hardware_bitmap_threshold_summary">If reader loads a blank image incrementally reduce the threshold.\nSelected: %s</string>
<string name="pref_crop_borders">Crop borders</string>
<string name="pref_custom_brightness">Custom brightness</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow

@Composable
fun <T: Any> StateFlow<Flow<PagingData<T>>>.collectAsLazyPagingItems(): LazyPagingItems<T> {
fun <T : Any> StateFlow<Flow<PagingData<T>>>.collectAsLazyPagingItems(): LazyPagingItems<T> {
val flow by collectAsState()
return flow.collectAsLazyPagingItems()
}

0 comments on commit d6dfd24

Please sign in to comment.