Revert of Linux MSan: enable swarming/sharding for browser_tests. (patchset #1 id...
[chromium-blink-merge.git] / cc / output / output_surface.h
blob29e32a5317ef3c61f2b329f6a390d1eb0d0f115f
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 explicit OutputSurface(
50 const scoped_refptr<ContextProvider>& context_provider);
52 explicit OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device);
54 OutputSurface(const scoped_refptr<ContextProvider>& context_provider,
55 scoped_ptr<SoftwareOutputDevice> software_device);
57 virtual ~OutputSurface();
59 struct Capabilities {
60 Capabilities()
61 : delegated_rendering(false),
62 max_frames_pending(0),
63 deferred_gl_initialization(false),
64 draw_and_swap_full_viewport_every_frame(false),
65 adjust_deadline_for_parent(true),
66 uses_default_gl_framebuffer(true),
67 flipped_output_surface(false),
68 can_force_reclaim_resources(false) {}
69 bool delegated_rendering;
70 int max_frames_pending;
71 bool deferred_gl_initialization;
72 bool draw_and_swap_full_viewport_every_frame;
73 // This doesn't handle the <webview> case, but once BeginFrame is
74 // supported natively, we shouldn't need adjust_deadline_for_parent.
75 bool adjust_deadline_for_parent;
76 // Whether this output surface renders to the default OpenGL zero
77 // framebuffer or to an offscreen framebuffer.
78 bool uses_default_gl_framebuffer;
79 // Whether this OutputSurface is flipped or not.
80 bool flipped_output_surface;
81 // Whether ForceReclaimResources can be called to reclaim all resources
82 // from the OutputSurface.
83 bool can_force_reclaim_resources;
86 const Capabilities& capabilities() const {
87 return capabilities_;
90 virtual bool HasExternalStencilTest() const;
92 // Obtain the 3d context or the software device associated with this output
93 // surface. Either of these may return a null pointer, but not both.
94 // In the event of a lost context, the entire output surface should be
95 // recreated.
96 ContextProvider* context_provider() const { return context_provider_.get(); }
97 SoftwareOutputDevice* software_device() const {
98 return software_device_.get();
101 // Called by the compositor on the compositor thread. This is a place where
102 // thread-specific data for the output surface can be initialized, since from
103 // this point on the output surface will only be used on the compositor
104 // thread.
105 virtual bool BindToClient(OutputSurfaceClient* client);
107 // This is called by the compositor on the compositor thread inside ReleaseGL
108 // in order to release the ContextProvider. Only used with
109 // deferred_gl_initialization capability.
110 void ReleaseContextProvider();
112 virtual void EnsureBackbuffer();
113 virtual void DiscardBackbuffer();
115 virtual void Reshape(const gfx::Size& size, float scale_factor);
116 virtual gfx::Size SurfaceSize() const;
118 // If supported, this causes a ReclaimResources for all resources that are
119 // currently in use.
120 virtual void ForceReclaimResources() {}
122 virtual void BindFramebuffer();
124 // The implementation may destroy or steal the contents of the CompositorFrame
125 // passed in (though it will not take ownership of the CompositorFrame
126 // itself). For successful swaps, the implementation must call
127 // OutputSurfaceClient::DidSwapBuffers() and eventually
128 // DidSwapBuffersComplete().
129 virtual void SwapBuffers(CompositorFrame* frame) = 0;
130 virtual void OnSwapBuffersComplete();
132 // Notifies frame-rate smoothness preference. If true, all non-critical
133 // processing should be stopped, or lowered in priority.
134 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {}
136 bool HasClient() { return !!client_; }
138 // Get the class capable of informing cc of hardware overlay capability.
139 OverlayCandidateValidator* overlay_candidate_validator() const {
140 return overlay_candidate_validator_.get();
143 void DidLoseOutputSurface();
144 void SetMemoryPolicy(const ManagedMemoryPolicy& policy);
146 protected:
147 OutputSurfaceClient* client_;
149 // Synchronously initialize context3d and enter hardware mode.
150 // This can only supported in threaded compositing mode.
151 bool InitializeAndSetContext3d(
152 scoped_refptr<ContextProvider> context_provider);
153 void ReleaseGL();
155 void PostSwapBuffersComplete();
157 struct OutputSurface::Capabilities capabilities_;
158 scoped_refptr<ContextProvider> context_provider_;
159 scoped_ptr<SoftwareOutputDevice> software_device_;
160 scoped_ptr<OverlayCandidateValidator> overlay_candidate_validator_;
161 gfx::Size surface_size_;
162 float device_scale_factor_;
164 void CommitVSyncParameters(base::TimeTicks timebase,
165 base::TimeDelta interval);
167 void SetNeedsRedrawRect(const gfx::Rect& damage_rect);
168 void ReclaimResources(const CompositorFrameAck* ack);
169 void SetExternalStencilTest(bool enabled);
170 void SetExternalDrawConstraints(
171 const gfx::Transform& transform,
172 const gfx::Rect& viewport,
173 const gfx::Rect& clip,
174 const gfx::Rect& viewport_rect_for_tile_priority,
175 const gfx::Transform& transform_for_tile_priority,
176 bool resourceless_software_draw);
178 private:
179 void SetUpContext3d();
180 void ResetContext3d();
182 bool external_stencil_test_enabled_;
184 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_;
186 DISALLOW_COPY_AND_ASSIGN(OutputSurface);
189 } // namespace cc
191 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_