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_RENDERER_GPU_COMPOSITOR_OUTPUT_SURFACE_H_
      6 #define CONTENT_RENDERER_GPU_COMPOSITOR_OUTPUT_SURFACE_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "base/memory/ref_counted.h"
     11 #include "base/memory/scoped_ptr.h"
     12 #include "base/threading/non_thread_safe.h"
     13 #include "base/threading/platform_thread.h"
     14 #include "base/time/time.h"
     15 #include "cc/output/begin_frame_args.h"
     16 #include "cc/output/output_surface.h"
     17 #include "ipc/ipc_sync_message_filter.h"
     18 
     19 namespace base {
     20 class TaskRunner;
     21 }
     22 
     23 namespace IPC {
     24 class ForwardingMessageFilter;
     25 class Message;
     26 }
     27 
     28 namespace cc {
     29 class CompositorFrame;
     30 class CompositorFrameAck;
     31 }
     32 
     33 namespace content {
     34 
     35 class WebGraphicsContext3DCommandBufferImpl;
     36 
     37 // This class can be created only on the main thread, but then becomes pinned
     38 // to a fixed thread when bindToClient is called.
     39 class CompositorOutputSurface
     40     : NON_EXPORTED_BASE(public cc::OutputSurface),
     41       NON_EXPORTED_BASE(public base::NonThreadSafe) {
     42  public:
     43   static IPC::ForwardingMessageFilter* CreateFilter(
     44       base::TaskRunner* target_task_runner);
     45 
     46   CompositorOutputSurface(int32 routing_id,
     47                           uint32 output_surface_id,
     48                           WebGraphicsContext3DCommandBufferImpl* context3d,
     49                           cc::SoftwareOutputDevice* software,
     50                           bool use_swap_compositor_frame_message);
     51   virtual ~CompositorOutputSurface();
     52 
     53   // cc::OutputSurface implementation.
     54   virtual bool BindToClient(cc::OutputSurfaceClient* client) OVERRIDE;
     55   virtual void SwapBuffers(cc::CompositorFrame* frame) OVERRIDE;
     56 #if defined(OS_ANDROID)
     57   virtual void SetNeedsBeginFrame(bool enable) OVERRIDE;
     58 #endif
     59 
     60   // TODO(epenner): This seems out of place here and would be a better fit
     61   // int CompositorThread after it is fully refactored (http://crbug/170828)
     62   virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) OVERRIDE;
     63 
     64  protected:
     65   virtual void OnSwapAck(uint32 output_surface_id,
     66                          const cc::CompositorFrameAck& ack);
     67   uint32 output_surface_id_;
     68 
     69  private:
     70   class CompositorOutputSurfaceProxy :
     71       public base::RefCountedThreadSafe<CompositorOutputSurfaceProxy> {
     72    public:
     73     explicit CompositorOutputSurfaceProxy(
     74         CompositorOutputSurface* output_surface)
     75         : output_surface_(output_surface) {}
     76     void ClearOutputSurface() { output_surface_ = NULL; }
     77     void OnMessageReceived(const IPC::Message& message) {
     78       if (output_surface_)
     79         output_surface_->OnMessageReceived(message);
     80     }
     81 
     82    private:
     83     friend class base::RefCountedThreadSafe<CompositorOutputSurfaceProxy>;
     84     ~CompositorOutputSurfaceProxy() {}
     85     CompositorOutputSurface* output_surface_;
     86 
     87     DISALLOW_COPY_AND_ASSIGN(CompositorOutputSurfaceProxy);
     88   };
     89 
     90   void OnMessageReceived(const IPC::Message& message);
     91   void OnUpdateVSyncParameters(
     92       base::TimeTicks timebase, base::TimeDelta interval);
     93 #if defined(OS_ANDROID)
     94   void OnBeginFrame(const cc::BeginFrameArgs& args);
     95 #endif
     96   bool Send(IPC::Message* message);
     97 
     98   bool use_swap_compositor_frame_message_;
     99 
    100   scoped_refptr<IPC::ForwardingMessageFilter> output_surface_filter_;
    101   scoped_refptr<CompositorOutputSurfaceProxy> output_surface_proxy_;
    102   scoped_refptr<IPC::SyncMessageFilter> message_sender_;
    103   int routing_id_;
    104   bool prefers_smoothness_;
    105   base::PlatformThreadHandle main_thread_handle_;
    106 };
    107 
    108 }  // namespace content
    109 
    110 #endif  // CONTENT_RENDERER_GPU_COMPOSITOR_OUTPUT_SURFACE_H_
    111