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