style: Use cbindgen for URIs.

This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:

 * Filters
 * Shapes and images, almost. Need to:
   * Get rid of the complex -moz- gradient parsing (let
     layout.css.simple-moz-gradient.enabled get to release).
 * Counters, almost. Need to:
   * Share the Attr representation with Gecko, by not using Option<>.
     * Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
       maybe).

Which in turn allows us to remove a whole lot of bindings in followups to this.

The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:

```
SpecifiedUrl
 * CssUrl
   * Arc<CssUrlData>
     * String
     * UrlExtraData
 * UrlValueSource
   * Arc<CssUrlData>
   * load id
   * resolved uri
   * CORS mode.
   * ...
```

The new one removes the double reference to the url data via URLValue, and looks
like:

```
SpecifiedUrl
 * CssUrl
   * Arc<CssUrlData>
     * String
     * UrlExtraData
     * CorsMode
     * LoadData
       * load id
       * resolved URI
```

The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.

I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).

The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.

One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).

Differential Revision: https://phabricator.services.mozilla.com/D31742
This commit is contained in:
Emilio Cobos Álvarez 2019-05-27 11:45:12 +00:00
parent 8a0cf600d6
commit ccff9b294f
11 changed files with 239 additions and 298 deletions

View file

@ -63,15 +63,25 @@ impl<T: RefCounted> RefPtr<T> {
}
}
/// Returns whether the current pointer is null.
pub fn is_null(&self) -> bool {
self.ptr.is_null()
}
/// Returns a null pointer.
pub fn null() -> Self {
Self {
ptr: ptr::null_mut(),
_marker: PhantomData,
}
}
/// Create a new RefPtr from a pointer obtained from FFI.
///
/// The pointer must be valid and non null.
///
/// This method calls addref() internally
pub unsafe fn new(ptr: *mut T) -> Self {
debug_assert!(!ptr.is_null());
let ret = RefPtr {
ptr: ptr,
ptr,
_marker: PhantomData,
};
ret.addref();
@ -97,8 +107,10 @@ impl<T: RefCounted> RefPtr<T> {
/// Addref the inner data, obviously leaky on its own.
pub fn addref(&self) {
unsafe {
(*self.ptr).addref();
if !self.ptr.is_null() {
unsafe {
(*self.ptr).addref();
}
}
}
@ -106,7 +118,9 @@ impl<T: RefCounted> RefPtr<T> {
///
/// Call only when the data actually needs releasing.
pub unsafe fn release(&self) {
(*self.ptr).release();
if !self.ptr.is_null() {
(*self.ptr).release();
}
}
}
@ -130,6 +144,7 @@ impl<T: RefCounted> UniqueRefPtr<T> {
impl<T: RefCounted> Deref for RefPtr<T> {
type Target = T;
fn deref(&self) -> &T {
debug_assert!(!self.ptr.is_null());
unsafe { &*self.ptr }
}
}
@ -152,7 +167,6 @@ impl<T: RefCounted> structs::RefPtr<T> {
///
/// Must be called on a valid, non-null structs::RefPtr<T>.
pub unsafe fn to_safe(&self) -> RefPtr<T> {
debug_assert!(!self.mRawPtr.is_null());
let r = RefPtr {
ptr: self.mRawPtr,
_marker: PhantomData,
@ -290,9 +304,9 @@ impl_threadsafe_refcount!(
bindings::Gecko_ReleaseURLExtraDataArbitraryThread
);
impl_threadsafe_refcount!(
structs::mozilla::css::URLValue,
bindings::Gecko_AddRefCSSURLValueArbitraryThread,
bindings::Gecko_ReleaseCSSURLValueArbitraryThread
structs::nsIURI,
bindings::Gecko_AddRefnsIURIArbitraryThread,
bindings::Gecko_ReleasensIURIArbitraryThread
);
impl_threadsafe_refcount!(
structs::mozilla::css::GridTemplateAreasValue,