Skip to content

Commit 3345d0b

Browse files
committed
Address review comments.
1 parent 2b80955 commit 3345d0b

File tree

5 files changed

+38
-47
lines changed

5 files changed

+38
-47
lines changed

webrender/src/internal_types.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ use profiler::BackendProfileCounters;
1414
use std::collections::{HashMap, HashSet};
1515
use std::f32;
1616
use std::hash::BuildHasherDefault;
17-
use std::i32;
17+
use std::{i32, usize};
1818
use std::path::PathBuf;
1919
use std::sync::Arc;
20-
use std::usize;
2120
use tiling;
2221
use webrender_traits::{Epoch, ColorF, PipelineId};
2322
use webrender_traits::{ImageFormat, MixBlendMode, NativeFontHandle};
@@ -35,12 +34,6 @@ use webrender_traits::{ScrollLayerId, WebGLCommand};
3534
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
3635
pub struct CacheTextureId(pub usize);
3736

38-
impl CacheTextureId {
39-
pub fn invalid() -> CacheTextureId {
40-
CacheTextureId(usize::MAX)
41-
}
42-
}
43-
4437
// Represents the source for a texture.
4538
// These are passed from throughout the
4639
// pipeline until they reach the rendering
@@ -367,14 +360,9 @@ pub enum RenderTargetMode {
367360
LayerRenderTarget(i32), // Number of texture layers
368361
}
369362

370-
#[derive(Debug)]
371-
pub enum TextureUpdateDetails {
372-
Blit(Vec<u8>, Option<u32>),
373-
}
374-
375363
pub enum TextureUpdateOp {
376364
Create(u32, u32, ImageFormat, TextureFilter, RenderTargetMode, Option<Vec<u8>>),
377-
Update(u32, u32, u32, u32, TextureUpdateDetails),
365+
Update(u32, u32, u32, u32, Vec<u8>, Option<u32>),
378366
Grow(u32, u32, ImageFormat, TextureFilter, RenderTargetMode),
379367
}
380368

webrender/src/renderer.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use device::{TextureFilter, VAOId, VertexUsageHint, FileWatcherHandler, TextureT
1616
use euclid::{Matrix4D, Size2D};
1717
use fnv::FnvHasher;
1818
use internal_types::{CacheTextureId, RendererFrame, ResultMsg, TextureUpdateOp};
19-
use internal_types::{TextureUpdateDetails, TextureUpdateList, PackedVertex, RenderTargetMode};
19+
use internal_types::{TextureUpdateList, PackedVertex, RenderTargetMode};
2020
use internal_types::{ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE, DevicePoint, SourceTexture};
2121
use internal_types::{BatchTextures, TextureSampler, GLContextHandleWrapper};
2222
use ipc_channel::ipc;
@@ -374,8 +374,12 @@ pub struct Renderer {
374374
/// Required to allow GLContext sharing in some implementations like WGL.
375375
main_thread_dispatcher: Arc<Mutex<Option<Box<RenderDispatcher>>>>,
376376

377-
// A vectors for fast resolves of texture cache IDs to
378-
// native texture IDs.
377+
/// A vector for fast resolves of texture cache IDs to
378+
/// native texture IDs. This maps to a free-list managed
379+
/// by the backend thread / texture cache. Because of this,
380+
/// items in this array may be None if they have been
381+
/// freed by the backend thread. This saves having to
382+
/// use a hashmap, and allows a flat vector for performance.
379383
cache_texture_id_map: Vec<Option<TextureId>>,
380384
}
381385

@@ -769,7 +773,8 @@ impl Renderer {
769773
&SourceTexture::Invalid => TextureId::invalid(),
770774
&SourceTexture::WebGL(id) => TextureId::new(id),
771775
&SourceTexture::TextureCache(index) => {
772-
self.cache_texture_id_map[index.0].unwrap()
776+
self.cache_texture_id_map[index.0]
777+
.expect("BUG: Texture should exist in texture cache map!")
773778
}
774779
}
775780
}
@@ -911,18 +916,13 @@ impl Renderer {
911916
filter,
912917
mode);
913918
}
914-
TextureUpdateOp::Update(x, y, width, height, details) => {
919+
TextureUpdateOp::Update(x, y, width, height, bytes, stride) => {
915920
let texture_id = self.cache_texture_id_map[update.id.0].unwrap();
916-
match details {
917-
TextureUpdateDetails::Blit(bytes, stride) => {
918-
self.device.update_texture(
919-
texture_id,
920-
x,
921-
y,
922-
width, height, stride,
923-
bytes.as_slice());
924-
}
925-
}
921+
self.device.update_texture(texture_id,
922+
x,
923+
y,
924+
width, height, stride,
925+
bytes.as_slice());
926926
}
927927
}
928928
}

webrender/src/resource_cache.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ use device::TextureFilter;
77
use euclid::{Point2D, Size2D};
88
use fnv::FnvHasher;
99
use frame::FrameId;
10-
use internal_types::{FontTemplate, TextureUpdateList};
11-
use freelist::FreeList;
12-
use internal_types::{CacheTextureId, FontTemplate, SourceTexture};
13-
use internal_types::{TextureUpdateList, DrawListId, DrawList};
10+
use internal_types::{FontTemplate, SourceTexture, TextureUpdateList};
1411
use platform::font::{FontContext, RasterizedGlyph};
1512
use rayon::prelude::*;
1613
use std::cell::RefCell;
@@ -354,7 +351,7 @@ impl ResourceCache {
354351
size,
355352
0,
356353
render_mode);
357-
let mut texture_id = CacheTextureId::invalid();
354+
let mut texture_id = None;
358355
for (loop_index, glyph_index) in glyph_indices.iter().enumerate() {
359356
glyph_key.key.index = *glyph_index;
360357
let image_id = self.cached_glyphs.get(&glyph_key, self.current_frame_id);
@@ -365,13 +362,13 @@ impl ResourceCache {
365362
let uv1 = Point2D::new(cache_item.pixel_rect.bottom_right.x as f32,
366363
cache_item.pixel_rect.bottom_right.y as f32);
367364
f(loop_index, uv0, uv1);
368-
debug_assert!(texture_id == CacheTextureId::invalid() ||
369-
texture_id == cache_item.texture_id);
370-
texture_id = cache_item.texture_id;
365+
debug_assert!(texture_id == None ||
366+
texture_id == Some(cache_item.texture_id));
367+
texture_id = Some(cache_item.texture_id);
371368
}
372369
}
373370

374-
SourceTexture::TextureCache(texture_id)
371+
texture_id.map_or(SourceTexture::Invalid, SourceTexture::TextureCache)
375372
}
376373

377374
pub fn get_glyph_dimensions(&mut self, glyph_key: &GlyphKey) -> Option<GlyphDimensions> {

webrender/src/texture_cache.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use device::{MAX_TEXTURE_SIZE, TextureFilter};
66
use euclid::{Point2D, Rect, Size2D};
77
use fnv::FnvHasher;
88
use freelist::{FreeList, FreeListItem, FreeListItemId};
9-
use internal_types::{TextureUpdate, TextureUpdateOp, TextureUpdateDetails};
9+
use internal_types::{TextureUpdate, TextureUpdateOp};
1010
use internal_types::{CacheTextureId, RenderTargetMode, TextureUpdateList};
1111
use internal_types::{RectUv, DevicePixel, DevicePoint};
1212
use std::cmp::{self, Ordering};
@@ -597,7 +597,7 @@ impl TextureCache {
597597
allocated_rect: Rect::zero(),
598598
requested_rect: Rect::zero(),
599599
texture_size: Size2D::zero(),
600-
texture_id: CacheTextureId::invalid(),
600+
texture_id: CacheTextureId(0),
601601
};
602602
self.items.insert(new_item)
603603
}
@@ -740,7 +740,8 @@ impl TextureCache {
740740
existing_item.requested_rect.origin.y,
741741
width,
742742
height,
743-
TextureUpdateDetails::Blit(bytes, stride));
743+
bytes,
744+
stride);
744745

745746
let update_op = TextureUpdate {
746747
id: existing_item.texture_id,
@@ -797,7 +798,8 @@ impl TextureCache {
797798
result.item.allocated_rect.origin.y,
798799
result.item.allocated_rect.size.width,
799800
1,
800-
TextureUpdateDetails::Blit(top_row_bytes, None))
801+
top_row_bytes,
802+
None)
801803
};
802804

803805
let border_update_op_bottom = TextureUpdate {
@@ -808,7 +810,8 @@ impl TextureCache {
808810
result.item.requested_rect.size.height + 1,
809811
result.item.allocated_rect.size.width,
810812
1,
811-
TextureUpdateDetails::Blit(bottom_row_bytes, None))
813+
bottom_row_bytes,
814+
None)
812815
};
813816

814817
let border_update_op_left = TextureUpdate {
@@ -818,7 +821,8 @@ impl TextureCache {
818821
result.item.requested_rect.origin.y,
819822
1,
820823
result.item.requested_rect.size.height,
821-
TextureUpdateDetails::Blit(left_column_bytes, None))
824+
left_column_bytes,
825+
None)
822826
};
823827

824828
let border_update_op_right = TextureUpdate {
@@ -827,7 +831,8 @@ impl TextureCache {
827831
result.item.requested_rect.origin.y,
828832
1,
829833
result.item.requested_rect.size.height,
830-
TextureUpdateDetails::Blit(right_column_bytes, None))
834+
right_column_bytes,
835+
None)
831836
};
832837

833838
self.pending_updates.push(border_update_op_top);
@@ -839,7 +844,8 @@ impl TextureCache {
839844
result.item.requested_rect.origin.y,
840845
width,
841846
height,
842-
TextureUpdateDetails::Blit(bytes,stride))
847+
bytes,
848+
stride)
843849
}
844850
AllocationKind::Standalone => {
845851
TextureUpdateOp::Create(width,

webrender/src/tiling.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ impl RenderTarget {
610610
text_run_textures: BatchTextures::no_texture(),
611611
vertical_blurs: Vec::new(),
612612
horizontal_blurs: Vec::new(),
613-
page_allocator: TexturePage::new(CacheTextureId::invalid(),
613+
page_allocator: TexturePage::new(CacheTextureId(0),
614614
RENDERABLE_CACHE_SIZE as u32),
615615
}
616616
}

0 commit comments

Comments
 (0)