Skip to content

Commit 8ad40df

Browse files
committed
upgrade winapi bindings to 0.54
1 parent ce747f5 commit 8ad40df

File tree

5 files changed

+54
-69
lines changed

5 files changed

+54
-69
lines changed

Cargo.lock

Lines changed: 23 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zbl/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ name = "zbl"
1010
once_cell = "1"
1111

1212
[dependencies.windows]
13-
# TODO bumping the version brings on weird API which i'm not sure how to work with
14-
version = "0.43"
13+
version = "0.54"
1514
features = [
1615
"Foundation",
1716
"Graphics_Capture",

zbl/src/capture/window.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ extern "system" fn enum_windows_cb(window: HWND, state: LPARAM) -> BOOL {
8181
fn enumerate_capturable_windows() -> Vec<Window> {
8282
let state = Box::into_raw(Box::default());
8383
*unsafe {
84-
EnumWindows(Some(enum_windows_cb), LPARAM(state as isize));
84+
EnumWindows(Some(enum_windows_cb), LPARAM(state as isize)).expect("EnumWindows");
8585
Box::from_raw(state)
8686
}
8787
}
@@ -213,9 +213,9 @@ impl Capturable for Window {
213213
let mut client_rect = RECT::default();
214214
let mut top_left = POINT::default();
215215
unsafe {
216-
GetWindowRect(self.handle, &mut window_rect as *mut _);
216+
GetWindowRect(self.handle, &mut window_rect as *mut _).expect("GetWindowRect");
217217
ClientToScreen(self.handle, &mut top_left as *mut _);
218-
GetClientRect(self.handle, &mut client_rect as *mut _);
218+
GetClientRect(self.handle, &mut client_rect as *mut _).expect("GetWindowRect");
219219
}
220220

221221
let mut client_box = D3D11_BOX::default();

zbl/src/d3d.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ impl D3D {
5757
pub fn new() -> Result<Self> {
5858
let device = create_d3d_device()?;
5959
let context = unsafe {
60-
let mut d3d_context = None;
61-
device.GetImmediateContext(&mut d3d_context);
62-
d3d_context.expect("failed to create d3d_context")
60+
device
61+
.GetImmediateContext()
62+
.expect("D3D11 immediate context")
6363
};
6464
let direct3d_device = create_direct3d_device(&device)?;
6565
Ok(Self {

zbl/src/staging_texture.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use windows::{
22
core::{Interface, Result},
33
Win32::Graphics::{
44
Direct3D11::{
5-
ID3D11Device, ID3D11DeviceContext, ID3D11Resource, ID3D11Texture2D, D3D11_BIND_FLAG,
6-
D3D11_CPU_ACCESS_READ, D3D11_MAPPED_SUBRESOURCE, D3D11_MAP_READ,
7-
D3D11_RESOURCE_MISC_FLAG, D3D11_TEXTURE2D_DESC, D3D11_USAGE_STAGING,
5+
ID3D11Device, ID3D11DeviceContext, ID3D11Resource, ID3D11Texture2D,
6+
D3D11_CPU_ACCESS_READ, D3D11_MAPPED_SUBRESOURCE, D3D11_MAP_READ, D3D11_TEXTURE2D_DESC,
7+
D3D11_USAGE_STAGING,
88
},
99
Dxgi::Common::{DXGI_FORMAT, DXGI_SAMPLE_DESC},
1010
},
@@ -33,15 +33,21 @@ impl StagingTexture {
3333
Count: 1,
3434
Quality: 0,
3535
},
36-
BindFlags: D3D11_BIND_FLAG(0),
37-
MiscFlags: D3D11_RESOURCE_MISC_FLAG(0),
36+
BindFlags: 0,
37+
MiscFlags: 0,
3838
Usage: D3D11_USAGE_STAGING,
39-
CPUAccessFlags: D3D11_CPU_ACCESS_READ,
39+
CPUAccessFlags: D3D11_CPU_ACCESS_READ.0 as u32,
4040
};
4141

42-
let texture = unsafe { device.CreateTexture2D(&desc, None)? };
42+
let mut texture = None;
43+
unsafe {
44+
device.CreateTexture2D(&desc, None, Some(&mut texture))?;
45+
}
4346

44-
Ok(Self { texture, desc })
47+
Ok(Self {
48+
texture: texture.expect("CreateTexture2D"),
49+
desc,
50+
})
4551
}
4652

4753
pub fn as_resource(&self) -> Result<ID3D11Resource> {
@@ -50,8 +56,16 @@ impl StagingTexture {
5056

5157
pub fn as_mapped(&self, context: &ID3D11DeviceContext) -> Result<D3D11_MAPPED_SUBRESOURCE> {
5258
let staging_texture_ptr: ID3D11Resource = self.texture.cast()?;
53-
let mapped_texture =
54-
unsafe { context.Map(Some(&staging_texture_ptr), 0, D3D11_MAP_READ, 0)? };
59+
let mut mapped_texture = D3D11_MAPPED_SUBRESOURCE::default();
60+
unsafe {
61+
context.Map(
62+
Some(&staging_texture_ptr),
63+
0,
64+
D3D11_MAP_READ,
65+
0,
66+
Some(&mut mapped_texture),
67+
)?;
68+
}
5569
// we can instantly unmap because the texture is staging, and will be still accessible by CPU
5670
// TODO there should be a way to do this by queueing a fence (we only need to wait copies) or something like that,
5771
// which would probably be more correct solution rather than map-unmap

0 commit comments

Comments
 (0)