1 // Copyright (c) 2012 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.
5 #ifndef CONTENT_RENDERER_GPU_COMPOSITOR_THREAD_H_
6 #define CONTENT_RENDERER_GPU_COMPOSITOR_THREAD_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h"
12 #include "content/renderer/render_view_impl.h"
13 #include "ipc/ipc_channel_proxy.h"
14 #include "webkit/glue/webthread_impl.h"
20 class InputEventFilter
;
22 // The CompositorThread class manages the background thread for the compositor.
23 // The CompositorThread instance can be assumed to outlive the background
25 class CompositorThread
{
27 // |main_listener| refers to the central IPC message listener that lives on
28 // the main thread, where all incoming IPC messages are first handled.
29 explicit CompositorThread(IPC::Listener
* main_listener
);
32 // This MessageFilter should be added to allow input events to be redirected
33 // to the compositor's thread.
34 IPC::ChannelProxy::MessageFilter
* GetMessageFilter() const;
36 // Callable from the main thread only.
37 void AddInputHandler(int routing_id
,
39 const base::WeakPtr
<RenderViewImpl
>& render_view_impl
);
41 webkit_glue::WebThreadImpl
* GetWebThread() { return &thread_
; }
43 MessageLoop
* message_loop() { return thread_
.message_loop(); }
46 // Callback only from the compositor's thread.
47 void RemoveInputHandler(int routing_id
);
49 // Called from the compositor's thread.
50 void HandleInputEvent(int routing_id
,
51 const WebKit::WebInputEvent
* input_event
);
53 // Called from the compositor's thread.
54 void AddInputHandlerOnCompositorThread(
57 scoped_refptr
<base::MessageLoopProxy
> main_loop
,
58 const base::WeakPtr
<RenderViewImpl
>& render_view_impl
);
60 class InputHandlerWrapper
;
61 friend class InputHandlerWrapper
;
63 typedef std::map
<int, // routing_id
64 scoped_refptr
<InputHandlerWrapper
> > InputHandlerMap
;
65 InputHandlerMap input_handlers_
;
67 webkit_glue::WebThreadImpl thread_
;
68 scoped_refptr
<InputEventFilter
> filter_
;
71 #endif // CONTENT_RENDERER_GPU_COMPOSITOR_THREAD_H_