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

Transparency support for D3D swap chain #837

Merged
merged 3 commits into from Dec 12, 2023

Conversation

MatkovIvan
Copy link
Member

@MatkovIvan MatkovIvan commented Dec 5, 2023

@MatkovIvan MatkovIvan force-pushed the ivan.matkov/transparency-support-d3d branch from bdf8985 to 6dee5e9 Compare December 6, 2023 11:02
Copy link
Collaborator

@eymar eymar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested in compose on my Windows 11 - works as expected

skiko/src/jvmMain/cpp/common/stubs.cc Show resolved Hide resolved
Copy link
Collaborator

@igordmn igordmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works in SkiaAwtSample if we set window.background = Color(0, 0, 0, 0), but now we have an issue with input handling - click events aren't consumed by the window:

java_8bL7QWkN6K.mp4

We should fix event handling before merging it.

@MatkovIvan
Copy link
Member Author

MatkovIvan commented Dec 12, 2023

if we set window.background = Color(0, 0, 0, 0), but now we have an issue with input handling - click events aren't consumed by the window

As was always before, and for all other renderer API on Windows. I wrote comment with explanation here: #915: ComposeWindowDelegate.desktop.kt R112-R120

/*
 * Windows makes clicks on transparent pixels fall through, but it doesn't work
 * with GPU accelerated rendering since this check requires having access to pixels from CPU.

My position here is to DROP DwmEnableBlurBehindWindow hack from other renderers like OpenGL to avoid setting window parameters by skiko view. But it's a separate story

@MatkovIvan MatkovIvan merged commit 5a29cb5 into master Dec 12, 2023
5 checks passed
@MatkovIvan MatkovIvan deleted the ivan.matkov/transparency-support-d3d branch December 12, 2023 15:38
MatkovIvan added a commit to JetBrains/compose-multiplatform-core that referenced this pull request Dec 15, 2023
## Proposed Changes

- Adopt an approach that we're using for iOS - using custom blending to
respect clip/shape modifiers and overlapped drawings.
- Fix bounds in window calculation - it should work properly inside
scaled content now.

## Testing

The new behavior is under a feature flag, so you can test it by setting
system property:

```kt
System.setProperty("compose.interop.blending", "true")
```

Currently it supports Metal (macOS), Direct3D (Windows) (requires
JetBrains/skiko#837), and off-screen rendering
(might be enable by another feature flag:
`compose.swing.render.on.graphics`)

### Clipping

```kt
SwingPanel(
    modifier = Modifier.clip(RoundedCornerShape(6.dp))
    ...
)
```
<img width="262" alt="image"
src="https://github.com/JetBrains/compose-multiplatform-core/assets/1836384/a03926f5-8977-4530-8894-d84aedfd5939">

### Overlapping

```kt
Box(modifier = Modifier.fillMaxSize()) {
    SwingPanel(factory = {
        JPanel().also { panel ->
            panel.background = java.awt.Color.red
            panel.add(JButton().also { button ->
                button.text = "JButton"
            })
        }
    })
    Snackbar(
        action = { Button(onClick = {}) { Text("OK") } },
        modifier = Modifier.padding(8.dp).align(Alignment.BottomCenter),
    ) {
        Text("Snackbar")
    }
    Popup(alignment = Alignment.Center) {
        Box(
            modifier = Modifier.size(200.dp, 100.dp).background(Gray),
            contentAlignment = Alignment.Center,
        ) {

            Text("Popup")
        }

    }
}
```
<img width="592" alt="Screenshot 2023-11-27 at 13 57 43"
src="https://github.com/JetBrains/compose-multiplatform-core/assets/1836384/dda1f2d6-6a1e-456c-8763-46a82d9562a8">


## Issues Fixed

Fixes JetBrains/compose-multiplatform#3823
Fixes JetBrains/compose-multiplatform#3739
Fixes JetBrains/compose-multiplatform#3353
Fixes JetBrains/compose-multiplatform#3474
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to create DirectX12 device when transparent = true
3 participants