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.
5 #ifndef CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_
6 #define CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "cc/output/compositor_frame.h"
15 #include "cc/output/managed_memory_policy.h"
16 #include "cc/output/output_surface.h"
17 #include "content/public/browser/android/synchronous_compositor.h"
18 #include "ipc/ipc_message.h"
19 #include "ui/gfx/transform.h"
22 class ContextProvider
;
23 class CompositorFrameMetadata
;
32 class FrameSwapMessageQueue
;
33 class SynchronousCompositorClient
;
34 class SynchronousCompositorOutputSurface
;
35 class WebGraphicsContext3DCommandBufferImpl
;
37 class SynchronousCompositorOutputSurfaceDelegate
{
39 virtual void DidBindOutputSurface(
40 SynchronousCompositorOutputSurface
* output_surface
) = 0;
41 virtual void DidDestroySynchronousOutputSurface(
42 SynchronousCompositorOutputSurface
* output_surface
) = 0;
43 virtual void SetContinuousInvalidate(bool enable
) = 0;
44 virtual void DidActivatePendingTree() = 0;
47 SynchronousCompositorOutputSurfaceDelegate() {}
48 virtual ~SynchronousCompositorOutputSurfaceDelegate() {}
51 // Specialization of the output surface that adapts it to implement the
52 // content::SynchronousCompositor public API. This class effects an "inversion
53 // of control" - enabling drawing to be orchestrated by the embedding
54 // layer, instead of driven by the compositor internals - hence it holds two
55 // 'client' pointers (|client_| in the OutputSurface baseclass and
56 // GetDelegate()) which represent the consumers of the two roles in plays.
57 // This class can be created only on the main thread, but then becomes pinned
58 // to a fixed thread when BindToClient is called.
59 class SynchronousCompositorOutputSurface
60 : NON_EXPORTED_BASE(public cc::OutputSurface
) {
62 explicit SynchronousCompositorOutputSurface(
64 scoped_refptr
<FrameSwapMessageQueue
> frame_swap_message_queue
);
65 virtual ~SynchronousCompositorOutputSurface();
68 virtual bool BindToClient(cc::OutputSurfaceClient
* surface_client
) OVERRIDE
;
69 virtual void Reshape(const gfx::Size
& size
, float scale_factor
) OVERRIDE
;
70 virtual void SetNeedsBeginFrame(bool enable
) OVERRIDE
;
71 virtual void SwapBuffers(cc::CompositorFrame
* frame
) OVERRIDE
;
73 // Partial SynchronousCompositor API implementation.
74 bool InitializeHwDraw(
75 scoped_refptr
<cc::ContextProvider
> onscreen_context_provider
);
77 scoped_ptr
<cc::CompositorFrame
> DemandDrawHw(
78 gfx::Size surface_size
,
79 const gfx::Transform
& transform
,
82 gfx::Rect viewport_rect_for_tile_priority
,
83 const gfx::Transform
& transform_for_tile_priority
);
84 void ReturnResources(const cc::CompositorFrameAck
& frame_ack
);
85 scoped_ptr
<cc::CompositorFrame
> DemandDrawSw(SkCanvas
* canvas
);
86 void SetMemoryPolicy(const SynchronousCompositorMemoryPolicy
& policy
);
87 void GetMessagesToDeliver(ScopedVector
<IPC::Message
>* messages
);
91 friend class SoftwareDevice
;
93 void InvokeComposite(const gfx::Transform
& transform
,
96 gfx::Rect viewport_rect_for_tile_priority
,
97 gfx::Transform transform_for_tile_priority
,
99 bool CalledOnValidThread() const;
100 SynchronousCompositorOutputSurfaceDelegate
* GetDelegate();
103 bool needs_begin_frame_
;
104 bool invoking_composite_
;
106 gfx::Transform cached_hw_transform_
;
107 gfx::Rect cached_hw_viewport_
;
108 gfx::Rect cached_hw_clip_
;
109 gfx::Rect cached_hw_viewport_rect_for_tile_priority_
;
110 gfx::Transform cached_hw_transform_for_tile_priority_
;
112 // Only valid (non-NULL) during a DemandDrawSw() call.
113 SkCanvas
* current_sw_canvas_
;
115 cc::ManagedMemoryPolicy memory_policy_
;
117 cc::OutputSurfaceClient
* output_surface_client_
;
118 scoped_ptr
<cc::CompositorFrame
> frame_holder_
;
120 scoped_refptr
<FrameSwapMessageQueue
> frame_swap_message_queue_
;
122 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorOutputSurface
);
125 } // namespace content
127 #endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_