Home | History | Annotate | Download | only in gpu
      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_GPU_GPU_PROCESS_HOST_UI_SHIM_H_
      6 #define CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_UI_SHIM_H_
      7 
      8 // This class lives on the UI thread and supports classes like the
      9 // BackingStoreProxy, which must live on the UI thread. The IO thread
     10 // portion of this class, the GpuProcessHost, is responsible for
     11 // shuttling messages between the browser and GPU processes.
     12 
     13 #include <string>
     14 
     15 #include "base/callback_forward.h"
     16 #include "base/compiler_specific.h"
     17 #include "base/memory/linked_ptr.h"
     18 #include "base/memory/ref_counted.h"
     19 #include "base/threading/non_thread_safe.h"
     20 #include "content/common/content_export.h"
     21 #include "content/common/message_router.h"
     22 #include "content/public/common/gpu_memory_stats.h"
     23 #include "gpu/config/gpu_info.h"
     24 #include "ipc/ipc_listener.h"
     25 #include "ipc/ipc_sender.h"
     26 
     27 struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params;
     28 struct GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params;
     29 struct GpuHostMsg_AcceleratedSurfaceRelease_Params;
     30 
     31 namespace ui {
     32 struct LatencyInfo;
     33 }
     34 
     35 namespace gfx {
     36 class Size;
     37 }
     38 
     39 namespace IPC {
     40 class Message;
     41 }
     42 
     43 namespace content {
     44 void RouteToGpuProcessHostUIShimTask(int host_id, const IPC::Message& msg);
     45 
     46 class GpuProcessHostUIShim : public IPC::Listener,
     47                              public IPC::Sender,
     48                              public base::NonThreadSafe {
     49  public:
     50   // Create a GpuProcessHostUIShim with the given ID.  The object can be found
     51   // using FromID with the same id.
     52   static GpuProcessHostUIShim* Create(int host_id);
     53 
     54   // Destroy the GpuProcessHostUIShim with the given host ID. This can only
     55   // be called on the UI thread. Only the GpuProcessHost should destroy the
     56   // UI shim.
     57   static void Destroy(int host_id, const std::string& message);
     58 
     59   // Destroy all remaining GpuProcessHostUIShims.
     60   CONTENT_EXPORT static void DestroyAll();
     61 
     62   CONTENT_EXPORT static GpuProcessHostUIShim* FromID(int host_id);
     63 
     64   // Get a GpuProcessHostUIShim instance; it doesn't matter which one.
     65   // Return NULL if none has been created.
     66   CONTENT_EXPORT static GpuProcessHostUIShim* GetOneInstance();
     67 
     68   // IPC::Sender implementation.
     69   virtual bool Send(IPC::Message* msg) OVERRIDE;
     70 
     71   // IPC::Listener implementation.
     72   // The GpuProcessHost causes this to be called on the UI thread to
     73   // dispatch the incoming messages from the GPU process, which are
     74   // actually received on the IO thread.
     75   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
     76 
     77   CONTENT_EXPORT void SimulateRemoveAllContext();
     78   CONTENT_EXPORT void SimulateCrash();
     79   CONTENT_EXPORT void SimulateHang();
     80 
     81  private:
     82   explicit GpuProcessHostUIShim(int host_id);
     83   virtual ~GpuProcessHostUIShim();
     84 
     85   // Message handlers.
     86   bool OnControlMessageReceived(const IPC::Message& message);
     87 
     88   void OnLogMessage(int level, const std::string& header,
     89       const std::string& message);
     90 #if defined(TOOLKIT_GTK) || defined(OS_WIN)
     91   void OnResizeView(int32 surface_id,
     92                     int32 route_id,
     93                     gfx::Size size);
     94 #endif
     95 
     96   void OnGraphicsInfoCollected(const gpu::GPUInfo& gpu_info);
     97 
     98   void OnAcceleratedSurfaceBuffersSwapped(
     99       const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params);
    100   void OnAcceleratedSurfacePostSubBuffer(
    101       const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params);
    102   void OnAcceleratedSurfaceSuspend(int32 surface_id);
    103   void OnAcceleratedSurfaceRelease(
    104       const GpuHostMsg_AcceleratedSurfaceRelease_Params& params);
    105   void OnVideoMemoryUsageStatsReceived(
    106       const GPUVideoMemoryUsageStats& video_memory_usage_stats);
    107   void OnUpdateVSyncParameters(int surface_id,
    108                                base::TimeTicks timebase,
    109                                base::TimeDelta interval);
    110   void OnFrameDrawn(const ui::LatencyInfo& latency_info);
    111 
    112   // The serial number of the GpuProcessHost / GpuProcessHostUIShim pair.
    113   int host_id_;
    114 };
    115 
    116 }  // namespace content
    117 
    118 #endif  // CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_UI_SHIM_H_
    119