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_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_ |
| 6 | #define CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_ |
| 7 | |
| 8 | #include "base/basictypes.h" |
| 9 | #include "base/compiler_specific.h" |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 10 | #include "base/memory/ref_counted.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 11 | #include "base/memory/scoped_ptr.h" |
| 12 | #include "cc/output/output_surface.h" |
| 13 | #include "content/public/browser/android/synchronous_compositor.h" |
| 14 | |
Torne (Richard Coles) | 5e3f23d | 2013-06-11 16:24:11 +0100 | [diff] [blame] | 15 | namespace cc { |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 16 | class ContextProvider; |
Torne (Richard Coles) | 5e3f23d | 2013-06-11 16:24:11 +0100 | [diff] [blame] | 17 | class CompositorFrameMetadata; |
| 18 | } |
| 19 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 20 | namespace content { |
| 21 | |
| 22 | class SynchronousCompositorClient; |
| 23 | class SynchronousCompositorOutputSurface; |
| 24 | class WebGraphicsContext3DCommandBufferImpl; |
| 25 | |
| 26 | class SynchronousCompositorOutputSurfaceDelegate { |
| 27 | public: |
| 28 | virtual void DidBindOutputSurface( |
| 29 | SynchronousCompositorOutputSurface* output_surface) = 0; |
| 30 | virtual void DidDestroySynchronousOutputSurface( |
| 31 | SynchronousCompositorOutputSurface* output_surface) = 0; |
| 32 | virtual void SetContinuousInvalidate(bool enable) = 0; |
Torne (Richard Coles) | 5e3f23d | 2013-06-11 16:24:11 +0100 | [diff] [blame] | 33 | virtual void UpdateFrameMetaData( |
| 34 | const cc::CompositorFrameMetadata& frame_metadata) = 0; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 35 | virtual void DidActivatePendingTree() = 0; |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 36 | |
| 37 | protected: |
| 38 | SynchronousCompositorOutputSurfaceDelegate() {} |
| 39 | virtual ~SynchronousCompositorOutputSurfaceDelegate() {} |
| 40 | }; |
| 41 | |
| 42 | // Specialization of the output surface that adapts it to implement the |
| 43 | // content::SynchronousCompositor public API. This class effects an "inversion |
| 44 | // of control" - enabling drawing to be orchestrated by the embedding |
| 45 | // layer, instead of driven by the compositor internals - hence it holds two |
| 46 | // 'client' pointers (|client_| in the OutputSurface baseclass and |
| 47 | // GetDelegate()) which represent the consumers of the two roles in plays. |
| 48 | // This class can be created only on the main thread, but then becomes pinned |
| 49 | // to a fixed thread when BindToClient is called. |
| 50 | class SynchronousCompositorOutputSurface |
| 51 | : NON_EXPORTED_BASE(public cc::OutputSurface) { |
| 52 | public: |
| 53 | explicit SynchronousCompositorOutputSurface(int routing_id); |
| 54 | virtual ~SynchronousCompositorOutputSurface(); |
| 55 | |
| 56 | // OutputSurface. |
| 57 | virtual bool ForcedDrawToSoftwareDevice() const OVERRIDE; |
| 58 | virtual bool BindToClient(cc::OutputSurfaceClient* surface_client) OVERRIDE; |
| 59 | virtual void Reshape(gfx::Size size, float scale_factor) OVERRIDE; |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 60 | virtual void SetNeedsBeginFrame(bool enable) OVERRIDE; |
Torne (Richard Coles) | 5e3f23d | 2013-06-11 16:24:11 +0100 | [diff] [blame] | 61 | virtual void SwapBuffers(cc::CompositorFrame* frame) OVERRIDE; |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 62 | |
| 63 | // Partial SynchronousCompositor API implementation. |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 64 | bool InitializeHwDraw( |
| 65 | scoped_refptr<gfx::GLSurface> surface, |
| 66 | scoped_refptr<cc::ContextProvider> offscreen_context); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 67 | void ReleaseHwDraw(); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 68 | bool DemandDrawHw(gfx::Size surface_size, |
| 69 | const gfx::Transform& transform, |
Ben Murdoch | fb25065 | 2013-07-31 11:42:55 +0100 | [diff] [blame] | 70 | gfx::Rect clip, |
| 71 | bool stencil_enabled); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 72 | bool DemandDrawSw(SkCanvas* canvas); |
| 73 | |
| 74 | private: |
| 75 | class SoftwareDevice; |
| 76 | friend class SoftwareDevice; |
| 77 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 78 | // Private OutputSurface overrides. |
| 79 | virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE; |
| 80 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 81 | void InvokeComposite(gfx::Size damage_size); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 82 | bool CalledOnValidThread() const; |
| 83 | SynchronousCompositorOutputSurfaceDelegate* GetDelegate(); |
| 84 | |
| 85 | int routing_id_; |
| 86 | bool needs_begin_frame_; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 87 | bool invoking_composite_; |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 88 | bool did_swap_buffer_; |
| 89 | |
| 90 | // Only valid (non-NULL) during a DemandDrawSw() call. |
| 91 | SkCanvas* current_sw_canvas_; |
| 92 | |
| 93 | DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorOutputSurface); |
| 94 | }; |
| 95 | |
| 96 | } // namespace content |
| 97 | |
| 98 | #endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_ |