Skip to content

Commit

Permalink
Adapt to nsIWidget changed
Browse files Browse the repository at this point in the history
Fixes also AsyncPanZoomEnabled state. Thus, fixing also APZCTreeManager
instantiation.
  • Loading branch information
rainemak committed Dec 19, 2016
1 parent 4a8baa3 commit 7f20b6d
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 64 deletions.
110 changes: 63 additions & 47 deletions embedding/embedlite/embedshared/EmbedLitePuppetWidget.cpp
Expand Up @@ -196,7 +196,7 @@ void EmbedLitePuppetWidget::SetActive(bool active)
NS_IMETHODIMP
EmbedLitePuppetWidget::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const nsIntRect& aRect,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData)
{
LOGT();
Expand All @@ -211,11 +211,11 @@ EmbedLitePuppetWidget::Create(nsIWidget* aParent,
mParent->mChildren.AppendElement(this);
}
mRotation = mParent ? mParent->mRotation : mRotation;
mBounds = mParent ? mParent->mBounds : aRect;
mBounds = mParent ? mParent->mBounds : aRect.ToUnknownRect();
mMargins = mParent ? mParent->mMargins : mMargins;
mNaturalBounds = mParent ? mParent->mNaturalBounds : aRect;
mNaturalBounds = mParent ? mParent->mNaturalBounds : aRect.ToUnknownRect();;

BaseCreate(aParent, aRect, aInitData);
BaseCreate(aParent, LayoutDeviceIntRect::FromUnknownRect(mBounds), aInitData);

if (IsTopLevel()) {
LOGT("Append this to toplevel windows:%p", this);
Expand All @@ -233,7 +233,7 @@ EmbedLitePuppetWidget::Create(nsIWidget* aParent,
}

already_AddRefed<nsIWidget>
EmbedLitePuppetWidget::CreateChild(const nsIntRect& aRect,
EmbedLitePuppetWidget::CreateChild(const LayoutDeviceIntRect &aRect,
nsWidgetInitData* aInitData,
bool aForceUseIWidgetParent)
{
Expand Down Expand Up @@ -308,7 +308,7 @@ EmbedLitePuppetWidget::Show(bool aState)

if (!wasVisible && mVisible) {
Resize(mNaturalBounds.width, mNaturalBounds.height, false);
Invalidate(mBounds);
Invalidate(LayoutDeviceIntRect::FromUnknownRect(mBounds));
}

// Only propagate visibility changes for widgets backing EmbedLiteView.
Expand Down Expand Up @@ -350,7 +350,7 @@ EmbedLitePuppetWidget::Resize(double aWidth, double aHeight, bool aRepaint)
}

if (aRepaint) {
Invalidate(mBounds);
Invalidate(LayoutDeviceIntRect::FromUnknownRect(mBounds));
}

nsIWidgetListener* listener =
Expand All @@ -375,8 +375,9 @@ EmbedLitePuppetWidget::SetFocus(bool aRaise)
}

NS_IMETHODIMP
EmbedLitePuppetWidget::Invalidate(const nsIntRect& aRect)
EmbedLitePuppetWidget::Invalidate(const LayoutDeviceIntRect& aRect)
{
Unused << aRect;
nsIWidgetListener* listener = GetWidgetListener();
if (listener) {
listener->WillPaintWindow(this);
Expand Down Expand Up @@ -442,20 +443,23 @@ EmbedLitePuppetWidget::DispatchEvent(WidgetGUIEvent* event, nsEventStatus& aStat

aStatus = listener->HandleEvent(event, mUseAttachedEvents);

switch (event->message) {
case NS_COMPOSITION_START:
switch (event->mMessage) {
case eCompositionStart:
MOZ_ASSERT(!mIMEComposing);
mIMEComposing = true;
break;
case NS_COMPOSITION_END:
case eCompositionEnd:
MOZ_ASSERT(mIMEComposing);
mIMEComposing = false;
mIMEComposingText.Truncate();
break;
case NS_COMPOSITION_CHANGE:
case eCompositionChange:
MOZ_ASSERT(mIMEComposing);
mIMEComposingText = static_cast<WidgetCompositionEvent*>(event)->mData;
break;
default:
// Do nothing
break;
}

return NS_OK;
Expand Down Expand Up @@ -498,15 +502,13 @@ NS_IMETHODIMP_(InputContext)
EmbedLitePuppetWidget::GetInputContext()
{
mInputContext.mIMEState.mOpen = IMEState::OPEN_STATE_NOT_SUPPORTED;
mInputContext.mNativeIMEContext = nullptr;
EmbedLiteViewChildIface* view = GetEmbedLiteChildView();
if (view) {
int32_t enabled, open;
intptr_t nativeIMEContext;
view->GetInputContext(&enabled, &open, &nativeIMEContext);
mInputContext.mIMEState.mEnabled = static_cast<IMEState::Enabled>(enabled);
mInputContext.mIMEState.mOpen = static_cast<IMEState::Open>(open);
mInputContext.mNativeIMEContext = reinterpret_cast<void*>(nativeIMEContext);
}
return mInputContext;
}
Expand All @@ -526,13 +528,13 @@ EmbedLitePuppetWidget::RemoveIMEComposition()

RefPtr<EmbedLitePuppetWidget> kungFuDeathGrip(this);

WidgetCompositionEvent textEvent(true, NS_COMPOSITION_CHANGE, this);
WidgetCompositionEvent textEvent(true, eCompositionChange, this);
textEvent.time = PR_Now() / 1000;
textEvent.mData = mIMEComposingText;
nsEventStatus status;
DispatchEvent(&textEvent, status);

WidgetCompositionEvent event(true, NS_COMPOSITION_END, this);
WidgetCompositionEvent event(true, eCompositionEnd, this);
event.time = PR_Now() / 1000;
DispatchEvent(&event, status);
}
Expand Down Expand Up @@ -575,9 +577,9 @@ EmbedLitePuppetWidget::CreateGLContextEarly(uint32_t aWindowId)
}
}

nsIntRect EmbedLitePuppetWidget::GetNaturalBounds()
LayoutDeviceIntRect EmbedLitePuppetWidget::GetNaturalBounds()
{
return mNaturalBounds;
return LayoutDeviceIntRect::FromUnknownRect(mNaturalBounds);
}

bool
Expand Down Expand Up @@ -633,8 +635,6 @@ EmbedLitePuppetWidget::GetLayerManager(PLayerTransactionChild* aShadowManager,
return mLayerManager;
}

mUseLayersAcceleration = ComputeShouldAccelerate(mUseLayersAcceleration);

// TODO : We should really split this into Android/Gonk like nsWindow and separate PuppetWidget
// Only Widget hosting window can create compositor.
// Bug: https://bugs.merproject.org/show_bug.cgi?id=1603
Expand All @@ -648,8 +648,6 @@ EmbedLitePuppetWidget::GetLayerManager(PLayerTransactionChild* aShadowManager,
}

mLayerManager = new ClientLayerManager(this);
mUseLayersAcceleration = false;

return mLayerManager;
}

Expand All @@ -667,6 +665,10 @@ EmbedLitePuppetWidget::GetDPI()
return mDPI;
}

bool EmbedLitePuppetWidget::AsyncPanZoomEnabled() const
{
return true;
}

CompositorParent*
EmbedLitePuppetWidget::NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight)
Expand All @@ -682,7 +684,7 @@ void EmbedLitePuppetWidget::CreateCompositor()
LOGT();
// Compositor should be created only for top level widgets, aka windows.
MOZ_ASSERT(mWindow);
gfxSize size = mWindow->GetSize();
LayoutDeviceIntRect size = mWindow->GetSize();
CreateCompositor(size.width, size.height);
}

Expand Down Expand Up @@ -712,17 +714,23 @@ void EmbedLitePuppetWidget::CreateCompositor(int aWidth, int aHeight)
MOZ_ASSERT(!mCompositorParent,
"Should have properly cleaned up the previous CompositorParent beforehand");

CreateCompositorVsyncDispatcher();
mCompositorParent = NewCompositorParent(aWidth, aHeight);
MessageChannel* parentChannel = mCompositorParent->GetIPCChannel();
// MessageChannel* parentChannel = mCompositorParent->GetIPCChannel();
RefPtr<ClientLayerManager> lm = new ClientLayerManager(this);
MessageLoop* childMessageLoop = CompositorParent::CompositorLoop();
// MessageLoop* childMessageLoop = CompositorParent::CompositorLoop();
mCompositorChild = new CompositorChild(lm);
mCompositorChild->Open(parentChannel, childMessageLoop, ipc::ChildSide);
// mCompositorChild->Open(parentChannel, childMessageLoop, ipc::ChildSide);
mCompositorChild->OpenSameProcess(mCompositorParent);

// Make sure the parent knows it is same process.
mCompositorParent->SetOtherProcessId(base::GetCurrentProcId());

TextureFactoryIdentifier textureFactoryIdentifier;
PLayerTransactionChild* shadowManager = nullptr;

nsTArray<LayersBackend> backendHints;
GetPreferredCompositorBackends(backendHints);
gfxPlatform::GetPlatform()->GetCompositorBackends(ComputeShouldAccelerate(), backendHints);

CheckForBasicBackends(backendHints);

Expand All @@ -732,52 +740,59 @@ void EmbedLitePuppetWidget::CreateCompositor(int aWidth, int aHeight)
backendHints, 0, &textureFactoryIdentifier, &success);
}

if (success) {
ShadowLayerForwarder* lf = lm->AsShadowForwarder();
if (!lf) {
lm = nullptr;
mCompositorChild = nullptr;
return;
}
lf->SetShadowManager(shadowManager);
lf->IdentifyTextureHost(textureFactoryIdentifier);
ImageBridgeChild::IdentifyCompositorTextureHost(textureFactoryIdentifier);
WindowUsesOMTC();

mLayerManager = lm.forget();
ShadowLayerForwarder* lf = lm->AsShadowForwarder();
if (!success || !lf) {
NS_WARNING("Failed to create an OMT compositor.");
DestroyCompositor();
mLayerManager = nullptr;
mCompositorChild = nullptr;
mCompositorParent = nullptr;
mCompositorVsyncDispatcher = nullptr;
return;
}

NS_WARNING("Failed to create an OMT compositor.");
DestroyCompositor();
// Compositor child had the only reference to LayerManager and will have
// deallocated it when being freed.
lf->SetShadowManager(shadowManager);
lf->IdentifyTextureHost(textureFactoryIdentifier);
ImageBridgeChild::IdentifyCompositorTextureHost(textureFactoryIdentifier);
WindowUsesOMTC();

mLayerManager = lm.forget();

if (mWindowType == eWindowType_toplevel) {
// Only track compositors for top-level windows, since other window types
// may use the basic compositor.
gfxPlatform::GetPlatform()->NotifyCompositorCreated(mLayerManager->GetCompositorBackendType());
}
}

void
EmbedLitePuppetWidget::DrawWindowUnderlay(LayerManagerComposite *aManager, nsIntRect aRect)
EmbedLitePuppetWidget::DrawWindowUnderlay(LayerManagerComposite *aManager, LayoutDeviceIntRect aRect)
{
MOZ_ASSERT(mWindow);
Unused << aManager;
Unused << aRect;
EmbedLiteWindow* window = EmbedLiteApp::GetInstance()->GetWindowByID(mWindow->GetUniqueID());
if (window) {
window->GetListener()->DrawUnderlay();
}
}

void
EmbedLitePuppetWidget::DrawWindowOverlay(LayerManagerComposite *aManager, nsIntRect aRect)
EmbedLitePuppetWidget::DrawWindowOverlay(LayerManagerComposite *aManager, LayoutDeviceIntRect aRect)
{
MOZ_ASSERT(mWindow);
Unused << aManager;
EmbedLiteWindow* window = EmbedLiteApp::GetInstance()->GetWindowByID(mWindow->GetUniqueID());
if (window) {
window->GetListener()->DrawOverlay(aRect);
window->GetListener()->DrawOverlay(aRect.ToUnknownRect());
}
}

bool
EmbedLitePuppetWidget::PreRender(LayerManagerComposite *aManager)
{
MOZ_ASSERT(mWindow);
Unused << aManager;
if (!IsVisible() || !mActive) {
return false;
}
Expand All @@ -793,6 +808,7 @@ void
EmbedLitePuppetWidget::PostRender(LayerManagerComposite *aManager)
{
MOZ_ASSERT(mWindow);
Unused << aManager;
EmbedLiteWindow* window = EmbedLiteApp::GetInstance()->GetWindowByID(mWindow->GetUniqueID());
if (window) {
window->GetListener()->CompositingFinished();
Expand Down
14 changes: 8 additions & 6 deletions embedding/embedlite/embedshared/EmbedLitePuppetWidget.h
Expand Up @@ -55,11 +55,11 @@ class EmbedLitePuppetWidget : public nsBaseWidget

NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const nsIntRect& aRect,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override;

virtual already_AddRefed<nsIWidget>
CreateChild(const nsIntRect& aRect,
CreateChild(const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr,
bool aForceUseIWidgetParent = false) override;

Expand Down Expand Up @@ -111,7 +111,7 @@ class EmbedLitePuppetWidget : public nsBaseWidget
LOGNI();
return NS_OK;
}
NS_IMETHOD Invalidate(const nsIntRect& aRect) override;
NS_IMETHOD Invalidate(const LayoutDeviceIntRect& aRect) override;
virtual void* GetNativeData(uint32_t aDataType) override;
// PuppetWidgets don't have any concept of titles..
NS_IMETHOD SetTitle(const nsAString& aTitle) override {
Expand All @@ -138,7 +138,7 @@ class EmbedLitePuppetWidget : public nsBaseWidget
return NS_ERROR_UNEXPECTED;
}

virtual nsIntRect GetNaturalBounds() override;
virtual LayoutDeviceIntRect GetNaturalBounds() override;
virtual bool NeedsPaint() override;

virtual LayerManager*
Expand All @@ -154,21 +154,23 @@ class EmbedLitePuppetWidget : public nsBaseWidget

virtual float GetDPI() override;

virtual bool AsyncPanZoomEnabled() const override;

/**
* Called before the LayerManager draws the layer tree.
*
* Always called from the compositing thread. Puppet Widget passes the call
* forward to the EmbedLiteCompositorParent.
*/
virtual void DrawWindowUnderlay(LayerManagerComposite* aManager, nsIntRect aRect) override;
virtual void DrawWindowUnderlay(LayerManagerComposite* aManager, LayoutDeviceIntRect aRect) override;

/**
* Called after the LayerManager draws the layer tree
*
* Always called from the compositing thread. Puppet Widget passes the call
* forward to the EmbedLiteCompositorParent.
*/
virtual void DrawWindowOverlay(LayerManagerComposite* aManager, nsIntRect aRect) override;
virtual void DrawWindowOverlay(LayerManagerComposite* aManager, LayoutDeviceIntRect aRect) override;

virtual bool PreRender(LayerManagerComposite* aManager) override;
virtual void PostRender(LayerManagerComposite* aManager) override;
Expand Down
11 changes: 6 additions & 5 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseChild.cpp
Expand Up @@ -177,15 +177,15 @@ EmbedLiteViewBaseChild::InitGeckoWindow(const uint32_t& parentId, const bool& is
widgetInit.clipChildren = true;
widgetInit.clipSiblings = true;
widgetInit.mWindowType = eWindowType_child;
nsIntRect naturalBounds = mWindow->GetWidget()->GetNaturalBounds();
LayoutDeviceIntRect naturalBounds = mWindow->GetWidget()->GetNaturalBounds();
rv = mWidget->Create(mWindow->GetWidget(), 0, naturalBounds, &widgetInit);
if (NS_FAILED(rv)) {
NS_ERROR("Failed to create widget for EmbedLiteView");
mWidget = nullptr;
return;
}

nsIntRect bounds;
LayoutDeviceIntRect bounds;
mWindow->GetWidget()->GetBounds(bounds);
rv = baseWindow->InitWindow(0, mWidget, 0, 0, bounds.width, bounds.height);
if (NS_FAILED(rv)) {
Expand Down Expand Up @@ -598,10 +598,11 @@ EmbedLiteViewBaseChild::RecvSetMargins(const int& aTop, const int& aRight,
widget->UpdateSize();

// Report update for the tab child helper. This triggers update for the viewport.
nsIntRect bounds;
LayoutDeviceIntRect bounds;
mWindow->GetWidget()->GetBounds(bounds);
bounds.Deflate(mMargins);
gfxSize size(bounds.width, bounds.height);
nsIntRect b = bounds.ToUnknownRect();
b.Deflate(mMargins);
gfxSize size(b.width, b.height);
mHelper->ReportSizeUpdate(size);
}

Expand Down

0 comments on commit 7f20b6d

Please sign in to comment.