Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ash / wm / boot_splash_screen_chromeos.cc
1 // Copyright 2013 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 "ash/wm/boot_splash_screen_chromeos.h"
6
7 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/window_tree_host.h"
10 #include "ui/base/x/x11_util.h"
11 #include "ui/compositor/layer.h"
12 #include "ui/compositor/layer_type.h"
13 #include "ui/compositor/scoped_layer_animation_settings.h"
14 #include "ui/gfx/canvas.h"
15
16 namespace ash {
17
18 // ui::LayerDelegate that copies the aura host window's content to a ui::Layer.
19 class BootSplashScreen::CopyHostContentLayerDelegate
20     : public ui::LayerDelegate {
21  public:
22   explicit CopyHostContentLayerDelegate(aura::WindowTreeHost* host)
23       : host_(host) {
24   }
25
26   virtual ~CopyHostContentLayerDelegate() {}
27
28   // ui::LayerDelegate overrides:
29   virtual void OnPaintLayer(gfx::Canvas* canvas) override {
30     // It'd be safer to copy the area to a canvas in the constructor and then
31     // copy from that canvas to this one here, but this appears to work (i.e. we
32     // only call this before we draw our first frame) and it saves us an extra
33     // copy.
34     // TODO(derat): Instead of copying the data, use GLX_EXT_texture_from_pixmap
35     // to create a zero-copy texture (when possible):
36     // https://codereview.chromium.org/10543125
37 #if defined(USE_X11)
38     ui::CopyAreaToCanvas(host_->GetAcceleratedWidget(),
39         host_->GetBounds(), gfx::Point(), canvas);
40 #else
41     // TODO(spang): Figure out what to do here.
42     NOTIMPLEMENTED();
43 #endif
44   }
45
46   virtual void OnDelegatedFrameDamage(
47       const gfx::Rect& damage_rect_in_dip) override {}
48
49   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
50
51   virtual base::Closure PrepareForLayerBoundsChange() override {
52     return base::Closure();
53   }
54
55  private:
56   aura::WindowTreeHost* host_;  // not owned
57
58   DISALLOW_COPY_AND_ASSIGN(CopyHostContentLayerDelegate);
59 };
60
61 BootSplashScreen::BootSplashScreen(aura::WindowTreeHost* host)
62     : layer_delegate_(new CopyHostContentLayerDelegate(host)),
63       layer_(new ui::Layer(ui::LAYER_TEXTURED)) {
64   layer_->set_delegate(layer_delegate_.get());
65
66   ui::Layer* root_layer = host->window()->layer();
67   layer_->SetBounds(gfx::Rect(host->window()->bounds().size()));
68   root_layer->Add(layer_.get());
69   root_layer->StackAtTop(layer_.get());
70 }
71
72 BootSplashScreen::~BootSplashScreen() {
73 }
74
75 void BootSplashScreen::StartHideAnimation(base::TimeDelta duration) {
76   ui::ScopedLayerAnimationSettings settings(layer_->GetAnimator());
77   settings.SetTransitionDuration(duration);
78   settings.SetPreemptionStrategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
79   layer_->SetOpacity(0.0f);
80 }
81
82 }  // namespace ash