blob: 8ea3ac1929601ec8e23e4a15abbad9c9d3444207 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/testing/sim/sim_compositor.h"
#include "cc/test/fake_layer_tree_frame_sink.h"
#include "cc/trees/render_frame_metadata_observer.h"
#include "third_party/blink/public/platform/web_rect.h"
#include "third_party/blink/renderer/core/exported/web_view_impl.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/paint/compositing/composited_layer_mapping.h"
#include "third_party/blink/renderer/core/paint/compositing/paint_layer_compositor.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/platform/graphics/graphics_context.h"
#include "third_party/blink/renderer/platform/graphics/paint/cull_rect.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_record_builder.h"
namespace blink {
SimCompositor::SimCompositor() {
last_frame_time_ = base::TimeTicks::Now();
}
SimCompositor::~SimCompositor() = default;
void SimCompositor::SetWebView(
WebViewImpl& web_view,
frame_test_helpers::TestWebViewClient& view_client) {
web_view_ = &web_view;
test_web_view_client_ = &view_client;
}
SimCanvas::Commands SimCompositor::BeginFrame(double time_delta_in_seconds) {
DCHECK(web_view_);
DCHECK(!layer_tree_host()->defer_main_frame_update());
// Verify that the need for a BeginMainFrame has been registered, and would
// have caused the compositor to schedule one if we were using its scheduler.
DCHECK(NeedsBeginFrame());
DCHECK_GT(time_delta_in_seconds, 0);
ClearAnimationScheduled();
last_frame_time_ += base::TimeDelta::FromSecondsD(time_delta_in_seconds);
SimCanvas::Commands commands;
paint_commands_ = &commands;
layer_tree_host()->Composite(last_frame_time_,
/*raster=*/false);
paint_commands_ = nullptr;
return commands;
}
SimCanvas::Commands SimCompositor::PaintFrame() {
DCHECK(web_view_);
auto* frame = web_view_->MainFrameImpl()->GetFrame();
DocumentLifecycle::AllowThrottlingScope throttling_scope(
frame->GetDocument()->Lifecycle());
frame->View()->UpdateAllLifecyclePhases(DocumentUpdateReason::kTest);
PaintRecordBuilder builder;
frame->View()->PaintOutsideOfLifecycle(builder.Context(),
kGlobalPaintFlattenCompositingLayers);
auto infinite_rect = LayoutRect::InfiniteIntRect();
SimCanvas canvas(infinite_rect.Width(), infinite_rect.Height());
builder.EndRecording()->Playback(&canvas);
return canvas.GetCommands();
}
void SimCompositor::DidBeginMainFrame() {
*paint_commands_ = PaintFrame();
}
} // namespace blink
|