- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / android / in_process / synchronous_compositor_output_surface.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_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"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "cc/output/managed_memory_policy.h"
13 #include "cc/output/output_surface.h"
14 #include "content/public/browser/android/synchronous_compositor.h"
15 #include "ui/gfx/transform.h"
16
17 namespace cc {
18 class ContextProvider;
19 class CompositorFrameMetadata;
20 }
21
22 namespace content {
23
24 class SynchronousCompositorClient;
25 class SynchronousCompositorOutputSurface;
26 class WebGraphicsContext3DCommandBufferImpl;
27
28 class SynchronousCompositorOutputSurfaceDelegate {
29  public:
30    virtual void DidBindOutputSurface(
31       SynchronousCompositorOutputSurface* output_surface) = 0;
32   virtual void DidDestroySynchronousOutputSurface(
33       SynchronousCompositorOutputSurface* output_surface) = 0;
34   virtual void SetContinuousInvalidate(bool enable) = 0;
35   virtual void UpdateFrameMetaData(
36       const cc::CompositorFrameMetadata& frame_metadata) = 0;
37   virtual void DidActivatePendingTree() = 0;
38
39  protected:
40   SynchronousCompositorOutputSurfaceDelegate() {}
41   virtual ~SynchronousCompositorOutputSurfaceDelegate() {}
42 };
43
44 // Specialization of the output surface that adapts it to implement the
45 // content::SynchronousCompositor public API. This class effects an "inversion
46 // of control" - enabling drawing to be  orchestrated by the embedding
47 // layer, instead of driven by the compositor internals - hence it holds two
48 // 'client' pointers (|client_| in the OutputSurface baseclass and
49 // GetDelegate()) which represent the consumers of the two roles in plays.
50 // This class can be created only on the main thread, but then becomes pinned
51 // to a fixed thread when BindToClient is called.
52 class SynchronousCompositorOutputSurface
53     : NON_EXPORTED_BASE(public cc::OutputSurface) {
54  public:
55   explicit SynchronousCompositorOutputSurface(int routing_id);
56   virtual ~SynchronousCompositorOutputSurface();
57
58   // OutputSurface.
59   virtual bool ForcedDrawToSoftwareDevice() const OVERRIDE;
60   virtual bool BindToClient(cc::OutputSurfaceClient* surface_client) OVERRIDE;
61   virtual void Reshape(gfx::Size size, float scale_factor) OVERRIDE;
62   virtual void SetNeedsBeginImplFrame(bool enable) OVERRIDE;
63   virtual void SwapBuffers(cc::CompositorFrame* frame) OVERRIDE;
64
65   // Partial SynchronousCompositor API implementation.
66   bool InitializeHwDraw(
67       scoped_refptr<gfx::GLSurface> surface,
68       scoped_refptr<cc::ContextProvider> offscreen_context_provider);
69   void ReleaseHwDraw();
70   bool DemandDrawHw(gfx::Size surface_size,
71                     const gfx::Transform& transform,
72                     gfx::Rect viewport,
73                     gfx::Rect clip,
74                     bool stencil_enabled);
75   bool DemandDrawSw(SkCanvas* canvas);
76   void SetMemoryPolicy(const SynchronousCompositorMemoryPolicy& policy);
77
78  private:
79   class SoftwareDevice;
80   friend class SoftwareDevice;
81
82   // Private OutputSurface overrides.
83   virtual void PostCheckForRetroactiveBeginImplFrame() OVERRIDE;
84
85   void InvokeComposite(const gfx::Transform& transform,
86                        gfx::Rect viewport,
87                        gfx::Rect clip,
88                        bool valid_for_tile_management);
89   bool CalledOnValidThread() const;
90   SynchronousCompositorOutputSurfaceDelegate* GetDelegate();
91
92   int routing_id_;
93   bool needs_begin_impl_frame_;
94   bool invoking_composite_;
95   bool did_swap_buffer_;
96
97   gfx::Transform cached_hw_transform_;
98   gfx::Rect cached_hw_viewport_;
99   gfx::Rect cached_hw_clip_;
100
101   // Only valid (non-NULL) during a DemandDrawSw() call.
102   SkCanvas* current_sw_canvas_;
103
104   cc::ManagedMemoryPolicy memory_policy_;
105
106   cc::OutputSurfaceClient* output_surface_client_;
107
108   DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorOutputSurface);
109 };
110
111 }  // namespace content
112
113 #endif  // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_