Bug 711168 - Implement the compositor protocol for OMTC. r=cjones
This commit is contained in:
@@ -38,6 +38,8 @@
|
||||
|
||||
#include "mozilla/Util.h"
|
||||
|
||||
#include "mozilla/layers/CompositorChild.h"
|
||||
#include "mozilla/layers/CompositorParent.h"
|
||||
#include "nsBaseWidget.h"
|
||||
#include "nsDeviceContext.h"
|
||||
#include "nsCOMPtr.h"
|
||||
@@ -55,6 +57,7 @@
|
||||
#include "nsIXULRuntime.h"
|
||||
#include "nsIGfxInfo.h"
|
||||
#include "npapi.h"
|
||||
#include "base/thread.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include "nsIObserver.h"
|
||||
@@ -70,6 +73,8 @@ static PRInt32 gNumWidgets;
|
||||
|
||||
using namespace mozilla::layers;
|
||||
using namespace mozilla;
|
||||
using base::Thread;
|
||||
using mozilla::ipc::AsyncChannel;
|
||||
|
||||
nsIContent* nsBaseWidget::mLastRollup = nsnull;
|
||||
|
||||
@@ -104,6 +109,7 @@ nsBaseWidget::nsBaseWidget()
|
||||
, mEventCallback(nsnull)
|
||||
, mViewCallback(nsnull)
|
||||
, mContext(nsnull)
|
||||
, mCompositorThread(nsnull)
|
||||
, mCursor(eCursor_standard)
|
||||
, mWindowType(eWindowType_child)
|
||||
, mBorderStyle(eBorderStyle_none)
|
||||
@@ -142,6 +148,12 @@ nsBaseWidget::~nsBaseWidget()
|
||||
|
||||
if (mLayerManager) {
|
||||
mLayerManager->Destroy();
|
||||
mLayerManager = nsnull;
|
||||
}
|
||||
|
||||
if (mCompositorChild) {
|
||||
mCompositorChild->Destroy();
|
||||
delete mCompositorThread;
|
||||
}
|
||||
|
||||
#ifdef NOISY_WIDGET_LEAKS
|
||||
@@ -814,6 +826,38 @@ nsBaseWidget::GetShouldAccelerate()
|
||||
return mUseAcceleratedRendering;
|
||||
}
|
||||
|
||||
void nsBaseWidget::CreateCompositor()
|
||||
{
|
||||
mCompositorParent = new CompositorParent(this);
|
||||
mCompositorThread = new Thread("CompositorThread");
|
||||
if (mCompositorThread->Start()) {
|
||||
LayerManager* lm = CreateBasicLayerManager();
|
||||
MessageLoop *childMessageLoop = mCompositorThread->message_loop();
|
||||
mCompositorChild = new CompositorChild(lm);
|
||||
AsyncChannel *parentChannel = mCompositorParent->GetIPCChannel();
|
||||
AsyncChannel::Side childSide = mozilla::ipc::AsyncChannel::Child;
|
||||
mCompositorChild->Open(parentChannel, childMessageLoop, childSide);
|
||||
PLayersChild* shadowManager =
|
||||
mCompositorChild->SendPLayersConstructor(LayerManager::LAYERS_OPENGL);
|
||||
|
||||
if (shadowManager) {
|
||||
ShadowLayerForwarder* lf = lm->AsShadowForwarder();
|
||||
if (!lf) {
|
||||
delete lm;
|
||||
mCompositorChild = nsnull;
|
||||
}
|
||||
lf->SetShadowManager(shadowManager);
|
||||
lf->SetParentBackendType(LayerManager::LAYERS_OPENGL);
|
||||
|
||||
mLayerManager = lm;
|
||||
} else {
|
||||
NS_WARNING("fail to construct LayersChild");
|
||||
delete lm;
|
||||
mCompositorChild = nsnull;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LayerManager* nsBaseWidget::GetLayerManager(PLayersChild* aShadowManager,
|
||||
LayersBackend aBackendHint,
|
||||
LayerManagerPersistence aPersistence,
|
||||
@@ -824,16 +868,29 @@ LayerManager* nsBaseWidget::GetLayerManager(PLayersChild* aShadowManager,
|
||||
mUseAcceleratedRendering = GetShouldAccelerate();
|
||||
|
||||
if (mUseAcceleratedRendering) {
|
||||
nsRefPtr<LayerManagerOGL> layerManager = new LayerManagerOGL(this);
|
||||
/**
|
||||
* XXX - On several OSes initialization is expected to fail for now.
|
||||
* If we'd get a none-basic layer manager they'd crash. This is ok though
|
||||
* since on those platforms it will fail. Anyone implementing new
|
||||
* platforms on LayerManagerOGL should ensure their widget is able to
|
||||
* deal with it though!
|
||||
*/
|
||||
if (layerManager->Initialize()) {
|
||||
mLayerManager = layerManager;
|
||||
|
||||
// Try to use an async compositor first, if possible
|
||||
bool useCompositor =
|
||||
Preferences::GetBool("layers.offmainthreadcomposition.enabled", false);
|
||||
if (useCompositor) {
|
||||
// e10s uses the parameter to pass in the shadow manager from the TabChild
|
||||
// so we don't expect to see it there since this doesn't support e10s.
|
||||
NS_ASSERTION(aShadowManager == nsnull, "Async Compositor not supported with e10s");
|
||||
CreateCompositor();
|
||||
}
|
||||
|
||||
if (!mLayerManager) {
|
||||
nsRefPtr<LayerManagerOGL> layerManager = new LayerManagerOGL(this);
|
||||
/**
|
||||
* XXX - On several OSes initialization is expected to fail for now.
|
||||
* If we'd get a non-basic layer manager they'd crash. This is ok though
|
||||
* since on those platforms it will fail. Anyone implementing new
|
||||
* platforms on LayerManagerOGL should ensure their widget is able to
|
||||
* deal with it though!
|
||||
*/
|
||||
if (layerManager->Initialize()) {
|
||||
mLayerManager = layerManager;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!mLayerManager) {
|
||||
|
||||
Reference in New Issue
Block a user