Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 "base/message_loop/message_loop_proxy.h" | |
| 6 #include "base/threading/simple_thread.h" | |
| 7 #include "cc/layers/delegated_renderer_layer.h" | |
| 8 #include "cc/layers/layer.h" | |
| 9 #include "cc/layers/solid_color_layer.h" | |
| 10 #include "cc/output/output_surface.h" | |
| 11 #include "cc/output/output_surface_client.h" | |
| 12 #include "cc/test/test_context_provider.h" | |
| 13 #include "cc/trees/layer_tree_host.h" | |
| 14 #include "cc/trees/layer_tree_host_client.h" | |
| 15 #include "cc/trees/layer_tree_host_single_thread_client.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 #include "third_party/skia/include/core/SkColor.h" | |
| 18 #include "ui/gfx/frame_time.h" | |
| 19 | |
| 20 namespace cc { | |
| 21 namespace { | |
| 22 | |
| 23 class NoMessageLoopOutputSurface : public OutputSurface { | |
| 24 public: | |
| 25 NoMessageLoopOutputSurface() : OutputSurface(TestContextProvider::Create()) {} | |
| 26 virtual ~NoMessageLoopOutputSurface() {} | |
| 27 | |
| 28 // OutputSurface overrides. | |
| 29 virtual void SwapBuffers(CompositorFrame* frame) OVERRIDE { | |
| 30 DCHECK(client_); | |
| 31 client_->DidSwapBuffers(); | |
| 32 client_->DidSwapBuffersComplete(); | |
| 33 } | |
| 34 }; | |
| 35 | |
| 36 class LayerTreeHostNoMessageLoopTest : public testing::Test, | |
| 37 public base::SimpleThread, | |
|
piman
2014/05/22 20:53:30
multiple implementation inheritance is unfortunate
boliu
2014/05/22 23:17:37
Done
| |
| 38 public LayerTreeHostClient, | |
| 39 public LayerTreeHostSingleThreadClient { | |
| 40 public: | |
| 41 LayerTreeHostNoMessageLoopTest() | |
| 42 : base::SimpleThread("LayerTreeHostNoMessageLoopTest"), | |
| 43 did_initialize_output_surface_(false), | |
| 44 did_commit_(false), | |
| 45 did_commit_and_draw_frame_(false) {} | |
| 46 virtual ~LayerTreeHostNoMessageLoopTest() {} | |
| 47 | |
| 48 // LayerTreeHostClient overrides. | |
| 49 virtual void WillBeginMainFrame(int frame_id) OVERRIDE {} | |
| 50 virtual void DidBeginMainFrame() OVERRIDE {} | |
| 51 virtual void Animate(base::TimeTicks frame_begin_time) OVERRIDE {} | |
| 52 virtual void Layout() OVERRIDE {} | |
| 53 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, | |
| 54 float page_scale) OVERRIDE {} | |
| 55 virtual scoped_ptr<OutputSurface> CreateOutputSurface( | |
| 56 bool fallback) OVERRIDE { | |
| 57 return make_scoped_ptr<OutputSurface>(new NoMessageLoopOutputSurface); | |
| 58 } | |
| 59 virtual void DidInitializeOutputSurface() OVERRIDE { | |
| 60 did_initialize_output_surface_ = true; | |
| 61 } | |
| 62 virtual void WillCommit() OVERRIDE {} | |
| 63 virtual void DidCommit() OVERRIDE { did_commit_ = true; } | |
| 64 virtual void DidCommitAndDrawFrame() OVERRIDE { | |
| 65 did_commit_and_draw_frame_ = true; | |
| 66 } | |
| 67 virtual void DidCompleteSwapBuffers() OVERRIDE {} | |
| 68 | |
| 69 // LayerTreeHostSingleThreadClient overrides. | |
| 70 virtual void ScheduleComposite() OVERRIDE {} | |
| 71 virtual void ScheduleAnimation() OVERRIDE {} | |
| 72 virtual void DidPostSwapBuffers() OVERRIDE {} | |
| 73 virtual void DidAbortSwapBuffers() OVERRIDE {} | |
| 74 | |
| 75 void RunTest() { | |
| 76 Start(); | |
| 77 Join(); | |
| 78 } | |
| 79 | |
| 80 // base::SimpleThread override. | |
| 81 virtual void Run() OVERRIDE { | |
| 82 ASSERT_FALSE(base::MessageLoopProxy::current()); | |
| 83 RunTestWithoutMessageLoop(); | |
| 84 EXPECT_FALSE(base::MessageLoopProxy::current()); | |
| 85 } | |
| 86 | |
| 87 virtual void RunTestWithoutMessageLoop() = 0; | |
| 88 | |
| 89 protected: | |
| 90 // All member variables accessed only on SimpleThread with no MessageLoop. | |
| 91 bool did_initialize_output_surface_; | |
| 92 bool did_commit_; | |
| 93 bool did_commit_and_draw_frame_; | |
| 94 }; | |
| 95 | |
| 96 class LayerTreeHostNoMessageLoopSmokeTest | |
| 97 : public LayerTreeHostNoMessageLoopTest { | |
| 98 virtual void RunTestWithoutMessageLoop() OVERRIDE { | |
| 99 did_initialize_output_surface_ = false; | |
| 100 gfx::Size size(100, 100); | |
| 101 | |
| 102 // Set up LayerTreeHost. | |
| 103 LayerTreeSettings settings; | |
| 104 scoped_ptr<LayerTreeHost> layer_tree_host = | |
| 105 LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings); | |
| 106 layer_tree_host->SetViewportSize(size); | |
| 107 | |
| 108 // Set up root layer. | |
| 109 scoped_refptr<SolidColorLayer> root_layer = SolidColorLayer::Create(); | |
| 110 root_layer->SetBackgroundColor(SK_ColorRED); | |
| 111 root_layer->SetBounds(size); | |
| 112 root_layer->SetIsDrawable(true); | |
| 113 layer_tree_host->SetRootLayer(root_layer); | |
| 114 | |
| 115 // Composite. | |
| 116 did_commit_ = false; | |
| 117 did_commit_and_draw_frame_ = false; | |
| 118 layer_tree_host->Composite(gfx::FrameTime::Now()); | |
| 119 EXPECT_TRUE(did_initialize_output_surface_); | |
| 120 EXPECT_TRUE(did_commit_); | |
| 121 EXPECT_TRUE(did_commit_and_draw_frame_); | |
| 122 | |
| 123 // Explicit teardown to make failures easier to debug. | |
| 124 layer_tree_host.reset(); | |
| 125 root_layer = NULL; | |
| 126 } | |
| 127 }; | |
| 128 | |
| 129 TEST_F(LayerTreeHostNoMessageLoopSmokeTest, SmokeTest) { | |
| 130 RunTest(); | |
| 131 } | |
| 132 | |
| 133 } // namespace | |
| 134 } // namespace cc | |
| OLD | NEW |