-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add constructor with RenderSettings
to ComposePanel
#1377
Changes from all commits
dee558d
22022fa
fc70078
1b08c88
eaa47d4
6fce56e
d242e85
96182de
b25b1a8
12b8b9e
6decc01
b76273e
68d5c9f
561d418
66445e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package androidx.compose.ui.awt | ||
|
||
import androidx.compose.ui.ExperimentalComposeUiApi | ||
import androidx.compose.ui.ComposeFeatureFlags | ||
import org.jetbrains.skiko.SkikoProperties | ||
|
||
/** | ||
* Configuration class for rendering settings. | ||
* | ||
* @property isVsyncEnabled Indicates whether presentation vsync is enabled or not | ||
* When true, the internal implementation will attempt to synchronize drawable presentations | ||
* with vsync. It guarantees that the frame is presented without visual artifacts like tearing in | ||
* exchange for a latency increase. | ||
* When false, the internal implementation will not attempt to synchronize drawable presentations | ||
* it can reduce latency but may introduce visual artifacts like screen tearing. | ||
* When null, the internal implementation will use the global configuration from [SkikoProperties.vsyncEnabled] | ||
* | ||
* This flag has no effect if [ComposeFeatureFlags.useSwingGraphics] is true. In this case Compose | ||
* will render the content to Swing provided offscreen buffer and the presentation will be controlled | ||
* by Swing. | ||
*/ | ||
@ExperimentalComposeUiApi | ||
class RenderSettings( | ||
val isVsyncEnabled: Boolean? | ||
) { | ||
companion object { | ||
/** | ||
* Default rendering settings | ||
*/ | ||
val Default = RenderSettings( | ||
isVsyncEnabled = null | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ import androidx.compose.ui.LayerType | |
import androidx.compose.ui.awt.AwtEventFilter | ||
import androidx.compose.ui.awt.AwtEventListener | ||
import androidx.compose.ui.awt.AwtEventListeners | ||
import androidx.compose.ui.awt.RenderSettings | ||
import androidx.compose.ui.input.key.KeyEvent | ||
import androidx.compose.ui.platform.LocalLifecycleOwner | ||
import androidx.compose.ui.platform.LocalInternalViewModelStoreOwner | ||
|
@@ -78,6 +79,7 @@ import org.jetbrains.skiko.SkiaLayerAnalytics | |
* for window coordinate space. | ||
* @property useSwingGraphics Flag indicating if offscreen rendering to Swing graphics is used. | ||
* @property layerType The type of layer used for Popup/Dialog. | ||
* @property renderSettings The settings for rendering. | ||
*/ | ||
internal class ComposeContainer( | ||
val container: JLayeredPane, | ||
|
@@ -88,6 +90,7 @@ internal class ComposeContainer( | |
|
||
private val useSwingGraphics: Boolean = ComposeFeatureFlags.useSwingGraphics, | ||
private val layerType: LayerType = ComposeFeatureFlags.layerType, | ||
private val renderSettings: RenderSettings, | ||
) : WindowFocusListener, WindowListener, LifecycleOwner, ViewModelStoreOwner { | ||
val windowContext = PlatformWindowContext() | ||
var window: Window? = null | ||
|
@@ -338,7 +341,13 @@ internal class ComposeContainer( | |
return if (useSwingGraphics) { | ||
SwingSkiaLayerComponent(mediator, renderDelegate, skiaLayerAnalytics) | ||
} else { | ||
WindowSkiaLayerComponent(mediator, windowContext, renderDelegate, skiaLayerAnalytics) | ||
WindowSkiaLayerComponent( | ||
mediator, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add explicit parameter names if it's not one-liner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we add them when variables match parameter names or are obvious? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to add it to be on the safe side during possible refactoring |
||
windowContext, | ||
renderDelegate, | ||
skiaLayerAnalytics, | ||
renderSettings | ||
) | ||
} | ||
} | ||
|
||
|
@@ -381,7 +390,8 @@ internal class ComposeContainer( | |
density = density, | ||
layoutDirection = layoutDirection, | ||
focusable = focusable, | ||
compositionContext = compositionContext | ||
compositionContext = compositionContext, | ||
renderSettings = renderSettings | ||
) | ||
LayerType.OnComponent -> SwingComposeSceneLayer( | ||
composeContainer = this, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better/cleaner to put this in a (fake) enum, e.g.
VSyncMode.Enabled
,VSyncMode.Disabled
, andVsyncMode.Default
. Although maybe it's overkill here; not sure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd leave it as it is now (ExperimentalAPI after all), I haven't yet performed an investigation about different presentation modes on non-Metal rendering backends.