Skip to content

Commit

Permalink
[embedlite] Create compositor parent in CompositorBridgeChild::InitSa…
Browse files Browse the repository at this point in the history
…meProcess (part 1). JB#49551

Compositor parent is created through following path:
- nsWindow::CreateCompositor (is nsBaseWidget)
- gfx::GPUProcessManager::CreateTopLevelCompositor
- InProcessCompositorSession::Create
- CompositorBridgeChild::InitSameProcess
  • Loading branch information
rainemak committed Apr 17, 2020
1 parent 387371a commit b7967c3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 44 deletions.
2 changes: 1 addition & 1 deletion embedding/embedlite/config/mozconfig.merqtxulrunner
Expand Up @@ -6,7 +6,7 @@ export MOZILLA_OFFICIAL=1

mk_add_options PROFILE_GEN_SCRIPT=@TOPSRCDIR@/build/profile_pageloader.pl

export CXXFLAGS="$CXXFLAGS -DUSE_ANDROID_OMTC_HACKS=1 -DUSE_OZONE=1"
export CXXFLAGS="$CXXFLAGS -DUSE_ANDROID_OMTC_HACKS=1 -DUSE_OZONE=1 -DMOZ_EMBEDLITE=1"

ac_add_options --prefix=/usr

Expand Down
24 changes: 11 additions & 13 deletions embedding/embedlite/embedshared/nsWindow.cpp
Expand Up @@ -59,7 +59,6 @@ static void InitPrefs()
nsWindow::nsWindow(EmbedLiteWindowBaseChild *window)
: PuppetWidgetBase()
, mWindow(window)
, mHasCompositor(false)
{
LOGT("nsWindow: %p window: %p", this, mWindow);
InitPrefs();
Expand Down Expand Up @@ -146,16 +145,6 @@ nsWindow::GetNaturalBounds()
return mNaturalBounds;
}

mozilla::layers::CompositorBridgeParent *
nsWindow::NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight)
{
// See nsBaseWidget::CreateCompositor and sha1 bb2cbc24f4cb9bee50a46ba7a520b9016d5207a5
LOGT();
mHasCompositor = true;
return new EmbedLiteCompositorBridgeParent(this, mWindow->GetUniqueID(), true,
aSurfaceWidth, aSurfaceHeight);
}

void
nsWindow::CreateCompositor()
{
Expand All @@ -164,8 +153,6 @@ nsWindow::CreateCompositor()
MOZ_ASSERT(mWindow);
LayoutDeviceIntRect size = mWindow->GetSize();
CreateCompositor(size.width, size.height);

// See nsBaseWidget
}

void
Expand Down Expand Up @@ -334,6 +321,12 @@ nsWindow::RemoveObserver(EmbedLitePuppetWidgetObserver *aObserver)
mObservers.RemoveElement(aObserver);
}

uint32_t nsWindow::GetUniqueID() const
{
MOZ_ASSERT(mWindow);
return mWindow->GetUniqueID();
}

nsWindow::~nsWindow()
{
LOGT("this: %p", this);
Expand All @@ -357,6 +350,11 @@ nsWindow::CreateRootContentController()
return nullptr;
}

bool nsWindow::UseExternalCompositingSurface() const
{
return true;
}

const char *
nsWindow::Type() const
{
Expand Down
9 changes: 4 additions & 5 deletions embedding/embedlite/embedshared/nsWindow.h
Expand Up @@ -53,9 +53,6 @@ class nsWindow : public PuppetWidgetBase

virtual LayoutDeviceIntRect GetNaturalBounds() override;

// TODO: Re-write this
virtual mozilla::layers::CompositorBridgeParent* NewCompositorParent(int aSurfaceWidth,
int aSurfaceHeight);
virtual void CreateCompositor() override;
virtual void CreateCompositor(int aWidth, int aHeight) override;

Expand Down Expand Up @@ -87,13 +84,17 @@ class nsWindow : public PuppetWidgetBase
void AddObserver(EmbedLitePuppetWidgetObserver* aObserver);
void RemoveObserver(EmbedLitePuppetWidgetObserver* aObserver);

uint32_t GetUniqueID() const;

protected:
virtual ~nsWindow() override;

virtual void ConfigureAPZCTreeManager();
virtual void ConfigureAPZControllerThread();
virtual already_AddRefed<GeckoContentController> CreateRootContentController() override;

virtual bool UseExternalCompositingSurface() const override;

const char *Type() const override;

CompositorBridgeParent* GetCompositorBridgeParent() const;
Expand All @@ -107,8 +108,6 @@ class nsWindow : public PuppetWidgetBase

EmbedLiteWindowBaseChild* mWindow; // Not owned, can be null.
InputContext mInputContext;

bool mHasCompositor;
};

} // namespace embedlite
Expand Down
35 changes: 13 additions & 22 deletions embedding/embedlite/embedthread/EmbedLiteCompositorBridgeParent.cpp
Expand Up @@ -38,32 +38,25 @@ namespace embedlite {

static const int sDefaultPaintInterval = nsRefreshDriver::DefaultInterval();

EmbedLiteCompositorBridgeParent::EmbedLiteCompositorBridgeParent(nsIWidget* widget,
uint32_t windowId,
bool aRenderToEGLSurface,
int aSurfaceWidth,
int aSurfaceHeight)
#if 1
: CompositorBridgeParent(CSSToLayoutDeviceScale(1.0),
gfxPlatform::GetPlatform()->GetHardwareVsync()->GetGlobalDisplay().GetVsyncRate(),
aRenderToEGLSurface, gfx::IntSize(aSurfaceWidth, aSurfaceHeight))
EmbedLiteCompositorBridgeParent::EmbedLiteCompositorBridgeParent(uint32_t windowId,
CSSToLayoutDeviceScale aScale,
const TimeDuration &aVsyncRate,
bool aRenderToEGLSurface,
const gfx::IntSize &aSurfaceSize)
: CompositorBridgeParent(aScale, aVsyncRate, aRenderToEGLSurface, aSurfaceSize)
, mWindowId(windowId)
, mCurrentCompositeTask(nullptr)
, mSurfaceSize(aSurfaceWidth, aSurfaceHeight)
, mRenderMutex("EmbedLiteCompositorBridgeParent render mutex")
{
EmbedLiteWindowBaseParent* parentWindow = EmbedLiteWindowBaseParent::From(mWindowId);
LOGT("this:%p, window:%p, sz[%i,%i]", this, parentWindow, aSurfaceWidth, aSurfaceHeight);
LOGT("this:%p, window:%p, sz[%i,%i]", this, parentWindow, aSurfaceSize.width, aSurfaceSize.height);
Preferences::AddBoolVarCache(&mUseExternalGLContext,
"embedlite.compositor.external_gl_context", false);
parentWindow->SetCompositor(this);

// Post open parent?
//
}
#else
{}
#endif

EmbedLiteCompositorBridgeParent::~EmbedLiteCompositorBridgeParent()
{
Expand Down Expand Up @@ -154,7 +147,7 @@ EmbedLiteCompositorBridgeParent::CompositeToDefaultTarget()

if (context->IsOffscreen()) {
MutexAutoLock lock(mRenderMutex);
if (context->OffscreenSize() != mSurfaceSize && !context->ResizeOffscreen(mSurfaceSize)) {
if (context->OffscreenSize() != mEGLSurfaceSize && !context->ResizeOffscreen(mEGLSurfaceSize)) {
return;
}
}
Expand Down Expand Up @@ -194,11 +187,9 @@ EmbedLiteCompositorBridgeParent::PresentOffscreenSurface()

void EmbedLiteCompositorBridgeParent::SetSurfaceSize(int width, int height)
{
if (width > 0 && height > 0 && (mSurfaceSize.width != width || mSurfaceSize.height != height)) {
SetEGLSurfaceSize(width, height);

if (width > 0 && height > 0 && (mEGLSurfaceSize.width != width || mEGLSurfaceSize.height != height)) {
MutexAutoLock lock(mRenderMutex);
mSurfaceSize = gfx::IntSize(width, height);
SetEGLSurfaceSize(width, height);
}
}

Expand Down Expand Up @@ -267,9 +258,9 @@ EmbedLiteCompositorBridgeParent::SuspendRendering()
void
EmbedLiteCompositorBridgeParent::ResumeRendering()
{
if (mSurfaceSize.width > 0 && mSurfaceSize.height > 0) {
CompositorBridgeParent::ScheduleResumeOnCompositorThread(mSurfaceSize.width,
mSurfaceSize.height);
if (mEGLSurfaceSize.width > 0 && mEGLSurfaceSize.height > 0) {
CompositorBridgeParent::ScheduleResumeOnCompositorThread(mEGLSurfaceSize.width,
mEGLSurfaceSize.height);
CompositorBridgeParent::ScheduleRenderOnCompositorThread();
}
}
Expand Down
Expand Up @@ -29,9 +29,11 @@ class EmbedLiteWindowListener;
class EmbedLiteCompositorBridgeParent : public mozilla::layers::CompositorBridgeParent
{
public:
EmbedLiteCompositorBridgeParent(nsIWidget* widget, uint32_t windowId,
bool aRenderToEGLSurface,
int aSurfaceWidth, int aSurfaceHeight);
EmbedLiteCompositorBridgeParent(uint32_t windowId,
CSSToLayoutDeviceScale aScale,
const TimeDuration& aVsyncRate,
bool aRenderToEGLSurface,
const gfx::IntSize& aSurfaceSize);

void SetSurfaceSize(int width, int height);
void* GetPlatformImage(int* width, int* height);
Expand Down
3 changes: 3 additions & 0 deletions embedding/embedlite/moz.build
Expand Up @@ -39,6 +39,9 @@ EXPORTS.mozilla.embedlite += [
'embedshared/EmbedLiteAppBaseChild.h',
'embedshared/EmbedLiteAppChildIface.h',
'embedshared/EmbedLiteViewChildIface.h',
'embedshared/nsWindow.h',
'embedshared/PuppetWidgetBase.h',
'embedthread/EmbedLiteCompositorBridgeParent.h',
'utils/EmbedLog.h',
]

Expand Down

0 comments on commit b7967c3

Please sign in to comment.