Skip to content

Commit

Permalink
Bug 1096093 - Add infrastructure for LookAndFeel metric caching, and …
Browse files Browse the repository at this point in the history
…allowing the parent process to send down cache to content process. r=jimm.
  • Loading branch information
mikeconley committed Apr 22, 2015
1 parent 446daf9 commit 35e4690
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#ifdef ACCESSIBILITY
#include "mozilla/a11y/DocAccessibleChild.h"
#endif
#include "mozilla/LookAndFeel.h"
#include "mozilla/Preferences.h"
#include "mozilla/ProcessHangMonitorIPC.h"
#include "mozilla/docshell/OfflineCacheUpdateChild.h"
Expand Down Expand Up @@ -53,6 +54,7 @@
#include "mozilla/net/NeckoChild.h"
#include "mozilla/plugins/PluginInstanceParent.h"
#include "mozilla/plugins/PluginModuleParent.h"
#include "mozilla/widget/WidgetMessageUtils.h"

#if defined(MOZ_CONTENT_SANDBOX)
#if defined(XP_WIN)
Expand Down
9 changes: 9 additions & 0 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include "mozilla/layers/CompositorParent.h"
#include "mozilla/layers/ImageBridgeParent.h"
#include "mozilla/layers/SharedBufferManagerParent.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/net/NeckoParent.h"
#include "mozilla/plugins/PluginBridge.h"
#include "mozilla/Preferences.h"
Expand Down Expand Up @@ -2887,6 +2888,7 @@ ContentParent::RecvAddNewProcess(const uint32_t& aPid,
InfallibleTArray<nsString> unusedDictionaries;
ClipboardCapabilities clipboardCaps;
DomainPolicyClone domainPolicy;

RecvGetXPCOMProcessAttributes(&isOffline, &isLangRTL, &unusedDictionaries,
&clipboardCaps, &domainPolicy);
mozilla::unused << content->SendSetOffline(isOffline);
Expand Down Expand Up @@ -4037,6 +4039,13 @@ ContentParent::RecvGetSystemMemory(const uint64_t& aGetterId)
return true;
}

bool
ContentParent::RecvGetLookAndFeelCache(nsTArray<LookAndFeelInt>&& aLookAndFeelIntCache)
{
aLookAndFeelIntCache = LookAndFeel::GetIntCache();
return true;
}

bool
ContentParent::RecvIsSecureURI(const uint32_t& type,
const URIParams& uri,
Expand Down
5 changes: 3 additions & 2 deletions dom/ipc/ContentParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,7 @@ class ContentParent final : public PContentParent
bool* aIsLangRTL,
InfallibleTArray<nsString>* dictionaries,
ClipboardCapabilities* clipboardCaps,
DomainPolicyClone* domainPolicy)
override;
DomainPolicyClone* domainPolicy) override;

virtual bool DeallocPJavaScriptParent(mozilla::jsipc::PJavaScriptParent*) override;

Expand Down Expand Up @@ -756,6 +755,8 @@ class ContentParent final : public PContentParent
const bool& aHidden) override;
virtual bool RecvGetSystemMemory(const uint64_t& getterId) override;

virtual bool RecvGetLookAndFeelCache(nsTArray<LookAndFeelInt>&& aLookAndFeelIntCache) override;

virtual bool RecvDataStoreGetStores(
const nsString& aName,
const nsString& aOwner,
Expand Down
3 changes: 3 additions & 0 deletions dom/ipc/PContent.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ using mozilla::hal::ProcessPriority from "mozilla/HalTypes.h";
using gfxIntSize from "nsSize.h";
using mozilla::dom::TabId from "mozilla/dom/ipc/IdType.h";
using mozilla::dom::ContentParentId from "mozilla/dom/ipc/IdType.h";
using struct LookAndFeelInt from "mozilla/widget/WidgetMessageUtils.h";

union ChromeRegistryItem
{
Expand Down Expand Up @@ -690,6 +691,8 @@ parent:
sync IsSecureURI(uint32_t type, URIParams uri, uint32_t flags)
returns (bool isSecureURI);

sync GetLookAndFeelCache(LookAndFeelInt[] lookAndFeelIntCache);

PHal();

PIcc(uint32_t serviceId);
Expand Down
14 changes: 14 additions & 0 deletions widget/LookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@

#include "nsDebug.h"
#include "nsColor.h"
#include "nsTArray.h"

struct gfxFontStyle;

struct LookAndFeelInt
{
int32_t id;
int32_t value;
};

namespace mozilla {

class LookAndFeel
Expand Down Expand Up @@ -583,6 +590,13 @@ class LookAndFeel
* cached data would be released.
*/
static void Refresh();

/**
* If the implementation is caching values, these accessors allow the
* cache to be exported and imported.
*/
static nsTArray<LookAndFeelInt> GetIntCache();
static void SetIntCache(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache);
};

} // namespace mozilla
Expand Down
39 changes: 39 additions & 0 deletions widget/WidgetMessageUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_WidgetMessageUtils_h
#define mozilla_WidgetMessageUtils_h

#include "ipc/IPCMessageUtils.h"
#include "mozilla/LookAndFeel.h"

namespace IPC {

template<>
struct ParamTraits<LookAndFeelInt>
{
typedef LookAndFeelInt paramType;

static void Write(Message* aMsg, const paramType& aParam)
{
WriteParam(aMsg, aParam.id);
WriteParam(aMsg, aParam.value);
}

static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
int32_t id, value;
if (ReadParam(aMsg, aIter, &id) &&
ReadParam(aMsg, aIter, &value)) {
aResult->id = id;
aResult->value = value;
return true;
}
return false;
}
};

} // namespace IPC

#endif // WidgetMessageUtils_h
1 change: 1 addition & 0 deletions widget/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ EXPORTS.mozilla += [

EXPORTS.mozilla.widget += [
'PuppetBidiKeyboard.h',
'WidgetMessageUtils.h',
]

UNIFIED_SOURCES += [
Expand Down
30 changes: 30 additions & 0 deletions widget/nsXPLookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "nsFont.h"
#include "mozilla/Preferences.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/widget/WidgetMessageUtils.h"

#include "gfxPlatform.h"
#include "qcms.h"
Expand Down Expand Up @@ -453,6 +454,15 @@ nsXPLookAndFeel::Init()
if (NS_SUCCEEDED(Preferences::GetBool("ui.use_native_colors", &val))) {
sUseNativeColors = val;
}

if (XRE_GetProcessType() == GeckoProcessType_Content) {
mozilla::dom::ContentChild* cc =
mozilla::dom::ContentChild::GetSingleton();

nsTArray<LookAndFeelInt> lookAndFeelIntCache;
cc->SendGetLookAndFeelCache(lookAndFeelIntCache);
LookAndFeel::SetIntCache(lookAndFeelIntCache);
}
}

nsXPLookAndFeel::~nsXPLookAndFeel()
Expand Down Expand Up @@ -703,6 +713,12 @@ nsXPLookAndFeel::RefreshImpl()
sCachedColorBits[i] = 0;
}

nsTArray<LookAndFeelInt>
nsXPLookAndFeel::GetIntCacheImpl()
{
return nsTArray<LookAndFeelInt>();
}

namespace mozilla {

// static
Expand Down Expand Up @@ -763,4 +779,18 @@ LookAndFeel::Refresh()
nsLookAndFeel::GetInstance()->RefreshImpl();
}

// static
nsTArray<LookAndFeelInt>
LookAndFeel::GetIntCache()
{
return nsLookAndFeel::GetInstance()->GetIntCacheImpl();
}

// static
void
LookAndFeel::SetIntCache(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache)
{
return nsLookAndFeel::GetInstance()->SetIntCacheImpl(aLookAndFeelIntCache);
}

} // namespace mozilla
4 changes: 4 additions & 0 deletions widget/nsXPLookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define __nsXPLookAndFeel

#include "mozilla/LookAndFeel.h"
#include "nsTArray.h"

class nsLookAndFeel;

Expand Down Expand Up @@ -79,6 +80,9 @@ class nsXPLookAndFeel: public mozilla::LookAndFeel
return 600;
}

virtual nsTArray<LookAndFeelInt> GetIntCacheImpl();
virtual void SetIntCacheImpl(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) {}

protected:
nsXPLookAndFeel();

Expand Down

0 comments on commit 35e4690

Please sign in to comment.