tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

alpha_perf.rs (2615B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 extern crate euclid;
      6 extern crate gleam;
      7 extern crate glutin;
      8 extern crate webrender;
      9 extern crate winit;
     10 
     11 #[path = "common/boilerplate.rs"]
     12 mod boilerplate;
     13 
     14 use crate::boilerplate::{Example, HandyDandyRectBuilder};
     15 use std::cmp;
     16 use webrender::api::*;
     17 use webrender::render_api::*;
     18 use webrender::api::units::DeviceIntSize;
     19 
     20 
     21 struct App {
     22    rect_count: usize,
     23 }
     24 
     25 impl Example for App {
     26    fn render(
     27        &mut self,
     28        _api: &mut RenderApi,
     29        builder: &mut DisplayListBuilder,
     30        _txn: &mut Transaction,
     31        _device_size: DeviceIntSize,
     32        pipeline_id: PipelineId,
     33        _document_id: DocumentId,
     34    ) {
     35        let bounds = (0, 0).to(1920, 1080);
     36        let space_and_clip = SpaceAndClipInfo::root_scroll(pipeline_id);
     37 
     38        builder.push_simple_stacking_context(
     39            bounds.min,
     40            space_and_clip.spatial_id,
     41            PrimitiveFlags::IS_BACKFACE_VISIBLE,
     42        );
     43 
     44        for _ in 0 .. self.rect_count {
     45            builder.push_rect(
     46                &CommonItemProperties::new(bounds, space_and_clip),
     47                bounds,
     48                ColorF::new(1.0, 1.0, 1.0, 0.05)
     49            );
     50        }
     51 
     52        builder.pop_stacking_context();
     53    }
     54 
     55    fn on_event(
     56        &mut self,
     57        event: winit::event::WindowEvent,
     58        _window: &winit::window::Window,
     59        _api: &mut RenderApi,
     60        _document_id: DocumentId,
     61    ) -> bool {
     62        match event {
     63            winit::event::WindowEvent::KeyboardInput {
     64                input: winit::event::KeyboardInput {
     65                    state: winit::event::ElementState::Pressed,
     66                    virtual_keycode: Some(key),
     67                    ..
     68                },
     69                ..
     70            } => {
     71                match key {
     72                    winit::event::VirtualKeyCode::Right => {
     73                        self.rect_count += 1;
     74                        println!("rects = {}", self.rect_count);
     75                    }
     76                    winit::event::VirtualKeyCode::Left => {
     77                        self.rect_count = cmp::max(self.rect_count, 1) - 1;
     78                        println!("rects = {}", self.rect_count);
     79                    }
     80                    _ => {}
     81                };
     82            }
     83            _ => (),
     84        }
     85 
     86        true
     87    }
     88 }
     89 
     90 fn main() {
     91    let mut app = App {
     92        rect_count: 1,
     93    };
     94    boilerplate::main_wrapper(&mut app, None);
     95 }