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" |
15 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 16 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
16 | 17 |
17 namespace ui { struct LatencyInfo; } | 18 namespace ui { struct LatencyInfo; } |
18 | 19 |
19 namespace gfx { | 20 namespace gfx { |
20 class Rect; | 21 class Rect; |
21 class Size; | 22 class Size; |
| 23 class Transform; |
22 } | 24 } |
23 | 25 |
24 namespace cc { | 26 namespace cc { |
25 | 27 |
26 class CompositorFrame; | 28 class CompositorFrame; |
| 29 class CompositorFrameAck; |
27 class OutputSurfaceClient; | 30 class OutputSurfaceClient; |
28 class OutputSurfaceCallbacks; | 31 class OutputSurfaceCallbacks; |
| 32 class Thread; |
29 | 33 |
30 // Represents the output surface for a compositor. The compositor owns | 34 // Represents the output surface for a compositor. The compositor owns |
31 // and manages its destruction. Its lifetime is: | 35 // and manages its destruction. Its lifetime is: |
32 // 1. Created on the main thread by the LayerTreeHost through its client. | 36 // 1. Created on the main thread by the LayerTreeHost through its client. |
33 // 2. Passed to the compositor thread and bound to a client via BindToClient. | 37 // 2. Passed to the compositor thread and bound to a client via BindToClient. |
34 // From here on, it will only be used on the compositor thread. | 38 // From here on, it will only be used on the compositor thread. |
35 // 3. If the 3D context is lost, then the compositor will delete the output | 39 // 3. If the 3D context is lost, then the compositor will delete the output |
36 // surface (on the compositor thread) and go back to step 1. | 40 // surface (on the compositor thread) and go back to step 1. |
37 class CC_EXPORT OutputSurface { | 41 class CC_EXPORT OutputSurface : public FrameRateControllerClient { |
38 public: | 42 public: |
39 explicit OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d); | 43 explicit OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d); |
40 | 44 |
41 explicit OutputSurface(scoped_ptr<cc::SoftwareOutputDevice> software_device); | 45 explicit OutputSurface(scoped_ptr<cc::SoftwareOutputDevice> software_device); |
42 | 46 |
43 OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d, | 47 OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d, |
44 scoped_ptr<cc::SoftwareOutputDevice> software_device); | 48 scoped_ptr<cc::SoftwareOutputDevice> software_device); |
45 | 49 |
46 virtual ~OutputSurface(); | 50 virtual ~OutputSurface(); |
47 | 51 |
(...skipping 28 matching lines...) Expand all Loading... |
76 // (namely Android WebView), this is called to determine whether the software | 80 // (namely Android WebView), this is called to determine whether the software |
77 // device should be used on the current frame. | 81 // device should be used on the current frame. |
78 virtual bool ForcedDrawToSoftwareDevice() const; | 82 virtual bool ForcedDrawToSoftwareDevice() const; |
79 | 83 |
80 // Called by the compositor on the compositor thread. This is a place where | 84 // Called by the compositor on the compositor thread. This is a place where |
81 // thread-specific data for the output surface can be initialized, since from | 85 // thread-specific data for the output surface can be initialized, since from |
82 // this point on the output surface will only be used on the compositor | 86 // this point on the output surface will only be used on the compositor |
83 // thread. | 87 // thread. |
84 virtual bool BindToClient(OutputSurfaceClient* client); | 88 virtual bool BindToClient(OutputSurfaceClient* client); |
85 | 89 |
| 90 void InitializeBeginFrameEmulation( |
| 91 Thread* thread, |
| 92 bool throttle_frame_production, |
| 93 base::TimeDelta interval); |
| 94 |
| 95 void SetMaxFramesPending(int max_frames_pending); |
| 96 |
86 virtual void EnsureBackbuffer(); | 97 virtual void EnsureBackbuffer(); |
87 virtual void DiscardBackbuffer(); | 98 virtual void DiscardBackbuffer(); |
88 | 99 |
89 virtual void Reshape(gfx::Size size, float scale_factor); | 100 virtual void Reshape(gfx::Size size, float scale_factor); |
90 virtual gfx::Size SurfaceSize() const; | 101 virtual gfx::Size SurfaceSize() const; |
91 | 102 |
92 virtual void BindFramebuffer(); | 103 virtual void BindFramebuffer(); |
93 | 104 |
94 // The implementation may destroy or steal the contents of the CompositorFrame | 105 // The implementation may destroy or steal the contents of the CompositorFrame |
95 // passed in (though it will not take ownership of the CompositorFrame | 106 // passed in (though it will not take ownership of the CompositorFrame |
96 // itself). | 107 // itself). |
97 virtual void SwapBuffers(CompositorFrame* frame); | 108 virtual void SwapBuffers(CompositorFrame* frame); |
98 | 109 |
99 // Notifies frame-rate smoothness preference. If true, all non-critical | 110 // Notifies frame-rate smoothness preference. If true, all non-critical |
100 // processing should be stopped, or lowered in priority. | 111 // processing should be stopped, or lowered in priority. |
101 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {} | 112 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {} |
102 | 113 |
103 // Requests a BeginFrame notification from the output surface. The | 114 // Requests a BeginFrame notification from the output surface. The |
104 // notification will be delivered by calling | 115 // notification will be delivered by calling |
105 // OutputSurfaceClient::BeginFrame until the callback is disabled. | 116 // OutputSurfaceClient::BeginFrame until the callback is disabled. |
106 virtual void SetNeedsBeginFrame(bool enable) {} | 117 virtual void SetNeedsBeginFrame(bool enable); |
107 | 118 |
108 protected: | 119 protected: |
109 // Synchronously initialize context3d and enter hardware mode. | 120 // Synchronously initialize context3d and enter hardware mode. |
110 // This can only supported in threaded compositing mode. | 121 // This can only supported in threaded compositing mode. |
111 // |offscreen_context_provider| should match what is returned by | 122 // |offscreen_context_provider| should match what is returned by |
112 // LayerTreeClient::OffscreenContextProviderForCompositorThread. | 123 // LayerTreeClient::OffscreenContextProviderForCompositorThread. |
113 bool InitializeAndSetContext3D( | 124 bool InitializeAndSetContext3D( |
114 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, | 125 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, |
115 scoped_refptr<ContextProvider> offscreen_context_provider); | 126 scoped_refptr<ContextProvider> offscreen_context_provider); |
116 | 127 |
117 void PostSwapBuffersComplete(); | 128 void PostSwapBuffersComplete(); |
118 | 129 |
119 OutputSurfaceClient* client_; | |
120 struct cc::OutputSurface::Capabilities capabilities_; | 130 struct cc::OutputSurface::Capabilities capabilities_; |
121 scoped_ptr<OutputSurfaceCallbacks> callbacks_; | 131 scoped_ptr<OutputSurfaceCallbacks> callbacks_; |
122 scoped_ptr<WebKit::WebGraphicsContext3D> context3d_; | 132 scoped_ptr<WebKit::WebGraphicsContext3D> context3d_; |
123 scoped_ptr<cc::SoftwareOutputDevice> software_device_; | 133 scoped_ptr<cc::SoftwareOutputDevice> software_device_; |
124 bool has_gl_discard_backbuffer_; | 134 bool has_gl_discard_backbuffer_; |
125 bool has_swap_buffers_complete_callback_; | 135 bool has_swap_buffers_complete_callback_; |
126 gfx::Size surface_size_; | 136 gfx::Size surface_size_; |
127 float device_scale_factor_; | 137 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); |
128 | 160 |
129 private: | 161 private: |
| 162 OutputSurfaceClient* client_; |
| 163 friend class OutputSurfaceCallbacks; |
| 164 |
130 void SetContext3D(scoped_ptr<WebKit::WebGraphicsContext3D> context3d); | 165 void SetContext3D(scoped_ptr<WebKit::WebGraphicsContext3D> context3d); |
131 void SwapBuffersComplete(); | |
132 | |
133 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; | |
134 | 166 |
135 DISALLOW_COPY_AND_ASSIGN(OutputSurface); | 167 DISALLOW_COPY_AND_ASSIGN(OutputSurface); |
136 }; | 168 }; |
137 | 169 |
138 } // namespace cc | 170 } // namespace cc |
139 | 171 |
140 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ | 172 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ |
OLD | NEW |