From 16cb2b191beb1a342f77b181f13989a2516dedd8 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 22 Feb 2018 14:47:36 -0500 Subject: [PATCH] Check for texture size --- webrender/src/device.rs | 10 ++++++++-- webrender/src/renderer.rs | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/webrender/src/device.rs b/webrender/src/device.rs index c40af173ba..0adf65fb91 100644 --- a/webrender/src/device.rs +++ b/webrender/src/device.rs @@ -1009,8 +1009,8 @@ impl Device { pub fn init_texture( &mut self, texture: &mut Texture, - width: u32, - height: u32, + mut width: u32, + mut height: u32, filter: TextureFilter, render_target: Option, layer_count: i32, @@ -1018,6 +1018,12 @@ impl Device { ) { debug_assert!(self.inside_frame); + if width > self.max_texture_size || height > self.max_texture_size { + error!("Attempting to allocate a texture of size {}x{} above the limit, trimming", width, height); + width = width.min(self.max_texture_size); + height = height.min(self.max_texture_size); + } + let is_resized = texture.width != width || texture.height != height; texture.width = width; diff --git a/webrender/src/renderer.rs b/webrender/src/renderer.rs index c7a99830b2..4b3eadccf5 100644 --- a/webrender/src/renderer.rs +++ b/webrender/src/renderer.rs @@ -1661,6 +1661,7 @@ pub struct Renderer { gpu_cache_texture: CacheTexture, gpu_cache_frame_id: FrameId, + gpu_cache_overflow: bool, pipeline_info: PipelineInfo, @@ -2345,6 +2346,7 @@ impl Renderer { gpu_profiles: VecDeque::new(), gpu_cache_texture, gpu_cache_frame_id: FrameId::new(0), + gpu_cache_overflow: false, texture_cache_upload_pbo, texture_resolver, renderer_errors: Vec::new(), @@ -2998,6 +3000,11 @@ impl Renderer { (count + list.blocks.len(), cmp::max(height, list.height)) }); + if max_requested_height > self.max_texture_size && !self.gpu_cache_overflow { + self.gpu_cache_overflow = true; + self.renderer_errors.push(RendererError::MaxTextureSize); + } + //Note: if we decide to switch to scatter-style GPU cache update // permanently, we can have this code nicer with `BufferUploader` kind // of helper, similarly to how `TextureUploader` API is used.