| 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> |
| 8 |
| 7 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
| 10 #include "cc/layers/solid_color_layer.h" |
| 8 #include "content/public/browser/android/compositor.h" | 11 #include "content/public/browser/android/compositor.h" |
| 9 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 10 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
| 11 #include "ui/android/window_android.h" | 14 #include "ui/android/window_android.h" |
| 12 | 15 |
| 13 namespace vr_shell { | 16 namespace vr_shell { |
| 14 | 17 |
| 15 VrCompositor::VrCompositor(ui::WindowAndroid* window, bool transparent) | 18 VrCompositor::VrCompositor(ui::WindowAndroid* window, bool transparent) |
| 16 : background_color_(SK_ColorWHITE), | 19 : background_color_(SK_ColorWHITE), |
| 17 transparent_(transparent) { | 20 transparent_(transparent) { |
| 18 compositor_.reset(content::Compositor::Create(this, window)); | 21 compositor_.reset(content::Compositor::Create(this, window)); |
| 19 compositor_->SetHasTransparentBackground(transparent); | 22 compositor_->SetHasTransparentBackground(transparent); |
| 20 } | 23 } |
| 21 | 24 |
| 22 VrCompositor::~VrCompositor() { | 25 VrCompositor::~VrCompositor() { |
| 23 if (layer_) | 26 RestoreLayer(); |
| 24 RestoreLayer(); | |
| 25 } | 27 } |
| 26 | 28 |
| 27 void VrCompositor::UpdateLayerTreeHost() {} | 29 void VrCompositor::UpdateLayerTreeHost() {} |
| 28 | 30 |
| 29 void VrCompositor::OnSwapBuffersCompleted(int pending_swap_buffers) {} | 31 void VrCompositor::OnSwapBuffersCompleted(int pending_swap_buffers) {} |
| 30 | 32 |
| 31 void VrCompositor::SetLayer(content::WebContents* web_contents) { | 33 void VrCompositor::SetLayer(content::WebContents* web_contents) { |
| 32 if (layer_) | 34 RestoreLayer(); |
| 33 RestoreLayer(); | 35 if (!web_contents) { |
| 36 scoped_refptr<cc::SolidColorLayer> layer = cc::SolidColorLayer::Create(); |
| 37 layer->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 38 compositor_->SetRootLayer(std::move(layer)); |
| 39 return; |
| 40 } |
| 34 ui::ViewAndroid* view_android = web_contents->GetNativeView(); | 41 ui::ViewAndroid* view_android = web_contents->GetNativeView(); |
| 35 | 42 |
| 36 // When we pass the layer for the ContentViewCore to the compositor it may be | 43 // When we pass the layer for the ContentViewCore to the compositor it may be |
| 37 // removing it from its previous parent, so we remember that and restore it to | 44 // removing it from its previous parent, so we remember that and restore it to |
| 38 // its previous parent on teardown. | 45 // its previous parent on teardown. |
| 39 layer_ = view_android->GetLayer(); | 46 layer_ = view_android->GetLayer(); |
| 40 | 47 |
| 41 // Remember the old background color to be restored later. | 48 // Remember the old background color to be restored later. |
| 42 background_color_ = layer_->background_color(); | 49 background_color_ = layer_->background_color(); |
| 43 if (transparent_) { | 50 if (transparent_) { |
| 44 layer_->SetBackgroundColor(SK_ColorTRANSPARENT); | 51 layer_->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 45 } | 52 } |
| 46 layer_parent_ = layer_->parent(); | 53 layer_parent_ = layer_->parent(); |
| 47 compositor_->SetRootLayer(layer_); | 54 compositor_->SetRootLayer(layer_); |
| 48 } | 55 } |
| 49 | 56 |
| 50 void VrCompositor::RestoreLayer() { | 57 void VrCompositor::RestoreLayer() { |
| 58 if (!layer_) |
| 59 return; |
| 51 layer_->SetBackgroundColor(background_color_); | 60 layer_->SetBackgroundColor(background_color_); |
| 52 if (layer_parent_) { | 61 if (layer_parent_) { |
| 53 layer_parent_->AddChild(layer_); | 62 layer_parent_->AddChild(layer_); |
| 54 } | 63 } |
| 64 layer_ = nullptr; |
| 55 } | 65 } |
| 56 | 66 |
| 57 void VrCompositor::SurfaceDestroyed() { | 67 void VrCompositor::SurfaceDestroyed() { |
| 58 compositor_->SetSurface(nullptr); | 68 compositor_->SetSurface(nullptr); |
| 59 } | 69 } |
| 60 | 70 |
| 61 void VrCompositor::SetWindowBounds(gfx::Size size) { | 71 void VrCompositor::SetWindowBounds(gfx::Size size) { |
| 62 compositor_->SetWindowBounds(size); | 72 compositor_->SetWindowBounds(size); |
| 63 } | 73 } |
| 64 | 74 |
| 65 void VrCompositor::SurfaceChanged(jobject surface) { | 75 void VrCompositor::SurfaceChanged(jobject surface) { |
| 66 DCHECK(surface); | |
| 67 compositor_->SetSurface(surface); | 76 compositor_->SetSurface(surface); |
| 68 } | 77 } |
| 69 | 78 |
| 70 } // namespace vr_shell | 79 } // namespace vr_shell |
| OLD | NEW |