Skip to content

Commit

Permalink
Implemented clean version of derived compositor
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeshkova committed May 28, 2014
1 parent f6ecd20 commit 80790a7
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 65 deletions.
56 changes: 42 additions & 14 deletions embedding/embedlite/embedthread/EmbedLiteCompositorParent.cpp
Expand Up @@ -36,24 +36,41 @@ EmbedLiteCompositorParent::EmbedLiteCompositorParent(nsIWidget* aWidget,
int aSurfaceWidth,
int aSurfaceHeight,
uint32_t id)
: mId(id)
: CompositorParent(aWidget, aRenderToEGLSurface, aSurfaceWidth, aSurfaceHeight)
, mId(id)
, mCurrentCompositeTask(nullptr)
, mLastViewSize(aSurfaceWidth, aSurfaceHeight)
, mInitialPaintCount(0)
{
mCompositor = new CompositorParent(aWidget, aRenderToEGLSurface, aSurfaceWidth, aSurfaceHeight);
mCompositor->SetCompositorInterface(this);
EmbedLiteView* view = EmbedLiteApp::GetInstance()->GetViewByID(mId);
LOGT("this:%p, view:%p", this, view);
MOZ_ASSERT(view, "Something went wrong, Compositor not suspended on destroy?");
EmbedLiteViewThreadParent* pview = static_cast<EmbedLiteViewThreadParent*>(view->GetImpl());
pview->SetCompositor(this);
}

EmbedLiteCompositorParent::~EmbedLiteCompositorParent()
bool
EmbedLiteCompositorParent::RecvStop()
{
LOGT();
EmbedLiteApp::GetInstance()->ViewDestroyed(mId);
return CompositorParent::RecvStop();
}

PLayerTransactionParent*
EmbedLiteCompositorParent::AllocPLayerTransactionParent(const nsTArray<LayersBackend>& aBackendHints,
const uint64_t& aId,
TextureFactoryIdentifier* aTextureFactoryIdentifier,
bool* aSuccess)
{
PLayerTransactionParent* p =
CompositorParent::AllocPLayerTransactionParent(aBackendHints,
aId,
aTextureFactoryIdentifier,
aSuccess);

Created();
return p;
}

void
Expand All @@ -65,7 +82,7 @@ EmbedLiteCompositorParent::Created()
listener->CompositorCreated();
}

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

GLContext* context = static_cast<CompositorOGL*>(state->mLayerManager->GetCompositor())->gl();
Expand Down Expand Up @@ -96,7 +113,7 @@ EmbedLiteCompositorParent::Created()
void
EmbedLiteCompositorParent::UpdateTransformState()
{
const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(mCompositor->RootLayerTreeId());
const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(RootLayerTreeId());
NS_ENSURE_TRUE(state && state->mLayerManager, );

GLContext* context = static_cast<CompositorOGL*>(state->mLayerManager->GetCompositor())->gl();
Expand All @@ -110,7 +127,17 @@ EmbedLiteCompositorParent::UpdateTransformState()

if (context->IsOffscreen() && context->OffscreenSize() != mLastViewSize) {
context->ResizeOffscreen(gfx::IntSize(mLastViewSize.width, mLastViewSize.height));
mCompositor->ScheduleRenderOnCompositorThread();
ScheduleRenderOnCompositorThread();
}
}

void
EmbedLiteCompositorParent::ScheduleTask(CancelableTask* task, int time)
{
if (Invalidate()) {
CancelCurrentCompositeTask();
} else {
CompositorParent::ScheduleTask(task, time);
}
}

Expand All @@ -129,22 +156,23 @@ EmbedLiteCompositorParent::Invalidate()
if (!view->GetListener()->Invalidate()) {
mCurrentCompositeTask = NewRunnableMethod(this, &EmbedLiteCompositorParent::RenderGL);
MessageLoop::current()->PostDelayedTask(FROM_HERE, mCurrentCompositeTask, 16);
return true;
}

return true;
return false;
}

bool EmbedLiteCompositorParent::RenderToContext(gfx::DrawTarget* aTarget)
{
LOGF();
const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(mCompositor->RootLayerTreeId());
const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(RootLayerTreeId());

NS_ENSURE_TRUE(state->mLayerManager, false);
if (!state->mLayerManager->GetRoot()) {
// Nothing to paint yet, just return silently
return false;
}
mCompositor->CompositeToTarget(aTarget);
CompositeToTarget(aTarget);
return true;
}

Expand All @@ -155,7 +183,7 @@ bool EmbedLiteCompositorParent::RenderGL()
mCurrentCompositeTask = nullptr;
}

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

GLContext* context = static_cast<CompositorOGL*>(state->mLayerManager->GetCompositor())->gl();
Expand All @@ -165,7 +193,7 @@ bool EmbedLiteCompositorParent::RenderGL()
ScopedScissorRect autoScissor(context);
GLenum oldTexUnit;
context->GetUIntegerv(LOCAL_GL_ACTIVE_TEXTURE, &oldTexUnit);
mCompositor->CompositeToTarget(nullptr);
CompositeToTarget(nullptr);
context->fActiveTexture(oldTexUnit);
}

Expand All @@ -175,7 +203,7 @@ bool EmbedLiteCompositorParent::RenderGL()
}
// Temporary hack, we need two extra paints in order to get initial picture
if (mInitialPaintCount < 2) {
mCompositor->ScheduleRenderOnCompositorThread();
ScheduleRenderOnCompositorThread();
mInitialPaintCount++;
}
}
Expand All @@ -191,7 +219,7 @@ bool EmbedLiteCompositorParent::RenderGL()
void EmbedLiteCompositorParent::SetSurfaceSize(int width, int height)
{
mLastViewSize.SizeTo(width, height);
mCompositor->SetEGLSurfaceSize(width, height);
SetEGLSurfaceSize(width, height);
}

void EmbedLiteCompositorParent::SetWorldTransform(gfx::Matrix aMatrix)
Expand Down
16 changes: 10 additions & 6 deletions embedding/embedlite/embedthread/EmbedLiteCompositorParent.h
Expand Up @@ -16,9 +16,8 @@
namespace mozilla {
namespace embedlite {

class EmbedLiteCompositorParent : public mozilla::layers::ICompositorListener
class EmbedLiteCompositorParent : public mozilla::layers::CompositorParent
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(EmbedLiteCompositorParent)
public:
EmbedLiteCompositorParent(nsIWidget* aWidget,
bool aRenderToEGLSurface,
Expand All @@ -30,10 +29,16 @@ class EmbedLiteCompositorParent : public mozilla::layers::ICompositorListener
void SetSurfaceSize(int width, int height);
void SetWorldTransform(gfx::Matrix);
void SetClipping(const gfxRect& aClipRect);
mozilla::layers::CompositorParent* Compositor() { return mCompositor.get(); }
mozilla::layers::CompositorParent* Compositor() { return this; }

private:
virtual ~EmbedLiteCompositorParent();
protected:
virtual PLayerTransactionParent*
AllocPLayerTransactionParent(const nsTArray<LayersBackend>& aBackendHints,
const uint64_t& aId,
TextureFactoryIdentifier* aTextureFactoryIdentifier,
bool* aSuccess) MOZ_OVERRIDE;
virtual void ScheduleTask(CancelableTask*, int);
virtual bool RecvStop() MOZ_OVERRIDE;

virtual void Created();
virtual bool Invalidate();
Expand All @@ -45,7 +50,6 @@ class EmbedLiteCompositorParent : public mozilla::layers::ICompositorListener
CancelableTask* mCurrentCompositeTask;
gfx::IntSize mLastViewSize;
short mInitialPaintCount;
RefPtr<mozilla::layers::CompositorParent> mCompositor;
};

} // embedlite
Expand Down
4 changes: 1 addition & 3 deletions embedding/embedlite/embedthread/EmbedLitePuppetWidget.cpp
Expand Up @@ -181,7 +181,6 @@ EmbedLitePuppetWidget::Destroy()
mLayerManager = nullptr;
mEmbed = nullptr;
mChild = nullptr;
mCompositorWrapper = nullptr;

DestroyCompositor();

Expand Down Expand Up @@ -490,8 +489,7 @@ CompositorParent*
EmbedLitePuppetWidget::NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight)
{
gfxPlatform::GetPlatform();
mCompositorWrapper = new EmbedLiteCompositorParent(this, true, aSurfaceWidth, aSurfaceHeight, mId);
return mCompositorWrapper->Compositor();
return new EmbedLiteCompositorParent(this, true, aSurfaceWidth, aSurfaceHeight, mId);
}

void EmbedLitePuppetWidget::CreateCompositor()
Expand Down
1 change: 0 additions & 1 deletion embedding/embedlite/embedthread/EmbedLitePuppetWidget.h
Expand Up @@ -173,7 +173,6 @@ class EmbedLitePuppetWidget : public nsBaseWidget,
nsCOMPtr<nsIWidget> mParent;

uint32_t mId;
RefPtr<EmbedLiteCompositorParent> mCompositorWrapper;
};

} // namespace widget
Expand Down
15 changes: 0 additions & 15 deletions gfx/layers/ipc/CompositorParent.cpp
Expand Up @@ -201,7 +201,6 @@ CompositorParent::CompositorParent(nsIWidget* aWidget,
, mOverrideComposeReadiness(false)
, mForceCompositionTask(nullptr)
, mWantDidCompositeEvent(false)
, mListener(nullptr)
{
NS_ABORT_IF_FALSE(sCompositorThread != nullptr || sCompositorThreadID,
"The compositor thread must be Initialized before instanciating a COmpositorParent.");
Expand All @@ -222,12 +221,6 @@ CompositorParent::CompositorParent(nsIWidget* aWidget,
++sCompositorThreadRefCount;
}

void
CompositorParent::SetCompositorInterface(ICompositorListener* aListener)
{
mListener = aListener;
}

PlatformThreadId
CompositorParent::CompositorThreadID()
{
Expand Down Expand Up @@ -526,11 +519,6 @@ CompositorParent::ScheduleResumeOnCompositorThread(int width, int height)
void
CompositorParent::ScheduleTask(CancelableTask* task, int time)
{
if (mListener && mListener->Invalidate()) {
CancelCurrentCompositeTask();
return;
}

if (time == 0) {
MessageLoop::current()->PostTask(FROM_HERE, task);
} else {
Expand Down Expand Up @@ -958,9 +946,6 @@ CompositorParent::AllocPLayerTransactionParent(const nsTArray<LayersBackend>& aB
LayerTransactionParent* p = new LayerTransactionParent(mLayerManager, this, 0,
// child side's process id is current process Id
base::GetProcId(base::GetCurrentProcessHandle()));
if (mListener) {
mListener->Created();
}
p->AddIPDLReference();
return p;
}
Expand Down
36 changes: 10 additions & 26 deletions gfx/layers/ipc/CompositorParent.h
Expand Up @@ -52,13 +52,6 @@ class Compositor;
class LayerManagerComposite;
class LayerTransactionParent;

class ICompositorListener
{
public:
virtual void Created() {};
virtual bool Invalidate() { return false; };
};

struct ScopedLayerTreeRegistration
{
ScopedLayerTreeRegistration(uint64_t aLayersId,
Expand All @@ -70,8 +63,8 @@ struct ScopedLayerTreeRegistration
uint64_t mLayersId;
};

class CompositorParent MOZ_FINAL : public PCompositorParent,
public ShadowLayersManager
class CompositorParent : public PCompositorParent,
public ShadowLayersManager
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorParent)

Expand All @@ -80,8 +73,6 @@ class CompositorParent MOZ_FINAL : public PCompositorParent,
bool aUseExternalSurfaceSize = false,
int aSurfaceWidth = -1, int aSurfaceHeight = -1);

void SetCompositorInterface(ICompositorListener* aListener);

// IToplevelProtocol::CloneToplevel()
virtual IToplevelProtocol*
CloneToplevel(const InfallibleTArray<mozilla::ipc::ProtocolFdMapping>& aFds,
Expand Down Expand Up @@ -251,27 +242,22 @@ class CompositorParent MOZ_FINAL : public PCompositorParent,
*/
static bool IsInCompositorThread();

/*
* Setup compositor surface size, must be called in Compositor parent thread
*/
void SetEGLSurfaceSize(int width, int height);

/*
* Composite to Target, if target is null, then compositing will be done to Current GL context
*/
void CompositeToTarget(gfx::DrawTarget* aTarget);

private:
// Private destructor, to discourage deletion outside of Release():
protected:
// protected destructor, to discourage deletion outside of Release():
virtual ~CompositorParent();

virtual PLayerTransactionParent*
AllocPLayerTransactionParent(const nsTArray<LayersBackend>& aBackendHints,
const uint64_t& aId,
TextureFactoryIdentifier* aTextureFactoryIdentifier,
bool* aSuccess) MOZ_OVERRIDE;
virtual bool DeallocPLayerTransactionParent(PLayerTransactionParent* aLayers) MOZ_OVERRIDE;
void CompositeToTarget(gfx::DrawTarget* aTarget);
void SetEGLSurfaceSize(int width, int height);
virtual void ScheduleTask(CancelableTask*, int);
void CancelCurrentCompositeTask();
virtual bool DeallocPLayerTransactionParent(PLayerTransactionParent* aLayers) MOZ_OVERRIDE;

private:
void Composite();
void ForceComposeToTarget(gfx::DrawTarget* aTarget);

Expand All @@ -280,7 +266,6 @@ class CompositorParent MOZ_FINAL : public PCompositorParent,
void ResumeComposition();
void ResumeCompositionAndResize(int width, int height);
void ForceComposition();
void CancelCurrentCompositeTask();

inline static PlatformThreadId CompositorThreadID();

Expand Down Expand Up @@ -360,7 +345,6 @@ class CompositorParent MOZ_FINAL : public PCompositorParent,
nsRefPtr<APZCTreeManager> mApzcTreeManager;

bool mWantDidCompositeEvent;
ICompositorListener* mListener;

DISALLOW_EVIL_CONSTRUCTORS(CompositorParent);
};
Expand Down

0 comments on commit 80790a7

Please sign in to comment.