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/common/gpu/gpu_result_codes.h"
17 #include "content/public/browser/browser_message_filter.h"
18 #include "ui/gfx/native_widget_types.h"
21 struct GPUCreateCommandBufferConfig;
28 class RenderWidgetHelper;
29 class RenderWidgetHostViewFrameSubscriber;
31 // A message filter for messages from the renderer to the GpuProcessHost(UIShim)
32 // in the browser. Such messages are typically destined for the GPU process,
33 // but need to be mediated by the browser.
34 class GpuMessageFilter : public BrowserMessageFilter {
36 GpuMessageFilter(int render_process_id,
37 RenderWidgetHelper* render_widget_helper);
39 // BrowserMessageFilter methods:
40 virtual bool OnMessageReceived(const IPC::Message& message) 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,
70 CreateCommandBufferResult result);
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_