From 301c1b00176a8faa872dd5de036f3a1b08c66e49 Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Thu, 28 Nov 2024 20:00:27 +0000 Subject: [PATCH] More benchmark consistency work (#424) - Enable disk caching - Change the scroll used in tests - Updated docs - Updated baseline profile --- docs/performance.md | 51 +++++--- .../baselineProfiles/baseline-prof.txt | 117 ++++++++++++------ .../BaselineProfileGenerator.kt | 8 +- .../haze/benchmark/BenchmarkTest.kt | 16 +-- .../chrisbanes/haze/testutils/UiAutomator.kt | 34 +++-- .../haze/sample/Platform.android.kt | 10 ++ .../dev/chrisbanes/haze/sample/Platform.kt | 9 ++ .../dev/chrisbanes/haze/sample/Samples.kt | 42 +++++-- .../chrisbanes/haze/sample/ScaffoldSample.kt | 9 +- .../chrisbanes/haze/sample/Platform.ios.kt | 9 ++ .../dev/chrisbanes/haze/sample/Platform.js.kt | 9 ++ .../chrisbanes/haze/sample/Platform.jvm.kt | 9 ++ .../chrisbanes/haze/sample/Platform.wasmJs.kt | 9 ++ 13 files changed, 241 insertions(+), 91 deletions(-) create mode 100644 sample/shared/src/androidMain/kotlin/dev/chrisbanes/haze/sample/Platform.android.kt create mode 100644 sample/shared/src/commonMain/kotlin/dev/chrisbanes/haze/sample/Platform.kt create mode 100644 sample/shared/src/iosMain/kotlin/dev/chrisbanes/haze/sample/Platform.ios.kt create mode 100644 sample/shared/src/jsMain/kotlin/dev/chrisbanes/haze/sample/Platform.js.kt create mode 100644 sample/shared/src/jvmMain/kotlin/dev/chrisbanes/haze/sample/Platform.jvm.kt create mode 100644 sample/shared/src/wasmJsMain/kotlin/dev/chrisbanes/haze/sample/Platform.wasmJs.kt diff --git a/docs/performance.md b/docs/performance.md index 43a05a7a..9387de7e 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -4,9 +4,12 @@ Haze tries to use the most performant mechanism possible on each platform, which ## Input Scale -You can provide an input scale value which determines how much the content is scaled in both the x and y dimensions, allowing the blur effect to be potentially applied over scaled-down content (and thus less pixels), before being scaled back up and drawn at the original size. +You can provide an input scale value which determines how much the content is scaled in both the x and y dimensions, allowing the blur effect to be potentially applied over scaled-down content (and thus less pixels), before being scaled back up and drawn at the original size. You can find more information on how to use this [here](usage.md#input-scale). -You can find more information [here](usage.md#input-scale). +In terms of the performance benefit which scaling provides, it's fairly small. In our Android benchmark tests, using an `inputScale` set to `0.5` reduced the _cost of Haze_ by **5-20%**. You can read more about this below. + +!!! abstract "Cost of Haze" + Just to call out: the percentage that I mentioned is a reduction in the cost of Haze, not the total frame duration. Haze itself introduces a cost, which you can read more about below. The reduction in total frame duration duration will be in the region of 3-5%. ## Benchmarks @@ -22,29 +25,39 @@ We currently have 4 benchmark scenarios, each of them is one of the samples in t - **Credit Card**. A simple example, where the user can drag the `hazeChild`. This tests how fast Haze's internal state invalidates and propogates to the `RenderNode`s. This example uses rounded rectangle haze areas like 'Images List'. !!! abstract "Test setup" - All of the tests were ran with 10 iterations on a Pixel 6, running the latest version of Android available. All of the numbers below are the P50 (median) frame duration time in milliseconds. - -As with all benchmark tests, the results are only true for the exact things being tested. Using Haze in your own applications may result in different performance characteristics, so it is wise to write your own performance tests to validate the impact to your apps. + All of the tests were ran with 16 iterations on a Pixel 6, running the latest version of Android available. -#### 0.7.3 vs 1.0.0 +As with all benchmark tests, the results are only true for the exact things being tested. Using Haze in your own applications may result in different performance characteristics, so it is wise to write your own performance tests to validate the impact to your apps. Benchmark tests will always have variability in them too, so don't take the numbers listed below as exact values. Look at them more as a guide. -| Test | 0.7.3 | 1.0.0 | Difference | -| ------------- | ---------- | -----------| ------------ | -| Scaffold | 6.9 ms | 6.4 ms | :material-trending-down: -7% | -| Scaffold (progressive) (SDK 32) | - | 14.8 ms | - | -| Scaffold (progressive) (SDK 34) | - | 7.9 ms | - | -| Images List | 6.9 ms | 6.8 ms | :material-trending-down: -1% | -| Credit Card | 4.9 ms | 4.7 ms | :material-trending-down: -4% | +The numbers listed below the P90 frame durations in milliseconds, which tend to be a good indicator of frames where a user interaction is happening (scrolling, etc). However, as these are the P90 values, these indicate the longest 10% frame durations, and thus are (probably) not indicitive of the performance which users see most of the time. It all depends on the distribution of the frame durations, but we're quickly getting into entry-level statistics, which is beyond what we're trying to document here. -#### 1.0.0 vs baseline +#### Cost of Haze -We can also measure the rough cost of using Haze in the same samples. Here we've ran the same tests, but with Haze being disabled: +We can also measure the rough cost of using Haze in the same samples. Here we've ran the same tests, with Haze being completely disabled: -| Test | 1.0.0 (disabled) | 1.0.0 | Difference | +| Test | 1.0.x (disabled) | 1.0.x | Difference | | ------------- | ------------------| -----------| ------------ | -| Scaffold | 4.9 ms | 6.4 ms | +31% | -| Images List | 4.6 ms | 6.8 ms | +48% | -| Credit Card | 4.1 ms | 4.7 ms | +15% | +| Scaffold | 7.5 ms | 9.7 ms | +29% | +| Images List | 6.6 ms | 9.6 ms | +45% | +| Credit Card | 6.6 ms | 13.1 ms | +98% | + +#### Cost of features + +We can also measure the rough cost of using features, such as input scale, progressive and masking: + +| Test | P90 frame duration (ms) | Difference (in Haze cost) | +| ------------- | -------------------------| -----------| +| Scaffold | 9.7 ms | - | +| Scaffold (inputScale = 0.5) | 9.6 ms | -5% | +| Scaffold (masked) | 9.8 ms | +5% | +| Scaffold (progressive) | 9.7 ms | 0% | +| Scaffold (progressive, inputScale = 0.5) | 9.4 ms | -14% | + +The values are all very close, with the differences easily being within a margin of error, so don't use these differences as exact values (especially with the variability that we mentioned above). I think there's two big take aways here though: + +- Masking has a negligible effect on frame durations. +- Progessive has a negligible effect on frame durations, when using using our custom blur shader (Android SDK 34+, all other platforms). +- Input Scale has a small but positive effect on frame duration. !!! example "Full results" For those interested, you can find the full results in this [spreadsheet](https://docs.google.com/spreadsheets/d/1wZ9pbX0HDIa08ITwYy7BrYYwOq2sX-HUyAMQlcb3dI4/edit?usp=sharing). diff --git a/haze/src/androidMain/generated/baselineProfiles/baseline-prof.txt b/haze/src/androidMain/generated/baselineProfiles/baseline-prof.txt index d6191d68..5a649313 100644 --- a/haze/src/androidMain/generated/baselineProfiles/baseline-prof.txt +++ b/haze/src/androidMain/generated/baselineProfiles/baseline-prof.txt @@ -18,32 +18,35 @@ PLdev/chrisbanes/haze/BlendModeKt$$ExternalSyntheticApiModelOutline0;->m(Landroi PLdev/chrisbanes/haze/BlendModeKt$$ExternalSyntheticApiModelOutline0;->m(Landroid/graphics/RuntimeShader;Ljava/lang/String;Landroid/graphics/Shader;)V PLdev/chrisbanes/haze/BlendModeKt$$ExternalSyntheticApiModelOutline0;->m(Landroid/graphics/Shader;)Landroid/graphics/RenderEffect; PLdev/chrisbanes/haze/BlendModeKt$$ExternalSyntheticApiModelOutline0;->m(Ljava/lang/String;)Landroid/graphics/RuntimeShader; +Ldev/chrisbanes/haze/GradientKt; PLdev/chrisbanes/haze/GradientKt;->asBrush$default(Ldev/chrisbanes/haze/HazeProgressive$LinearGradient;IILjava/lang/Object;)Landroidx/compose/ui/graphics/Brush; -PLdev/chrisbanes/haze/GradientKt;->asBrush(Ldev/chrisbanes/haze/HazeProgressive$LinearGradient;I)Landroidx/compose/ui/graphics/Brush; +HPLdev/chrisbanes/haze/GradientKt;->asBrush(Ldev/chrisbanes/haze/HazeProgressive$LinearGradient;I)Landroidx/compose/ui/graphics/Brush; Ldev/chrisbanes/haze/HazeChildKt; HSPLdev/chrisbanes/haze/HazeChildKt;->hazeChild$default(Landroidx/compose/ui/Modifier;Ldev/chrisbanes/haze/HazeState;Ldev/chrisbanes/haze/HazeStyle;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Landroidx/compose/ui/Modifier; HSPLdev/chrisbanes/haze/HazeChildKt;->hazeChild(Landroidx/compose/ui/Modifier;Ldev/chrisbanes/haze/HazeState;Ldev/chrisbanes/haze/HazeStyle;Lkotlin/jvm/functions/Function1;)Landroidx/compose/ui/Modifier; Ldev/chrisbanes/haze/HazeChildNode; -HSPLdev/chrisbanes/haze/HazeChildNode;->$r8$lambda$r1HDnNv10MaXz_bu2cEaBm19yyY(Ldev/chrisbanes/haze/HazeChildNode;JLandroidx/compose/ui/graphics/layer/GraphicsLayer;Landroidx/compose/ui/graphics/drawscope/DrawScope;)Lkotlin/Unit; -HSPLdev/chrisbanes/haze/HazeChildNode;->$r8$lambda$ughv07ZX8pJks1lK41Tnn8NeGh8(Ldev/chrisbanes/haze/HazeChildNode;)Lkotlin/Unit; +HSPLdev/chrisbanes/haze/HazeChildNode;->$r8$lambda$K619w--mW2awolKyh86WJxfVvds(Ldev/chrisbanes/haze/HazeChildNode;)Lkotlin/Unit; +HSPLdev/chrisbanes/haze/HazeChildNode;->$r8$lambda$T8dltSr3FDlz9xCZjtUFrYgVNkQ(JLdev/chrisbanes/haze/HazeChildNode;JLandroidx/compose/ui/graphics/layer/GraphicsLayer;Landroidx/compose/ui/graphics/drawscope/DrawScope;)Lkotlin/Unit; HSPLdev/chrisbanes/haze/HazeChildNode;->()V HSPLdev/chrisbanes/haze/HazeChildNode;->(Ldev/chrisbanes/haze/HazeState;Ldev/chrisbanes/haze/HazeStyle;Lkotlin/jvm/functions/Function1;)V HSPLdev/chrisbanes/haze/HazeChildNode;->draw(Landroidx/compose/ui/graphics/drawscope/ContentDrawScope;)V -HSPLdev/chrisbanes/haze/HazeChildNode;->drawEffectWithGraphicsLayer$lambda$26(Ldev/chrisbanes/haze/HazeChildNode;JLandroidx/compose/ui/graphics/layer/GraphicsLayer;Landroidx/compose/ui/graphics/drawscope/DrawScope;)Lkotlin/Unit; +HSPLdev/chrisbanes/haze/HazeChildNode;->drawEffectWithGraphicsLayer$lambda$31(JLdev/chrisbanes/haze/HazeChildNode;JLandroidx/compose/ui/graphics/layer/GraphicsLayer;Landroidx/compose/ui/graphics/drawscope/DrawScope;)Lkotlin/Unit; HSPLdev/chrisbanes/haze/HazeChildNode;->drawEffectWithGraphicsLayer(Landroidx/compose/ui/graphics/drawscope/DrawScope;Landroidx/compose/ui/graphics/layer/GraphicsLayer;)V -HSPLdev/chrisbanes/haze/HazeChildNode;->drawEffectWithScrim$scrim(Ldev/chrisbanes/haze/HazeTint;Ldev/chrisbanes/haze/HazeChildNode;Landroidx/compose/ui/graphics/drawscope/DrawScope;)V +HSPLdev/chrisbanes/haze/HazeChildNode;->drawEffectWithScrim$scrim(Ldev/chrisbanes/haze/HazeChildNode;Landroidx/compose/ui/graphics/drawscope/DrawScope;Ldev/chrisbanes/haze/HazeTint;)V HSPLdev/chrisbanes/haze/HazeChildNode;->drawEffectWithScrim(Landroidx/compose/ui/graphics/drawscope/DrawScope;)V HSPLdev/chrisbanes/haze/HazeChildNode;->getAlpha()F HSPLdev/chrisbanes/haze/HazeChildNode;->getBackgroundColor-0d7_KjU()J +HSPLdev/chrisbanes/haze/HazeChildNode;->getBlurEnabled()Z HSPLdev/chrisbanes/haze/HazeChildNode;->getBlurRadius-D9Ej5fM()F HSPLdev/chrisbanes/haze/HazeChildNode;->getCompositionLocalStyle$haze_release()Ldev/chrisbanes/haze/HazeStyle; HSPLdev/chrisbanes/haze/HazeChildNode;->getContentOffset-F1C5BW0$haze_release()J HSPLdev/chrisbanes/haze/HazeChildNode;->getFallbackTint()Ldev/chrisbanes/haze/HazeTint; -PLdev/chrisbanes/haze/HazeChildNode;->getLayerSize-NH-jbRc$haze_release()J +HSPLdev/chrisbanes/haze/HazeChildNode;->getInputScale()F HSPLdev/chrisbanes/haze/HazeChildNode;->getMask()Landroidx/compose/ui/graphics/Brush; HSPLdev/chrisbanes/haze/HazeChildNode;->getNoiseFactor()F HSPLdev/chrisbanes/haze/HazeChildNode;->getProgressive()Ldev/chrisbanes/haze/HazeProgressive; HSPLdev/chrisbanes/haze/HazeChildNode;->getShouldAutoInvalidate()Z +HSPLdev/chrisbanes/haze/HazeChildNode;->getSize-NH-jbRc$haze_release()J HSPLdev/chrisbanes/haze/HazeChildNode;->getStyle()Ldev/chrisbanes/haze/HazeStyle; HSPLdev/chrisbanes/haze/HazeChildNode;->getTints()Ljava/util/List; HSPLdev/chrisbanes/haze/HazeChildNode;->isValid()Z @@ -51,47 +54,47 @@ HSPLdev/chrisbanes/haze/HazeChildNode;->needInvalidation()Z HSPLdev/chrisbanes/haze/HazeChildNode;->onAttach()V HSPLdev/chrisbanes/haze/HazeChildNode;->onGloballyPositioned(Landroidx/compose/ui/layout/LayoutCoordinates;)V HSPLdev/chrisbanes/haze/HazeChildNode;->onMeasureResultChanged()V -HSPLdev/chrisbanes/haze/HazeChildNode;->onObservedReadsChanged$lambda$14(Ldev/chrisbanes/haze/HazeChildNode;)Lkotlin/Unit; +HSPLdev/chrisbanes/haze/HazeChildNode;->onObservedReadsChanged$lambda$17(Ldev/chrisbanes/haze/HazeChildNode;)Lkotlin/Unit; HSPLdev/chrisbanes/haze/HazeChildNode;->onObservedReadsChanged()V HSPLdev/chrisbanes/haze/HazeChildNode;->onPostDraw()V HSPLdev/chrisbanes/haze/HazeChildNode;->setBlock(Lkotlin/jvm/functions/Function1;)V HSPLdev/chrisbanes/haze/HazeChildNode;->setCompositionLocalStyle$haze_release(Ldev/chrisbanes/haze/HazeStyle;)V -HSPLdev/chrisbanes/haze/HazeChildNode;->setLayerSize-uvyYCjk$haze_release(J)V +HPLdev/chrisbanes/haze/HazeChildNode;->setInputScale(F)V +HSPLdev/chrisbanes/haze/HazeChildNode;->setLayerSize-uvyYCjk(J)V HSPLdev/chrisbanes/haze/HazeChildNode;->setPositionInContent-k-4lQ0M(J)V PLdev/chrisbanes/haze/HazeChildNode;->setProgressive(Ldev/chrisbanes/haze/HazeProgressive;)V -HSPLdev/chrisbanes/haze/HazeChildNode;->setSize-uvyYCjk(J)V +HSPLdev/chrisbanes/haze/HazeChildNode;->setSize-uvyYCjk$haze_release(J)V HSPLdev/chrisbanes/haze/HazeChildNode;->setState(Ldev/chrisbanes/haze/HazeState;)V HSPLdev/chrisbanes/haze/HazeChildNode;->setStyle(Ldev/chrisbanes/haze/HazeStyle;)V HSPLdev/chrisbanes/haze/HazeChildNode;->update$haze_release()V HSPLdev/chrisbanes/haze/HazeChildNode;->updateEffect()V -HSPLdev/chrisbanes/haze/HazeChildNode;->updateRenderEffectIfDirty(Landroidx/compose/ui/graphics/drawscope/DrawScope;)V +HSPLdev/chrisbanes/haze/HazeChildNode;->updateRenderEffectIfDirty()V Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda0; HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda0;->()V Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda1; HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda1;->()V Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda10; -HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda10;->(Landroidx/compose/ui/layout/LayoutCoordinates;)V +HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda10;->(Ldev/chrisbanes/haze/HazeChildNode;)V Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda11; -Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda12; -HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda12;->(Ldev/chrisbanes/haze/HazeChildNode;JLandroidx/compose/ui/graphics/layer/GraphicsLayer;)V -HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda12;->invoke(Ljava/lang/Object;)Ljava/lang/Object; Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda13; -HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda13;->()V +HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda13;->(Landroidx/compose/ui/layout/LayoutCoordinates;)V Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda14; -HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda14;->()V -Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda19; -HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda19;->(Ldev/chrisbanes/haze/HazeChildNode;J)V -PLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda20;->(Ldev/chrisbanes/haze/HazeChildNode;Ldev/chrisbanes/haze/HazeStyle;)V -Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda21; -HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda21;->(Ldev/chrisbanes/haze/HazeChildNode;)V -HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda21;->invoke()Ljava/lang/Object; -Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda4; -HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda4;->(Ldev/chrisbanes/haze/HazeChildNode;J)V -PLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda6;->(Ldev/chrisbanes/haze/HazeChildNode;Ldev/chrisbanes/haze/HazeProgressive;)V -Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda7; -HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda7;->(Ldev/chrisbanes/haze/HazeChildNode;J)V -Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda9; -HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda9;->(Ldev/chrisbanes/haze/HazeChildNode;)V +HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda14;->(JLdev/chrisbanes/haze/HazeChildNode;JLandroidx/compose/ui/graphics/layer/GraphicsLayer;)V +HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda14;->invoke(Ljava/lang/Object;)Ljava/lang/Object; +Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda15; +HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda15;->()V +Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda16; +HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda16;->()V +Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda20; +HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda20;->(Ldev/chrisbanes/haze/HazeChildNode;J)V +Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda23; +HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda23;->(Ldev/chrisbanes/haze/HazeChildNode;)V +HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda23;->invoke()Ljava/lang/Object; +Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda6; +HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda6;->(Ldev/chrisbanes/haze/HazeChildNode;J)V +PLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda7;->(Ldev/chrisbanes/haze/HazeChildNode;Ldev/chrisbanes/haze/HazeProgressive;)V +Ldev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda8; +HSPLdev/chrisbanes/haze/HazeChildNode$$ExternalSyntheticLambda8;->(Ldev/chrisbanes/haze/HazeChildNode;J)V Ldev/chrisbanes/haze/HazeChildNode$Companion; HSPLdev/chrisbanes/haze/HazeChildNode$Companion;->()V HSPLdev/chrisbanes/haze/HazeChildNode$Companion;->(Lkotlin/jvm/internal/DefaultConstructorMarker;)V @@ -103,14 +106,33 @@ HSPLdev/chrisbanes/haze/HazeChildNodeElement;->equals(Ljava/lang/Object;)Z HSPLdev/chrisbanes/haze/HazeChildNodeElement;->update(Landroidx/compose/ui/Modifier$Node;)V HSPLdev/chrisbanes/haze/HazeChildNodeElement;->update(Ldev/chrisbanes/haze/HazeChildNode;)V Ldev/chrisbanes/haze/HazeChildNodeKt; +HSPLdev/chrisbanes/haze/HazeChildNodeKt;->$r8$lambda$k6w-KQkrwpTIqEt50dKuczn_nx4()Lio/github/reactivecircus/cache4k/Cache; +HSPLdev/chrisbanes/haze/HazeChildNodeKt;->()V +HSPLdev/chrisbanes/haze/HazeChildNodeKt;->getOrCreateRenderEffect(Landroidx/compose/ui/node/CompositionLocalConsumerModifierNode;Ldev/chrisbanes/haze/RenderEffectParams;)Landroidx/compose/ui/graphics/RenderEffect; +HSPLdev/chrisbanes/haze/HazeChildNodeKt;->getOrCreateRenderEffect-NXZB3nA$default(Ldev/chrisbanes/haze/HazeChildNode;FFFLjava/util/List;FJJLandroidx/compose/ui/graphics/Brush;Landroidx/compose/ui/graphics/Brush;ILjava/lang/Object;)Landroidx/compose/ui/graphics/RenderEffect; +HSPLdev/chrisbanes/haze/HazeChildNodeKt;->getOrCreateRenderEffect-NXZB3nA(Ldev/chrisbanes/haze/HazeChildNode;FFFLjava/util/List;FJJLandroidx/compose/ui/graphics/Brush;Landroidx/compose/ui/graphics/Brush;)Landroidx/compose/ui/graphics/RenderEffect; +HSPLdev/chrisbanes/haze/HazeChildNodeKt;->getRenderEffectCache()Lio/github/reactivecircus/cache4k/Cache; +HSPLdev/chrisbanes/haze/HazeChildNodeKt;->renderEffectCache_delegate$lambda$0()Lio/github/reactivecircus/cache4k/Cache; HSPLdev/chrisbanes/haze/HazeChildNodeKt;->resolveBackgroundColor(Ldev/chrisbanes/haze/HazeChildNode;)J HSPLdev/chrisbanes/haze/HazeChildNodeKt;->resolveBlurRadius(Ldev/chrisbanes/haze/HazeChildNode;)F HSPLdev/chrisbanes/haze/HazeChildNodeKt;->resolveFallbackTint(Ldev/chrisbanes/haze/HazeChildNode;)Ldev/chrisbanes/haze/HazeTint; HSPLdev/chrisbanes/haze/HazeChildNodeKt;->resolveNoiseFactor(Ldev/chrisbanes/haze/HazeChildNode;)F HSPLdev/chrisbanes/haze/HazeChildNodeKt;->resolveTints(Ldev/chrisbanes/haze/HazeChildNode;)Ljava/util/List; +Ldev/chrisbanes/haze/HazeChildNodeKt$$ExternalSyntheticLambda0; +HSPLdev/chrisbanes/haze/HazeChildNodeKt$$ExternalSyntheticLambda0;->()V +HSPLdev/chrisbanes/haze/HazeChildNodeKt$$ExternalSyntheticLambda0;->invoke()Ljava/lang/Object; +Ldev/chrisbanes/haze/HazeChildNodeKt$$ExternalSyntheticLambda1; +HSPLdev/chrisbanes/haze/HazeChildNodeKt$$ExternalSyntheticLambda1;->(Ldev/chrisbanes/haze/RenderEffectParams;)V +Ldev/chrisbanes/haze/HazeChildNodeKt$$ExternalSyntheticLambda2; +HSPLdev/chrisbanes/haze/HazeChildNodeKt$$ExternalSyntheticLambda2;->(Ldev/chrisbanes/haze/RenderEffectParams;)V +Ldev/chrisbanes/haze/HazeChildNodeKt$$ExternalSyntheticLambda3; +HSPLdev/chrisbanes/haze/HazeChildNodeKt$$ExternalSyntheticLambda3;->(Ldev/chrisbanes/haze/RenderEffectParams;)V PLdev/chrisbanes/haze/HazeChildNode_androidKt;->drawLinearGradientProgressiveEffect(Ldev/chrisbanes/haze/HazeChildNode;Landroidx/compose/ui/graphics/drawscope/DrawScope;Ldev/chrisbanes/haze/HazeProgressive$LinearGradient;Landroidx/compose/ui/graphics/layer/GraphicsLayer;)V Ldev/chrisbanes/haze/HazeChildScope; Ldev/chrisbanes/haze/HazeDefaults; +HSPLdev/chrisbanes/haze/HazeDefaults;->()V +HSPLdev/chrisbanes/haze/HazeDefaults;->()V +HSPLdev/chrisbanes/haze/HazeDefaults;->blurEnabled()Z Ldev/chrisbanes/haze/HazeKt; HSPLdev/chrisbanes/haze/HazeKt;->haze(Landroidx/compose/ui/Modifier;Ldev/chrisbanes/haze/HazeState;)Landroidx/compose/ui/Modifier; Ldev/chrisbanes/haze/HazeNode; @@ -147,16 +169,18 @@ HSPLdev/chrisbanes/haze/HazeNodeElement;->update(Ldev/chrisbanes/haze/HazeNode;) Ldev/chrisbanes/haze/HazeNodeKt; HSPLdev/chrisbanes/haze/HazeNodeKt;->boostAlphaForBlurRadius-l07J4OM(JF)J HSPLdev/chrisbanes/haze/HazeNodeKt;->boostForFallback-3ABfNKs(Ldev/chrisbanes/haze/HazeTint;F)Ldev/chrisbanes/haze/HazeTint; +Ldev/chrisbanes/haze/HazeNode_androidKt; +HSPLdev/chrisbanes/haze/HazeNode_androidKt;->isBlurEnabledByDefault()Z Ldev/chrisbanes/haze/HazeProgressive; PLdev/chrisbanes/haze/HazeProgressive;->()V PLdev/chrisbanes/haze/HazeProgressive$Companion;->()V PLdev/chrisbanes/haze/HazeProgressive$Companion;->()V -PLdev/chrisbanes/haze/HazeProgressive$Companion;->verticalGradient$default(Ldev/chrisbanes/haze/HazeProgressive$Companion;Landroidx/compose/animation/core/Easing;FFFFILjava/lang/Object;)Ldev/chrisbanes/haze/HazeProgressive$LinearGradient; -PLdev/chrisbanes/haze/HazeProgressive$Companion;->verticalGradient(Landroidx/compose/animation/core/Easing;FFFF)Ldev/chrisbanes/haze/HazeProgressive$LinearGradient; +PLdev/chrisbanes/haze/HazeProgressive$Companion;->verticalGradient$default(Ldev/chrisbanes/haze/HazeProgressive$Companion;Landroidx/compose/animation/core/Easing;FFFFZILjava/lang/Object;)Ldev/chrisbanes/haze/HazeProgressive$LinearGradient; +PLdev/chrisbanes/haze/HazeProgressive$Companion;->verticalGradient(Landroidx/compose/animation/core/Easing;FFFFZ)Ldev/chrisbanes/haze/HazeProgressive$LinearGradient; Ldev/chrisbanes/haze/HazeProgressive$LinearGradient; PLdev/chrisbanes/haze/HazeProgressive$LinearGradient;->()V -PLdev/chrisbanes/haze/HazeProgressive$LinearGradient;->(Landroidx/compose/animation/core/Easing;JFJF)V -PLdev/chrisbanes/haze/HazeProgressive$LinearGradient;->(Landroidx/compose/animation/core/Easing;JFJFLkotlin/jvm/internal/DefaultConstructorMarker;)V +PLdev/chrisbanes/haze/HazeProgressive$LinearGradient;->(Landroidx/compose/animation/core/Easing;JFJFZ)V +PLdev/chrisbanes/haze/HazeProgressive$LinearGradient;->(Landroidx/compose/animation/core/Easing;JFJFZLkotlin/jvm/internal/DefaultConstructorMarker;)V PLdev/chrisbanes/haze/HazeProgressive$LinearGradient;->equals(Ljava/lang/Object;)Z PLdev/chrisbanes/haze/HazeProgressive$LinearGradient;->getEasing()Landroidx/compose/animation/core/Easing; PLdev/chrisbanes/haze/HazeProgressive$LinearGradient;->getEnd-F1C5BW0()J @@ -210,6 +234,7 @@ HSPLdev/chrisbanes/haze/HazeTint;->copy-xETnrds(JI)Ldev/chrisbanes/haze/HazeTint HSPLdev/chrisbanes/haze/HazeTint;->equals(Ljava/lang/Object;)Z HSPLdev/chrisbanes/haze/HazeTint;->getBlendMode-0nO6VwU()I HSPLdev/chrisbanes/haze/HazeTint;->getColor-0d7_KjU()J +HSPLdev/chrisbanes/haze/HazeTint;->hashCode()I HSPLdev/chrisbanes/haze/HazeTint;->isSpecified()Z Ldev/chrisbanes/haze/HazeTint$Companion; HSPLdev/chrisbanes/haze/HazeTint$Companion;->()V @@ -217,25 +242,37 @@ HSPLdev/chrisbanes/haze/HazeTint$Companion;->(Lkotlin/jvm/internal/Default HSPLdev/chrisbanes/haze/HazeTint$Companion;->getUnspecified()Ldev/chrisbanes/haze/HazeTint; Ldev/chrisbanes/haze/Log_androidKt; HSPLdev/chrisbanes/haze/Log_androidKt;->log(Ljava/lang/String;Lkotlin/jvm/functions/Function0;)V +Ldev/chrisbanes/haze/RenderEffectParams; +HSPLdev/chrisbanes/haze/RenderEffectParams;->()V +HSPLdev/chrisbanes/haze/RenderEffectParams;->(FFLjava/util/List;FJJLandroidx/compose/ui/graphics/Brush;Landroidx/compose/ui/graphics/Brush;F)V +HSPLdev/chrisbanes/haze/RenderEffectParams;->(FFLjava/util/List;FJJLandroidx/compose/ui/graphics/Brush;Landroidx/compose/ui/graphics/Brush;FLkotlin/jvm/internal/DefaultConstructorMarker;)V +HSPLdev/chrisbanes/haze/RenderEffectParams;->equals(Ljava/lang/Object;)Z +HSPLdev/chrisbanes/haze/RenderEffectParams;->getBlurRadius-D9Ej5fM()F +HSPLdev/chrisbanes/haze/RenderEffectParams;->getContentOffset-F1C5BW0()J +HSPLdev/chrisbanes/haze/RenderEffectParams;->getContentSize-NH-jbRc()J +HSPLdev/chrisbanes/haze/RenderEffectParams;->getInputScale()F +HSPLdev/chrisbanes/haze/RenderEffectParams;->getMask()Landroidx/compose/ui/graphics/Brush; +HSPLdev/chrisbanes/haze/RenderEffectParams;->getNoiseFactor()F +HSPLdev/chrisbanes/haze/RenderEffectParams;->getProgressive()Landroidx/compose/ui/graphics/Brush; +HSPLdev/chrisbanes/haze/RenderEffectParams;->getTintAlphaModulate()F +HSPLdev/chrisbanes/haze/RenderEffectParams;->getTints()Ljava/util/List; +HSPLdev/chrisbanes/haze/RenderEffectParams;->hashCode()I Ldev/chrisbanes/haze/RenderEffect_androidKt; HSPLdev/chrisbanes/haze/RenderEffect_androidKt;->()V PLdev/chrisbanes/haze/RenderEffect_androidKt;->blendWith-moWRBKg(Landroid/graphics/RenderEffect;Landroid/graphics/RenderEffect;Landroid/graphics/BlendMode;J)Landroid/graphics/RenderEffect; +HSPLdev/chrisbanes/haze/RenderEffect_androidKt;->canUseGraphicLayers(Landroidx/compose/ui/graphics/drawscope/DrawScope;)Z PLdev/chrisbanes/haze/RenderEffect_androidKt;->chainWith(Landroid/graphics/RenderEffect;Landroid/graphics/RenderEffect;)Landroid/graphics/RenderEffect; PLdev/chrisbanes/haze/RenderEffect_androidKt;->createBlurImageFilterWithMask$shader(FLandroidx/compose/ui/geometry/Rect;Landroid/graphics/Shader;Z)Landroid/graphics/RenderEffect; PLdev/chrisbanes/haze/RenderEffect_androidKt;->createBlurImageFilterWithMask(FLandroidx/compose/ui/geometry/Rect;Landroid/graphics/Shader;)Landroid/graphics/RenderEffect; -HSPLdev/chrisbanes/haze/RenderEffect_androidKt;->createRenderEffect-nhveHWw$default(Ldev/chrisbanes/haze/HazeChildNode;FFLjava/util/List;FJJJLandroidx/compose/ui/graphics/Brush;Landroidx/compose/ui/graphics/Brush;ILjava/lang/Object;)Landroidx/compose/ui/graphics/RenderEffect; -HSPLdev/chrisbanes/haze/RenderEffect_androidKt;->createRenderEffect-nhveHWw(Ldev/chrisbanes/haze/HazeChildNode;FFLjava/util/List;FJJJLandroidx/compose/ui/graphics/Brush;Landroidx/compose/ui/graphics/Brush;)Landroidx/compose/ui/graphics/RenderEffect; +HSPLdev/chrisbanes/haze/RenderEffect_androidKt;->createRenderEffect(Landroidx/compose/ui/node/CompositionLocalConsumerModifierNode;Ldev/chrisbanes/haze/RenderEffectParams;)Landroidx/compose/ui/graphics/RenderEffect; PLdev/chrisbanes/haze/RenderEffect_androidKt;->toShader-d16Qtg0(Landroidx/compose/ui/graphics/Brush;J)Landroid/graphics/Shader; -HSPLdev/chrisbanes/haze/RenderEffect_androidKt;->useGraphicLayers(Landroidx/compose/ui/graphics/drawscope/DrawScope;)Z HSPLdev/chrisbanes/haze/RenderEffect_androidKt;->withMask-jA9W-mQ$default(Landroid/graphics/RenderEffect;Landroidx/compose/ui/graphics/Brush;JJLandroid/graphics/BlendMode;ILjava/lang/Object;)Landroid/graphics/RenderEffect; HSPLdev/chrisbanes/haze/RenderEffect_androidKt;->withMask-jA9W-mQ(Landroid/graphics/RenderEffect;Landroidx/compose/ui/graphics/Brush;JJLandroid/graphics/BlendMode;)Landroid/graphics/RenderEffect; -HSPLdev/chrisbanes/haze/RenderEffect_androidKt;->withNoise(Landroidx/compose/ui/node/CompositionLocalConsumerModifierNode;Landroid/graphics/RenderEffect;F)Landroid/graphics/RenderEffect; +HSPLdev/chrisbanes/haze/RenderEffect_androidKt;->withNoise(Landroid/graphics/RenderEffect;Landroid/content/Context;FF)Landroid/graphics/RenderEffect; HSPLdev/chrisbanes/haze/RenderEffect_androidKt;->withTint-0mBilkg(Landroid/graphics/RenderEffect;Ldev/chrisbanes/haze/HazeTint;FLandroid/graphics/Shader;J)Landroid/graphics/RenderEffect; HSPLdev/chrisbanes/haze/RenderEffect_androidKt;->withTints-0mBilkg(Landroid/graphics/RenderEffect;Ljava/util/List;FLandroid/graphics/Shader;J)Landroid/graphics/RenderEffect; Ldev/chrisbanes/haze/RenderEffect_androidKt$$ExternalSyntheticLambda15; -HSPLdev/chrisbanes/haze/RenderEffect_androidKt$$ExternalSyntheticLambda15;->(FFLjava/util/List;JJJ)V -Ldev/chrisbanes/haze/RenderEffect_androidKt$special$$inlined$lruCache$default$1; -HSPLdev/chrisbanes/haze/RenderEffect_androidKt$special$$inlined$lruCache$default$1;->(I)V +HSPLdev/chrisbanes/haze/RenderEffect_androidKt$$ExternalSyntheticLambda15;->()V Ldev/chrisbanes/haze/UtilsKt; HSPLdev/chrisbanes/haze/UtilsKt;->expand-TmRCtEA(JF)J PLdev/chrisbanes/haze/UtilsKt;->lerp(FFF)F diff --git a/internal/benchmark/src/main/kotlin/dev/chrisbanes/haze/baselineprofile/BaselineProfileGenerator.kt b/internal/benchmark/src/main/kotlin/dev/chrisbanes/haze/baselineprofile/BaselineProfileGenerator.kt index e3ff912a..8e296e4a 100644 --- a/internal/benchmark/src/main/kotlin/dev/chrisbanes/haze/baselineprofile/BaselineProfileGenerator.kt +++ b/internal/benchmark/src/main/kotlin/dev/chrisbanes/haze/baselineprofile/BaselineProfileGenerator.kt @@ -9,7 +9,7 @@ import androidx.test.uiautomator.By import dev.chrisbanes.haze.testutils.navigateToImagesList import dev.chrisbanes.haze.testutils.navigateToScaffold import dev.chrisbanes.haze.testutils.navigateToScaffoldWithProgressive -import dev.chrisbanes.haze.testutils.scroll +import dev.chrisbanes.haze.testutils.repeatedScrolls import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -28,18 +28,18 @@ class BaselineProfileGenerator { // Scroll down several times device.navigateToImagesList() - device.scroll("lazy_column") + device.repeatedScrolls("lazy_column") device.findObject(By.res("back")).click() device.waitForIdle() device.navigateToScaffoldWithProgressive() - device.scroll("lazy_grid") + device.repeatedScrolls("lazy_grid") device.findObject(By.res("back")).click() device.waitForIdle() device.navigateToScaffold() - device.scroll("lazy_grid") + device.repeatedScrolls("lazy_grid") } } diff --git a/internal/benchmark/src/main/kotlin/dev/chrisbanes/haze/benchmark/BenchmarkTest.kt b/internal/benchmark/src/main/kotlin/dev/chrisbanes/haze/benchmark/BenchmarkTest.kt index 6824f35c..145d048a 100644 --- a/internal/benchmark/src/main/kotlin/dev/chrisbanes/haze/benchmark/BenchmarkTest.kt +++ b/internal/benchmark/src/main/kotlin/dev/chrisbanes/haze/benchmark/BenchmarkTest.kt @@ -16,13 +16,13 @@ import dev.chrisbanes.haze.testutils.navigateToScaffoldScaled import dev.chrisbanes.haze.testutils.navigateToScaffoldWithMask import dev.chrisbanes.haze.testutils.navigateToScaffoldWithProgressive import dev.chrisbanes.haze.testutils.navigateToScaffoldWithProgressiveScaled -import dev.chrisbanes.haze.testutils.scroll +import dev.chrisbanes.haze.testutils.repeatedScrolls import dev.chrisbanes.haze.testutils.waitForObject import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith -private const val DEFAULT_ITERATIONS = 8 +private const val DEFAULT_ITERATIONS = 16 private const val APP_PACKAGE = "dev.chrisbanes.haze.sample.android" @RunWith(AndroidJUnit4::class) @@ -42,7 +42,7 @@ class BenchmarkTest { device.navigateToImagesList() }, ) { - device.scroll("lazy_column") + device.repeatedScrolls("lazy_column") } } @@ -58,7 +58,7 @@ class BenchmarkTest { device.navigateToScaffold() }, ) { - device.scroll("lazy_grid") + device.repeatedScrolls("lazy_grid") } } @@ -74,7 +74,7 @@ class BenchmarkTest { device.navigateToScaffoldScaled() }, ) { - device.scroll("lazy_grid") + device.repeatedScrolls("lazy_grid") } } @@ -90,7 +90,7 @@ class BenchmarkTest { device.navigateToScaffoldWithProgressive() }, ) { - device.scroll("lazy_grid") + device.repeatedScrolls("lazy_grid") } } @@ -106,7 +106,7 @@ class BenchmarkTest { device.navigateToScaffoldWithProgressiveScaled() }, ) { - device.scroll("lazy_grid") + device.repeatedScrolls("lazy_grid") } } @@ -122,7 +122,7 @@ class BenchmarkTest { device.navigateToScaffoldWithMask() }, ) { - device.scroll("lazy_grid") + device.repeatedScrolls("lazy_grid") } } diff --git a/internal/benchmark/src/main/kotlin/dev/chrisbanes/haze/testutils/UiAutomator.kt b/internal/benchmark/src/main/kotlin/dev/chrisbanes/haze/testutils/UiAutomator.kt index 7ec72c89..d74b1880 100644 --- a/internal/benchmark/src/main/kotlin/dev/chrisbanes/haze/testutils/UiAutomator.kt +++ b/internal/benchmark/src/main/kotlin/dev/chrisbanes/haze/testutils/UiAutomator.kt @@ -3,13 +3,14 @@ package dev.chrisbanes.haze.testutils -import android.graphics.Point import androidx.test.uiautomator.By import androidx.test.uiautomator.BySelector +import androidx.test.uiautomator.Direction import androidx.test.uiautomator.SearchCondition import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.UiObject2 import androidx.test.uiautomator.Until +import kotlin.math.roundToInt import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds @@ -70,13 +71,30 @@ internal fun UiDevice.navigateToCreditCard() { waitForIdle() } -internal fun UiDevice.scroll(tag: String, scrolls: Int = 5) { - val grid = waitForObject(By.res(tag)) - // Set gesture margin to avoid triggering gesture navigation +internal fun UiDevice.repeatedScrolls( + tag: String, + startDirection: Direction = Direction.DOWN, + repetitions: Int = 4, +) { + val node = waitForObject(By.res(tag)) + // Set gesture margins to avoid triggering gesture navigation // with input events from automation. - grid.setGestureMargin(displayWidth / 5) - // Scroll down several times - repeat(scrolls) { - grid.drag(Point(grid.visibleCenter.x, grid.visibleBounds.top)) + val horiz = (displayWidth / 6f).roundToInt() + val vert = (displayHeight / 8f).roundToInt() + node.setGestureMargins(horiz, vert, horiz, vert) + // Scroll up + down several times + repeat(repetitions) { index -> + val direction = when { + index % 2 == 0 -> startDirection + else -> startDirection.opposite() + } + node.scroll(direction, 0.8f) } } + +private fun Direction.opposite(): Direction = when (this) { + Direction.LEFT -> Direction.RIGHT + Direction.RIGHT -> Direction.LEFT + Direction.DOWN -> Direction.UP + else -> Direction.DOWN +} diff --git a/sample/shared/src/androidMain/kotlin/dev/chrisbanes/haze/sample/Platform.android.kt b/sample/shared/src/androidMain/kotlin/dev/chrisbanes/haze/sample/Platform.android.kt new file mode 100644 index 00000000..29cb069a --- /dev/null +++ b/sample/shared/src/androidMain/kotlin/dev/chrisbanes/haze/sample/Platform.android.kt @@ -0,0 +1,10 @@ +// Copyright 2024, Christopher Banes and the Haze project contributors +// SPDX-License-Identifier: Apache-2.0 + +package dev.chrisbanes.haze.sample + +import coil3.PlatformContext +import okio.Path +import okio.Path.Companion.toOkioPath + +actual fun PlatformContext.cacheDirPath(): Path? = this.cacheDir.toOkioPath() diff --git a/sample/shared/src/commonMain/kotlin/dev/chrisbanes/haze/sample/Platform.kt b/sample/shared/src/commonMain/kotlin/dev/chrisbanes/haze/sample/Platform.kt new file mode 100644 index 00000000..ea0c9e65 --- /dev/null +++ b/sample/shared/src/commonMain/kotlin/dev/chrisbanes/haze/sample/Platform.kt @@ -0,0 +1,9 @@ +// Copyright 2024, Christopher Banes and the Haze project contributors +// SPDX-License-Identifier: Apache-2.0 + +package dev.chrisbanes.haze.sample + +import coil3.PlatformContext +import okio.Path + +expect fun PlatformContext.cacheDirPath(): Path? diff --git a/sample/shared/src/commonMain/kotlin/dev/chrisbanes/haze/sample/Samples.kt b/sample/shared/src/commonMain/kotlin/dev/chrisbanes/haze/sample/Samples.kt index 6ed8cffb..9b846034 100644 --- a/sample/shared/src/commonMain/kotlin/dev/chrisbanes/haze/sample/Samples.kt +++ b/sample/shared/src/commonMain/kotlin/dev/chrisbanes/haze/sample/Samples.kt @@ -30,8 +30,12 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag +import coil3.ImageLoader import coil3.SingletonImageLoader import coil3.compose.LocalPlatformContext +import coil3.compose.setSingletonImageLoaderFactory +import coil3.disk.DiskCache +import coil3.memory.MemoryCache import coil3.request.ImageRequest import dev.chrisbanes.haze.HazeInputScale @@ -76,6 +80,34 @@ fun Samples( appTitle: String, samples: List = Samples, ) { + setSingletonImageLoaderFactory { context -> + ImageLoader.Builder(context) + .memoryCache { + MemoryCache.Builder() + .maxSizePercent(context, 0.2) + .build() + } + .diskCache { + context.cacheDirPath()?.let { cacheDirPath -> + DiskCache.Builder() + .directory(cacheDirPath.resolve("image_cache")) + .maximumMaxSizeBytes(32 * 1024 * 1024) + .build() + } + } + .build() + } + + val coilPlatformContext = LocalPlatformContext.current + LaunchedEffect(coilPlatformContext) { + // Preload the first 20 precanned image urls + val imageLoader = SingletonImageLoader.get(coilPlatformContext) + precannedImageUrls + .asSequence() + .map { ImageRequest.Builder(coilPlatformContext).data(it).build() } + .forEach { imageLoader.enqueue(it) } + } + SamplesTheme { var currentSample by remember { mutableStateOf(null) } @@ -83,16 +115,6 @@ fun Samples( Navigator { currentSample = null } } - val coilPlatformContext = LocalPlatformContext.current - LaunchedEffect(coilPlatformContext) { - // Preload the first 20 precanned image urls - val imageLoader = SingletonImageLoader.get(coilPlatformContext) - precannedImageUrls - .asSequence() - .map { ImageRequest.Builder(coilPlatformContext).data(it).build() } - .forEach { imageLoader.enqueue(it) } - } - Crossfade( targetState = currentSample, modifier = Modifier.testTagsAsResourceId(true), diff --git a/sample/shared/src/commonMain/kotlin/dev/chrisbanes/haze/sample/ScaffoldSample.kt b/sample/shared/src/commonMain/kotlin/dev/chrisbanes/haze/sample/ScaffoldSample.kt index 1dcb14a5..8f67b191 100644 --- a/sample/shared/src/commonMain/kotlin/dev/chrisbanes/haze/sample/ScaffoldSample.kt +++ b/sample/shared/src/commonMain/kotlin/dev/chrisbanes/haze/sample/ScaffoldSample.kt @@ -39,6 +39,7 @@ import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.dp +import dev.chrisbanes.haze.ExperimentalHazeApi import dev.chrisbanes.haze.HazeInputScale import dev.chrisbanes.haze.HazeProgressive import dev.chrisbanes.haze.HazeState @@ -53,7 +54,11 @@ enum class ScaffoldSampleMode { Mask, } -@OptIn(ExperimentalMaterial3Api::class, ExperimentalHazeMaterialsApi::class) +@OptIn( + ExperimentalMaterial3Api::class, + ExperimentalHazeMaterialsApi::class, + ExperimentalHazeApi::class, +) @Composable fun ScaffoldSample( navigator: Navigator, @@ -112,7 +117,7 @@ fun ScaffoldSample( exit = slideOutVertically { it }, ) { SampleNavigationBar( - selectedIndex, + selectedIndex = selectedIndex, onItemClicked = { selectedIndex = it }, modifier = Modifier .hazeChild(state = hazeState, style = style) { diff --git a/sample/shared/src/iosMain/kotlin/dev/chrisbanes/haze/sample/Platform.ios.kt b/sample/shared/src/iosMain/kotlin/dev/chrisbanes/haze/sample/Platform.ios.kt new file mode 100644 index 00000000..50434173 --- /dev/null +++ b/sample/shared/src/iosMain/kotlin/dev/chrisbanes/haze/sample/Platform.ios.kt @@ -0,0 +1,9 @@ +// Copyright 2024, Christopher Banes and the Haze project contributors +// SPDX-License-Identifier: Apache-2.0 + +package dev.chrisbanes.haze.sample + +import coil3.PlatformContext +import okio.Path + +actual fun PlatformContext.cacheDirPath(): Path? = null diff --git a/sample/shared/src/jsMain/kotlin/dev/chrisbanes/haze/sample/Platform.js.kt b/sample/shared/src/jsMain/kotlin/dev/chrisbanes/haze/sample/Platform.js.kt new file mode 100644 index 00000000..50434173 --- /dev/null +++ b/sample/shared/src/jsMain/kotlin/dev/chrisbanes/haze/sample/Platform.js.kt @@ -0,0 +1,9 @@ +// Copyright 2024, Christopher Banes and the Haze project contributors +// SPDX-License-Identifier: Apache-2.0 + +package dev.chrisbanes.haze.sample + +import coil3.PlatformContext +import okio.Path + +actual fun PlatformContext.cacheDirPath(): Path? = null diff --git a/sample/shared/src/jvmMain/kotlin/dev/chrisbanes/haze/sample/Platform.jvm.kt b/sample/shared/src/jvmMain/kotlin/dev/chrisbanes/haze/sample/Platform.jvm.kt new file mode 100644 index 00000000..50434173 --- /dev/null +++ b/sample/shared/src/jvmMain/kotlin/dev/chrisbanes/haze/sample/Platform.jvm.kt @@ -0,0 +1,9 @@ +// Copyright 2024, Christopher Banes and the Haze project contributors +// SPDX-License-Identifier: Apache-2.0 + +package dev.chrisbanes.haze.sample + +import coil3.PlatformContext +import okio.Path + +actual fun PlatformContext.cacheDirPath(): Path? = null diff --git a/sample/shared/src/wasmJsMain/kotlin/dev/chrisbanes/haze/sample/Platform.wasmJs.kt b/sample/shared/src/wasmJsMain/kotlin/dev/chrisbanes/haze/sample/Platform.wasmJs.kt new file mode 100644 index 00000000..50434173 --- /dev/null +++ b/sample/shared/src/wasmJsMain/kotlin/dev/chrisbanes/haze/sample/Platform.wasmJs.kt @@ -0,0 +1,9 @@ +// Copyright 2024, Christopher Banes and the Haze project contributors +// SPDX-License-Identifier: Apache-2.0 + +package dev.chrisbanes.haze.sample + +import coil3.PlatformContext +import okio.Path + +actual fun PlatformContext.cacheDirPath(): Path? = null