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