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