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

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

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

Powered by Google App Engine
This is Rietveld 408576698