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

Side by Side Diff: blimp/client/core/contents/blimp_contents_impl.cc

Issue 2241623002: blimp: Move compositing, input and render widget feature to client/core. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments from #7 Created 4 years, 4 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 "blimp/client/core/contents/blimp_contents_impl.h" 5 #include "blimp/client/core/contents/blimp_contents_impl.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/supports_user_data.h" 8 #include "base/supports_user_data.h"
9 #include "blimp/client/core/compositor/compositor_deps_provider.h"
10 #include "blimp/client/core/render_widget/blimp_render_widget.h"
9 #include "blimp/client/public/contents/blimp_contents_observer.h" 11 #include "blimp/client/public/contents/blimp_contents_observer.h"
12 #include "cc/proto/compositor_message.pb.h"
10 13
11 #if defined(OS_ANDROID) 14 #if defined(OS_ANDROID)
12 #include "blimp/client/core/contents/android/blimp_contents_impl_android.h" 15 #include "blimp/client/core/contents/android/blimp_contents_impl_android.h"
13 #endif // OS_ANDROID 16 #endif // OS_ANDROID
14 17
15 namespace blimp { 18 namespace blimp {
16 namespace client { 19 namespace client {
17 20
18 namespace { 21 namespace {
19 22
23 const int kDummyTabId = 0;
24
20 #if defined(OS_ANDROID) 25 #if defined(OS_ANDROID)
21 const char kBlimpContentsImplAndroidKey[] = "blimp_contents_impl_android"; 26 const char kBlimpContentsImplAndroidKey[] = "blimp_contents_impl_android";
22 #endif // OS_ANDROID 27 #endif // OS_ANDROID
23 } 28 }
24 29
25 BlimpContentsImpl::BlimpContentsImpl(int id) 30 BlimpContentsImpl::BlimpContentsImpl(int id,
26 : navigation_controller_(this, nullptr), id_(id) {} 31 RenderWidgetFeature* render_widget_feature)
32 : id_(id),
33 render_widget_feature_(render_widget_feature),
34 visible_(false),
35 window_(gfx::kNullAcceleratedWidget),
36 active_widget_(nullptr),
37 navigation_controller_(this, nullptr) {
38 render_widget_feature_->SetDelegate(kDummyTabId, this);
39 }
27 40
28 BlimpContentsImpl::~BlimpContentsImpl() { 41 BlimpContentsImpl::~BlimpContentsImpl() {
42 // Drop any references to the |window_|
43 if (CompositorDepsProvider::current()->use_internal_display()) {
44 SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
45 }
46
29 FOR_EACH_OBSERVER(BlimpContentsObserver, observers_, BlimpContentsDying()); 47 FOR_EACH_OBSERVER(BlimpContentsObserver, observers_, BlimpContentsDying());
30 } 48 }
31 49
32 #if defined(OS_ANDROID) 50 #if defined(OS_ANDROID)
33 51
34 base::android::ScopedJavaLocalRef<jobject> 52 base::android::ScopedJavaLocalRef<jobject>
35 BlimpContentsImpl::GetJavaBlimpContentsImpl() { 53 BlimpContentsImpl::GetJavaBlimpContentsImpl() {
36 return GetBlimpContentsImplAndroid()->GetJavaObject(); 54 return GetBlimpContentsImplAndroid()->GetJavaObject();
37 } 55 }
38 56
(...skipping 24 matching lines...) Expand all
63 81
64 bool BlimpContentsImpl::HasObserver(BlimpContentsObserver* observer) { 82 bool BlimpContentsImpl::HasObserver(BlimpContentsObserver* observer) {
65 return observers_.HasObserver(observer); 83 return observers_.HasObserver(observer);
66 } 84 }
67 85
68 void BlimpContentsImpl::OnNavigationStateChanged() { 86 void BlimpContentsImpl::OnNavigationStateChanged() {
69 FOR_EACH_OBSERVER(BlimpContentsObserver, observers_, 87 FOR_EACH_OBSERVER(BlimpContentsObserver, observers_,
70 OnNavigationStateChanged()); 88 OnNavigationStateChanged());
71 } 89 }
72 90
91 void BlimpContentsImpl::SetVisible(bool visible) {
92 visible_ = visible;
93 if (active_widget_) {
94 active_widget_->SetVisible(visible);
95 }
96 }
97
98 void BlimpContentsImpl::SetAcceleratedWidget(gfx::AcceleratedWidget widget) {
99 DCHECK(CompositorDepsProvider::current()->use_internal_display());
100
101 // Drop any references to the current |window_| first.
102 if (active_widget_) {
103 active_widget_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
104 }
105
106 window_ = widget;
107
108 if (active_widget_) {
109 active_widget_->SetAcceleratedWidget(window_);
110 }
111 }
112
113 BlimpRenderWidget* BlimpContentsImpl::GetActiveWidget() const {
114 return active_widget_;
115 }
116
117 void BlimpContentsImpl::SendWebGestureEvent(
118 BlimpRenderWidget* render_widget,
119 const blink::WebGestureEvent& gesture_event) {
120 render_widget_feature_->SendWebGestureEvent(
121 kDummyTabId, render_widget->GetId(), gesture_event);
122 }
123
124 void BlimpContentsImpl::SendCompositorMessage(
125 BlimpRenderWidget* render_widget,
126 const cc::proto::CompositorMessage& message) {
127 render_widget_feature_->SendCompositorMessage(
128 kDummyTabId, render_widget->GetId(), message);
129 }
130
131 void BlimpContentsImpl::CompositorDidCompleteSwapBuffers() {
132 if (!did_complete_swap_buffers_.is_null())
133 did_complete_swap_buffers_.Run();
134 }
135
136 BlimpRenderWidget* BlimpContentsImpl::GetWidgetForId(int render_widget_id) {
137 RenderWidgetMap::const_iterator it = render_widgets_.find(render_widget_id);
138 if (it == render_widgets_.end()) {
139 return nullptr;
140 }
141
142 return it->second.get();
143 }
144
145 std::unique_ptr<BlimpRenderWidget> BlimpContentsImpl::CreateBlimpRenderWidget(
146 int32_t render_widget_id,
147 BlimpRenderWidgetDelegate* delegate) {
148 return base::MakeUnique<BlimpRenderWidget>(render_widget_id, delegate);
149 }
150
151 void BlimpContentsImpl::OnRenderWidgetCreated(int render_widget_id) {
152 CHECK(!GetWidgetForId(render_widget_id));
153
154 render_widgets_[render_widget_id] =
155 CreateBlimpRenderWidget(render_widget_id, this);
156 }
157
158 void BlimpContentsImpl::OnRenderWidgetInitialized(int render_widget_id) {
159 if (active_widget_ && active_widget_->GetId() == render_widget_id)
160 return;
161
162 if (active_widget_) {
163 VLOG(1) << "Hiding currently active compositor for render widget: "
164 << active_widget_->GetId();
165 active_widget_->SetVisible(false);
166 if (CompositorDepsProvider::current()->use_internal_display()) {
167 active_widget_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
168 }
169 }
170
171 active_widget_ = GetWidgetForId(render_widget_id);
172 CHECK(active_widget_);
173
174 active_widget_->SetVisible(visible_);
175 if (CompositorDepsProvider::current()->use_internal_display()) {
176 active_widget_->SetAcceleratedWidget(window_);
177 }
178 }
179
180 void BlimpContentsImpl::OnRenderWidgetDeleted(int render_widget_id) {
181 RenderWidgetMap::const_iterator it = render_widgets_.find(render_widget_id);
182 CHECK(it != render_widgets_.end());
183
184 // Reset the |active_widget_| if that is what we're destroying right now.
185 if (active_widget_ == it->second.get()) {
186 active_widget_ = nullptr;
187 }
188
189 render_widgets_.erase(it);
190 }
191
192 void BlimpContentsImpl::OnCompositorMessageReceived(
193 int render_widget_id,
194 std::unique_ptr<cc::proto::CompositorMessage> message) {
195 BlimpRenderWidget* render_widget = GetWidgetForId(render_widget_id);
196 CHECK(render_widget);
197
198 render_widget->OnCompositorMessageReceived(std::move(message));
199 }
200
73 } // namespace client 201 } // namespace client
74 } // namespace blimp 202 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698