Compute if a layer is clipped outside CalcDrawProps
[chromium-blink-merge.git] / cc / output / output_surface.h
blob423dc6317c37397664ceeeb336dd4109c0612902
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 draw_and_swap_full_viewport_every_frame(false),
69 adjust_deadline_for_parent(true),
70 uses_default_gl_framebuffer(true),
71 flipped_output_surface(false),
72 can_force_reclaim_resources(false),
73 delegated_sync_points_required(true) {}
74 bool delegated_rendering;
75 int max_frames_pending;
76 bool draw_and_swap_full_viewport_every_frame;
77 // This doesn't handle the <webview> case, but once BeginFrame is
78 // supported natively, we shouldn't need adjust_deadline_for_parent.
79 bool adjust_deadline_for_parent;
80 // Whether this output surface renders to the default OpenGL zero
81 // framebuffer or to an offscreen framebuffer.
82 bool uses_default_gl_framebuffer;
83 // Whether this OutputSurface is flipped or not.
84 bool flipped_output_surface;
85 // Whether ForceReclaimResources can be called to reclaim all resources
86 // from the OutputSurface.
87 bool can_force_reclaim_resources;
88 // True if sync points for resources are needed when swapping delegated
89 // frames.
90 bool delegated_sync_points_required;
93 const Capabilities& capabilities() const {
94 return capabilities_;
97 virtual bool HasExternalStencilTest() const;
99 // Obtain the 3d context or the software device associated with this output
100 // surface. Either of these may return a null pointer, but not both.
101 // In the event of a lost context, the entire output surface should be
102 // recreated.
103 ContextProvider* context_provider() const { return context_provider_.get(); }
104 ContextProvider* worker_context_provider() const {
105 return worker_context_provider_.get();
107 SoftwareOutputDevice* software_device() const {
108 return software_device_.get();
111 // Called by the compositor on the compositor thread. This is a place where
112 // thread-specific data for the output surface can be initialized, since from
113 // this point on the output surface will only be used on the compositor
114 // thread.
115 virtual bool BindToClient(OutputSurfaceClient* client);
117 virtual void EnsureBackbuffer();
118 virtual void DiscardBackbuffer();
120 virtual void Reshape(const gfx::Size& size, float scale_factor);
121 virtual gfx::Size SurfaceSize() const;
123 // If supported, this causes a ReclaimResources for all resources that are
124 // currently in use.
125 virtual void ForceReclaimResources() {}
127 virtual void BindFramebuffer();
129 // The implementation may destroy or steal the contents of the CompositorFrame
130 // passed in (though it will not take ownership of the CompositorFrame
131 // itself). For successful swaps, the implementation must call
132 // OutputSurfaceClient::DidSwapBuffers() and eventually
133 // DidSwapBuffersComplete().
134 virtual void SwapBuffers(CompositorFrame* frame) = 0;
135 virtual void OnSwapBuffersComplete();
137 // Notifies frame-rate smoothness preference. If true, all non-critical
138 // processing should be stopped, or lowered in priority.
139 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {}
141 bool HasClient() { return !!client_; }
143 // Get the class capable of informing cc of hardware overlay capability.
144 virtual OverlayCandidateValidator* GetOverlayCandidateValidator() const;
146 void DidLoseOutputSurface();
147 void SetMemoryPolicy(const ManagedMemoryPolicy& policy);
149 // Support for a pull-model where draws are requested by the output surface.
151 // OutputSurface::Invalidate is called by the compositor to notify that
152 // there's new content.
153 virtual void Invalidate() {}
155 // Updates the worker context provider's visibility, freeing GPU resources if
156 // appropriate.
157 virtual void SetWorkerContextShouldAggressivelyFreeResources(bool is_visible);
159 // If this returns true, then the surface will not attempt to draw.
160 virtual bool SurfaceIsSuspendForRecycle() const;
162 protected:
163 OutputSurfaceClient* client_;
165 void PostSwapBuffersComplete();
167 struct OutputSurface::Capabilities capabilities_;
168 scoped_refptr<ContextProvider> context_provider_;
169 scoped_refptr<ContextProvider> worker_context_provider_;
170 scoped_ptr<SoftwareOutputDevice> software_device_;
171 gfx::Size surface_size_;
172 float device_scale_factor_;
174 void CommitVSyncParameters(base::TimeTicks timebase,
175 base::TimeDelta interval);
177 void SetNeedsRedrawRect(const gfx::Rect& damage_rect);
178 void ReclaimResources(const CompositorFrameAck* ack);
179 void SetExternalStencilTest(bool enabled);
180 void SetExternalDrawConstraints(
181 const gfx::Transform& transform,
182 const gfx::Rect& viewport,
183 const gfx::Rect& clip,
184 const gfx::Rect& viewport_rect_for_tile_priority,
185 const gfx::Transform& transform_for_tile_priority,
186 bool resourceless_software_draw);
188 private:
189 bool external_stencil_test_enabled_;
191 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_;
193 DISALLOW_COPY_AND_ASSIGN(OutputSurface);
196 } // namespace cc
198 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_