Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 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 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 8 | #include "base/memory/ref_counted.h" |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 9 | #include "content/common/content_export.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 10 | #include "ui/gfx/rect.h" |
| 11 | #include "ui/gfx/size.h" |
| 12 | |
| 13 | class SkCanvas; |
| 14 | |
| 15 | namespace gfx { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 16 | class GLSurface; |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 17 | class Transform; |
| 18 | }; |
| 19 | |
| 20 | namespace content { |
| 21 | |
| 22 | class WebContents; |
| 23 | |
| 24 | class 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) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 29 | class CONTENT_EXPORT SynchronousCompositor { |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 30 | 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 Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 42 | // 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 Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 45 | // 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) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 48 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 49 | // 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) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 54 | // "On demand" hardware draw. The content is first clipped to |damage_area|, |
Ben Murdoch | fb25065 | 2013-07-31 11:42:55 +0100 | [diff] [blame] | 55 | // then transformed through |transform|, and finally clipped to |view_size| |
| 56 | // and by the existing stencil buffer if any. |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 57 | virtual bool DemandDrawHw( |
| 58 | gfx::Size view_size, |
| 59 | const gfx::Transform& transform, |
Ben Murdoch | fb25065 | 2013-07-31 11:42:55 +0100 | [diff] [blame] | 60 | gfx::Rect damage_area, |
| 61 | bool stencil_enabled) = 0; |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 62 | |
| 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) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 67 | // 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) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 72 | protected: |
| 73 | virtual ~SynchronousCompositor() {} |
| 74 | }; |
| 75 | |
| 76 | } // namespace content |
| 77 | |
| 78 | #endif // CONTENT_PUBLIC_BROWSER_ANDROID_SYNCHRONOUS_COMPOSITOR_H_ |