diff --git a/app/src/main/java/com/limelight/Game.java b/app/src/main/java/com/limelight/Game.java index 992fc00a71..bb0be05a48 100755 --- a/app/src/main/java/com/limelight/Game.java +++ b/app/src/main/java/com/limelight/Game.java @@ -313,6 +313,62 @@ public interface GameMenuCallbacks { private static final int UTF8_CHUNK_SIZE = 512; private final Queue commitTextQueue = new ArrayDeque<>(); private final Handler commitTextHandler = new Handler(Looper.getMainLooper()); + + static boolean displaySupportsHdr10(Display.HdrCapabilities hdrCapabilities) { + if (hdrCapabilities == null) { + return false; + } + + for (int hdrType : hdrCapabilities.getSupportedHdrTypes()) { + if (hdrType == Display.HdrCapabilities.HDR_TYPE_HDR10) { + return true; + } + } + + return false; + } + + static boolean shouldRequestHdrStream(boolean prefEnableHdr, + boolean onExternalDisplay, + int sdkInt, + boolean displaySupportsHdr10) { + if (!prefEnableHdr) { + return false; + } + + if (onExternalDisplay) { + return true; + } + + if (sdkInt < Build.VERSION_CODES.N) { + return false; + } + + if (displaySupportsHdr10) { + return true; + } + + // Explicit HDR opt-in still requests a 10-bit stream on SDR panels. + return true; + } + + static boolean shouldShowSdr10BitOptInToast(boolean prefEnableHdr, + boolean onExternalDisplay, + int sdkInt, + boolean displaySupportsHdr10) { + return prefEnableHdr && + !onExternalDisplay && + sdkInt >= Build.VERSION_CODES.N && + !displaySupportsHdr10; + } + + static boolean shouldShowHdrRequiresAndroidNToast(boolean prefEnableHdr, + boolean onExternalDisplay, + int sdkInt) { + return prefEnableHdr && + !onExternalDisplay && + sdkInt < Build.VERSION_CODES.N; + } private final Runnable flushCommitTextQueue = new Runnable() { @Override @@ -598,36 +654,30 @@ public boolean onCapturedPointer(View view, MotionEvent motionEvent) { MediaCodecHelper.initialize(this, glPrefs.glRenderer); // Check if the user has enabled HDR - boolean willStreamHdr = false; - if (prefConfig.enableHdr) { - if (onExternelDisplay) { - // Enforce HDR on unsupported hardware can still enable 10bit streaming for better quality - willStreamHdr = true; - } else { - // Start our HDR checklist - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - Display.HdrCapabilities hdrCaps = currentDisplay.getHdrCapabilities(); - - // We must now ensure our display is compatible with HDR10 - if (hdrCaps != null) { - // getHdrCapabilities() returns null on Lenovo Lenovo Mirage Solo (vega), Android 8.0 - for (int hdrType : hdrCaps.getSupportedHdrTypes()) { - if (hdrType == Display.HdrCapabilities.HDR_TYPE_HDR10) { - willStreamHdr = true; - break; - } - } - } + boolean displaySupportsHdr10 = false; + if (!onExternelDisplay && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + displaySupportsHdr10 = displaySupportsHdr10(currentDisplay.getHdrCapabilities()); + } + boolean willStreamHdr = shouldRequestHdrStream( + prefConfig.enableHdr, + onExternelDisplay, + Build.VERSION.SDK_INT, + displaySupportsHdr10 + ); - if (!willStreamHdr) { - // Nope, no HDR for us :( - Toast.makeText(this, "Display does not support HDR10", Toast.LENGTH_LONG).show(); - } - } - else { - Toast.makeText(this, "HDR requires Android 7.0 or later", Toast.LENGTH_LONG).show(); - } - } + if (shouldShowSdr10BitOptInToast( + prefConfig.enableHdr, + onExternelDisplay, + Build.VERSION.SDK_INT, + displaySupportsHdr10 + )) { + Toast.makeText(this, "Display does not support HDR10. Artemis will request a 10-bit SDR stream.", Toast.LENGTH_LONG).show(); + } else if (shouldShowHdrRequiresAndroidNToast( + prefConfig.enableHdr, + onExternelDisplay, + Build.VERSION.SDK_INT + )) { + Toast.makeText(this, "HDR requires Android 7.0 or later", Toast.LENGTH_LONG).show(); } // Check if the user has enabled performance stats overlay @@ -4346,4 +4396,4 @@ private SurfaceView findFirstSurfaceViewFrom(View v) { return null; } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/limelight/preferences/StreamSettings.java b/app/src/main/java/com/limelight/preferences/StreamSettings.java index 5b2d20de13..4f8408f1f1 100755 --- a/app/src/main/java/com/limelight/preferences/StreamSettings.java +++ b/app/src/main/java/com/limelight/preferences/StreamSettings.java @@ -629,7 +629,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { } }); - // Remove HDR preference for devices below Nougat + // Remove HDR preference for devices below Nougat. + // On SDR handheld panels running Android N+, we still expose this toggle if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { LimeLog.info("Excluding HDR toggle based on OS"); PreferenceCategory category = @@ -650,21 +651,21 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { } } } + PreferenceCategory category = + (PreferenceCategory) findPreference("category_video_settings"); + CheckBoxPreference hdrPref = (CheckBoxPreference) category.findPreference("checkbox_enable_hdr"); - if (!foundHdr10) { - LimeLog.info("Excluding HDR toggle based on display capabilities"); - PreferenceCategory category = - (PreferenceCategory) findPreference("category_video_settings"); - category.removePreference(findPreference("checkbox_enable_hdr")); + if (!foundHdr10 && hdrPref != null) { + LimeLog.info("Keeping HDR toggle visible for 10-bit SDR opt-in"); + hdrPref.setSummary(R.string.summary_enable_hdr_sdr_10bit); } else if (PreferenceConfiguration.isShieldAtvFirmwareWithBrokenHdr()) { LimeLog.info("Disabling HDR toggle on old broken SHIELD TV firmware"); - PreferenceCategory category = - (PreferenceCategory) findPreference("category_video_settings"); - CheckBoxPreference hdrPref = (CheckBoxPreference) category.findPreference("checkbox_enable_hdr"); - hdrPref.setEnabled(false); - hdrPref.setChecked(false); - hdrPref.setSummary("Update the firmware on your NVIDIA SHIELD Android TV to enable HDR"); + if (hdrPref != null) { + hdrPref.setEnabled(false); + hdrPref.setChecked(false); + hdrPref.setSummary("Update the firmware on your NVIDIA SHIELD Android TV to enable HDR"); + } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 95f64c92a5..df366b19ce 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -306,6 +306,7 @@ Newer codecs can lower video bandwidth requirements if your device supports them. Codec selections may be ignored if not supported by the host software or GPU. Enable HDR (Experimental) Stream HDR when the game and PC GPU support it. HDR requires a GPU with HEVC Main 10 encoding support. + Request a 10-bit stream even on SDR displays. On Devices with SDR panels Artemis will prefer a 10-bit SDR stream when the host supports Main10. Force full range video (Experimental) This will cause loss of detail in light and dark areas if your device doesn\'t properly display full range video content. Prevent Packet Loss