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.
5 #include "blimp/client/compositor/test/dummy_layer_driver.h"
8 #include "base/location.h"
9 #include "base/task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "cc/layers/layer.h"
12 #include "cc/layers/solid_color_layer.h"
13 #include "cc/trees/layer_tree_settings.h"
14 #include "ui/gfx/geometry/size.h"
18 DummyLayerDriver::DummyLayerDriver()
19 : layer_(cc::SolidColorLayer::Create(cc::LayerSettings())),
20 animation_running_(false),
22 layer_
->SetIsDrawable(true);
23 layer_
->SetBackgroundColor(SK_ColorBLUE
);
24 layer_
->SetBounds(gfx::Size(300, 300));
27 DummyLayerDriver::~DummyLayerDriver() {}
29 void DummyLayerDriver::SetParentLayer(scoped_refptr
<cc::Layer
> layer
) {
30 // This will automatically remove layer_ from the previous layer.
31 layer
->AddChild(layer_
);
33 // If we're not expecting another animation step, start one now.
34 if (!animation_running_
) {
35 animation_running_
= true;
40 void DummyLayerDriver::StepAnimation() {
41 // Detached from the cc::LayerTreeHost. Stop doing work.
42 if (!layer_
->layer_tree_host()) {
43 animation_running_
= false;
48 SkColor color
= layer_
->background_color();
49 color
= SkColorSetRGB((SkColorGetR(color
) + 5) % 255,
50 (SkColorGetG(color
) + 3) % 255,
51 (SkColorGetB(color
) + 1) % 255);
52 layer_
->SetBackgroundColor(color
);
54 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
56 base::Bind(&DummyLayerDriver::StepAnimation
, weak_factory_
.GetWeakPtr()),
57 base::TimeDelta::FromMilliseconds(16));