2019-05-09 15:43:19 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
/* Some inline functions declared in cbindgen.toml */
|
|
|
|
|
|
|
|
#ifndef mozilla_ServoStyleConstsInlines_h
|
|
|
|
#define mozilla_ServoStyleConstsInlines_h
|
|
|
|
|
|
|
|
#include "mozilla/ServoStyleConsts.h"
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
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
2019-05-27 14:45:12 +03:00
|
|
|
#include "mozilla/URLExtraData.h"
|
2019-05-17 02:03:29 +03:00
|
|
|
#include "nsGkAtoms.h"
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
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
2019-05-27 14:45:12 +03:00
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
#include "nsNetUtil.h"
|
2019-05-09 15:43:19 +03:00
|
|
|
#include <type_traits>
|
2019-05-17 02:04:32 +03:00
|
|
|
#include <new>
|
2019-05-09 15:43:19 +03:00
|
|
|
|
|
|
|
// TODO(emilio): there are quite a few other implementations scattered around
|
|
|
|
// that should move here.
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2019-05-17 02:04:32 +03:00
|
|
|
template <typename T>
|
2019-05-27 15:37:37 +03:00
|
|
|
inline void StyleOwnedSlice<T>::Clear() {
|
|
|
|
if (!len) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (size_t i : IntegerRange(len)) {
|
|
|
|
ptr[i].~T();
|
|
|
|
}
|
|
|
|
free(ptr);
|
|
|
|
ptr = (T*)alignof(T);
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void StyleOwnedSlice<T>::CopyFrom(const StyleOwnedSlice& aOther) {
|
|
|
|
Clear();
|
2019-05-17 02:04:32 +03:00
|
|
|
len = aOther.len;
|
|
|
|
if (!len) {
|
|
|
|
ptr = (T*)alignof(T);
|
|
|
|
} else {
|
|
|
|
ptr = (T*)malloc(len * sizeof(T));
|
|
|
|
size_t i = 0;
|
|
|
|
for (const T& elem : aOther.AsSpan()) {
|
|
|
|
new (ptr + i++) T(elem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2019-05-27 15:37:37 +03:00
|
|
|
inline void StyleOwnedSlice<T>::SwapElements(StyleOwnedSlice& aOther) {
|
|
|
|
std::swap(ptr, aOther.ptr);
|
|
|
|
std::swap(len, aOther.len);
|
2019-05-27 15:37:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2019-05-27 15:37:37 +03:00
|
|
|
inline StyleOwnedSlice<T>::StyleOwnedSlice(const StyleOwnedSlice& aOther)
|
|
|
|
: StyleOwnedSlice() {
|
|
|
|
CopyFrom(aOther);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleOwnedSlice<T>::StyleOwnedSlice(StyleOwnedSlice&& aOther)
|
|
|
|
: StyleOwnedSlice() {
|
|
|
|
SwapElements(aOther);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleOwnedSlice<T>& StyleOwnedSlice<T>::operator=(
|
|
|
|
const StyleOwnedSlice& aOther) {
|
|
|
|
CopyFrom(aOther);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleOwnedSlice<T>& StyleOwnedSlice<T>::operator=(
|
|
|
|
StyleOwnedSlice&& aOther) {
|
|
|
|
Clear();
|
|
|
|
SwapElements(aOther);
|
|
|
|
return *this;
|
2019-05-17 02:04:32 +03:00
|
|
|
}
|
|
|
|
|
2019-05-17 02:05:54 +03:00
|
|
|
template <typename T>
|
|
|
|
inline StyleOwnedSlice<T>::~StyleOwnedSlice() {
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
2019-05-09 15:43:19 +03:00
|
|
|
// This code is basically a C++ port of the Arc::clone() implementation in
|
|
|
|
// servo/components/servo_arc/lib.rs.
|
|
|
|
static constexpr const size_t kStaticRefcount =
|
|
|
|
std::numeric_limits<size_t>::max();
|
|
|
|
static constexpr const size_t kMaxRefcount =
|
|
|
|
std::numeric_limits<intptr_t>::max();
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
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
2019-05-27 14:45:12 +03:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void StyleArcInner<T>::IncrementRef() {
|
|
|
|
if (count.load(std::memory_order_relaxed) != kStaticRefcount) {
|
|
|
|
auto old_size = count.fetch_add(1, std::memory_order_relaxed);
|
|
|
|
if (MOZ_UNLIKELY(old_size > kMaxRefcount)) {
|
|
|
|
::abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a C++ port-ish of Arc::drop().
|
|
|
|
template <typename T>
|
|
|
|
inline bool StyleArcInner<T>::DecrementRef() {
|
|
|
|
if (count.load(std::memory_order_relaxed) == kStaticRefcount) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (count.fetch_sub(1, std::memory_order_release) != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
count.load(std::memory_order_acquire);
|
2019-05-16 05:35:34 +03:00
|
|
|
MOZ_LOG_DTOR(this, "ServoArc", 8);
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
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
2019-05-27 14:45:12 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:22:04 +03:00
|
|
|
static constexpr const uint64_t kArcSliceCanary = 0xf3f3f3f3f3f3f3f3;
|
2019-05-09 15:43:19 +03:00
|
|
|
|
|
|
|
#define ASSERT_CANARY \
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(_0.ptr->data.header.header == kArcSliceCanary, "Uh?");
|
|
|
|
|
2019-05-17 02:03:29 +03:00
|
|
|
template <typename T>
|
|
|
|
inline StyleArcSlice<T>::StyleArcSlice() {
|
|
|
|
_0.ptr = reinterpret_cast<decltype(_0.ptr)>(Servo_StyleArcSlice_EmptyPtr());
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
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
2019-05-27 14:45:12 +03:00
|
|
|
ASSERT_CANARY
|
2019-05-17 02:03:29 +03:00
|
|
|
}
|
|
|
|
|
2019-05-09 15:43:19 +03:00
|
|
|
template <typename T>
|
|
|
|
inline StyleArcSlice<T>::StyleArcSlice(const StyleArcSlice& aOther) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aOther._0.ptr);
|
|
|
|
_0.ptr = aOther._0.ptr;
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
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
2019-05-27 14:45:12 +03:00
|
|
|
_0.ptr->IncrementRef();
|
2019-05-09 15:43:19 +03:00
|
|
|
ASSERT_CANARY
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleArcSlice<T>::StyleArcSlice(
|
|
|
|
const StyleForgottenArcSlicePtr<T>& aPtr) {
|
|
|
|
// See the forget() implementation to see why reinterpret_cast() is ok.
|
|
|
|
_0.ptr = reinterpret_cast<decltype(_0.ptr)>(aPtr._0);
|
|
|
|
ASSERT_CANARY
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline size_t StyleArcSlice<T>::Length() const {
|
|
|
|
ASSERT_CANARY
|
|
|
|
return _0.ptr->data.header.length;
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:04:32 +03:00
|
|
|
template <typename T>
|
|
|
|
inline bool StyleArcSlice<T>::IsEmpty() const {
|
|
|
|
ASSERT_CANARY
|
|
|
|
return Length() == 0;
|
|
|
|
}
|
|
|
|
|
2019-05-09 15:43:19 +03:00
|
|
|
template <typename T>
|
|
|
|
inline Span<const T> StyleArcSlice<T>::AsSpan() const {
|
|
|
|
ASSERT_CANARY
|
|
|
|
return MakeSpan(_0.ptr->data.slice, Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline bool StyleArcSlice<T>::operator==(const StyleArcSlice& aOther) const {
|
|
|
|
ASSERT_CANARY
|
|
|
|
return AsSpan() == aOther.AsSpan();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline bool StyleArcSlice<T>::operator!=(const StyleArcSlice& aOther) const {
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleArcSlice<T>::~StyleArcSlice() {
|
|
|
|
ASSERT_CANARY
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
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
2019-05-27 14:45:12 +03:00
|
|
|
if (MOZ_LIKELY(!_0.ptr->DecrementRef())) {
|
2019-05-09 15:43:19 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (T& elem : MakeSpan(_0.ptr->data.slice, Length())) {
|
|
|
|
elem.~T();
|
|
|
|
}
|
|
|
|
free(_0.ptr); // Drop the allocation now.
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef ASSERT_CANARY
|
|
|
|
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
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
2019-05-27 14:45:12 +03:00
|
|
|
template <typename T>
|
|
|
|
inline StyleArc<T>::StyleArc(const StyleArc& aOther) : p(aOther.p) {
|
|
|
|
p->IncrementRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void StyleArc<T>::Release() {
|
|
|
|
if (MOZ_LIKELY(!p->DecrementRef())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p->data.~T();
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleArc<T>& StyleArc<T>::operator=(const StyleArc& aOther) {
|
|
|
|
if (p != aOther.p) {
|
|
|
|
Release();
|
|
|
|
p = aOther.p;
|
|
|
|
p->IncrementRef();
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleArc<T>& StyleArc<T>::operator=(StyleArc&& aOther) {
|
|
|
|
std::swap(p, aOther.p);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleArc<T>::~StyleArc() {
|
|
|
|
Release();
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:03:29 +03:00
|
|
|
inline bool StyleAtom::IsStatic() const { return !!(_0 & 1); }
|
|
|
|
|
2019-05-17 02:23:28 +03:00
|
|
|
inline nsAtom* StyleAtom::AsAtom() const {
|
|
|
|
if (IsStatic()) {
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
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
2019-05-27 14:45:12 +03:00
|
|
|
return const_cast<nsStaticAtom*>(&detail::gGkAtoms.mAtoms[_0 >> 1]);
|
2019-05-17 02:23:28 +03:00
|
|
|
}
|
|
|
|
return reinterpret_cast<nsAtom*>(_0);
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:03:29 +03:00
|
|
|
inline StyleAtom::~StyleAtom() {
|
|
|
|
if (!IsStatic()) {
|
2019-05-17 02:23:28 +03:00
|
|
|
AsAtom()->Release();
|
2019-05-17 02:03:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline StyleAtom::StyleAtom(const StyleAtom& aOther) : _0(aOther._0) {
|
|
|
|
if (!IsStatic()) {
|
|
|
|
reinterpret_cast<nsAtom*>(_0)->AddRef();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:23:28 +03:00
|
|
|
inline nsAtom* StyleCustomIdent::AsAtom() const { return _0.AsAtom(); }
|
|
|
|
|
2019-05-17 02:04:31 +03:00
|
|
|
inline nsDependentCSubstring StyleOwnedStr::AsString() const {
|
|
|
|
Span<const uint8_t> s = _0.AsSpan();
|
|
|
|
return nsDependentCSubstring(reinterpret_cast<const char*>(s.Elements()),
|
|
|
|
s.Length());
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:25:10 +03:00
|
|
|
template <typename T>
|
|
|
|
inline Span<const T> StyleGenericTransform<T>::Operations() const {
|
|
|
|
return _0.AsSpan();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline bool StyleGenericTransform<T>::IsNone() const {
|
|
|
|
return Operations().IsEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline StyleAngle StyleAngle::Zero() { return {0.0f}; }
|
|
|
|
|
|
|
|
inline float StyleAngle::ToDegrees() const { return _0; }
|
|
|
|
|
|
|
|
inline double StyleAngle::ToRadians() const {
|
|
|
|
return double(ToDegrees()) * M_PI / 180.0;
|
|
|
|
}
|
|
|
|
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
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
2019-05-27 14:45:12 +03:00
|
|
|
inline bool StyleUrlExtraData::IsShared() const { return !!(_0 & 1); }
|
|
|
|
|
|
|
|
inline StyleUrlExtraData::~StyleUrlExtraData() {
|
|
|
|
if (!IsShared()) {
|
|
|
|
reinterpret_cast<URLExtraData*>(_0)->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const URLExtraData& StyleUrlExtraData::get() const {
|
|
|
|
if (IsShared()) {
|
|
|
|
return *URLExtraData::sShared[_0 >> 1].get();
|
|
|
|
}
|
|
|
|
return *reinterpret_cast<const URLExtraData*>(_0);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsDependentCSubstring StyleCssUrl::SpecifiedSerialization() const {
|
|
|
|
return _0->serialization.AsString();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const URLExtraData& StyleCssUrl::ExtraData() const {
|
|
|
|
return _0->extra_data.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline StyleLoadData& StyleCssUrl::LoadData() const {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
|
|
|
|
if (MOZ_LIKELY(_0->load_data.tag == StyleLoadDataSource::Tag::Owned)) {
|
|
|
|
return const_cast<StyleLoadData&>(_0->load_data.owned._0);
|
|
|
|
}
|
|
|
|
return const_cast<StyleLoadData&>(*Servo_LoadData_GetLazy(&_0->load_data));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsIURI* StyleCssUrl::GetURI() const {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
|
|
|
|
auto& loadData = LoadData();
|
|
|
|
if (!loadData.tried_to_resolve) {
|
|
|
|
loadData.tried_to_resolve = true;
|
|
|
|
NS_NewURI(getter_AddRefs(loadData.resolved), SpecifiedSerialization(),
|
|
|
|
nullptr, ExtraData().BaseURI());
|
|
|
|
}
|
|
|
|
return loadData.resolved.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsDependentCSubstring StyleComputedUrl::SpecifiedSerialization() const {
|
|
|
|
return _0.SpecifiedSerialization();
|
|
|
|
}
|
|
|
|
inline const URLExtraData& StyleComputedUrl::ExtraData() const {
|
|
|
|
return _0.ExtraData();
|
|
|
|
}
|
|
|
|
inline StyleLoadData& StyleComputedUrl::LoadData() const {
|
|
|
|
return _0.LoadData();
|
|
|
|
}
|
|
|
|
inline CORSMode StyleComputedUrl::CorsMode() const {
|
|
|
|
switch (_0._0->cors_mode) {
|
|
|
|
case StyleCorsMode::Anonymous:
|
|
|
|
return CORSMode::CORS_ANONYMOUS;
|
|
|
|
case StyleCorsMode::None:
|
|
|
|
return CORSMode::CORS_NONE;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unknown cors-mode from style?");
|
|
|
|
return CORSMode::CORS_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inline nsIURI* StyleComputedUrl::GetURI() const { return _0.GetURI(); }
|
|
|
|
|
|
|
|
inline bool StyleComputedUrl::IsLocalRef() const {
|
|
|
|
return Servo_CssUrl_IsLocalRef(&_0);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool StyleComputedUrl::HasRef() const {
|
|
|
|
if (IsLocalRef()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nsIURI* uri = GetURI()) {
|
|
|
|
bool hasRef = false;
|
|
|
|
return NS_SUCCEEDED(uri->GetHasRef(&hasRef)) && hasRef;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-07 17:13:17 +03:00
|
|
|
template <>
|
|
|
|
bool StyleGradient::IsOpaque() const;
|
|
|
|
|
2019-05-09 15:43:19 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|