Skip to content

Commit

Permalink
[sailfishos][compositor] Implement support for Pausing/Resuming OpenG…
Browse files Browse the repository at this point in the history
…L compositing process.

This patch implements the necessary bits to allowing multiple CompositorOGL
instances to share the same compsiting surface. Without the patch
CompositorOGL::{Pause|Resume} are basically no-ops in embedlite builds.

It's not clear if this patch is needed for gecko v38. Contrary to gecko v31
::Pause and ::Resume calls in v38 are actually implemented for non Android
platforms.

Conflicts:
	gfx/layers/opengl/CompositorOGL.cpp
	gfx/layers/opengl/CompositorOGL.h
  • Loading branch information
tworaz authored and rainemak committed May 27, 2020
1 parent 6c03611 commit 085ea19
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
9 changes: 8 additions & 1 deletion gfx/gl/GLContextProviderEGL.cpp
Expand Up @@ -87,6 +87,7 @@
#include "gfxUtils.h"
#include "GLBlitHelper.h"
#include "GLContextEGL.h"
#include "gfxPrefs.h"
#include "GLContextProvider.h"
#include "GLLibraryEGL.h"
#include "mozilla/ArrayUtils.h"
Expand Down Expand Up @@ -378,7 +379,13 @@ GLContextEGL::IsCurrent() {
bool
GLContextEGL::RenewSurface(nsIWidget* aWidget) {
if (!mOwnsContext) {
return false;
if (gfxPrefs::UseExternalWindow()) {
mSurface = sEGLLibrary.fGetCurrentSurface(LOCAL_EGL_DRAW);
MOZ_ASSERT(mSurface != EGL_NO_SURFACE);
return MakeCurrent(true);
} else {
return false;
}
}
// unconditionally release the surface and create a new one. Don't try to optimize this away.
// If we get here, then by definition we know that we want to get a new surface.
Expand Down
34 changes: 31 additions & 3 deletions gfx/layers/opengl/CompositorOGL.cpp
Expand Up @@ -96,6 +96,7 @@ CompositorOGL::CompositorOGL(CompositorBridgeParent* aParent,
, mFrameInProgress(false)
, mDestroyed(false)
, mViewportSize(0, 0)
, mPaused(false)
, mCurrentProgram(nullptr)
{
MOZ_COUNT_CTOR(CompositorOGL);
Expand Down Expand Up @@ -1712,28 +1713,55 @@ CompositorOGL::CopyToTarget(DrawTarget* aTarget, const nsIntPoint& aTopLeft, con
void
CompositorOGL::Pause()
{
#ifdef MOZ_WIDGET_ANDROID
if (!gl() || gl()->IsDestroyed())
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_QT)
if (!gl() || gl()->IsDestroyed() || !gfxPrefs::UseExternalWindow())
return;

if (mFrameInProgress) {
// The browser may request compositor pause when actual compositing is
// in progress. Make sure we abort this process.
mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0);
mFrameInProgress = false;
mCurrentRenderTarget = nullptr;

if (mTexturePool) {
mTexturePool->EndFrame();
}
}
// ReleaseSurface internally calls MakeCurrent.
gl()->ReleaseSurface();
#endif

mPaused = true;
}

bool
CompositorOGL::Resume()
{
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_UIKIT)
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_UIKIT) || defined(MOZ_WIDGET_QT)
if (!gfxPrefs::UseExternalWindow())
return true;

if (!gl() || gl()->IsDestroyed())
return false;

mPaused = false;

// RenewSurface internally calls MakeCurrent.
return gl()->RenewSurface(GetWidget()->RealWidget());
#endif
return true;
}

bool
CompositorOGL::Ready()
{
if (gfxPrefs::UseExternalWindow() && mPaused) {
return false;
}
return Compositor::Ready();
}

already_AddRefed<DataTextureSource>
CompositorOGL::CreateDataTextureSource(TextureFlags aFlags)
{
Expand Down
2 changes: 2 additions & 0 deletions gfx/layers/opengl/CompositorOGL.h
Expand Up @@ -248,6 +248,7 @@ class CompositorOGL final : public Compositor

virtual void Pause() override;
virtual bool Resume() override;
virtual bool Ready() override;

virtual bool HasImageHostOverlays() override
{
Expand Down Expand Up @@ -486,6 +487,7 @@ class CompositorOGL final : public Compositor
ContextStateTrackerOGL mContextStateTracker;

bool mDestroyed;
bool mPaused;

/**
* Size of the OpenGL context's primary framebuffer in pixels. Used by
Expand Down
1 change: 1 addition & 0 deletions gfx/thebes/gfxPrefs.h
Expand Up @@ -366,6 +366,7 @@ class gfxPrefs final
DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-items", CanvasSkiaGLCacheItems, int32_t, 256);
DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-size", CanvasSkiaGLCacheSize, int32_t, 96);
DECL_GFX_PREF(Once, "gfx.canvas.skiagl.dynamic-cache", CanvasSkiaGLDynamicCache, bool, false);
DECL_GFX_PREF(Once, "gfx.compositor.external-window", UseExternalWindow, bool, false);

DECL_GFX_PREF(Live, "gfx.color_management.enablev4", CMSEnableV4, bool, false);
DECL_GFX_PREF(Live, "gfx.color_management.mode", CMSMode, int32_t,-1);
Expand Down

0 comments on commit 085ea19

Please sign in to comment.