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