Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[embedlite] Fix offscreen rendering pipeline creation. Contributes to…
… JB#35100

When offscreen rendering is enabled the surface size needs to
be known when GLContextProvider::CreateOffscreen is called. If size
is empty, context creation fails and we would create another window instance.

This commit allows us to pass initial window for the EmbedLiteWindow
that will passed to the created Compositor instance from
EmbedLitePuppetWidget::CreateCompositor. This change does not
affect on the external window usage as "embedlite.compositor.external_gl_context"
preference is preferred over MOZ_LAYERS_PREFER_OFFSCREEN environment
variable (see EmbedLitePuppetWidget::GetNativeData and CompositorOGL::CreateContext)

In addition this commit removes mLastViewSize from EmbedLiteCompositorParent
as that will be always the same as mEGLSurfaceSize of the CompositorParent.

Furthermore, setting surface size to zero is know guarded.
  • Loading branch information
rainemak committed Jun 7, 2016
1 parent a305fad commit 448caef
Show file tree
Hide file tree
Showing 22 changed files with 41 additions and 39 deletions.
4 changes: 2 additions & 2 deletions embedding/embedlite/EmbedLiteApp.cpp
Expand Up @@ -447,15 +447,15 @@ EmbedLiteApp::CreateView(EmbedLiteWindow* aWindow, uint32_t aParent, bool aIsPri
}

EmbedLiteWindow*
EmbedLiteApp::CreateWindow()
EmbedLiteApp::CreateWindow(int width, int height)
{
LOGT();
NS_ASSERTION(mState == INITIALIZED, "The app must be up and runnning by now");
static uint32_t sWindowCreateID = 0;
sWindowCreateID++;

PEmbedLiteWindowParent* windowParent = static_cast<PEmbedLiteWindowParent*>(
mAppParent->SendPEmbedLiteWindowConstructor(sWindowCreateID));
mAppParent->SendPEmbedLiteWindowConstructor(width, height, sWindowCreateID));
EmbedLiteWindow* window = new EmbedLiteWindow(this, windowParent, sWindowCreateID);
mWindows[sWindowCreateID] = window;
return window;
Expand Down
2 changes: 1 addition & 1 deletion embedding/embedlite/EmbedLiteApp.h
Expand Up @@ -111,7 +111,7 @@ class EmbedLiteApp
virtual bool StopChildThread();

virtual EmbedLiteView* CreateView(EmbedLiteWindow* aWindow, uint32_t aParent = 0, bool aIsPrivateWindow = false);
virtual EmbedLiteWindow* CreateWindow();
virtual EmbedLiteWindow* CreateWindow(int width, int height);
virtual void DestroyView(EmbedLiteView* aView);
virtual void DestroyWindow(EmbedLiteWindow* aWindow);

Expand Down
2 changes: 1 addition & 1 deletion embedding/embedlite/PEmbedLiteApp.ipdl
Expand Up @@ -24,7 +24,7 @@ parent:

child:
PEmbedLiteView(uint32_t windowId, uint32_t id, uint32_t parentId, bool isPrivateWindow);
PEmbedLiteWindow(uint32_t id);
PEmbedLiteWindow(uint16_t width, uint16_t height, uint32_t id);
PreDestroy();
SetBoolPref(nsCString name, bool value);
SetCharPref(nsCString name, nsCString value);
Expand Down
Expand Up @@ -162,7 +162,7 @@ EmbedLiteAppProcessChild::AllocPEmbedLiteViewChild(const uint32_t& windowId, con
}

PEmbedLiteWindowChild*
EmbedLiteAppProcessChild::AllocPEmbedLiteWindowChild(const uint32_t& id)
EmbedLiteAppProcessChild::AllocPEmbedLiteWindowChild(const uint16_t& width, const uint16_t& height, const uint32_t& id)
{
LOGNI();
return nullptr;
Expand Down
3 changes: 2 additions & 1 deletion embedding/embedlite/embedprocess/EmbedLiteAppProcessChild.h
Expand Up @@ -43,7 +43,8 @@ class EmbedLiteAppProcessChild : public EmbedLiteAppBaseChild
const uint32_t& id,
const uint32_t& parentId,
const bool& isPrivateWindow) override;
virtual PEmbedLiteWindowChild* AllocPEmbedLiteWindowChild(const uint32_t& id) override;
virtual PEmbedLiteWindowChild* AllocPEmbedLiteWindowChild(const uint16_t& width, const uint16_t& height,
const uint32_t& id) override;

virtual PCompositorChild* AllocPCompositorChild(Transport* aTransport, ProcessId aOtherProcess);

Expand Down
Expand Up @@ -260,7 +260,7 @@ EmbedLiteAppProcessParent::DeallocPEmbedLiteViewParent(PEmbedLiteViewParent* aAc
}

PEmbedLiteWindowParent*
EmbedLiteAppProcessParent::AllocPEmbedLiteWindowParent(const uint32_t& id)
EmbedLiteAppProcessParent::AllocPEmbedLiteWindowParent(const uint16_t& width, const uint16_t& height, const uint32_t& id)
{
LOGNI();

Expand Down
Expand Up @@ -60,7 +60,7 @@ class EmbedLiteAppProcessParent : public PEmbedLiteAppParent
DeallocPEmbedLiteViewParent(PEmbedLiteViewParent* aActor);

virtual PEmbedLiteWindowParent*
AllocPEmbedLiteWindowParent(const uint32_t& id) override;
AllocPEmbedLiteWindowParent(const uint16_t& width, const uint16_t& height, const uint32_t& id) override;

virtual bool
DeallocPEmbedLiteWindowParent(PEmbedLiteWindowParent* aActor) override;
Expand Down
9 changes: 6 additions & 3 deletions embedding/embedlite/embedshared/EmbedLiteWindowBaseChild.cpp
Expand Up @@ -25,10 +25,10 @@ namespace embedlite {

static int sWindowCount = 0;

EmbedLiteWindowBaseChild::EmbedLiteWindowBaseChild(const uint32_t& aId)
EmbedLiteWindowBaseChild::EmbedLiteWindowBaseChild(const uint16_t& width, const uint16_t& height, const uint32_t& aId)
: mId(aId)
, mWidget(nullptr)
, mSize(0, 0)
, mSize(width, height)
, mRotation(ROTATION_0)
{
MOZ_COUNT_CTOR(EmbedLiteWindowBaseChild);
Expand Down Expand Up @@ -77,8 +77,8 @@ bool EmbedLiteWindowBaseChild::RecvDestroy()

bool EmbedLiteWindowBaseChild::RecvSetSize(const gfxSize& aSize)
{
LOGT("this:%p", this);
mSize = aSize;
LOGT("this:%p width: %f, height: %f", this, aSize.width, aSize.height);
if (mWidget) {
mWidget->Resize(aSize.width, aSize.height, true);
}
Expand Down Expand Up @@ -151,6 +151,9 @@ void EmbedLiteWindowBaseChild::CreateWidget()
widgetInit.clipChildren = true;
widgetInit.mWindowType = eWindowType_toplevel;
widgetInit.mRequireOffMainThreadCompositing = true;

// EmbedLitePuppetWidget::CreateCompositor() reads back Size
// when it creates the compositor.
mWidget->Create(
nullptr, 0, // no parents
nsIntRect(nsIntPoint(0, 0), nsIntSize(mSize.width, mSize.height)),
Expand Down
2 changes: 1 addition & 1 deletion embedding/embedlite/embedshared/EmbedLiteWindowBaseChild.h
Expand Up @@ -18,7 +18,7 @@ class EmbedLiteWindowBaseChild : public PEmbedLiteWindowChild
NS_INLINE_DECL_REFCOUNTING(EmbedLiteWindowBaseChild)

public:
EmbedLiteWindowBaseChild(const uint32_t& id);
EmbedLiteWindowBaseChild(const uint16_t& width, const uint16_t& height, const uint32_t& id);

uint32_t GetUniqueID() const { return mId; }
EmbedLitePuppetWidget* GetWidget() const;
Expand Down
Expand Up @@ -39,10 +39,11 @@ static inline gfx::SurfaceFormat _depth_to_gfxformat(int depth)

} // namespace

EmbedLiteWindowBaseParent::EmbedLiteWindowBaseParent(const uint32_t& id)
EmbedLiteWindowBaseParent::EmbedLiteWindowBaseParent(const uint16_t& width, const uint16_t& height, const uint32_t& id)
: mId(id)
, mWindow(nullptr)
, mCompositor(nullptr)
, mSize(width, height)
, mRotation(ROTATION_0)
{
MOZ_ASSERT(sWindowMap.find(id) == sWindowMap.end());
Expand Down
Expand Up @@ -25,7 +25,7 @@ class EmbedLiteWindowBaseParent : public PEmbedLiteWindowParent
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(EmbedLiteWindowBaseParent)
public:
EmbedLiteWindowBaseParent(const uint32_t& id);
EmbedLiteWindowBaseParent(const uint16_t& width, const uint16_t& height, const uint32_t& id);

static EmbedLiteWindowBaseParent* From(const uint32_t id);

Expand Down
4 changes: 2 additions & 2 deletions embedding/embedlite/embedthread/EmbedLiteAppThreadChild.cpp
Expand Up @@ -44,10 +44,10 @@ EmbedLiteAppThreadChild::AllocPEmbedLiteViewChild(const uint32_t& windowId, cons
}

PEmbedLiteWindowChild*
EmbedLiteAppThreadChild::AllocPEmbedLiteWindowChild(const uint32_t& id)
EmbedLiteAppThreadChild::AllocPEmbedLiteWindowChild(const uint16_t& width, const uint16_t& height, const uint32_t& id)
{
LOGT("id:%u", id);
EmbedLiteWindowThreadChild* window = new EmbedLiteWindowThreadChild(id);
EmbedLiteWindowThreadChild* window = new EmbedLiteWindowThreadChild(width, height, id);
mWeakWindowMap[id] = window;
window->AddRef();
return window;
Expand Down
2 changes: 1 addition & 1 deletion embedding/embedlite/embedthread/EmbedLiteAppThreadChild.h
Expand Up @@ -21,7 +21,7 @@ class EmbedLiteAppThreadChild : public EmbedLiteAppBaseChild
virtual ~EmbedLiteAppThreadChild();

virtual PEmbedLiteViewChild* AllocPEmbedLiteViewChild(const uint32_t&, const uint32_t&, const uint32_t& parentId, const bool& isPrivateWindow) override;
virtual PEmbedLiteWindowChild* AllocPEmbedLiteWindowChild(const uint32_t&) override;
virtual PEmbedLiteWindowChild* AllocPEmbedLiteWindowChild(const uint16_t& width, const uint16_t& height, const uint32_t&) override;
virtual PCompositorChild* AllocPCompositorChild(Transport* aTransport, ProcessId aOtherProcess);

private:
Expand Down
4 changes: 2 additions & 2 deletions embedding/embedlite/embedthread/EmbedLiteAppThreadParent.cpp
Expand Up @@ -100,10 +100,10 @@ EmbedLiteAppThreadParent::DeallocPEmbedLiteViewParent(PEmbedLiteViewParent* acto
}

PEmbedLiteWindowParent*
EmbedLiteAppThreadParent::AllocPEmbedLiteWindowParent(const uint32_t& id)
EmbedLiteAppThreadParent::AllocPEmbedLiteWindowParent(const uint16_t& width, const uint16_t& height, const uint32_t &id)
{
LOGT("id:%u", id);
EmbedLiteWindowThreadParent* p = new EmbedLiteWindowThreadParent(id);
EmbedLiteWindowThreadParent* p = new EmbedLiteWindowThreadParent(width, height, id);
p->AddRef();
return p;
}
Expand Down
2 changes: 1 addition & 1 deletion embedding/embedlite/embedthread/EmbedLiteAppThreadParent.h
Expand Up @@ -26,7 +26,7 @@ class EmbedLiteAppThreadParent : public PEmbedLiteAppParent
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
virtual PEmbedLiteViewParent* AllocPEmbedLiteViewParent(const uint32_t&, const uint32_t&, const uint32_t&, const bool&) override;
virtual bool DeallocPEmbedLiteViewParent(PEmbedLiteViewParent*) override;
virtual PEmbedLiteWindowParent* AllocPEmbedLiteWindowParent(const uint32_t&) override;
virtual PEmbedLiteWindowParent* AllocPEmbedLiteWindowParent(const uint16_t&, const uint16_t&, const uint32_t&) override;
virtual bool DeallocPEmbedLiteWindowParent(PEmbedLiteWindowParent*) override;

// IPDL interface
Expand Down
19 changes: 9 additions & 10 deletions embedding/embedlite/embedthread/EmbedLiteCompositorParent.cpp
Expand Up @@ -37,19 +37,18 @@ namespace embedlite {
static const int sDefaultPaintInterval = nsRefreshDriver::DefaultInterval();

EmbedLiteCompositorParent::EmbedLiteCompositorParent(nsIWidget* widget,
uint32_t windowId,
uint32_t windowId,
bool aRenderToEGLSurface,
int aSurfaceWidth,
int aSurfaceHeight)
: CompositorParent(widget, aRenderToEGLSurface, aSurfaceWidth, aSurfaceHeight)
, mWindowId(windowId)
, mCurrentCompositeTask(nullptr)
, mLastViewSize(aSurfaceWidth, aSurfaceHeight)
{
EmbedLiteWindowBaseParent* parentWindow = EmbedLiteWindowBaseParent::From(mWindowId);
LOGT("this:%p, window:%p, sz[%i,%i]", this, parentWindow, aSurfaceWidth, aSurfaceHeight);
Preferences::AddBoolVarCache(&mUseExternalGLContext,
"embedlite.compositor.external_gl_context", false);
"embedlite.compositor.external_gl_context", false);
parentWindow->SetCompositor(this);
}

Expand Down Expand Up @@ -124,8 +123,8 @@ EmbedLiteCompositorParent::UpdateTransformState()
GLContext* context = compositor->gl();
NS_ENSURE_TRUE(context, );

if (context->IsOffscreen() && context->OffscreenSize() != mLastViewSize) {
context->ResizeOffscreen(mLastViewSize);
gfx::IntSize eglSize(mEGLSurfaceSize.width, mEGLSurfaceSize.height);
if (context->IsOffscreen() && context->OffscreenSize() != eglSize && context->ResizeOffscreen(eglSize)) {
ScheduleRenderOnCompositorThread();
}
}
Expand Down Expand Up @@ -183,6 +182,7 @@ bool EmbedLiteCompositorParent::RenderGL(TimeStamp aScheduleTime)
if (context->IsOffscreen()) {
GLScreenBuffer* screen = context->Screen();
MOZ_ASSERT(screen);

if (screen->Size().IsEmpty() || !screen->PublishFrame(screen->Size())) {
NS_ERROR("Failed to publish context frame");
return false;
Expand All @@ -200,9 +200,8 @@ bool EmbedLiteCompositorParent::RenderGL(TimeStamp aScheduleTime)

void EmbedLiteCompositorParent::SetSurfaceSize(int width, int height)
{
if (mEGLSurfaceSize.width != width || mEGLSurfaceSize.height != height) {
if (width > 0 && height > 0 && (mEGLSurfaceSize.width != width || mEGLSurfaceSize.height != height)) {
SetEGLSurfaceSize(width, height);
mLastViewSize = gfx::IntSize(width, height);
}
}

Expand Down Expand Up @@ -243,9 +242,9 @@ EmbedLiteCompositorParent::SuspendRendering()
void
EmbedLiteCompositorParent::ResumeRendering()
{
if (mLastViewSize.width > 0 && mLastViewSize.height > 0) {
CompositorParent::ScheduleResumeOnCompositorThread(mLastViewSize.width,
mLastViewSize.height);
if (mEGLSurfaceSize.width > 0 && mEGLSurfaceSize.height > 0) {
CompositorParent::ScheduleResumeOnCompositorThread(mEGLSurfaceSize.width,
mEGLSurfaceSize.height);
CompositorParent::ScheduleRenderOnCompositorThread();
}
}
Expand Down
Expand Up @@ -52,7 +52,6 @@ class EmbedLiteCompositorParent : public mozilla::layers::CompositorParent

uint32_t mWindowId;
CancelableTask* mCurrentCompositeTask;
gfx::IntSize mLastViewSize;
bool mUseExternalGLContext;

DISALLOW_EVIL_CONSTRUCTORS(EmbedLiteCompositorParent);
Expand Down
Expand Up @@ -10,8 +10,8 @@
namespace mozilla {
namespace embedlite {

EmbedLiteWindowThreadChild::EmbedLiteWindowThreadChild(const uint32_t& id)
: EmbedLiteWindowBaseChild(id)
EmbedLiteWindowThreadChild::EmbedLiteWindowThreadChild(const uint16_t& width, const uint16_t& height, const uint32_t& id)
: EmbedLiteWindowBaseChild(width, height, id)
{
LOGT();
}
Expand Down
Expand Up @@ -14,7 +14,7 @@ namespace embedlite {
class EmbedLiteWindowThreadChild : public EmbedLiteWindowBaseChild
{
public:
EmbedLiteWindowThreadChild(const uint32_t& id);
EmbedLiteWindowThreadChild(const uint16_t& width, const uint16_t& height, const uint32_t& id);

protected:
virtual ~EmbedLiteWindowThreadChild();
Expand Down
Expand Up @@ -8,8 +8,8 @@
namespace mozilla {
namespace embedlite {

EmbedLiteWindowThreadParent::EmbedLiteWindowThreadParent(const uint32_t& id)
: EmbedLiteWindowBaseParent(id)
EmbedLiteWindowThreadParent::EmbedLiteWindowThreadParent(const uint16_t& width, const uint16_t& height, const uint32_t& id)
: EmbedLiteWindowBaseParent(width, height, id)
{
}

Expand Down
Expand Up @@ -14,7 +14,7 @@ namespace embedlite {
class EmbedLiteWindowThreadParent : public EmbedLiteWindowBaseParent
{
public:
EmbedLiteWindowThreadParent(const uint32_t& id);
EmbedLiteWindowThreadParent(const uint16_t& width, const uint16_t& height, const uint32_t& id);

protected:
virtual ~EmbedLiteWindowThreadParent() override;
Expand Down
3 changes: 1 addition & 2 deletions embedding/embedlite/tests/embedLiteViewInitTest.cpp
Expand Up @@ -55,8 +55,7 @@ class MyViewListener : public EmbedLiteViewListener
, mWindow(nullptr)
, mView(nullptr)
{
mWindow = mAppListener->App()->CreateWindow();
mWindow->SetSize(800, 600);
mWindow = mAppListener->App()->CreateWindow(800, 600);
mView = mAppListener->App()->CreateView(mWindow);
mView->SetListener(this);
}
Expand Down

0 comments on commit 448caef

Please sign in to comment.