Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[embedlite] Add support for creating external GL context early. JB#30162
In sailfish browser we're interested in creating external window
compositing surface as early as possible. To avoid seeing any rendering
artifacts / content from a previously rendered web page we want to reset
the state of the surface to a know state. Unfortunately gecko creates
it's compositor context after the page being loaded requests it's first
frame to be painted. In majority of cases this is to late for us.

This patch introduces an additional gecko pref which asks the embedder
to create it's GL context as soon as top level PuppetWidget is created
for the view. The initial request is made from the compositor thread
since the GLContext object created by the application will be used from
this thread. The PuppetWidget does not do any caching of the requested
context. It's expected that this part will be handled by the application
itself (already the case for sailfish-browser).
  • Loading branch information
tworaz committed Jun 24, 2015
1 parent 51366e0 commit e214344
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions embedding/embedlite/embedding.js
Expand Up @@ -113,6 +113,10 @@ pref("embedlite.azpc.json.longtap", false);
pref("embedlite.azpc.json.scroll", false);
// Make gecko compositor use GL context/surface provided by the application.
pref("embedlite.compositor.external_gl_context", false);
// Request the application to create GLContext for the compositor as
// soon as the top level PuppetWidget is creted for the view. Setting
// this pref only makes sense when using external compositor gl context.
pref("embedlite.compositor.request_external_gl_context_early", false);
pref("extensions.update.enabled", false);
pref("toolkit.storage.synchronous", 0);
/* new html5 forms */
Expand Down
24 changes: 24 additions & 0 deletions embedding/embedlite/embedshared/EmbedLitePuppetWidget.cpp
Expand Up @@ -51,6 +51,7 @@ const size_t EmbedLitePuppetWidget::kMaxDimension = 4000;
static nsTArray<EmbedLitePuppetWidget*> gTopLevelWindows;
static bool sFailedToCreateGLContext = false;
static bool sUseExternalGLContext = false;
static bool sRequestGLContextEarly = false;

NS_IMPL_ISUPPORTS_INHERITED(EmbedLitePuppetWidget, nsBaseWidget,
nsISupportsWeakReference)
Expand Down Expand Up @@ -101,6 +102,8 @@ EmbedLitePuppetWidget::EmbedLitePuppetWidget(EmbedLiteViewChildIface* aEmbed, ui
if (!prefsInitialized) {
Preferences::AddBoolVarCache(&sUseExternalGLContext,
"embedlite.compositor.external_gl_context", false);
Preferences::AddBoolVarCache(&sRequestGLContextEarly,
"embedlite.compositor.request_external_gl_context_early", false);
prefsInitialized = true;
}
}
Expand Down Expand Up @@ -154,6 +157,13 @@ EmbedLitePuppetWidget::Create(nsIWidget* aParent,
gTopLevelWindows.AppendElement(this);
}

if (sUseExternalGLContext && sRequestGLContextEarly) {
// GetPlatform() should create compositor loop if it doesn't exist, yet.
gfxPlatform::GetPlatform();
CompositorParent::CompositorLoop()->PostTask(FROM_HERE,
NewRunnableFunction(&CreateGLContextEarly, mId));
}

return NS_OK;
}

Expand Down Expand Up @@ -458,6 +468,20 @@ EmbedLitePuppetWidget::GetGLContext() const
return nullptr;
}

void
EmbedLitePuppetWidget::CreateGLContextEarly(uint32_t aViewId)
{
LOGT("ViewId:%u", aViewId);
MOZ_ASSERT(CompositorParent::IsInCompositorThread());
MOZ_ASSERT(sRequestGLContextEarly);
EmbedLiteView* view = EmbedLiteApp::GetInstance()->GetViewByID(aViewId);
if (view) {
view->GetListener()->RequestCurrentGLContext();
} else {
NS_WARNING("Trying to early create GL context for non existing view!");
}
}

LayerManager*
EmbedLitePuppetWidget::GetLayerManager(PLayerTransactionChild* aShadowManager,
LayersBackend aBackendHint,
Expand Down
1 change: 1 addition & 0 deletions embedding/embedlite/embedshared/EmbedLitePuppetWidget.h
Expand Up @@ -172,6 +172,7 @@ class EmbedLitePuppetWidget : public nsBaseWidget
nsresult Paint();
bool ViewIsValid();
mozilla::gl::GLContext* GetGLContext() const;
static void CreateGLContextEarly(uint32_t aViewId);

EmbedLitePuppetWidget* TopWindow();
bool IsTopLevel();
Expand Down

0 comments on commit e214344

Please sign in to comment.