[chromium] Allow us to disable overdraw metrics when tracing is off
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Mar 2012 21:34:10 +0000 (21:34 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Mar 2012 21:34:10 +0000 (21:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=81431

Patch by Dana Jansens <danakj@chromium.org> on 2012-03-20
Reviewed by Adrienne Walker.

Source/WebCore:

This change allows us to disable overdraw metrics conditionally in the
future with a one-line change in each LayerTreeHost class.

Unit test: CCQuadCullerTest.verifyWithoutMetrics

* platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
(WebCore::CCLayerTreeHost::paintLayerContents):
* platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
(WebCore::CCLayerTreeHostImpl::calculateRenderPasses):
* platform/graphics/chromium/cc/CCOcclusionTracker.cpp:
(WebCore::::CCOcclusionTrackerBase):
(WebCore):
* platform/graphics/chromium/cc/CCOcclusionTracker.h:
(CCOcclusionTrackerBase):
* platform/graphics/chromium/cc/CCOverdrawMetrics.cpp:
(WebCore::CCOverdrawMetrics::CCOverdrawMetrics):
(WebCore::CCOverdrawMetrics::didCull):
(WebCore::CCOverdrawMetrics::didDraw):
(WebCore::CCOverdrawMetrics::recordMetrics):
* platform/graphics/chromium/cc/CCOverdrawMetrics.h:
(WebCore::CCOverdrawMetrics::create):
(CCOverdrawMetrics):

Source/WebKit/chromium:

* tests/CCOcclusionTrackerTest.cpp:
(WebCore::TestCCOcclusionTrackerBase::TestCCOcclusionTrackerBase):
* tests/CCQuadCullerTest.cpp:
(WebCore::TestCCOcclusionTrackerImpl::TestCCOcclusionTrackerImpl):
(WebCore::TEST):
(WebCore):
* tests/TiledLayerChromiumTest.cpp:
(WTF::TestCCOcclusionTracker::TestCCOcclusionTracker):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@111441 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp
Source/WebCore/platform/graphics/chromium/cc/CCOcclusionTracker.cpp
Source/WebCore/platform/graphics/chromium/cc/CCOcclusionTracker.h
Source/WebCore/platform/graphics/chromium/cc/CCOverdrawMetrics.cpp
Source/WebCore/platform/graphics/chromium/cc/CCOverdrawMetrics.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/tests/CCOcclusionTrackerTest.cpp
Source/WebKit/chromium/tests/CCQuadCullerTest.cpp
Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp

index 74656c69640e219d674d48c1a7229df5a5c00c4d..b95d9d730c420315405e55b28ee3bfad25943be8 100644 (file)
@@ -1,3 +1,33 @@
+2012-03-20  Dana Jansens  <danakj@chromium.org>
+
+        [chromium] Allow us to disable overdraw metrics when tracing is off
+        https://bugs.webkit.org/show_bug.cgi?id=81431
+
+        Reviewed by Adrienne Walker.
+
+        This change allows us to disable overdraw metrics conditionally in the
+        future with a one-line change in each LayerTreeHost class.
+
+        Unit test: CCQuadCullerTest.verifyWithoutMetrics
+
+        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
+        (WebCore::CCLayerTreeHost::paintLayerContents):
+        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
+        (WebCore::CCLayerTreeHostImpl::calculateRenderPasses):
+        * platform/graphics/chromium/cc/CCOcclusionTracker.cpp:
+        (WebCore::::CCOcclusionTrackerBase):
+        (WebCore):
+        * platform/graphics/chromium/cc/CCOcclusionTracker.h:
+        (CCOcclusionTrackerBase):
+        * platform/graphics/chromium/cc/CCOverdrawMetrics.cpp:
+        (WebCore::CCOverdrawMetrics::CCOverdrawMetrics):
+        (WebCore::CCOverdrawMetrics::didCull):
+        (WebCore::CCOverdrawMetrics::didDraw):
+        (WebCore::CCOverdrawMetrics::recordMetrics):
+        * platform/graphics/chromium/cc/CCOverdrawMetrics.h:
+        (WebCore::CCOverdrawMetrics::create):
+        (CCOverdrawMetrics):
+
 2012-03-20  Robert Hogan  <robert@webkit.org>
 
         Use-after-free of continuation in RenderBlock::paintContinuationOutlines()
index a142be30992a9e78464379740241a5fea4c56258..ad400e979bece2fcf807ec9c7eabc444759c727d 100644 (file)
@@ -547,7 +547,8 @@ void CCLayerTreeHost::paintLayerContents(const LayerList& renderSurfaceLayerList
     // Use FrontToBack to allow for testing occlusion and performing culling during the tree walk.
     typedef CCLayerIterator<LayerChromium, Vector<RefPtr<LayerChromium> >, RenderSurfaceChromium, CCLayerIteratorActions::FrontToBack> CCLayerIteratorType;
 
-    CCOcclusionTracker occlusionTracker(IntRect(IntPoint(), viewportSize()));
+    bool recordMetricsForFrame = true; // FIXME: In the future, disable this when about:tracing is off.
+    CCOcclusionTracker occlusionTracker(IntRect(IntPoint(), viewportSize()), recordMetricsForFrame);
     occlusionTracker.setUsePaintTracking(true); // FIXME: Remove this after m19 branch.
 
     CCLayerIteratorType end = CCLayerIteratorType::end(&renderSurfaceLayerList);
index ad892f28f45fc7b9d42b0646d984b8fc4615966e..07812e21c1c9ad166b1885d9d89e884e57a84059 100644 (file)
@@ -280,7 +280,9 @@ void CCLayerTreeHostImpl::calculateRenderPasses(CCRenderPassList& passes, CCLaye
         scissorRect = enclosingIntRect(m_rootDamageRect);
     else
         scissorRect = IntRect(IntPoint(), viewportSize());
-    CCOcclusionTrackerImpl occlusionTracker(scissorRect);
+
+    bool recordMetricsForFrame = true; // FIXME: In the future, disable this when about:tracing is off.
+    CCOcclusionTrackerImpl occlusionTracker(scissorRect, recordMetricsForFrame);
 
     // Add quads to the Render passes in FrontToBack order to allow for testing occlusion and performing culling during the tree walk.
     typedef CCLayerIterator<CCLayerImpl, Vector<CCLayerImpl*>, CCRenderSurface, CCLayerIteratorActions::FrontToBack> CCLayerIteratorType;
index 4c617ad67e461f6bf6ef8c62305950b7ea5ccfd4..971494b9089d5cf902458ea9ae9e3a5367b8e5d6 100644 (file)
@@ -39,9 +39,9 @@ using namespace std;
 namespace WebCore {
 
 template<typename LayerType, typename RenderSurfaceType>
-CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::CCOcclusionTrackerBase(IntRect scissorRectInScreenSpace)
+CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::CCOcclusionTrackerBase(IntRect scissorRectInScreenSpace, bool recordMetricsForFrame)
     : m_scissorRectInScreenSpace(scissorRectInScreenSpace)
-    , m_overdrawMetrics(CCOverdrawMetrics::create())
+    , m_overdrawMetrics(CCOverdrawMetrics::create(recordMetricsForFrame))
     , m_usePaintTracking(true) // FIXME: Remove this when paint tracking is on for paint culling.
 {
 }
@@ -369,7 +369,7 @@ const Region& CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::currentOcclu
 
 
 // Declare the possible functions here for the linker.
-template CCOcclusionTrackerBase<LayerChromium, RenderSurfaceChromium>::CCOcclusionTrackerBase(IntRect scissorRectInScreenSpace);
+template CCOcclusionTrackerBase<LayerChromium, RenderSurfaceChromium>::CCOcclusionTrackerBase(IntRect scissorRectInScreenSpace, bool recordMetricsForFrame);
 template void CCOcclusionTrackerBase<LayerChromium, RenderSurfaceChromium>::enterTargetRenderSurface(const RenderSurfaceChromium* newTarget);
 template void CCOcclusionTrackerBase<LayerChromium, RenderSurfaceChromium>::finishedTargetRenderSurface(const LayerChromium* owningLayer, const RenderSurfaceChromium* finishedTarget);
 template void CCOcclusionTrackerBase<LayerChromium, RenderSurfaceChromium>::leaveToTargetRenderSurface(const RenderSurfaceChromium* newTarget);
@@ -380,7 +380,7 @@ template const Region& CCOcclusionTrackerBase<LayerChromium, RenderSurfaceChromi
 template const Region& CCOcclusionTrackerBase<LayerChromium, RenderSurfaceChromium>::currentOcclusionInTargetSurface() const;
 template IntRect CCOcclusionTrackerBase<LayerChromium, RenderSurfaceChromium>::layerScissorRectInTargetSurface(const LayerChromium*) const;
 
-template CCOcclusionTrackerBase<CCLayerImpl, CCRenderSurface>::CCOcclusionTrackerBase(IntRect scissorRectInScreenSpace);
+template CCOcclusionTrackerBase<CCLayerImpl, CCRenderSurface>::CCOcclusionTrackerBase(IntRect scissorRectInScreenSpace, bool recordMetricsForFrame);
 template void CCOcclusionTrackerBase<CCLayerImpl, CCRenderSurface>::enterTargetRenderSurface(const CCRenderSurface* newTarget);
 template void CCOcclusionTrackerBase<CCLayerImpl, CCRenderSurface>::finishedTargetRenderSurface(const CCLayerImpl* owningLayer, const CCRenderSurface* finishedTarget);
 template void CCOcclusionTrackerBase<CCLayerImpl, CCRenderSurface>::leaveToTargetRenderSurface(const CCRenderSurface* newTarget);
index 282deffdf2564be3f9013d2e92026e9b8d6e2afd..530e6f3df1d00202733433555d01ab3d9257854d 100644 (file)
@@ -46,7 +46,7 @@ template<typename LayerType, typename RenderSurfaceType>
 class CCOcclusionTrackerBase {
     WTF_MAKE_NONCOPYABLE(CCOcclusionTrackerBase);
 public:
-    CCOcclusionTrackerBase(IntRect scissorRectInScreenSpace);
+    CCOcclusionTrackerBase(IntRect scissorRectInScreenSpace, bool recordMetricsForFrame);
 
     // Called when visiting a layer representing itself. If the target was not already current, then this indicates we have entered a new surface subtree.
     void enterTargetRenderSurface(const RenderSurfaceType* newTarget);
index a77dc69f061b5083b88c8b58f2908c3c495064c4..885c3b034fdca1a4990bf9b1ad20490979b746ae 100644 (file)
@@ -37,8 +37,9 @@
 
 namespace WebCore {
 
-CCOverdrawMetrics::CCOverdrawMetrics()
-    : m_pixelsDrawnOpaque(0)
+CCOverdrawMetrics::CCOverdrawMetrics(bool recordMetricsForFrame)
+    : m_recordMetricsForFrame(recordMetricsForFrame)
+    , m_pixelsDrawnOpaque(0)
     , m_pixelsDrawnTranslucent(0)
     , m_pixelsCulled(0)
 {
@@ -60,6 +61,9 @@ static inline float quadArea(const FloatQuad& quad)
 
 void CCOverdrawMetrics::didCull(const TransformationMatrix& transformToTarget, const IntRect& beforeCullRect, const IntRect& afterCullRect)
 {
+    if (!m_recordMetricsForFrame)
+        return;
+
     float beforeCullArea = quadArea(transformToTarget.mapQuad(FloatQuad(beforeCullRect)));
     float afterCullArea = quadArea(transformToTarget.mapQuad(FloatQuad(afterCullRect)));
 
@@ -68,6 +72,9 @@ void CCOverdrawMetrics::didCull(const TransformationMatrix& transformToTarget, c
 
 void CCOverdrawMetrics::didDraw(const TransformationMatrix& transformToTarget, const IntRect& afterCullRect, const IntRect& opaqueRect)
 {
+    if (!m_recordMetricsForFrame)
+        return;
+
     float afterCullArea = quadArea(transformToTarget.mapQuad(FloatQuad(afterCullRect)));
     float afterCullOpaqueArea = quadArea(transformToTarget.mapQuad(FloatQuad(intersection(opaqueRect, afterCullRect))));
 
@@ -77,12 +84,14 @@ void CCOverdrawMetrics::didDraw(const TransformationMatrix& transformToTarget, c
 
 void CCOverdrawMetrics::recordMetrics(const CCLayerTreeHost* layerTreeHost) const
 {
-    recordMetricsInternal<CCLayerTreeHost>(UPLOADING, layerTreeHost);
+    if (m_recordMetricsForFrame)
+        recordMetricsInternal<CCLayerTreeHost>(UPLOADING, layerTreeHost);
 }
 
 void CCOverdrawMetrics::recordMetrics(const CCLayerTreeHostImpl* layerTreeHost) const
 {
-    recordMetricsInternal<CCLayerTreeHostImpl>(DRAWING, layerTreeHost);
+    if (m_recordMetricsForFrame)
+        recordMetricsInternal<CCLayerTreeHostImpl>(DRAWING, layerTreeHost);
 }
 
 template<typename LayerTreeHostType>
index 489ca569c5255389ccf302a4c38cd87f620cc1f4..e224c7dccd2b7e74a42b2f24b38347f0e32ff3d7 100644 (file)
@@ -36,7 +36,7 @@ class CCLayerTreeHostImpl;
 // FIXME: compute overdraw metrics only occasionally, not every frame.
 class CCOverdrawMetrics {
 public:
-    static PassOwnPtr<CCOverdrawMetrics> create() { return adoptPtr(new CCOverdrawMetrics()); }
+    static PassOwnPtr<CCOverdrawMetrics> create(bool recordMetricsForFrame) { return adoptPtr(new CCOverdrawMetrics(recordMetricsForFrame)); }
 
     void didCull(const TransformationMatrix& transformToTarget, const IntRect& beforeCullRect, const IntRect& afterCullRect);
     void didDraw(const TransformationMatrix& transformToTarget, const IntRect& afterCullRect, const IntRect& opaqueRect);
@@ -50,7 +50,7 @@ public:
     float pixelsCulled() const { return m_pixelsCulled; }
 
 private:
-    CCOverdrawMetrics();
+    explicit CCOverdrawMetrics(bool recordMetricsForFrame);
 
     enum MetricsType {
         DRAWING,
@@ -60,6 +60,8 @@ private:
     template<typename LayerTreeHostType>
     void recordMetricsInternal(MetricsType, const LayerTreeHostType*) const;
 
+    // When false this class is a giant no-op.
+    bool m_recordMetricsForFrame;
     // Count of pixels that are opaque (and thus occlude). Ideally this is no more
     // than wiewport width x height.
     float m_pixelsDrawnOpaque;
index b2531c7271fc9235fb91ecf3e97d29e21726db76..0ccc56013c13577b7b5b4c694f20a2c01a7a778a 100644 (file)
@@ -1,3 +1,19 @@
+2012-03-20  Dana Jansens  <danakj@chromium.org>
+
+        [chromium] Allow us to disable overdraw metrics when tracing is off
+        https://bugs.webkit.org/show_bug.cgi?id=81431
+
+        Reviewed by Adrienne Walker.
+
+        * tests/CCOcclusionTrackerTest.cpp:
+        (WebCore::TestCCOcclusionTrackerBase::TestCCOcclusionTrackerBase):
+        * tests/CCQuadCullerTest.cpp:
+        (WebCore::TestCCOcclusionTrackerImpl::TestCCOcclusionTrackerImpl):
+        (WebCore::TEST):
+        (WebCore):
+        * tests/TiledLayerChromiumTest.cpp:
+        (WTF::TestCCOcclusionTracker::TestCCOcclusionTracker):
+
 2012-03-20  Dana Jansens  <danakj@chromium.org>
 
         [chromium] Use opaque contents for paint culling
index 7589a3c8664187ebf48c3eac028a4e12f7db1145..1e9d8d283e1bb244af448c86f1587d324719a655 100644 (file)
@@ -75,8 +75,8 @@ private:
 template<typename LayerType, typename RenderSurfaceType>
 class TestCCOcclusionTrackerBase : public CCOcclusionTrackerBase<LayerType, RenderSurfaceType> {
 public:
-    TestCCOcclusionTrackerBase(IntRect screenScissorRect)
-        : CCOcclusionTrackerBase<LayerType, RenderSurfaceType>(screenScissorRect)
+    TestCCOcclusionTrackerBase(IntRect screenScissorRect, bool recordMetricsForFrame = false)
+        : CCOcclusionTrackerBase<LayerType, RenderSurfaceType>(screenScissorRect, recordMetricsForFrame)
         , m_overrideLayerScissorRect(false)
     {
     }
index 11a089a52cdec9bed4efb3dc2124a3f3e43b759f..c1bbce62526d153be5829e5a9afaf997f8179d8a 100644 (file)
@@ -40,8 +40,8 @@ namespace {
 
 class TestCCOcclusionTrackerImpl : public CCOcclusionTrackerImpl {
 public:
-    TestCCOcclusionTrackerImpl(const IntRect& scissorRectInScreen)
-        : CCOcclusionTrackerImpl(scissorRectInScreen)
+    TestCCOcclusionTrackerImpl(const IntRect& scissorRectInScreen, bool recordMetricsForFrame = true)
+        : CCOcclusionTrackerImpl(scissorRectInScreen, recordMetricsForFrame)
         , m_scissorRectInScreen(scissorRectInScreen)
     {
         // Pretend we have visited a render surface.
@@ -447,4 +447,22 @@ TEST(CCQuadCullerTest, verifyCullOutsideScissorOverNoTiles)
     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 130000, 1);
 }
 
+TEST(CCQuadCullerTest, verifyWithoutMetrics)
+{
+    DECLARE_AND_INITIALIZE_TEST_QUADS
+
+    OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
+    OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
+    TestCCOcclusionTrackerImpl occlusionTracker(IntRect(50, 50, 200, 200), false);
+
+    appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
+    occlusionTracker.markOccludedBehindLayer(childLayer.get());
+    appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
+    EXPECT_EQ(quadList.size(), 9u);
+    EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 0, 1);
+    EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
+    EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 0, 1);
+}
+
+
 } // namespace
index 5368c29347fde3378afb575236f46ed120daeb1b..94f9eb4d8a266b6a3f63f7bc9073225274fa5c1f 100644 (file)
@@ -51,7 +51,7 @@ namespace {
 class TestCCOcclusionTracker : public CCOcclusionTracker {
 public:
     TestCCOcclusionTracker()
-        : CCOcclusionTracker(IntRect(0, 0, 1000, 1000))
+        : CCOcclusionTracker(IntRect(0, 0, 1000, 1000), true)
         , m_scissorRectInScreen(IntRect(0, 0, 1000, 1000))
     {
         // Pretend we have visited a render surface.