OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 "blimp/client/compositor/test/dummy_layer_driver.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/location.h" | |
9 #include "base/task_runner.h" | |
10 #include "base/thread_task_runner_handle.h" | |
11 #include "blimp/client/compositor/blimp_compositor.h" | |
12 #include "cc/layers/layer.h" | |
13 #include "cc/layers/layer_settings.h" | |
14 #include "cc/layers/solid_color_layer.h" | |
15 #include "cc/trees/layer_tree_settings.h" | |
16 #include "ui/gfx/geometry/size.h" | |
17 | |
18 namespace blimp { | |
19 namespace client { | |
20 | |
21 DummyLayerDriver::DummyLayerDriver() | |
22 : layer_(cc::SolidColorLayer::Create(BlimpCompositor::LayerSettings())), | |
23 animation_running_(false), | |
24 weak_factory_(this) { | |
25 layer_->SetIsDrawable(true); | |
26 layer_->SetBackgroundColor(SK_ColorBLUE); | |
27 layer_->SetBounds(gfx::Size(300, 300)); | |
28 } | |
29 | |
30 DummyLayerDriver::~DummyLayerDriver() {} | |
31 | |
32 void DummyLayerDriver::SetParentLayer(scoped_refptr<cc::Layer> layer) { | |
33 // This will automatically remove layer_ from the previous layer. | |
34 layer->AddChild(layer_); | |
35 | |
36 // If we're not expecting another animation step, start one now. | |
37 if (!animation_running_) { | |
38 animation_running_ = true; | |
39 StepAnimation(); | |
40 } | |
41 } | |
42 | |
43 void DummyLayerDriver::StepAnimation() { | |
44 // Detached from the cc::LayerTreeHost. Stop doing work. | |
45 if (!layer_->layer_tree_host()) { | |
46 animation_running_ = false; | |
47 return; | |
48 } | |
49 | |
50 // Fun with colors | |
51 SkColor color = layer_->background_color(); | |
52 color = SkColorSetRGB((SkColorGetR(color) + 5) % 255, | |
53 (SkColorGetG(color) + 3) % 255, | |
54 (SkColorGetB(color) + 1) % 255); | |
55 layer_->SetBackgroundColor(color); | |
56 | |
57 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
58 FROM_HERE, | |
59 base::Bind(&DummyLayerDriver::StepAnimation, weak_factory_.GetWeakPtr()), | |
60 base::TimeDelta::FromMilliseconds(16)); | |
61 } | |
62 | |
63 } // namespace client | |
64 } // namespace blimp | |
OLD | NEW |