Skip to content

Add an example app using the DirectComposition API #2458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 75 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
4f67edd
Initial commit
SimonSapin Jan 30, 2018
7dfa0b4
Copy example program from glutin’s README
SimonSapin Jan 30, 2018
5c80249
Start to translate "How to initialize DirectComposition" example
SimonSapin Jan 30, 2018
fdab306
Return these pointers we so arduously obtained
SimonSapin Jan 30, 2018
307b3f0
Add a COM pointer abstraction
SimonSapin Feb 13, 2018
0507f4c
Import fewer single-use things
SimonSapin Feb 13, 2018
58b9ab1
*mut *mut _ alreay requires unsafe to break invariants
SimonSapin Feb 13, 2018
a91c6a8
Return a struct
SimonSapin Feb 13, 2018
fc680d6
Switch to wio::ComPtr
SimonSapin Feb 14, 2018
7ff8ed1
Create some DirectComposition visuals
SimonSapin Feb 14, 2018
f758d2b
Use the winit crate directly
SimonSapin Feb 14, 2018
9effb30
Drop GL for now
SimonSapin Feb 15, 2018
e637e08
Remove click event handling
SimonSapin Feb 15, 2018
955b210
Create swap chains
SimonSapin Feb 20, 2018
7fd064c
Fork wio::ComPtr
SimonSapin Feb 20, 2018
8d40fdf
First D3D rectangle!
SimonSapin Feb 20, 2018
5c6ae42
Try to provide safe APIs. (Still needs safety review.)
SimonSapin Feb 22, 2018
e10178d
Separate the library crate from the demo app
SimonSapin Feb 22, 2018
17c3957
Make the lib more library-like, keep hard-coded values in the demo app.
SimonSapin Feb 22, 2018
aff6c39
Move demo app’s unsafe code into a safe function
SimonSapin Feb 22, 2018
39c125c
Two D3D things in the same window
SimonSapin Feb 22, 2018
828c285
Alpha transparency!
SimonSapin Feb 22, 2018
c7eea0b
Scrolling without re-rendering
SimonSapin Feb 22, 2018
281a511
Remove unused and unsound DerefMut
SimonSapin Feb 22, 2018
b8458bb
Repaint one of the visuals on click
SimonSapin Feb 22, 2018
b69dbd6
OMSetRenderTargets appears to be unnecessary here
SimonSapin Feb 23, 2018
a730f98
Keep one shared D3D context
SimonSapin Feb 23, 2018
ce02a22
Make sure we can keep rendering both visuals
SimonSapin Feb 23, 2018
1842280
Rewrite ComPtr::cast in terms of new_with_uuid
SimonSapin Feb 23, 2018
c264c97
Keep a "render target view" together with each visual
SimonSapin Feb 23, 2018
6a46a4b
Make D3D stuff public, move rendering to the app
SimonSapin Feb 23, 2018
bb9fbbf
Add EGL bindings through the gl_generator crate
SimonSapin Feb 23, 2018
d380331
Remove obsolete comment
SimonSapin Feb 23, 2018
118d0b1
Link to ANGLE (but assume it is already built)
SimonSapin Feb 23, 2018
fa95b12
Create and initialize an EGL display
SimonSapin Feb 26, 2018
ac0ac79
Create EGL configs and surfaces
SimonSapin Feb 26, 2018
8553788
Create EGL contexts and call MakeCurrent()
SimonSapin Feb 27, 2018
e7b9614
Use gleam
SimonSapin Feb 27, 2018
be24ac2
Attempt to use OpenGL through gleam + ANGLE + EGL… but the window sta…
SimonSapin Feb 27, 2018
fede929
Add Visual::present
SimonSapin Feb 27, 2018
68d8fef
Remove public APIs for rendering with Direct3D
SimonSapin Feb 27, 2018
6327ed1
Check for EGL errors more systematically
SimonSapin Feb 27, 2018
959a56a
More well-defined public API for EGL things
SimonSapin Feb 27, 2018
567f82c
Keep a reference to shared EGL things next to per-visual things
SimonSapin Feb 27, 2018
f3c21a3
Destroy EGL things in Drop
SimonSapin Feb 27, 2018
c35ccfc
Keep the DXGI back buffer object alive, in case that matters
SimonSapin Feb 27, 2018
3c36118
Call glFinish() before IDXGISwapChain::Present
SimonSapin Feb 27, 2018
023022a
Demo add: access gleam through visuals
SimonSapin Feb 27, 2018
0b45cf7
Rename the crate with a dash
SimonSapin Feb 27, 2018
75901d6
Move to a subdirectory, for merging into the webrender repo
SimonSapin Feb 27, 2018
efae554
Merge branch 'master' of ../rust-directcomposition into dcomp
SimonSapin Feb 27, 2018
70937d6
Add direct-composition to the webrender workspace.
SimonSapin Feb 27, 2018
9c11d75
Turns out ClearColor doesn’t clear, it just sets the color… Thanks So…
SimonSapin Feb 28, 2018
9d99193
Keeping a reference to back_buffer isn’t necessary.
SimonSapin Feb 28, 2018
872f356
Switch to gl_generator::StaticGenerator
SimonSapin Feb 28, 2018
9238751
Add a private Check trait for EGL return values
SimonSapin Feb 28, 2018
a3b8aba
Move to-be-implemented EGL config choice to a function
SimonSapin Feb 28, 2018
41d4283
eglDestroyContext/Surface already do the right thing for the current …
SimonSapin Feb 28, 2018
6c8928d
Panic in the library on COM errors
SimonSapin Feb 28, 2018
3dd8117
Use tuples for RGBA colors
SimonSapin Feb 28, 2018
6c71656
One same EGL context can be used with multiple surfaces.
SimonSapin Feb 28, 2018
f942806
Initialize WebRender in the DComp demo app
SimonSapin Feb 28, 2018
eb5de06
Rename D3DVisual to AngleVisual
SimonSapin Feb 28, 2018
cc4980f
Add a Rectangle abstraction in the demo app
SimonSapin Feb 28, 2018
42a25b4
Render with WebRender
SimonSapin Mar 1, 2018
27be710
Block until the pipeline is ready, before rendering.
SimonSapin Mar 2, 2018
8766dfc
Use the mozangle crate
SimonSapin Mar 3, 2018
aa39ae5
Use mozangle instead of the other angle crate.
SimonSapin Mar 4, 2018
83edf97
Merge remote-tracking branch 'origin/master' into dcomp
SimonSapin Mar 9, 2018
87812ae
Make the direct-composition demo compile to an empty program on non-w…
SimonSapin Mar 9, 2018
9d92ad5
direct-composition tidy
SimonSapin Mar 9, 2018
19b3df1
Update mozangle
SimonSapin Mar 9, 2018
2062501
Appveyor: Switch to MSVC toolchain
SimonSapin Mar 9, 2018
60d8f08
Build the direct-composition demo on Appveyor CI
SimonSapin Mar 9, 2018
c4a859d
Revert AppVeyor image change
SimonSapin Mar 9, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
license = "MPL-2.0"
members = [
"direct-composition",
"webrender",
"webrender_api",
"wrench",
Expand Down
8 changes: 5 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
environment:
PATH: 'C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%;C:\Rust\bin'
RUST_BACKTRACE: 1
TARGET: x86_64-pc-windows-msvc

install:
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-1.23.0-x86_64-pc-windows-gnu.msi"
- msiexec /passive /i "rust-1.23.0-x86_64-pc-windows-gnu.msi" ADDLOCAL=Rustc,Cargo,Std INSTALLDIR=C:\Rust
- bash -lc "pacman -S --noconfirm mingw-w64-x86_64-cmake"
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-1.23.0-${env:TARGET}.msi"
- msiexec /passive /i "rust-1.23.0-%TARGET%.msi" ADDLOCAL=Rustc,Cargo,Std INSTALLDIR=C:\Rust
- rustc -V
- cargo -V

Expand All @@ -18,3 +18,5 @@ test_script:
- cargo test --verbose
- cd ../wrench
- cargo test --verbose
- cd ../direct-composition
- cargo build --verbose
13 changes: 13 additions & 0 deletions direct-composition/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "direct-composition"
version = "0.1.0"
authors = ["Simon Sapin <[email protected]>"]
license = "MPL-2.0"

[target.'cfg(windows)'.dependencies]
euclid = "0.17"
gleam = "0.4"
mozangle = {version = "0.1", features = ["egl"]}
webrender = {path = "../webrender"}
winapi = {version = "0.3", features = ["winerror", "d3d11", "dcomp"]}
winit = "0.10"
112 changes: 112 additions & 0 deletions direct-composition/src/com.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/* 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 http://mozilla.org/MPL/2.0/. */

use std::ops;
use std::ptr;
use winapi::Interface;
use winapi::ctypes::c_void;
use winapi::shared::guiddef::GUID;
use winapi::shared::winerror::HRESULT;
use winapi::shared::winerror::SUCCEEDED;
use winapi::um::unknwnbase::IUnknown;

pub fn as_ptr<T>(x: &T) -> *mut T {
x as *const T as _
}

pub trait CheckHResult {
fn check_hresult(self);
}

impl CheckHResult for HRESULT {
fn check_hresult(self) {
if !SUCCEEDED(self) {
panic_com(self)
}
}
}

fn panic_com(hresult: HRESULT) -> ! {
panic!("COM error 0x{:08X}", hresult as u32)
}

/// Forked from <https://github.com/retep998/wio-rs/blob/44093f7db8/src/com.rs>
#[derive(PartialEq, Debug)]
pub struct ComPtr<T>(*mut T) where T: Interface;

impl<T> ComPtr<T> where T: Interface {
/// Creates a `ComPtr` to wrap a raw pointer.
/// It takes ownership over the pointer which means it does __not__ call `AddRef`.
/// `T` __must__ be a COM interface that inherits from `IUnknown`.
pub unsafe fn from_raw(ptr: *mut T) -> ComPtr<T> {
assert!(!ptr.is_null());
ComPtr(ptr)
}

/// For use with APIs that take an interface UUID and
/// "return" a new COM object through a `*mut *mut c_void` out-parameter.
pub unsafe fn new_with_uuid<F>(f: F) -> Self
where F: FnOnce(&GUID, *mut *mut c_void) -> HRESULT
{
Self::new_with(|ptr| f(&T::uuidof(), ptr as _))
}

/// For use with APIs that "return" a new COM object through a `*mut *mut T` out-parameter.
pub unsafe fn new_with<F>(f: F) -> Self
where F: FnOnce(*mut *mut T) -> HRESULT
{
let mut ptr = ptr::null_mut();
let hresult = f(&mut ptr);
if SUCCEEDED(hresult) {
ComPtr::from_raw(ptr)
} else {
if !ptr.is_null() {
let ptr = ptr as *mut IUnknown;
(*ptr).Release();
}
panic_com(hresult)
}
}

pub fn as_raw(&self) -> *mut T {
self.0
}

fn as_unknown(&self) -> &IUnknown {
unsafe {
&*(self.0 as *mut IUnknown)
}
}

/// Performs QueryInterface fun.
pub fn cast<U>(&self) -> ComPtr<U> where U: Interface {
unsafe {
ComPtr::<U>::new_with_uuid(|uuid, ptr| self.as_unknown().QueryInterface(uuid, ptr))
}
}
}

impl<T> ops::Deref for ComPtr<T> where T: Interface {
type Target = T;
fn deref(&self) -> &T {
unsafe { &*self.0 }
}
}

impl<T> Clone for ComPtr<T> where T: Interface {
fn clone(&self) -> Self {
unsafe {
self.as_unknown().AddRef();
ComPtr(self.0)
}
}
}

impl<T> Drop for ComPtr<T> where T: Interface {
fn drop(&mut self) {
unsafe {
self.as_unknown().Release();
}
}
}
Loading