Home | History | Annotate | Download | only in android
      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_PUBLIC_BROWSER_ANDROID_SYNCHRONOUS_COMPOSITOR_H_
      6 #define CONTENT_PUBLIC_BROWSER_ANDROID_SYNCHRONOUS_COMPOSITOR_H_
      7 
      8 #include "base/memory/ref_counted.h"
      9 #include "content/common/content_export.h"
     10 #include "ui/gfx/rect.h"
     11 #include "ui/gfx/size.h"
     12 
     13 class SkCanvas;
     14 
     15 namespace gfx {
     16 class GLSurface;
     17 class Transform;
     18 };
     19 
     20 namespace content {
     21 
     22 class WebContents;
     23 
     24 class SynchronousCompositorClient;
     25 
     26 struct CONTENT_EXPORT SynchronousCompositorMemoryPolicy {
     27   // Memory limit for rendering and pre-rendering.
     28   size_t bytes_limit;
     29 
     30   // Limit of number of GL resources used for rendering and pre-rendering.
     31   size_t num_resources_limit;
     32 
     33   SynchronousCompositorMemoryPolicy();
     34 
     35   bool operator==(const SynchronousCompositorMemoryPolicy& other) const;
     36   bool operator!=(const SynchronousCompositorMemoryPolicy& other) const;
     37 };
     38 
     39 // Interface for embedders that wish to direct compositing operations
     40 // synchronously under their own control. Only meaningful when the
     41 // kEnableSyncrhonousRendererCompositor flag is specified.
     42 class CONTENT_EXPORT SynchronousCompositor {
     43  public:
     44   // Must be called once per WebContents instance. Will create the compositor
     45   // instance as needed, but only if |client| is non-NULL.
     46   static void SetClientForWebContents(WebContents* contents,
     47                                       SynchronousCompositorClient* client);
     48 
     49   // Allows changing or resetting the client to NULL (this must be used if
     50   // the client is being deleted prior to the DidDestroyCompositor() call
     51   // being received by the client). Ownership of |client| remains with
     52   // the caller.
     53   virtual void SetClient(SynchronousCompositorClient* client) = 0;
     54 
     55   // Synchronously initialize compositor for hardware draw. Can only be called
     56   // while compositor is in software only mode, either after compositor is
     57   // first created or after ReleaseHwDraw is called. It is invalid to
     58   // DemandDrawHw before this returns true. |surface| is the GLSurface that
     59   // should be used to create the underlying hardware context.
     60   virtual bool InitializeHwDraw(scoped_refptr<gfx::GLSurface> surface) = 0;
     61 
     62   // Reverse of InitializeHwDraw above. Can only be called while hardware draw
     63   // is already initialized. Brings compositor back to software only mode and
     64   // releases all hardware resources.
     65   virtual void ReleaseHwDraw() = 0;
     66 
     67   // "On demand" hardware draw. The content is first clipped to |damage_area|,
     68   // then transformed through |transform|, and finally clipped to |view_size|
     69   // and by the existing stencil buffer if any.
     70   virtual bool DemandDrawHw(
     71       gfx::Size surface_size,
     72       const gfx::Transform& transform,
     73       gfx::Rect viewport,
     74       gfx::Rect clip,
     75       bool stencil_enabled) = 0;
     76 
     77   // "On demand" SW draw, into the supplied canvas (observing the transform
     78   // and clip set there-in).
     79   virtual bool DemandDrawSw(SkCanvas* canvas) = 0;
     80 
     81   // Set the memory limit policy of this compositor.
     82   virtual void SetMemoryPolicy(
     83       const SynchronousCompositorMemoryPolicy& policy) = 0;
     84 
     85   // Should be called by the embedder after the embedder had modified the
     86   // scroll offset of the root layer (as returned by
     87   // SynchronousCompositorClient::GetTotalRootLayerScrollOffset).
     88   virtual void DidChangeRootLayerScrollOffset() = 0;
     89 
     90  protected:
     91   virtual ~SynchronousCompositor() {}
     92 };
     93 
     94 }  // namespace content
     95 
     96 #endif  // CONTENT_PUBLIC_BROWSER_ANDROID_SYNCHRONOUS_COMPOSITOR_H_
     97