Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
gw3583 committed Nov 14, 2016
1 parent 2b80955 commit 3345d0b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 47 deletions.
16 changes: 2 additions & 14 deletions webrender/src/internal_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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
Expand Down Expand Up @@ -367,14 +360,9 @@ pub enum RenderTargetMode {
LayerRenderTarget(i32), // Number of texture layers
}

#[derive(Debug)]
pub enum TextureUpdateDetails {
Blit(Vec<u8>, Option<u32>),
}

pub enum TextureUpdateOp {
Create(u32, u32, ImageFormat, TextureFilter, RenderTargetMode, Option<Vec<u8>>),
Update(u32, u32, u32, u32, TextureUpdateDetails),
Update(u32, u32, u32, u32, Vec<u8>, Option<u32>),
Grow(u32, u32, ImageFormat, TextureFilter, RenderTargetMode),
}

Expand Down
30 changes: 15 additions & 15 deletions webrender/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -374,8 +374,12 @@ pub struct Renderer {
/// Required to allow GLContext sharing in some implementations like WGL.
main_thread_dispatcher: Arc<Mutex<Option<Box<RenderDispatcher>>>>,

// 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<Option<TextureId>>,
}

Expand Down Expand Up @@ -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!")
}
}
}
Expand Down Expand Up @@ -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());
}
}
}
Expand Down
15 changes: 6 additions & 9 deletions webrender/src/resource_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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<GlyphDimensions> {
Expand Down
22 changes: 14 additions & 8 deletions webrender/src/texture_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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);
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion webrender/src/tiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down

0 comments on commit 3345d0b

Please sign in to comment.