diff --git a/webrender/src/internal_types.rs b/webrender/src/internal_types.rs index 60008518f4..936e85f6ce 100644 --- a/webrender/src/internal_types.rs +++ b/webrender/src/internal_types.rs @@ -14,10 +14,9 @@ use profiler::BackendProfileCounters; use std::collections::{HashMap, HashSet}; use std::f32; use std::hash::BuildHasherDefault; -use std::i32; +use std::{i32, usize}; use std::path::PathBuf; use std::sync::Arc; -use std::usize; use tiling; use webrender_traits::{Epoch, ColorF, PipelineId}; use webrender_traits::{ImageFormat, MixBlendMode, NativeFontHandle}; @@ -35,12 +34,6 @@ use webrender_traits::{ScrollLayerId, WebGLCommand}; #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] pub struct CacheTextureId(pub usize); -impl CacheTextureId { - pub fn invalid() -> CacheTextureId { - CacheTextureId(usize::MAX) - } -} - // Represents the source for a texture. // These are passed from throughout the // pipeline until they reach the rendering @@ -367,14 +360,9 @@ pub enum RenderTargetMode { LayerRenderTarget(i32), // Number of texture layers } -#[derive(Debug)] -pub enum TextureUpdateDetails { - Blit(Vec, Option), -} - pub enum TextureUpdateOp { Create(u32, u32, ImageFormat, TextureFilter, RenderTargetMode, Option>), - Update(u32, u32, u32, u32, TextureUpdateDetails), + Update(u32, u32, u32, u32, Vec, Option), Grow(u32, u32, ImageFormat, TextureFilter, RenderTargetMode), } diff --git a/webrender/src/renderer.rs b/webrender/src/renderer.rs index 5705fcc49a..561791a1b8 100644 --- a/webrender/src/renderer.rs +++ b/webrender/src/renderer.rs @@ -16,7 +16,7 @@ use device::{TextureFilter, VAOId, VertexUsageHint, FileWatcherHandler, TextureT use euclid::{Matrix4D, Size2D}; use fnv::FnvHasher; use internal_types::{CacheTextureId, RendererFrame, ResultMsg, TextureUpdateOp}; -use internal_types::{TextureUpdateDetails, TextureUpdateList, PackedVertex, RenderTargetMode}; +use internal_types::{TextureUpdateList, PackedVertex, RenderTargetMode}; use internal_types::{ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE, DevicePoint, SourceTexture}; use internal_types::{BatchTextures, TextureSampler, GLContextHandleWrapper}; use ipc_channel::ipc; @@ -374,8 +374,12 @@ pub struct Renderer { /// Required to allow GLContext sharing in some implementations like WGL. main_thread_dispatcher: Arc>>>, - // A vectors for fast resolves of texture cache IDs to - // native texture IDs. + /// A vector for fast resolves of texture cache IDs to + /// native texture IDs. This maps to a free-list managed + /// by the backend thread / texture cache. Because of this, + /// items in this array may be None if they have been + /// freed by the backend thread. This saves having to + /// use a hashmap, and allows a flat vector for performance. cache_texture_id_map: Vec>, } @@ -769,7 +773,8 @@ impl Renderer { &SourceTexture::Invalid => TextureId::invalid(), &SourceTexture::WebGL(id) => TextureId::new(id), &SourceTexture::TextureCache(index) => { - self.cache_texture_id_map[index.0].unwrap() + self.cache_texture_id_map[index.0] + .expect("BUG: Texture should exist in texture cache map!") } } } @@ -911,18 +916,13 @@ impl Renderer { filter, mode); } - TextureUpdateOp::Update(x, y, width, height, details) => { + TextureUpdateOp::Update(x, y, width, height, bytes, stride) => { let texture_id = self.cache_texture_id_map[update.id.0].unwrap(); - match details { - TextureUpdateDetails::Blit(bytes, stride) => { - self.device.update_texture( - texture_id, - x, - y, - width, height, stride, - bytes.as_slice()); - } - } + self.device.update_texture(texture_id, + x, + y, + width, height, stride, + bytes.as_slice()); } } } diff --git a/webrender/src/resource_cache.rs b/webrender/src/resource_cache.rs index 68863c502a..c439f21ca0 100644 --- a/webrender/src/resource_cache.rs +++ b/webrender/src/resource_cache.rs @@ -7,10 +7,7 @@ use device::TextureFilter; use euclid::{Point2D, Size2D}; use fnv::FnvHasher; use frame::FrameId; -use internal_types::{FontTemplate, TextureUpdateList}; -use freelist::FreeList; -use internal_types::{CacheTextureId, FontTemplate, SourceTexture}; -use internal_types::{TextureUpdateList, DrawListId, DrawList}; +use internal_types::{FontTemplate, SourceTexture, TextureUpdateList}; use platform::font::{FontContext, RasterizedGlyph}; use rayon::prelude::*; use std::cell::RefCell; @@ -354,7 +351,7 @@ impl ResourceCache { size, 0, render_mode); - let mut texture_id = CacheTextureId::invalid(); + let mut texture_id = None; for (loop_index, glyph_index) in glyph_indices.iter().enumerate() { glyph_key.key.index = *glyph_index; let image_id = self.cached_glyphs.get(&glyph_key, self.current_frame_id); @@ -365,13 +362,13 @@ impl ResourceCache { let uv1 = Point2D::new(cache_item.pixel_rect.bottom_right.x as f32, cache_item.pixel_rect.bottom_right.y as f32); f(loop_index, uv0, uv1); - debug_assert!(texture_id == CacheTextureId::invalid() || - texture_id == cache_item.texture_id); - texture_id = cache_item.texture_id; + debug_assert!(texture_id == None || + texture_id == Some(cache_item.texture_id)); + texture_id = Some(cache_item.texture_id); } } - SourceTexture::TextureCache(texture_id) + texture_id.map_or(SourceTexture::Invalid, SourceTexture::TextureCache) } pub fn get_glyph_dimensions(&mut self, glyph_key: &GlyphKey) -> Option { diff --git a/webrender/src/texture_cache.rs b/webrender/src/texture_cache.rs index 7205612e18..313bce09c8 100644 --- a/webrender/src/texture_cache.rs +++ b/webrender/src/texture_cache.rs @@ -6,7 +6,7 @@ use device::{MAX_TEXTURE_SIZE, TextureFilter}; use euclid::{Point2D, Rect, Size2D}; use fnv::FnvHasher; use freelist::{FreeList, FreeListItem, FreeListItemId}; -use internal_types::{TextureUpdate, TextureUpdateOp, TextureUpdateDetails}; +use internal_types::{TextureUpdate, TextureUpdateOp}; use internal_types::{CacheTextureId, RenderTargetMode, TextureUpdateList}; use internal_types::{RectUv, DevicePixel, DevicePoint}; use std::cmp::{self, Ordering}; @@ -597,7 +597,7 @@ impl TextureCache { allocated_rect: Rect::zero(), requested_rect: Rect::zero(), texture_size: Size2D::zero(), - texture_id: CacheTextureId::invalid(), + texture_id: CacheTextureId(0), }; self.items.insert(new_item) } @@ -740,7 +740,8 @@ impl TextureCache { existing_item.requested_rect.origin.y, width, height, - TextureUpdateDetails::Blit(bytes, stride)); + bytes, + stride); let update_op = TextureUpdate { id: existing_item.texture_id, @@ -797,7 +798,8 @@ impl TextureCache { result.item.allocated_rect.origin.y, result.item.allocated_rect.size.width, 1, - TextureUpdateDetails::Blit(top_row_bytes, None)) + top_row_bytes, + None) }; let border_update_op_bottom = TextureUpdate { @@ -808,7 +810,8 @@ impl TextureCache { result.item.requested_rect.size.height + 1, result.item.allocated_rect.size.width, 1, - TextureUpdateDetails::Blit(bottom_row_bytes, None)) + bottom_row_bytes, + None) }; let border_update_op_left = TextureUpdate { @@ -818,7 +821,8 @@ impl TextureCache { result.item.requested_rect.origin.y, 1, result.item.requested_rect.size.height, - TextureUpdateDetails::Blit(left_column_bytes, None)) + left_column_bytes, + None) }; let border_update_op_right = TextureUpdate { @@ -827,7 +831,8 @@ impl TextureCache { result.item.requested_rect.origin.y, 1, result.item.requested_rect.size.height, - TextureUpdateDetails::Blit(right_column_bytes, None)) + right_column_bytes, + None) }; self.pending_updates.push(border_update_op_top); @@ -839,7 +844,8 @@ impl TextureCache { result.item.requested_rect.origin.y, width, height, - TextureUpdateDetails::Blit(bytes,stride)) + bytes, + stride) } AllocationKind::Standalone => { TextureUpdateOp::Create(width, diff --git a/webrender/src/tiling.rs b/webrender/src/tiling.rs index b0ee94b36b..d2ee1ba849 100644 --- a/webrender/src/tiling.rs +++ b/webrender/src/tiling.rs @@ -610,7 +610,7 @@ impl RenderTarget { text_run_textures: BatchTextures::no_texture(), vertical_blurs: Vec::new(), horizontal_blurs: Vec::new(), - page_allocator: TexturePage::new(CacheTextureId::invalid(), + page_allocator: TexturePage::new(CacheTextureId(0), RENDERABLE_CACHE_SIZE as u32), } }