• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/root_window.h"
9 #include "ui/aura/window.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 namespace internal {
18 
19 // ui::LayerDelegate that copies the aura host window's content to a ui::Layer.
20 class BootSplashScreen::CopyHostContentLayerDelegate
21     : public ui::LayerDelegate {
22  public:
CopyHostContentLayerDelegate(aura::RootWindow * root_window)23   explicit CopyHostContentLayerDelegate(aura::RootWindow* root_window)
24       : root_window_(root_window) {
25   }
26 
~CopyHostContentLayerDelegate()27   virtual ~CopyHostContentLayerDelegate() {}
28 
29   // ui::LayerDelegate overrides:
OnPaintLayer(gfx::Canvas * canvas)30   virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
31     // It'd be safer to copy the area to a canvas in the constructor and then
32     // copy from that canvas to this one here, but this appears to work (i.e. we
33     // only call this before we draw our first frame) and it saves us an extra
34     // copy.
35     // TODO(derat): Instead of copying the data, use GLX_EXT_texture_from_pixmap
36     // to create a zero-copy texture (when possible):
37     // https://codereview.chromium.org/10543125
38     ui::CopyAreaToCanvas(root_window_->host()->GetAcceleratedWidget(),
39         root_window_->host()->GetBounds(), gfx::Point(), canvas);
40   }
41 
OnDeviceScaleFactorChanged(float device_scale_factor)42   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {}
43 
PrepareForLayerBoundsChange()44   virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE {
45     return base::Closure();
46   }
47 
48  private:
49   aura::RootWindow* root_window_;  // not owned
50 
51   DISALLOW_COPY_AND_ASSIGN(CopyHostContentLayerDelegate);
52 };
53 
BootSplashScreen(aura::RootWindow * root_window)54 BootSplashScreen::BootSplashScreen(aura::RootWindow* root_window)
55     : layer_delegate_(new CopyHostContentLayerDelegate(root_window)),
56       layer_(new ui::Layer(ui::LAYER_TEXTURED)) {
57   layer_->set_delegate(layer_delegate_.get());
58 
59   ui::Layer* root_layer = root_window->window()->layer();
60   layer_->SetBounds(gfx::Rect(root_layer->bounds().size()));
61   root_layer->Add(layer_.get());
62   root_layer->StackAtTop(layer_.get());
63 }
64 
~BootSplashScreen()65 BootSplashScreen::~BootSplashScreen() {
66 }
67 
StartHideAnimation(base::TimeDelta duration)68 void BootSplashScreen::StartHideAnimation(base::TimeDelta duration) {
69   ui::ScopedLayerAnimationSettings settings(layer_->GetAnimator());
70   settings.SetTransitionDuration(duration);
71   settings.SetPreemptionStrategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
72   layer_->SetOpacity(0.0f);
73 }
74 
75 }  // namespace internal
76 }  // namespace ash
77