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