Home | History | Annotate | Download | only in renderer_host
      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/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"
     17 
     18 class GpuProcessHost;
     19 struct GPUCreateCommandBufferConfig;
     20 
     21 namespace gpu {
     22 struct GPUInfo;
     23 }
     24 
     25 namespace content {
     26 class RenderWidgetHelper;
     27 class RenderWidgetHostViewFrameSubscriber;
     28 
     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 {
     33  public:
     34   GpuMessageFilter(int render_process_id,
     35                    RenderWidgetHelper* render_widget_helper);
     36 
     37   // BrowserMessageFilter methods:
     38   virtual bool OnMessageReceived(const IPC::Message& message,
     39                                  bool* message_was_ok) OVERRIDE;
     40 
     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);
     44 
     45   // This set of API is used to subscribe to frame presentation events.
     46   // See RenderWidgetHostViewFrameSubscriber for more details.
     47   void BeginFrameSubscription(
     48       int route_id,
     49       scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber);
     50   void EndFrameSubscription(int route_id);
     51 
     52  private:
     53   friend class BrowserThread;
     54   friend class base::DeleteHelper<GpuMessageFilter>;
     55   struct CreateViewCommandBufferRequest;
     56   struct FrameSubscription;
     57 
     58   virtual ~GpuMessageFilter();
     59 
     60   // Message handlers called on the browser IO thread:
     61   void OnEstablishGpuChannel(CauseForGpuLaunch,
     62                              IPC::Message* reply);
     63   void OnCreateViewCommandBuffer(
     64       int32 surface_id,
     65       const GPUCreateCommandBufferConfig& init_params,
     66       IPC::Message* reply);
     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);
     72 
     73   void BeginAllFrameSubscriptions();
     74   void EndAllFrameSubscriptions();
     75   void BeginFrameSubscriptionInternal(
     76       linked_ptr<FrameSubscription> subscription);
     77   void EndFrameSubscriptionInternal(
     78       linked_ptr<FrameSubscription> subscription);
     79 
     80   int gpu_process_id_;
     81   int render_process_id_;
     82   bool share_contexts_;
     83 
     84   scoped_refptr<RenderWidgetHelper> render_widget_helper_;
     85   std::vector<linked_ptr<CreateViewCommandBufferRequest> > pending_requests_;
     86 
     87   base::WeakPtrFactory<GpuMessageFilter> weak_ptr_factory_;
     88 
     89   typedef std::vector<linked_ptr<FrameSubscription> > FrameSubscriptionList;
     90   FrameSubscriptionList frame_subscription_list_;
     91 
     92   DISALLOW_COPY_AND_ASSIGN(GpuMessageFilter);
     93 };
     94 
     95 }  // namespace content
     96 
     97 #endif  // CONTENT_BROWSER_RENDERER_HOST_GPU_MESSAGE_FILTER_H_
     98