From 6e82302b53af816d2fafce1dbcaf482cd55887b3 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Wed, 9 Aug 2017 15:43:00 +0200 Subject: [PATCH] Fail initialization if the max texture size is insufficient. --- webrender/src/renderer.rs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/webrender/src/renderer.rs b/webrender/src/renderer.rs index 91359239d4..a615e08d45 100644 --- a/webrender/src/renderer.rs +++ b/webrender/src/renderer.rs @@ -810,6 +810,7 @@ pub struct Renderer { pub enum InitError { Shader(ShaderError), Thread(std::io::Error), + MaxTextureSize, } impl From for InitError { @@ -839,13 +840,12 @@ impl Renderer { /// ``` /// [rendereroptions]: struct.RendererOptions.html pub fn new(gl: Rc, mut options: RendererOptions) -> Result<(Renderer, RenderApiSender), InitError> { + let (api_tx, api_rx) = try!{ channel::msg_channel() }; let (payload_tx, payload_rx) = try!{ channel::payload_channel() }; let (result_tx, result_rx) = channel(); let gl_type = gl.get_type(); - register_thread_with_profiler("Compositor".to_owned()); - let notifier = Arc::new(Mutex::new(None)); let file_watch_handler = FileWatcher { @@ -853,9 +853,28 @@ impl Renderer { notifier: Arc::clone(¬ifier), }; - let mut device = Device::new(gl, - options.resource_override_path.clone(), - Box::new(file_watch_handler)); + let mut device = Device::new( + gl, + options.resource_override_path.clone(), + Box::new(file_watch_handler) + ); + + let device_max_size = device.max_texture_size(); + // 512 is the minimum that the texture cache can work with. + // Broken GL contexts can return a max texture size of zero (See #1260). Better to + // gracefully fail now than panic as soon as a texture is allocated. + let min_texture_size = 512; + if device_max_size < min_texture_size { + println!("Device reporting insufficient max texture size ({})", device_max_size); + return Err(InitError::MaxTextureSize); + } + let max_texture_size = cmp::max( + cmp::min(device_max_size, options.max_texture_size.unwrap_or(device_max_size)), + min_texture_size + ); + + register_thread_with_profiler("Compositor".to_owned()); + // device-pixel ratio doesn't matter here - we are just creating resources. device.begin_frame(1.0); @@ -1112,9 +1131,6 @@ impl Renderer { options.precache_shaders) }; - let device_max_size = device.max_texture_size(); - let max_texture_size = cmp::min(device_max_size, options.max_texture_size.unwrap_or(device_max_size)); - let texture_cache = TextureCache::new(max_texture_size); let backend_profile_counters = BackendProfileCounters::new();