blob: 9edc508b311618c8f23aaff183a6b67b8370568b [file] [log] [blame]
[email protected]ba91a792013-02-06 09:48:281// 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
avi1023d012015-12-25 02:39:148#include <stdint.h>
9
[email protected]666d7cf2013-10-12 01:30:2910#include "base/callback.h"
[email protected]200a9c062013-05-20 04:34:3711#include "base/memory/weak_ptr.h"
[email protected]abb522162013-06-28 01:54:1612#include "base/time/time.h"
[email protected]752e2cf2013-10-21 21:41:1513#include "base/values.h"
[email protected]9b003482013-05-21 14:00:1714#include "cc/input/top_controls_state.h"
sohan.jyoti127a06b42015-10-05 08:23:3415#include "cc/output/managed_memory_policy.h"
jamesrf313a212015-03-16 21:27:3716#include "cc/output/swap_promise.h"
[email protected]556fd292013-03-18 08:03:0417#include "cc/trees/layer_tree_host_client.h"
[email protected]943528e2013-11-07 05:01:3218#include "cc/trees/layer_tree_host_single_thread_client.h"
[email protected]556fd292013-03-18 08:03:0419#include "cc/trees/layer_tree_settings.h"
dtrainor5ef644e2015-11-19 00:12:4720#include "cc/trees/remote_proto_channel.h"
jamesrf313a212015-03-16 21:27:3721#include "cc/trees/swap_promise_monitor.h"
skyostil7759d7a2014-09-05 08:22:2322#include "content/common/content_export.h"
danakj6e3bf8012014-12-16 18:27:5323#include "content/renderer/gpu/compositor_dependencies.h"
[email protected]5c30b5e02013-05-30 03:46:0824#include "third_party/WebKit/public/platform/WebLayerTreeView.h"
tfarina3b0452d2014-12-31 15:20:0925#include "ui/gfx/geometry/rect.h"
[email protected]ba91a792013-02-06 09:48:2826
danakja40dd4482016-06-28 01:14:1027namespace base {
28class CommandLine;
[email protected]4b157662013-05-29 04:05:0529}
30
[email protected]ba91a792013-02-06 09:48:2831namespace cc {
enne89e6c3aa2014-10-01 15:07:5932class CopyOutputRequest;
[email protected]200a9c062013-05-20 04:34:3733class InputHandler;
[email protected]f7837a92013-08-21 03:00:0534class Layer;
khushalsagarcebe4942016-09-07 23:27:0135class LayerTreeHostInterface;
dtrainor5ef644e2015-11-19 00:12:4736namespace proto {
37class CompositorMessage;
38}
danakja40dd4482016-06-28 01:14:1039}
dtrainor5ef644e2015-11-19 00:12:4740
ccameronf408cab2016-09-14 16:54:4241namespace gfx {
42class ColorSpace;
43}
44
danakja40dd4482016-06-28 01:14:1045namespace ui {
46class LatencyInfo;
[email protected]ba91a792013-02-06 09:48:2847}
48
49namespace content {
fsamuel78f86e42016-01-20 04:10:2350
51class RenderWidgetCompositorDelegate;
[email protected]ba91a792013-02-06 09:48:2852
skyostil7759d7a2014-09-05 08:22:2353class CONTENT_EXPORT RenderWidgetCompositor
54 : NON_EXPORTED_BASE(public blink::WebLayerTreeView),
55 NON_EXPORTED_BASE(public cc::LayerTreeHostClient),
dtrainor5ef644e2015-11-19 00:12:4756 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient),
57 NON_EXPORTED_BASE(public cc::RemoteProtoChannel) {
[email protected]ba91a792013-02-06 09:48:2858 public:
59 // Attempt to construct and initialize a compositor instance for the widget
60 // with the given settings. Returns NULL if initialization fails.
dchengcedca5612016-04-09 01:40:1561 static std::unique_ptr<RenderWidgetCompositor> Create(
fsamuel78f86e42016-01-20 04:10:2362 RenderWidgetCompositorDelegate* delegate,
63 float device_scale_factor,
danakj6e3bf8012014-12-16 18:27:5364 CompositorDependencies* compositor_deps);
[email protected]ba91a792013-02-06 09:48:2865
avi5c77d212015-09-25 20:08:2566 ~RenderWidgetCompositor() override;
[email protected]ba91a792013-02-06 09:48:2867
danakja40dd4482016-06-28 01:14:1068 static cc::LayerTreeSettings GenerateLayerTreeSettings(
69 const base::CommandLine& cmd,
70 CompositorDependencies* compositor_deps,
71 float device_scale_factor);
72 static cc::ManagedMemoryPolicy GetGpuMemoryPolicy(
73 const cc::ManagedMemoryPolicy& policy);
74
sievers71c62dd52015-10-07 01:44:3975 void SetNeverVisible();
[email protected]200a9c062013-05-20 04:34:3776 const base::WeakPtr<cc::InputHandler>& GetInputHandler();
[email protected]971728d2013-10-26 10:39:3177 bool BeginMainFrameRequested() const;
[email protected]24ed0432013-04-24 07:50:3178 void SetNeedsDisplayOnAllLayers();
[email protected]206a3922013-05-17 06:34:1279 void SetRasterizeOnlyVisibleContent();
[email protected]0bc1f572013-04-17 01:46:3180 void SetNeedsRedrawRect(gfx::Rect damage_rect);
[email protected]7d08a9352013-10-15 08:24:5681 // Like setNeedsRedraw but forces the frame to be drawn, without early-outs.
82 // Redraw will be forced after the next commit
83 void SetNeedsForcedRedraw();
[email protected]6be422b2013-12-08 06:47:3184 // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped
85 // LatencyInfoSwapPromiseMonitor. During the life time of the
igsollaeab34cc2015-02-20 11:33:3586 // LatencyInfoSwapPromiseMonitor, if SetNeedsCommit() or
87 // SetNeedsUpdateLayers() is called on LayerTreeHost, the original latency
88 // info will be turned into a LatencyInfoSwapPromise.
dchengcedca5612016-04-09 01:40:1589 std::unique_ptr<cc::SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
[email protected]6be422b2013-12-08 06:47:3190 ui::LatencyInfo* latency);
[email protected]8062ab262014-05-27 16:56:4391 // Calling QueueSwapPromise() to directly queue a SwapPromise into
92 // LayerTreeHost.
dchengcedca5612016-04-09 01:40:1593 void QueueSwapPromise(std::unique_ptr<cc::SwapPromise> swap_promise);
[email protected]586871b2014-07-22 17:05:1194 int GetSourceFrameNumber() const;
igsollaeab34cc2015-02-20 11:33:3595 void SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:1196 void SetNeedsCommit();
[email protected]df09e052013-07-31 18:59:5097 void NotifyInputThrottledUntilCommit();
[email protected]f7837a92013-08-21 03:00:0598 const cc::Layer* GetRootLayer() const;
[email protected]67e703e12014-05-30 05:31:5199 int ScheduleMicroBenchmark(
[email protected]666d7cf2013-10-12 01:30:29100 const std::string& name,
dchengcedca5612016-04-09 01:40:15101 std::unique_ptr<base::Value> value,
102 const base::Callback<void(std::unique_ptr<base::Value>)>& callback);
103 bool SendMessageToMicroBenchmark(int id, std::unique_ptr<base::Value> value);
fsamuel278664272016-07-13 04:06:59104 void SetSurfaceClientId(uint32_t surface_id_namespace);
dtrainor5ef644e2015-11-19 00:12:47105 void OnHandleCompositorProto(const std::vector<uint8_t>& proto);
oshima750cb4342015-10-31 00:59:01106 void SetPaintedDeviceScaleFactor(float device_scale);
ccameronf408cab2016-09-14 16:54:42107 void SetDeviceColorSpace(const gfx::ColorSpace& color_space);
[email protected]9ed83fe2013-02-27 01:52:28108
[email protected]ba91a792013-02-06 09:48:28109 // WebLayerTreeView implementation.
avi5c77d212015-09-25 20:08:25110 void setRootLayer(const blink::WebLayer& layer) override;
111 void clearRootLayer() override;
112 void attachCompositorAnimationTimeline(
loyso26f3c552016-02-10 23:54:34113 cc::AnimationTimeline* compositor_timeline) override;
avi5c77d212015-09-25 20:08:25114 void detachCompositorAnimationTimeline(
loyso26f3c552016-02-10 23:54:34115 cc::AnimationTimeline* compositor_timeline) override;
avi5c77d212015-09-25 20:08:25116 void setViewportSize(const blink::WebSize& device_viewport_size) override;
[email protected]180ef242013-11-07 06:50:46117 virtual blink::WebFloatPoint adjustEventPointForPinchZoom(
118 const blink::WebFloatPoint& point) const;
avi5c77d212015-09-25 20:08:25119 void setDeviceScaleFactor(float device_scale) override;
avi5c77d212015-09-25 20:08:25120 void setBackgroundColor(blink::WebColor color) override;
121 void setHasTransparentBackground(bool transparent) override;
122 void setVisible(bool visible) override;
123 void setPageScaleFactorAndLimits(float page_scale_factor,
124 float minimum,
125 float maximum) override;
126 void startPageScaleAnimation(const blink::WebPoint& destination,
127 bool use_anchor,
128 float new_page_scale,
129 double duration_sec) override;
dglazkov4969a3e2016-05-20 21:13:51130 bool hasPendingPageScaleAnimation() const override;
avi5c77d212015-09-25 20:08:25131 void heuristicsForGpuRasterizationUpdated(bool matches_heuristics) override;
132 void setNeedsAnimate() override;
133 void setNeedsBeginFrame() override;
134 void setNeedsCompositorUpdate() override;
135 void didStopFlinging() override;
136 void layoutAndPaintAsync(
137 blink::WebLayoutAndPaintAsyncCallback* callback) override;
138 void compositeAndReadbackAsync(
139 blink::WebCompositeAndReadbackAsyncCallback* callback) override;
140 void setDeferCommits(bool defer_commits) override;
avi5c77d212015-09-25 20:08:25141 void registerViewportLayers(
ccameron8230b68b2014-11-21 19:25:18142 const blink::WebLayer* overscrollElasticityLayer,
143 const blink::WebLayer* pageScaleLayer,
144 const blink::WebLayer* innerViewportScrollLayer,
145 const blink::WebLayer* outerViewportScrollLayer) override;
avi5c77d212015-09-25 20:08:25146 void clearViewportLayers() override;
147 void registerSelection(const blink::WebSelection& selection) override;
148 void clearSelection() override;
flackrf54e9b42016-05-31 15:20:10149 void setMutatorClient(
150 std::unique_ptr<blink::WebCompositorMutatorClient>) override;
dtapuskaf206a40d2016-02-05 21:36:02151 void setEventListenerProperties(
152 blink::WebEventListenerClass eventClass,
153 blink::WebEventListenerProperties properties) override;
154 blink::WebEventListenerProperties eventListenerProperties(
155 blink::WebEventListenerClass eventClass) const override;
dtapuskaf024e552016-02-03 01:19:46156 void setHaveScrollEventHandlers(bool) override;
157 bool haveScrollEventHandlers() const override;
avi5c77d212015-09-25 20:08:25158 int layerTreeId() const override;
159 void setShowFPSCounter(bool show) override;
160 void setShowPaintRects(bool show) override;
161 void setShowDebugBorders(bool show) override;
162 void setShowScrollBottleneckRects(bool show) override;
aelias6004fe02015-02-07 21:43:01163
avi5c77d212015-09-25 20:08:25164 void updateTopControlsState(blink::WebTopControlsState constraints,
majidvpfb80e432015-02-23 14:15:50165 blink::WebTopControlsState current,
avi5c77d212015-09-25 20:08:25166 bool animate) override;
167 void setTopControlsHeight(float height, bool shrink) override;
168 void setTopControlsShownRatio(float) override;
ianwene5fc5782016-08-18 04:05:15169 // TODO(ianwen): Move this method to WebLayerTreeView and implement main
170 // thread scrolling.
171 virtual void setBottomControlsHeight(float height);
[email protected]ba91a792013-02-06 09:48:28172
173 // cc::LayerTreeHostClient implementation.
caseq7d2f4c92015-02-04 16:43:27174 void WillBeginMainFrame() override;
dcheng6d18e402014-10-21 12:32:52175 void DidBeginMainFrame() override;
176 void BeginMainFrame(const cc::BeginFrameArgs& args) override;
rmcilroy0a19362a2015-02-18 12:34:25177 void BeginMainFrameNotExpectedSoon() override;
wkorman7265db012015-11-03 04:08:25178 void UpdateLayerTreeHost() override;
miletus7a221752015-02-04 20:44:49179 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
180 const gfx::Vector2dF& outer_delta,
ccameron98be9ac2014-12-09 19:56:32181 const gfx::Vector2dF& elastic_overscroll_delta,
dcheng6d18e402014-10-21 12:32:52182 float page_scale,
183 float top_controls_delta) override;
enne7f8fdde2014-12-10 21:32:09184 void RequestNewOutputSurface() override;
dcheng6d18e402014-10-21 12:32:52185 void DidInitializeOutputSurface() override;
enne7f8fdde2014-12-10 21:32:09186 void DidFailToInitializeOutputSurface() override;
dcheng6d18e402014-10-21 12:32:52187 void WillCommit() override;
188 void DidCommit() override;
189 void DidCommitAndDrawFrame() override;
190 void DidCompleteSwapBuffers() override;
rouslanf7ebd8832015-01-22 01:54:14191 void DidCompletePageScaleAnimation() override;
[email protected]ba91a792013-02-06 09:48:28192
[email protected]943528e2013-11-07 05:01:32193 // cc::LayerTreeHostSingleThreadClient implementation.
danakj53eccbc2016-03-02 22:51:07194 void RequestScheduleAnimation() override;
dcheng6d18e402014-10-21 12:32:52195 void DidPostSwapBuffers() override;
196 void DidAbortSwapBuffers() override;
[email protected]943528e2013-11-07 05:01:32197
dtrainor5ef644e2015-11-19 00:12:47198 // cc::RemoteProtoChannel implementation.
199 void SetProtoReceiver(ProtoReceiver* receiver) override;
200 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override;
201
enne7f8fdde2014-12-10 21:32:09202 enum {
mpbed24c2c2015-06-05 20:57:13203 OUTPUT_SURFACE_RETRIES_BEFORE_FALLBACK = 4,
204 MAX_OUTPUT_SURFACE_RETRIES = 5,
enne7f8fdde2014-12-10 21:32:09205 };
206
207 protected:
oshima50872a72016-03-04 13:26:18208 friend class RenderViewImplScaleFactorTest;
209
fsamuel78f86e42016-01-20 04:10:23210 RenderWidgetCompositor(RenderWidgetCompositorDelegate* delegate,
danakj6e3bf8012014-12-16 18:27:53211 CompositorDependencies* compositor_deps);
[email protected]ba91a792013-02-06 09:48:28212
fsamuel78f86e42016-01-20 04:10:23213 void Initialize(float device_scale_factor);
khushalsagarcebe4942016-09-07 23:27:01214 cc::LayerTreeHostInterface* layer_tree_host() {
215 return layer_tree_host_.get();
216 }
enne7f8fdde2014-12-10 21:32:09217
218 private:
wangxianzhu67d1fae2015-06-30 22:15:53219 void LayoutAndUpdateLayers();
220 void InvokeLayoutAndPaintCallback();
221 bool CompositeIsSynchronous() const;
222 void SynchronouslyComposite();
wangxianzhu372112e2015-05-06 23:01:57223
enne7f8fdde2014-12-10 21:32:09224 int num_failed_recreate_attempts_;
fsamuel78f86e42016-01-20 04:10:23225 RenderWidgetCompositorDelegate* const delegate_;
226 CompositorDependencies* const compositor_deps_;
danakja40dd4482016-06-28 01:14:10227 const bool threaded_;
khushalsagarcebe4942016-09-07 23:27:01228 std::unique_ptr<cc::LayerTreeHostInterface> layer_tree_host_;
sievers71c62dd52015-10-07 01:44:39229 bool never_visible_;
ernstm50aec922014-08-26 22:16:11230
wangxianzhu372112e2015-05-06 23:01:57231 blink::WebLayoutAndPaintAsyncCallback* layout_and_paint_async_callback_;
enne89e6c3aa2014-10-01 15:07:59232
dtrainor5ef644e2015-11-19 00:12:47233 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_;
234
enne7f8fdde2014-12-10 21:32:09235 base::WeakPtrFactory<RenderWidgetCompositor> weak_factory_;
[email protected]ba91a792013-02-06 09:48:28236};
237
238} // namespace content
239
240#endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_