servoshell: Remove duplicate egl bindings on android/ohos (#34716)

- The default value for SwapInterval is 1,
  so setting it to 1 changes nothing
- We don't clear the screen immediately anymore, which was the only
  useage of the egl bindings

this saves us from duplicated EGL bindings.

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
Jonathan Schwender 2024-12-20 16:08:09 +01:00 committed by GitHub
parent 65c65c9a6a
commit 0dd8798148
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 6 additions and 110 deletions

1
Cargo.lock generated
View file

@ -6594,7 +6594,6 @@ dependencies = [
"euclid",
"getopts",
"gilrs",
"gl_generator",
"gleam",
"glow",
"headers",

View file

@ -23,8 +23,6 @@ bench = false
# must unconditionally add these dependencies. See https://github.com/rust-lang/cargo/issues/4932
[build-dependencies]
vergen-git2 = { version = "1.0.2", features = ["build"] }
# Android and OpenHarmony
gl_generator = "0.14"
# MacOS only
cc = "1.2"

View file

@ -7,19 +7,8 @@ use std::fs::File;
use std::io::Write;
use std::path::Path;
use gl_generator::{Api, Fallbacks, Profile, Registry};
use vergen_git2::{Emitter, Git2Builder};
// We can make this configurable in the future if different platforms start to have
// different needs.
fn generate_egl_bindings(out_dir: &Path) {
let mut file = File::create(out_dir.join("egl_bindings.rs")).unwrap();
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [])
.write_bindings(gl_generator::StaticStructGenerator, &mut file)
.unwrap();
println!("cargo:rustc-link-lib=EGL");
}
fn emit_git_sha() -> Result<(), String> {
let git_options = Git2Builder::default()
.sha(true /* short */)
@ -55,7 +44,6 @@ fn main() -> Result<(), Box<dyn Error>> {
// Note: We can't use `#[cfg(windows)]`, since that would check the host platform
// and not the target platform
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
if target_os == "windows" {
#[cfg(windows)]
@ -72,8 +60,6 @@ fn main() -> Result<(), Box<dyn Error>> {
.file("platform/macos/count_threads.c")
.compile("count_threads");
} else if target_os == "android" {
generate_egl_bindings(out);
// FIXME: We need this workaround since jemalloc-sys still links
// to libgcc instead of libunwind, but Android NDK 23c and above
// don't have libgcc. We can't disable jemalloc for Android as
@ -83,8 +69,6 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut libgcc = File::create(out.join("libgcc.a")).unwrap();
libgcc.write_all(b"INPUT(-lunwind)").unwrap();
println!("cargo:rustc-link-search=native={}", out.display());
} else if target_env == "ohos" {
generate_egl_bindings(out);
}
if let Err(error) = emit_git_sha() {

View file

@ -21,7 +21,6 @@ use simpleservo::{
PromptResult, SERVO,
};
use super::gl_glue;
use super::host_trait::HostTrait;
use super::servo_glue::{Coordinates, ServoGlue};
@ -142,9 +141,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_init<'local>(
let wakeup = Box::new(WakeupCallback::new(callbacks_ref.clone(), &env));
let callbacks = Box::new(HostCallbacks::new(callbacks_ref, &env));
if let Err(err) = gl_glue::init()
.and_then(|egl_init| simpleservo::init(opts, egl_init.gl_wrapper, wakeup, callbacks))
{
if let Err(err) = simpleservo::init(opts, wakeup, callbacks) {
throw(&mut env, err)
};
}

View file

@ -22,7 +22,7 @@ use servo::servo_config::{opts, pref};
use servo::servo_url::ServoUrl;
pub use servo::webrender_api::units::DeviceIntRect;
use servo::webrender_traits::RenderingContext;
use servo::{self, gl, Servo};
use servo::{self, Servo};
use surfman::{Connection, SurfaceType};
use crate::egl::android::resources::ResourceReaderInstance;
@ -56,7 +56,6 @@ pub enum SurfmanIntegration {
/// In the future, this will be done in multiple steps.
pub fn init(
mut init_opts: InitOptions,
gl: Rc<dyn gl::Gl>,
waker: Box<dyn EventLoopWaker>,
callbacks: Box<dyn HostTrait>,
) -> Result<(), &'static str> {
@ -78,10 +77,6 @@ pub fn init(
let url = embedder_url.or(pref_url).or(blank_url).unwrap();
gl.clear_color(1.0, 1.0, 1.0, 1.0);
gl.clear(gl::COLOR_BUFFER_BIT);
gl.finish();
// Initialize surfman
let connection = Connection::new().or(Err("Failed to create connection"))?;
let adapter = connection
@ -112,7 +107,6 @@ pub fn init(
waker,
#[cfg(feature = "webxr")]
init_opts.xr_discovery,
gl.clone(),
));
let servo = Servo::new(

View file

@ -1,54 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#![allow(non_camel_case_types)]
#![allow(unused_imports)]
pub type ServoGl = std::rc::Rc<dyn servo::gl::Gl>;
use std::ffi::CString;
use std::os::raw::c_void;
use log::info;
use servo::gl::GlesFns;
pub type EGLNativeWindowType = *const libc::c_void;
pub type khronos_utime_nanoseconds_t = khronos_uint64_t;
pub type khronos_uint64_t = u64;
pub type khronos_ssize_t = libc::c_long;
pub type EGLint = i32;
pub type EGLContext = *const libc::c_void;
pub type EGLNativeDisplayType = *const libc::c_void;
pub type EGLNativePixmapType = *const libc::c_void;
pub type NativeDisplayType = EGLNativeDisplayType;
pub type NativePixmapType = EGLNativePixmapType;
pub type NativeWindowType = EGLNativeWindowType;
include!(concat!(env!("OUT_DIR"), "/egl_bindings.rs"));
pub struct EGLInitResult {
pub gl_wrapper: ServoGl,
pub gl_context: EGLContext,
pub display: EGLNativeDisplayType,
}
pub fn init() -> Result<EGLInitResult, &'static str> {
info!("Loading EGL...");
unsafe {
let egl = Egl;
let display = egl.GetCurrentDisplay();
egl.SwapInterval(display, 1);
let egl = GlesFns::load_with(|addr| {
let addr = CString::new(addr.as_bytes()).unwrap();
let addr = addr.as_ptr();
let egl = Egl;
egl.GetProcAddress(addr) as *const c_void
});
info!("EGL loaded");
Ok(EGLInitResult {
gl_wrapper: egl,
gl_context: Egl.GetCurrentContext(),
display,
})
}
}

View file

@ -2,9 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#[cfg(any(target_os = "android", target_env = "ohos"))]
pub mod gl_glue;
#[cfg(target_os = "android")]
mod android;

View file

@ -36,7 +36,6 @@ use xcomponent_sys::{
OH_NativeXComponent_GetKeyEventCode, OH_NativeXComponent_KeyAction, OH_NativeXComponent_KeyCode,
};
use super::gl_glue;
use super::host_trait::HostTrait;
use super::servo_glue::ServoGlue;
@ -240,7 +239,6 @@ extern "C" fn on_surface_created_cb(xcomponent: *mut OH_NativeXComponent, window
let wakeup = Box::new(WakeupCallback::new(tx));
let callbacks = Box::new(HostCallbacks::new());
let egl_init = gl_glue::init().expect("egl::init() failed");
let xc = xc_wrapper;
let window = window_wrapper;
let init_opts = if let Ok(ServoAction::Initialize(init_opts)) = rx.recv() {
@ -248,15 +246,8 @@ extern "C" fn on_surface_created_cb(xcomponent: *mut OH_NativeXComponent, window
} else {
panic!("Servos GL thread received another event before it was initialized")
};
let mut servo = simpleservo::init(
*init_opts,
window.0,
xc.0,
egl_init.gl_wrapper,
wakeup,
callbacks,
)
.expect("Servo initialization failed");
let mut servo = simpleservo::init(*init_opts, window.0, xc.0, wakeup, callbacks)
.expect("Servo initialization failed");
info!("Surface created!");
let native_vsync =

View file

@ -21,7 +21,7 @@ use servo::servo_config::opts;
use servo::servo_config::opts::ArgumentParsingResult;
use servo::servo_url::ServoUrl;
use servo::webrender_traits::RenderingContext;
use servo::{self, gl, Servo};
use servo::{self, Servo};
use surfman::{Connection, SurfaceType};
use crate::egl::host_trait::HostTrait;
@ -37,7 +37,6 @@ pub fn init(
options: InitOpts,
native_window: *mut c_void,
xcomponent: *mut OH_NativeXComponent,
gl: Rc<dyn gl::Gl>,
waker: Box<dyn EventLoopWaker>,
callbacks: Box<dyn HostTrait>,
) -> Result<ServoGlue, &'static str> {
@ -92,10 +91,6 @@ pub fn init(
crate::prefs::register_user_prefs(&opts_matches);
gl.clear_color(1.0, 1.0, 1.0, 1.0);
gl.clear(gl::COLOR_BUFFER_BIT);
gl.finish();
// Initialize surfman
let connection = Connection::new().or(Err("Failed to create connection"))?;
let adapter = connection
@ -139,7 +134,6 @@ pub fn init(
waker,
#[cfg(feature = "webxr")]
None,
gl.clone(),
));
let servo = Servo::new(

View file

@ -28,7 +28,7 @@ use servo::servo_geometry::DeviceIndependentPixel;
use servo::webrender_api::units::DevicePixel;
use servo::webrender_api::ScrollLocation;
use servo::webrender_traits::RenderingContext;
use servo::{gl, Servo, TopLevelBrowsingContextId};
use servo::{Servo, TopLevelBrowsingContextId};
use crate::egl::host_trait::HostTrait;
@ -660,21 +660,17 @@ pub(super) struct ServoEmbedderCallbacks {
waker: Box<dyn EventLoopWaker>,
#[cfg(feature = "webxr")]
xr_discovery: Option<webxr::Discovery>,
#[allow(unused)]
gl: Rc<dyn gl::Gl>,
}
impl ServoEmbedderCallbacks {
pub(super) fn new(
waker: Box<dyn EventLoopWaker>,
#[cfg(feature = "webxr")] xr_discovery: Option<webxr::Discovery>,
gl: Rc<dyn gl::Gl>,
) -> Self {
Self {
waker,
#[cfg(feature = "webxr")]
xr_discovery,
gl,
}
}
}