From ab15b1bb8bf38bff167f47184fee001415749d68 Mon Sep 17 00:00:00 2001 From: Jinlei Li Date: Sun, 21 Jan 2024 23:02:03 +0800 Subject: [PATCH] Fix config size --- .github/workflows/ci.yml | 2 +- README.MD | 2 +- app-surface/Cargo.toml | 2 +- app-surface/src/android.rs | 1 - app-surface/src/app_surface.rs | 21 ++++++++++++++------- wgpu-in-app/Cargo.toml | 2 +- wgpu-in-app/src/examples/msaa_line.rs | 1 - 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99306f0..e3fd0e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ env: CARGO_INCREMENTAL: false CARGO_TERM_COLOR: always RUST_BACKTRACE: full - MSRV: 1.70 + MSRV: 1.71 jobs: check-msrv: diff --git a/README.MD b/README.MD index 615b845..c164aae 100644 --- a/README.MD +++ b/README.MD @@ -1,6 +1,6 @@ # wgpu in App -![Minimum Rust Version](https://img.shields.io/badge/min%20rust-1.70-green.svg) +![Minimum Rust Version](https://img.shields.io/badge/min%20rust-1.71-green.svg) [![Build Status](https://github.com/jinleili/wgpu-in-app/workflows/CI/badge.svg?branch=master)](https://github.com/jinleili/wgpu-in-app/actions) [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jinleili/wgpu-in-app/blob/master/LICENSE.MIT) diff --git a/app-surface/Cargo.toml b/app-surface/Cargo.toml index 4527d3a..5ea80a7 100644 --- a/app-surface/Cargo.toml +++ b/app-surface/Cargo.toml @@ -4,7 +4,7 @@ authors = ["jinleili"] description = "Integrate wgpu into your existing iOS and Android apps." edition = "2021" version = "0.4.0" -rust-version = "1.70" +rust-version = "1.71" repository = "https://github.com/jinleili/wgpu-in-app" keywords = ["android", "SurfaceView", "ios", "app", "wgpu"] license = "MIT" diff --git a/app-surface/src/android.rs b/app-surface/src/android.rs index 901828f..6d30d42 100644 --- a/app-surface/src/android.rs +++ b/app-surface/src/android.rs @@ -32,7 +32,6 @@ impl AppSurface { let caps = surface.get_capabilities(&adapter); - log::info!("adapter.limits(): {:?}", adapter.limits()); let config = wgpu::SurfaceConfiguration { usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format: wgpu::TextureFormat::Rgba8UnormSrgb, diff --git a/app-surface/src/app_surface.rs b/app-surface/src/app_surface.rs index 36f65fa..50d1516 100644 --- a/app-surface/src/app_surface.rs +++ b/app-surface/src/app_surface.rs @@ -25,7 +25,9 @@ impl AppSurface { #[allow(clippy::needless_update)] pub async fn new(view: Window) -> Self { let scale_factor = view.scale_factor() as f32; - let physical_size = view.inner_size(); + let mut physical_size = view.inner_size(); + physical_size.width = physical_size.width.max(1); + physical_size.height = physical_size.height.max(1); let view_setting = ViewSetting { scale_factor, physical_size: (physical_size.width, physical_size.height), @@ -36,6 +38,10 @@ impl AppSurface { Self::create(view_setting).await } + pub fn get_view(&self) -> &Window { + return self.view.as_ref().unwrap(); + } + #[cfg(target_arch = "wasm32")] pub async fn from_offscreen_canvas( offscreen_canvas: web_sys::OffscreenCanvas, @@ -81,10 +87,11 @@ impl AppSurface { wgpu::SurfaceTarget::OffscreenCanvas(view_setting.offscreen_canvas.unwrap()) ) } else { - use winit::platform::web::WindowExtWebSys; - let canvas: web_sys::HtmlCanvasElement = - view.as_ref().canvas().unwrap(); - instance.create_surface(wgpu::SurfaceTarget::Canvas(canvas)) + // use winit::platform::web::WindowExtWebSys; + // let canvas: web_sys::HtmlCanvasElement = + // view.as_ref().canvas().unwrap(); + // instance.create_surface(wgpu::SurfaceTarget::Canvas(canvas)) + instance.create_surface(view.clone()) }; } else { let surface = instance.create_surface(view.clone()); @@ -165,8 +172,8 @@ impl AppSurface { if self.is_offscreen_canvas { panic!("Offscreen canvas cannot provide any DOM interfaces."); } else { - let physical = self.view.as_ref().unwrap().inner_size(); - (physical.width, physical.height) + let physical = self.get_view().inner_size(); + (physical.width.max(1), physical.height.max(1)) } } } diff --git a/wgpu-in-app/Cargo.toml b/wgpu-in-app/Cargo.toml index 66a5e90..2fff55e 100644 --- a/wgpu-in-app/Cargo.toml +++ b/wgpu-in-app/Cargo.toml @@ -3,7 +3,7 @@ name = "wgpu-in-app" authors = ["jinleili"] version = "0.3.0" edition = "2021" -rust-version = "1.70" +rust-version = "1.71" [lib] crate-type = ["rlib", "staticlib", "cdylib"] diff --git a/wgpu-in-app/src/examples/msaa_line.rs b/wgpu-in-app/src/examples/msaa_line.rs index 8f66073..df58c16 100644 --- a/wgpu-in-app/src/examples/msaa_line.rs +++ b/wgpu-in-app/src/examples/msaa_line.rs @@ -145,7 +145,6 @@ impl MSAALine { vertex_buffer_list: &Vec, vertex_count: u32, ) -> wgpu::RenderBundle { - log::info!("sample_count: {}", sample_count); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(pipeline_layout),