Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 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. |
| 4 | |
| 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_quad_culler.h" |
| 11 | #include "testing/gtest/include/gtest/gtest.h" |
| 12 | |
| 13 | namespace cc { |
| 14 | namespace { |
| 15 | |
| 16 | void CheckDrawLayer(HeadsUpDisplayLayerImpl* layer, |
| 17 | ResourceProvider* resource_provider, |
| 18 | DrawMode draw_mode) { |
| 19 | MockQuadCuller quad_culler; |
| 20 | AppendQuadsData data; |
| 21 | bool will_draw = layer->WillDraw(draw_mode, resource_provider); |
| 22 | if (will_draw) |
| 23 | layer->AppendQuads(&quad_culler, &data); |
| 24 | layer->UpdateHudTexture(draw_mode, resource_provider); |
| 25 | if (will_draw) |
| 26 | layer->DidDraw(resource_provider); |
| 27 | |
| 28 | size_t expected_quad_list_size = will_draw ? 1 : 0; |
| 29 | EXPECT_EQ(expected_quad_list_size, quad_culler.quad_list().size()); |
| 30 | } |
| 31 | |
| 32 | TEST(HeadsUpDisplayLayerImplTest, ResourcelessSoftwareDrawAfterResourceLoss) { |
| 33 | FakeImplProxy proxy; |
| 34 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 35 | host_impl.CreatePendingTree(); |
| 36 | host_impl.InitializeRenderer(CreateFakeOutputSurface()); |
| 37 | scoped_ptr<HeadsUpDisplayLayerImpl> layer = |
| 38 | HeadsUpDisplayLayerImpl::Create(host_impl.pending_tree(), 1); |
| 39 | layer->SetContentBounds(gfx::Size(100, 100)); |
| 40 | |
| 41 | // Check regular hardware draw is ok. |
| 42 | CheckDrawLayer( |
| 43 | layer.get(), host_impl.resource_provider(), DRAW_MODE_HARDWARE); |
| 44 | |
| 45 | // Simulate a resource loss on transitioning to resourceless software mode. |
| 46 | layer->DidLoseOutputSurface(); |
| 47 | |
| 48 | // Should skip resourceless software draw and not crash in UpdateHudTexture. |
| 49 | CheckDrawLayer(layer.get(), |
| 50 | host_impl.resource_provider(), |
| 51 | DRAW_MODE_RESOURCELESS_SOFTWARE); |
| 52 | } |
| 53 | |
| 54 | } // namespace |
| 55 | } // namespace cc |