summaryrefslogtreecommitdiffstats
path: root/content/renderer/gpu/compositor_thread.h
blob: aed3afd51249b1a02061e8d8d239d2f31b2640da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_RENDERER_GPU_COMPOSITOR_THREAD_H_
#define CONTENT_RENDERER_GPU_COMPOSITOR_THREAD_H_

#include <map>

#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "content/renderer/render_view_impl.h"
#include "ipc/ipc_channel_proxy.h"
#include "webkit/glue/webthread_impl.h"

namespace WebKit {
class WebInputEvent;
}

class InputEventFilter;

// The CompositorThread class manages the background thread for the compositor.
// The CompositorThread instance can be assumed to outlive the background
// thread it manages.
class CompositorThread {
 public:
  // |main_listener| refers to the central IPC message listener that lives on
  // the main thread, where all incoming IPC messages are first handled.
  explicit CompositorThread(IPC::Channel::Listener* main_listener);
  ~CompositorThread();

  // This MessageFilter should be added to allow input events to be redirected
  // to the compositor's thread.
  IPC::ChannelProxy::MessageFilter* GetMessageFilter() const;

  // Callable from the main thread only.
  void AddInputHandler(int routing_id,
                       int input_handler_id,
                       const base::WeakPtr<RenderViewImpl>& render_view_impl);

  webkit_glue::WebThreadImpl* GetWebThread() { return &thread_; }

 private:
  // Callback only from the compositor's thread.
  void RemoveInputHandler(int routing_id);

  // Called from the compositor's thread.
  void HandleInputEvent(int routing_id,
                        const WebKit::WebInputEvent* input_event);

  // Called from the compositor's thread.
  void AddInputHandlerOnCompositorThread(
      int routing_id,
      int input_handler_id,
      scoped_refptr<base::MessageLoopProxy> main_loop,
      const base::WeakPtr<RenderViewImpl>& render_view_impl);

  class InputHandlerWrapper;
  friend class InputHandlerWrapper;

  typedef std::map<int,  // routing_id
                   scoped_refptr<InputHandlerWrapper> > InputHandlerMap;
  InputHandlerMap input_handlers_;

  webkit_glue::WebThreadImpl thread_;
  scoped_refptr<InputEventFilter> filter_;
};

#endif  // CONTENT_RENDERER_GPU_COMPOSITOR_THREAD_H_