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_BROWSER_RENDERER_HOST_GPU_MESSAGE_FILTER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_GPU_MESSAGE_FILTER_H_
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"
20 struct GPUCreateCommandBufferConfig;
27 class RenderWidgetHelper;
28 class RenderWidgetHostViewFrameSubscriber;
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 {
35 GpuMessageFilter(int render_process_id,
36 RenderWidgetHelper* render_widget_helper);
38 // BrowserMessageFilter methods:
39 virtual bool OnMessageReceived(const IPC::Message& message,
40 bool* message_was_ok) OVERRIDE;
42 // This set of API is used to subscribe to frame presentation events.
43 // See RenderWidgetHostViewFrameSubscriber for more details.
44 void BeginFrameSubscription(
46 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber);
47 void EndFrameSubscription(int route_id);
50 friend class BrowserThread;
51 friend class base::DeleteHelper<GpuMessageFilter>;
52 struct CreateViewCommandBufferRequest;
53 struct FrameSubscription;
55 virtual ~GpuMessageFilter();
57 // Message handlers called on the browser IO thread:
58 void OnEstablishGpuChannel(CauseForGpuLaunch,
60 void OnCreateViewCommandBuffer(
62 const GPUCreateCommandBufferConfig& init_params,
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,
72 void BeginAllFrameSubscriptions();
73 void EndAllFrameSubscriptions();
74 void BeginFrameSubscriptionInternal(
75 linked_ptr<FrameSubscription> subscription);
76 void EndFrameSubscriptionInternal(
77 linked_ptr<FrameSubscription> subscription);
80 int render_process_id_;
82 scoped_refptr<RenderWidgetHelper> render_widget_helper_;
84 base::WeakPtrFactory<GpuMessageFilter> weak_ptr_factory_;
86 typedef std::vector<linked_ptr<FrameSubscription> > FrameSubscriptionList;
87 FrameSubscriptionList frame_subscription_list_;
89 DISALLOW_COPY_AND_ASSIGN(GpuMessageFilter);
92 } // namespace content
94 #endif // CONTENT_BROWSER_RENDERER_HOST_GPU_MESSAGE_FILTER_H_