-
Notifications
You must be signed in to change notification settings - Fork 51
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 connector_id to DrmWindowHandle #170
base: master
Are you sure you want to change the base?
Changes from all commits
b598cf5
332ee85
2c43a16
017263b
1eb46ad
e51370e
10eb23b
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -239,6 +239,8 @@ impl DrmDisplayHandle { | |||||||||
pub struct DrmWindowHandle { | ||||||||||
/// The primary drm plane handle. | ||||||||||
pub plane: u32, | ||||||||||
/// An optional handle to chosen drm connector | ||||||||||
pub connector_id: Option<NonZeroU32>, | ||||||||||
} | ||||||||||
|
||||||||||
impl DrmWindowHandle { | ||||||||||
|
@@ -255,7 +257,32 @@ impl DrmWindowHandle { | |||||||||
/// let handle = DrmWindowHandle::new(plane); | ||||||||||
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. Please update this example to also set the 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. What I mean here is something like:
Suggested change
|
||||||||||
/// ``` | ||||||||||
pub fn new(plane: u32) -> Self { | ||||||||||
Self { plane } | ||||||||||
Self { | ||||||||||
plane, | ||||||||||
connector_id: None, | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/// Create a new handle to a plane and associated connector_id. | ||||||||||
/// | ||||||||||
/// | ||||||||||
/// # Example | ||||||||||
/// | ||||||||||
/// ``` | ||||||||||
/// # use raw_window_handle::DrmWindowHandle; | ||||||||||
/// # use core::num::NonZeroU32; | ||||||||||
/// # | ||||||||||
/// let plane: u32; | ||||||||||
/// # plane = 0; | ||||||||||
/// let connector_id: NonZeroU32; | ||||||||||
/// # connector_id = unsafe { NonZeroU32::new_unchecked(1) }; | ||||||||||
/// let handle = DrmWindowHandle::new_with_connector_id(plane, connector_id); | ||||||||||
/// ``` | ||||||||||
pub fn new_with_connector_id(plane: u32, connector_id: NonZeroU32) -> Self { | ||||||||||
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. Nit: This doesn't really match what's exposed for the other platforms, there, the user would just do: let mut handle = DrmWindowHandle::new(...);
handle.connector_id = Some(...); But perhaps this approach is indeed better? In any case, might make sense to not do such a change in this PR, as it's somewhat inconsistent with the other platforms. 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. Using the Implementing these constructors will not compromise backwards compatibility, as the only scenario requiring their removal would be the elimination of the corresponding fields. In such a case, a breaking change would be inevitable regardless. 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. Furthermore, implementing a separate constructor prevents unnecessary mutability of the created handle, which typically does not require any kind of modification. 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. I'm generally against constructors like that in this crate because they are prone to factorial growth. So if you want to add one more optional field you'd need to add permutations, since you don't generally require all the things to be present. Unless you just stuck constructors with I'm also not that much in love with 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. The primary justification for introducing a new constructor is that it is not feasible to manually instantiate a handle due to the struct being marked as non_exhaustive. This is not merely a matter of convenience or shorthand. Structs marked as non_exhaustive cannot be instantiated outside of their originating crate. A dedicated function to construct one is mandatory. 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.
The proper solution would be to only have one constructor that takes all the parameters but that would break backwards compatibility and require a version bump. My understanding was that we should avoid that if possible. 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. The connector is optional though, since not all APIs require it and some APIs may require a list of connectors. 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.
Which perfectly translates into the new constructor. A new constructor like this would only be necessary for an optional field. I am also not aware of any API that requires a least of connectors that would also consume a window handle. Do you have any examples? If that's the case then maybe the signature of field should be reconsidered. My main use case for this is implementing a drm backend for wgpu which afaik would require only a specific connector, at least for the vulkan backend. 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.
I know that In general I won't block on adding a constructor, it's just I don't really like it, though, I'm not sure there will be more fields to add. 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. I'd like @Lokathor's opinion - but as stated in my first comment, this is very much nitpicking ;) |
||||||||||
Self { | ||||||||||
plane, | ||||||||||
connector_id: Some(connector_id), | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
|
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.
Should document what is it.
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.
Also ideally with links to other documentation explaining it, if such docs exist.