2018-09-25 05:48:02 +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/. */
|
|
|
|
|
|
|
|
#include "CrossProcessPaint.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/ContentProcessManager.h"
|
|
|
|
#include "mozilla/dom/ImageBitmap.h"
|
2019-04-10 00:38:15 +03:00
|
|
|
#include "mozilla/dom/BrowserParent.h"
|
2019-07-10 19:45:46 +03:00
|
|
|
#include "mozilla/dom/PWindowGlobalParent.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2019-07-10 19:45:46 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalParent.h"
|
|
|
|
#include "mozilla/dom/WindowGlobalChild.h"
|
2019-08-14 13:23:39 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalActorsBinding.h"
|
2018-09-25 05:48:02 +03:00
|
|
|
#include "mozilla/gfx/DrawEventRecorder.h"
|
|
|
|
#include "mozilla/gfx/InlineTranslator.h"
|
2019-10-31 03:08:47 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2018-09-25 05:48:02 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
|
|
|
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsGlobalWindowInner.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
|
2019-10-31 03:08:47 +03:00
|
|
|
static mozilla::LazyLogModule gCrossProcessPaintLog("CrossProcessPaint");
|
|
|
|
static mozilla::LazyLogModule gPaintFragmentLog("PaintFragment");
|
2018-09-25 05:48:02 +03:00
|
|
|
|
2019-10-31 03:08:47 +03:00
|
|
|
#define CPP_LOG(msg, ...) \
|
|
|
|
MOZ_LOG(gCrossProcessPaintLog, LogLevel::Debug, (msg, ##__VA_ARGS__))
|
|
|
|
#define PF_LOG(msg, ...) \
|
|
|
|
MOZ_LOG(gPaintFragmentLog, LogLevel::Debug, (msg, ##__VA_ARGS__))
|
2018-09-25 05:48:02 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
/// The minimum scale we allow tabs to be rasterized at.
|
2018-10-09 05:31:41 +03:00
|
|
|
static const float kMinPaintScale = 0.05f;
|
2018-09-25 05:48:02 +03:00
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
2020-12-11 18:43:19 +03:00
|
|
|
PaintFragment PaintFragment::Record(dom::BrowsingContext* aBc,
|
2019-07-10 19:45:46 +03:00
|
|
|
const Maybe<IntRect>& aRect, float aScale,
|
2019-08-14 13:23:39 +03:00
|
|
|
nscolor aBackgroundColor,
|
|
|
|
CrossProcessPaintFlags aFlags) {
|
2020-12-11 18:43:19 +03:00
|
|
|
nsIDocShell* ds = aBc->GetDocShell();
|
|
|
|
if (!ds) {
|
|
|
|
PF_LOG("Couldn't find docshell.\n");
|
2019-07-10 19:45:46 +03:00
|
|
|
return PaintFragment{};
|
|
|
|
}
|
|
|
|
|
2020-12-11 18:43:19 +03:00
|
|
|
RefPtr<nsPresContext> presContext = ds->GetPresContext();
|
2019-07-10 19:45:46 +03:00
|
|
|
if (!presContext) {
|
|
|
|
PF_LOG("Couldn't find PresContext.\n");
|
|
|
|
return PaintFragment{};
|
|
|
|
}
|
|
|
|
|
|
|
|
IntRect rect;
|
|
|
|
if (!aRect) {
|
|
|
|
nsCOMPtr<nsIWidget> widget =
|
2020-12-11 18:43:19 +03:00
|
|
|
nsContentUtils::WidgetForDocument(presContext->Document());
|
2019-07-10 19:45:46 +03:00
|
|
|
|
|
|
|
// TODO: Apply some sort of clipping to visible bounds here (Bug 1562720)
|
|
|
|
LayoutDeviceIntRect boundsDevice = widget->GetBounds();
|
|
|
|
boundsDevice.MoveTo(0, 0);
|
|
|
|
nsRect boundsAu = LayoutDevicePixel::ToAppUnits(
|
|
|
|
boundsDevice, presContext->AppUnitsPerDevPixel());
|
|
|
|
rect = gfx::RoundedOut(CSSPixel::FromAppUnits(boundsAu).ToUnknownRect());
|
|
|
|
} else {
|
|
|
|
rect = *aRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rect.IsEmpty()) {
|
|
|
|
// TODO: Should we return an empty surface here?
|
|
|
|
PF_LOG("Empty rect to paint.\n");
|
|
|
|
return PaintFragment{};
|
|
|
|
}
|
|
|
|
|
|
|
|
IntSize surfaceSize = rect.Size();
|
2018-09-25 05:48:02 +03:00
|
|
|
surfaceSize.width *= aScale;
|
|
|
|
surfaceSize.height *= aScale;
|
|
|
|
|
|
|
|
CPP_LOG(
|
|
|
|
"Recording "
|
2020-12-11 18:43:19 +03:00
|
|
|
"[browsingContext=%p, "
|
2018-09-25 05:48:02 +03:00
|
|
|
"rect=(%d, %d) x (%d, %d), "
|
|
|
|
"scale=%f, "
|
|
|
|
"color=(%u, %u, %u, %u)]\n",
|
2020-12-11 18:43:19 +03:00
|
|
|
aBc, rect.x, rect.y, rect.width, rect.height, aScale,
|
2018-09-25 05:48:02 +03:00
|
|
|
NS_GET_R(aBackgroundColor), NS_GET_G(aBackgroundColor),
|
|
|
|
NS_GET_B(aBackgroundColor), NS_GET_A(aBackgroundColor));
|
|
|
|
|
|
|
|
// Check for invalid sizes
|
|
|
|
if (surfaceSize.width <= 0 || surfaceSize.height <= 0 ||
|
|
|
|
!Factory::CheckSurfaceSize(surfaceSize)) {
|
|
|
|
PF_LOG("Invalid surface size of (%d x %d).\n", surfaceSize.width,
|
|
|
|
surfaceSize.height);
|
|
|
|
return PaintFragment{};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flush any pending notifications
|
2020-12-11 18:43:19 +03:00
|
|
|
nsContentUtils::FlushLayoutForTree(ds->GetWindow());
|
2018-09-25 05:48:02 +03:00
|
|
|
|
|
|
|
// Initialize the recorder
|
|
|
|
SurfaceFormat format = SurfaceFormat::B8G8R8A8;
|
|
|
|
RefPtr<DrawTarget> referenceDt = Factory::CreateDrawTarget(
|
|
|
|
gfxPlatform::GetPlatform()->GetSoftwareBackend(), IntSize(1, 1), format);
|
|
|
|
|
|
|
|
// TODO: This may OOM crash if the content is complex enough
|
|
|
|
RefPtr<DrawEventRecorderMemory> recorder =
|
|
|
|
MakeAndAddRef<DrawEventRecorderMemory>(nullptr);
|
2019-07-10 16:49:08 +03:00
|
|
|
RefPtr<DrawTarget> dt = Factory::CreateRecordingDrawTarget(
|
|
|
|
recorder, referenceDt, IntRect(IntPoint(0, 0), surfaceSize));
|
2018-09-25 05:48:02 +03:00
|
|
|
|
2019-08-14 13:23:39 +03:00
|
|
|
RenderDocumentFlags renderDocFlags = RenderDocumentFlags::None;
|
|
|
|
if (!(aFlags & CrossProcessPaintFlags::DrawView)) {
|
|
|
|
renderDocFlags = (RenderDocumentFlags::IgnoreViewportScrolling |
|
2021-02-22 07:20:29 +03:00
|
|
|
RenderDocumentFlags::ResetViewportScrolling |
|
2019-08-14 13:23:39 +03:00
|
|
|
RenderDocumentFlags::DocumentRelative);
|
|
|
|
}
|
|
|
|
|
2018-09-25 05:48:02 +03:00
|
|
|
// Perform the actual rendering
|
|
|
|
{
|
2019-07-10 19:45:46 +03:00
|
|
|
nsRect r(nsPresContext::CSSPixelsToAppUnits(rect.x),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(rect.y),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(rect.width),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(rect.height));
|
2018-09-25 05:48:02 +03:00
|
|
|
|
|
|
|
RefPtr<gfxContext> thebes = gfxContext::CreateOrNull(dt);
|
|
|
|
thebes->SetMatrix(Matrix::Scaling(aScale, aScale));
|
2019-04-03 15:40:26 +03:00
|
|
|
RefPtr<PresShell> presShell = presContext->PresShell();
|
2019-08-14 13:23:39 +03:00
|
|
|
Unused << presShell->RenderDocument(r, renderDocFlags, aBackgroundColor,
|
|
|
|
thebes);
|
2018-09-25 05:48:02 +03:00
|
|
|
}
|
|
|
|
|
2019-12-16 11:13:06 +03:00
|
|
|
if (!recorder->mOutputStream.mValid) {
|
|
|
|
return PaintFragment{};
|
|
|
|
}
|
|
|
|
|
2018-09-25 05:48:02 +03:00
|
|
|
ByteBuf recording = ByteBuf((uint8_t*)recorder->mOutputStream.mData,
|
|
|
|
recorder->mOutputStream.mLength,
|
|
|
|
recorder->mOutputStream.mCapacity);
|
|
|
|
recorder->mOutputStream.mData = nullptr;
|
|
|
|
recorder->mOutputStream.mLength = 0;
|
|
|
|
recorder->mOutputStream.mCapacity = 0;
|
|
|
|
|
|
|
|
return PaintFragment{
|
|
|
|
surfaceSize,
|
|
|
|
std::move(recording),
|
|
|
|
std::move(recorder->TakeDependentSurfaces()),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PaintFragment::IsEmpty() const {
|
|
|
|
return !mRecording.mData || mRecording.mLen == 0 || mSize == IntSize(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
PaintFragment::PaintFragment(IntSize aSize, ByteBuf&& aRecording,
|
|
|
|
nsTHashtable<nsUint64HashKey>&& aDependencies)
|
|
|
|
: mSize(aSize),
|
|
|
|
mRecording(std::move(aRecording)),
|
|
|
|
mDependencies(std::move(aDependencies)) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-10-07 23:30:01 +03:00
|
|
|
static dom::TabId GetTabId(dom::WindowGlobalParent* aWGP) {
|
|
|
|
// There is no unique TabId for a given WindowGlobalParent, as multiple
|
|
|
|
// WindowGlobalParents share the same PBrowser actor. However, we only
|
|
|
|
// ever queue one paint per PBrowser by just using the current
|
|
|
|
// WindowGlobalParent for a PBrowser. So we can interchange TabId and
|
|
|
|
// WindowGlobalParent when dealing with resolving surfaces.
|
|
|
|
RefPtr<dom::BrowserParent> browserParent = aWGP->GetBrowserParent();
|
|
|
|
return browserParent ? browserParent->GetTabId() : dom::TabId(0);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
2019-07-10 19:45:46 +03:00
|
|
|
bool CrossProcessPaint::Start(dom::WindowGlobalParent* aRoot,
|
|
|
|
const dom::DOMRect* aRect, float aScale,
|
|
|
|
nscolor aBackgroundColor,
|
2019-08-14 13:23:39 +03:00
|
|
|
CrossProcessPaintFlags aFlags,
|
2019-07-10 19:45:46 +03:00
|
|
|
dom::Promise* aPromise) {
|
2018-09-25 05:48:02 +03:00
|
|
|
MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
|
|
|
|
aScale = std::max(aScale, kMinPaintScale);
|
|
|
|
|
|
|
|
CPP_LOG(
|
2019-07-10 19:45:46 +03:00
|
|
|
"Starting paint. "
|
|
|
|
"[wgp=%p, "
|
2018-09-25 05:48:02 +03:00
|
|
|
"scale=%f, "
|
|
|
|
"color=(%u, %u, %u, %u)]\n",
|
2019-07-10 19:45:46 +03:00
|
|
|
aRoot, aScale, NS_GET_R(aBackgroundColor), NS_GET_G(aBackgroundColor),
|
2018-09-25 05:48:02 +03:00
|
|
|
NS_GET_B(aBackgroundColor), NS_GET_A(aBackgroundColor));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
Maybe<IntRect> rect;
|
|
|
|
if (aRect) {
|
2019-07-31 22:01:05 +03:00
|
|
|
rect =
|
|
|
|
Some(IntRect::RoundOut((float)aRect->X(), (float)aRect->Y(),
|
|
|
|
(float)aRect->Width(), (float)aRect->Height()));
|
2019-07-10 19:45:46 +03:00
|
|
|
}
|
|
|
|
|
2019-12-16 03:20:55 +03:00
|
|
|
if (rect && rect->IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:30:01 +03:00
|
|
|
dom::TabId rootId = GetTabId(aRoot);
|
|
|
|
|
|
|
|
RefPtr<CrossProcessPaint> resolver = new CrossProcessPaint(aScale, rootId);
|
|
|
|
RefPtr<CrossProcessPaint::ResolvePromise> promise;
|
2018-09-25 05:48:02 +03:00
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
if (aRoot->IsInProcess()) {
|
|
|
|
RefPtr<dom::WindowGlobalChild> childActor = aRoot->GetChildActor();
|
|
|
|
if (!childActor) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-25 05:48:02 +03:00
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
// `BrowsingContext()` cannot be nullptr.
|
2020-12-11 18:43:19 +03:00
|
|
|
RefPtr<dom::BrowsingContext> bc = childActor->BrowsingContext();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-10-07 23:30:01 +03:00
|
|
|
promise = resolver->Init();
|
2019-07-10 19:45:46 +03:00
|
|
|
resolver->mPendingFragments += 1;
|
|
|
|
resolver->ReceiveFragment(
|
2020-12-11 18:43:19 +03:00
|
|
|
aRoot,
|
|
|
|
PaintFragment::Record(bc, rect, aScale, aBackgroundColor, aFlags));
|
2019-07-10 19:45:46 +03:00
|
|
|
} else {
|
2020-10-07 23:30:01 +03:00
|
|
|
promise = resolver->Init();
|
2019-08-14 13:23:39 +03:00
|
|
|
resolver->QueuePaint(aRoot, rect, aBackgroundColor, aFlags);
|
2019-07-10 19:45:46 +03:00
|
|
|
}
|
2020-10-07 23:30:01 +03:00
|
|
|
|
|
|
|
promise->Then(
|
|
|
|
GetCurrentSerialEventTarget(), __func__,
|
|
|
|
[promise = RefPtr{aPromise}, rootId](ResolvedFragmentMap&& aFragments) {
|
|
|
|
RefPtr<RecordedDependentSurface> root = aFragments.Get(rootId);
|
|
|
|
CPP_LOG("Resolved all fragments.\n");
|
|
|
|
|
|
|
|
// Create the destination draw target
|
|
|
|
RefPtr<DrawTarget> drawTarget =
|
|
|
|
gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
|
|
|
|
root->mSize, SurfaceFormat::B8G8R8A8);
|
|
|
|
if (!drawTarget || !drawTarget->IsValid()) {
|
|
|
|
CPP_LOG("Couldn't create (%d x %d) surface for fragment %" PRIu64
|
|
|
|
".\n",
|
|
|
|
root->mSize.width, root->mSize.height, (uint64_t)rootId);
|
|
|
|
promise->MaybeReject(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Translate the recording using our child tabs
|
|
|
|
{
|
|
|
|
InlineTranslator translator(drawTarget, nullptr);
|
|
|
|
translator.SetDependentSurfaces(&aFragments);
|
|
|
|
if (!translator.TranslateRecording((char*)root->mRecording.mData,
|
|
|
|
root->mRecording.mLen)) {
|
|
|
|
CPP_LOG("Couldn't translate recording for fragment %" PRIu64 ".\n",
|
|
|
|
(uint64_t)rootId);
|
|
|
|
promise->MaybeReject(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<SourceSurface> snapshot = drawTarget->Snapshot();
|
|
|
|
if (!snapshot) {
|
|
|
|
promise->MaybeReject(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
RefPtr<dom::ImageBitmap> bitmap =
|
|
|
|
dom::ImageBitmap::CreateFromSourceSurface(
|
|
|
|
promise->GetParentObject(), snapshot, rv);
|
|
|
|
|
|
|
|
if (!rv.Failed()) {
|
|
|
|
CPP_LOG("Success, fulfilling promise.\n");
|
|
|
|
promise->MaybeResolve(bitmap);
|
|
|
|
} else {
|
|
|
|
CPP_LOG("Couldn't create ImageBitmap for SourceSurface.\n");
|
|
|
|
promise->MaybeReject(std::move(rv));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[promise = RefPtr{aPromise}](const nsresult& aRv) {
|
|
|
|
promise->MaybeReject(aRv);
|
|
|
|
});
|
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
return true;
|
2018-09-25 05:48:02 +03:00
|
|
|
}
|
|
|
|
|
2020-10-07 23:30:14 +03:00
|
|
|
/* static */
|
|
|
|
RefPtr<CrossProcessPaint::ResolvePromise> CrossProcessPaint::Start(
|
|
|
|
nsTHashtable<nsUint64HashKey>&& aDependencies) {
|
|
|
|
MOZ_ASSERT(!aDependencies.IsEmpty());
|
|
|
|
RefPtr<CrossProcessPaint> resolver =
|
|
|
|
new CrossProcessPaint(1.0, dom::TabId(0));
|
|
|
|
|
|
|
|
RefPtr<CrossProcessPaint::ResolvePromise> promise = resolver->Init();
|
|
|
|
|
|
|
|
PaintFragment rootFragment;
|
|
|
|
rootFragment.mDependencies = std::move(aDependencies);
|
|
|
|
|
|
|
|
resolver->QueueDependencies(rootFragment.mDependencies);
|
|
|
|
resolver->mReceivedFragments.Put(dom::TabId(0), std::move(rootFragment));
|
|
|
|
|
2021-02-12 03:40:41 +03:00
|
|
|
resolver->MaybeResolve();
|
|
|
|
|
2020-10-07 23:30:14 +03:00
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:30:01 +03:00
|
|
|
CrossProcessPaint::CrossProcessPaint(float aScale, dom::TabId aRoot)
|
|
|
|
: mRoot{aRoot}, mScale{aScale}, mPendingFragments{0} {}
|
2018-09-25 05:48:02 +03:00
|
|
|
|
2020-03-04 18:39:20 +03:00
|
|
|
CrossProcessPaint::~CrossProcessPaint() = default;
|
2018-09-25 05:48:02 +03:00
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
void CrossProcessPaint::ReceiveFragment(dom::WindowGlobalParent* aWGP,
|
2018-09-25 05:48:02 +03:00
|
|
|
PaintFragment&& aFragment) {
|
|
|
|
if (IsCleared()) {
|
2019-07-10 19:45:46 +03:00
|
|
|
CPP_LOG("Ignoring fragment from %p.\n", aWGP);
|
2018-09-25 05:48:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-14 13:23:34 +03:00
|
|
|
dom::TabId surfaceId = GetTabId(aWGP);
|
|
|
|
|
2018-09-25 05:48:02 +03:00
|
|
|
MOZ_ASSERT(mPendingFragments > 0);
|
2019-08-14 13:23:34 +03:00
|
|
|
MOZ_ASSERT(!mReceivedFragments.GetValue(surfaceId));
|
2018-09-25 05:48:02 +03:00
|
|
|
|
|
|
|
// Double check our invariants to protect against a compromised content
|
|
|
|
// process
|
2019-08-14 13:23:34 +03:00
|
|
|
if (mPendingFragments == 0 || mReceivedFragments.GetValue(surfaceId) ||
|
2018-09-25 05:48:02 +03:00
|
|
|
aFragment.IsEmpty()) {
|
2019-07-10 19:45:46 +03:00
|
|
|
CPP_LOG("Dropping invalid fragment from %p.\n", aWGP);
|
|
|
|
LostFragment(aWGP);
|
2018-09-25 05:48:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:08:47 +03:00
|
|
|
CPP_LOG("Receiving fragment from %p(%" PRIu64 ").\n", aWGP,
|
|
|
|
(uint64_t)surfaceId);
|
2018-09-25 05:48:02 +03:00
|
|
|
|
|
|
|
// Queue paints for child tabs
|
2020-10-07 23:30:01 +03:00
|
|
|
QueueDependencies(aFragment.mDependencies);
|
|
|
|
|
|
|
|
mReceivedFragments.Put(surfaceId, std::move(aFragment));
|
|
|
|
mPendingFragments -= 1;
|
|
|
|
|
|
|
|
// Resolve this paint if we have received all pending fragments
|
|
|
|
MaybeResolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CrossProcessPaint::LostFragment(dom::WindowGlobalParent* aWGP) {
|
|
|
|
if (IsCleared()) {
|
|
|
|
CPP_LOG("Ignoring lost fragment from %p.\n", aWGP);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Clear(NS_ERROR_LOSS_OF_SIGNIFICANT_DATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CrossProcessPaint::QueueDependencies(
|
|
|
|
const nsTHashtable<nsUint64HashKey>& aDependencies) {
|
|
|
|
for (auto iter = aDependencies.ConstIter(); !iter.Done(); iter.Next()) {
|
2019-07-10 19:45:46 +03:00
|
|
|
auto dependency = dom::TabId(iter.Get()->GetKey());
|
|
|
|
|
|
|
|
// Get the current WindowGlobalParent of the remote browser that was marked
|
|
|
|
// as a dependency
|
|
|
|
dom::ContentProcessManager* cpm =
|
|
|
|
dom::ContentProcessManager::GetSingleton();
|
|
|
|
dom::ContentParentId cpId = cpm->GetTabProcessId(dependency);
|
|
|
|
RefPtr<dom::BrowserParent> browser =
|
|
|
|
cpm->GetBrowserParentByProcessAndTabId(cpId, dependency);
|
2021-02-12 03:40:40 +03:00
|
|
|
if (!browser) {
|
|
|
|
CPP_LOG("Skipping dependency %" PRIu64 "with no current BrowserParent.\n",
|
|
|
|
(uint64_t)dependency);
|
|
|
|
continue;
|
|
|
|
}
|
2019-07-10 19:45:46 +03:00
|
|
|
RefPtr<dom::WindowGlobalParent> wgp =
|
|
|
|
browser->GetBrowsingContext()->GetCurrentWindowGlobal();
|
|
|
|
|
|
|
|
if (!wgp) {
|
2019-10-31 03:08:47 +03:00
|
|
|
CPP_LOG("Skipping dependency %" PRIu64 "with no current WGP.\n",
|
2019-07-10 19:45:46 +03:00
|
|
|
(uint64_t)dependency);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Apply some sort of clipping to visible bounds here (Bug 1562720)
|
|
|
|
QueuePaint(wgp, Nothing());
|
2018-09-25 05:48:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
void CrossProcessPaint::QueuePaint(dom::WindowGlobalParent* aWGP,
|
2019-07-11 17:01:15 +03:00
|
|
|
const Maybe<IntRect>& aRect,
|
2019-08-14 13:23:39 +03:00
|
|
|
nscolor aBackgroundColor,
|
|
|
|
CrossProcessPaintFlags aFlags) {
|
2019-08-14 13:23:34 +03:00
|
|
|
MOZ_ASSERT(!mReceivedFragments.GetValue(GetTabId(aWGP)));
|
2018-09-25 05:48:02 +03:00
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
CPP_LOG("Queueing paint for %p.\n", aWGP);
|
2018-09-25 05:48:02 +03:00
|
|
|
|
2019-08-14 13:23:39 +03:00
|
|
|
aWGP->DrawSnapshotInternal(this, aRect, mScale, aBackgroundColor,
|
|
|
|
(uint32_t)aFlags);
|
2018-09-25 05:48:02 +03:00
|
|
|
mPendingFragments += 1;
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:30:01 +03:00
|
|
|
void CrossProcessPaint::Clear(nsresult aStatus) {
|
2018-09-25 05:48:02 +03:00
|
|
|
mPendingFragments = 0;
|
|
|
|
mReceivedFragments.Clear();
|
2020-10-07 23:30:01 +03:00
|
|
|
mPromise.RejectIfExists(aStatus, __func__);
|
2018-09-25 05:48:02 +03:00
|
|
|
}
|
|
|
|
|
2020-10-07 23:30:01 +03:00
|
|
|
bool CrossProcessPaint::IsCleared() const { return mPromise.IsEmpty(); }
|
2018-09-25 05:48:02 +03:00
|
|
|
|
|
|
|
void CrossProcessPaint::MaybeResolve() {
|
|
|
|
// Don't do anything if we aren't ready, experienced an error, or already
|
|
|
|
// resolved this paint
|
|
|
|
if (IsCleared() || mPendingFragments > 0) {
|
|
|
|
CPP_LOG("Not ready to resolve yet, have %u fragments left.\n",
|
|
|
|
mPendingFragments);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPP_LOG("Starting to resolve fragments.\n");
|
|
|
|
|
|
|
|
// Resolve the paint fragments from the bottom up
|
2020-10-07 23:30:01 +03:00
|
|
|
ResolvedFragmentMap resolved;
|
2019-08-14 13:23:34 +03:00
|
|
|
{
|
2020-10-07 23:30:01 +03:00
|
|
|
nsresult rv = ResolveInternal(mRoot, &resolved);
|
2019-08-14 13:23:34 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
CPP_LOG("Couldn't resolve.\n");
|
2020-10-07 23:30:01 +03:00
|
|
|
Clear(rv);
|
2019-08-14 13:23:34 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-09-25 05:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CPP_LOG("Resolved all fragments.\n");
|
|
|
|
|
2020-10-07 23:30:01 +03:00
|
|
|
mPromise.ResolveIfExists(std::move(resolved), __func__);
|
|
|
|
Clear(NS_OK);
|
2018-09-25 05:48:02 +03:00
|
|
|
}
|
|
|
|
|
2019-08-14 13:23:34 +03:00
|
|
|
nsresult CrossProcessPaint::ResolveInternal(dom::TabId aTabId,
|
2020-10-07 23:30:01 +03:00
|
|
|
ResolvedFragmentMap* aResolved) {
|
2018-09-25 05:48:02 +03:00
|
|
|
// We should not have resolved this paint already
|
2019-08-14 13:23:34 +03:00
|
|
|
MOZ_ASSERT(!aResolved->GetWeak(aTabId));
|
2018-09-25 05:48:02 +03:00
|
|
|
|
2019-10-31 03:08:47 +03:00
|
|
|
CPP_LOG("Resolving fragment %" PRIu64 ".\n", (uint64_t)aTabId);
|
2018-09-25 05:48:02 +03:00
|
|
|
|
2021-02-22 15:07:48 +03:00
|
|
|
Maybe<PaintFragment> fragment = mReceivedFragments.Extract(aTabId);
|
2019-08-14 13:23:34 +03:00
|
|
|
if (!fragment) {
|
|
|
|
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
|
|
|
}
|
2018-09-25 05:48:02 +03:00
|
|
|
|
|
|
|
// Rasterize all the dependencies first so that we can resolve this fragment
|
|
|
|
for (auto iter = fragment->mDependencies.Iter(); !iter.Done(); iter.Next()) {
|
2019-07-10 19:45:46 +03:00
|
|
|
auto dependency = dom::TabId(iter.Get()->GetKey());
|
|
|
|
|
2019-08-14 13:23:34 +03:00
|
|
|
nsresult rv = ResolveInternal(dependency, aResolved);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2018-09-25 05:48:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:30:01 +03:00
|
|
|
RefPtr<RecordedDependentSurface> surface = new RecordedDependentSurface{
|
|
|
|
fragment->mSize, std::move(fragment->mRecording)};
|
|
|
|
aResolved->Put(aTabId, std::move(surface));
|
2019-08-14 13:23:34 +03:00
|
|
|
return NS_OK;
|
2018-09-25 05:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|