Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: blimp/client/compositor/test/dummy_layer_driver.cc

Issue 1295243003: Initial commit of the blimp/ folder and target (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address final nits. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "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"
15
16 namespace blimp {
17
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));
25 }
26
27 DummyLayerDriver::~DummyLayerDriver() {}
28
29 void DummyLayerDriver::SetParentLayer(scoped_refptr<cc::Layer> layer) {
30 // This will automatically remove layer_ from the previous layer.
31 layer->AddChild(layer_);
32
33 // If we're not expecting another animation step, start one now.
34 if (!animation_running_) {
35 animation_running_ = true;
36 StepAnimation();
37 }
38 }
39
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;
45 }
46
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);
53
54 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
55 FROM_HERE,
56 base::Bind(&DummyLayerDriver::StepAnimation, weak_factory_.GetWeakPtr()),
57 base::TimeDelta::FromMilliseconds(16));
58 }
59
60 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698