зеркало из https://github.com/mozilla/gecko-dev.git
Bug 820831 - Turn on ContentScaleFactor calculation on Windows; r=jimm
MozReview-Commit-ID: 5rqTURsO839 --HG-- extra : rebase_source : 2e2f71d825221723990049958d43d6e2eb40411d
This commit is contained in:
Родитель
16413c625c
Коммит
f8661f72f8
|
@ -279,6 +279,8 @@ PluginPRLibrary::IsRemoteDrawingCoreAnimation(NPP instance, bool *aDrawing)
|
|||
*aDrawing = false;
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
nsresult
|
||||
PluginPRLibrary::ContentsScaleFactorChanged(NPP instance, double aContentsScaleFactor)
|
||||
{
|
||||
|
|
|
@ -114,6 +114,8 @@ public:
|
|||
virtual bool IsOOP() override { return false; }
|
||||
#if defined(XP_MACOSX)
|
||||
virtual nsresult IsRemoteDrawingCoreAnimation(NPP aInstance, bool* aDrawing) override;
|
||||
#endif
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
virtual nsresult ContentsScaleFactorChanged(NPP aInstance, double aContentsScaleFactor) override;
|
||||
#endif
|
||||
virtual nsresult SetBackgroundUnknown(NPP instance) override;
|
||||
|
|
|
@ -416,8 +416,10 @@ typedef enum {
|
|||
NPNVCSSZoomFactor = 23,
|
||||
|
||||
NPNVpluginDrawingModel = 1000 /* Get the current drawing model (NPDrawingModel) */
|
||||
#if defined(XP_MACOSX)
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
, NPNVcontentsScaleFactor = 1001
|
||||
#endif
|
||||
#if defined(XP_MACOSX)
|
||||
#ifndef NP_NO_QUICKDRAW
|
||||
, NPNVsupportsQuickDrawBool = 2000
|
||||
#endif
|
||||
|
|
|
@ -2013,7 +2013,9 @@ _getvalue(NPP npp, NPNVariable variable, void *result)
|
|||
*(NPBool*)result = true;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
case NPNVcontentsScaleFactor: {
|
||||
nsNPAPIPluginInstance *inst =
|
||||
(nsNPAPIPluginInstance *) (npp ? npp->ndata : nullptr);
|
||||
|
|
|
@ -1005,7 +1005,7 @@ nsresult nsNPAPIPluginInstance::IsRemoteDrawingCoreAnimation(bool* aDrawing)
|
|||
nsresult
|
||||
nsNPAPIPluginInstance::ContentsScaleFactorChanged(double aContentsScaleFactor)
|
||||
{
|
||||
#ifdef XP_MACOSX
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
if (!mPlugin)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
|
|
@ -1353,14 +1353,6 @@ bool nsPluginInstanceOwner::IsRemoteDrawingCoreAnimation()
|
|||
return coreAnimation;
|
||||
}
|
||||
|
||||
nsresult nsPluginInstanceOwner::ContentsScaleFactorChanged(double aContentsScaleFactor)
|
||||
{
|
||||
if (!mInstance) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
return mInstance->ContentsScaleFactorChanged(aContentsScaleFactor);
|
||||
}
|
||||
|
||||
NPEventModel nsPluginInstanceOwner::GetEventModel()
|
||||
{
|
||||
return mEventModel;
|
||||
|
@ -1451,6 +1443,16 @@ void nsPluginInstanceOwner::SetPluginPort()
|
|||
mPluginWindow->window = pluginPort;
|
||||
}
|
||||
#endif
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
nsresult nsPluginInstanceOwner::ContentsScaleFactorChanged(double aContentsScaleFactor)
|
||||
{
|
||||
if (!mInstance) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
return mInstance->ContentsScaleFactorChanged(aContentsScaleFactor);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// static
|
||||
uint32_t
|
||||
|
@ -3623,7 +3625,7 @@ nsPluginInstanceOwner::UpdateWindowVisibility(bool aVisible)
|
|||
void
|
||||
nsPluginInstanceOwner::ResolutionMayHaveChanged()
|
||||
{
|
||||
#ifdef XP_MACOSX
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
double scaleFactor = 1.0;
|
||||
GetContentsScaleFactor(&scaleFactor);
|
||||
if (scaleFactor != mLastScaleFactor) {
|
||||
|
@ -3709,7 +3711,7 @@ nsPluginInstanceOwner::GetContentsScaleFactor(double *result)
|
|||
// On Mac, device pixels need to be translated to (and from) "display pixels"
|
||||
// for plugins. On other platforms, plugin coordinates are always in device
|
||||
// pixels.
|
||||
#if defined(XP_MACOSX)
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
nsCOMPtr<nsIContent> content = do_QueryReferent(mContent);
|
||||
nsIPresShell* presShell = nsContentUtils::FindPresShellForDocument(content->OwnerDoc());
|
||||
if (presShell) {
|
||||
|
|
|
@ -141,7 +141,7 @@ public:
|
|||
void SendWindowFocusChanged(bool aIsActive);
|
||||
NPDrawingModel GetDrawingModel();
|
||||
bool IsRemoteDrawingCoreAnimation();
|
||||
nsresult ContentsScaleFactorChanged(double aContentsScaleFactor);
|
||||
|
||||
NPEventModel GetEventModel();
|
||||
static void CARefresh(nsITimer *aTimer, void *aClosure);
|
||||
void AddToCARefreshTimer();
|
||||
|
@ -158,6 +158,10 @@ public:
|
|||
#endif // XP_MACOSX
|
||||
|
||||
void ResolutionMayHaveChanged();
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
nsresult ContentsScaleFactorChanged(double aContentsScaleFactor);
|
||||
#endif
|
||||
|
||||
void UpdateDocumentActiveState(bool aIsActive);
|
||||
|
||||
void SetFrame(nsPluginFrame *aFrame);
|
||||
|
@ -337,10 +341,10 @@ private:
|
|||
bool mSentInitialTopLevelWindowEvent;
|
||||
bool mLastWindowIsActive;
|
||||
bool mLastContentFocused;
|
||||
double mLastScaleFactor;
|
||||
// True if, the next time the window is activated, we should blur ourselves.
|
||||
bool mShouldBlurOnActivate;
|
||||
#endif
|
||||
double mLastScaleFactor;
|
||||
double mLastCSSZoomFactor;
|
||||
// Initially, the event loop nesting level we were created on, it's updated
|
||||
// if we detect the appshell is on a lower level as long as we're not stopped.
|
||||
|
|
|
@ -25,6 +25,7 @@ struct NPRemoteEvent
|
|||
RECT rect;
|
||||
WINDOWPOS windowpos;
|
||||
} lParamData;
|
||||
double contentsScaleFactor;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ PluginInstanceChild::PluginInstanceChild(const NPPluginFuncs* aPluginIface,
|
|||
, mMode(aMode)
|
||||
, mNames(aNames)
|
||||
, mValues(aValues)
|
||||
#if defined(XP_DARWIN)
|
||||
#if defined(XP_DARWIN) || defined (XP_WIN)
|
||||
, mContentsScaleFactor(1.0)
|
||||
#endif
|
||||
, mPostingKeyEvents(0)
|
||||
|
@ -534,12 +534,14 @@ PluginInstanceChild::NPN_GetValue(NPNVariable aVar,
|
|||
return NPERR_NO_ERROR;
|
||||
}
|
||||
#endif /* NP_NO_QUICKDRAW */
|
||||
#endif /* XP_MACOSX */
|
||||
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
case NPNVcontentsScaleFactor: {
|
||||
*static_cast<double*>(aValue) = mContentsScaleFactor;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
#endif /* XP_MACOSX */
|
||||
#endif /* defined(XP_MACOSX) || defined(XP_WIN) */
|
||||
|
||||
case NPNVCSSZoomFactor: {
|
||||
*static_cast<double*>(aValue) = mCSSZoomFactor;
|
||||
|
@ -871,12 +873,6 @@ PluginInstanceChild::AnswerNPP_HandleEvent(const NPRemoteEvent& event,
|
|||
#ifdef XP_MACOSX
|
||||
// Mac OS X does not define an NPEvent structure. It defines more specific types.
|
||||
NPCocoaEvent evcopy = event.event;
|
||||
// event.contentsScaleFactor <= 0 is a signal we shouldn't use it,
|
||||
// for example when AnswerNPP_HandleEvent() is called from elsewhere
|
||||
// in the child process (not via rpc code from the parent process).
|
||||
if (event.contentsScaleFactor > 0) {
|
||||
mContentsScaleFactor = event.contentsScaleFactor;
|
||||
}
|
||||
|
||||
// Make sure we reset mCurrentEvent in case of an exception
|
||||
AutoRestore<const NPCocoaEvent*> savePreviousEvent(mCurrentEvent);
|
||||
|
@ -888,6 +884,15 @@ PluginInstanceChild::AnswerNPP_HandleEvent(const NPRemoteEvent& event,
|
|||
NPEvent evcopy = event.event;
|
||||
#endif
|
||||
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
// event.contentsScaleFactor <= 0 is a signal we shouldn't use it,
|
||||
// for example when AnswerNPP_HandleEvent() is called from elsewhere
|
||||
// in the child process (not via rpc code from the parent process).
|
||||
if (event.contentsScaleFactor > 0) {
|
||||
mContentsScaleFactor = event.contentsScaleFactor;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef OS_WIN
|
||||
// FIXME/bug 567645: temporarily drop the "dummy event" on the floor
|
||||
if (WM_NULL == evcopy.event)
|
||||
|
@ -1133,17 +1138,19 @@ PluginInstanceChild::RecvWindowPosChanged(const NPRemoteEvent& event)
|
|||
bool
|
||||
PluginInstanceChild::RecvContentsScaleFactorChanged(const double& aContentsScaleFactor)
|
||||
{
|
||||
#ifdef XP_MACOSX
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
mContentsScaleFactor = aContentsScaleFactor;
|
||||
#if defined(XP_MACOSX)
|
||||
if (mShContext) {
|
||||
// Release the shared context so that it is reallocated
|
||||
// with the new size.
|
||||
::CGContextRelease(mShContext);
|
||||
mShContext = nullptr;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
#else
|
||||
NS_RUNTIMEABORT("ContentsScaleFactorChanged is an OSX-only message");
|
||||
NS_RUNTIMEABORT("ContentsScaleFactorChanged is an Windows or OSX only message");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
@ -1338,6 +1345,7 @@ PluginInstanceChild::AnswerNPP_SetWindow(const NPRemoteWindow& aWindow)
|
|||
mWindow.width = aWindow.width;
|
||||
mWindow.height = aWindow.height;
|
||||
mWindow.type = aWindow.type;
|
||||
mContentsScaleFactor = aWindow.contentsScaleFactor;
|
||||
|
||||
if (mPluginIface->setwindow) {
|
||||
SetProp(mPluginWindowHWND, kPluginIgnoreSubclassProperty, (HANDLE)1);
|
||||
|
@ -3329,7 +3337,7 @@ PluginInstanceChild::DoAsyncSetWindow(const gfxSurfaceType& aSurfaceType,
|
|||
mWindow.height = aWindow.height;
|
||||
mWindow.clipRect = aWindow.clipRect;
|
||||
mWindow.type = aWindow.type;
|
||||
#ifdef XP_MACOSX
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
mContentsScaleFactor = aWindow.contentsScaleFactor;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -410,7 +410,7 @@ private:
|
|||
InfallibleTArray<nsCString> mValues;
|
||||
NPP_t mData;
|
||||
NPWindow mWindow;
|
||||
#if defined(XP_DARWIN)
|
||||
#if defined(XP_DARWIN) || defined(XP_WIN)
|
||||
double mContentsScaleFactor;
|
||||
#endif
|
||||
double mCSSZoomFactor;
|
||||
|
|
|
@ -992,7 +992,7 @@ PluginInstanceParent::AsyncSetWindow(NPWindow* aWindow)
|
|||
window.height = aWindow->height;
|
||||
window.clipRect = aWindow->clipRect;
|
||||
window.type = aWindow->type;
|
||||
#ifdef XP_MACOSX
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
double scaleFactor = 1.0;
|
||||
mNPNIface->getvalue(mNPP, NPNVcontentsScaleFactor, &scaleFactor);
|
||||
window.contentsScaleFactor = scaleFactor;
|
||||
|
@ -1106,7 +1106,8 @@ PluginInstanceParent::IsRemoteDrawingCoreAnimation(bool *aDrawing)
|
|||
NPDrawingModelInvalidatingCoreAnimation == (NPDrawingModel)mDrawingModel);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
nsresult
|
||||
PluginInstanceParent::ContentsScaleFactorChanged(double aContentsScaleFactor)
|
||||
{
|
||||
|
@ -1365,12 +1366,13 @@ PluginInstanceParent::NPP_SetWindow(const NPWindow* aWindow)
|
|||
window.type = aWindow->type;
|
||||
#endif
|
||||
|
||||
#if defined(XP_MACOSX)
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
double floatScaleFactor = 1.0;
|
||||
mNPNIface->getvalue(mNPP, NPNVcontentsScaleFactor, &floatScaleFactor);
|
||||
int scaleFactor = ceil(floatScaleFactor);
|
||||
window.contentsScaleFactor = floatScaleFactor;
|
||||
|
||||
#endif
|
||||
#if defined(XP_MACOSX)
|
||||
if (mShWidth != window.width * scaleFactor || mShHeight != window.height * scaleFactor) {
|
||||
if (mDrawingModel == NPDrawingModelCoreAnimation ||
|
||||
mDrawingModel == NPDrawingModelInvalidatingCoreAnimation) {
|
||||
|
@ -1565,7 +1567,7 @@ PluginInstanceParent::NPP_HandleEvent(void* event)
|
|||
#endif
|
||||
NPRemoteEvent npremoteevent;
|
||||
npremoteevent.event = *npevent;
|
||||
#if defined(XP_MACOSX)
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
double scaleFactor = 1.0;
|
||||
mNPNIface->getvalue(mNPP, NPNVcontentsScaleFactor, &scaleFactor);
|
||||
npremoteevent.contentsScaleFactor = scaleFactor;
|
||||
|
|
|
@ -324,6 +324,8 @@ public:
|
|||
nsresult GetImageSize(nsIntSize* aSize);
|
||||
#ifdef XP_MACOSX
|
||||
nsresult IsRemoteDrawingCoreAnimation(bool *aDrawing);
|
||||
#endif
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
nsresult ContentsScaleFactorChanged(double aContentsScaleFactor);
|
||||
#endif
|
||||
nsresult SetBackgroundUnknown();
|
||||
|
|
|
@ -85,6 +85,8 @@ public:
|
|||
virtual bool IsOOP() = 0;
|
||||
#if defined(XP_MACOSX)
|
||||
virtual nsresult IsRemoteDrawingCoreAnimation(NPP instance, bool *aDrawing) = 0;
|
||||
#endif
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
virtual nsresult ContentsScaleFactorChanged(NPP instance, double aContentsScaleFactor) = 0;
|
||||
#endif
|
||||
#if defined(XP_WIN)
|
||||
|
|
|
@ -93,7 +93,7 @@ struct NPRemoteWindow
|
|||
VisualID visualID;
|
||||
Colormap colormap;
|
||||
#endif /* XP_UNIX */
|
||||
#if defined(XP_MACOSX)
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
double contentsScaleFactor;
|
||||
#endif
|
||||
};
|
||||
|
@ -346,7 +346,7 @@ struct ParamTraits<mozilla::plugins::NPRemoteWindow>
|
|||
aMsg->WriteULong(aParam.visualID);
|
||||
aMsg->WriteULong(aParam.colormap);
|
||||
#endif
|
||||
#if defined(XP_MACOSX)
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
aMsg->WriteDouble(aParam.contentsScaleFactor);
|
||||
#endif
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ struct ParamTraits<mozilla::plugins::NPRemoteWindow>
|
|||
return false;
|
||||
#endif
|
||||
|
||||
#if defined(XP_MACOSX)
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
double contentsScaleFactor;
|
||||
if (!aMsg->ReadDouble(aIter, &contentsScaleFactor))
|
||||
return false;
|
||||
|
@ -392,7 +392,7 @@ struct ParamTraits<mozilla::plugins::NPRemoteWindow>
|
|||
aResult->visualID = visualID;
|
||||
aResult->colormap = colormap;
|
||||
#endif
|
||||
#if defined(XP_MACOSX)
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
aResult->contentsScaleFactor = contentsScaleFactor;
|
||||
#endif
|
||||
return true;
|
||||
|
|
|
@ -2855,7 +2855,8 @@ PluginModuleParent::IsRemoteDrawingCoreAnimation(NPP instance, bool *aDrawing)
|
|||
|
||||
return i->IsRemoteDrawingCoreAnimation(aDrawing);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
nsresult
|
||||
PluginModuleParent::ContentsScaleFactorChanged(NPP instance, double aContentsScaleFactor)
|
||||
{
|
||||
|
|
|
@ -305,6 +305,8 @@ public:
|
|||
|
||||
#if defined(XP_MACOSX)
|
||||
virtual nsresult IsRemoteDrawingCoreAnimation(NPP instance, bool *aDrawing) override;
|
||||
#endif
|
||||
#if defined(XP_MACOSX) || defined(XP_WIN)
|
||||
virtual nsresult ContentsScaleFactorChanged(NPP instance, double aContentsScaleFactor) override;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -570,6 +570,8 @@ nsPluginFrame::FixupWindow(const nsSize& aSize)
|
|||
nsIntPoint origin = GetWindowOriginInPixels(windowless);
|
||||
|
||||
// window must be in "display pixels"
|
||||
#if defined(XP_MACOSX)
|
||||
// window must be in "display pixels"
|
||||
double scaleFactor = 1.0;
|
||||
if (NS_FAILED(mInstanceOwner->GetContentsScaleFactor(&scaleFactor))) {
|
||||
scaleFactor = 1.0;
|
||||
|
@ -579,6 +581,12 @@ nsPluginFrame::FixupWindow(const nsSize& aSize)
|
|||
window->y = origin.y / intScaleFactor;
|
||||
window->width = presContext->AppUnitsToDevPixels(aSize.width) / intScaleFactor;
|
||||
window->height = presContext->AppUnitsToDevPixels(aSize.height) / intScaleFactor;
|
||||
#else
|
||||
window->x = origin.x;
|
||||
window->y = origin.y;
|
||||
window->width = presContext->AppUnitsToDevPixels(aSize.width);
|
||||
window->height = presContext->AppUnitsToDevPixels(aSize.height);
|
||||
#endif
|
||||
|
||||
#ifndef XP_MACOSX
|
||||
mInstanceOwner->UpdateWindowPositionAndClipRect(false);
|
||||
|
@ -639,17 +647,24 @@ nsPluginFrame::CallSetWindow(bool aCheckIsHidden)
|
|||
intBounds.x += intOffset.x;
|
||||
intBounds.y += intOffset.y;
|
||||
|
||||
#if defined(XP_MACOSX)
|
||||
// window must be in "display pixels"
|
||||
double scaleFactor = 1.0;
|
||||
if (NS_FAILED(instanceOwnerRef->GetContentsScaleFactor(&scaleFactor))) {
|
||||
scaleFactor = 1.0;
|
||||
}
|
||||
|
||||
size_t intScaleFactor = ceil(scaleFactor);
|
||||
window->x = intBounds.x / intScaleFactor;
|
||||
window->y = intBounds.y / intScaleFactor;
|
||||
window->width = intBounds.width / intScaleFactor;
|
||||
window->height = intBounds.height / intScaleFactor;
|
||||
|
||||
#else
|
||||
window->x = intBounds.x;
|
||||
window->y = intBounds.y;
|
||||
window->width = intBounds.width;
|
||||
window->height = intBounds.height;
|
||||
#endif
|
||||
// BE CAREFUL: By the time we get here the PluginFrame is sometimes destroyed
|
||||
// and poisoned. If we reference local fields (implicit this deref),
|
||||
// we will crash.
|
||||
|
@ -1442,12 +1457,19 @@ nsPluginFrame::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|||
if (window->width <= 0 || window->height <= 0)
|
||||
return nullptr;
|
||||
|
||||
#if defined(XP_MACOSX)
|
||||
// window is in "display pixels", but size needs to be in device pixels
|
||||
// window must be in "display pixels"
|
||||
double scaleFactor = 1.0;
|
||||
if (NS_FAILED(mInstanceOwner->GetContentsScaleFactor(&scaleFactor))) {
|
||||
scaleFactor = 1.0;
|
||||
}
|
||||
int intScaleFactor = ceil(scaleFactor);
|
||||
|
||||
size_t intScaleFactor = ceil(scaleFactor);
|
||||
#else
|
||||
size_t intScaleFactor = 1;
|
||||
#endif
|
||||
|
||||
IntSize size(window->width * intScaleFactor, window->height * intScaleFactor);
|
||||
|
||||
nsRect area = GetContentRectRelativeToSelf() + aItem->ToReferenceFrame();
|
||||
|
|
Загрузка…
Ссылка в новой задаче