Adding Peter Thatcher to the owners file.
[chromium-blink-merge.git] / cc / output / output_surface.h
blobb72f7fd5571dbe634a330f7788504b5abc9bfffb
1 // Copyright 2012 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 CC_OUTPUT_OUTPUT_SURFACE_H_
6 #define CC_OUTPUT_OUTPUT_SURFACE_H_
8 #include <deque>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "cc/base/cc_export.h"
15 #include "cc/output/context_provider.h"
16 #include "cc/output/overlay_candidate_validator.h"
17 #include "cc/output/software_output_device.h"
19 namespace base { class SingleThreadTaskRunner; }
21 namespace ui { struct LatencyInfo; }
23 namespace gfx {
24 class Rect;
25 class Size;
26 class Transform;
29 namespace cc {
31 class CompositorFrame;
32 class CompositorFrameAck;
33 struct ManagedMemoryPolicy;
34 class OutputSurfaceClient;
36 // Represents the output surface for a compositor. The compositor owns
37 // and manages its destruction. Its lifetime is:
38 // 1. Created on the main thread by the LayerTreeHost through its client.
39 // 2. Passed to the compositor thread and bound to a client via BindToClient.
40 // From here on, it will only be used on the compositor thread.
41 // 3. If the 3D context is lost, then the compositor will delete the output
42 // surface (on the compositor thread) and go back to step 1.
43 class CC_EXPORT OutputSurface {
44 public:
45 enum {
46 DEFAULT_MAX_FRAMES_PENDING = 2
49 OutputSurface(const scoped_refptr<ContextProvider>& context_provider,
50 const scoped_refptr<ContextProvider>& worker_context_provider,
51 scoped_ptr<SoftwareOutputDevice> software_device);
52 OutputSurface(const scoped_refptr<ContextProvider>& context_provider,
53 const scoped_refptr<ContextProvider>& worker_context_provider);
54 explicit OutputSurface(
55 const scoped_refptr<ContextProvider>& context_provider);
57 explicit OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device);
59 OutputSurface(const scoped_refptr<ContextProvider>& context_provider,
60 scoped_ptr<SoftwareOutputDevice> software_device);
62 virtual ~OutputSurface();
64 struct Capabilities {
65 Capabilities()
66 : delegated_rendering(false),
67 max_frames_pending(0),
68 deferred_gl_initialization(false),
69 draw_and_swap_full_viewport_every_frame(false),
70 adjust_deadline_for_parent(true),
71 uses_default_gl_framebuffer(true),
72 flipped_output_surface(false),
73 can_force_reclaim_resources(false) {}
74 bool delegated_rendering;
75 int max_frames_pending;
76 bool deferred_gl_initialization;
77 bool draw_and_swap_full_viewport_every_frame;
78 // This doesn't handle the <webview> case, but once BeginFrame is
79 // supported natively, we shouldn't need adjust_deadline_for_parent.
80 bool adjust_deadline_for_parent;
81 // Whether this output surface renders to the default OpenGL zero
82 // framebuffer or to an offscreen framebuffer.
83 bool uses_default_gl_framebuffer;
84 // Whether this OutputSurface is flipped or not.
85 bool flipped_output_surface;
86 // Whether ForceReclaimResources can be called to reclaim all resources
87 // from the OutputSurface.
88 bool can_force_reclaim_resources;
91 const Capabilities& capabilities() const {
92 return capabilities_;
95 virtual bool HasExternalStencilTest() const;
97 // Obtain the 3d context or the software device associated with this output
98 // surface. Either of these may return a null pointer, but not both.
99 // In the event of a lost context, the entire output surface should be
100 // recreated.
101 ContextProvider* context_provider() const { return context_provider_.get(); }
102 ContextProvider* worker_context_provider() const {
103 return worker_context_provider_.get();
105 SoftwareOutputDevice* software_device() const {
106 return software_device_.get();
109 // Called by the compositor on the compositor thread. This is a place where
110 // thread-specific data for the output surface can be initialized, since from
111 // this point on the output surface will only be used on the compositor
112 // thread.
113 virtual bool BindToClient(OutputSurfaceClient* client);
115 // This is called by the compositor on the compositor thread inside ReleaseGL
116 // in order to release the ContextProvider. Only used with
117 // deferred_gl_initialization capability.
118 void ReleaseContextProvider();
120 virtual void EnsureBackbuffer();
121 virtual void DiscardBackbuffer();
123 virtual void Reshape(const gfx::Size& size, float scale_factor);
124 virtual gfx::Size SurfaceSize() const;
126 // If supported, this causes a ReclaimResources for all resources that are
127 // currently in use.
128 virtual void ForceReclaimResources() {}
130 virtual void BindFramebuffer();
132 // The implementation may destroy or steal the contents of the CompositorFrame
133 // passed in (though it will not take ownership of the CompositorFrame
134 // itself). For successful swaps, the implementation must call
135 // OutputSurfaceClient::DidSwapBuffers() and eventually
136 // DidSwapBuffersComplete().
137 virtual void SwapBuffers(CompositorFrame* frame) = 0;
138 virtual void OnSwapBuffersComplete();
140 // Notifies frame-rate smoothness preference. If true, all non-critical
141 // processing should be stopped, or lowered in priority.
142 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {}
144 bool HasClient() { return !!client_; }
146 // Get the class capable of informing cc of hardware overlay capability.
147 OverlayCandidateValidator* overlay_candidate_validator() const {
148 return overlay_candidate_validator_.get();
151 void DidLoseOutputSurface();
152 void SetMemoryPolicy(const ManagedMemoryPolicy& policy);
154 // Support for a pull-model where draws are requested by the output surface.
156 // OutputSurface::Invalidate is called by the compositor to notify that
157 // there's new content.
158 virtual void Invalidate() {}
160 protected:
161 OutputSurfaceClient* client_;
163 // Synchronously initialize context3d and enter hardware mode.
164 // This can only supported in threaded compositing mode.
165 bool InitializeAndSetContext3d(
166 scoped_refptr<ContextProvider> context_provider,
167 scoped_refptr<ContextProvider> worker_context_provider);
168 void ReleaseGL();
170 void PostSwapBuffersComplete();
172 struct OutputSurface::Capabilities capabilities_;
173 scoped_refptr<ContextProvider> context_provider_;
174 scoped_refptr<ContextProvider> worker_context_provider_;
175 scoped_ptr<SoftwareOutputDevice> software_device_;
176 scoped_ptr<OverlayCandidateValidator> overlay_candidate_validator_;
177 gfx::Size surface_size_;
178 float device_scale_factor_;
180 void CommitVSyncParameters(base::TimeTicks timebase,
181 base::TimeDelta interval);
183 void SetNeedsRedrawRect(const gfx::Rect& damage_rect);
184 void ReclaimResources(const CompositorFrameAck* ack);
185 void SetExternalStencilTest(bool enabled);
186 void SetExternalDrawConstraints(
187 const gfx::Transform& transform,
188 const gfx::Rect& viewport,
189 const gfx::Rect& clip,
190 const gfx::Rect& viewport_rect_for_tile_priority,
191 const gfx::Transform& transform_for_tile_priority,
192 bool resourceless_software_draw);
194 private:
195 void SetUpContext3d();
196 void ResetContext3d();
198 bool external_stencil_test_enabled_;
200 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_;
202 DISALLOW_COPY_AND_ASSIGN(OutputSurface);
205 } // namespace cc
207 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_