Skip to content

Commit 44b07f6

Browse files
committed
Address review comments.
1 parent e8c92e8 commit 44b07f6

File tree

5 files changed

+38
-44
lines changed

5 files changed

+38
-44
lines changed

webrender/src/internal_types.rs

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

39-
impl CacheTextureId {
40-
pub fn invalid() -> CacheTextureId {
41-
CacheTextureId(usize::MAX)
42-
}
43-
}
44-
4538
// Represents the source for a texture.
4639
// These are passed from throughout the
4740
// pipeline until they reach the rendering
@@ -370,14 +363,9 @@ pub enum RenderTargetMode {
370363
LayerRenderTarget(i32), // Number of texture layers
371364
}
372365

373-
#[derive(Debug)]
374-
pub enum TextureUpdateDetails {
375-
Blit(Vec<u8>, Option<u32>),
376-
}
377-
378366
pub enum TextureUpdateOp {
379367
Create(u32, u32, ImageFormat, TextureFilter, RenderTargetMode, Option<Vec<u8>>),
380-
Update(u32, u32, u32, u32, TextureUpdateDetails),
368+
Update(u32, u32, u32, u32, Vec<u8>, Option<u32>),
381369
Grow(u32, u32, ImageFormat, TextureFilter, RenderTargetMode),
382370
}
383371

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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use euclid::{Point2D, Size2D};
88
use fnv::FnvHasher;
99
use frame::FrameId;
1010
use freelist::FreeList;
11-
use internal_types::{CacheTextureId, FontTemplate, SourceTexture};
11+
use internal_types::{FontTemplate, SourceTexture};
1212
use internal_types::{TextureUpdateList, DrawListId, DrawList};
1313
use platform::font::{FontContext, RasterizedGlyph};
1414
use rayon::prelude::*;
@@ -368,7 +368,7 @@ impl ResourceCache {
368368
size,
369369
0,
370370
render_mode);
371-
let mut texture_id = CacheTextureId::invalid();
371+
let mut texture_id = None;
372372
for (loop_index, glyph_index) in glyph_indices.iter().enumerate() {
373373
glyph_key.key.index = *glyph_index;
374374
let image_id = self.cached_glyphs.get(&glyph_key, self.current_frame_id);
@@ -379,13 +379,13 @@ impl ResourceCache {
379379
let uv1 = Point2D::new(cache_item.pixel_rect.bottom_right.x as f32,
380380
cache_item.pixel_rect.bottom_right.y as f32);
381381
f(loop_index, uv0, uv1);
382-
debug_assert!(texture_id == CacheTextureId::invalid() ||
383-
texture_id == cache_item.texture_id);
384-
texture_id = cache_item.texture_id;
382+
debug_assert!(texture_id == None ||
383+
texture_id == Some(cache_item.texture_id));
384+
texture_id = Some(cache_item.texture_id);
385385
}
386386
}
387387

388-
SourceTexture::TextureCache(texture_id)
388+
texture_id.map_or(SourceTexture::Invalid, SourceTexture::TextureCache)
389389
}
390390

391391
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
@@ -597,7 +597,7 @@ impl RenderTarget {
597597
text_run_textures: BatchTextures::no_texture(),
598598
vertical_blurs: Vec::new(),
599599
horizontal_blurs: Vec::new(),
600-
page_allocator: TexturePage::new(CacheTextureId::invalid(),
600+
page_allocator: TexturePage::new(CacheTextureId(0),
601601
RENDERABLE_CACHE_SIZE as u32),
602602
}
603603
}

0 commit comments

Comments
 (0)