| 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 "cc/scheduler/frame_rate_controller.h" |
| 16 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | |
| 17 | 16 |
| 18 namespace base { class SingleThreadTaskRunner; } | 17 namespace base { class SingleThreadTaskRunner; } |
| 19 | 18 |
| 20 namespace ui { struct LatencyInfo; } | 19 namespace ui { struct LatencyInfo; } |
| 21 | 20 |
| 22 namespace gfx { | 21 namespace gfx { |
| 23 class Rect; | 22 class Rect; |
| 24 class Size; | 23 class Size; |
| 25 class Transform; | 24 class Transform; |
| 26 } | 25 } |
| 27 | 26 |
| 28 namespace cc { | 27 namespace cc { |
| 29 | 28 |
| 30 class CompositorFrame; | 29 class CompositorFrame; |
| 31 class CompositorFrameAck; | 30 class CompositorFrameAck; |
| 32 struct ManagedMemoryPolicy; | 31 struct ManagedMemoryPolicy; |
| 33 class OutputSurfaceClient; | 32 class OutputSurfaceClient; |
| 34 class OutputSurfaceCallbacks; | |
| 35 | 33 |
| 36 // Represents the output surface for a compositor. The compositor owns | 34 // Represents the output surface for a compositor. The compositor owns |
| 37 // and manages its destruction. Its lifetime is: | 35 // and manages its destruction. Its lifetime is: |
| 38 // 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. |
| 39 // 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. |
| 40 // 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. |
| 41 // 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 |
| 42 // surface (on the compositor thread) and go back to step 1. | 40 // surface (on the compositor thread) and go back to step 1. |
| 43 class CC_EXPORT OutputSurface : public FrameRateControllerClient { | 41 class CC_EXPORT OutputSurface : public FrameRateControllerClient { |
| 44 public: | 42 public: |
| 45 enum { | 43 enum { |
| 46 DEFAULT_MAX_FRAMES_PENDING = 2 | 44 DEFAULT_MAX_FRAMES_PENDING = 2 |
| 47 }; | 45 }; |
| 48 | 46 |
| 49 explicit OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d); | 47 explicit OutputSurface(scoped_refptr<ContextProvider> context_provider); |
| 50 | 48 |
| 51 explicit OutputSurface(scoped_ptr<cc::SoftwareOutputDevice> software_device); | 49 explicit OutputSurface(scoped_ptr<cc::SoftwareOutputDevice> software_device); |
| 52 | 50 |
| 53 OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d, | 51 OutputSurface(scoped_refptr<ContextProvider> context_provider, |
| 54 scoped_ptr<cc::SoftwareOutputDevice> software_device); | 52 scoped_ptr<cc::SoftwareOutputDevice> software_device); |
| 55 | 53 |
| 56 virtual ~OutputSurface(); | 54 virtual ~OutputSurface(); |
| 57 | 55 |
| 58 struct Capabilities { | 56 struct Capabilities { |
| 59 Capabilities() | 57 Capabilities() |
| 60 : delegated_rendering(false), | 58 : delegated_rendering(false), |
| 61 max_frames_pending(0), | 59 max_frames_pending(0), |
| 62 deferred_gl_initialization(false), | 60 deferred_gl_initialization(false), |
| 63 draw_and_swap_full_viewport_every_frame(false), | 61 draw_and_swap_full_viewport_every_frame(false), |
| 64 adjust_deadline_for_parent(true) {} | 62 adjust_deadline_for_parent(true) {} |
| 65 bool delegated_rendering; | 63 bool delegated_rendering; |
| 66 int max_frames_pending; | 64 int max_frames_pending; |
| 67 bool deferred_gl_initialization; | 65 bool deferred_gl_initialization; |
| 68 bool draw_and_swap_full_viewport_every_frame; | 66 bool draw_and_swap_full_viewport_every_frame; |
| 69 // This doesn't handle the <webview> case, but once BeginFrame is | 67 // This doesn't handle the <webview> case, but once BeginFrame is |
| 70 // supported natively, we shouldn't need adjust_deadline_for_parent. | 68 // supported natively, we shouldn't need adjust_deadline_for_parent. |
| 71 bool adjust_deadline_for_parent; | 69 bool adjust_deadline_for_parent; |
| 72 }; | 70 }; |
| 73 | 71 |
| 74 const Capabilities& capabilities() const { | 72 const Capabilities& capabilities() const { |
| 75 return capabilities_; | 73 return capabilities_; |
| 76 } | 74 } |
| 77 | 75 |
| 78 // Obtain the 3d context or the software device associated with this output | 76 // Obtain the 3d context or the software device associated with this output |
| 79 // surface. Either of these may return a null pointer, but not both. | 77 // surface. Either of these may return a null pointer, but not both. |
| 80 // In the event of a lost context, the entire output surface should be | 78 // In the event of a lost context, the entire output surface should be |
| 81 // recreated. | 79 // recreated. |
| 82 WebKit::WebGraphicsContext3D* context3d() const { | 80 scoped_refptr<ContextProvider> context_provider() const { |
| 83 return context3d_.get(); | 81 return context_provider_.get(); |
| 84 } | 82 } |
| 85 | |
| 86 SoftwareOutputDevice* software_device() const { | 83 SoftwareOutputDevice* software_device() const { |
| 87 return software_device_.get(); | 84 return software_device_.get(); |
| 88 } | 85 } |
| 89 | 86 |
| 90 // In the case where both the context3d and software_device are present | 87 // In the case where both the context3d and software_device are present |
| 91 // (namely Android WebView), this is called to determine whether the software | 88 // (namely Android WebView), this is called to determine whether the software |
| 92 // device should be used on the current frame. | 89 // device should be used on the current frame. |
| 93 virtual bool ForcedDrawToSoftwareDevice() const; | 90 virtual bool ForcedDrawToSoftwareDevice() const; |
| 94 | 91 |
| 95 // Called by the compositor on the compositor thread. This is a place where | 92 // Called by the compositor on the compositor thread. This is a place where |
| (...skipping 24 matching lines...) Expand all Loading... |
| 120 | 117 |
| 121 // Notifies frame-rate smoothness preference. If true, all non-critical | 118 // Notifies frame-rate smoothness preference. If true, all non-critical |
| 122 // processing should be stopped, or lowered in priority. | 119 // processing should be stopped, or lowered in priority. |
| 123 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {} | 120 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {} |
| 124 | 121 |
| 125 // Requests a BeginFrame notification from the output surface. The | 122 // Requests a BeginFrame notification from the output surface. The |
| 126 // notification will be delivered by calling | 123 // notification will be delivered by calling |
| 127 // OutputSurfaceClient::BeginFrame until the callback is disabled. | 124 // OutputSurfaceClient::BeginFrame until the callback is disabled. |
| 128 virtual void SetNeedsBeginFrame(bool enable); | 125 virtual void SetNeedsBeginFrame(bool enable); |
| 129 | 126 |
| 127 bool HasClient() { return !!client_; } |
| 128 |
| 130 protected: | 129 protected: |
| 131 // Synchronously initialize context3d and enter hardware mode. | 130 // Synchronously initialize context3d and enter hardware mode. |
| 132 // This can only supported in threaded compositing mode. | 131 // This can only supported in threaded compositing mode. |
| 133 // |offscreen_context_provider| should match what is returned by | 132 // |offscreen_context_provider| should match what is returned by |
| 134 // LayerTreeClient::OffscreenContextProviderForCompositorThread. | 133 // LayerTreeClient::OffscreenContextProviderForCompositorThread. |
| 135 bool InitializeAndSetContext3D( | 134 bool InitializeAndSetContext3d( |
| 136 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, | 135 scoped_refptr<ContextProvider> context_provider, |
| 137 scoped_refptr<ContextProvider> offscreen_context_provider); | 136 scoped_refptr<ContextProvider> offscreen_context_provider); |
| 138 void ReleaseGL(); | 137 void ReleaseGL(); |
| 139 | 138 |
| 140 void PostSwapBuffersComplete(); | 139 void PostSwapBuffersComplete(); |
| 141 | 140 |
| 142 struct cc::OutputSurface::Capabilities capabilities_; | 141 struct cc::OutputSurface::Capabilities capabilities_; |
| 143 scoped_ptr<OutputSurfaceCallbacks> callbacks_; | 142 scoped_refptr<ContextProvider> context_provider_; |
| 144 scoped_ptr<WebKit::WebGraphicsContext3D> context3d_; | |
| 145 scoped_ptr<cc::SoftwareOutputDevice> software_device_; | 143 scoped_ptr<cc::SoftwareOutputDevice> software_device_; |
| 146 bool has_gl_discard_backbuffer_; | 144 bool has_gl_discard_backbuffer_; |
| 147 bool has_swap_buffers_complete_callback_; | 145 bool has_swap_buffers_complete_callback_; |
| 148 gfx::Size surface_size_; | 146 gfx::Size surface_size_; |
| 149 float device_scale_factor_; | 147 float device_scale_factor_; |
| 150 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; | 148 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; |
| 151 | 149 |
| 152 // The FrameRateController is deprecated. | 150 // The FrameRateController is deprecated. |
| 153 // Platforms should move to native BeginFrames instead. | 151 // Platforms should move to native BeginFrames instead. |
| 154 void OnVSyncParametersChanged(base::TimeTicks timebase, | 152 void OnVSyncParametersChanged(base::TimeTicks timebase, |
| 155 base::TimeDelta interval); | 153 base::TimeDelta interval); |
| 156 virtual void FrameRateControllerTick(bool throttled, | 154 virtual void FrameRateControllerTick(bool throttled, |
| 157 const BeginFrameArgs& args) OVERRIDE; | 155 const BeginFrameArgs& args) OVERRIDE; |
| 158 scoped_ptr<FrameRateController> frame_rate_controller_; | 156 scoped_ptr<FrameRateController> frame_rate_controller_; |
| 159 int max_frames_pending_; | 157 int max_frames_pending_; |
| 160 int pending_swap_buffers_; | 158 int pending_swap_buffers_; |
| 161 bool needs_begin_frame_; | 159 bool needs_begin_frame_; |
| 162 bool begin_frame_pending_; | 160 bool begin_frame_pending_; |
| 163 | 161 |
| 164 // Forwarded to OutputSurfaceClient but threaded through OutputSurface | 162 // Forwarded to OutputSurfaceClient but threaded through OutputSurface |
| 165 // first so OutputSurface has a chance to update the FrameRateController | 163 // first so OutputSurface has a chance to update the FrameRateController |
| 166 bool HasClient() { return !!client_; } | |
| 167 void SetNeedsRedrawRect(gfx::Rect damage_rect); | 164 void SetNeedsRedrawRect(gfx::Rect damage_rect); |
| 168 void BeginFrame(const BeginFrameArgs& args); | 165 void BeginFrame(const BeginFrameArgs& args); |
| 169 void DidSwapBuffers(); | 166 void DidSwapBuffers(); |
| 170 void OnSwapBuffersComplete(const CompositorFrameAck* ack); | 167 void OnSwapBuffersComplete(const CompositorFrameAck* ack); |
| 171 void DidLoseOutputSurface(); | 168 void DidLoseOutputSurface(); |
| 172 void SetExternalStencilTest(bool enabled); | 169 void SetExternalStencilTest(bool enabled); |
| 173 void SetExternalDrawConstraints(const gfx::Transform& transform, | 170 void SetExternalDrawConstraints(const gfx::Transform& transform, |
| 174 gfx::Rect viewport); | 171 gfx::Rect viewport); |
| 175 | 172 |
| 176 // virtual for testing. | 173 // virtual for testing. |
| 177 virtual base::TimeDelta RetroactiveBeginFramePeriod(); | 174 virtual base::TimeDelta RetroactiveBeginFramePeriod(); |
| 178 virtual void PostCheckForRetroactiveBeginFrame(); | 175 virtual void PostCheckForRetroactiveBeginFrame(); |
| 179 void CheckForRetroactiveBeginFrame(); | 176 void CheckForRetroactiveBeginFrame(); |
| 180 | 177 |
| 181 private: | 178 private: |
| 182 OutputSurfaceClient* client_; | 179 OutputSurfaceClient* client_; |
| 183 friend class OutputSurfaceCallbacks; | 180 friend class OutputSurfaceCallbacks; |
| 184 | 181 |
| 185 void SetContext3D(scoped_ptr<WebKit::WebGraphicsContext3D> context3d); | 182 void SetUpContext3d(); |
| 186 void ResetContext3D(); | 183 void ResetContext3d(); |
| 187 void SetMemoryPolicy(const ManagedMemoryPolicy& policy, | 184 void SetMemoryPolicy(const ManagedMemoryPolicy& policy, |
| 188 bool discard_backbuffer_when_not_visible); | 185 bool discard_backbuffer_when_not_visible); |
| 189 | 186 |
| 190 // This stores a BeginFrame that we couldn't process immediately, but might | 187 // This stores a BeginFrame that we couldn't process immediately, but might |
| 191 // process retroactively in the near future. | 188 // process retroactively in the near future. |
| 192 BeginFrameArgs skipped_begin_frame_args_; | 189 BeginFrameArgs skipped_begin_frame_args_; |
| 193 | 190 |
| 194 // check_for_retroactive_begin_frame_pending_ is used to avoid posting | 191 // check_for_retroactive_begin_frame_pending_ is used to avoid posting |
| 195 // redundant checks for a retroactive BeginFrame. | 192 // redundant checks for a retroactive BeginFrame. |
| 196 bool check_for_retroactive_begin_frame_pending_; | 193 bool check_for_retroactive_begin_frame_pending_; |
| 197 | 194 |
| 198 DISALLOW_COPY_AND_ASSIGN(OutputSurface); | 195 DISALLOW_COPY_AND_ASSIGN(OutputSurface); |
| 199 }; | 196 }; |
| 200 | 197 |
| 201 } // namespace cc | 198 } // namespace cc |
| 202 | 199 |
| 203 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ | 200 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ |
| OLD | NEW |