OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/android/vr_shell/vr_compositor.h" | 5 #include "chrome/browser/android/vr_shell/vr_compositor.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
10 #include "cc/layers/solid_color_layer.h" | 10 #include "cc/layers/solid_color_layer.h" |
11 #include "content/public/browser/android/compositor.h" | 11 #include "content/public/browser/android/compositor.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
14 #include "ui/android/window_android.h" | 14 #include "ui/android/window_android.h" |
15 | 15 |
16 namespace vr_shell { | 16 namespace vr_shell { |
17 | 17 |
18 VrCompositor::VrCompositor(ui::WindowAndroid* window, bool transparent) | 18 VrCompositor::VrCompositor(ui::WindowAndroid* window) { |
19 : background_color_(SK_ColorWHITE), transparent_(transparent) { | |
20 compositor_.reset(content::Compositor::Create(this, window)); | 19 compositor_.reset(content::Compositor::Create(this, window)); |
21 compositor_->SetHasTransparentBackground(transparent); | |
22 } | 20 } |
23 | 21 |
24 VrCompositor::~VrCompositor() { | 22 VrCompositor::~VrCompositor() { |
25 RestoreLayer(); | 23 RestoreLayer(); |
26 } | 24 } |
27 | 25 |
28 void VrCompositor::SetLayer(content::WebContents* web_contents) { | 26 void VrCompositor::SetLayer(content::WebContents* web_contents) { |
29 RestoreLayer(); | 27 RestoreLayer(); |
30 if (!web_contents) { | 28 if (!web_contents) { |
31 scoped_refptr<cc::SolidColorLayer> layer = cc::SolidColorLayer::Create(); | 29 scoped_refptr<cc::SolidColorLayer> layer = cc::SolidColorLayer::Create(); |
32 layer->SetBackgroundColor(SK_ColorTRANSPARENT); | 30 layer->SetBackgroundColor(SK_ColorTRANSPARENT); |
33 compositor_->SetRootLayer(std::move(layer)); | 31 compositor_->SetRootLayer(std::move(layer)); |
34 return; | 32 return; |
35 } | 33 } |
36 ui::ViewAndroid* view_android = web_contents->GetNativeView(); | 34 ui::ViewAndroid* view_android = web_contents->GetNativeView(); |
37 | 35 |
38 // When we pass the layer for the ContentViewCore to the compositor it may be | 36 // When we pass the layer for the ContentViewCore to the compositor it may be |
39 // removing it from its previous parent, so we remember that and restore it to | 37 // removing it from its previous parent, so we remember that and restore it to |
40 // its previous parent on teardown. | 38 // its previous parent on teardown. |
41 layer_ = view_android->GetLayer(); | 39 layer_ = view_android->GetLayer(); |
42 | |
43 // Remember the old background color to be restored later. | |
44 background_color_ = layer_->background_color(); | |
45 if (transparent_) { | |
46 layer_->SetBackgroundColor(SK_ColorTRANSPARENT); | |
47 } | |
48 layer_parent_ = layer_->parent(); | 40 layer_parent_ = layer_->parent(); |
49 compositor_->SetRootLayer(layer_); | 41 compositor_->SetRootLayer(layer_); |
50 } | 42 } |
51 | 43 |
52 void VrCompositor::RestoreLayer() { | 44 void VrCompositor::RestoreLayer() { |
53 if (!layer_) | 45 if (layer_ && layer_parent_) |
54 return; | |
55 layer_->SetBackgroundColor(background_color_); | |
56 if (layer_parent_) { | |
57 layer_parent_->AddChild(layer_); | 46 layer_parent_->AddChild(layer_); |
58 } | |
59 layer_ = nullptr; | 47 layer_ = nullptr; |
| 48 layer_parent_ = nullptr; |
60 } | 49 } |
61 | 50 |
62 void VrCompositor::SurfaceDestroyed() { | 51 void VrCompositor::SurfaceDestroyed() { |
63 compositor_->SetSurface(nullptr); | 52 compositor_->SetSurface(nullptr); |
64 } | 53 } |
65 | 54 |
66 void VrCompositor::SetWindowBounds(gfx::Size size) { | 55 void VrCompositor::SetWindowBounds(gfx::Size size) { |
67 compositor_->SetWindowBounds(size); | 56 compositor_->SetWindowBounds(size); |
68 } | 57 } |
69 | 58 |
70 void VrCompositor::SurfaceChanged(jobject surface) { | 59 void VrCompositor::SurfaceChanged(jobject surface) { |
71 compositor_->SetSurface(surface); | 60 compositor_->SetSurface(surface); |
72 } | 61 } |
73 | 62 |
74 } // namespace vr_shell | 63 } // namespace vr_shell |
OLD | NEW |