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