[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 | |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 8 | #include "base/callback.h" |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 9 | #include "base/memory/weak_ptr.h" |
[email protected] | abb52216 | 2013-06-28 01:54:16 | [diff] [blame] | 10 | #include "base/time/time.h" |
[email protected] | 752e2cf | 2013-10-21 21:41:15 | [diff] [blame] | 11 | #include "base/values.h" |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 12 | #include "cc/input/top_controls_state.h" |
jamesr | f313a21 | 2015-03-16 21:27:37 | [diff] [blame^] | 13 | #include "cc/output/swap_promise.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 14 | #include "cc/trees/layer_tree_host_client.h" |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 15 | #include "cc/trees/layer_tree_host_single_thread_client.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 16 | #include "cc/trees/layer_tree_settings.h" |
jamesr | f313a21 | 2015-03-16 21:27:37 | [diff] [blame^] | 17 | #include "cc/trees/swap_promise_monitor.h" |
skyostil | 7759d7a | 2014-09-05 08:22:23 | [diff] [blame] | 18 | #include "content/common/content_export.h" |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 19 | #include "content/renderer/gpu/compositor_dependencies.h" |
[email protected] | 5c30b5e0 | 2013-05-30 03:46:08 | [diff] [blame] | 20 | #include "third_party/WebKit/public/platform/WebLayerTreeView.h" |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 21 | #include "third_party/skia/include/core/SkBitmap.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 22 | #include "ui/gfx/geometry/rect.h" |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 23 | |
[email protected] | 4b15766 | 2013-05-29 04:05:05 | [diff] [blame] | 24 | namespace ui { |
| 25 | struct LatencyInfo; |
| 26 | } |
| 27 | |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 28 | namespace cc { |
enne | 89e6c3aa | 2014-10-01 15:07:59 | [diff] [blame] | 29 | class CopyOutputRequest; |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 30 | class InputHandler; |
[email protected] | f7837a9 | 2013-08-21 03:00:05 | [diff] [blame] | 31 | class Layer; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 32 | class LayerTreeHost; |
| 33 | } |
| 34 | |
| 35 | namespace content { |
| 36 | class RenderWidget; |
| 37 | |
skyostil | 7759d7a | 2014-09-05 08:22:23 | [diff] [blame] | 38 | class CONTENT_EXPORT RenderWidgetCompositor |
| 39 | : NON_EXPORTED_BASE(public blink::WebLayerTreeView), |
| 40 | NON_EXPORTED_BASE(public cc::LayerTreeHostClient), |
| 41 | NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 42 | public: |
| 43 | // Attempt to construct and initialize a compositor instance for the widget |
| 44 | // with the given settings. Returns NULL if initialization fails. |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 45 | static scoped_ptr<RenderWidgetCompositor> Create( |
| 46 | RenderWidget* widget, |
| 47 | CompositorDependencies* compositor_deps); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 48 | |
| 49 | virtual ~RenderWidgetCompositor(); |
| 50 | |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 51 | const base::WeakPtr<cc::InputHandler>& GetInputHandler(); |
[email protected] | 971728d | 2013-10-26 10:39:31 | [diff] [blame] | 52 | bool BeginMainFrameRequested() const; |
[email protected] | 24ed043 | 2013-04-24 07:50:31 | [diff] [blame] | 53 | void SetNeedsDisplayOnAllLayers(); |
[email protected] | 206a392 | 2013-05-17 06:34:12 | [diff] [blame] | 54 | void SetRasterizeOnlyVisibleContent(); |
[email protected] | 0bc1f57 | 2013-04-17 01:46:31 | [diff] [blame] | 55 | void SetNeedsRedrawRect(gfx::Rect damage_rect); |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 56 | // Like setNeedsRedraw but forces the frame to be drawn, without early-outs. |
| 57 | // Redraw will be forced after the next commit |
| 58 | void SetNeedsForcedRedraw(); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 59 | // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped |
| 60 | // LatencyInfoSwapPromiseMonitor. During the life time of the |
igsolla | eab34cc | 2015-02-20 11:33:35 | [diff] [blame] | 61 | // LatencyInfoSwapPromiseMonitor, if SetNeedsCommit() or |
| 62 | // SetNeedsUpdateLayers() is called on LayerTreeHost, the original latency |
| 63 | // info will be turned into a LatencyInfoSwapPromise. |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 64 | scoped_ptr<cc::SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor( |
| 65 | ui::LatencyInfo* latency); |
[email protected] | 8062ab26 | 2014-05-27 16:56:43 | [diff] [blame] | 66 | // Calling QueueSwapPromise() to directly queue a SwapPromise into |
| 67 | // LayerTreeHost. |
| 68 | void QueueSwapPromise(scoped_ptr<cc::SwapPromise> swap_promise); |
[email protected] | 6e89eb7 | 2013-07-23 13:28:22 | [diff] [blame] | 69 | int GetLayerTreeId() const; |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 70 | int GetSourceFrameNumber() const; |
igsolla | eab34cc | 2015-02-20 11:33:35 | [diff] [blame] | 71 | void SetNeedsUpdateLayers(); |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 72 | void SetNeedsCommit(); |
[email protected] | df09e05 | 2013-07-31 18:59:50 | [diff] [blame] | 73 | void NotifyInputThrottledUntilCommit(); |
[email protected] | f7837a9 | 2013-08-21 03:00:05 | [diff] [blame] | 74 | const cc::Layer* GetRootLayer() const; |
[email protected] | 67e703e1 | 2014-05-30 05:31:51 | [diff] [blame] | 75 | int ScheduleMicroBenchmark( |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 76 | const std::string& name, |
[email protected] | 752e2cf | 2013-10-21 21:41:15 | [diff] [blame] | 77 | scoped_ptr<base::Value> value, |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 78 | const base::Callback<void(scoped_ptr<base::Value>)>& callback); |
[email protected] | 67e703e1 | 2014-05-30 05:31:51 | [diff] [blame] | 79 | bool SendMessageToMicroBenchmark(int id, scoped_ptr<base::Value> value); |
danakj | 018271e3 | 2014-12-16 21:17:26 | [diff] [blame] | 80 | void StartCompositor(); |
[email protected] | 9ed83fe | 2013-02-27 01:52:28 | [diff] [blame] | 81 | |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 82 | // WebLayerTreeView implementation. |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 83 | virtual void setRootLayer(const blink::WebLayer& layer); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 84 | virtual void clearRootLayer(); |
| 85 | virtual void setViewportSize( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 86 | const blink::WebSize& unused_deprecated, |
| 87 | const blink::WebSize& device_viewport_size); |
[email protected] | 4a57189 | 2014-05-22 05:52:30 | [diff] [blame] | 88 | virtual void setViewportSize(const blink::WebSize& device_viewport_size); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 89 | virtual blink::WebSize layoutViewportSize() const; |
| 90 | virtual blink::WebSize deviceViewportSize() const; |
| 91 | virtual blink::WebFloatPoint adjustEventPointForPinchZoom( |
| 92 | const blink::WebFloatPoint& point) const; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 93 | virtual void setDeviceScaleFactor(float device_scale); |
| 94 | virtual float deviceScaleFactor() const; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 95 | virtual void setBackgroundColor(blink::WebColor color); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 96 | virtual void setHasTransparentBackground(bool transparent); |
| 97 | virtual void setVisible(bool visible); |
| 98 | virtual void setPageScaleFactorAndLimits(float page_scale_factor, |
| 99 | float minimum, |
| 100 | float maximum); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 101 | virtual void startPageScaleAnimation(const blink::WebPoint& destination, |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 102 | bool use_anchor, |
| 103 | float new_page_scale, |
| 104 | double duration_sec); |
[email protected] | 27a747d | 2014-04-30 10:23:01 | [diff] [blame] | 105 | virtual void heuristicsForGpuRasterizationUpdated(bool matches_heuristics); |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 106 | virtual void setNeedsAnimate(); |
| 107 | virtual bool commitRequested() const; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 108 | virtual void didStopFlinging(); |
[email protected] | 9e4067f4 | 2014-05-02 20:57:10 | [diff] [blame] | 109 | virtual void compositeAndReadbackAsync( |
| 110 | blink::WebCompositeAndReadbackAsyncCallback* callback); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 111 | virtual void finishAllRendering(); |
| 112 | virtual void setDeferCommits(bool defer_commits); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 113 | virtual void registerForAnimations(blink::WebLayer* layer); |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 114 | virtual void registerViewportLayers( |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 115 | const blink::WebLayer* overscrollElasticityLayer, |
| 116 | const blink::WebLayer* pageScaleLayer, |
| 117 | const blink::WebLayer* innerViewportScrollLayer, |
| 118 | const blink::WebLayer* outerViewportScrollLayer) override; |
mohan.reddy | ee0b42a | 2014-10-08 04:53:14 | [diff] [blame] | 119 | virtual void clearViewportLayers() override; |
[email protected] | ebb179b | 2014-07-16 17:54:41 | [diff] [blame] | 120 | virtual void registerSelection(const blink::WebSelectionBound& start, |
mohan.reddy | ee0b42a | 2014-10-08 04:53:14 | [diff] [blame] | 121 | const blink::WebSelectionBound& end) override; |
| 122 | virtual void clearSelection() override; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 123 | virtual void setShowFPSCounter(bool show); |
| 124 | virtual void setShowPaintRects(bool show); |
[email protected] | d3be028 | 2013-02-07 19:00:23 | [diff] [blame] | 125 | virtual void setShowDebugBorders(bool show); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 126 | virtual void setContinuousPaintingEnabled(bool enabled); |
[email protected] | 32802a3 | 2013-07-04 11:45:41 | [diff] [blame] | 127 | virtual void setShowScrollBottleneckRects(bool show); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 128 | |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 129 | virtual void updateTopControlsState(blink::WebTopControlsState constraints, |
| 130 | blink::WebTopControlsState current, |
| 131 | bool animate); |
| 132 | virtual void setTopControlsHeight(float height, bool shrink); |
| 133 | virtual void setTopControlsShownRatio(float); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 134 | |
| 135 | // cc::LayerTreeHostClient implementation. |
caseq | 7d2f4c9 | 2015-02-04 16:43:27 | [diff] [blame] | 136 | void WillBeginMainFrame() override; |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 137 | void DidBeginMainFrame() override; |
| 138 | void BeginMainFrame(const cc::BeginFrameArgs& args) override; |
rmcilroy | 0a19362a | 2015-02-18 12:34:25 | [diff] [blame] | 139 | void BeginMainFrameNotExpectedSoon() override; |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 140 | void Layout() override; |
miletus | 7a22175 | 2015-02-04 20:44:49 | [diff] [blame] | 141 | void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
| 142 | const gfx::Vector2dF& outer_delta, |
ccameron | 98be9ac | 2014-12-09 19:56:32 | [diff] [blame] | 143 | const gfx::Vector2dF& elastic_overscroll_delta, |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 144 | float page_scale, |
| 145 | float top_controls_delta) override; |
| 146 | void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta, |
| 147 | float page_scale, |
| 148 | float top_controls_delta) override; |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 149 | void RequestNewOutputSurface() override; |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 150 | void DidInitializeOutputSurface() override; |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 151 | void DidFailToInitializeOutputSurface() override; |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 152 | void WillCommit() override; |
| 153 | void DidCommit() override; |
| 154 | void DidCommitAndDrawFrame() override; |
| 155 | void DidCompleteSwapBuffers() override; |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 156 | void DidCompletePageScaleAnimation() override; |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 157 | void RateLimitSharedMainThreadContext() override; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 158 | |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 159 | // cc::LayerTreeHostSingleThreadClient implementation. |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 160 | void ScheduleAnimation() override; |
| 161 | void DidPostSwapBuffers() override; |
| 162 | void DidAbortSwapBuffers() override; |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 163 | |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 164 | enum { |
| 165 | OUTPUT_SURFACE_RETRIES_BEFORE_FALLBACK = 4, |
| 166 | MAX_OUTPUT_SURFACE_RETRIES = 5, |
| 167 | }; |
| 168 | |
| 169 | protected: |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 170 | RenderWidgetCompositor(RenderWidget* widget, |
| 171 | CompositorDependencies* compositor_deps); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 172 | |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 173 | void Initialize(); |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 174 | cc::LayerTreeHost* layer_tree_host() { return layer_tree_host_.get(); } |
| 175 | |
| 176 | private: |
| 177 | int num_failed_recreate_attempts_; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 178 | RenderWidget* widget_; |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 179 | CompositorDependencies* compositor_deps_; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 180 | scoped_ptr<cc::LayerTreeHost> layer_tree_host_; |
ernstm | 50aec92 | 2014-08-26 22:16:11 | [diff] [blame] | 181 | |
enne | 89e6c3aa | 2014-10-01 15:07:59 | [diff] [blame] | 182 | scoped_ptr<cc::CopyOutputRequest> temporary_copy_output_request_; |
| 183 | |
enne | 7f8fdde | 2014-12-10 21:32:09 | [diff] [blame] | 184 | base::WeakPtrFactory<RenderWidgetCompositor> weak_factory_; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | } // namespace content |
| 188 | |
| 189 | #endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_ |