/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use gleam::gl; use glutin::config::{ConfigTemplateBuilder, GlConfig}; use glutin::context::{
ContextApi, ContextAttributesBuilder, NotCurrentGlContext,
PossiblyCurrentContext, Version,
}; use glutin::display::{GetGlDisplay, GlDisplay}; use glutin::surface::{GlSurface, Surface, SurfaceAttributesBuilder, WindowSurface}; use glutin_winit::DisplayBuilder; use std::env; use std::ffi::CString; use std::num::NonZeroU32; use std::path::PathBuf; use std::rc::Rc; use webrender; use webrender::{DebugFlags, ShaderPrecacheFlags}; use webrender::api::*; use webrender::render_api::*; use webrender::api::units::*; use winit::application::ApplicationHandler; use winit::event::{ElementState, KeyEvent, WindowEvent}; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::keyboard::{Key, NamedKey}; use winit::raw_window_handle::{HasWindowHandle, RawWindowHandle}; use winit::window::Window;
let args: Vec<String> = env::args().collect(); let res_path = if args.len() > 1 {
Some(PathBuf::from(&args[1]))
} else {
None
};
let window_attrs = Window::default_attributes()
.with_title(E::TITLE)
.with_inner_size(winit::dpi::LogicalSize::new(E::WIDTH as f64, E::HEIGHT as f64));
let template = ConfigTemplateBuilder::new().with_depth_size(24);
let (window, gl_config) = DisplayBuilder::new()
.with_window_attributes(Some(window_attrs))
.build(event_loop, template, |configs| {
configs.reduce(|acc, config| { if config.num_samples() > acc.num_samples() { config } else { acc }
}).unwrap()
})
.expect("failed to create GL display and window");
let window = window.unwrap(); let gl_display = gl_config.display();
let raw_window_handle: RawWindowHandle = window
.window_handle()
.expect("failed to get window handle")
.as_raw();
// Try OpenGL first, fall back to GLES. let (not_current_ctx, is_gles) = { let gl_attrs = ContextAttributesBuilder::new()
.with_context_api(ContextApi::OpenGl(Some(Version::new(3, 2))))
.build(Some(raw_window_handle)); matchunsafe { gl_display.create_context(&gl_config, &gl_attrs) } {
Ok(ctx) => (ctx, false),
Err(_) => { let gles_attrs = ContextAttributesBuilder::new()
.with_context_api(ContextApi::Gles(Some(Version::new(3, 0))))
.build(Some(raw_window_handle)); let ctx = unsafe { gl_display.create_context(&gl_config, &gles_attrs) }
.expect("failed to create GLES context");
(ctx, true)
}
}
};
let physical_size = window.inner_size(); let surface_attrs = SurfaceAttributesBuilder::<WindowSurface>::new()
.build(
raw_window_handle,
NonZeroU32::new(physical_size.width.max(1)).unwrap(),
NonZeroU32::new(physical_size.height.max(1)).unwrap(),
);
let gl_surface = unsafe {
gl_display
.create_window_surface(&gl_config, &surface_attrs)
.expect("failed to create GL surface")
};
let gl_context = not_current_ctx
.make_current(&gl_surface)
.expect("failed to make GL context current");
let gl = load_gl_fns(is_gles, &gl_display);
println!("OpenGL version {}", gl.get_string(gl::VERSION));
println!("Shader resource path: {:?}", res_path); let device_pixel_ratio = window.scale_factor() as f32;
println!("Device pixel ratio: {}", device_pixel_ratio);
let device_size = { let size = window.inner_size();
DeviceIntSize::new(size.width as i32, size.height as i32)
}; let notifier = Box::new(Notifier::new(self.proxy.clone())); let (mut renderer, sender) = webrender::create_webrender_instance(
gl.clone(),
notifier,
opts,
None,
).unwrap(); letmut api = sender.create_api(); let document_id = api.add_document(device_size);
let window = self.window.as_ref().unwrap(); let api = self.api.as_mut().unwrap(); let renderer = self.renderer.as_mut().unwrap(); let gl = self.gl.as_ref().unwrap(); let gl_surface = self.gl_surface.as_ref().unwrap(); let gl_context = self.gl_context.as_ref().unwrap(); let document_id = self.document_id.unwrap();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.