OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "web/tests/sim/SimCompositor.h" | |
7 | |
8 #include "core/frame/FrameView.h" | |
9 #include "core/layout/LayoutView.h" | |
10 #include "core/layout/compositing/CompositedDeprecatedPaintLayerMapping.h" | |
11 #include "core/paint/DeprecatedPaintLayer.h" | |
12 #include "platform/graphics/ContentLayerDelegate.h" | |
13 #include "public/platform/WebRect.h" | |
14 #include "web/WebLocalFrameImpl.h" | |
15 #include "web/WebViewImpl.h" | |
16 #include "web/tests/sim/SimDisplayItemList.h" | |
17 #include "web/tests/sim/SimLayerTreeView.h" | |
18 #include "wtf/CurrentTime.h" | |
19 | |
20 namespace blink { | |
21 | |
22 static void paintLayers(DeprecatedPaintLayer& layer, SimDisplayItemList& display
List) | |
23 { | |
24 if (layer.compositingState() == PaintsIntoOwnBacking) { | |
25 CompositedDeprecatedPaintLayerMapping* mapping = layer.compositedDepreca
tedPaintLayerMapping(); | |
26 GraphicsLayer* graphicsLayer = mapping->mainGraphicsLayer(); | |
27 if (graphicsLayer->hasTrackedPaintInvalidations()) { | |
28 ContentLayerDelegate* delegate = graphicsLayer->contentLayerDelegate
ForTesting(); | |
29 delegate->paintContents(&displayList, WebRect(0, 0, layer.size().wid
th(), layer.size().height())); | |
30 graphicsLayer->resetTrackedPaintInvalidations(); | |
31 } | |
32 } | |
33 for (DeprecatedPaintLayer* child = layer.firstChild(); child; child = child-
>nextSibling()) | |
34 paintLayers(*child, displayList); | |
35 } | |
36 | |
37 static void paintFrames(LocalFrame& root, SimDisplayItemList& displayList) | |
38 { | |
39 for (Frame* frame = &root; frame; frame = frame->tree().traverseNext(&root))
{ | |
40 if (!frame->isLocalFrame()) | |
41 continue; | |
42 DeprecatedPaintLayer* layer = toLocalFrame(frame)->view()->layoutView()-
>layer(); | |
43 paintLayers(*layer, displayList); | |
44 } | |
45 } | |
46 | |
47 SimCompositor::SimCompositor(SimLayerTreeView& layerTreeView) | |
48 : m_layerTreeView(&layerTreeView) | |
49 , m_webViewImpl(0) | |
50 , m_lastFrameTimeMonotonic(0) | |
51 { | |
52 FrameView::setInitialTracksPaintInvalidationsForTesting(true); | |
53 } | |
54 | |
55 SimCompositor::~SimCompositor() | |
56 { | |
57 FrameView::setInitialTracksPaintInvalidationsForTesting(false); | |
58 } | |
59 | |
60 void SimCompositor::setWebViewImpl(WebViewImpl& webViewImpl) | |
61 { | |
62 m_webViewImpl = &webViewImpl; | |
63 } | |
64 | |
65 SimCompositor::BeginFrameResult SimCompositor::beginFrame() | |
66 { | |
67 ASSERT(m_webViewImpl); | |
68 ASSERT(!m_layerTreeView->deferCommits()); | |
69 ASSERT(m_layerTreeView->needsAnimate()); | |
70 | |
71 // Always advance the time as if the compositor was running at 60fps. | |
72 m_lastFrameTimeMonotonic = monotonicallyIncreasingTime() + 0.016; | |
73 | |
74 WebBeginFrameArgs args(m_lastFrameTimeMonotonic, 0, 0); | |
75 m_webViewImpl->beginFrame(args); | |
76 m_webViewImpl->layout(); | |
77 | |
78 LocalFrame* root = m_webViewImpl->mainFrameImpl()->frame(); | |
79 | |
80 SimDisplayItemList displayList; | |
81 paintFrames(*root, displayList); | |
82 | |
83 BeginFrameResult result; | |
84 result.didDrawText = displayList.didDrawText(); | |
85 result.drawCount = displayList.drawCount(); | |
86 | |
87 m_layerTreeView->clearNeedsAnimate(); | |
88 | |
89 return result; | |
90 } | |
91 | |
92 } // namespace blink | |
OLD | NEW |