blob: 3ab149818ae2f9e0b1b1cba01afec4851cc49cbc [file] [log] [blame]
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +01001// 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"
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010010#include "base/memory/ref_counted.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010011#include "base/memory/scoped_ptr.h"
12#include "cc/output/output_surface.h"
13#include "content/public/browser/android/synchronous_compositor.h"
14
Torne (Richard Coles)5e3f23d2013-06-11 16:24:11 +010015namespace cc {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010016class ContextProvider;
Torne (Richard Coles)5e3f23d2013-06-11 16:24:11 +010017class CompositorFrameMetadata;
18}
19
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010020namespace content {
21
22class SynchronousCompositorClient;
23class SynchronousCompositorOutputSurface;
24class WebGraphicsContext3DCommandBufferImpl;
25
26class SynchronousCompositorOutputSurfaceDelegate {
27 public:
28 virtual void DidBindOutputSurface(
29 SynchronousCompositorOutputSurface* output_surface) = 0;
30 virtual void DidDestroySynchronousOutputSurface(
31 SynchronousCompositorOutputSurface* output_surface) = 0;
32 virtual void SetContinuousInvalidate(bool enable) = 0;
Torne (Richard Coles)5e3f23d2013-06-11 16:24:11 +010033 virtual void UpdateFrameMetaData(
34 const cc::CompositorFrameMetadata& frame_metadata) = 0;
Ben Murdochca12bfa2013-07-23 11:17:05 +010035 virtual void DidActivatePendingTree() = 0;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010036
37 protected:
38 SynchronousCompositorOutputSurfaceDelegate() {}
39 virtual ~SynchronousCompositorOutputSurfaceDelegate() {}
40};
41
42// Specialization of the output surface that adapts it to implement the
43// content::SynchronousCompositor public API. This class effects an "inversion
44// of control" - enabling drawing to be orchestrated by the embedding
45// layer, instead of driven by the compositor internals - hence it holds two
46// 'client' pointers (|client_| in the OutputSurface baseclass and
47// GetDelegate()) which represent the consumers of the two roles in plays.
48// This class can be created only on the main thread, but then becomes pinned
49// to a fixed thread when BindToClient is called.
50class SynchronousCompositorOutputSurface
51 : NON_EXPORTED_BASE(public cc::OutputSurface) {
52 public:
53 explicit SynchronousCompositorOutputSurface(int routing_id);
54 virtual ~SynchronousCompositorOutputSurface();
55
56 // OutputSurface.
57 virtual bool ForcedDrawToSoftwareDevice() const OVERRIDE;
58 virtual bool BindToClient(cc::OutputSurfaceClient* surface_client) OVERRIDE;
59 virtual void Reshape(gfx::Size size, float scale_factor) OVERRIDE;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010060 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE;
Torne (Richard Coles)5e3f23d2013-06-11 16:24:11 +010061 virtual void SwapBuffers(cc::CompositorFrame* frame) OVERRIDE;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010062
63 // Partial SynchronousCompositor API implementation.
Ben Murdochbb1529c2013-08-08 10:24:53 +010064 bool InitializeHwDraw(
65 scoped_refptr<gfx::GLSurface> surface,
66 scoped_refptr<cc::ContextProvider> offscreen_context);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010067 void ReleaseHwDraw();
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010068 bool DemandDrawHw(gfx::Size surface_size,
69 const gfx::Transform& transform,
Ben Murdochfb250652013-07-31 11:42:55 +010070 gfx::Rect clip,
71 bool stencil_enabled);
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010072 bool DemandDrawSw(SkCanvas* canvas);
73
74 private:
75 class SoftwareDevice;
76 friend class SoftwareDevice;
77
Ben Murdocheb525c52013-07-10 11:40:50 +010078 // Private OutputSurface overrides.
79 virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE;
80
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010081 void InvokeComposite(gfx::Size damage_size);
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010082 bool CalledOnValidThread() const;
83 SynchronousCompositorOutputSurfaceDelegate* GetDelegate();
84
85 int routing_id_;
86 bool needs_begin_frame_;
Ben Murdocheb525c52013-07-10 11:40:50 +010087 bool invoking_composite_;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010088 bool did_swap_buffer_;
89
90 // Only valid (non-NULL) during a DemandDrawSw() call.
91 SkCanvas* current_sw_canvas_;
92
93 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorOutputSurface);
94};
95
96} // namespace content
97
98#endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_