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.
5 #ifndef CONTENT_PUBLIC_BROWSER_ANDROID_SYNCHRONOUS_COMPOSITOR_H_
6 #define CONTENT_PUBLIC_BROWSER_ANDROID_SYNCHRONOUS_COMPOSITOR_H_
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"
25 class SynchronousCompositorClient
;
27 struct CONTENT_EXPORT SynchronousCompositorMemoryPolicy
{
28 // Memory limit for rendering and pre-rendering.
31 // Limit of number of GL resources used for rendering and pre-rendering.
32 size_t num_resources_limit
;
34 SynchronousCompositorMemoryPolicy();
36 bool operator==(const SynchronousCompositorMemoryPolicy
& other
) const;
37 bool operator!=(const SynchronousCompositorMemoryPolicy
& other
) const;
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
{
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
);
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
54 virtual void SetClient(SynchronousCompositorClient
* client
) = 0;
56 static void SetGpuService(
57 scoped_refptr
<gpu::InProcessCommandBuffer::Service
> service
);
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;
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;
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
,
79 bool stencil_enabled
) = 0;
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;
85 // Set the memory limit policy of this compositor.
86 virtual void SetMemoryPolicy(
87 const SynchronousCompositorMemoryPolicy
& policy
) = 0;
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;
95 virtual ~SynchronousCompositor() {}
98 } // namespace content
100 #endif // CONTENT_PUBLIC_BROWSER_ANDROID_SYNCHRONOUS_COMPOSITOR_H_