Home | History | Annotate | Download | only in browser
      1 // Copyright (c) 2011 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 CHROME_BROWSER_GPU_PROCESS_HOST_UI_SHIM_H_
      6 #define CHROME_BROWSER_GPU_PROCESS_HOST_UI_SHIM_H_
      7 #pragma once
      8 
      9 // This class lives on the UI thread and supports classes like the
     10 // BackingStoreProxy, which must live on the UI thread. The IO thread
     11 // portion of this class, the GpuProcessHost, is responsible for
     12 // shuttling messages between the browser and GPU processes.
     13 
     14 #include <queue>
     15 
     16 #include "base/callback.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/gpu/gpu_channel_manager.h"
     21 #include "content/common/gpu/gpu_info.h"
     22 #include "content/common/gpu_feature_flags.h"
     23 #include "content/common/gpu_process_launch_causes.h"
     24 #include "content/common/message_router.h"
     25 
     26 namespace gfx {
     27 class Size;
     28 }
     29 
     30 struct GPUCreateCommandBufferConfig;
     31 struct GpuHostMsg_AcceleratedSurfaceSetIOSurface_Params;
     32 struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params;
     33 
     34 namespace IPC {
     35 struct ChannelHandle;
     36 class Message;
     37 }
     38 
     39 // A task that will forward an IPC message to the UI shim.
     40 class RouteToGpuProcessHostUIShimTask : public Task {
     41  public:
     42   RouteToGpuProcessHostUIShimTask(int host_id, const IPC::Message& msg);
     43   ~RouteToGpuProcessHostUIShimTask();
     44 
     45  private:
     46   virtual void Run();
     47 
     48   int host_id_;
     49   IPC::Message msg_;
     50 };
     51 
     52 class GpuProcessHostUIShim
     53     : public IPC::Channel::Listener,
     54       public IPC::Channel::Sender,
     55       public base::NonThreadSafe {
     56  public:
     57   // Create a GpuProcessHostUIShim with the given ID.  The object can be found
     58   // using FromID with the same id.
     59   static GpuProcessHostUIShim* Create(int host_id);
     60 
     61   // Destroy the GpuProcessHostUIShim with the given host ID. This can only
     62   // be called on the UI thread. Only the GpuProcessHost should destroy the
     63   // UI shim.
     64   static void Destroy(int host_id);
     65 
     66   // Destroy all remaining GpuProcessHostUIShims.
     67   static void DestroyAll();
     68 
     69   static GpuProcessHostUIShim* FromID(int host_id);
     70 
     71   // IPC::Channel::Sender implementation.
     72   virtual bool Send(IPC::Message* msg);
     73 
     74   // IPC::Channel::Listener implementation.
     75   // The GpuProcessHost causes this to be called on the UI thread to
     76   // dispatch the incoming messages from the GPU process, which are
     77   // actually received on the IO thread.
     78   virtual bool OnMessageReceived(const IPC::Message& message);
     79 
     80 #if defined(OS_MACOSX)
     81   // Notify the GPU process that an accelerated surface was destroyed.
     82   void DidDestroyAcceleratedSurface(int renderer_id, int32 render_view_id);
     83 
     84   // TODO(apatrick): Remove this when mac does not use AcceleratedSurfaces for
     85   // when running the GPU thread in the browser process.
     86   static void SendToGpuHost(int host_id, IPC::Message* msg);
     87 #endif
     88 
     89  private:
     90   explicit GpuProcessHostUIShim(int host_id);
     91   virtual ~GpuProcessHostUIShim();
     92 
     93   // Message handlers.
     94   bool OnControlMessageReceived(const IPC::Message& message);
     95 
     96   void OnLogMessage(int level, const std::string& header,
     97       const std::string& message);
     98 #if defined(OS_LINUX) && !defined(TOUCH_UI) || defined(OS_WIN)
     99   void OnResizeView(int32 renderer_id,
    100                     int32 render_view_id,
    101                     int32 command_buffer_route_id,
    102                     gfx::Size size);
    103 #elif defined(OS_MACOSX)
    104   void OnAcceleratedSurfaceSetIOSurface(
    105       const GpuHostMsg_AcceleratedSurfaceSetIOSurface_Params& params);
    106   void OnAcceleratedSurfaceBuffersSwapped(
    107       const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params);
    108 #endif
    109 #if defined(OS_WIN)
    110   void OnScheduleComposite(int32 renderer_id, int32 render_view_id);
    111 #endif
    112 
    113   // The serial number of the GpuProcessHost / GpuProcessHostUIShim pair.
    114   int host_id_;
    115 
    116   // In single process and in process GPU mode, this references the
    117   // GpuChannelManager or null otherwise. It must be called and deleted on the
    118   // GPU thread.
    119   GpuChannelManager* gpu_channel_manager_;
    120 
    121   // This is likewise single process / in process GPU specific. This is a Sender
    122   // implementation that forwards IPC messages to this UI shim on the UI thread.
    123   IPC::Channel::Sender* ui_thread_sender_;
    124 };
    125 
    126 #endif  // CHROME_BROWSER_GPU_PROCESS_HOST_UI_SHIM_H_
    127 
    128