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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
cc / layers / heads_up_display_layer_impl_unittest.cc [blame]
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include <utility>
#include "cc/layers/append_quads_data.h"
#include "cc/layers/heads_up_display_layer_impl.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_frame_sink.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/layer_tree_impl_test_base.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/raster_capabilities.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
namespace {
void CheckDrawLayer(HeadsUpDisplayLayerImpl* layer,
LayerTreeFrameSink* frame_sink,
viz::ClientResourceProvider* resource_provider,
viz::RasterContextProvider* context_provider,
DrawMode draw_mode) {
auto render_pass = viz::CompositorRenderPass::Create();
AppendQuadsData data;
bool will_draw = layer->WillDraw(draw_mode, resource_provider);
if (will_draw)
layer->AppendQuads(render_pass.get(), &data);
viz::CompositorRenderPassList pass_list;
pass_list.push_back(std::move(render_pass));
RasterCapabilities raster_caps;
raster_caps.use_gpu_rasterization = context_provider != nullptr;
layer->UpdateHudTexture(draw_mode, frame_sink, resource_provider, raster_caps,
pass_list);
if (will_draw)
layer->DidDraw(resource_provider);
size_t expected_quad_list_size = will_draw ? 1 : 0;
EXPECT_EQ(expected_quad_list_size, pass_list.back()->quad_list.size());
EXPECT_EQ(0, data.num_missing_tiles);
EXPECT_FALSE(data.checkerboarded_needs_raster);
EXPECT_FALSE(data.checkerboarded_needs_record);
}
class HeadsUpDisplayLayerImplTest : public LayerTreeImplTestBase,
public ::testing::Test {
public:
HeadsUpDisplayLayerImplTest()
: LayerTreeImplTestBase(
FakeLayerTreeFrameSink::Create3dForGpuRasterization()) {}
};
TEST_F(HeadsUpDisplayLayerImplTest, ResourcelessSoftwareDrawAfterResourceLoss) {
host_impl()->CreatePendingTree();
auto* root = EnsureRootLayerInPendingTree();
auto* layer = AddLayerInPendingTree<HeadsUpDisplayLayerImpl>(std::string());
layer->SetBounds(gfx::Size(100, 100));
layer->set_visible_layer_rect(gfx::Rect(100, 100));
CopyProperties(root, layer);
UpdatePendingTreeDrawProperties();
// Check regular hardware draw is ok.
CheckDrawLayer(layer, layer_tree_frame_sink(), resource_provider(),
layer_tree_frame_sink()->context_provider(),
DRAW_MODE_HARDWARE);
// Simulate a resource loss on transitioning to resourceless software mode.
layer->ReleaseResources();
// Should skip resourceless software draw and not crash in UpdateHudTexture.
CheckDrawLayer(layer, layer_tree_frame_sink(), resource_provider(),
layer_tree_frame_sink()->context_provider(),
DRAW_MODE_RESOURCELESS_SOFTWARE);
}
TEST_F(HeadsUpDisplayLayerImplTest, CPUAndGPURasterCanvas) {
host_impl()->CreatePendingTree();
auto* root = EnsureRootLayerInPendingTree();
auto* layer = AddLayerInPendingTree<HeadsUpDisplayLayerImpl>(std::string());
layer->SetBounds(gfx::Size(100, 100));
CopyProperties(root, layer);
UpdatePendingTreeDrawProperties();
// Check Ganesh canvas drawing is ok.
CheckDrawLayer(layer, layer_tree_frame_sink(), resource_provider(),
layer_tree_frame_sink()->context_provider(),
DRAW_MODE_HARDWARE);
host_impl()->ReleaseLayerTreeFrameSink();
auto layer_tree_frame_sink = FakeLayerTreeFrameSink::CreateSoftware();
host_impl()->InitializeFrameSink(layer_tree_frame_sink.get());
// Check SW canvas drawing is ok.
CheckDrawLayer(layer, layer_tree_frame_sink.get(), resource_provider(),
nullptr, DRAW_MODE_SOFTWARE);
host_impl()->ReleaseLayerTreeFrameSink();
}
} // namespace
} // namespace cc