Skip to content
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 dedicated feature flags class for desktop #945

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2023 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

import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.Popup

/**
* The helper singleton object that provides the access to feature flags that
* configure Compose behaviour.
*/
internal object ComposeFeatureFlags {
/**
* Indicates whether the Compose should use Swing graphics for rendering.
* This prevents transitional rendering issues when panels are being shown, hidden, or resized.
* It also enables proper layering when combining Swing components and compose panels.
*
* Please note that it requires additional copy from offscreen texture to Swing graphics,
* so it has some performance penalty.
*/
val useSwingGraphics: Boolean
get() = System.getProperty("compose.swing.render.on.graphics").toBoolean()

/**
* Indicates whether interop blending is enabled.
* It allows drawing compose elements above interop and apply clip/shape modifiers to it.
*
* Note that it currently works only with Metal, DirectX and offscreen rendering.
*/
val useInteropBlending: Boolean
get() = System.getProperty("compose.interop.blending").toBoolean()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package androidx.compose.ui.awt

import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.ComposeFeatureFlags
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.window.WindowExceptionHandler
Expand Down Expand Up @@ -200,13 +201,9 @@ class ComposePanel @ExperimentalComposeUiApi constructor(
private val componentLayer: Int
get() = if (interopBlending) 0 else 20

private val renderOnGraphics: Boolean
get() = System.getProperty("compose.swing.render.on.graphics").toBoolean()
private val _interopBlending: Boolean
get() = System.getProperty("compose.interop.blending").toBoolean()
private val interopBlending: Boolean
get() = _interopBlending &&
(renderOnGraphics || requireNotNull(bridge).interopBlendingSupported)
get() = ComposeFeatureFlags.useInteropBlending &&
(ComposeFeatureFlags.useSwingGraphics || requireNotNull(bridge).interopBlendingSupported)

override fun addNotify() {
super.addNotify()
Expand All @@ -223,7 +220,7 @@ class ComposePanel @ExperimentalComposeUiApi constructor(
}

private fun createComposeBridge(): ComposeBridge {
val bridge: ComposeBridge = if (renderOnGraphics) {
val bridge: ComposeBridge = if (ComposeFeatureFlags.useSwingGraphics) {
SwingComposeBridge(skiaLayerAnalytics, layoutDirectionFor(this))
} else {
WindowComposeBridge(skiaLayerAnalytics, layoutDirectionFor(this))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package androidx.compose.ui.awt
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalContext
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.ComposeFeatureFlags
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.KeyEvent
Expand Down Expand Up @@ -93,10 +94,8 @@ internal class ComposeWindowDelegate(
val renderApi: GraphicsApi
get() = bridge.renderApi

private val _interopBlending: Boolean
get() = System.getProperty("compose.interop.blending").toBoolean()
private val interopBlending: Boolean
get() = _interopBlending && bridge.interopBlendingSupported
get() = ComposeFeatureFlags.useInteropBlending && bridge.interopBlendingSupported

var isWindowTransparent: Boolean = false
set(value) {
Expand Down