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"
17 class CompositorFrame;
18 class CompositorFrameAck;
26 class GLInProcessContext;
31 class SynchronousCompositorClient;
34 struct CONTENT_EXPORT SynchronousCompositorMemoryPolicy {
35 // Memory limit for rendering and pre-rendering.
38 // Limit of number of GL resources used for rendering and pre-rendering.
39 size_t num_resources_limit;
41 SynchronousCompositorMemoryPolicy();
43 bool operator==(const SynchronousCompositorMemoryPolicy& other) const;
44 bool operator!=(const SynchronousCompositorMemoryPolicy& other) const;
47 // Interface for embedders that wish to direct compositing operations
48 // synchronously under their own control. Only meaningful when the
49 // kEnableSyncrhonousRendererCompositor flag is specified.
50 class CONTENT_EXPORT SynchronousCompositor {
52 // Must be called once per WebContents instance. Will create the compositor
53 // instance as needed, but only if |client| is non-NULL.
54 static void SetClientForWebContents(WebContents* contents,
55 SynchronousCompositorClient* client);
57 // Allows changing or resetting the client to NULL (this must be used if
58 // the client is being deleted prior to the DidDestroyCompositor() call
59 // being received by the client). Ownership of |client| remains with
61 virtual void SetClient(SynchronousCompositorClient* client) = 0;
63 static void SetGpuService(
64 scoped_refptr<gpu::InProcessCommandBuffer::Service> service);
66 // By default, synchronous compopsitor records the full layer, not only
67 // what is inside and around the view port. This can be used to switch
68 // between this record-full-layer behavior and normal record-around-viewport
70 static void SetRecordFullDocument(bool record_full_document);
72 // Synchronously initialize compositor for hardware draw. Can only be called
73 // while compositor is in software only mode, either after compositor is
74 // first created or after ReleaseHwDraw is called. It is invalid to
75 // DemandDrawHw before this returns true.
76 virtual bool InitializeHwDraw() = 0;
78 // Reverse of InitializeHwDraw above. Can only be called while hardware draw
79 // is already initialized. Brings compositor back to software only mode and
80 // releases all hardware resources.
81 virtual void ReleaseHwDraw() = 0;
83 // "On demand" hardware draw. The content is first clipped to |damage_area|,
84 // then transformed through |transform|, and finally clipped to |view_size|.
85 virtual scoped_ptr<cc::CompositorFrame> DemandDrawHw(
86 gfx::Size surface_size,
87 const gfx::Transform& transform,
90 gfx::Rect viewport_rect_for_tile_priority,
91 const gfx::Transform& transform_for_tile_priority) = 0;
93 // For delegated rendering, return resources from parent compositor to this.
94 // Note that all resources must be returned before ReleaseHwDraw.
95 virtual void ReturnResources(const cc::CompositorFrameAck& frame_ack) = 0;
97 // "On demand" SW draw, into the supplied canvas (observing the transform
98 // and clip set there-in).
99 virtual bool DemandDrawSw(SkCanvas* canvas) = 0;
101 // Set the memory limit policy of this compositor.
102 virtual void SetMemoryPolicy(
103 const SynchronousCompositorMemoryPolicy& policy) = 0;
105 // Should be called by the embedder after the embedder had modified the
106 // scroll offset of the root layer (as returned by
107 // SynchronousCompositorClient::GetTotalRootLayerScrollOffset).
108 virtual void DidChangeRootLayerScrollOffset() = 0;
111 virtual ~SynchronousCompositor() {}
114 } // namespace content
116 #endif // CONTENT_PUBLIC_BROWSER_ANDROID_SYNCHRONOUS_COMPOSITOR_H_