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/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"
18 class ContextProvider;
19 class CompositorFrameMetadata;
24 class SynchronousCompositorClient;
25 class SynchronousCompositorOutputSurface;
26 class WebGraphicsContext3DCommandBufferImpl;
28 class SynchronousCompositorOutputSurfaceDelegate {
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;
40 SynchronousCompositorOutputSurfaceDelegate() {}
41 virtual ~SynchronousCompositorOutputSurfaceDelegate() {}
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) {
55 explicit SynchronousCompositorOutputSurface(int routing_id);
56 virtual ~SynchronousCompositorOutputSurface();
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;
65 // Partial SynchronousCompositor API implementation.
66 bool InitializeHwDraw(
67 scoped_refptr<gfx::GLSurface> surface,
68 scoped_refptr<cc::ContextProvider> offscreen_context_provider);
70 bool DemandDrawHw(gfx::Size surface_size,
71 const gfx::Transform& transform,
74 bool stencil_enabled);
75 bool DemandDrawSw(SkCanvas* canvas);
76 void SetMemoryPolicy(const SynchronousCompositorMemoryPolicy& policy);
80 friend class SoftwareDevice;
82 // Private OutputSurface overrides.
83 virtual void PostCheckForRetroactiveBeginImplFrame() OVERRIDE;
85 void InvokeComposite(const gfx::Transform& transform,
88 bool valid_for_tile_management);
89 bool CalledOnValidThread() const;
90 SynchronousCompositorOutputSurfaceDelegate* GetDelegate();
93 bool needs_begin_impl_frame_;
94 bool invoking_composite_;
95 bool did_swap_buffer_;
97 gfx::Transform cached_hw_transform_;
98 gfx::Rect cached_hw_viewport_;
99 gfx::Rect cached_hw_clip_;
101 // Only valid (non-NULL) during a DemandDrawSw() call.
102 SkCanvas* current_sw_canvas_;
104 cc::ManagedMemoryPolicy memory_policy_;
106 cc::OutputSurfaceClient* output_surface_client_;
108 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorOutputSurface);
111 } // namespace content
113 #endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_