aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hoisie <hoisie@google.com>2024-04-16 09:07:00 -0700
committerCopybara-Service <copybara-worker@google.com>2024-04-16 09:07:39 -0700
commit6970abf2416fd09ac8fb0d4d993b20aaa2834bfe (patch)
treea6960999966ba1c7b2bf184e39dae85394296802
parent2720630fde3f4e3d17a3b3c55e8f05fada5b950b (diff)
downloadrobolectric-6970abf2416fd09ac8fb0d4d993b20aaa2834bfe.tar.gz
Rename `robolectric.screenshot.hwrdr.native` to `robolectric.pixelCopyRenderMode`
The system property `robolectric.screenshot.hwrdr.native` is starting to be used for some screenshot tests in external Gradle projects. The goal was to have this be a short-lived internal system property. However, it may need to persist until HW rendering is more mature (e.g. supported on all RNG SDK levels) and can support all relevant PixelCopy use cases. Rename the system property to `robolectric.pixelCopyRenderMode` to make it clear and unambiguous what the effect of the system property will be. If `robolectric.pixelCopyRenderMode` is set to `hardware`, HW rendering will be used for PixelCopy operations. Otherwise, SW rendering will be used for PixelCopy. Otherwise it has no effect. PiperOrigin-RevId: 625351004
-rw-r--r--integration_tests/roborazzi/src/test/java/org/robolectric/integration/roborazzi/RoborazziCaptureTest.kt31
-rw-r--r--shadows/framework/src/main/java/org/robolectric/shadows/HardwareRenderingScreenshot.java4
2 files changed, 16 insertions, 19 deletions
diff --git a/integration_tests/roborazzi/src/test/java/org/robolectric/integration/roborazzi/RoborazziCaptureTest.kt b/integration_tests/roborazzi/src/test/java/org/robolectric/integration/roborazzi/RoborazziCaptureTest.kt
index 9adbe305e..6a54739fd 100644
--- a/integration_tests/roborazzi/src/test/java/org/robolectric/integration/roborazzi/RoborazziCaptureTest.kt
+++ b/integration_tests/roborazzi/src/test/java/org/robolectric/integration/roborazzi/RoborazziCaptureTest.kt
@@ -51,12 +51,7 @@ class RoborazziCaptureTest {
RoborazziRule.Options(
outputDirectoryPath = OUTPUT_DIRECTORY_PATH,
roborazziOptions =
- RoborazziOptions(
- recordOptions =
- RoborazziOptions.RecordOptions(
- resizeScale = 0.5,
- )
- )
+ RoborazziOptions(recordOptions = RoborazziOptions.RecordOptions(resizeScale = 0.5)),
)
)
@@ -99,13 +94,16 @@ class RoborazziCaptureTest {
|run `./gradlew integration_tests:roborazzi:recordRoborazziDebug -Drobolectric.alwaysIncludeVariantMarkersInTestName=true` and commit the changes.
|"""
.trimMargin(),
- e
+ e,
)
}
}
companion object {
+ // TODO(hoisie): `robolectric.screenshot.hwrdr.native` is obsolete, remove it after the next
+ // Robolectric point release.
const val USE_HARDWARE_RENDERER_NATIVE_ENV = "robolectric.screenshot.hwrdr.native"
+ const val PIXEL_COPY_RENDER_MODE = "robolectric.pixelCopyRenderMode"
}
}
@@ -113,17 +111,14 @@ private fun registerActivityToPackageManager(activity: String) {
val appContext: Application =
InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as Application
Shadows.shadowOf(appContext.packageManager)
- .addActivityIfNotPresent(
- ComponentName(
- appContext.packageName,
- activity,
- )
- )
+ .addActivityIfNotPresent(ComponentName(appContext.packageName, activity))
}
private fun hardwareRendererEnvironment(block: () -> Unit) {
val originalHwrdrOption =
System.getProperty(RoborazziCaptureTest.USE_HARDWARE_RENDERER_NATIVE_ENV, null)
+ val originalPixelCopyOption =
+ System.getProperty(RoborazziCaptureTest.PIXEL_COPY_RENDER_MODE, null)
// This cause ClassNotFoundException: java.nio.NioUtils
// TODO: Remove comment out after fix this issue
// https://github.com/robolectric/robolectric/issues/8081#issuecomment-1858726896
@@ -133,8 +128,10 @@ private fun hardwareRendererEnvironment(block: () -> Unit) {
} finally {
if (originalHwrdrOption == null) {
System.clearProperty(RoborazziCaptureTest.USE_HARDWARE_RENDERER_NATIVE_ENV)
+ System.clearProperty(RoborazziCaptureTest.PIXEL_COPY_RENDER_MODE)
} else {
System.setProperty(RoborazziCaptureTest.USE_HARDWARE_RENDERER_NATIVE_ENV, originalHwrdrOption)
+ System.setProperty(RoborazziCaptureTest.PIXEL_COPY_RENDER_MODE, originalPixelCopyOption)
}
}
}
@@ -158,9 +155,9 @@ private class RoborazziViewWithElevationTestActivity : Activity() {
},
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
- LinearLayout.LayoutParams.MATCH_PARENT
+ LinearLayout.LayoutParams.MATCH_PARENT,
)
- .apply { setMargins(10.toDp(), 10.toDp(), 10.toDp(), 10.toDp()) }
+ .apply { setMargins(10.toDp(), 10.toDp(), 10.toDp(), 10.toDp()) },
)
}
)
@@ -181,9 +178,9 @@ private class RoborazziDialogTestActivity : Activity() {
TextView(this.context).apply { text = "Under the dialog" },
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.WRAP_CONTENT
+ LinearLayout.LayoutParams.WRAP_CONTENT,
)
- .apply { setMargins(10.toDp(), 10.toDp(), 10.toDp(), 10.toDp()) }
+ .apply { setMargins(10.toDp(), 10.toDp(), 10.toDp(), 10.toDp()) },
)
}
)
diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/HardwareRenderingScreenshot.java b/shadows/framework/src/main/java/org/robolectric/shadows/HardwareRenderingScreenshot.java
index fbbe12385..63e9d7bd8 100644
--- a/shadows/framework/src/main/java/org/robolectric/shadows/HardwareRenderingScreenshot.java
+++ b/shadows/framework/src/main/java/org/robolectric/shadows/HardwareRenderingScreenshot.java
@@ -25,7 +25,7 @@ import org.robolectric.util.ReflectionHelpers;
*/
public final class HardwareRenderingScreenshot {
- static final String USE_HARDWARE_RENDERER_NATIVE_ENV = "robolectric.screenshot.hwrdr.native";
+ static final String PIXEL_COPY_RENDER_MODE = "robolectric.pixelCopyRenderMode";
private HardwareRenderingScreenshot() {}
@@ -36,7 +36,7 @@ public final class HardwareRenderingScreenshot {
*/
static boolean canTakeScreenshot() {
return VERSION.SDK_INT >= VERSION_CODES.S
- && Boolean.getBoolean(HardwareRenderingScreenshot.USE_HARDWARE_RENDERER_NATIVE_ENV)
+ && "hardware".equalsIgnoreCase(System.getProperty(PIXEL_COPY_RENDER_MODE, ""))
&& ShadowView.useRealGraphics();
}