Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / blimp / client / compositor / test / dummy_layer_driver.cc
blob306dd70e211bd6fb645f185e078bf58ee3e7a18c
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"
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 "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"
16 namespace blimp {
18 DummyLayerDriver::DummyLayerDriver()
19 : layer_(cc::SolidColorLayer::Create(cc::LayerSettings())),
20 animation_running_(false),
21 weak_factory_(this) {
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;
36 StepAnimation();
40 void DummyLayerDriver::StepAnimation() {
41 // Detached from the cc::LayerTreeHost. Stop doing work.
42 if (!layer_->layer_tree_host()) {
43 animation_running_ = false;
44 return;
47 // Fun with colors
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(
55 FROM_HERE,
56 base::Bind(&DummyLayerDriver::StepAnimation, weak_factory_.GetWeakPtr()),
57 base::TimeDelta::FromMilliseconds(16));
60 } // namespace blimp