Skip to content

Commit

Permalink
WR - use struct ExternalImageData to present the different external t…
Browse files Browse the repository at this point in the history
…exture handle type.
  • Loading branch information
JerryShih committed Mar 26, 2017
1 parent 0981276 commit b4e91e1
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 140 deletions.
4 changes: 2 additions & 2 deletions webrender/src/internal_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use tiling;
use renderer::BlendMode;
use webrender_traits::{Epoch, ColorF, PipelineId, DeviceIntSize};
use webrender_traits::{ImageFormat, NativeFontHandle};
use webrender_traits::{ExternalImageId, ScrollLayerId, WebGLCommand};
use webrender_traits::{ExternalImageData, ExternalImageId, ScrollLayerId, WebGLCommand};
use webrender_traits::{ImageData};
use webrender_traits::{DeviceUintRect};

Expand All @@ -49,7 +49,7 @@ pub enum SourceTexture {
Invalid,
TextureCache(CacheTextureId),
WebGL(u32), // Is actually a gl::GLuint
External(ExternalImageId),
External(ExternalImageData),
}

pub enum GLContextHandleWrapper {
Expand Down
6 changes: 3 additions & 3 deletions webrender/src/prim_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,8 @@ impl PrimitiveStore {

// Check if an external image that needs to be resolved
// by the render thread.
match image_properties.external_id {
Some(external_id) => {
match image_properties.external_image {
Some(external_image) => {
// This is an external texture - we will add it to
// the deferred resolves list to be patched by
// the render thread...
Expand All @@ -874,7 +874,7 @@ impl PrimitiveStore {
resource_address: image_uv_address,
});

(SourceTexture::External(external_id), None)
(SourceTexture::External(external_image), None)
}
None => {
let cache_item = resource_cache.get_cached_image(image_key, image_rendering, tile_offset);
Expand Down
57 changes: 32 additions & 25 deletions webrender/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use time::precise_time_ns;
use thread_profiler::{register_thread_with_profiler, write_profile};
use util::TransformedRectKind;
use webrender_traits::{ColorF, Epoch, PipelineId, RenderNotifier, RenderDispatcher};
use webrender_traits::{ExternalImageId, ImageData, ImageFormat, RenderApiSender};
use webrender_traits::{ExternalImageId, ExternalImageType, ImageData, ImageFormat, RenderApiSender};
use webrender_traits::{DeviceIntRect, DevicePoint, DeviceIntPoint, DeviceIntSize, DeviceUintSize};
use webrender_traits::{ImageDescriptor, BlobImageRenderer};
use webrender_traits::channel;
Expand Down Expand Up @@ -1038,10 +1038,10 @@ impl Renderer {
fn resolve_source_texture(&mut self, texture_id: &SourceTexture) -> TextureId {
match *texture_id {
SourceTexture::Invalid => TextureId::invalid(),
SourceTexture::WebGL(id) => TextureId::new(id),
SourceTexture::External(ref key) => {
SourceTexture::WebGL(id) => TextureId::new(id, TextureTarget::Default),
SourceTexture::External(external_image) => {
*self.external_images
.get(key)
.get(&external_image.id)
.expect("BUG: External image should be resolved by now!")
}
SourceTexture::TextureCache(index) => {
Expand Down Expand Up @@ -1192,24 +1192,31 @@ impl Renderer {
mode,
Some(raw.as_slice()));
}
ImageData::ExternalBuffer(id) => {
let handler = self.external_image_handler
.as_mut()
.expect("Found external image, but no handler set!");

match handler.lock(id).source {
ExternalImageSource::RawData(raw) => {
self.device.init_texture(texture_id,
width,
height,
format,
filter,
mode,
Some(raw));
ImageData::External(ext_image) => {
match ext_image.image_type {
ExternalImageType::ExternalBuffer => {
let handler = self.external_image_handler
.as_mut()
.expect("Found external image, but no handler set!");

match handler.lock(ext_image.id).source {
ExternalImageSource::RawData(raw) => {
self.device.init_texture(texture_id,
width,
height,
format,
filter,
mode,
Some(raw));
}
_ => panic!("No external buffer found"),
};
handler.unlock(ext_image.id);
}
_ => panic!("No external buffer found"),
};
handler.unlock(id);
_ => {
panic!("External texture handle should not use TextureUpdateOp::Create.");
}
}
}
_ => {
panic!("No suitable image buffer for TextureUpdateOp::Create.");
Expand Down Expand Up @@ -1641,16 +1648,16 @@ impl Renderer {
for deferred_resolve in &frame.deferred_resolves {
GpuMarker::fire(self.device.gl(), "deferred resolve");
let props = &deferred_resolve.image_properties;
let external_id = props.external_id
.expect("BUG: Deferred resolves must be external images!");
let image = handler.lock(external_id);
let ext_image = props.external_image
.expect("BUG: Deferred resolves must be external images!");
let image = handler.lock(ext_image.id);

let texture_id = match image.source {
ExternalImageSource::NativeTexture(texture_id) => TextureId::new(texture_id),
_ => panic!("No native texture found."),
};

self.external_images.insert(external_id, texture_id);
self.external_images.insert(ext_image.id, texture_id);
let resource_rect_index = deferred_resolve.resource_address.0 as usize;
let resource_rect = &mut frame.gpu_resource_rects[resource_rect_index];
resource_rect.uv0 = DevicePoint::new(image.u0, image.v0);
Expand Down
Loading

0 comments on commit b4e91e1

Please sign in to comment.