Use a transparent layer for status bar

This allows the compositor to blend the GPUI view with the background.
This commit is contained in:
Antonio Scandurra 2022-09-13 14:05:50 +02:00
parent a9c2881831
commit 11d47f5c72
3 changed files with 8 additions and 6 deletions

View File

@ -10,14 +10,14 @@ use crate::{
}; };
use cocoa::{ use cocoa::{
base::{NO, YES}, base::{NO, YES},
foundation::{NSRect, NSUInteger}, foundation::NSUInteger,
quartzcore::AutoresizingMask, quartzcore::AutoresizingMask,
}; };
use core_foundation::base::TCFType; use core_foundation::base::TCFType;
use foreign_types::ForeignTypeRef; use foreign_types::ForeignTypeRef;
use log::warn; use log::warn;
use media::core_video::{self, CVMetalTextureCache}; use media::core_video::{self, CVMetalTextureCache};
use metal::{CGFloat, CommandQueue, MTLPixelFormat, MTLResourceOptions, NSRange}; use metal::{CommandQueue, MTLPixelFormat, MTLResourceOptions, NSRange};
use objc::{self, msg_send, sel, sel_impl}; use objc::{self, msg_send, sel, sel_impl};
use shaders::ToFloat2 as _; use shaders::ToFloat2 as _;
use std::{collections::HashMap, ffi::c_void, iter::Peekable, mem, ptr, sync::Arc, vec}; use std::{collections::HashMap, ffi::c_void, iter::Peekable, mem, ptr, sync::Arc, vec};
@ -55,7 +55,7 @@ pub struct Surface {
} }
impl Renderer { impl Renderer {
pub fn new(fonts: Arc<dyn platform::FontSystem>) -> Self { pub fn new(is_opaque: bool, fonts: Arc<dyn platform::FontSystem>) -> Self {
const PIXEL_FORMAT: MTLPixelFormat = MTLPixelFormat::BGRA8Unorm; const PIXEL_FORMAT: MTLPixelFormat = MTLPixelFormat::BGRA8Unorm;
let device: metal::Device = if let Some(device) = metal::Device::system_default() { let device: metal::Device = if let Some(device) = metal::Device::system_default() {
@ -69,6 +69,7 @@ impl Renderer {
layer.set_device(&device); layer.set_device(&device);
layer.set_pixel_format(PIXEL_FORMAT); layer.set_pixel_format(PIXEL_FORMAT);
layer.set_presents_with_transaction(true); layer.set_presents_with_transaction(true);
layer.set_opaque(is_opaque);
unsafe { unsafe {
let _: () = msg_send![&*layer, setAllowsNextDrawableTimeout: NO]; let _: () = msg_send![&*layer, setAllowsNextDrawableTimeout: NO];
let _: () = msg_send![&*layer, setNeedsDisplayOnBoundsChange: YES]; let _: () = msg_send![&*layer, setNeedsDisplayOnBoundsChange: YES];
@ -363,7 +364,8 @@ impl Renderer {
color_attachment.set_texture(Some(output)); color_attachment.set_texture(Some(output));
color_attachment.set_load_action(metal::MTLLoadAction::Clear); color_attachment.set_load_action(metal::MTLLoadAction::Clear);
color_attachment.set_store_action(metal::MTLStoreAction::Store); color_attachment.set_store_action(metal::MTLStoreAction::Store);
color_attachment.set_clear_color(metal::MTLClearColor::new(0., 0., 0., 1.)); let alpha = if self.layer.is_opaque() { 1. } else { 0. };
color_attachment.set_clear_color(metal::MTLClearColor::new(0., 0., 0., alpha));
let command_encoder = command_buffer.new_render_command_encoder(render_pass_descriptor); let command_encoder = command_buffer.new_render_command_encoder(render_pass_descriptor);
command_encoder.set_viewport(metal::MTLViewport { command_encoder.set_viewport(metal::MTLViewport {

View File

@ -65,7 +65,7 @@ struct StatusItemState {
impl StatusItem { impl StatusItem {
pub fn add(fonts: Arc<dyn FontSystem>) -> Self { pub fn add(fonts: Arc<dyn FontSystem>) -> Self {
unsafe { unsafe {
let renderer = Renderer::new(fonts); let renderer = Renderer::new(false, fonts);
let status_bar = NSStatusBar::systemStatusBar(nil); let status_bar = NSStatusBar::systemStatusBar(nil);
let native_item = let native_item =
StrongPtr::retain(status_bar.statusItemWithLength_(NSSquareStatusItemLength)); StrongPtr::retain(status_bar.statusItemWithLength_(NSSquareStatusItemLength));

View File

@ -382,7 +382,7 @@ impl Window {
synthetic_drag_counter: 0, synthetic_drag_counter: 0,
executor, executor,
scene_to_render: Default::default(), scene_to_render: Default::default(),
renderer: Renderer::new(fonts), renderer: Renderer::new(true, fonts),
last_fresh_keydown: None, last_fresh_keydown: None,
traffic_light_position: options traffic_light_position: options
.titlebar .titlebar