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.
5 #include "ash/wm/boot_splash_screen_chromeos.h"
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/paint_recorder.h"
14 #include "ui/compositor/scoped_layer_animation_settings.h"
15 #include "ui/gfx/canvas.h"
19 // ui::LayerDelegate that copies the aura host window's content to a ui::Layer.
20 class BootSplashScreen::CopyHostContentLayerDelegate
21 : public ui::LayerDelegate
{
23 explicit CopyHostContentLayerDelegate(aura::WindowTreeHost
* host
)
27 ~CopyHostContentLayerDelegate() override
{}
29 // ui::LayerDelegate overrides:
30 void OnPaintLayer(const ui::PaintContext
& context
) 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
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
39 ui::PaintRecorder
recorder(context
);
40 ui::CopyAreaToCanvas(host_
->GetAcceleratedWidget(), host_
->GetBounds(),
41 gfx::Point(), recorder
.canvas());
43 // TODO(spang): Figure out what to do here.
48 void OnDelegatedFrameDamage(const gfx::Rect
& damage_rect_in_dip
) override
{}
50 void OnDeviceScaleFactorChanged(float device_scale_factor
) override
{}
52 base::Closure
PrepareForLayerBoundsChange() override
{
53 return base::Closure();
57 aura::WindowTreeHost
* host_
; // not owned
59 DISALLOW_COPY_AND_ASSIGN(CopyHostContentLayerDelegate
);
62 BootSplashScreen::BootSplashScreen(aura::WindowTreeHost
* host
)
63 : layer_delegate_(new CopyHostContentLayerDelegate(host
)),
64 layer_(new ui::Layer(ui::LAYER_TEXTURED
)) {
65 layer_
->set_delegate(layer_delegate_
.get());
67 ui::Layer
* root_layer
= host
->window()->layer();
68 layer_
->SetBounds(gfx::Rect(host
->window()->bounds().size()));
69 root_layer
->Add(layer_
.get());
70 root_layer
->StackAtTop(layer_
.get());
73 BootSplashScreen::~BootSplashScreen() {
76 void BootSplashScreen::StartHideAnimation(base::TimeDelta duration
) {
77 ui::ScopedLayerAnimationSettings
settings(layer_
->GetAnimator());
78 settings
.SetTransitionDuration(duration
);
79 settings
.SetPreemptionStrategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS
);
80 layer_
->SetOpacity(0.0f
);