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 // Signals that the handle for a surface id was updated, and it may be time to 43 // unblock existing CreateViewCommandBuffer requests using that surface. 44 void SurfaceUpdated(int32 surface_id); 45 46 // This set of API is used to subscribe to frame presentation events. 47 // See RenderWidgetHostViewFrameSubscriber for more details. 48 void BeginFrameSubscription( 49 int route_id, 50 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber); 51 void EndFrameSubscription(int route_id); 52 53 private: 54 friend class BrowserThread; 55 friend class base::DeleteHelper<GpuMessageFilter>; 56 struct CreateViewCommandBufferRequest; 57 struct FrameSubscription; 58 59 virtual ~GpuMessageFilter(); 60 61 // Message handlers called on the browser IO thread: 62 void OnEstablishGpuChannel(CauseForGpuLaunch, 63 IPC::Message* reply); 64 void OnCreateViewCommandBuffer( 65 int32 surface_id, 66 const GPUCreateCommandBufferConfig& init_params, 67 IPC::Message* reply); 68 // Helper callbacks for the message handlers. 69 void EstablishChannelCallback(scoped_ptr<IPC::Message> reply, 70 const IPC::ChannelHandle& channel, 71 const gpu::GPUInfo& gpu_info); 72 void CreateCommandBufferCallback(scoped_ptr<IPC::Message> reply, 73 int32 route_id); 74 75 void BeginAllFrameSubscriptions(); 76 void EndAllFrameSubscriptions(); 77 void BeginFrameSubscriptionInternal( 78 linked_ptr<FrameSubscription> subscription); 79 void EndFrameSubscriptionInternal( 80 linked_ptr<FrameSubscription> subscription); 81 82 int gpu_process_id_; 83 int render_process_id_; 84 bool share_contexts_; 85 86 scoped_refptr<RenderWidgetHelper> render_widget_helper_; 87 std::vector<linked_ptr<CreateViewCommandBufferRequest> > pending_requests_; 88 89 base::WeakPtrFactory<GpuMessageFilter> weak_ptr_factory_; 90 91 typedef std::vector<linked_ptr<FrameSubscription> > FrameSubscriptionList; 92 FrameSubscriptionList frame_subscription_list_; 93 94 DISALLOW_COPY_AND_ASSIGN(GpuMessageFilter); 95 }; 96 97 } // namespace content 98 99 #endif // CONTENT_BROWSER_RENDERER_HOST_GPU_MESSAGE_FILTER_H_ 100