Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / gpu_message_filter.h
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.
4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_GPU_MESSAGE_FILTER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_GPU_MESSAGE_FILTER_H_
7
8 #include <vector>
9
10 #include "base/memory/linked_ptr.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/sequenced_task_runner_helpers.h"
15 #include "content/common/gpu/gpu_process_launch_causes.h"
16 #include "content/public/browser/browser_message_filter.h"
17 #include "ui/gfx/native_widget_types.h"
18
19 class GpuProcessHost;
20 struct GPUCreateCommandBufferConfig;
21
22 namespace gpu {
23 struct GPUInfo;
24 }
25
26 namespace content {
27 class RenderWidgetHelper;
28 class RenderWidgetHostViewFrameSubscriber;
29
30 // A message filter for messages from the renderer to the GpuProcessHost(UIShim)
31 // in the browser. Such messages are typically destined for the GPU process,
32 // but need to be mediated by the browser.
33 class GpuMessageFilter : public BrowserMessageFilter {
34  public:
35   GpuMessageFilter(int render_process_id,
36                    RenderWidgetHelper* render_widget_helper);
37
38   // BrowserMessageFilter methods:
39   virtual bool OnMessageReceived(const IPC::Message& message,
40                                  bool* message_was_ok) OVERRIDE;
41
42   // This set of API is used to subscribe to frame presentation events.
43   // See RenderWidgetHostViewFrameSubscriber for more details.
44   void BeginFrameSubscription(
45       int route_id,
46       scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber);
47   void EndFrameSubscription(int route_id);
48
49  private:
50   friend class BrowserThread;
51   friend class base::DeleteHelper<GpuMessageFilter>;
52   struct CreateViewCommandBufferRequest;
53   struct FrameSubscription;
54
55   virtual ~GpuMessageFilter();
56
57   // Message handlers called on the browser IO thread:
58   void OnEstablishGpuChannel(CauseForGpuLaunch,
59                              IPC::Message* reply);
60   void OnCreateViewCommandBuffer(
61       int32 surface_id,
62       const GPUCreateCommandBufferConfig& init_params,
63       int32 route_id,
64       IPC::Message* reply);
65   // Helper callbacks for the message handlers.
66   void EstablishChannelCallback(scoped_ptr<IPC::Message> reply,
67                                 const IPC::ChannelHandle& channel,
68                                 const gpu::GPUInfo& gpu_info);
69   void CreateCommandBufferCallback(scoped_ptr<IPC::Message> reply,
70                                    bool succeeded);
71
72   void BeginAllFrameSubscriptions();
73   void EndAllFrameSubscriptions();
74   void BeginFrameSubscriptionInternal(
75       linked_ptr<FrameSubscription> subscription);
76   void EndFrameSubscriptionInternal(
77       linked_ptr<FrameSubscription> subscription);
78
79   int gpu_process_id_;
80   int render_process_id_;
81
82   scoped_refptr<RenderWidgetHelper> render_widget_helper_;
83
84   base::WeakPtrFactory<GpuMessageFilter> weak_ptr_factory_;
85
86   typedef std::vector<linked_ptr<FrameSubscription> > FrameSubscriptionList;
87   FrameSubscriptionList frame_subscription_list_;
88
89   DISALLOW_COPY_AND_ASSIGN(GpuMessageFilter);
90 };
91
92 }  // namespace content
93
94 #endif  // CONTENT_BROWSER_RENDERER_HOST_GPU_MESSAGE_FILTER_H_