Skip to content

Commit

Permalink
Added partial implementation for context suspend/resume functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeshkova committed Sep 4, 2014
1 parent 9db54f7 commit 2aa5a2a
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 1 deletion.
14 changes: 14 additions & 0 deletions embedding/embedlite/EmbedLiteView.cpp
Expand Up @@ -296,6 +296,20 @@ EmbedLiteView::ScheduleRender()
mViewImpl->ScheduleRender();
}

void
EmbedLiteView::SuspendRendering()
{
NS_ENSURE_TRUE(mViewImpl, );
mViewImpl->SuspendRendering();
}

void
EmbedLiteView::ResumeRendering()
{
NS_ENSURE_TRUE(mViewImpl, );
mViewImpl->ResumeRendering();
}

void
EmbedLiteView::ReceiveInputEvent(const InputData& aEvent)
{
Expand Down
3 changes: 3 additions & 0 deletions embedding/embedlite/EmbedLiteView.h
Expand Up @@ -133,6 +133,9 @@ class EmbedLiteView
virtual bool GetPendingTexture(EmbedLiteRenderTarget* aContextWrapper, int* textureID, int* width, int* height, int* textureTarget = 0);
virtual void* GetPlatformImage(int* width, int* height);

virtual void SuspendRendering();
virtual void ResumeRendering();

private:
friend class EmbedLiteViewThreadParent;
friend class EmbedLiteCompositorParent;
Expand Down
2 changes: 2 additions & 0 deletions embedding/embedlite/embedhelpers/EmbedLiteViewIface.idl
Expand Up @@ -60,4 +60,6 @@ interface EmbedLiteViewIface
void GetUniqueID(out uint32_t aId);
void GetPendingTexture(in EmbedLiteRenderTarget aContextWrapper, out int32_t aTextureID, out int32_t aTextureTarget, out int32_t aWidth, out int32_t aHeight);
void GetPlatformImage(out PlatformImage aImage, out int32_t aWidth, out int32_t aHeight);
void SuspendRendering();
void ResumeRendering();
};
31 changes: 30 additions & 1 deletion embedding/embedlite/embedthread/EmbedLiteCompositorParent.cpp
Expand Up @@ -226,7 +226,8 @@ EmbedLiteCompositorParent::GetPlatformImage(int* width, int* height)
NS_ENSURE_TRUE(state && state->mLayerManager, nullptr);

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

SharedSurface* sharedSurf = context->RequestFrame();
NS_ENSURE_TRUE(sharedSurf, nullptr);
Expand All @@ -242,6 +243,34 @@ EmbedLiteCompositorParent::GetPlatformImage(int* width, int* height)
return nullptr;
}

void
EmbedLiteCompositorParent::SuspendRendering()
{
if (!CompositorParent::IsInCompositorThread()) {
CancelableTask* pauseTask = NewRunnableMethod(this, &EmbedLiteCompositorParent::SuspendRendering);
CompositorLoop()->PostTask(FROM_HERE, pauseTask);
return;
}

const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(RootLayerTreeId());
NS_ENSURE_TRUE(state && state->mLayerManager, );
static_cast<CompositorOGL*>(state->mLayerManager->GetCompositor())->Pause();
}

void
EmbedLiteCompositorParent::ResumeRendering()
{
if (!CompositorParent::IsInCompositorThread()) {
CancelableTask* pauseTask = NewRunnableMethod(this, &EmbedLiteCompositorParent::ResumeRendering);
CompositorLoop()->PostTask(FROM_HERE, pauseTask);
return;
}

const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(RootLayerTreeId());
NS_ENSURE_TRUE(state && state->mLayerManager, );
static_cast<CompositorOGL*>(state->mLayerManager->GetCompositor())->Resume();
}

} // namespace embedlite
} // namespace mozilla

2 changes: 2 additions & 0 deletions embedding/embedlite/embedthread/EmbedLiteCompositorParent.h
Expand Up @@ -27,6 +27,8 @@ class EmbedLiteCompositorParent : public mozilla::layers::CompositorParent
bool RenderToContext(gfx::DrawTarget* aTarget);
void SetSurfaceSize(int width, int height);
void* GetPlatformImage(int* width, int* height);
virtual void SuspendRendering();
virtual void ResumeRendering();

protected:
virtual ~EmbedLiteCompositorParent();
Expand Down
20 changes: 20 additions & 0 deletions embedding/embedlite/embedthread/EmbedLiteViewThreadParent.cpp
Expand Up @@ -565,6 +565,26 @@ EmbedLiteViewThreadParent::ScheduleRender()
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteViewThreadParent::ResumeRendering()
{
if (mCompositor) {
mCompositor->ResumeRendering();
}

return NS_OK;
}

NS_IMETHODIMP
EmbedLiteViewThreadParent::SuspendRendering()
{
if (mCompositor) {
mCompositor->SuspendRendering();
}

return NS_OK;
}

NS_IMETHODIMP
EmbedLiteViewThreadParent::ReceiveInputEvent(const mozilla::InputData& aEvent)
{
Expand Down
12 changes: 12 additions & 0 deletions gfx/layers/opengl/CompositorOGL.cpp
Expand Up @@ -1512,6 +1512,12 @@ CompositorOGL::Pause()

// ReleaseSurface internally calls MakeCurrent.
gl()->ReleaseSurface();
#else
if (!gl() || gl()->IsDestroyed())
return;

// TODO: call Layers->SetCompositor(nullptr);
CleanupResources();
#endif
}

Expand All @@ -1524,6 +1530,12 @@ CompositorOGL::Resume()

// RenewSurface internally calls MakeCurrent.
return gl()->RenewSurface();
#else
if (gl() && !gl()->IsDestroyed())
return false;

Initialize();
// TODO: call Layers->SetCompositor(thisOD);
#endif
return true;
}
Expand Down

0 comments on commit 2aa5a2a

Please sign in to comment.