OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_OUTPUT_OUTPUT_SURFACE_H_ | 5 #ifndef CC_OUTPUT_OUTPUT_SURFACE_H_ |
6 #define CC_OUTPUT_OUTPUT_SURFACE_H_ | 6 #define CC_OUTPUT_OUTPUT_SURFACE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "cc/base/cc_export.h" | 12 #include "cc/base/cc_export.h" |
13 #include "cc/output/context_provider.h" | 13 #include "cc/output/context_provider.h" |
14 #include "cc/output/software_output_device.h" | 14 #include "cc/output/software_output_device.h" |
15 #include "cc/scheduler/frame_rate_controller.h" | |
16 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 15 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
17 | 16 |
18 namespace ui { struct LatencyInfo; } | 17 namespace ui { struct LatencyInfo; } |
19 | 18 |
20 namespace gfx { | 19 namespace gfx { |
21 class Rect; | 20 class Rect; |
22 class Size; | 21 class Size; |
23 class Transform; | |
24 } | 22 } |
25 | 23 |
26 namespace cc { | 24 namespace cc { |
27 | 25 |
28 class CompositorFrame; | 26 class CompositorFrame; |
29 class CompositorFrameAck; | |
30 class OutputSurfaceClient; | 27 class OutputSurfaceClient; |
31 class OutputSurfaceCallbacks; | 28 class OutputSurfaceCallbacks; |
32 class Thread; | |
33 | 29 |
34 // Represents the output surface for a compositor. The compositor owns | 30 // Represents the output surface for a compositor. The compositor owns |
35 // and manages its destruction. Its lifetime is: | 31 // and manages its destruction. Its lifetime is: |
36 // 1. Created on the main thread by the LayerTreeHost through its client. | 32 // 1. Created on the main thread by the LayerTreeHost through its client. |
37 // 2. Passed to the compositor thread and bound to a client via BindToClient. | 33 // 2. Passed to the compositor thread and bound to a client via BindToClient. |
38 // From here on, it will only be used on the compositor thread. | 34 // From here on, it will only be used on the compositor thread. |
39 // 3. If the 3D context is lost, then the compositor will delete the output | 35 // 3. If the 3D context is lost, then the compositor will delete the output |
40 // surface (on the compositor thread) and go back to step 1. | 36 // surface (on the compositor thread) and go back to step 1. |
41 class CC_EXPORT OutputSurface : public FrameRateControllerClient { | 37 class CC_EXPORT OutputSurface { |
42 public: | 38 public: |
43 explicit OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d); | 39 explicit OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d); |
44 | 40 |
45 explicit OutputSurface(scoped_ptr<cc::SoftwareOutputDevice> software_device); | 41 explicit OutputSurface(scoped_ptr<cc::SoftwareOutputDevice> software_device); |
46 | 42 |
47 OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d, | 43 OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d, |
48 scoped_ptr<cc::SoftwareOutputDevice> software_device); | 44 scoped_ptr<cc::SoftwareOutputDevice> software_device); |
49 | 45 |
50 virtual ~OutputSurface(); | 46 virtual ~OutputSurface(); |
51 | 47 |
(...skipping 28 matching lines...) Expand all Loading... |
80 // (namely Android WebView), this is called to determine whether the software | 76 // (namely Android WebView), this is called to determine whether the software |
81 // device should be used on the current frame. | 77 // device should be used on the current frame. |
82 virtual bool ForcedDrawToSoftwareDevice() const; | 78 virtual bool ForcedDrawToSoftwareDevice() const; |
83 | 79 |
84 // Called by the compositor on the compositor thread. This is a place where | 80 // Called by the compositor on the compositor thread. This is a place where |
85 // thread-specific data for the output surface can be initialized, since from | 81 // thread-specific data for the output surface can be initialized, since from |
86 // this point on the output surface will only be used on the compositor | 82 // this point on the output surface will only be used on the compositor |
87 // thread. | 83 // thread. |
88 virtual bool BindToClient(OutputSurfaceClient* client); | 84 virtual bool BindToClient(OutputSurfaceClient* client); |
89 | 85 |
90 void InitializeBeginFrameEmulation( | |
91 Thread* thread, | |
92 bool throttle_frame_production, | |
93 base::TimeDelta interval); | |
94 | |
95 void SetMaxFramesPending(int max_frames_pending); | |
96 | |
97 virtual void EnsureBackbuffer(); | 86 virtual void EnsureBackbuffer(); |
98 virtual void DiscardBackbuffer(); | 87 virtual void DiscardBackbuffer(); |
99 | 88 |
100 virtual void Reshape(gfx::Size size, float scale_factor); | 89 virtual void Reshape(gfx::Size size, float scale_factor); |
101 virtual gfx::Size SurfaceSize() const; | 90 virtual gfx::Size SurfaceSize() const; |
102 | 91 |
103 virtual void BindFramebuffer(); | 92 virtual void BindFramebuffer(); |
104 | 93 |
105 // The implementation may destroy or steal the contents of the CompositorFrame | 94 // The implementation may destroy or steal the contents of the CompositorFrame |
106 // passed in (though it will not take ownership of the CompositorFrame | 95 // passed in (though it will not take ownership of the CompositorFrame |
107 // itself). | 96 // itself). |
108 virtual void SwapBuffers(CompositorFrame* frame); | 97 virtual void SwapBuffers(CompositorFrame* frame); |
109 | 98 |
110 // Notifies frame-rate smoothness preference. If true, all non-critical | 99 // Notifies frame-rate smoothness preference. If true, all non-critical |
111 // processing should be stopped, or lowered in priority. | 100 // processing should be stopped, or lowered in priority. |
112 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {} | 101 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {} |
113 | 102 |
114 // Requests a BeginFrame notification from the output surface. The | 103 // Requests a BeginFrame notification from the output surface. The |
115 // notification will be delivered by calling | 104 // notification will be delivered by calling |
116 // OutputSurfaceClient::BeginFrame until the callback is disabled. | 105 // OutputSurfaceClient::BeginFrame until the callback is disabled. |
117 virtual void SetNeedsBeginFrame(bool enable); | 106 virtual void SetNeedsBeginFrame(bool enable) {} |
118 | 107 |
119 protected: | 108 protected: |
120 // Synchronously initialize context3d and enter hardware mode. | 109 // Synchronously initialize context3d and enter hardware mode. |
121 // This can only supported in threaded compositing mode. | 110 // This can only supported in threaded compositing mode. |
122 // |offscreen_context_provider| should match what is returned by | 111 // |offscreen_context_provider| should match what is returned by |
123 // LayerTreeClient::OffscreenContextProviderForCompositorThread. | 112 // LayerTreeClient::OffscreenContextProviderForCompositorThread. |
124 bool InitializeAndSetContext3D( | 113 bool InitializeAndSetContext3D( |
125 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, | 114 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, |
126 scoped_refptr<ContextProvider> offscreen_context_provider); | 115 scoped_refptr<ContextProvider> offscreen_context_provider); |
127 | 116 |
128 void PostSwapBuffersComplete(); | 117 void PostSwapBuffersComplete(); |
129 | 118 |
| 119 OutputSurfaceClient* client_; |
130 struct cc::OutputSurface::Capabilities capabilities_; | 120 struct cc::OutputSurface::Capabilities capabilities_; |
131 scoped_ptr<OutputSurfaceCallbacks> callbacks_; | 121 scoped_ptr<OutputSurfaceCallbacks> callbacks_; |
132 scoped_ptr<WebKit::WebGraphicsContext3D> context3d_; | 122 scoped_ptr<WebKit::WebGraphicsContext3D> context3d_; |
133 scoped_ptr<cc::SoftwareOutputDevice> software_device_; | 123 scoped_ptr<cc::SoftwareOutputDevice> software_device_; |
134 bool has_gl_discard_backbuffer_; | 124 bool has_gl_discard_backbuffer_; |
135 bool has_swap_buffers_complete_callback_; | 125 bool has_swap_buffers_complete_callback_; |
136 gfx::Size surface_size_; | 126 gfx::Size surface_size_; |
137 float device_scale_factor_; | 127 float device_scale_factor_; |
138 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; | |
139 | |
140 // The FrameRateController is deprecated. | |
141 // Platforms should move to native BeginFrames instead. | |
142 void OnVSyncParametersChanged(base::TimeTicks timebase, | |
143 base::TimeDelta interval); | |
144 virtual void FrameRateControllerTick(bool throttled) OVERRIDE; | |
145 scoped_ptr<FrameRateController> frame_rate_controller_; | |
146 int max_frames_pending_; | |
147 int pending_swap_buffers_; | |
148 bool begin_frame_pending_; | |
149 | |
150 // Forwarded to OutputSurfaceClient but threaded through OutputSurface | |
151 // first so OutputSurface has a chance to update the FrameRateController | |
152 bool HasClient() { return !!client_; } | |
153 void SetNeedsRedrawRect(gfx::Rect damage_rect); | |
154 void BeginFrame(base::TimeTicks frame_time); | |
155 void DidSwapBuffers(); | |
156 void OnSwapBuffersComplete(const CompositorFrameAck* ack); | |
157 void DidLoseOutputSurface(); | |
158 void SetExternalDrawConstraints(const gfx::Transform& transform, | |
159 gfx::Rect viewport); | |
160 | 128 |
161 private: | 129 private: |
162 OutputSurfaceClient* client_; | 130 void SetContext3D(scoped_ptr<WebKit::WebGraphicsContext3D> context3d); |
163 friend class OutputSurfaceCallbacks; | 131 void SwapBuffersComplete(); |
164 | 132 |
165 void SetContext3D(scoped_ptr<WebKit::WebGraphicsContext3D> context3d); | 133 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; |
166 | 134 |
167 DISALLOW_COPY_AND_ASSIGN(OutputSurface); | 135 DISALLOW_COPY_AND_ASSIGN(OutputSurface); |
168 }; | 136 }; |
169 | 137 |
170 } // namespace cc | 138 } // namespace cc |
171 | 139 |
172 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ | 140 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ |
OLD | NEW |