summaryrefslogtreecommitdiffstats
path: root/content/common/gpu/gpu_channel_manager.h
blob: 683c9cd13d33a4fb61883fa180756070dbe13b6a (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (c) 2011 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_COMMON_GPU_GPU_CHANNEL_MANAGER_H_
#define CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_
#pragma once

#include "base/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop_proxy.h"
#include "build/build_config.h"
#include "ipc/ipc_channel.h"
#include "ipc/ipc_message.h"
#include "ui/gfx/native_widget_types.h"

namespace base {
class WaitableEvent;
}

namespace IPC {
struct ChannelHandle;
}

class GpuChannel;
class GpuWatchdog;
struct GPUCreateCommandBufferConfig;

// A GpuChannelManager is a thread responsible for issuing rendering commands
// managing the lifetimes of GPU channels and forwarding IPC requests from the
// browser process to them based on the corresponding renderer ID.
//
// A GpuChannelManager can also be hosted in the browser process in single
// process or in-process GPU modes. In this case there is no corresponding
// GpuChildThread and this is the reason the GpuChildThread is referenced via
// a pointer to IPC::Message::Sender, which can be implemented by other hosts
// to send IPC messages to the browser process IO thread on the
// GpuChannelManager's behalf.
class GpuChannelManager : public IPC::Channel::Listener,
                          public IPC::Message::Sender {
 public:
  GpuChannelManager(IPC::Message::Sender* browser_channel,
                    GpuWatchdog* watchdog,
                    base::MessageLoopProxy* io_message_loop,
                    base::WaitableEvent* shutdown_event);
  virtual ~GpuChannelManager();

  // Remove the channel for a particular renderer.
  void RemoveChannel(int renderer_id);

  // Listener overrides.
  virtual bool OnMessageReceived(const IPC::Message& msg);

  // Sender overrides.
  virtual bool Send(IPC::Message* msg);

  void LoseAllContexts();

  ScopedRunnableMethodFactory<GpuChannelManager> method_factory_;

 private:
  // Message handlers.
  void OnEstablishChannel(int renderer_id);
  void OnCloseChannel(const IPC::ChannelHandle& channel_handle);
  void OnVisibilityChanged(
      int32 render_view_id, int32 renderer_id, bool visible);
  void OnCreateViewCommandBuffer(
      gfx::PluginWindowHandle window,
      int32 render_view_id,
      int32 renderer_id,
      const GPUCreateCommandBufferConfig& init_params);
  void OnResizeViewACK(int32 renderer_id, int32 command_buffer_route_id);

#if defined(TOUCH_UI)
  void OnAcceleratedSurfaceSetIOSurfaceACK(
      int renderer_id, int32 route_id, uint64 surface_id);
  void OnAcceleratedSurfaceReleaseACK(
      int renderer_id, int32 route_id, uint64 surface_id);
#endif

#if defined(OS_MACOSX) || defined(TOUCH_UI)
  void OnAcceleratedSurfaceBuffersSwappedACK(
      int renderer_id, int32 route_id, uint64 swap_buffers_count);
#endif

#if defined(OS_MACOSX)
  void OnDestroyCommandBuffer(int renderer_id, int32 renderer_view_id);
#endif

  void OnLoseAllContexts();

  scoped_refptr<base::MessageLoopProxy> io_message_loop_;
  base::WaitableEvent* shutdown_event_;

  // Either an IPC channel to the browser or, if the GpuChannelManager is
  // running in the browser process, a Sender implementation that will post
  // IPC messages to the UI thread.
  IPC::Message::Sender* browser_channel_;

  // These objects manage channels to individual renderer processes there is
  // one channel for each renderer process that has connected to this GPU
  // process.
  typedef base::hash_map<int, scoped_refptr<GpuChannel> > GpuChannelMap;
  GpuChannelMap gpu_channels_;
  GpuWatchdog* watchdog_;

  DISALLOW_COPY_AND_ASSIGN(GpuChannelManager);
};

#endif  // CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_