Add ICU message format support
[chromium-blink-merge.git] / cc / output / output_surface.h
blob7d0a5d97a15823b91785afbf82bda91b9bae429a
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 {
22 class LatencyInfo;
25 namespace gfx {
26 class Rect;
27 class Size;
28 class Transform;
31 namespace cc {
33 class CompositorFrame;
34 class CompositorFrameAck;
35 struct ManagedMemoryPolicy;
36 class OutputSurfaceClient;
38 // Represents the output surface for a compositor. The compositor owns
39 // and manages its destruction. Its lifetime is:
40 // 1. Created on the main thread by the LayerTreeHost through its client.
41 // 2. Passed to the compositor thread and bound to a client via BindToClient.
42 // From here on, it will only be used on the compositor thread.
43 // 3. If the 3D context is lost, then the compositor will delete the output
44 // surface (on the compositor thread) and go back to step 1.
45 class CC_EXPORT OutputSurface {
46 public:
47 enum {
48 DEFAULT_MAX_FRAMES_PENDING = 2
51 OutputSurface(const scoped_refptr<ContextProvider>& context_provider,
52 const scoped_refptr<ContextProvider>& worker_context_provider,
53 scoped_ptr<SoftwareOutputDevice> software_device);
54 OutputSurface(const scoped_refptr<ContextProvider>& context_provider,
55 const scoped_refptr<ContextProvider>& worker_context_provider);
56 explicit OutputSurface(
57 const scoped_refptr<ContextProvider>& context_provider);
59 explicit OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device);
61 OutputSurface(const scoped_refptr<ContextProvider>& context_provider,
62 scoped_ptr<SoftwareOutputDevice> software_device);
64 virtual ~OutputSurface();
66 struct Capabilities {
67 Capabilities()
68 : delegated_rendering(false),
69 max_frames_pending(0),
70 draw_and_swap_full_viewport_every_frame(false),
71 adjust_deadline_for_parent(true),
72 uses_default_gl_framebuffer(true),
73 flipped_output_surface(false),
74 can_force_reclaim_resources(false),
75 delegated_sync_points_required(true) {}
76 bool delegated_rendering;
77 int max_frames_pending;
78 bool draw_and_swap_full_viewport_every_frame;
79 // This doesn't handle the <webview> case, but once BeginFrame is
80 // supported natively, we shouldn't need adjust_deadline_for_parent.
81 bool adjust_deadline_for_parent;
82 // Whether this output surface renders to the default OpenGL zero
83 // framebuffer or to an offscreen framebuffer.
84 bool uses_default_gl_framebuffer;
85 // Whether this OutputSurface is flipped or not.
86 bool flipped_output_surface;
87 // Whether ForceReclaimResources can be called to reclaim all resources
88 // from the OutputSurface.
89 bool can_force_reclaim_resources;
90 // True if sync points for resources are needed when swapping delegated
91 // frames.
92 bool delegated_sync_points_required;
95 const Capabilities& capabilities() const {
96 return capabilities_;
99 virtual bool HasExternalStencilTest() const;
101 // Obtain the 3d context or the software device associated with this output
102 // surface. Either of these may return a null pointer, but not both.
103 // In the event of a lost context, the entire output surface should be
104 // recreated.
105 ContextProvider* context_provider() const { return context_provider_.get(); }
106 ContextProvider* worker_context_provider() const {
107 return worker_context_provider_.get();
109 SoftwareOutputDevice* software_device() const {
110 return software_device_.get();
113 // Called by the compositor on the compositor thread. This is a place where
114 // thread-specific data for the output surface can be initialized, since from
115 // this point on the output surface will only be used on the compositor
116 // thread.
117 virtual bool BindToClient(OutputSurfaceClient* client);
119 virtual void EnsureBackbuffer();
120 virtual void DiscardBackbuffer();
122 virtual void Reshape(const gfx::Size& size, float scale_factor);
123 virtual gfx::Size SurfaceSize() const;
125 // If supported, this causes a ReclaimResources for all resources that are
126 // currently in use.
127 virtual void ForceReclaimResources() {}
129 virtual void BindFramebuffer();
131 // The implementation may destroy or steal the contents of the CompositorFrame
132 // passed in (though it will not take ownership of the CompositorFrame
133 // itself). For successful swaps, the implementation must call
134 // OutputSurfaceClient::DidSwapBuffers() and eventually
135 // DidSwapBuffersComplete().
136 virtual void SwapBuffers(CompositorFrame* frame) = 0;
137 virtual void OnSwapBuffersComplete();
139 // Notifies frame-rate smoothness preference. If true, all non-critical
140 // processing should be stopped, or lowered in priority.
141 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {}
143 bool HasClient() { return !!client_; }
145 // Get the class capable of informing cc of hardware overlay capability.
146 virtual OverlayCandidateValidator* GetOverlayCandidateValidator() const;
148 void DidLoseOutputSurface();
149 void SetMemoryPolicy(const ManagedMemoryPolicy& policy);
151 // Support for a pull-model where draws are requested by the output surface.
153 // OutputSurface::Invalidate is called by the compositor to notify that
154 // there's new content.
155 virtual void Invalidate() {}
157 // Updates the worker context provider's visibility, freeing GPU resources if
158 // appropriate.
159 virtual void SetWorkerContextShouldAggressivelyFreeResources(bool is_visible);
161 // If this returns true, then the surface will not attempt to draw.
162 virtual bool SurfaceIsSuspendForRecycle() const;
164 protected:
165 OutputSurfaceClient* client_;
167 void PostSwapBuffersComplete();
169 struct OutputSurface::Capabilities capabilities_;
170 scoped_refptr<ContextProvider> context_provider_;
171 scoped_refptr<ContextProvider> worker_context_provider_;
172 scoped_ptr<SoftwareOutputDevice> software_device_;
173 gfx::Size surface_size_;
174 float device_scale_factor_;
176 void CommitVSyncParameters(base::TimeTicks timebase,
177 base::TimeDelta interval);
179 void SetNeedsRedrawRect(const gfx::Rect& damage_rect);
180 void ReclaimResources(const CompositorFrameAck* ack);
181 void SetExternalStencilTest(bool enabled);
182 void SetExternalDrawConstraints(
183 const gfx::Transform& transform,
184 const gfx::Rect& viewport,
185 const gfx::Rect& clip,
186 const gfx::Rect& viewport_rect_for_tile_priority,
187 const gfx::Transform& transform_for_tile_priority,
188 bool resourceless_software_draw);
190 private:
191 bool external_stencil_test_enabled_;
193 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_;
195 DISALLOW_COPY_AND_ASSIGN(OutputSurface);
198 } // namespace cc
200 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_