| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "blimp/client/feature/compositor/blimp_compositor_manager.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" | |
| 9 #include "cc/proto/compositor_message.pb.h" | |
| 10 | |
| 11 namespace blimp { | |
| 12 namespace client { | |
| 13 | |
| 14 namespace { | |
| 15 const int kDummyTabId = 0; | |
| 16 } // namespace | |
| 17 | |
| 18 BlimpCompositorManager::BlimpCompositorManager( | |
| 19 RenderWidgetFeature* render_widget_feature, | |
| 20 BlimpCompositorDependencies* compositor_dependencies) | |
| 21 : render_widget_feature_(render_widget_feature), | |
| 22 visible_(false), | |
| 23 layer_(cc::Layer::Create()), | |
| 24 active_compositor_(nullptr), | |
| 25 compositor_dependencies_(compositor_dependencies) { | |
| 26 DCHECK(render_widget_feature_); | |
| 27 DCHECK(compositor_dependencies_); | |
| 28 | |
| 29 render_widget_feature_->SetDelegate(kDummyTabId, this); | |
| 30 } | |
| 31 | |
| 32 BlimpCompositorManager::~BlimpCompositorManager() { | |
| 33 render_widget_feature_->RemoveDelegate(kDummyTabId); | |
| 34 } | |
| 35 | |
| 36 void BlimpCompositorManager::SetVisible(bool visible) { | |
| 37 visible_ = visible; | |
| 38 if (active_compositor_) | |
| 39 active_compositor_->SetVisible(visible_); | |
| 40 } | |
| 41 | |
| 42 bool BlimpCompositorManager::OnTouchEvent(const ui::MotionEvent& motion_event) { | |
| 43 if (active_compositor_) | |
| 44 return active_compositor_->OnTouchEvent(motion_event); | |
| 45 return false; | |
| 46 } | |
| 47 | |
| 48 std::unique_ptr<BlimpCompositor> BlimpCompositorManager::CreateBlimpCompositor( | |
| 49 int render_widget_id, | |
| 50 BlimpCompositorDependencies* compositor_dependencies, | |
| 51 BlimpCompositorClient* client) { | |
| 52 return base::MakeUnique<BlimpCompositor>(render_widget_id, | |
| 53 compositor_dependencies, client); | |
| 54 } | |
| 55 | |
| 56 void BlimpCompositorManager::OnRenderWidgetCreated(int render_widget_id) { | |
| 57 CHECK(!GetCompositor(render_widget_id)); | |
| 58 | |
| 59 compositors_[render_widget_id] = | |
| 60 CreateBlimpCompositor(render_widget_id, compositor_dependencies_, this); | |
| 61 } | |
| 62 | |
| 63 void BlimpCompositorManager::OnRenderWidgetInitialized(int render_widget_id) { | |
| 64 if (active_compositor_ && | |
| 65 active_compositor_->render_widget_id() == render_widget_id) | |
| 66 return; | |
| 67 | |
| 68 // Detach the content layer from the old compositor. | |
| 69 layer_->RemoveAllChildren(); | |
| 70 | |
| 71 if (active_compositor_) { | |
| 72 VLOG(1) << "Hiding currently active compositor for render widget: " | |
| 73 << active_compositor_->render_widget_id(); | |
| 74 active_compositor_->SetVisible(false); | |
| 75 } | |
| 76 | |
| 77 active_compositor_ = GetCompositor(render_widget_id); | |
| 78 CHECK(active_compositor_); | |
| 79 | |
| 80 active_compositor_->SetVisible(visible_); | |
| 81 layer_->AddChild(active_compositor_->layer()); | |
| 82 } | |
| 83 | |
| 84 void BlimpCompositorManager::OnRenderWidgetDeleted(int render_widget_id) { | |
| 85 CompositorMap::const_iterator it = compositors_.find(render_widget_id); | |
| 86 CHECK(it != compositors_.end()); | |
| 87 | |
| 88 // Reset the |active_compositor_| if that is what we're destroying right now. | |
| 89 if (active_compositor_ == it->second.get()) { | |
| 90 layer_->RemoveAllChildren(); | |
| 91 active_compositor_ = nullptr; | |
| 92 } | |
| 93 | |
| 94 compositors_.erase(it); | |
| 95 } | |
| 96 | |
| 97 void BlimpCompositorManager::OnCompositorMessageReceived( | |
| 98 int render_widget_id, | |
| 99 std::unique_ptr<cc::proto::CompositorMessage> message) { | |
| 100 BlimpCompositor* compositor = GetCompositor(render_widget_id); | |
| 101 CHECK(compositor); | |
| 102 | |
| 103 compositor->OnCompositorMessageReceived(std::move(message)); | |
| 104 } | |
| 105 | |
| 106 void BlimpCompositorManager::SendWebGestureEvent( | |
| 107 int render_widget_id, | |
| 108 const blink::WebGestureEvent& gesture_event) { | |
| 109 render_widget_feature_->SendWebGestureEvent(kDummyTabId, | |
| 110 render_widget_id, | |
| 111 gesture_event); | |
| 112 } | |
| 113 | |
| 114 void BlimpCompositorManager::SendCompositorMessage( | |
| 115 int render_widget_id, | |
| 116 const cc::proto::CompositorMessage& message) { | |
| 117 render_widget_feature_->SendCompositorMessage(kDummyTabId, | |
| 118 render_widget_id, | |
| 119 message); | |
| 120 } | |
| 121 | |
| 122 BlimpCompositor* BlimpCompositorManager::GetCompositor(int render_widget_id) { | |
| 123 CompositorMap::const_iterator it = compositors_.find(render_widget_id); | |
| 124 if (it == compositors_.end()) | |
| 125 return nullptr; | |
| 126 return it->second.get(); | |
| 127 } | |
| 128 | |
| 129 } // namespace client | |
| 130 } // namespace blimp | |
| OLD | NEW |