/* 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::ffi::CString; use std::fs::File; use std::io::Read; use std::num::NonZeroU32; use std::rc::Rc; use webrender::api::*; use webrender::api::units::*; use webrender::render_api::*; use webrender::DebugFlags; use winit::application::ApplicationHandler; use winit::dpi::LogicalSize; use winit::event::{ElementState, KeyEvent, WindowEvent}; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::keyboard::{Key, NamedKey}; use winit::raw_window_handle::{HasWindowHandle, RawWindowHandle};
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();
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);
let opts = webrender::WebRenderOptions {
clear_color,
..webrender::WebRenderOptions::default()
};
let device_size = { let size = window.inner_size();
DeviceIntSize::new(size.width as i32, size.height as i32)
}; let notifier = Box::new(Notifier::new(proxy.clone())); let (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 epoch = Epoch(0); let pipeline_id = PipelineId(0, 0); letmut txn = Transaction::new();
let font_key = api.generate_font_key(); let font_bytes = load_file("../wrench/reftests/text/FreeSans.ttf");
txn.add_raw_font(font_key, font_bytes, 0);
let font_instance_key = api.generate_font_instance_key();
txn.add_font_instance(font_instance_key, font_key, 32.0, None, None, Vec::new());
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.