From 66a8a0359fcb971d9c4a939f38ea6de6c3a7ce88 Mon Sep 17 00:00:00 2001 From: Oleg Romashin Date: Tue, 8 May 2012 12:40:41 -0700 Subject: [PATCH] Bug 752643 - Make CompositorParent eglSurface setup available for non-android environment. r=ajuma --- gfx/layers/ipc/CompositorParent.cpp | 29 +++++++++++++++++++---------- gfx/layers/ipc/CompositorParent.h | 7 ++++++- widget/xpwidgets/nsBaseWidget.cpp | 10 +++++++++- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/gfx/layers/ipc/CompositorParent.cpp b/gfx/layers/ipc/CompositorParent.cpp index 4c138360a43..8c3be5e4de0 100644 --- a/gfx/layers/ipc/CompositorParent.cpp +++ b/gfx/layers/ipc/CompositorParent.cpp @@ -57,7 +57,9 @@ using base::Thread; namespace mozilla { namespace layers { -CompositorParent::CompositorParent(nsIWidget* aWidget, MessageLoop* aMsgLoop, PlatformThreadId aThreadID) +CompositorParent::CompositorParent(nsIWidget* aWidget, MessageLoop* aMsgLoop, + PlatformThreadId aThreadID, bool aRenderToEGLSurface, + int aSurfaceWidth, int aSurfaceHeight) : mWidget(aWidget) , mCurrentCompositeTask(NULL) , mPaused(false) @@ -67,6 +69,8 @@ CompositorParent::CompositorParent(nsIWidget* aWidget, MessageLoop* aMsgLoop, Pl , mLayersUpdated(false) , mCompositorLoop(aMsgLoop) , mThreadID(aThreadID) + , mRenderToEGLSurface(aRenderToEGLSurface) + , mEGLSurfaceSize(aSurfaceWidth, aSurfaceHeight) { MOZ_COUNT_CTOR(CompositorParent); } @@ -163,10 +167,20 @@ CompositorParent::ResumeComposition() #endif } +void +CompositorParent::SetEGLSurfaceSize(int width, int height) +{ + NS_ASSERTION(mRenderToEGLSurface, "Compositor created without RenderToEGLSurface ar provided"); + mEGLSurfaceSize.SizeTo(width, height); + if (mLayerManager) { + static_cast(mLayerManager.get())->SetSurfaceSize(mEGLSurfaceSize.width, mEGLSurfaceSize.height); + } +} + void CompositorParent::ResumeCompositionAndResize(int width, int height) { - static_cast(mLayerManager.get())->SetSurfaceSize(width, height); + SetEGLSurfaceSize(width, height); ResumeComposition(); } @@ -434,14 +448,9 @@ PLayersParent* CompositorParent::AllocPLayers(const LayersBackend &backendType) { if (backendType == LayerManager::LAYERS_OPENGL) { -#ifdef MOZ_JAVA_COMPOSITOR - nsIntRect rect; - mWidget->GetBounds(rect); - nsRefPtr layerManager = - new LayerManagerOGL(mWidget, rect.width, rect.height, true); -#else - nsRefPtr layerManager = new LayerManagerOGL(mWidget); -#endif + nsRefPtr layerManager; + layerManager = + new LayerManagerOGL(mWidget, mEGLSurfaceSize.width, mEGLSurfaceSize.height, mRenderToEGLSurface); mWidget = NULL; mLayerManager = layerManager; diff --git a/gfx/layers/ipc/CompositorParent.h b/gfx/layers/ipc/CompositorParent.h index 0e1cccb337d..46e10b92fdb 100644 --- a/gfx/layers/ipc/CompositorParent.h +++ b/gfx/layers/ipc/CompositorParent.h @@ -86,7 +86,9 @@ class CompositorParent : public PCompositorParent, { NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorParent) public: - CompositorParent(nsIWidget* aWidget, MessageLoop* aMsgLoop, PlatformThreadId aThreadID); + CompositorParent(nsIWidget* aWidget, MessageLoop* aMsgLoop, + PlatformThreadId aThreadID, bool aRenderToEGLSurface = false, + int aSurfaceWidth = -1, int aSurfaceHeight = -1); virtual ~CompositorParent(); @@ -119,6 +121,7 @@ protected: virtual void SetPageSize(float aZoom, float aPageWidth, float aPageHeight, float aCssPageWidth, float aCssPageHeight); virtual void SyncViewportInfo(const nsIntRect& aDisplayPort, float aDisplayResolution, bool aLayersUpdated, nsIntPoint& aScrollOffset, float& aScaleX, float& aScaleY); + void SetEGLSurfaceSize(int width, int height); private: void PauseComposition(); @@ -164,6 +167,8 @@ private: MessageLoop* mCompositorLoop; PlatformThreadId mThreadID; + bool mRenderToEGLSurface; + nsIntSize mEGLSurfaceSize; DISALLOW_EVIL_CONSTRUCTORS(CompositorParent); }; diff --git a/widget/xpwidgets/nsBaseWidget.cpp b/widget/xpwidgets/nsBaseWidget.cpp index 619d2829bae..f4221c3007e 100644 --- a/widget/xpwidgets/nsBaseWidget.cpp +++ b/widget/xpwidgets/nsBaseWidget.cpp @@ -874,7 +874,15 @@ void nsBaseWidget::CreateCompositor() { mCompositorThread = new Thread("CompositorThread"); if (mCompositorThread->Start()) { - mCompositorParent = new CompositorParent(this, mCompositorThread->message_loop(), mCompositorThread->thread_id()); + bool renderToEGLSurface = false; +#ifdef MOZ_JAVA_COMPOSITOR + renderToEGLSurface = true; +#endif + nsIntRect rect; + GetBounds(rect); + mCompositorParent = + new CompositorParent(this, mCompositorThread->message_loop(), mCompositorThread->thread_id(), + renderToEGLSurface, rect.width, rect.height); LayerManager* lm = CreateBasicLayerManager(); MessageLoop *childMessageLoop = mCompositorThread->message_loop(); mCompositorChild = new CompositorChild(lm);