Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[embedlite] Guard swaping while reading platform image. Contributes t…
…o JB#36158

RenderGL is called always from Gecko compositor thread.
GLScreenBuffer::PublishFrame does swap buffers and that
cannot happen while reading content of the previous frame on
EmbedLiteCompositorParent::GetPlatformImage.

This commit adds MutexAutoLock to sync GetPlatformImage
and GLScreenBuffer::PublishFrame calls. For instance
with QtMozEmbed GetPlatformImage is called is called from
Qt rendering thread.
  • Loading branch information
rainemak committed Sep 8, 2016
1 parent c1ee89f commit b6924ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions embedding/embedlite/embedthread/EmbedLiteCompositorParent.cpp
Expand Up @@ -44,6 +44,7 @@ EmbedLiteCompositorParent::EmbedLiteCompositorParent(nsIWidget* widget,
: CompositorParent(widget, aRenderToEGLSurface, aSurfaceWidth, aSurfaceHeight)
, mWindowId(windowId)
, mCurrentCompositeTask(nullptr)
, mRenderMutex("EmbedLiteCompositorParent render mutex")
{
EmbedLiteWindowBaseParent* parentWindow = EmbedLiteWindowBaseParent::From(mWindowId);
LOGT("this:%p, window:%p, sz[%i,%i]", this, parentWindow, aSurfaceWidth, aSurfaceHeight);
Expand Down Expand Up @@ -180,6 +181,11 @@ bool EmbedLiteCompositorParent::RenderGL(TimeStamp aScheduleTime)
}

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 EmbedLiteCompositorParent::GetPlatformImage
// (potentially from another thread).
MutexAutoLock lock(mRenderMutex);
GLScreenBuffer* screen = context->Screen();
MOZ_ASSERT(screen);

Expand Down Expand Up @@ -208,6 +214,7 @@ void EmbedLiteCompositorParent::SetSurfaceSize(int width, int height)
void*
EmbedLiteCompositorParent::GetPlatformImage(int* width, int* height)
{
MutexAutoLock lock(mRenderMutex);
const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(RootLayerTreeId());
NS_ENSURE_TRUE(state && state->mLayerManager, nullptr);

Expand Down
2 changes: 2 additions & 0 deletions embedding/embedlite/embedthread/EmbedLiteCompositorParent.h
Expand Up @@ -9,6 +9,7 @@
#define COMPOSITOR_PERFORMANCE_WARNING

#include "Layers.h"
#include "mozilla/Mutex.h"
#include "mozilla/WidgetUtils.h"
#include "mozilla/layers/CompositorChild.h"
#include "mozilla/layers/CompositorParent.h"
Expand Down Expand Up @@ -53,6 +54,7 @@ class EmbedLiteCompositorParent : public mozilla::layers::CompositorParent
uint32_t mWindowId;
CancelableTask* mCurrentCompositeTask;
bool mUseExternalGLContext;
Mutex mRenderMutex;

DISALLOW_EVIL_CONSTRUCTORS(EmbedLiteCompositorParent);
};
Expand Down

0 comments on commit b6924ca

Please sign in to comment.