Skip to content

Commit

Permalink
Add API for setting APZC's DPI
Browse files Browse the repository at this point in the history
While it is possible to set DPI in EmbedlitePuppetWidget class using
the gfxPlatform::GetDPI() call this aproach doesn't seem to be plausible,
because theoretically the device may have more than one screen with different
DPI. Thus gfxPlatform::GetDPI() is not used neither in B2G nor in Metro.
Instead these two embeddings set DPI at the moment of view creation.
And their PuppetWidget works as a proxy for the real window which lives
in the UI thread. Particularly PuppetWidget forwards GetDPI() requests
from TabChild to TabParent synchronously. And TabParent maintains its
own copy of DPI value set during window creation.

So, this commit also overrides GetDPI() for EmbedlitePuppetWidget.
First call to this methods gets forwarded synchronously to the UI thread
with the help of EmbedLiteViewBaseChild. The result is cached. After
that only cached value is returned.

Conflicts:
	embedding/embedlite/EmbedLiteView.cpp
	embedding/embedlite/EmbedLiteView.h
	embedding/embedlite/embedshared/EmbedLitePuppetWidget.cpp
	embedding/embedlite/embedshared/EmbedLitePuppetWidget.h
	embedding/embedlite/embedshared/EmbedLiteViewBaseParent.cpp
	embedding/embedlite/embedshared/EmbedLiteViewBaseParent.h
	embedding/embedlite/embedshared/EmbedLiteViewIface.idl
  • Loading branch information
rojkov committed Oct 14, 2015
1 parent b0d1a5a commit e3a03fd
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 0 deletions.
7 changes: 7 additions & 0 deletions embedding/embedlite/EmbedLiteView.cpp
Expand Up @@ -211,6 +211,13 @@ EmbedLiteView::SetMargins(int top, int right, int bottom, int left)
unused << mViewParent->SendSetMargins(top, right, bottom, left);
}

void
EmbedLiteView::SetDPI(const float& dpi)
{
NS_ENSURE_TRUE(mViewImpl, );
mViewImpl->SetDPI(dpi);
}

void
EmbedLiteView::ReceiveInputEvent(const InputData& aEvent)
{
Expand Down
3 changes: 3 additions & 0 deletions embedding/embedlite/EmbedLiteView.h
Expand Up @@ -99,6 +99,9 @@ class EmbedLiteView

virtual void SetMargins(int top, int right, int bottom, int left);

// Set DPI for the view (views placed on different screens may get different DPI).
virtual void SetDPI(const float& dpi);

// Scripting Interface, allow to extend embedding API by creating
// child js scripts and messaging interface.
// and do communication between UI and Content child via json messages.
Expand Down
5 changes: 5 additions & 0 deletions embedding/embedlite/PEmbedLiteView.ipdl
Expand Up @@ -101,6 +101,11 @@ parent:
SetBackgroundColor(nscolor color);
ContentReceivedInputBlock(ScrollableLayerGuid aGuid, uint64_t aInputBlockId, bool aPreventDefault);

/*
* Gets the DPI of the screen corresponding to this view.
*/
sync GetDPI() returns (float value);

sync SyncMessage(nsString aMessage, nsString aJSON)
returns (nsString[] retval);

Expand Down
1 change: 1 addition & 0 deletions embedding/embedlite/embedding.js
Expand Up @@ -75,6 +75,7 @@ pref("apz.fling_curve_function_y2", "1.0");
pref("apz.fling_curve_threshold_inches_per_ms", "0.03");
pref("apz.fling_friction", "0.003");
pref("apz.max_velocity_inches_per_ms", "0.07");
pref("apz.touch_start_tolerance", "0.027777f");

// Tweak default displayport values to reduce the risk of running out of
// memory when zooming in
Expand Down
16 changes: 16 additions & 0 deletions embedding/embedlite/embedshared/EmbedLitePuppetWidget.cpp
Expand Up @@ -91,6 +91,7 @@ EmbedLitePuppetWidget::EmbedLitePuppetWidget(EmbedLiteWindowBaseChild* window,
, mParent(nullptr)
, mRotation(ROTATION_0)
, mMargins(0, 0, 0, 0)
, mDPI(-1.0)
{
MOZ_COUNT_CTOR(EmbedLitePuppetWidget);
LOGT("this:%p", this);
Expand Down Expand Up @@ -643,6 +644,21 @@ EmbedLitePuppetWidget::GetLayerManager(PLayerTransactionChild* aShadowManager,
return mLayerManager;
}

float
EmbedLitePuppetWidget::GetDPI()
{
if (mDPI < 0) {
if (mView) {
mView->GetDPI(&mDPI);
} else {
mDPI = nsBaseWidget::GetDPI();
}
}

return mDPI;
}


CompositorParent*
EmbedLitePuppetWidget::NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight)
{
Expand Down
3 changes: 3 additions & 0 deletions embedding/embedlite/embedshared/EmbedLitePuppetWidget.h
Expand Up @@ -152,6 +152,8 @@ class EmbedLitePuppetWidget : public nsBaseWidget
virtual void CreateCompositor() override;
virtual void CreateCompositor(int aWidth, int aHeight) override;

virtual float GetDPI() override;

/**
* Called before the LayerManager draws the layer tree.
*
Expand Down Expand Up @@ -216,6 +218,7 @@ class EmbedLitePuppetWidget : public nsBaseWidget
nsIntRect mNaturalBounds;
nsIntMargin mMargins;
ObserverArray mObservers;
float mDPI;
};

} // namespace widget
Expand Down
6 changes: 6 additions & 0 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseChild.cpp
Expand Up @@ -349,6 +349,12 @@ EmbedLiteViewBaseChild::ZoomToRect(const uint32_t& aPresShellId,
return SendZoomToRect(aPresShellId, aViewId, aRect);
}

bool
EmbedLiteViewBaseChild::GetDPI(float* aDPI)
{
return SendGetDPI(aDPI);
}

bool
EmbedLiteViewBaseChild::UpdateZoomConstraints(const uint32_t& aPresShellId,
const ViewID& aViewId,
Expand Down
1 change: 1 addition & 0 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseChild.h
Expand Up @@ -66,6 +66,7 @@ class EmbedLiteViewBaseChild : public PEmbedLiteViewChild,

virtual nsIWebNavigation* WebNavigation() override;
virtual nsIWidget* WebWidget() override;
virtual bool GetDPI(float* aDPI) override;

/*---------TabChildIface---------------*/

Expand Down
26 changes: 26 additions & 0 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseParent.cpp
Expand Up @@ -25,6 +25,7 @@ EmbedLiteViewBaseParent::EmbedLiteViewBaseParent(const uint32_t& windowId, const
, mViewAPIDestroyed(false)
, mWindow(*EmbedLiteWindowBaseParent::From(windowId))
, mCompositor(nullptr)
, mDPI(-1.0)
, mUILoop(MessageLoop::current())
, mLastIMEState(0)
, mUploadTexture(0)
Expand Down Expand Up @@ -73,6 +74,9 @@ EmbedLiteViewBaseParent::UpdateScrollController()
if (mCompositor) {
mRootLayerTreeId = mCompositor->RootLayerTreeId();
mController->SetManagerByRootLayerTreeId(mRootLayerTreeId);
if (mDPI > 0) {
mController->GetManager()->SetDPI(mDPI);
}
CompositorParent::SetControllerForLayerTree(mRootLayerTreeId, mController);
}
}
Expand Down Expand Up @@ -344,6 +348,28 @@ EmbedLiteViewBaseParent::RecvRpcMessage(const nsString& aMessage,
return RecvSyncMessage(aMessage, aJSON, aJSONRetVal);
}


NS_IMETHODIMP
EmbedLiteViewBaseParent::SetDPI(float dpi)
{
mDPI = dpi;

if (mController->GetManager()) {
mController->GetManager()->SetDPI(mDPI);
}

return NS_OK;
}

bool
EmbedLiteViewBaseParent::RecvGetDPI(float* aValue)
{
NS_ENSURE_TRUE((mDPI > 0), false);

*aValue = mDPI;
return true;
}

void
EmbedLiteViewBaseParent::CompositorCreated()
{
Expand Down
4 changes: 4 additions & 0 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseParent.h
Expand Up @@ -118,6 +118,8 @@ class EmbedLiteViewBaseParent : public PEmbedLiteViewParent,
// EmbedLiteWindowParentObserver:
void CompositorCreated() override;

virtual bool RecvGetDPI(float* aValue) override;

private:
friend class EmbedContentController;
friend class EmbedLiteCompositorParent;
Expand All @@ -133,6 +135,8 @@ class EmbedLiteViewBaseParent : public PEmbedLiteViewParent,
EmbedLiteWindowBaseParent& mWindow;
RefPtr<EmbedLiteCompositorParent> mCompositor;

float mDPI;

MessageLoop* mUILoop;
int mLastIMEState;

Expand Down
1 change: 1 addition & 0 deletions embedding/embedlite/embedshared/EmbedLiteViewChildIface.h
Expand Up @@ -52,6 +52,7 @@ class EmbedLiteViewChildIface
virtual bool DoCallRpcMessage(const char16_t* aMessageName,
const char16_t* aMessage,
InfallibleTArray<nsString>* aJSONRetVal) = 0;
virtual bool GetDPI(float* aDPI) = 0;

/**
* Relay given frame metrics to listeners subscribed via EmbedLiteAppService
Expand Down
1 change: 1 addition & 0 deletions embedding/embedlite/embedshared/EmbedLiteViewIface.idl
Expand Up @@ -31,6 +31,7 @@ class nsString;
[scriptable, uuid(6d7750f8-e028-4445-a0cb-d9ce28fb03dd)]
interface EmbedLiteViewIface
{
void SetDPI(in float dpi);
void ReceiveInputEvent([const] in InputData aEvent);
void TextEvent(in string aComposite, in string aPreEdit);
void SendKeyPress(in int32_t aDomKeyCode, in int32_t aModifiers, in int32_t aCharCode);
Expand Down

0 comments on commit e3a03fd

Please sign in to comment.