Bug 847890 - paint flashing for content only. r=roc

This commit is contained in:
Paul Rouget 2013-03-12 11:01:00 -07:00
Родитель f567819f9d
Коммит b1db0cf9dc
7 изменённых файлов: 89 добавлений и 17 удалений

Просмотреть файл

@ -3210,6 +3210,35 @@ nsDOMWindowUtils::IsNodeDisabledForEvents(nsIDOMNode* aNode, bool* aRetVal)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsDOMWindowUtils::SetPaintFlashing(bool aPaintFlashing)
{
nsPresContext* presContext = GetPresContext();
if (presContext) {
presContext->RefreshDriver()->SetPaintFlashing(aPaintFlashing);
// Clear paint flashing colors
nsIPresShell* presShell = GetPresShell();
if (!aPaintFlashing && presShell) {
nsIFrame* rootFrame = presShell->GetRootFrame();
if (rootFrame) {
rootFrame->InvalidateFrameSubtree();
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::GetPaintFlashing(bool* aRetVal)
{
*aRetVal = false;
nsPresContext* presContext = GetPresContext();
if (presContext) {
*aRetVal = presContext->RefreshDriver()->GetPaintFlashing();
}
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
nsDOMWindowUtils::DispatchEventToChromeOnly(nsIDOMEventTarget* aTarget, nsDOMWindowUtils::DispatchEventToChromeOnly(nsIDOMEventTarget* aTarget,
nsIDOMEvent* aEvent, nsIDOMEvent* aEvent,

Просмотреть файл

@ -1349,4 +1349,9 @@ interface nsIDOMWindowUtils : nsISupports {
* attribute or -moz-user-input: none/disabled. * attribute or -moz-user-input: none/disabled.
*/ */
boolean isNodeDisabledForEvents(in nsIDOMNode aNode); boolean isNodeDisabledForEvents(in nsIDOMNode aNode);
/**
* Setting paintFlashing to true will flash newly painted area.
*/
attribute boolean paintFlashing;
}; };

Просмотреть файл

@ -759,22 +759,11 @@ FrameLayerBuilder::Init(nsDisplayListBuilder* aBuilder, LayerManager* aManager)
void void
FrameLayerBuilder::FlashPaint(gfxContext *aContext) FrameLayerBuilder::FlashPaint(gfxContext *aContext)
{ {
static bool sPaintFlashingEnabled; float r = float(rand()) / RAND_MAX;
static bool sPaintFlashingPrefCached = false; float g = float(rand()) / RAND_MAX;
float b = float(rand()) / RAND_MAX;
if (!sPaintFlashingPrefCached) { aContext->SetColor(gfxRGBA(r, g, b, 0.4));
sPaintFlashingPrefCached = true; aContext->Paint();
mozilla::Preferences::AddBoolVarCache(&sPaintFlashingEnabled,
"nglayout.debug.paint_flashing");
}
if (sPaintFlashingEnabled) {
float r = float(rand()) / RAND_MAX;
float g = float(rand()) / RAND_MAX;
float b = float(rand()) / RAND_MAX;
aContext->SetColor(gfxRGBA(r, g, b, 0.2));
aContext->Paint();
}
} }
FrameLayerBuilder::DisplayItemData* FrameLayerBuilder::DisplayItemData*
@ -3361,7 +3350,10 @@ FrameLayerBuilder::DrawThebesLayer(ThebesLayer* aLayer,
aContext->Restore(); aContext->Restore();
} }
FlashPaint(aContext); if (presContext->RefreshDriver()->GetPaintFlashing()) {
FlashPaint(aContext);
}
if (!aRegionToInvalidate.IsEmpty()) { if (!aRegionToInvalidate.IsEmpty()) {
aLayer->AddInvalidRect(aRegionToInvalidate.GetBounds()); aLayer->AddInvalidRect(aRegionToInvalidate.GetBounds());
} }

Просмотреть файл

@ -528,6 +528,8 @@ nsRefreshDriver::nsRefreshDriver(nsPresContext* aPresContext)
mMostRecentRefreshEpochTime = JS_Now(); mMostRecentRefreshEpochTime = JS_Now();
mMostRecentRefresh = TimeStamp::Now(); mMostRecentRefresh = TimeStamp::Now();
mPaintFlashing = Preferences::GetBool("nglayout.debug.paint_flashing");
mRequests.Init(); mRequests.Init();
} }

Просмотреть файл

@ -229,6 +229,17 @@ public:
*/ */
static int32_t DefaultInterval(); static int32_t DefaultInterval();
/**
* Enable/disable paint flashing.
*/
void SetPaintFlashing(bool aPaintFlashing) {
mPaintFlashing = aPaintFlashing;
}
bool GetPaintFlashing() {
return mPaintFlashing;
}
private: private:
typedef nsTObserverArray<nsARefreshObserver*> ObserverArray; typedef nsTObserverArray<nsARefreshObserver*> ObserverArray;
typedef nsTHashtable<nsISupportsHashKey> RequestTable; typedef nsTHashtable<nsISupportsHashKey> RequestTable;
@ -265,6 +276,7 @@ private:
bool mTestControllingRefreshes; bool mTestControllingRefreshes;
bool mViewManagerFlushIsPending; bool mViewManagerFlushIsPending;
bool mRequestedHighPrecision; bool mRequestedHighPrecision;
bool mPaintFlashing;
int64_t mMostRecentRefreshEpochTime; int64_t mMostRecentRefreshEpochTime;
mozilla::TimeStamp mMostRecentRefresh; mozilla::TimeStamp mMostRecentRefresh;

Просмотреть файл

@ -51,6 +51,7 @@ MOCHITEST_CHROME_FILES = \
test_passpointerevents.html \ test_passpointerevents.html \
passpointerevents_window.html \ passpointerevents_window.html \
test_bug812817.xul \ test_bug812817.xul \
test_bug847890_paintFlashing.html \
$(NULL) $(NULL)
ifdef MOZ_DEBUG ifdef MOZ_DEBUG

Просмотреть файл

@ -0,0 +1,31 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Tests for paint flashing</title>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/paint_listener.js"></script>
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
function startTest() {
waitForAllPaintsFlushed(function () {
var before = snapshotWindow(window, false);
SpecialPowers.getDOMWindowUtils(window).paintFlashing = true;
document.body.innerHTML = "bar";
waitForAllPaintsFlushed(function () {
document.body.innerHTML = "foo";
waitForAllPaintsFlushed(function () {
var after = snapshotWindow(window, false);
ok(compareSnapshots(before, after, false)[0], "windows are different");
SpecialPowers.getDOMWindowUtils(window).paintFlashing = false;
SimpleTest.finish();
});
});
});
}
</script>
</head>
<body onload="startTest()">foo</body>
</html>