OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 "content/renderer/gpu/compositor_thread.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "content/renderer/gpu/input_event_filter.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorClient.h
" |
| 11 |
| 12 using WebKit::WebCompositor; |
| 13 using WebKit::WebInputEvent; |
| 14 |
| 15 //------------------------------------------------------------------------------ |
| 16 |
| 17 class CompositorThread::CompositorWrapper : public WebKit::WebCompositorClient { |
| 18 public: |
| 19 CompositorWrapper(CompositorThread* compositor_thread, |
| 20 int routing_id, |
| 21 WebKit::WebCompositor* compositor) |
| 22 : compositor_thread_(compositor_thread), |
| 23 routing_id_(routing_id), |
| 24 compositor_(compositor) { |
| 25 compositor_->setClient(this); |
| 26 } |
| 27 |
| 28 virtual ~CompositorWrapper() { |
| 29 compositor_->setClient(NULL); |
| 30 } |
| 31 |
| 32 int routing_id() const { return routing_id_; } |
| 33 WebKit::WebCompositor* compositor() const { return compositor_; } |
| 34 |
| 35 // WebCompositorClient methods: |
| 36 |
| 37 virtual void willShutdown() { |
| 38 compositor_thread_->RemoveCompositor(routing_id_); |
| 39 } |
| 40 |
| 41 virtual void didHandleInputEvent() { |
| 42 compositor_thread_->filter_->DidHandleInputEvent(); |
| 43 } |
| 44 |
| 45 virtual void didNotHandleInputEvent(bool send_to_widget) { |
| 46 compositor_thread_->filter_->DidNotHandleInputEvent(send_to_widget); |
| 47 } |
| 48 |
| 49 private: |
| 50 CompositorThread* compositor_thread_; |
| 51 int routing_id_; |
| 52 WebKit::WebCompositor* compositor_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(CompositorWrapper); |
| 55 }; |
| 56 |
| 57 //------------------------------------------------------------------------------ |
| 58 |
| 59 CompositorThread::CompositorThread(IPC::Channel::Listener* main_listener) |
| 60 : thread_("Compositor") { |
| 61 filter_ = |
| 62 new InputEventFilter(main_listener, |
| 63 thread_.message_loop()->message_loop_proxy(), |
| 64 base::Bind(&CompositorThread::HandleInputEvent, |
| 65 base::Unretained(this))); |
| 66 WebCompositor::setThread(&thread_); |
| 67 } |
| 68 |
| 69 CompositorThread::~CompositorThread() { |
| 70 } |
| 71 |
| 72 IPC::ChannelProxy::MessageFilter* CompositorThread::GetMessageFilter() const { |
| 73 return filter_; |
| 74 } |
| 75 |
| 76 void CompositorThread::AddCompositor(int routing_id, int compositor_id) { |
| 77 if (thread_.message_loop() != MessageLoop::current()) { |
| 78 thread_.message_loop()->PostTask( |
| 79 FROM_HERE, |
| 80 base::Bind(&CompositorThread::AddCompositor, base::Unretained(this), |
| 81 routing_id, compositor_id)); |
| 82 return; |
| 83 } |
| 84 |
| 85 WebCompositor* compositor = WebCompositor::fromIdentifier(compositor_id); |
| 86 if (!compositor) |
| 87 return; |
| 88 |
| 89 filter_->AddRoute(routing_id); |
| 90 compositors_[routing_id] = |
| 91 make_linked_ptr(new CompositorWrapper(this, routing_id, compositor)); |
| 92 } |
| 93 |
| 94 void CompositorThread::RemoveCompositor(int routing_id) { |
| 95 DCHECK(thread_.message_loop() == MessageLoop::current()); |
| 96 |
| 97 filter_->RemoveRoute(routing_id); |
| 98 compositors_.erase(routing_id); |
| 99 } |
| 100 |
| 101 void CompositorThread::HandleInputEvent( |
| 102 int routing_id, |
| 103 const WebInputEvent* input_event) { |
| 104 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); |
| 105 |
| 106 CompositorMap::iterator it = compositors_.find(routing_id); |
| 107 if (it == compositors_.end()) { |
| 108 // Oops, we no longer have an interested compositor. |
| 109 filter_->DidNotHandleInputEvent(true); |
| 110 return; |
| 111 } |
| 112 |
| 113 it->second->compositor()->handleInputEvent(*input_event); |
| 114 } |
OLD | NEW |