Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / public / browser / android / synchronous_compositor.h
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 cc {
17 class CompositorFrame;
18 class CompositorFrameAck;
19 }
20
21 namespace gfx {
22 class Transform;
23 };
24
25 namespace gpu {
26 class GLInProcessContext;
27 }
28
29 namespace content {
30
31 class SynchronousCompositorClient;
32 class WebContents;
33
34 // Interface for embedders that wish to direct compositing operations
35 // synchronously under their own control. Only meaningful when the
36 // kEnableSyncrhonousRendererCompositor flag is specified.
37 class CONTENT_EXPORT SynchronousCompositor {
38  public:
39   // Must be called once per WebContents instance. Will create the compositor
40   // instance as needed, but only if |client| is non-NULL.
41   static void SetClientForWebContents(WebContents* contents,
42                                       SynchronousCompositorClient* client);
43
44   // Allows changing or resetting the client to NULL (this must be used if
45   // the client is being deleted prior to the DidDestroyCompositor() call
46   // being received by the client). Ownership of |client| remains with
47   // the caller.
48   virtual void SetClient(SynchronousCompositorClient* client) = 0;
49
50   static void SetGpuService(
51       scoped_refptr<gpu::InProcessCommandBuffer::Service> service);
52
53   // By default, synchronous compopsitor records the full layer, not only
54   // what is inside and around the view port. This can be used to switch
55   // between this record-full-layer behavior and normal record-around-viewport
56   // behavior.
57   static void SetRecordFullDocument(bool record_full_document);
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.
63   virtual bool InitializeHwDraw() = 0;
64
65   // Reverse of InitializeHwDraw above. Can only be called while hardware draw
66   // is already initialized. Brings compositor back to software only mode and
67   // releases all hardware resources.
68   virtual void ReleaseHwDraw() = 0;
69
70   // "On demand" hardware draw. The content is first clipped to |damage_area|,
71   // then transformed through |transform|, and finally clipped to |view_size|.
72   virtual scoped_ptr<cc::CompositorFrame> DemandDrawHw(
73       gfx::Size surface_size,
74       const gfx::Transform& transform,
75       gfx::Rect viewport,
76       gfx::Rect clip,
77       gfx::Rect viewport_rect_for_tile_priority,
78       const gfx::Transform& transform_for_tile_priority) = 0;
79
80   // For delegated rendering, return resources from parent compositor to this.
81   // Note that all resources must be returned before ReleaseHwDraw.
82   virtual void ReturnResources(const cc::CompositorFrameAck& frame_ack) = 0;
83
84   // "On demand" SW draw, into the supplied canvas (observing the transform
85   // and clip set there-in).
86   virtual bool DemandDrawSw(SkCanvas* canvas) = 0;
87
88   // Set the memory limit policy of this compositor.
89   virtual void SetMemoryPolicy(size_t bytes_limit) = 0;
90
91   // Should be called by the embedder after the embedder had modified the
92   // scroll offset of the root layer (as returned by
93   // SynchronousCompositorClient::GetTotalRootLayerScrollOffset).
94   virtual void DidChangeRootLayerScrollOffset() = 0;
95
96  protected:
97   virtual ~SynchronousCompositor() {}
98 };
99
100 }  // namespace content
101
102 #endif  // CONTENT_PUBLIC_BROWSER_ANDROID_SYNCHRONOUS_COMPOSITOR_H_