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 "ui/gfx/rect.h"
11 #include "ui/gfx/size.h"
24 class SynchronousCompositorClient;
26 struct CONTENT_EXPORT SynchronousCompositorMemoryPolicy {
27 // Memory limit for rendering and pre-rendering.
30 // Limit of number of GL resources used for rendering and pre-rendering.
31 size_t num_resources_limit;
33 SynchronousCompositorMemoryPolicy();
35 bool operator==(const SynchronousCompositorMemoryPolicy& other) const;
36 bool operator!=(const SynchronousCompositorMemoryPolicy& other) const;
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 {
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);
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
53 virtual void SetClient(SynchronousCompositorClient* client) = 0;
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;
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;
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,
75 bool stencil_enabled) = 0;
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;
81 // Set the memory limit policy of this compositor.
82 virtual void SetMemoryPolicy(
83 const SynchronousCompositorMemoryPolicy& policy) = 0;
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;
91 virtual ~SynchronousCompositor() {}
94 } // namespace content
96 #endif // CONTENT_PUBLIC_BROWSER_ANDROID_SYNCHRONOUS_COMPOSITOR_H_