Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / layers / heads_up_display_layer_impl_unittest.cc
blob2c057dd13da8941610df856f2e4af0f3d790ee7e
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/mock_occlusion_tracker.h"
11 #include "cc/test/test_shared_bitmap_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace cc {
15 namespace {
17 void CheckDrawLayer(HeadsUpDisplayLayerImpl* layer,
18 ResourceProvider* resource_provider,
19 DrawMode draw_mode) {
20 MockOcclusionTracker<LayerImpl> occlusion_tracker;
21 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
22 AppendQuadsData data;
23 bool will_draw = layer->WillDraw(draw_mode, resource_provider);
24 if (will_draw)
25 layer->AppendQuads(render_pass.get(), occlusion_tracker, &data);
26 layer->UpdateHudTexture(draw_mode, resource_provider);
27 if (will_draw)
28 layer->DidDraw(resource_provider);
30 size_t expected_quad_list_size = will_draw ? 1 : 0;
31 EXPECT_EQ(expected_quad_list_size, render_pass->quad_list.size());
34 TEST(HeadsUpDisplayLayerImplTest, ResourcelessSoftwareDrawAfterResourceLoss) {
35 FakeImplProxy proxy;
36 TestSharedBitmapManager shared_bitmap_manager;
37 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
38 host_impl.CreatePendingTree();
39 host_impl.InitializeRenderer(
40 FakeOutputSurface::Create3d().PassAs<OutputSurface>());
41 scoped_ptr<HeadsUpDisplayLayerImpl> layer =
42 HeadsUpDisplayLayerImpl::Create(host_impl.pending_tree(), 1);
43 layer->SetContentBounds(gfx::Size(100, 100));
45 // Check regular hardware draw is ok.
46 CheckDrawLayer(
47 layer.get(), host_impl.resource_provider(), DRAW_MODE_HARDWARE);
49 // Simulate a resource loss on transitioning to resourceless software mode.
50 layer->ReleaseResources();
52 // Should skip resourceless software draw and not crash in UpdateHudTexture.
53 CheckDrawLayer(layer.get(),
54 host_impl.resource_provider(),
55 DRAW_MODE_RESOURCELESS_SOFTWARE);
58 } // namespace
59 } // namespace cc