blob: f559b97337ee48bf5855521b502ca1d53ebcf859 [file] [log] [blame]
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +01001// 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
Ben Murdochbb1529c2013-08-08 10:24:53 +01008#include "base/memory/ref_counted.h"
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +01009#include "content/common/content_export.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010010#include "ui/gfx/rect.h"
11#include "ui/gfx/size.h"
12
13class SkCanvas;
14
15namespace gfx {
Ben Murdochbb1529c2013-08-08 10:24:53 +010016class GLSurface;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010017class Transform;
18};
19
20namespace content {
21
22class WebContents;
23
24class SynchronousCompositorClient;
25
26// Interface for embedders that wish to direct compositing operations
27// synchronously under their own control. Only meaningful when the
28// kEnableSyncrhonousRendererCompositor flag is specified.
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010029class CONTENT_EXPORT SynchronousCompositor {
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010030 public:
31 // Must be called once per WebContents instance. Will create the compositor
32 // instance as needed, but only if |client| is non-NULL.
33 static void SetClientForWebContents(WebContents* contents,
34 SynchronousCompositorClient* client);
35
36 // Allows changing or resetting the client to NULL (this must be used if
37 // the client is being deleted prior to the DidDestroyCompositor() call
38 // being received by the client). Ownership of |client| remains with
39 // the caller.
40 virtual void SetClient(SynchronousCompositorClient* client) = 0;
41
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010042 // Synchronously initialize compositor for hardware draw. Can only be called
43 // while compositor is in software only mode, either after compositor is
44 // first created or after ReleaseHwDraw is called. It is invalid to
Ben Murdochbb1529c2013-08-08 10:24:53 +010045 // DemandDrawHw before this returns true. |surface| is the GLSurface that
46 // should be used to create the underlying hardware context.
47 virtual bool InitializeHwDraw(scoped_refptr<gfx::GLSurface> surface) = 0;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010048
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010049 // Reverse of InitializeHwDraw above. Can only be called while hardware draw
50 // is already initialized. Brings compositor back to software only mode and
51 // releases all hardware resources.
52 virtual void ReleaseHwDraw() = 0;
53
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010054 // "On demand" hardware draw. The content is first clipped to |damage_area|,
Ben Murdochfb250652013-07-31 11:42:55 +010055 // then transformed through |transform|, and finally clipped to |view_size|
56 // and by the existing stencil buffer if any.
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010057 virtual bool DemandDrawHw(
58 gfx::Size view_size,
59 const gfx::Transform& transform,
Ben Murdochfb250652013-07-31 11:42:55 +010060 gfx::Rect damage_area,
61 bool stencil_enabled) = 0;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010062
63 // "On demand" SW draw, into the supplied canvas (observing the transform
64 // and clip set there-in).
65 virtual bool DemandDrawSw(SkCanvas* canvas) = 0;
66
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010067 // Should be called by the embedder after the embedder had modified the
68 // scroll offset of the root layer (as returned by
69 // SynchronousCompositorClient::GetTotalRootLayerScrollOffset).
70 virtual void DidChangeRootLayerScrollOffset() = 0;
71
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010072 protected:
73 virtual ~SynchronousCompositor() {}
74};
75
76} // namespace content
77
78#endif // CONTENT_PUBLIC_BROWSER_ANDROID_SYNCHRONOUS_COMPOSITOR_H_