Skip to content

Commit 916f46e

Browse files
author
bors-servo
authored
Auto merge of #554 - glennw:ext, r=pcwalton
Introduce SourceTexture, an abstraction for location of source textures. This allows the backend thread to work with textures that have been allocation by the texture cache, via webgl or an external source transparently. The native texture ID is resolved by the rendering thread as requited. Specifically: * Add SourceTexture, an abstraction for the location of a source texture. * Add CacheTextureID, an ID for a texture cache managed texture. * This removes the need to allocate a pool of textures up front. * Remove unused batch.rs file. * Remove the concept of "raw textures" from device.rs * The native texture ID is stored inside the SourceTexture enum now. * Remove some unused functions in device.rs. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/554) <!-- Reviewable:end -->
2 parents 087516e + 3345d0b commit 916f46e

File tree

9 files changed

+210
-330
lines changed

9 files changed

+210
-330
lines changed

webrender/src/batch.rs

Lines changed: 0 additions & 111 deletions
This file was deleted.

webrender/src/device.rs

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,6 @@ pub struct Device {
735735
// resources
736736
resource_path: PathBuf,
737737
textures: HashMap<TextureId, Texture, BuildHasherDefault<FnvHasher>>,
738-
raw_textures: HashMap<TextureId, (u32, u32, u32, u32), BuildHasherDefault<FnvHasher>>,
739738
programs: HashMap<ProgramId, Program, BuildHasherDefault<FnvHasher>>,
740739
vaos: HashMap<VAOId, VAO, BuildHasherDefault<FnvHasher>>,
741740

@@ -778,7 +777,6 @@ impl Device {
778777
default_fbo: 0,
779778

780779
textures: HashMap::with_hasher(Default::default()),
781-
raw_textures: HashMap::with_hasher(Default::default()),
782780
programs: HashMap::with_hasher(Default::default()),
783781
vaos: HashMap::with_hasher(Default::default()),
784782

@@ -946,33 +944,8 @@ impl Device {
946944
}
947945

948946
pub fn get_texture_dimensions(&self, texture_id: TextureId) -> (u32, u32) {
949-
if let Some(texture) = self.textures.get(&texture_id) {
950-
(texture.width, texture.height)
951-
} else {
952-
let dimensions = self.raw_textures.get(&texture_id).unwrap();
953-
(dimensions.2, dimensions.3)
954-
}
955-
}
956-
957-
pub fn texture_has_alpha(&self, texture_id: TextureId) -> bool {
958-
if let Some(texture) = self.textures.get(&texture_id) {
959-
texture.format == ImageFormat::RGBA8
960-
} else {
961-
true
962-
}
963-
}
964-
965-
pub fn update_raw_texture(&mut self,
966-
texture_id: TextureId,
967-
x0: u32,
968-
y0: u32,
969-
width: u32,
970-
height: u32) {
971-
self.raw_textures.insert(texture_id, (x0, y0, width, height));
972-
}
973-
974-
pub fn remove_raw_texture(&mut self, texture_id: TextureId) {
975-
self.raw_textures.remove(&texture_id);
947+
let texture = &self.textures[&texture_id];
948+
(texture.width, texture.height)
976949
}
977950

978951
fn set_texture_parameters(&mut self, target: gl::GLuint, filter: TextureFilter) {
@@ -1526,25 +1499,6 @@ impl Device {
15261499
}
15271500
}
15281501

1529-
pub fn read_framebuffer_rect(&mut self,
1530-
texture_id: TextureId,
1531-
dest_x: i32,
1532-
dest_y: i32,
1533-
src_x: i32,
1534-
src_y: i32,
1535-
width: i32,
1536-
height: i32) {
1537-
self.bind_texture(DEFAULT_TEXTURE, texture_id);
1538-
gl::copy_tex_sub_image_2d(texture_id.target,
1539-
0,
1540-
dest_x,
1541-
dest_y,
1542-
src_x as gl::GLint,
1543-
src_y as gl::GLint,
1544-
width as gl::GLint,
1545-
height as gl::GLint);
1546-
}
1547-
15481502
fn clear_vertex_array(&mut self) {
15491503
debug_assert!(self.inside_frame);
15501504
gl::bind_vertex_array(0);

webrender/src/internal_types.rs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use app_units::Au;
6-
use device::{TextureId, TextureFilter};
7-
use euclid::{Point2D, Rect, Size2D, TypedRect, TypedPoint2D, TypedSize2D, Length, UnknownUnit};
6+
use device::TextureFilter;
7+
use euclid::{Size2D, TypedRect, TypedPoint2D, TypedSize2D, Length, UnknownUnit};
88
use fnv::FnvHasher;
99
use offscreen_gl_context::{NativeGLContext, NativeGLContextHandle};
1010
use offscreen_gl_context::{GLContext, NativeGLContextMethods, GLContextDispatcher};
@@ -14,14 +14,42 @@ 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;
2020
use tiling;
2121
use webrender_traits::{Epoch, ColorF, PipelineId};
2222
use webrender_traits::{ImageFormat, MixBlendMode, NativeFontHandle};
2323
use webrender_traits::{ScrollLayerId, WebGLCommand};
2424

25+
// An ID for a texture that is owned by the
26+
// texture cache module. This can include atlases
27+
// or standalone textures allocated via the
28+
// texture cache (e.g. if an image is too large
29+
// to be added to an atlas). The texture cache
30+
// manages the allocation and freeing of these
31+
// IDs, and the rendering thread maintains a
32+
// map from cache texture ID to native texture.
33+
34+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
35+
pub struct CacheTextureId(pub usize);
36+
37+
// Represents the source for a texture.
38+
// These are passed from throughout the
39+
// pipeline until they reach the rendering
40+
// thread, where they are resolved to a
41+
// native texture ID.
42+
43+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
44+
pub enum SourceTexture {
45+
Invalid,
46+
TextureCache(CacheTextureId),
47+
WebGL(u32), // Is actually a gl::GLuint
48+
49+
// TODO(gw): Implement external image support via callback
50+
//External(i32),
51+
}
52+
2553
pub enum GLContextHandleWrapper {
2654
Native(NativeGLContextHandle),
2755
OSMesa(OSMesaContextHandle),
@@ -194,15 +222,15 @@ impl TextureSampler {
194222
/// Textures that are not used by the batch are equal to TextureId::invalid().
195223
#[derive(Copy, Clone, Debug)]
196224
pub struct BatchTextures {
197-
pub colors: [TextureId; 3],
198-
pub mask: TextureId,
225+
pub colors: [SourceTexture; 3],
226+
pub mask: SourceTexture,
199227
}
200228

201229
impl BatchTextures {
202230
pub fn no_texture() -> Self {
203231
BatchTextures {
204-
colors: [TextureId::invalid(); 3],
205-
mask: TextureId::invalid(),
232+
colors: [SourceTexture::Invalid; 3],
233+
mask: SourceTexture::Invalid,
206234
}
207235
}
208236
}
@@ -332,28 +360,14 @@ pub enum RenderTargetMode {
332360
LayerRenderTarget(i32), // Number of texture layers
333361
}
334362

335-
#[derive(Debug)]
336-
pub enum TextureUpdateDetails {
337-
Raw,
338-
Blit(Vec<u8>, Option<u32>),
339-
}
340-
341-
#[derive(Clone, Copy, Debug)]
342-
pub struct TextureImage {
343-
pub texture_id: TextureId,
344-
pub texel_uv: Rect<f32>,
345-
pub pixel_uv: Point2D<u32>,
346-
}
347-
348363
pub enum TextureUpdateOp {
349364
Create(u32, u32, ImageFormat, TextureFilter, RenderTargetMode, Option<Vec<u8>>),
350-
Update(u32, u32, u32, u32, TextureUpdateDetails),
365+
Update(u32, u32, u32, u32, Vec<u8>, Option<u32>),
351366
Grow(u32, u32, ImageFormat, TextureFilter, RenderTargetMode),
352-
Remove
353367
}
354368

355369
pub struct TextureUpdate {
356-
pub id: TextureId,
370+
pub id: CacheTextureId,
357371
pub op: TextureUpdateOp,
358372
}
359373

webrender/src/prim_store.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use app_units::Au;
6-
use device::TextureId;
76
use euclid::{Point2D, Matrix4D, Rect, Size2D};
87
use gpu_store::{GpuStore, GpuStoreAddress};
9-
use internal_types::{device_pixel, DeviceRect, DeviceSize};
8+
use internal_types::{device_pixel, DeviceRect, DeviceSize, SourceTexture};
109
use resource_cache::ResourceCache;
1110
use std::mem;
1211
use std::usize;
@@ -63,7 +62,7 @@ pub enum PrimitiveClipSource {
6362
#[derive(Debug)]
6463
pub struct PrimitiveMetadata {
6564
pub is_opaque: bool,
66-
pub mask_texture_id: TextureId,
65+
pub mask_texture_id: SourceTexture,
6766
pub clip_index: Option<GpuStoreAddress>,
6867
pub clip_source: Box<PrimitiveClipSource>,
6968
pub prim_kind: PrimitiveKind,
@@ -96,7 +95,7 @@ pub enum ImagePrimitiveKind {
9695
#[derive(Debug)]
9796
pub struct ImagePrimitiveCpu {
9897
pub kind: ImagePrimitiveKind,
99-
pub color_texture_id: TextureId,
98+
pub color_texture_id: SourceTexture,
10099
}
101100

102101
#[derive(Debug, Clone)]
@@ -189,7 +188,7 @@ pub struct TextRunPrimitiveCpu {
189188
pub cache_dirty: bool,
190189
// TODO(gw): Maybe make this an Arc for sharing with resource cache
191190
pub glyph_indices: Vec<u32>,
192-
pub color_texture_id: TextureId,
191+
pub color_texture_id: SourceTexture,
193192
pub color: ColorF,
194193
pub render_mode: FontRenderMode,
195194
}
@@ -413,7 +412,7 @@ impl PrimitiveStore {
413412

414413
let metadata = PrimitiveMetadata {
415414
is_opaque: is_opaque,
416-
mask_texture_id: TextureId::invalid(),
415+
mask_texture_id: SourceTexture::Invalid,
417416
clip_index: None,
418417
clip_source: clip_source,
419418
prim_kind: PrimitiveKind::Rectangle,
@@ -432,7 +431,7 @@ impl PrimitiveStore {
432431

433432
let metadata = PrimitiveMetadata {
434433
is_opaque: false,
435-
mask_texture_id: TextureId::invalid(),
434+
mask_texture_id: SourceTexture::Invalid,
436435
clip_index: None,
437436
clip_source: clip_source,
438437
prim_kind: PrimitiveKind::TextRun,
@@ -451,7 +450,7 @@ impl PrimitiveStore {
451450

452451
let metadata = PrimitiveMetadata {
453452
is_opaque: false,
454-
mask_texture_id: TextureId::invalid(),
453+
mask_texture_id: SourceTexture::Invalid,
455454
clip_index: None,
456455
clip_source: clip_source,
457456
prim_kind: PrimitiveKind::Image,
@@ -470,7 +469,7 @@ impl PrimitiveStore {
470469

471470
let metadata = PrimitiveMetadata {
472471
is_opaque: false,
473-
mask_texture_id: TextureId::invalid(),
472+
mask_texture_id: SourceTexture::Invalid,
474473
clip_index: None,
475474
clip_source: clip_source,
476475
prim_kind: PrimitiveKind::Border,
@@ -490,7 +489,7 @@ impl PrimitiveStore {
490489

491490
let metadata = PrimitiveMetadata {
492491
is_opaque: false,
493-
mask_texture_id: TextureId::invalid(),
492+
mask_texture_id: SourceTexture::Invalid,
494493
clip_index: None,
495494
clip_source: clip_source,
496495
prim_kind: PrimitiveKind::Gradient,
@@ -539,7 +538,7 @@ impl PrimitiveStore {
539538

540539
let metadata = PrimitiveMetadata {
541540
is_opaque: false,
542-
mask_texture_id: TextureId::invalid(),
541+
mask_texture_id: SourceTexture::Invalid,
543542
clip_index: None,
544543
clip_source: clip_source,
545544
prim_kind: PrimitiveKind::BoxShadow,
@@ -729,7 +728,7 @@ impl PrimitiveStore {
729728
let gpu_data = self.gpu_data32.get_slice_mut(gpu_address, 6);
730729
Self::populate_clip_data(gpu_data, data);
731730
metadata.clip_index = Some(gpu_address);
732-
metadata.mask_texture_id = dummy_mask_cache_item.texture_id;
731+
metadata.mask_texture_id = SourceTexture::TextureCache(dummy_mask_cache_item.texture_id);
733732
}
734733
}
735734

0 commit comments

Comments
 (0)