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_
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"
19 class ContextProvider;
20 class CompositorFrameMetadata;
25 class SynchronousCompositorClient;
26 class SynchronousCompositorOutputSurface;
27 class WebGraphicsContext3DCommandBufferImpl;
29 class SynchronousCompositorOutputSurfaceDelegate {
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;
39 SynchronousCompositorOutputSurfaceDelegate() {}
40 virtual ~SynchronousCompositorOutputSurfaceDelegate() {}
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) {
54 explicit SynchronousCompositorOutputSurface(int routing_id);
55 virtual ~SynchronousCompositorOutputSurface();
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;
64 // Partial SynchronousCompositor API implementation.
65 bool InitializeHwDraw(
66 scoped_refptr<cc::ContextProvider> onscreen_context_provider);
68 scoped_ptr<cc::CompositorFrame> DemandDrawHw(gfx::Size surface_size,
69 const gfx::Transform& transform,
72 void ReturnResources(const cc::CompositorFrameAck& frame_ack);
73 scoped_ptr<cc::CompositorFrame> DemandDrawSw(SkCanvas* canvas);
74 void SetMemoryPolicy(const SynchronousCompositorMemoryPolicy& policy);
78 friend class SoftwareDevice;
80 void InvokeComposite(const gfx::Transform& transform,
83 bool valid_for_tile_management);
84 bool CalledOnValidThread() const;
85 SynchronousCompositorOutputSurfaceDelegate* GetDelegate();
88 bool needs_begin_frame_;
89 bool invoking_composite_;
91 gfx::Transform cached_hw_transform_;
92 gfx::Rect cached_hw_viewport_;
93 gfx::Rect cached_hw_clip_;
95 // Only valid (non-NULL) during a DemandDrawSw() call.
96 SkCanvas* current_sw_canvas_;
98 cc::ManagedMemoryPolicy memory_policy_;
100 cc::OutputSurfaceClient* output_surface_client_;
101 scoped_ptr<cc::CompositorFrame> frame_holder_;
103 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorOutputSurface);
106 } // namespace content
108 #endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_