Bug 1558482 - Add visibleRect and scaling to EffectsInfo and compute them when using layers. r=mattwoodrow

Differential Revision: https://phabricator.services.mozilla.com/D34523

--HG--
extra : rebase_source : 3bbef496359ae108e1f4adc2548e0140cfd7b0a8
This commit is contained in:
Ryan Hunt 2019-06-11 07:50:40 -05:00
Родитель 94dd792600
Коммит 99aaa4e6c6
6 изменённых файлов: 64 добавлений и 18 удалений

Просмотреть файл

@ -2741,7 +2741,7 @@ bool BrowserChild::IsVisible() {
} }
void BrowserChild::UpdateVisibility(bool aForceRepaint) { void BrowserChild::UpdateVisibility(bool aForceRepaint) {
bool shouldBeVisible = mIsTopLevel ? mRenderLayers : mEffectsInfo.mVisible; bool shouldBeVisible = mIsTopLevel ? mRenderLayers : mEffectsInfo.IsVisible();
bool isVisible = IsVisible(); bool isVisible = IsVisible();
if (shouldBeVisible != isVisible) { if (shouldBeVisible != isVisible) {

Просмотреть файл

@ -7,6 +7,8 @@
#ifndef mozilla_dom_EffectsInfo_h #ifndef mozilla_dom_EffectsInfo_h
#define mozilla_dom_EffectsInfo_h #define mozilla_dom_EffectsInfo_h
#include "nsRect.h"
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
@ -14,29 +16,37 @@ namespace dom {
* An EffectsInfo contains information for a remote browser about the graphical * An EffectsInfo contains information for a remote browser about the graphical
* effects that are being applied to it by ancestor browsers in different * effects that are being applied to it by ancestor browsers in different
* processes. * processes.
*
* TODO: This struct currently only reports visibility, and should be extended
* with information on clipping and scaling.
*/ */
class EffectsInfo { class EffectsInfo {
public: public:
EffectsInfo() { *this = EffectsInfo::FullyHidden(); } EffectsInfo() { *this = EffectsInfo::FullyHidden(); }
static EffectsInfo FullyVisible() { return EffectsInfo{true}; }
static EffectsInfo FullyHidden() { return EffectsInfo{false}; } static EffectsInfo VisibleWithinRect(const nsRect& aVisibleRect,
float aScaleX, float aScaleY) {
return EffectsInfo{aVisibleRect, aScaleX, aScaleY};
}
static EffectsInfo FullyHidden() { return EffectsInfo{nsRect(), 1.0f, 1.0f}; }
bool operator==(const EffectsInfo& aOther) { bool operator==(const EffectsInfo& aOther) {
return mVisible == aOther.mVisible; return mVisibleRect == aOther.mVisibleRect && mScaleX == aOther.mScaleX &&
mScaleY == aOther.mScaleY;
} }
bool operator!=(const EffectsInfo& aOther) { return !(*this == aOther); } bool operator!=(const EffectsInfo& aOther) { return !(*this == aOther); }
// If you add new state here, you must also update operator== bool IsVisible() const { return !mVisibleRect.IsEmpty(); }
bool mVisible;
/* // The visible rect of this browser relative to the root frame. If this is
* TODO: Add information for ancestor scaling and clipping. // empty then the browser can be considered invisible.
*/ nsRect mVisibleRect;
// The desired scale factors to apply to rasterized content to match
// transforms applied in ancestor browsers.
float mScaleX;
float mScaleY;
// If you add new fields here, you must also update operator==
private: private:
explicit EffectsInfo(bool aVisible) : mVisible(aVisible) {} EffectsInfo(const nsRect& aVisibleRect, float aScaleX, float aScaleY)
: mVisibleRect(aVisibleRect), mScaleX(aScaleX), mScaleY(aScaleY) {}
}; };
} // namespace dom } // namespace dom

Просмотреть файл

@ -81,12 +81,16 @@ struct ParamTraits<mozilla::dom::EffectsInfo> {
typedef mozilla::dom::EffectsInfo paramType; typedef mozilla::dom::EffectsInfo paramType;
static void Write(Message* aMsg, const paramType& aParam) { static void Write(Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, aParam.mVisible); WriteParam(aMsg, aParam.mVisibleRect);
WriteParam(aMsg, aParam.mScaleX);
WriteParam(aMsg, aParam.mScaleY);
} }
static bool Read(const Message* aMsg, PickleIterator* aIter, static bool Read(const Message* aMsg, PickleIterator* aIter,
paramType* aResult) { paramType* aResult) {
return ReadParam(aMsg, aIter, &aResult->mVisible); return ReadParam(aMsg, aIter, &aResult->mVisibleRect) &&
ReadParam(aMsg, aIter, &aResult->mScaleX) &&
ReadParam(aMsg, aIter, &aResult->mScaleY);
} }
}; };

Просмотреть файл

@ -14,6 +14,7 @@
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/PresShell.h" #include "mozilla/PresShell.h"
#include "mozilla/StaticPrefs.h" #include "mozilla/StaticPrefs.h"
#include "mozilla/Unused.h"
#include "mozilla/dom/Document.h" #include "mozilla/dom/Document.h"
#include "mozilla/dom/HTMLFrameElement.h" #include "mozilla/dom/HTMLFrameElement.h"
#include "mozilla/dom/BrowserParent.h" #include "mozilla/dom/BrowserParent.h"
@ -1404,8 +1405,20 @@ already_AddRefed<mozilla::layers::Layer> nsDisplayRemote::BuildLayer(
if (RefPtr<RemoteBrowser> remoteBrowser = if (RefPtr<RemoteBrowser> remoteBrowser =
GetFrameLoader()->GetRemoteBrowser()) { GetFrameLoader()->GetRemoteBrowser()) {
// Adjust mItemVisibleRect, which is relative to the reference frame, to be
// relative to this frame
nsRect visibleRect;
if (aContainerParameters.mItemVisibleRect) {
visibleRect = *aContainerParameters.mItemVisibleRect - ToReferenceFrame();
} else {
visibleRect = mFrame->GetContentRectRelativeToSelf();
}
// Generate an effects update notifying the browser it is visible // Generate an effects update notifying the browser it is visible
aBuilder->AddEffectUpdate(remoteBrowser, EffectsInfo::FullyVisible()); aBuilder->AddEffectUpdate(remoteBrowser,
EffectsInfo::VisibleWithinRect(
visibleRect, aContainerParameters.mXScale,
aContainerParameters.mYScale));
// FrameLayerBuilder will take care of notifying the browser when it is no // FrameLayerBuilder will take care of notifying the browser when it is no
// longer visible // longer visible
} }
@ -1465,8 +1478,10 @@ bool nsDisplayRemote::CreateWebRenderCommands(
if (RefPtr<RemoteBrowser> remoteBrowser = if (RefPtr<RemoteBrowser> remoteBrowser =
GetFrameLoader()->GetRemoteBrowser()) { GetFrameLoader()->GetRemoteBrowser()) {
// Generate an effects update notifying the browser it is visible // Generate an effects update notifying the browser it is visible
aDisplayListBuilder->AddEffectUpdate(remoteBrowser, // TODO - Gather visibleRect and scaling factors
EffectsInfo::FullyVisible()); aDisplayListBuilder->AddEffectUpdate(
remoteBrowser, EffectsInfo::VisibleWithinRect(
mFrame->GetContentRectRelativeToSelf(), 1.0f, 1.0f));
// Create a WebRenderRemoteData to notify the RemoteBrowser when it is no // Create a WebRenderRemoteData to notify the RemoteBrowser when it is no
// longer visible // longer visible

Просмотреть файл

@ -4657,6 +4657,7 @@ void ContainerState::ProcessDisplayItems(nsDisplayList* aList) {
transformNode = transformNode->Parent(); transformNode = transformNode->Parent();
} }
nsRect itemVisibleRectAu = itemContent;
if (transformNode) { if (transformNode) {
// If we are within transform, transform itemContent and itemDrawRect. // If we are within transform, transform itemContent and itemDrawRect.
MOZ_ASSERT(transformNode); MOZ_ASSERT(transformNode);
@ -4818,6 +4819,15 @@ void ContainerState::ProcessDisplayItems(nsDisplayList* aList) {
ContainerLayerParameters params = mParameters; ContainerLayerParameters params = mParameters;
params.mBackgroundColor = uniformColor; params.mBackgroundColor = uniformColor;
params.mLayerCreationHint = GetLayerCreationHint(itemAGR); params.mLayerCreationHint = GetLayerCreationHint(itemAGR);
if (!transformNode) {
params.mItemVisibleRect = &itemVisibleRectAu;
} else {
// We only use mItemVisibleRect for getting the visible rect for
// remote browsers (which should never have inactive transforms), so we
// avoid doing transforms on itemVisibleRectAu above and can't report
// an accurate bounds here.
params.mItemVisibleRect = nullptr;
}
params.mScrollMetadataASR = params.mScrollMetadataASR =
ActiveScrolledRoot::IsAncestor(scrollMetadataASR, ActiveScrolledRoot::IsAncestor(scrollMetadataASR,
mContainerScrollMetadataASR) mContainerScrollMetadataASR)

Просмотреть файл

@ -285,6 +285,7 @@ struct ContainerLayerParameters {
: mXScale(aXScale), : mXScale(aXScale),
mYScale(aYScale), mYScale(aYScale),
mLayerContentsVisibleRect(nullptr), mLayerContentsVisibleRect(nullptr),
mItemVisibleRect(nullptr),
mBackgroundColor(NS_RGBA(0, 0, 0, 0)), mBackgroundColor(NS_RGBA(0, 0, 0, 0)),
mScrollMetadataASR(nullptr), mScrollMetadataASR(nullptr),
mCompositorASR(nullptr), mCompositorASR(nullptr),
@ -298,6 +299,7 @@ struct ContainerLayerParameters {
: mXScale(aXScale), : mXScale(aXScale),
mYScale(aYScale), mYScale(aYScale),
mLayerContentsVisibleRect(nullptr), mLayerContentsVisibleRect(nullptr),
mItemVisibleRect(nullptr),
mOffset(aOffset), mOffset(aOffset),
mBackgroundColor(aParent.mBackgroundColor), mBackgroundColor(aParent.mBackgroundColor),
mScrollMetadataASR(aParent.mScrollMetadataASR), mScrollMetadataASR(aParent.mScrollMetadataASR),
@ -320,6 +322,11 @@ struct ContainerLayerParameters {
*/ */
nsIntRect* mLayerContentsVisibleRect; nsIntRect* mLayerContentsVisibleRect;
/**
* If non-null, the rectangle which stores the item's visible rect.
*/
nsRect* mItemVisibleRect;
/** /**
* An offset to apply to all child layers created. * An offset to apply to all child layers created.
*/ */