[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 1 | // Copyright (c) 2013 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. |
| 4 | |
| 5 | #ifndef CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_ |
| 6 | #define CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_ |
| 7 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 10 | #include "base/callback.h" |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 11 | #include "base/memory/weak_ptr.h" |
[email protected] | abb52216 | 2013-06-28 01:54:16 | [diff] [blame] | 12 | #include "base/time/time.h" |
[email protected] | 752e2cf | 2013-10-21 21:41:15 | [diff] [blame] | 13 | #include "base/values.h" |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 14 | #include "cc/input/top_controls_state.h" |
sohan.jyoti | 127a06b4 | 2015-10-05 08:23:34 | [diff] [blame] | 15 | #include "cc/output/managed_memory_policy.h" |
jamesr | f313a21 | 2015-03-16 21:27:37 | [diff] [blame] | 16 | #include "cc/output/swap_promise.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 17 | #include "cc/trees/layer_tree_host_client.h" |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 18 | #include "cc/trees/layer_tree_host_single_thread_client.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 19 | #include "cc/trees/layer_tree_settings.h" |
dtrainor | 5ef644e | 2015-11-19 00:12:47 | [diff] [blame] | 20 | #include "cc/trees/remote_proto_channel.h" |
jamesr | f313a21 | 2015-03-16 21:27:37 | [diff] [blame] | 21 | #include "cc/trees/swap_promise_monitor.h" |
skyostil | 7759d7a | 2014-09-05 08:22:23 | [diff] [blame] | 22 | #include "content/common/content_export.h" |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 23 | #include "content/renderer/gpu/compositor_dependencies.h" |
[email protected] | 5c30b5e0 | 2013-05-30 03:46:08 | [diff] [blame] | 24 | #include "third_party/WebKit/public/platform/WebLayerTreeView.h" |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 25 | #include "third_party/skia/include/core/SkBitmap.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 26 | #include "ui/gfx/geometry/rect.h" |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 27 | |
[email protected] | 4b15766 | 2013-05-29 04:05:05 | [diff] [blame] | 28 | namespace ui { |
miletus | 45effdc4 | 2015-08-05 00:29:18 | [diff] [blame] | 29 | class LatencyInfo; |
[email protected] | 4b15766 | 2013-05-29 04:05:05 | [diff] [blame] | 30 | } |
| 31 | |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 32 | namespace cc { |
enne | 89e6c3aa | 2014-10-01 15:07:59 | [diff] [blame] | 33 | class CopyOutputRequest; |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 34 | class InputHandler; |
[email protected] | f7837a9 | 2013-08-21 03:00:05 | [diff] [blame] | 35 | class Layer; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 36 | class LayerTreeHost; |
dtrainor | 5ef644e | 2015-11-19 00:12:47 | [diff] [blame] | 37 | |
| 38 | namespace proto { |
| 39 | class CompositorMessage; |
| 40 | } |
| 41 | |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | namespace content { |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 45 | |
| 46 | class RenderWidgetCompositorDelegate; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 47 | |
skyostil | 7759d7a | 2014-09-05 08:22:23 | [diff] [blame] | 48 | class CONTENT_EXPORT RenderWidgetCompositor |
| 49 | : NON_EXPORTED_BASE(public blink::WebLayerTreeView), |
| 50 | NON_EXPORTED_BASE(public cc::LayerTreeHostClient), |
dtrainor | 5ef644e | 2015-11-19 00:12:47 | [diff] [blame] | 51 | NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient), |
| 52 | NON_EXPORTED_BASE(public cc::RemoteProtoChannel) { |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 53 | public: |
| 54 | // Attempt to construct and initialize a compositor instance for the widget |
| 55 | // with the given settings. Returns NULL if initialization fails. |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 56 | static scoped_ptr<RenderWidgetCompositor> Create( |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 57 | RenderWidgetCompositorDelegate* delegate, |
| 58 | float device_scale_factor, |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 59 | CompositorDependencies* compositor_deps); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 60 | |
avi | 5c77d21 | 2015-09-25 20:08:25 | [diff] [blame] | 61 | ~RenderWidgetCompositor() override; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 62 | |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 63 | void SetNeverVisible(); |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 64 | const base::WeakPtr<cc::InputHandler>& GetInputHandler(); |
[email protected] | 971728d | 2013-10-26 10:39:31 | [diff] [blame] | 65 | bool BeginMainFrameRequested() const; |
[email protected] | 24ed043 | 2013-04-24 07:50:31 | [diff] [blame] | 66 | void SetNeedsDisplayOnAllLayers(); |
[email protected] | 206a392 | 2013-05-17 06:34:12 | [diff] [blame] | 67 | void SetRasterizeOnlyVisibleContent(); |
[email protected] | 0bc1f57 | 2013-04-17 01:46:31 | [diff] [blame] | 68 | void SetNeedsRedrawRect(gfx::Rect damage_rect); |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 69 | // Like setNeedsRedraw but forces the frame to be drawn, without early-outs. |
| 70 | // Redraw will be forced after the next commit |
| 71 | void SetNeedsForcedRedraw(); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 72 | // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped |
| 73 | // LatencyInfoSwapPromiseMonitor. During the life time of the |
igsolla | eab34cc | 2015-02-20 11:33:35 | [diff] [blame] | 74 | // LatencyInfoSwapPromiseMonitor, if SetNeedsCommit() or |
| 75 | // SetNeedsUpdateLayers() is called on LayerTreeHost, the original latency |
| 76 | // info will be turned into a LatencyInfoSwapPromise. |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 77 | scoped_ptr<cc::SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor( |
| 78 | ui::LatencyInfo* latency); |
[email protected] | 8062ab26 | 2014-05-27 16:56:43 | [diff] [blame] | 79 | // Calling QueueSwapPromise() to directly queue a SwapPromise into |
| 80 | // LayerTreeHost. |
| 81 | void QueueSwapPromise(scoped_ptr<cc::SwapPromise> swap_promise); |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 82 | int GetSourceFrameNumber() const; |
igsolla | eab34cc | 2015-02-20 11:33:35 | [diff] [blame] | 83 | void SetNeedsUpdateLayers(); |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 84 | void SetNeedsCommit(); |
[email protected] | df09e05 | 2013-07-31 18:59:50 | [diff] [blame] | 85 | void NotifyInputThrottledUntilCommit(); |
[email protected] | f7837a9 | 2013-08-21 03:00:05 | [diff] [blame] | 86 | const cc::Layer* GetRootLayer() const; |
[email protected] | 67e703e1 | 2014-05-30 05:31:51 | [diff] [blame] | 87 | int ScheduleMicroBenchmark( |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 88 | const std::string& name, |
[email protected] | 752e2cf | 2013-10-21 21:41:15 | [diff] [blame] | 89 | scoped_ptr<base::Value> value, |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 90 | const base::Callback<void(scoped_ptr<base::Value>)>& callback); |
[email protected] | 67e703e1 | 2014-05-30 05:31:51 | [diff] [blame] | 91 | bool SendMessageToMicroBenchmark(int id, scoped_ptr<base::Value> value); |
kenrb | b4e2a3b | 2015-05-14 15:05:05 | [diff] [blame] | 92 | void SetSurfaceIdNamespace(uint32_t surface_id_namespace); |
dtrainor | 5ef644e | 2015-11-19 00:12:47 | [diff] [blame] | 93 | void OnHandleCompositorProto(const std::vector<uint8_t>& proto); |
sohan.jyoti | 127a06b4 | 2015-10-05 08:23:34 | [diff] [blame] | 94 | cc::ManagedMemoryPolicy GetGpuMemoryPolicy( |
| 95 | const cc::ManagedMemoryPolicy& policy); |
oshima | 750cb434 | 2015-10-31 00:59:01 | [diff] [blame] | 96 | void SetPaintedDeviceScaleFactor(float device_scale); |
[email protected] | 9ed83fe | 2013-02-27 01:52:28 | [diff] [blame] | 97 | |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 98 | // WebLayerTreeView implementation. |
avi | 5c77d21 | 2015-09-25 20:08:25 | [diff] [blame] | 99 | void setRootLayer(const blink::WebLayer& layer) override; |
| 100 | void clearRootLayer() override; |
| 101 | void attachCompositorAnimationTimeline( |
loyso | 26f3c55 | 2016-02-10 23:54:34 | [diff] [blame] | 102 | cc::AnimationTimeline* compositor_timeline) override; |
avi | 5c77d21 | 2015-09-25 20:08:25 | [diff] [blame] | 103 | void detachCompositorAnimationTimeline( |
loyso | 26f3c55 | 2016-02-10 23:54:34 | [diff] [blame] | 104 | cc::AnimationTimeline* compositor_timeline) override; |
avi | 5c77d21 | 2015-09-25 20:08:25 | [diff] [blame] | 105 | void setViewportSize(const blink::WebSize& device_viewport_size) override; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 106 | virtual blink::WebFloatPoint adjustEventPointForPinchZoom( |
| 107 | const blink::WebFloatPoint& point) const; |
avi | 5c77d21 | 2015-09-25 20:08:25 | [diff] [blame] | 108 | void setDeviceScaleFactor(float device_scale) override; |
avi | 5c77d21 | 2015-09-25 20:08:25 | [diff] [blame] | 109 | void setBackgroundColor(blink::WebColor color) override; |
| 110 | void setHasTransparentBackground(bool transparent) override; |
| 111 | void setVisible(bool visible) override; |
| 112 | void setPageScaleFactorAndLimits(float page_scale_factor, |
| 113 | float minimum, |
| 114 | float maximum) override; |
| 115 | void startPageScaleAnimation(const blink::WebPoint& destination, |
| 116 | bool use_anchor, |
| 117 | float new_page_scale, |
| 118 | double duration_sec) override; |
| 119 | void heuristicsForGpuRasterizationUpdated(bool matches_heuristics) override; |
| 120 | void setNeedsAnimate() override; |
| 121 | void setNeedsBeginFrame() override; |
| 122 | void setNeedsCompositorUpdate() override; |
| 123 | void didStopFlinging() override; |
| 124 | void layoutAndPaintAsync( |
| 125 | blink::WebLayoutAndPaintAsyncCallback* callback) override; |
| 126 | void compositeAndReadbackAsync( |
| 127 | blink::WebCompositeAndReadbackAsyncCallback* callback) override; |
| 128 | void setDeferCommits(bool defer_commits) override; |
avi | 5c77d21 | 2015-09-25 20:08:25 | [diff] [blame] | 129 | void registerViewportLayers( |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 130 | const blink::WebLayer* overscrollElasticityLayer, |
| 131 | const blink::WebLayer* pageScaleLayer, |
| 132 | const blink::WebLayer* innerViewportScrollLayer, |
| 133 | const blink::WebLayer* outerViewportScrollLayer) override; |
avi | 5c77d21 | 2015-09-25 20:08:25 | [diff] [blame] | 134 | void clearViewportLayers() override; |
| 135 | void registerSelection(const blink::WebSelection& selection) override; |
| 136 | void clearSelection() override; |
dtapuska | f206a40d | 2016-02-05 21:36:02 | [diff] [blame] | 137 | void setEventListenerProperties( |
| 138 | blink::WebEventListenerClass eventClass, |
| 139 | blink::WebEventListenerProperties properties) override; |
| 140 | blink::WebEventListenerProperties eventListenerProperties( |
| 141 | blink::WebEventListenerClass eventClass) const override; |
dtapuska | f024e55 | 2016-02-03 01:19:46 | [diff] [blame] | 142 | void setHaveScrollEventHandlers(bool) override; |
| 143 | bool haveScrollEventHandlers() const override; |
avi | 5c77d21 | 2015-09-25 20:08:25 | [diff] [blame] | 144 | int layerTreeId() const override; |
| 145 | void setShowFPSCounter(bool show) override; |
| 146 | void setShowPaintRects(bool show) override; |
| 147 | void setShowDebugBorders(bool show) override; |
| 148 | void setShowScrollBottleneckRects(bool show) override; |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 149 | |
avi | 5c77d21 | 2015-09-25 20:08:25 | [diff] [blame] | 150 | void updateTopControlsState(blink::WebTopControlsState constraints, |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 151 | blink::WebTopControlsState current, |
avi | 5c77d21 | 2015-09-25 20:08:25 | [diff] [blame] | 152 | bool animate) override; |
| 153 | void setTopControlsHeight(float height, bool shrink) override; |
| 154 | void setTopControlsShownRatio(float) override; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 155 | |
| 156 | // cc::LayerTreeHostClient implementation. |
caseq | 7d2f4c9 | 2015-02-04 16:43:27 | [diff] [blame] | 157 | void WillBeginMainFrame() override; |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 158 | void DidBeginMainFrame() override; |
| 159 | void BeginMainFrame(const cc::BeginFrameArgs& args) override; |
rmcilroy | 0a19362a | 2015-02-18 12:34:25 | [diff] [blame] | 160 | void BeginMainFrameNotExpectedSoon() override; |
wkorman | 7265db01 | 2015-11-03 04:08:25 | [diff] [blame] | 161 | void UpdateLayerTreeHost() override; |
miletus | 7a22175 | 2015-02-04 20:44:49 | [diff] [blame] | 162 | void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
| 163 | const gfx::Vector2dF& outer_delta, |
ccameron | 98be9ac | 2014-12-09 19:56:32 | [diff] [blame] | 164 | const gfx::Vector2dF& elastic_overscroll_delta, |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 165 | float page_scale, |
| 166 | float top_controls_delta) override; |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 167 | void RequestNewOutputSurface() override; |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 168 | void DidInitializeOutputSurface() override; |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 169 | void DidFailToInitializeOutputSurface() override; |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 170 | void WillCommit() override; |
| 171 | void DidCommit() override; |
| 172 | void DidCommitAndDrawFrame() override; |
| 173 | void DidCompleteSwapBuffers() override; |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 174 | void DidCompletePageScaleAnimation() override; |
mpb | ed24c2c | 2015-06-05 20:57:13 | [diff] [blame] | 175 | void RecordFrameTimingEvents( |
| 176 | scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, |
| 177 | scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) |
| 178 | override; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 179 | |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 180 | // cc::LayerTreeHostSingleThreadClient implementation. |
danakj | 53eccbc | 2016-03-02 22:51:07 | [diff] [blame^] | 181 | void RequestScheduleAnimation() override; |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 182 | void DidPostSwapBuffers() override; |
| 183 | void DidAbortSwapBuffers() override; |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 184 | |
dtrainor | 5ef644e | 2015-11-19 00:12:47 | [diff] [blame] | 185 | // cc::RemoteProtoChannel implementation. |
| 186 | void SetProtoReceiver(ProtoReceiver* receiver) override; |
| 187 | void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; |
| 188 | |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 189 | enum { |
mpb | ed24c2c | 2015-06-05 20:57:13 | [diff] [blame] | 190 | OUTPUT_SURFACE_RETRIES_BEFORE_FALLBACK = 4, |
| 191 | MAX_OUTPUT_SURFACE_RETRIES = 5, |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 192 | }; |
| 193 | |
| 194 | protected: |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 195 | RenderWidgetCompositor(RenderWidgetCompositorDelegate* delegate, |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 196 | CompositorDependencies* compositor_deps); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 197 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 198 | void Initialize(float device_scale_factor); |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 199 | cc::LayerTreeHost* layer_tree_host() { return layer_tree_host_.get(); } |
| 200 | |
| 201 | private: |
wangxianzhu | 67d1fae | 2015-06-30 22:15:53 | [diff] [blame] | 202 | void LayoutAndUpdateLayers(); |
| 203 | void InvokeLayoutAndPaintCallback(); |
| 204 | bool CompositeIsSynchronous() const; |
| 205 | void SynchronouslyComposite(); |
wangxianzhu | 372112e | 2015-05-06 23:01:57 | [diff] [blame] | 206 | |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 207 | int num_failed_recreate_attempts_; |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 208 | RenderWidgetCompositorDelegate* const delegate_; |
| 209 | CompositorDependencies* const compositor_deps_; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 210 | scoped_ptr<cc::LayerTreeHost> layer_tree_host_; |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 211 | bool never_visible_; |
ernstm | 50aec92 | 2014-08-26 22:16:11 | [diff] [blame] | 212 | |
wangxianzhu | 372112e | 2015-05-06 23:01:57 | [diff] [blame] | 213 | blink::WebLayoutAndPaintAsyncCallback* layout_and_paint_async_callback_; |
enne | 89e6c3aa | 2014-10-01 15:07:59 | [diff] [blame] | 214 | scoped_ptr<cc::CopyOutputRequest> temporary_copy_output_request_; |
| 215 | |
dtrainor | 5ef644e | 2015-11-19 00:12:47 | [diff] [blame] | 216 | cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; |
| 217 | |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 218 | base::WeakPtrFactory<RenderWidgetCompositor> weak_factory_; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | } // namespace content |
| 222 | |
| 223 | #endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_ |