Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: chrome/browser/android/vr_shell/vr_compositor.cc

Issue 2657703002: Swap to foreground tab when following links that open in a new tab/window in VR Shell. (Closed)
Patch Set: Address comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "cc/layers/layer.h" 7 #include "cc/layers/layer.h"
8 #include "content/public/browser/android/compositor.h" 8 #include "content/public/browser/android/compositor.h"
9 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 #include "third_party/skia/include/core/SkColor.h" 10 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/android/window_android.h" 11 #include "ui/android/window_android.h"
12 12
13 namespace vr_shell { 13 namespace vr_shell {
14 14
15 VrCompositor::VrCompositor(ui::WindowAndroid* window, bool transparent) 15 VrCompositor::VrCompositor(ui::WindowAndroid* window, bool transparent)
16 : background_color_(SK_ColorWHITE), 16 : background_color_(SK_ColorWHITE),
17 transparent_(transparent) { 17 transparent_(transparent) {
18 compositor_.reset(content::Compositor::Create(this, window)); 18 compositor_.reset(content::Compositor::Create(this, window));
19 compositor_->SetHasTransparentBackground(transparent); 19 compositor_->SetHasTransparentBackground(transparent);
20 } 20 }
21 21
22 VrCompositor::~VrCompositor() { 22 VrCompositor::~VrCompositor() {
23 if (layer_) { 23 if (layer_)
24 layer_->SetBackgroundColor(background_color_); 24 RestoreLayer();
25 if (layer_parent_) {
26 layer_parent_->AddChild(layer_);
27 }
28 }
29 } 25 }
30 26
31 void VrCompositor::UpdateLayerTreeHost() {} 27 void VrCompositor::UpdateLayerTreeHost() {}
32 28
33 void VrCompositor::OnSwapBuffersCompleted(int pending_swap_buffers) {} 29 void VrCompositor::OnSwapBuffersCompleted(int pending_swap_buffers) {}
34 30
35 void VrCompositor::SetLayer(content::WebContents* web_contents) { 31 void VrCompositor::SetLayer(content::WebContents* web_contents) {
36 assert(layer_ == nullptr); 32 if (layer_)
33 RestoreLayer();
37 ui::ViewAndroid* view_android = web_contents->GetNativeView(); 34 ui::ViewAndroid* view_android = web_contents->GetNativeView();
38 35
39 // 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
40 // 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
41 // its previous parent on teardown. 38 // its previous parent on teardown.
42 layer_ = view_android->GetLayer(); 39 layer_ = view_android->GetLayer();
43 40
44 // Remember the old background color to be restored later. 41 // Remember the old background color to be restored later.
45 background_color_ = layer_->background_color(); 42 background_color_ = layer_->background_color();
46 if (transparent_) { 43 if (transparent_) {
47 layer_->SetBackgroundColor(SK_ColorTRANSPARENT); 44 layer_->SetBackgroundColor(SK_ColorTRANSPARENT);
48 } 45 }
49 layer_parent_ = layer_->parent(); 46 layer_parent_ = layer_->parent();
50 compositor_->SetRootLayer(layer_); 47 compositor_->SetRootLayer(layer_);
51 } 48 }
52 49
50 void VrCompositor::RestoreLayer() {
51 layer_->SetBackgroundColor(background_color_);
52 if (layer_parent_) {
53 layer_parent_->AddChild(layer_);
54 }
55 }
56
53 void VrCompositor::SurfaceDestroyed() { 57 void VrCompositor::SurfaceDestroyed() {
54 compositor_->SetSurface(nullptr); 58 compositor_->SetSurface(nullptr);
55 } 59 }
56 60
57 void VrCompositor::SetWindowBounds(gfx::Size size) { 61 void VrCompositor::SetWindowBounds(gfx::Size size) {
58 bounds_ = size; 62 bounds_ = size;
59 compositor_->SetWindowBounds(bounds_); 63 compositor_->SetWindowBounds(bounds_);
60 } 64 }
61 65
62 void VrCompositor::SurfaceChanged(jobject surface) { 66 void VrCompositor::SurfaceChanged(jobject surface) {
63 DCHECK(surface); 67 DCHECK(surface);
64 compositor_->SetSurface(surface); 68 compositor_->SetSurface(surface);
65 } 69 }
66 70
67 } // namespace vr_shell 71 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_compositor.h ('k') | chrome/browser/android/vr_shell/vr_input_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698