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 "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 using base::android::JavaParamRef; |
| 14 |
13 namespace vr_shell { | 15 namespace vr_shell { |
14 | 16 |
15 VrCompositor::VrCompositor(ui::WindowAndroid* window, bool transparent) | 17 VrCompositor::VrCompositor(ui::WindowAndroid* window, bool transparent) |
16 : background_color_(SK_ColorWHITE), | 18 : background_color_(SK_ColorWHITE), |
17 transparent_(transparent) { | 19 transparent_(transparent) { |
18 compositor_.reset(content::Compositor::Create(this, window)); | 20 compositor_.reset(content::Compositor::Create(this, window)); |
19 compositor_->SetHasTransparentBackground(transparent); | 21 compositor_->SetHasTransparentBackground(transparent); |
20 } | 22 } |
21 | 23 |
22 VrCompositor::~VrCompositor() { | 24 VrCompositor::~VrCompositor() { |
23 if (layer_) { | 25 if (layer_) { |
24 layer_->SetBackgroundColor(background_color_); | 26 layer_->SetBackgroundColor(background_color_); |
25 if (layer_parent_) { | 27 if (layer_parent_) { |
26 layer_parent_->AddChild(layer_); | 28 layer_parent_->AddChild(layer_); |
27 } | 29 } |
28 } | 30 } |
29 } | 31 } |
30 | 32 |
31 void VrCompositor::UpdateLayerTreeHost() {} | 33 void VrCompositor::UpdateLayerTreeHost() {} |
32 | 34 |
33 void VrCompositor::OnSwapBuffersCompleted(int pending_swap_buffers) {} | 35 void VrCompositor::OnSwapBuffersCompleted(int pending_swap_buffers) {} |
34 | 36 |
35 void VrCompositor::SetLayer(content::WebContents* web_contents) { | 37 void VrCompositor::SetLayer(content::WebContents* web_contents) { |
36 assert(layer_ == nullptr); | 38 assert(layer_ == nullptr); |
37 ui::ViewAndroid* view_android = web_contents->GetNativeView(); | 39 ui::ViewAndroid* view_android = web_contents->GetNativeView(); |
| 40 |
38 // 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 |
39 // 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 |
40 // its previous parent on teardown. | 43 // its previous parent on teardown. |
41 layer_ = view_android->GetLayer(); | 44 layer_ = view_android->GetLayer(); |
42 | 45 |
43 // Remember the old background color to be restored later. | 46 // Remember the old background color to be restored later. |
44 background_color_ = layer_->background_color(); | 47 background_color_ = layer_->background_color(); |
45 if (transparent_) { | 48 if (transparent_) { |
46 layer_->SetBackgroundColor(SK_ColorTRANSPARENT); | 49 layer_->SetBackgroundColor(SK_ColorTRANSPARENT); |
47 } | 50 } |
48 layer_parent_ = layer_->parent(); | 51 layer_parent_ = layer_->parent(); |
49 compositor_->SetRootLayer(layer_); | 52 compositor_->SetRootLayer(layer_); |
50 } | 53 } |
51 | 54 |
52 void VrCompositor::SurfaceDestroyed() { | 55 void VrCompositor::SurfaceDestroyed() { |
53 compositor_->SetSurface(nullptr); | 56 compositor_->SetSurface(nullptr); |
54 } | 57 } |
55 | 58 |
56 void VrCompositor::SurfaceChanged( | 59 void VrCompositor::SetWindowBounds(int width, int height) { |
57 int width, | |
58 int height, | |
59 const base::android::JavaParamRef<jobject>& surface) { | |
60 DCHECK(surface); | |
61 compositor_->SetSurface(surface); | |
62 compositor_->SetWindowBounds(gfx::Size(width, height)); | 60 compositor_->SetWindowBounds(gfx::Size(width, height)); |
63 } | 61 } |
64 | 62 |
| 63 void VrCompositor::SurfaceChanged(const JavaParamRef<jobject>& surface) { |
| 64 DCHECK(surface); |
| 65 compositor_->SetSurface(surface); |
| 66 } |
| 67 |
65 } // namespace vr_shell | 68 } // namespace vr_shell |
OLD | NEW |