@@ -8,8 +8,9 @@ use euclid::{Size2D, Point2D, Rect, Matrix4D};
8
8
use gleam:: gl;
9
9
use std:: path:: PathBuf ;
10
10
use std:: ffi:: CStr ;
11
- use webrender_traits:: { AuxiliaryListsBuilder , ColorF , Epoch , GlyphInstance } ;
12
- use webrender_traits:: { ImageFormat , PipelineId , RendererKind } ;
11
+ use webrender:: { ExternalImage , ExternalImageHandler } ;
12
+ use webrender_traits:: { AuxiliaryListsBuilder , ColorF , Epoch , GlyphInstance , ExternalImageId } ;
13
+ use webrender_traits:: { ImageData , ImageFormat , PipelineId , RendererKind , ImageRendering } ;
13
14
use std:: fs:: File ;
14
15
use std:: io:: Read ;
15
16
use std:: env;
@@ -53,6 +54,49 @@ impl webrender_traits::RenderNotifier for Notifier {
53
54
}
54
55
}
55
56
57
+ struct ImageHandler {
58
+ data : Vec < u8 > ,
59
+ frame : u64 ,
60
+ }
61
+
62
+ impl ImageHandler {
63
+ fn new ( ) -> ImageHandler {
64
+ ImageHandler {
65
+ frame : 0 ,
66
+ data : vec ! [ 0xff , 0x00 , 0x00 , 0xff ,
67
+ 0x00 , 0xff , 0x00 , 0xff ,
68
+ 0x00 , 0x00 , 0xff , 0xff ,
69
+ 0x00 , 0xff , 0xff , 0xff ] ,
70
+ }
71
+ }
72
+ }
73
+
74
+ impl ExternalImageHandler for ImageHandler {
75
+ fn lock_image ( & mut self , _: ExternalImageId ) -> ExternalImage {
76
+ self . frame += 1 ;
77
+
78
+ if self . frame == 10 {
79
+ self . data = vec ! [ 0x00 , 0x00 , 0x00 , 0xff ,
80
+ 0xff , 0xff , 0xff , 0xff ,
81
+ 0xff , 0xff , 0xff , 0xff ,
82
+ 0x00 , 0x00 , 0x00 , 0xff ] ;
83
+ }
84
+
85
+ ExternalImage {
86
+ timestamp : self . frame ,
87
+ u0 : 0.0 ,
88
+ v0 : 0.0 ,
89
+ u1 : 2.0 ,
90
+ v1 : 2.0 ,
91
+ data : self . data . as_ptr ( ) ,
92
+ len : self . data . len ( ) ,
93
+ }
94
+ }
95
+
96
+ fn unlock_image ( & mut self , _: ExternalImageId ) {
97
+ }
98
+ }
99
+
56
100
fn main ( ) {
57
101
let args: Vec < String > = env:: args ( ) . collect ( ) ;
58
102
if args. len ( ) != 2 {
@@ -106,6 +150,7 @@ fn main() {
106
150
107
151
let notifier = Box :: new ( Notifier :: new ( window. create_window_proxy ( ) ) ) ;
108
152
renderer. set_render_notifier ( notifier) ;
153
+ renderer. set_external_image_handler ( Box :: new ( ImageHandler :: new ( ) ) ) ;
109
154
110
155
let pipeline_id = PipelineId ( 0 , 0 ) ;
111
156
let epoch = Epoch ( 0 ) ;
@@ -135,7 +180,7 @@ fn main() {
135
180
let clip_region = {
136
181
let rect = Rect :: new ( Point2D :: new ( 100.0 , 100.0 ) , Size2D :: new ( 100.0 , 100.0 ) ) ;
137
182
let mask = webrender_traits:: ImageMask {
138
- image : api. add_image ( 2 , 2 , None , ImageFormat :: A8 , vec ! [ 0 , 80 , 180 , 255 ] ) ,
183
+ image : api. add_image ( 2 , 2 , None , ImageFormat :: A8 , ImageData :: Raw ( vec ! [ 0 , 80 , 180 , 255 ] ) ) ,
139
184
rect : rect,
140
185
repeat : false ,
141
186
} ;
@@ -154,6 +199,22 @@ fn main() {
154
199
155
200
let _text_bounds = Rect :: new ( Point2D :: new ( 100.0 , 200.0 ) , Size2D :: new ( 700.0 , 300.0 ) ) ;
156
201
202
+ let ext_id = ExternalImageId ( 0 ) ;
203
+ let image_key = api. add_image ( 2 , 2 , None , ImageFormat :: RGBA8 , ImageData :: External ( ext_id) ) ;
204
+
205
+ let ext_image_rect = Rect :: new ( Point2D :: new ( 300.0 , 100.0 ) , Size2D :: new ( 100.0 , 100.0 ) ) ;
206
+ let ext_image_clip_region = webrender_traits:: ClipRegion :: new ( & ext_image_rect,
207
+ vec ! [ ] ,
208
+ None ,
209
+ & mut auxiliary_lists_builder) ;
210
+
211
+ builder. push_image ( ext_image_rect,
212
+ ext_image_clip_region,
213
+ Size2D :: new ( 100.0 , 100.0 ) ,
214
+ Size2D :: zero ( ) ,
215
+ ImageRendering :: Auto ,
216
+ image_key) ;
217
+
157
218
let _glyphs = vec ! [
158
219
GlyphInstance {
159
220
index: 48 ,
0 commit comments