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

Use objc2 v0.6 #1726

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
strategy:
fail-fast: false
matrix:
rust_version: [1.70.0, stable, nightly]
rust_version: [1.71.0, stable, nightly]
platform:
- { target: x86_64-pc-windows-msvc, os: windows-latest, }
- { target: i686-pc-windows-msvc, os: windows-latest, }
Expand All @@ -59,10 +59,10 @@ jobs:
- { target: x86_64-apple-darwin, os: macos-latest, }
exclude:
# Android is tested on stable-3
- rust_version: '1.70.0'
- rust_version: '1.71.0'
platform: { target: aarch64-linux-android, os: ubuntu-latest, cmd: 'apk --' }
include:
- rust_version: '1.70.0'
- rust_version: '1.71.0'
platform: { target: aarch64-linux-android, os: ubuntu-latest, cmd: 'apk --' }


Expand Down Expand Up @@ -117,6 +117,5 @@ jobs:

- name: Lint with clippy
shell: bash
if: (matrix.rust_version == '1.70.0') && !contains(matrix.platform.options, '--no-default-features')
if: (matrix.rust_version == '1.71.0') && !contains(matrix.platform.options, '--no-default-features')
run: cargo clippy --workspace --all-targets --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES -- -Dwarnings

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Unreleased

- **Breaking:** Added `make_current_surfaceless(self)` for `{Possibly,Not}CurrentGlContext`.
- Bump MSRV from `1.70` to `1.71`.
- Updated `objc2` dependency to `v0.6`.

# Version 0.32.2

Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ members = [
"glutin_wgl_sys",
"glutin_gles2_sys",
]

[workspace.package]
# MSRV. Also update in ci.yml
rust-version = "1.71.0"
2 changes: 1 addition & 1 deletion glutin-winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT"
readme = "README.md"
repository = "https://github.com/rust-windowing/glutin"
edition = "2021"
rust-version = "1.70.0"
rust-version.workspace = true

[features]
default = ["egl", "glx", "x11", "wayland", "wgl"]
Expand Down
40 changes: 24 additions & 16 deletions glutin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/rust-windowing/glutin"
documentation = "https://docs.rs/glutin"
rust-version = "1.70.0"
rust-version.workspace = true
edition = "2021"

[features]
Expand Down Expand Up @@ -46,33 +46,41 @@ glutin_egl_sys = { version = "0.7.1", path = "../glutin_egl_sys" }
[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
glutin_egl_sys = { version = "0.7.1", path = "../glutin_egl_sys", optional = true }
glutin_glx_sys = { version = "0.6.1", path = "../glutin_glx_sys", optional = true }
wayland-sys = { version = "0.31.1", default-features = false, features = ["egl", "client", "dlopen"], optional = true }
wayland-sys = { version = "0.31.1", default-features = false, features = [
"egl",
"client",
"dlopen",
], optional = true }
x11-dl = { version = "2.20.0", optional = true }

[target.'cfg(any(target_os = "macos"))'.dependencies]
cgl = "0.3.2"
core-foundation = "0.9.3"
objc2 = "0.5.1"
dispatch = "0.2.0"

[target.'cfg(any(target_os = "macos"))'.dependencies.objc2-foundation]
version = "0.2.0"
features = [
"dispatch",
dispatch2 = { version = "0.2.0", default-features = false, features = [
"std",
"objc2",
] }
objc2 = "0.6.0"
objc2-core-foundation = { version = "0.3.0", default-features = false, features = [
"std",
"CFBase",
"CFString",
"CFBundle",
] }
objc2-foundation = { version = "0.3.0", default-features = false, features = [
"std",
"NSArray",
"NSThread",
]

[target.'cfg(any(target_os = "macos"))'.dependencies.objc2-app-kit]
version = "0.2.0"
features = [
] }
objc2-app-kit = { version = "0.3.0", default-features = false, features = [
"std",
"objc2-core-foundation",
"NSApplication",
"NSResponder",
"NSView",
"NSWindow",
"NSOpenGL",
"NSOpenGLView",
]
] }

[build-dependencies]
cfg_aliases = "0.2.1"
Expand Down
80 changes: 34 additions & 46 deletions glutin/src/api/cgl/appkit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#![allow(non_snake_case)]

use objc2::encode::{Encoding, RefEncode};
use objc2::rc::{Allocated, Id};
use objc2::{extern_class, extern_methods, mutability, ClassType};
use objc2::rc::{Allocated, Retained};
use objc2::{extern_class, extern_methods, AllocAnyThread, MainThreadMarker};
#[allow(deprecated)]
use objc2_app_kit::{NSOpenGLContextParameter, NSOpenGLPixelFormatAttribute, NSView};
use objc2_foundation::{MainThreadMarker, NSObject};
use objc2_foundation::NSObject;

pub type GLint = i32;

Expand All @@ -21,98 +21,86 @@ unsafe impl RefEncode for CGLContextObj {
}

extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub(crate) struct NSOpenGLContext;

// Strict order required by macro, tracked in https://github.com/madsmtm/objc2/issues/479
#[rustfmt::skip]
unsafe impl ClassType for NSOpenGLContext {
type Super = NSObject;
type Mutability = mutability::InteriorMutable;
}
);

unsafe impl Send for NSOpenGLContext {}
unsafe impl Sync for NSOpenGLContext {}

extern_methods!(
unsafe impl NSOpenGLContext {
#[method_id(currentContext)]
pub(crate) fn currentContext() -> Option<Id<Self>>;
impl NSOpenGLContext {
extern_methods!(
#[unsafe(method(currentContext))]
pub(crate) fn currentContext() -> Option<Retained<Self>>;

#[method_id(initWithFormat:shareContext:)]
#[unsafe(method(initWithFormat:shareContext:))]
pub(crate) fn initWithFormat_shareContext(
this: Allocated<Self>,
format: &NSOpenGLPixelFormat,
share: Option<&NSOpenGLContext>,
) -> Option<Id<Self>>;
) -> Option<Retained<Self>>;

#[method(clearCurrentContext)]
#[unsafe(method(clearCurrentContext))]
pub(crate) fn clearCurrentContext();

#[method(makeCurrentContext)]
#[unsafe(method(makeCurrentContext))]
pub(crate) fn makeCurrentContext(&self);

#[method(update)]
#[unsafe(method(update))]
pub(crate) fn update(&self);

#[method(flushBuffer)]
#[unsafe(method(flushBuffer))]
pub(crate) fn flushBuffer(&self);

#[method_id(view)]
pub(crate) fn view(&self, mtm: MainThreadMarker) -> Option<Id<NSView>>;
#[unsafe(method(view))]
pub(crate) fn view(&self, mtm: MainThreadMarker) -> Option<Retained<NSView>>;

#[method(setView:)]
#[unsafe(method(setView:))]
pub(crate) unsafe fn setView(&self, view: Option<&NSView>);

#[allow(deprecated)]
#[method(setValues:forParameter:)]
#[unsafe(method(setValues:forParameter:))]
pub(crate) unsafe fn setValues_forParameter(
&self,
vals: *const GLint,
param: NSOpenGLContextParameter,
);

#[method(CGLContextObj)]
#[unsafe(method(CGLContextObj))]
pub(crate) fn CGLContextObj(&self) -> *mut CGLContextObj;
}
);
);
}

extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub(crate) struct NSOpenGLPixelFormat;

// Strict order required by macro, tracked in https://github.com/madsmtm/objc2/issues/479
#[rustfmt::skip]
unsafe impl ClassType for NSOpenGLPixelFormat {
type Super = NSObject;
type Mutability = mutability::Immutable;
}
);

unsafe impl Send for NSOpenGLPixelFormat {}
unsafe impl Sync for NSOpenGLPixelFormat {}

extern_methods!(
unsafe impl NSOpenGLPixelFormat {
#[method_id(initWithAttributes:)]
impl NSOpenGLPixelFormat {
extern_methods!(
#[unsafe(method(initWithAttributes:))]
unsafe fn initWithAttributes(
this: Allocated<Self>,
attrs: *const NSOpenGLPixelFormatAttribute,
) -> Option<Id<Self>>;

pub(crate) unsafe fn newWithAttributes(
attrs: &[NSOpenGLPixelFormatAttribute],
) -> Option<Id<Self>> {
unsafe { Self::initWithAttributes(Self::alloc(), attrs.as_ptr()) }
}
) -> Option<Retained<Self>>;

#[method(getValues:forAttribute:forVirtualScreen:)]
#[unsafe(method(getValues:forAttribute:forVirtualScreen:))]
pub(crate) unsafe fn getValues_forAttribute_forVirtualScreen(
&self,
vals: *mut GLint,
param: NSOpenGLPixelFormatAttribute,
screen: GLint,
);
);

pub(crate) unsafe fn newWithAttributes(
attrs: &[NSOpenGLPixelFormatAttribute],
) -> Option<Retained<Self>> {
unsafe { Self::initWithAttributes(Self::alloc(), attrs.as_ptr()) }
}
);
}
6 changes: 3 additions & 3 deletions glutin/src/api/cgl/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::sync::Arc;
use std::{fmt, iter};

use objc2::rc::Id;
use objc2::rc::Retained;
#[allow(deprecated)]
use objc2_app_kit::{
NSOpenGLPFAAccelerated, NSOpenGLPFAAllowOfflineRenderers, NSOpenGLPFAAlphaSize,
Expand Down Expand Up @@ -219,7 +219,7 @@ impl GetGlDisplay for Config {

impl AsRawConfig for Config {
fn raw_config(&self) -> RawConfig {
RawConfig::Cgl(Id::as_ptr(&self.inner.raw).cast())
RawConfig::Cgl(Retained::as_ptr(&self.inner.raw).cast())
}
}

Expand All @@ -228,7 +228,7 @@ impl Sealed for Config {}
pub(crate) struct ConfigInner {
display: Display,
pub(crate) transparency: bool,
pub(crate) raw: Id<NSOpenGLPixelFormat>,
pub(crate) raw: Retained<NSOpenGLPixelFormat>,
}

impl PartialEq for ConfigInner {
Expand Down
14 changes: 7 additions & 7 deletions glutin/src/api/cgl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use std::fmt;
use std::marker::PhantomData;

use cgl::CGLSetParameter;
use objc2::rc::{autoreleasepool, Id};
use objc2::ClassType;
use dispatch2::{run_on_main, MainThreadBound};
use objc2::rc::{autoreleasepool, Retained};
use objc2::AllocAnyThread;
use objc2_app_kit::{NSOpenGLCPSwapInterval, NSView};
use objc2_foundation::{run_on_main, MainThreadBound};

use crate::config::GetGlConfig;
use crate::context::{
Expand Down Expand Up @@ -139,7 +139,7 @@ impl GetGlDisplay for NotCurrentContext {

impl AsRawContext for NotCurrentContext {
fn raw_context(&self) -> RawContext {
RawContext::Cgl(Id::as_ptr(&self.inner.raw).cast())
RawContext::Cgl(Retained::as_ptr(&self.inner.raw).cast())
}
}

Expand Down Expand Up @@ -220,7 +220,7 @@ impl GetGlDisplay for PossiblyCurrentContext {

impl AsRawContext for PossiblyCurrentContext {
fn raw_context(&self) -> RawContext {
RawContext::Cgl(Id::as_ptr(&self.inner.raw).cast())
RawContext::Cgl(Retained::as_ptr(&self.inner.raw).cast())
}
}

Expand All @@ -229,7 +229,7 @@ impl Sealed for PossiblyCurrentContext {}
pub(crate) struct ContextInner {
display: Display,
config: Config,
pub(crate) raw: Id<NSOpenGLContext>,
pub(crate) raw: Retained<NSOpenGLContext>,
}

impl ContextInner {
Expand Down Expand Up @@ -294,7 +294,7 @@ impl ContextInner {
})
}

pub(crate) fn is_view_current(&self, view: &MainThreadBound<Id<NSView>>) -> bool {
pub(crate) fn is_view_current(&self, view: &MainThreadBound<Retained<NSView>>) -> bool {
run_on_main(|mtm| {
self.raw.view(mtm).expect("context to have a current view") == *view.get(mtm)
})
Expand Down
14 changes: 7 additions & 7 deletions glutin/src/api/cgl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use std::ffi::{self, CStr};
use std::marker::PhantomData;

use core_foundation::base::TCFType;
use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName};
use core_foundation::string::CFString;
use objc2_core_foundation::{
CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName, CFString,
};
use raw_window_handle::RawDisplayHandle;

use crate::config::ConfigTemplate;
Expand Down Expand Up @@ -87,11 +87,11 @@ impl GlDisplay for Display {
}

fn get_proc_address(&self, addr: &CStr) -> *const ffi::c_void {
let symbol_name = CFString::new(addr.to_str().unwrap());
let framework_name = CFString::new("com.apple.opengl");
let symbol_name = CFString::from_str(addr.to_str().unwrap());
let framework_name = CFString::from_static_str("com.apple.opengl");
unsafe {
let framework = CFBundleGetBundleWithIdentifier(framework_name.as_concrete_TypeRef());
CFBundleGetFunctionPointerForName(framework, symbol_name.as_concrete_TypeRef()).cast()
let framework = CFBundleGetBundleWithIdentifier(Some(&framework_name)).unwrap();
CFBundleGetFunctionPointerForName(&framework, Some(&symbol_name))
}
}

Expand Down
Loading
Loading