gecko-dev/layout/style/PostTraversalTask.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

128 строки
3.6 KiB
C
Исходник Обычный вид История

/* -*- 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/. */
#ifndef mozilla_PostTraversalTask_h
#define mozilla_PostTraversalTask_h
#include "nscore.h"
/* a task to be performed immediately after a Servo traversal */
namespace mozilla {
class ServoStyleSet;
namespace dom {
class FontFace;
class FontFaceSet;
} // namespace dom
namespace fontlist {
struct Family;
} // namespace fontlist
} // namespace mozilla
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which represents the state just after a gfxUserFontEntry's url()-valued source would being loading, except that we can't start the load due to being on a Servo style worker thread. In that case, we defer the work of initiating the load until just after the Servo traversal is finished. URLs that can normally be loaded synchronously, such as data: URLs and script-implemented protocols marked as synchronous, must be handled asynchronously when encountered during Servo traversal, since various main-thread only work (in FontFaceSet::SyncLoadFontData) must happen. This is a user visible change from stock Gecko, but should only happen when font metrics for a data: URL font are requested due to ch/ex unit resolution when layout hasn't previously requested the font load. Hopefully nobody relies on synchronous resolution of ch/ex units with data: URLs. We unfortunately also can't pick gfxUserFontEntry objects out of the UserFontCache during Servo traversal, since validating the cache entry involves doing content policy checking, which is not thread-safe (due in part to taking strong references to nsIPrincipals). Platform fonts and ArrayBuffer-backed DOM FontFace objects continue to be handled synchronously. The PostTraversalTask does not take a strong reference to the gfxUserFontEntry object, since it is held on to by the DOM FontFace object, which itself won't go away before the PostTraversalTask is run. MozReview-Commit-ID: J9ODLsusrNV --HG-- extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
class gfxUserFontEntry;
namespace mozilla {
/**
* A PostTraversalTask is a task to be performed immediately after a Servo
* traversal. There are just a few tasks we need to perform, so we use this
* class rather than Runnables, to avoid virtual calls and some allocations.
*
* A PostTraversalTask is only safe to run immediately after the Servo
* traversal, since it can hold raw pointers to DOM objects.
*/
class PostTraversalTask {
public:
static PostTraversalTask ResolveFontFaceLoadedPromise(
dom::FontFace* aFontFace) {
auto task = PostTraversalTask(Type::ResolveFontFaceLoadedPromise);
task.mTarget = aFontFace;
return task;
}
static PostTraversalTask RejectFontFaceLoadedPromise(dom::FontFace* aFontFace,
nsresult aResult) {
auto task = PostTraversalTask(Type::ResolveFontFaceLoadedPromise);
task.mTarget = aFontFace;
task.mResult = aResult;
return task;
}
static PostTraversalTask DispatchLoadingEventAndReplaceReadyPromise(
dom::FontFaceSet* aFontFaceSet) {
auto task =
PostTraversalTask(Type::DispatchLoadingEventAndReplaceReadyPromise);
task.mTarget = aFontFaceSet;
return task;
}
static PostTraversalTask DispatchFontFaceSetCheckLoadingFinishedAfterDelay(
dom::FontFaceSet* aFontFaceSet) {
auto task = PostTraversalTask(
Type::DispatchFontFaceSetCheckLoadingFinishedAfterDelay);
task.mTarget = aFontFaceSet;
return task;
}
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which represents the state just after a gfxUserFontEntry's url()-valued source would being loading, except that we can't start the load due to being on a Servo style worker thread. In that case, we defer the work of initiating the load until just after the Servo traversal is finished. URLs that can normally be loaded synchronously, such as data: URLs and script-implemented protocols marked as synchronous, must be handled asynchronously when encountered during Servo traversal, since various main-thread only work (in FontFaceSet::SyncLoadFontData) must happen. This is a user visible change from stock Gecko, but should only happen when font metrics for a data: URL font are requested due to ch/ex unit resolution when layout hasn't previously requested the font load. Hopefully nobody relies on synchronous resolution of ch/ex units with data: URLs. We unfortunately also can't pick gfxUserFontEntry objects out of the UserFontCache during Servo traversal, since validating the cache entry involves doing content policy checking, which is not thread-safe (due in part to taking strong references to nsIPrincipals). Platform fonts and ArrayBuffer-backed DOM FontFace objects continue to be handled synchronously. The PostTraversalTask does not take a strong reference to the gfxUserFontEntry object, since it is held on to by the DOM FontFace object, which itself won't go away before the PostTraversalTask is run. MozReview-Commit-ID: J9ODLsusrNV --HG-- extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
static PostTraversalTask LoadFontEntry(gfxUserFontEntry* aFontEntry) {
auto task = PostTraversalTask(Type::LoadFontEntry);
task.mTarget = aFontEntry;
return task;
}
static PostTraversalTask InitializeFamily(fontlist::Family* aFamily) {
auto task = PostTraversalTask(Type::InitializeFamily);
task.mTarget = aFamily;
return task;
}
static PostTraversalTask FontInfoUpdate(ServoStyleSet* aSet) {
auto task = PostTraversalTask(Type::FontInfoUpdate);
task.mTarget = aSet;
return task;
}
void Run();
private:
// For any new raw pointer type that we need to store in a PostTraversalTask,
// please add an assertion that class' destructor that we are not in a Servo
// traversal, to protect against the possibility of having dangling pointers.
enum class Type {
// mTarget (FontFace*)
ResolveFontFaceLoadedPromise,
// mTarget (FontFace*)
// mResult
RejectFontFaceLoadedPromise,
// mTarget (FontFaceSet*)
DispatchLoadingEventAndReplaceReadyPromise,
// mTarget (FontFaceSet*)
DispatchFontFaceSetCheckLoadingFinishedAfterDelay,
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which represents the state just after a gfxUserFontEntry's url()-valued source would being loading, except that we can't start the load due to being on a Servo style worker thread. In that case, we defer the work of initiating the load until just after the Servo traversal is finished. URLs that can normally be loaded synchronously, such as data: URLs and script-implemented protocols marked as synchronous, must be handled asynchronously when encountered during Servo traversal, since various main-thread only work (in FontFaceSet::SyncLoadFontData) must happen. This is a user visible change from stock Gecko, but should only happen when font metrics for a data: URL font are requested due to ch/ex unit resolution when layout hasn't previously requested the font load. Hopefully nobody relies on synchronous resolution of ch/ex units with data: URLs. We unfortunately also can't pick gfxUserFontEntry objects out of the UserFontCache during Servo traversal, since validating the cache entry involves doing content policy checking, which is not thread-safe (due in part to taking strong references to nsIPrincipals). Platform fonts and ArrayBuffer-backed DOM FontFace objects continue to be handled synchronously. The PostTraversalTask does not take a strong reference to the gfxUserFontEntry object, since it is held on to by the DOM FontFace object, which itself won't go away before the PostTraversalTask is run. MozReview-Commit-ID: J9ODLsusrNV --HG-- extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
// mTarget (gfxUserFontEntry*)
LoadFontEntry,
// mTarget (fontlist::Family*)
InitializeFamily,
// mTarget (ServoStyleSet*)
FontInfoUpdate,
};
explicit PostTraversalTask(Type aType)
: mType(aType), mTarget(nullptr), mResult(NS_OK) {}
Type mType;
void* mTarget;
nsresult mResult;
};
} // namespace mozilla
#endif // mozilla_PostTraversalTask_h