Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce SourceTexture, an abstraction for location of source textures. #554

Merged
merged 2 commits into from
Nov 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 0 additions & 111 deletions webrender/src/batch.rs

This file was deleted.

50 changes: 2 additions & 48 deletions webrender/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,6 @@ pub struct Device {
// resources
resource_path: PathBuf,
textures: HashMap<TextureId, Texture, BuildHasherDefault<FnvHasher>>,
raw_textures: HashMap<TextureId, (u32, u32, u32, u32), BuildHasherDefault<FnvHasher>>,
programs: HashMap<ProgramId, Program, BuildHasherDefault<FnvHasher>>,
vaos: HashMap<VAOId, VAO, BuildHasherDefault<FnvHasher>>,

Expand Down Expand Up @@ -778,7 +777,6 @@ impl Device {
default_fbo: 0,

textures: HashMap::with_hasher(Default::default()),
raw_textures: HashMap::with_hasher(Default::default()),
programs: HashMap::with_hasher(Default::default()),
vaos: HashMap::with_hasher(Default::default()),

Expand Down Expand Up @@ -946,33 +944,8 @@ impl Device {
}

pub fn get_texture_dimensions(&self, texture_id: TextureId) -> (u32, u32) {
if let Some(texture) = self.textures.get(&texture_id) {
(texture.width, texture.height)
} else {
let dimensions = self.raw_textures.get(&texture_id).unwrap();
(dimensions.2, dimensions.3)
}
}

pub fn texture_has_alpha(&self, texture_id: TextureId) -> bool {
if let Some(texture) = self.textures.get(&texture_id) {
texture.format == ImageFormat::RGBA8
} else {
true
}
}

pub fn update_raw_texture(&mut self,
texture_id: TextureId,
x0: u32,
y0: u32,
width: u32,
height: u32) {
self.raw_textures.insert(texture_id, (x0, y0, width, height));
}

pub fn remove_raw_texture(&mut self, texture_id: TextureId) {
self.raw_textures.remove(&texture_id);
let texture = &self.textures[&texture_id];
(texture.width, texture.height)
}

fn set_texture_parameters(&mut self, target: gl::GLuint, filter: TextureFilter) {
Expand Down Expand Up @@ -1526,25 +1499,6 @@ impl Device {
}
}

pub fn read_framebuffer_rect(&mut self,
texture_id: TextureId,
dest_x: i32,
dest_y: i32,
src_x: i32,
src_y: i32,
width: i32,
height: i32) {
self.bind_texture(DEFAULT_TEXTURE, texture_id);
gl::copy_tex_sub_image_2d(texture_id.target,
0,
dest_x,
dest_y,
src_x as gl::GLint,
src_y as gl::GLint,
width as gl::GLint,
height as gl::GLint);
}

fn clear_vertex_array(&mut self) {
debug_assert!(self.inside_frame);
gl::bind_vertex_array(0);
Expand Down
60 changes: 37 additions & 23 deletions webrender/src/internal_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

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

// An ID for a texture that is owned by the
// texture cache module. This can include atlases
// or standalone textures allocated via the
// texture cache (e.g. if an image is too large
// to be added to an atlas). The texture cache
// manages the allocation and freeing of these
// IDs, and the rendering thread maintains a
// map from cache texture ID to native texture.

#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct CacheTextureId(pub usize);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the long term, I'd like to have types like this opaque (non-public internals), but this can (and should) be done later on as a separate change


// Represents the source for a texture.
// These are passed from throughout the
// pipeline until they reach the rendering
// thread, where they are resolved to a
// native texture ID.

#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum SourceTexture {
Invalid,
TextureCache(CacheTextureId),
WebGL(u32), // Is actually a gl::GLuint

// TODO(gw): Implement external image support via callback
//External(i32),
}

pub enum GLContextHandleWrapper {
Native(NativeGLContextHandle),
OSMesa(OSMesaContextHandle),
Expand Down Expand Up @@ -194,15 +222,15 @@ impl TextureSampler {
/// Textures that are not used by the batch are equal to TextureId::invalid().
#[derive(Copy, Clone, Debug)]
pub struct BatchTextures {
pub colors: [TextureId; 3],
pub mask: TextureId,
pub colors: [SourceTexture; 3],
pub mask: SourceTexture,
}

impl BatchTextures {
pub fn no_texture() -> Self {
BatchTextures {
colors: [TextureId::invalid(); 3],
mask: TextureId::invalid(),
colors: [SourceTexture::Invalid; 3],
mask: SourceTexture::Invalid,
}
}
}
Expand Down Expand Up @@ -332,28 +360,14 @@ pub enum RenderTargetMode {
LayerRenderTarget(i32), // Number of texture layers
}

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

#[derive(Clone, Copy, Debug)]
pub struct TextureImage {
pub texture_id: TextureId,
pub texel_uv: Rect<f32>,
pub pixel_uv: Point2D<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),
Remove
}

pub struct TextureUpdate {
pub id: TextureId,
pub id: CacheTextureId,
pub op: TextureUpdateOp,
}

Expand Down
23 changes: 11 additions & 12 deletions webrender/src/prim_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use app_units::Au;
use device::TextureId;
use euclid::{Point2D, Matrix4D, Rect, Size2D};
use gpu_store::{GpuStore, GpuStoreAddress};
use internal_types::{device_pixel, DeviceRect, DeviceSize};
use internal_types::{device_pixel, DeviceRect, DeviceSize, SourceTexture};
use resource_cache::ResourceCache;
use std::mem;
use std::usize;
Expand Down Expand Up @@ -63,7 +62,7 @@ pub enum PrimitiveClipSource {
#[derive(Debug)]
pub struct PrimitiveMetadata {
pub is_opaque: bool,
pub mask_texture_id: TextureId,
pub mask_texture_id: SourceTexture,
pub clip_index: Option<GpuStoreAddress>,
pub clip_source: Box<PrimitiveClipSource>,
pub prim_kind: PrimitiveKind,
Expand Down Expand Up @@ -96,7 +95,7 @@ pub enum ImagePrimitiveKind {
#[derive(Debug)]
pub struct ImagePrimitiveCpu {
pub kind: ImagePrimitiveKind,
pub color_texture_id: TextureId,
pub color_texture_id: SourceTexture,
}

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

let metadata = PrimitiveMetadata {
is_opaque: is_opaque,
mask_texture_id: TextureId::invalid(),
mask_texture_id: SourceTexture::Invalid,
clip_index: None,
clip_source: clip_source,
prim_kind: PrimitiveKind::Rectangle,
Expand All @@ -432,7 +431,7 @@ impl PrimitiveStore {

let metadata = PrimitiveMetadata {
is_opaque: false,
mask_texture_id: TextureId::invalid(),
mask_texture_id: SourceTexture::Invalid,
clip_index: None,
clip_source: clip_source,
prim_kind: PrimitiveKind::TextRun,
Expand All @@ -451,7 +450,7 @@ impl PrimitiveStore {

let metadata = PrimitiveMetadata {
is_opaque: false,
mask_texture_id: TextureId::invalid(),
mask_texture_id: SourceTexture::Invalid,
clip_index: None,
clip_source: clip_source,
prim_kind: PrimitiveKind::Image,
Expand All @@ -470,7 +469,7 @@ impl PrimitiveStore {

let metadata = PrimitiveMetadata {
is_opaque: false,
mask_texture_id: TextureId::invalid(),
mask_texture_id: SourceTexture::Invalid,
clip_index: None,
clip_source: clip_source,
prim_kind: PrimitiveKind::Border,
Expand All @@ -490,7 +489,7 @@ impl PrimitiveStore {

let metadata = PrimitiveMetadata {
is_opaque: false,
mask_texture_id: TextureId::invalid(),
mask_texture_id: SourceTexture::Invalid,
clip_index: None,
clip_source: clip_source,
prim_kind: PrimitiveKind::Gradient,
Expand Down Expand Up @@ -539,7 +538,7 @@ impl PrimitiveStore {

let metadata = PrimitiveMetadata {
is_opaque: false,
mask_texture_id: TextureId::invalid(),
mask_texture_id: SourceTexture::Invalid,
clip_index: None,
clip_source: clip_source,
prim_kind: PrimitiveKind::BoxShadow,
Expand Down Expand Up @@ -729,7 +728,7 @@ impl PrimitiveStore {
let gpu_data = self.gpu_data32.get_slice_mut(gpu_address, 6);
Self::populate_clip_data(gpu_data, data);
metadata.clip_index = Some(gpu_address);
metadata.mask_texture_id = dummy_mask_cache_item.texture_id;
metadata.mask_texture_id = SourceTexture::TextureCache(dummy_mask_cache_item.texture_id);
}
}

Expand Down
Loading