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/weak_ptr.h"
13 #include "base/sequenced_task_runner_helpers.h"
14 #include "content/common/gpu/gpu_process_launch_causes.h"
15 #include "content/public/browser/browser_message_filter.h"
16 #include "ui/gfx/native_widget_types.h"
19 struct GPUCreateCommandBufferConfig;
26 class RenderWidgetHelper;
27 class RenderWidgetHostViewFrameSubscriber;
29 // A message filter for messages from the renderer to the GpuProcessHost(UIShim)
30 // in the browser. Such messages are typically destined for the GPU process,
31 // but need to be mediated by the browser.
32 class GpuMessageFilter : public BrowserMessageFilter {
34 GpuMessageFilter(int render_process_id,
35 RenderWidgetHelper* render_widget_helper);
37 // BrowserMessageFilter methods:
38 virtual bool OnMessageReceived(const IPC::Message& message,
39 bool* message_was_ok) OVERRIDE;
41 // Signals that the handle for a surface id was updated, and it may be time to
42 // unblock existing CreateViewCommandBuffer requests using that surface.
43 void SurfaceUpdated(int32 surface_id);
45 // This set of API is used to subscribe to frame presentation events.
46 // See RenderWidgetHostViewFrameSubscriber for more details.
47 void BeginFrameSubscription(
49 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber);
50 void EndFrameSubscription(int route_id);
53 friend class BrowserThread;
54 friend class base::DeleteHelper<GpuMessageFilter>;
55 struct CreateViewCommandBufferRequest;
56 struct FrameSubscription;
58 virtual ~GpuMessageFilter();
60 // Message handlers called on the browser IO thread:
61 void OnEstablishGpuChannel(CauseForGpuLaunch,
63 void OnCreateViewCommandBuffer(
65 const GPUCreateCommandBufferConfig& init_params,
67 // Helper callbacks for the message handlers.
68 void EstablishChannelCallback(IPC::Message* reply,
69 const IPC::ChannelHandle& channel,
70 const gpu::GPUInfo& gpu_info);
71 void CreateCommandBufferCallback(IPC::Message* reply, int32 route_id);
73 void BeginAllFrameSubscriptions();
74 void EndAllFrameSubscriptions();
75 void BeginFrameSubscriptionInternal(
76 linked_ptr<FrameSubscription> subscription);
77 void EndFrameSubscriptionInternal(
78 linked_ptr<FrameSubscription> subscription);
81 int render_process_id_;
84 scoped_refptr<RenderWidgetHelper> render_widget_helper_;
85 std::vector<linked_ptr<CreateViewCommandBufferRequest> > pending_requests_;
87 base::WeakPtrFactory<GpuMessageFilter> weak_ptr_factory_;
89 typedef std::vector<linked_ptr<FrameSubscription> > FrameSubscriptionList;
90 FrameSubscriptionList frame_subscription_list_;
92 DISALLOW_COPY_AND_ASSIGN(GpuMessageFilter);
95 } // namespace content
97 #endif // CONTENT_BROWSER_RENDERER_HOST_GPU_MESSAGE_FILTER_H_