Home | History | Annotate | Download | only in in_process
      1 // Copyright 2013 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_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_
      6 #define CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_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 "cc/output/compositor_frame.h"
     13 #include "cc/output/managed_memory_policy.h"
     14 #include "cc/output/output_surface.h"
     15 #include "content/public/browser/android/synchronous_compositor.h"
     16 #include "ui/gfx/transform.h"
     17 
     18 namespace cc {
     19 class ContextProvider;
     20 class CompositorFrameMetadata;
     21 }
     22 
     23 namespace content {
     24 
     25 class SynchronousCompositorClient;
     26 class SynchronousCompositorOutputSurface;
     27 class WebGraphicsContext3DCommandBufferImpl;
     28 
     29 class SynchronousCompositorOutputSurfaceDelegate {
     30  public:
     31    virtual void DidBindOutputSurface(
     32       SynchronousCompositorOutputSurface* output_surface) = 0;
     33   virtual void DidDestroySynchronousOutputSurface(
     34       SynchronousCompositorOutputSurface* output_surface) = 0;
     35   virtual void SetContinuousInvalidate(bool enable) = 0;
     36   virtual void DidActivatePendingTree() = 0;
     37 
     38  protected:
     39   SynchronousCompositorOutputSurfaceDelegate() {}
     40   virtual ~SynchronousCompositorOutputSurfaceDelegate() {}
     41 };
     42 
     43 // Specialization of the output surface that adapts it to implement the
     44 // content::SynchronousCompositor public API. This class effects an "inversion
     45 // of control" - enabling drawing to be  orchestrated by the embedding
     46 // layer, instead of driven by the compositor internals - hence it holds two
     47 // 'client' pointers (|client_| in the OutputSurface baseclass and
     48 // GetDelegate()) which represent the consumers of the two roles in plays.
     49 // This class can be created only on the main thread, but then becomes pinned
     50 // to a fixed thread when BindToClient is called.
     51 class SynchronousCompositorOutputSurface
     52     : NON_EXPORTED_BASE(public cc::OutputSurface) {
     53  public:
     54   explicit SynchronousCompositorOutputSurface(int routing_id);
     55   virtual ~SynchronousCompositorOutputSurface();
     56 
     57   // OutputSurface.
     58   virtual bool BindToClient(cc::OutputSurfaceClient* surface_client) OVERRIDE;
     59   virtual void Reshape(const gfx::Size& size, float scale_factor) OVERRIDE;
     60   virtual void SetNeedsBeginFrame(bool enable) OVERRIDE;
     61   virtual void SwapBuffers(cc::CompositorFrame* frame) OVERRIDE;
     62 
     63   // Partial SynchronousCompositor API implementation.
     64   bool InitializeHwDraw(
     65       scoped_refptr<cc::ContextProvider> onscreen_context_provider);
     66   void ReleaseHwDraw();
     67   scoped_ptr<cc::CompositorFrame> DemandDrawHw(
     68       gfx::Size surface_size,
     69       const gfx::Transform& transform,
     70       gfx::Rect viewport,
     71       gfx::Rect clip,
     72       gfx::Rect viewport_rect_for_tile_priority,
     73       const gfx::Transform& transform_for_tile_priority);
     74   void ReturnResources(const cc::CompositorFrameAck& frame_ack);
     75   scoped_ptr<cc::CompositorFrame> DemandDrawSw(SkCanvas* canvas);
     76   void SetMemoryPolicy(const SynchronousCompositorMemoryPolicy& policy);
     77 
     78  private:
     79   class SoftwareDevice;
     80   friend class SoftwareDevice;
     81 
     82   void InvokeComposite(const gfx::Transform& transform,
     83                        gfx::Rect viewport,
     84                        gfx::Rect clip,
     85                        gfx::Rect viewport_rect_for_tile_priority,
     86                        gfx::Transform transform_for_tile_priority,
     87                        bool hardware_draw);
     88   bool CalledOnValidThread() const;
     89   SynchronousCompositorOutputSurfaceDelegate* GetDelegate();
     90 
     91   int routing_id_;
     92   bool needs_begin_frame_;
     93   bool invoking_composite_;
     94 
     95   gfx::Transform cached_hw_transform_;
     96   gfx::Rect cached_hw_viewport_;
     97   gfx::Rect cached_hw_clip_;
     98   gfx::Rect cached_hw_viewport_rect_for_tile_priority_;
     99   gfx::Transform cached_hw_transform_for_tile_priority_;
    100 
    101   // Only valid (non-NULL) during a DemandDrawSw() call.
    102   SkCanvas* current_sw_canvas_;
    103 
    104   cc::ManagedMemoryPolicy memory_policy_;
    105 
    106   cc::OutputSurfaceClient* output_surface_client_;
    107   scoped_ptr<cc::CompositorFrame> frame_holder_;
    108 
    109   DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorOutputSurface);
    110 };
    111 
    112 }  // namespace content
    113 
    114 #endif  // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_
    115