1 // Copyright 2013 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.
5 #include "cc/layers/append_quads_data.h"
6 #include "cc/layers/heads_up_display_layer_impl.h"
7 #include "cc/test/fake_impl_proxy.h"
8 #include "cc/test/fake_layer_tree_host_impl.h"
9 #include "cc/test/fake_output_surface.h"
10 #include "cc/test/test_shared_bitmap_manager.h"
11 #include "testing/gtest/include/gtest/gtest.h"
16 void CheckDrawLayer(HeadsUpDisplayLayerImpl
* layer
,
17 ResourceProvider
* resource_provider
,
19 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
21 bool will_draw
= layer
->WillDraw(draw_mode
, resource_provider
);
23 layer
->AppendQuads(render_pass
.get(), &data
);
24 layer
->UpdateHudTexture(draw_mode
, resource_provider
);
26 layer
->DidDraw(resource_provider
);
28 size_t expected_quad_list_size
= will_draw
? 1 : 0;
29 EXPECT_EQ(expected_quad_list_size
, render_pass
->quad_list
.size());
32 TEST(HeadsUpDisplayLayerImplTest
, ResourcelessSoftwareDrawAfterResourceLoss
) {
34 TestSharedBitmapManager shared_bitmap_manager
;
35 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
36 host_impl
.CreatePendingTree();
37 host_impl
.InitializeRenderer(FakeOutputSurface::Create3d());
38 scoped_ptr
<HeadsUpDisplayLayerImpl
> layer
=
39 HeadsUpDisplayLayerImpl::Create(host_impl
.pending_tree(), 1);
40 layer
->SetBounds(gfx::Size(100, 100));
41 layer
->draw_properties().ideal_contents_scale
= 1.f
;
43 // Check regular hardware draw is ok.
45 layer
.get(), host_impl
.resource_provider(), DRAW_MODE_HARDWARE
);
47 // Simulate a resource loss on transitioning to resourceless software mode.
48 layer
->ReleaseResources();
50 // Should skip resourceless software draw and not crash in UpdateHudTexture.
51 CheckDrawLayer(layer
.get(),
52 host_impl
.resource_provider(),
53 DRAW_MODE_RESOURCELESS_SOFTWARE
);