Skip to content

Commit

Permalink
Use chains API from surfman (servo#209)
Browse files Browse the repository at this point in the history
Since this change touches use statements, it also formats them to be in
the more familiar rust style.
  • Loading branch information
mrobinson authored Aug 10, 2023
1 parent 798bf4d commit d817d07
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 212 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ members = [
"webxr",
"webxr-api"
]

3 changes: 1 addition & 2 deletions webxr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ gvr-sys = { version = "0.7", optional = true }
openxr = { git = "https://github.com/servo/openxrs.git", branch="secondary-views-2", optional = true }
serde = { version = "1.0", optional = true }
sparkle = "0.1"
surfman = "0.7"
surfman-chains = "0.8"
surfman = { version = "0.8", features = ["chains"] }
time = "0.1.42"

[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
92 changes: 18 additions & 74 deletions webxr/glwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,26 @@
* 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/. */

use crate::SurfmanGL;
use crate::SurfmanLayerManager;

use euclid::Angle;
use euclid::Point2D;
use euclid::Rect;
use euclid::RigidTransform3D;
use euclid::Rotation3D;
use euclid::Size2D;
use euclid::Transform3D;
use euclid::UnknownUnit;
use euclid::Vector3D;

use sparkle::gl;
use sparkle::gl::GLuint;
use sparkle::gl::Gl;

use crate::{SurfmanGL, SurfmanLayerManager};
use euclid::{
Angle, Point2D, Rect, RigidTransform3D, Rotation3D, Size2D, Transform3D, UnknownUnit, Vector3D,
};
use sparkle::gl::{self, GLuint, Gl};
use std::ffi::c_void;
use std::rc::Rc;

use surfman::Adapter;
use surfman::Connection;
use surfman::Context as SurfmanContext;
use surfman::ContextAttributes;
use surfman::Device as SurfmanDevice;
use surfman::GLApi;
use surfman::NativeWidget;
use surfman::SurfaceAccess;
use surfman::SurfaceType;

use surfman_chains::SwapChain;
use surfman_chains::SwapChainAPI;
use surfman_chains::SwapChains;
use surfman_chains::SwapChainsAPI;

use surfman::chains::{PreserveBuffer, SwapChain, SwapChainAPI, SwapChains, SwapChainsAPI};
use surfman::{
Adapter, Connection, Context as SurfmanContext, ContextAttributes, Device as SurfmanDevice,
GLApi, NativeWidget, SurfaceAccess, SurfaceType,
};
use webxr_api::util::ClipPlanes;
use webxr_api::ContextId;
use webxr_api::DeviceAPI;
use webxr_api::DiscoveryAPI;
use webxr_api::Display;
use webxr_api::Error;
use webxr_api::Event;
use webxr_api::EventBuffer;
use webxr_api::Floor;
use webxr_api::Frame;
use webxr_api::InputSource;
use webxr_api::LayerGrandManager;
use webxr_api::LayerId;
use webxr_api::LayerInit;
use webxr_api::LayerManager;
use webxr_api::Native;
use webxr_api::Quitter;
use webxr_api::Sender;
use webxr_api::Session;
use webxr_api::SessionBuilder;
use webxr_api::SessionInit;
use webxr_api::SessionMode;
use webxr_api::SomeEye;
use webxr_api::View;
use webxr_api::Viewer;
use webxr_api::ViewerPose;
use webxr_api::Viewport;
use webxr_api::Viewports;
use webxr_api::Views;
use webxr_api::CUBE_BACK;
use webxr_api::CUBE_BOTTOM;
use webxr_api::CUBE_LEFT;
use webxr_api::CUBE_RIGHT;
use webxr_api::CUBE_TOP;
use webxr_api::LEFT_EYE;
use webxr_api::RIGHT_EYE;
use webxr_api::VIEWER;
use webxr_api::{
ContextId, DeviceAPI, DiscoveryAPI, Display, Error, Event, EventBuffer, Floor, Frame,
InputSource, LayerGrandManager, LayerId, LayerInit, LayerManager, Native, Quitter, Sender,
Session, SessionBuilder, SessionInit, SessionMode, SomeEye, View, Viewer, ViewerPose, Viewport,
Viewports, Views, CUBE_BACK, CUBE_BOTTOM, CUBE_LEFT, CUBE_RIGHT, CUBE_TOP, LEFT_EYE, RIGHT_EYE,
VIEWER,
};

// How far off the ground are the viewer's eyes?
const HEIGHT: f32 = 1.0;
Expand Down Expand Up @@ -322,11 +270,7 @@ impl DeviceAPI for GlWindowDevice {
Some(target_swap_chain) => {
// Rendering to a surfman swap chain
target_swap_chain
.swap_buffers(
&mut self.device,
&mut self.context,
surfman_chains::PreserveBuffer::No,
)
.swap_buffers(&mut self.device, &mut self.context, PreserveBuffer::No)
.unwrap();
}
None => {
Expand Down
70 changes: 17 additions & 53 deletions webxr/googlevr/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,27 @@
* 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/. */

use webxr_api::util::{self, ClipPlanes};
use webxr_api::ContextId;
use webxr_api::DeviceAPI;
use webxr_api::Error;
use webxr_api::Event;
use webxr_api::EventBuffer;
use webxr_api::Floor;
use webxr_api::Frame;
use webxr_api::InputFrame;
use webxr_api::InputId;
use webxr_api::InputSource;
use webxr_api::LayerGrandManager;
use webxr_api::LayerId;
use webxr_api::LayerInit;
use webxr_api::LayerManager;
use webxr_api::Native;
use webxr_api::Quitter;
use webxr_api::Sender;
use webxr_api::TargetRayMode;
use webxr_api::View;
use webxr_api::Viewer;
use webxr_api::ViewerPose;
use webxr_api::Viewports;
use webxr_api::Views;

use super::discovery::SendPtr;
use super::input::GoogleVRController;
use crate::gles as gl;
use crate::SurfmanGL;
use crate::SurfmanLayerManager;

use crate::{SurfmanGL, SurfmanLayerManager};
use euclid::default::Size2D as DefaultSize2D;
use euclid::Point2D;
use euclid::Rect;
use euclid::RigidTransform3D;
use euclid::Rotation3D;
use euclid::Size2D;
use euclid::Transform3D;
use euclid::Vector3D;

use gvr_sys as gvr;
use gvr_sys::gvr_color_format_type::*;
use gvr_sys::gvr_depth_stencil_format_type::*;
use gvr_sys::gvr_feature::*;

use euclid::{Point2D, Rect, RigidTransform3D, Rotation3D, Size2D, Transform3D, Vector3D};
use gvr_sys::{
self as gvr, gvr_color_format_type::*, gvr_depth_stencil_format_type::*, gvr_feature::*,
};
use log::warn;

use std::{mem, ptr};

use super::discovery::SendPtr;
use super::input::GoogleVRController;

use surfman::Connection as SurfmanConnection;
use surfman::Context as SurfmanContext;
use surfman::Device as SurfmanDevice;

use surfman_chains::SwapChainAPI;
use surfman_chains::SwapChains;
use surfman_chains::SwapChainsAPI;
use surfman::chains::{SwapChainAPI, SwapChains, SwapChainsAPI};
use surfman::{
Connection as SurfmanConnection, Context as SurfmanContext, Device as SurfmanDevice,
};
use webxr_api::util::{self, ClipPlanes};
use webxr_api::{
ContextId, DeviceAPI, Error, Event, EventBuffer, Floor, Frame, InputFrame, InputId,
InputSource, LayerGrandManager, LayerId, LayerInit, LayerManager, Native, Quitter, Sender,
TargetRayMode, View, Viewer, ViewerPose, Viewports, Views,
};

#[cfg(target_os = "android")]
use crate::jni_utils::JNIScope;
Expand Down
63 changes: 10 additions & 53 deletions webxr/headless/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,19 @@

use crate::SurfmanGL;
use crate::SurfmanLayerManager;

use webxr_api::util::{self, ClipPlanes, HitTestList};
use webxr_api::ApiSpace;
use webxr_api::BaseSpace;
use webxr_api::ContextId;
use webxr_api::DeviceAPI;
use webxr_api::DiscoveryAPI;
use webxr_api::Error;
use webxr_api::Event;
use webxr_api::EventBuffer;
use webxr_api::Floor;
use webxr_api::Frame;
use webxr_api::FrameUpdateEvent;
use webxr_api::HitTestId;
use webxr_api::HitTestResult;
use webxr_api::HitTestSource;
use webxr_api::Input;
use webxr_api::InputFrame;
use webxr_api::InputId;
use webxr_api::InputSource;
use webxr_api::LayerGrandManager;
use webxr_api::LayerId;
use webxr_api::LayerInit;
use webxr_api::LayerManager;
use webxr_api::MockDeviceInit;
use webxr_api::MockDeviceMsg;
use webxr_api::MockDiscoveryAPI;
use webxr_api::MockInputMsg;
use webxr_api::MockViewInit;
use webxr_api::MockViewsInit;
use webxr_api::MockWorld;
use webxr_api::Native;
use webxr_api::Quitter;
use webxr_api::Ray;
use webxr_api::Receiver;
use webxr_api::SelectEvent;
use webxr_api::SelectKind;
use webxr_api::Sender;
use webxr_api::Session;
use webxr_api::SessionBuilder;
use webxr_api::SessionInit;
use webxr_api::SessionMode;
use webxr_api::Space;
use webxr_api::SubImages;
use webxr_api::View;
use webxr_api::Viewer;
use webxr_api::ViewerPose;
use webxr_api::Viewports;
use webxr_api::Views;

use euclid::RigidTransform3D;

use std::sync::{Arc, Mutex};
use std::thread;

use surfman_chains::SwapChains;
use surfman::chains::SwapChains;
use webxr_api::util::{self, ClipPlanes, HitTestList};
use webxr_api::{
ApiSpace, BaseSpace, ContextId, DeviceAPI, DiscoveryAPI, Error, Event, EventBuffer, Floor,
Frame, FrameUpdateEvent, HitTestId, HitTestResult, HitTestSource, Input, InputFrame, InputId,
InputSource, LayerGrandManager, LayerId, LayerInit, LayerManager, MockDeviceInit,
MockDeviceMsg, MockDiscoveryAPI, MockInputMsg, MockViewInit, MockViewsInit, MockWorld, Native,
Quitter, Ray, Receiver, SelectEvent, SelectKind, Sender, Session, SessionBuilder, SessionInit,
SessionMode, Space, SubImages, View, Viewer, ViewerPose, Viewports, Views,
};

pub struct HeadlessMockDiscovery {}

Expand Down
38 changes: 9 additions & 29 deletions webxr/surfman_layer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,15 @@
//! An implementation of layer management using surfman
use crate::gl_utils::GlClearer;

use euclid::Point2D;
use euclid::Rect;
use euclid::Size2D;

use sparkle::gl;
use sparkle::gl::GLuint;
use sparkle::gl::Gl;

use euclid::{Point2D, Rect, Size2D};
use sparkle::gl::{self, GLuint, Gl};
use std::collections::HashMap;

use surfman::Context as SurfmanContext;
use surfman::Device as SurfmanDevice;
use surfman::SurfaceAccess;
use surfman::SurfaceTexture;

use surfman_chains::SwapChains;
use surfman_chains::SwapChainsAPI;

use webxr_api::ContextId;
use webxr_api::Error;
use webxr_api::GLContexts;
use webxr_api::GLTypes;
use webxr_api::LayerId;
use webxr_api::LayerInit;
use webxr_api::LayerManagerAPI;
use webxr_api::SubImage;
use webxr_api::SubImages;
use webxr_api::Viewports;
use surfman::chains::{PreserveBuffer, SwapChains, SwapChainsAPI};
use surfman::{Context as SurfmanContext, Device as SurfmanDevice, SurfaceAccess, SurfaceTexture};
use webxr_api::{
ContextId, Error, GLContexts, GLTypes, LayerId, LayerInit, LayerManagerAPI, SubImage,
SubImages, Viewports,
};

#[derive(Copy, Clone, Debug)]
pub enum SurfmanGL {}
Expand Down Expand Up @@ -233,7 +213,7 @@ impl LayerManagerAPI<SurfmanGL> for SurfmanLayerManager {
.recycle_surface_texture(device, context, surface_texture)
.map_err(|err| Error::BackendSpecific(format!("{:?}", err)))?;
swap_chain
.swap_buffers(device, context, surfman_chains::PreserveBuffer::No)
.swap_buffers(device, context, PreserveBuffer::No)
.map_err(|err| Error::BackendSpecific(format!("{:?}", err)))?;
}
Ok(())
Expand Down

0 comments on commit d817d07

Please sign in to comment.