Skip to content

Commit e27cb5c

Browse files
committed
Address some review comments.
1 parent d237ebc commit e27cb5c

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

webrender/src/resource_cache.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ use webrender_traits::{GlyphDimensions, PipelineId, WebGLContextId};
2626

2727
thread_local!(pub static FONT_CONTEXT: RefCell<FontContext> = RefCell::new(FontContext::new()));
2828

29+
// These coordinates are always in texels.
30+
// They are converted to normalized ST
31+
// values in the vertex shader. The reason
32+
// for this is that the texture may change
33+
// dimensions (e.g. the pages in a texture
34+
// atlas can grow). When this happens, by
35+
// storing the coordinates as texel values
36+
// we don't need to go through and update
37+
// various CPU-side structures.
2938
pub struct CacheItem {
3039
pub texture_id: TextureId,
3140
pub uv0: Point2D<f32>,
@@ -129,11 +138,6 @@ impl<K,V> ResourceClassCache<K,V> where K: Clone + Hash + Eq + Debug, V: Resourc
129138
}
130139
}
131140

132-
struct ImageResourceRequest {
133-
key: ImageKey,
134-
rendering: ImageRendering,
135-
}
136-
137141
struct TextRunResourceRequest {
138142
key: FontKey,
139143
size: Au,
@@ -142,16 +146,21 @@ struct TextRunResourceRequest {
142146
}
143147

144148
enum ResourceRequest {
145-
Image(ImageResourceRequest),
149+
Image(ImageKey, ImageRendering),
146150
TextRun(TextRunResourceRequest),
147151
}
148152

153+
struct WebGLTexture {
154+
id: TextureId,
155+
size: Size2D<i32>,
156+
}
157+
149158
pub struct ResourceCache {
150159
cached_glyphs: ResourceClassCache<GlyphKey, Option<TextureCacheItemId>>,
151160
cached_images: ResourceClassCache<(ImageKey, ImageRendering), CachedImageInfo>,
152161

153162
// TODO(pcwalton): Figure out the lifecycle of these.
154-
webgl_textures: HashMap<WebGLContextId, (TextureId, Size2D<i32>), BuildHasherDefault<FnvHasher>>,
163+
webgl_textures: HashMap<WebGLContextId, WebGLTexture, BuildHasherDefault<FnvHasher>>,
155164

156165
draw_lists: FreeList<DrawList>,
157166
font_templates: HashMap<FontKey, FontTemplate, BuildHasherDefault<FnvHasher>>,
@@ -246,18 +255,18 @@ impl ResourceCache {
246255
}
247256

248257
pub fn add_webgl_texture(&mut self, id: WebGLContextId, texture_id: TextureId, size: Size2D<i32>) {
249-
self.webgl_textures.insert(id, (texture_id, size));
258+
self.webgl_textures.insert(id, WebGLTexture {
259+
id: texture_id,
260+
size: size,
261+
});
250262
self.texture_cache.add_raw_update(texture_id, size);
251263
}
252264

253265
pub fn request_image(&mut self,
254266
key: ImageKey,
255267
rendering: ImageRendering) {
256268
debug_assert!(self.state == State::AddResources);
257-
self.pending_requests.push(ResourceRequest::Image(ImageResourceRequest {
258-
key: key,
259-
rendering: rendering,
260-
}));
269+
self.pending_requests.push(ResourceRequest::Image(key, rendering));
261270
}
262271

263272
pub fn request_glyphs(&mut self,
@@ -430,11 +439,11 @@ impl ResourceCache {
430439

431440
#[inline]
432441
pub fn get_webgl_texture(&self, context_id: &WebGLContextId) -> CacheItem {
433-
let (id, size) = *self.webgl_textures.get(context_id).unwrap();
442+
let webgl_texture = &self.webgl_textures[context_id];
434443
CacheItem {
435-
texture_id: id,
436-
uv0: Point2D::new(0.0, size.height as f32),
437-
uv1: Point2D::new(size.width as f32, 0.0),
444+
texture_id: webgl_texture.id,
445+
uv0: Point2D::new(0.0, webgl_texture.size.height as f32),
446+
uv1: Point2D::new(webgl_texture.size.width as f32, 0.0),
438447
}
439448
}
440449

@@ -455,12 +464,11 @@ impl ResourceCache {
455464

456465
for request in self.pending_requests.drain(..) {
457466
match request {
458-
ResourceRequest::Image(ref image_request) => {
467+
ResourceRequest::Image(key, rendering) => {
459468
let cached_images = &mut self.cached_images;
460-
let image_template = &self.image_templates[&image_request.key];
461-
let key = (image_request.key, image_request.rendering);
469+
let image_template = &self.image_templates[&key];
462470

463-
match cached_images.entry(key, self.current_frame_id) {
471+
match cached_images.entry((key, rendering), self.current_frame_id) {
464472
Occupied(entry) => {
465473
let image_id = entry.get().texture_cache_id;
466474

@@ -482,7 +490,7 @@ impl ResourceCache {
482490
Vacant(entry) => {
483491
let image_id = self.texture_cache.new_item_id();
484492

485-
let filter = match image_request.rendering {
493+
let filter = match rendering {
486494
ImageRendering::Pixelated => TextureFilter::Nearest,
487495
ImageRendering::Auto | ImageRendering::CrispEdges => TextureFilter::Linear,
488496
};

webrender/src/tiling.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,13 +475,13 @@ impl AlphaBatcher {
475475
}
476476

477477
struct CompileTileContext<'a> {
478-
layer_store: &'a Vec<StackingContext>,
478+
layer_store: &'a [StackingContext],
479479
prim_store: &'a PrimitiveStore,
480480
render_task_id_counter: AtomicUsize,
481481
}
482482

483483
struct RenderTargetContext<'a> {
484-
layer_store: &'a Vec<StackingContext>,
484+
layer_store: &'a [StackingContext],
485485
prim_store: &'a PrimitiveStore,
486486
}
487487

@@ -2142,7 +2142,7 @@ impl FrameBuilder {
21422142

21432143
// Build list of passes, target allocs that each tile needs.
21442144
for screen_tile in screen_tiles {
2145-
let rect = screen_tile.rect; // TODO(gw): Remove clone here
2145+
let rect = screen_tile.rect;
21462146
match screen_tile.compile(&ctx) {
21472147
Some(compiled_screen_tile) => {
21482148
max_passes_needed = cmp::max(max_passes_needed,

0 commit comments

Comments
 (0)