Skip to content

Commit

Permalink
Merge remote-tracking branch 'sailfishos/master' into sailfishos-esr52
Browse files Browse the repository at this point in the history
Rename mozilla::Function to mozilla::function

Gecko commit SHA1 52f227c
Subject: Bug 1253678 - Rename mozilla::Function to mozilla::function. r=froydnj

Disable SharedSurface WaitSync for now

Investigate how this should be implemented. Based on git history
maybe we should use ProducerAcquireImpl() & ProducerReleaseImpl().

Alternatively we can bring back wait from
sha1 b66e705 as embedlite implementation
for the EmbedLiteCompositorBridgeParent.
  • Loading branch information
rainemak committed Apr 17, 2020
2 parents ca68862 + ab66135 commit 1f635f6
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 99 deletions.
5 changes: 5 additions & 0 deletions embedding/embedlite/EmbedLiteWindow.cpp
Expand Up @@ -93,6 +93,11 @@ void* EmbedLiteWindow::GetPlatformImage(int* width, int* height)
return mWindowParent->GetPlatformImage(width, height);
}

void EmbedLiteWindow::GetPlatformImage(const mozilla::function<void(void *image, int width, int height)> &callback)
{
mWindowParent->GetPlatformImage(callback);
}

} // nemsapace embedlite
} // namespace mozilla

2 changes: 2 additions & 0 deletions embedding/embedlite/EmbedLiteWindow.h
Expand Up @@ -9,6 +9,7 @@
#include <stdint.h>

#include "nsRect.h"
#include "mozilla/Function.h"

namespace mozilla {
namespace embedlite {
Expand Down Expand Up @@ -83,6 +84,7 @@ class EmbedLiteWindow {
virtual void SuspendRendering();
virtual void ResumeRendering();
virtual void* GetPlatformImage(int* width, int* height);
virtual void GetPlatformImage(const mozilla::function<void(void *image, int width, int height)> &callback);

protected:
friend class EmbedLiteApp;
Expand Down
2 changes: 1 addition & 1 deletion embedding/embedlite/embedding.js
Expand Up @@ -388,7 +388,7 @@ pref("media.peerconnection.enabled", false);
pref("media.useAudioChannelService", true);

pref("extensions.blocklist.enabled", false);
pref("extensions.logging.enabled", true);
pref("extensions.logging.enabled", false);
pref("extensions.strictCompatibility", false);
pref("extensions.minCompatibleAppVersion", "11.0");

Expand Down
7 changes: 7 additions & 0 deletions embedding/embedlite/embedshared/EmbedLiteWindowBaseParent.cpp
Expand Up @@ -97,6 +97,13 @@ void* EmbedLiteWindowBaseParent::GetPlatformImage(int* width, int* height)
return nullptr;
}

void EmbedLiteWindowBaseParent::GetPlatformImage(const mozilla::function<void(void *image, int width, int height)> &callback)
{
if (mCompositor) {
mCompositor->GetPlatformImage(callback);
}
}

void EmbedLiteWindowBaseParent::SetEmbedAPIWindow(EmbedLiteWindow* window)
{
mWindow = window;
Expand Down
2 changes: 2 additions & 0 deletions embedding/embedlite/embedshared/EmbedLiteWindowBaseParent.h
Expand Up @@ -7,6 +7,7 @@
#define MOZ_WINDOW_EMBED_BASE_PARENT_H

#include "mozilla/embedlite/PEmbedLiteWindowParent.h"
#include "mozilla/Function.h"
#include "mozilla/WidgetUtils.h"

namespace mozilla {
Expand Down Expand Up @@ -40,6 +41,7 @@ class EmbedLiteWindowBaseParent : public PEmbedLiteWindowParent
void SuspendRendering();
void ResumeRendering();
void* GetPlatformImage(int* width, int* height);
void GetPlatformImage(const mozilla::function<void(void *image, int width, int height)> &callback);

protected:
friend class EmbedLiteCompositorBridgeParent;
Expand Down
5 changes: 5 additions & 0 deletions embedding/embedlite/embedshared/nsWindow.cpp
Expand Up @@ -310,6 +310,11 @@ nsWindow::PostRender(mozilla::widget::WidgetRenderingContext *aContext)
{
MOZ_ASSERT(mWindow);
Unused << aContext;

if (GetCompositorBridgeParent()) {
static_cast<EmbedLiteCompositorBridgeParent*>(GetCompositorBridgeParent())->PresentOffscreenSurface();
}

EmbedLiteWindow* window = EmbedLiteApp::GetInstance()->GetWindowByID(mWindow->GetUniqueID());
if (window) {
window->GetListener()->CompositingFinished();
Expand Down
135 changes: 60 additions & 75 deletions embedding/embedlite/embedthread/EmbedLiteCompositorBridgeParent.cpp
Expand Up @@ -104,6 +104,7 @@ bool EmbedLiteCompositorBridgeParent::DeallocPLayerTransactionParent(PLayerTrans
void
EmbedLiteCompositorBridgeParent::PrepareOffscreen()
{
fprintf(stderr, "=============== Preparing offscreen rendering context ===============\n");

const CompositorBridgeParent::LayerTreeState* state = CompositorBridgeParent::GetIndirectShadowTree(RootLayerTreeId());
NS_ENSURE_TRUE(state && state->mLayerManager, );
Expand All @@ -122,15 +123,13 @@ EmbedLiteCompositorBridgeParent::PrepareOffscreen()
}

auto forwarder = state->mLayerManager->AsShadowForwarder()->GetTextureForwarder();
printf("=============== caps.premultAlpha: %d ptr: %p\n", screen->mCaps.premultAlpha, forwarder);
if (context->GetContextType() == GLContextType::EGL) {
// [Basic/OGL Layers, OMTC] WebGL layer init.
factory = SurfaceFactory_EGLImage::Create(context, screen->mCaps, forwarder, flags);
} else {
// [Basic Layers, OMTC] WebGL layer init.
// Well, this *should* work...
GLContext* nullConsGL = nullptr; // Bug 1050044.
// iicpChannel = compositorConnection->GetTextureForwarder()
factory = MakeUnique<SurfaceFactory_GLTexture>(context, screen->mCaps, forwarder, flags);
}
if (factory) {
Expand All @@ -141,108 +140,94 @@ EmbedLiteCompositorBridgeParent::PrepareOffscreen()
}

void
EmbedLiteCompositorBridgeParent::UpdateTransformState()
EmbedLiteCompositorBridgeParent::CompositeToDefaultTarget()
{
const CompositorBridgeParent::LayerTreeState* state = CompositorBridgeParent::GetIndirectShadowTree(RootLayerTreeId());
NS_ENSURE_TRUE(state && state->mLayerManager, );

CompositorOGL *compositor = static_cast<CompositorOGL*>(state->mLayerManager->GetCompositor());
NS_ENSURE_TRUE(compositor, );

GLContext* context = compositor->gl();
GLContext* context = static_cast<CompositorOGL*>(state->mLayerManager->GetCompositor())->gl();
NS_ENSURE_TRUE(context, );

if (context->IsOffscreen() && context->OffscreenSize() != mSurfaceSize && context->ResizeOffscreen(mSurfaceSize)) {
ScheduleRenderOnCompositorThread();
if (!context->IsCurrent()) {
context->MakeCurrent(true);
}
}
NS_ENSURE_TRUE(context->IsCurrent(), );

void
EmbedLiteCompositorBridgeParent::ScheduleTask(already_AddRefed<CancelableRunnable> task, int time)
{
#if 0
if (Invalidate()) {
task->Cancel();
CancelCurrentCompositeTask();
} else {
CompositorBridgeParent::ScheduleTask(task, time);
if (context->IsOffscreen()) {
MutexAutoLock lock(mRenderMutex);
if (context->OffscreenSize() != mSurfaceSize && !context->ResizeOffscreen(mSurfaceSize)) {
return;
}
}
#endif
}

bool
EmbedLiteCompositorBridgeParent::Invalidate()
{
if (!mUseExternalGLContext) {
UpdateTransformState();
mCurrentCompositeTask = NewCancelableRunnableMethod<mozilla::TimeStamp>(this,
&EmbedLiteCompositorBridgeParent::RenderGL,
TimeStamp::Now());
RefPtr<Runnable> addrefedTask = mCurrentCompositeTask;
MessageLoop::current()->PostDelayedTask(addrefedTask.forget(), sDefaultPaintInterval);
return true;
{
ScopedScissorRect autoScissor(context);
GLenum oldTexUnit;
context->GetUIntegerv(LOCAL_GL_ACTIVE_TEXTURE, &oldTexUnit);
CompositeToTarget(nullptr);
context->fActiveTexture(oldTexUnit);
}

return false;
}

bool EmbedLiteCompositorBridgeParent::RenderGL(TimeStamp aScheduleTime)
void
EmbedLiteCompositorBridgeParent::PresentOffscreenSurface()
{
if (mCurrentCompositeTask) {
mCurrentCompositeTask->Cancel();
mCurrentCompositeTask = nullptr;
}

const CompositorBridgeParent::LayerTreeState* state = CompositorBridgeParent::GetIndirectShadowTree(RootLayerTreeId());
NS_ENSURE_TRUE(state && state->mLayerManager, false);
NS_ENSURE_TRUE(state && state->mLayerManager, );

GLContext* context = static_cast<CompositorOGL*>(state->mLayerManager->GetCompositor())->gl();
NS_ENSURE_TRUE(context, false);
if (!context->IsCurrent()) {
context->MakeCurrent(true);
}
NS_ENSURE_TRUE(context->IsCurrent(), false);
NS_ENSURE_TRUE(context, );
NS_ENSURE_TRUE(context->IsOffscreen(), );

{
ScopedScissorRect autoScissor(context);
GLenum oldTexUnit;
context->GetUIntegerv(LOCAL_GL_ACTIVE_TEXTURE, &oldTexUnit);
CompositeToTarget(nullptr);
context->fActiveTexture(oldTexUnit);
}
// RenderGL is called always from Gecko compositor thread.
// GLScreenBuffer::PublishFrame does swap buffers and that
// cannot happen while reading previous frame on EmbedLiteCompositorBridgeParent::GetPlatformImage
// (potentially from another thread).
MutexAutoLock lock(mRenderMutex);

if (context->IsOffscreen()) {
// RenderGL is called always from Gecko compositor thread.
// GLScreenBuffer::PublishFrame does swap buffers and that
// cannot happen while reading previous frame on EmbedLiteCompositorBridgeParent::GetPlatformImage
// (potentially from another thread).
MutexAutoLock lock(mRenderMutex);
GLScreenBuffer* screen = context->Screen();
MOZ_ASSERT(screen);
GLScreenBuffer* screen = context->Screen();
MOZ_ASSERT(screen);

if (screen->Size().IsEmpty() || !screen->PublishFrame(screen->Size())) {
NS_ERROR("Failed to publish context frame");
return false;
}
// Temporary hack, we need two extra paints in order to get initial picture
static int sInitialPaintCount = 0;
if (sInitialPaintCount < 2) {
ScheduleRenderOnCompositorThread();
sInitialPaintCount++;
}
if (screen->Size().IsEmpty() || !screen->PublishFrame(screen->Size())) {
NS_ERROR("Failed to publish context frame");
}

return false;
}

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

MutexAutoLock lock(mRenderMutex);
mSurfaceSize = gfx::IntSize(width, height);
}
}

void
EmbedLiteCompositorBridgeParent::GetPlatformImage(const mozilla::function<void(void *image, int width, int height)> &callback)
{
MutexAutoLock lock(mRenderMutex);
const CompositorBridgeParent::LayerTreeState* state = CompositorBridgeParent::GetIndirectShadowTree(RootLayerTreeId());
NS_ENSURE_TRUE(state && state->mLayerManager, );

GLContext* context = static_cast<CompositorOGL*>(state->mLayerManager->GetCompositor())->gl();
NS_ENSURE_TRUE(context, );
NS_ENSURE_TRUE(context->IsOffscreen(), );

GLScreenBuffer* screen = context->Screen();
MOZ_ASSERT(screen);
NS_ENSURE_TRUE(screen->Front(),);
SharedSurface* sharedSurf = screen->Front()->Surf();
NS_ENSURE_TRUE(sharedSurf, );
// sharedSurf->WaitSync();
// See ProducerAcquireImpl() & ProducerReleaseImpl()
// See sha1 b66e705f3998791c137f8fce908ec0835b84afbe from gecko-mirror

if (sharedSurf->mType == SharedSurfaceType::EGLImageShare) {
SharedSurface_EGLImage* eglImageSurf = SharedSurface_EGLImage::Cast(sharedSurf);
callback(eglImageSurf->mImage, sharedSurf->mSize.width, sharedSurf->mSize.height);
}
}

void*
EmbedLiteCompositorBridgeParent::GetPlatformImage(int* width, int* height)
{
Expand All @@ -260,7 +245,7 @@ EmbedLiteCompositorBridgeParent::GetPlatformImage(int* width, int* height)
SharedSurface* sharedSurf = screen->Front()->Surf();
NS_ENSURE_TRUE(sharedSurf, nullptr);
// sharedSurf->WaitSync();
// ProducerAcquire & ProducerRelease ?
// ProducerAcquireImpl & ProducerReleaseImpl ?

*width = sharedSurf->mSize.width;
*height = sharedSurf->mSize.height;
Expand Down
Expand Up @@ -9,6 +9,7 @@
#define COMPOSITOR_PERFORMANCE_WARNING

#include "Layers.h"
#include "mozilla/Function.h"
#include "base/task.h" // for CancelableRunnable
#include "mozilla/Mutex.h"
#include "mozilla/WidgetUtils.h"
Expand All @@ -23,6 +24,8 @@ class LayerManagerComposite;

namespace embedlite {

class EmbedLiteWindowListener;

class EmbedLiteCompositorBridgeParent : public mozilla::layers::CompositorBridgeParent
{
public:
Expand All @@ -32,9 +35,12 @@ class EmbedLiteCompositorBridgeParent : public mozilla::layers::CompositorBridge

void SetSurfaceSize(int width, int height);
void* GetPlatformImage(int* width, int* height);
void GetPlatformImage(const mozilla::function<void(void *image, int width, int height)> &callback);
void SuspendRendering();
void ResumeRendering();

void PresentOffscreenSurface();

protected:
friend class EmbedLitePuppetWidget;

Expand All @@ -45,13 +51,10 @@ class EmbedLiteCompositorBridgeParent : public mozilla::layers::CompositorBridge
TextureFactoryIdentifier* aTextureFactoryIdentifier,
bool* aSuccess) override;
virtual bool DeallocPLayerTransactionParent(PLayerTransactionParent* aLayers) override;
virtual void ScheduleTask(already_AddRefed<CancelableRunnable>, int) override;
virtual void CompositeToDefaultTarget() override;

private:
void PrepareOffscreen();
bool Invalidate();
void UpdateTransformState();
bool RenderGL(TimeStamp aScheduleTime);

uint32_t mWindowId;
RefPtr<CancelableRunnable> mCurrentCompositeTask;
Expand Down
@@ -0,0 +1,74 @@
From f2e8fe315400e9df42d1e89a7d7bacf4fe6038c1 Mon Sep 17 00:00:00 2001
From: Andrew den Exter <andrew.den.exter@qinetic.com.au>
Date: Mon, 9 Dec 2019 01:29:16 +0000
Subject: [PATCH] Allow compositor specializations to override the composite
command.

---
gfx/layers/ipc/CompositorParent.cpp | 16 +++++++++++++---
gfx/layers/ipc/CompositorParent.h | 1 +
2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/gfx/layers/ipc/CompositorParent.cpp b/gfx/layers/ipc/CompositorParent.cpp
index be0f067..c3cc99b 100644
--- a/gfx/layers/ipc/CompositorParent.cpp
+++ b/gfx/layers/ipc/CompositorParent.cpp
@@ -437,7 +437,7 @@ CompositorVsyncScheduler::Composite(TimeStamp aVsyncTimestamp)
if (mNeedsComposite || mAsapScheduling) {
mNeedsComposite = 0;
mLastCompose = aVsyncTimestamp;
- ComposeToTarget(nullptr);
+ mCompositorParent->CompositeToDefaultTarget();
mVsyncNotificationsSkipped = 0;

TimeDuration compositeFrameTotal = TimeStamp::Now() - aVsyncTimestamp;
@@ -548,7 +548,7 @@ CompositorVsyncScheduler::ResumeComposition()
{
MOZ_ASSERT(CompositorParent::IsInCompositorThread());
mLastCompose = TimeStamp::Now();
- ComposeToTarget(nullptr);
+ mCompositorParent->CompositeToDefaultTarget();
}

void
@@ -556,7 +556,11 @@ CompositorVsyncScheduler::ComposeToTarget(gfx::DrawTarget* aTarget, const IntRec
{
MOZ_ASSERT(CompositorParent::IsInCompositorThread());
MOZ_ASSERT(mCompositorParent);
- mCompositorParent->CompositeToTarget(aTarget, aRect);
+ if (aTarget) {
+ mCompositorParent->CompositeToTarget(aTarget, aRect);
+ } else {
+ mCompositorParent->CompositeToDefaultTarget();
+ }
}

CompositorParent::CompositorParent(nsIWidget* aWidget,
@@ -1044,6 +1048,12 @@ CompositorParent::SetShadowProperties(Layer* aLayer)
}

void
+CompositorParent::CompositeToDefaultTarget()
+{
+ CompositeToTarget(nullptr);
+}
+
+void
CompositorParent::CompositeToTarget(DrawTarget* aTarget, const gfx::IntRect* aRect)
{
profiler_tracing("Paint", "Composite", TRACING_INTERVAL_START);
diff --git a/gfx/layers/ipc/CompositorParent.h b/gfx/layers/ipc/CompositorParent.h
index bc9a319..7ca9053 100644
--- a/gfx/layers/ipc/CompositorParent.h
+++ b/gfx/layers/ipc/CompositorParent.h
@@ -422,6 +422,7 @@ protected:
virtual void ScheduleTask(CancelableTask*, int);
void CompositeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect = nullptr);
void ForceComposeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect = nullptr);
+ virtual void CompositeToDefaultTarget();

void SetEGLSurfaceSize(int width, int height);

--
1.8.3-rc3

0 comments on commit 1f635f6

Please sign in to comment.