blob: ae79a3082fe511371d98cfe633ae1343d042e2f4 [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
[email protected]666d7cf2013-10-12 01:30:298#include "base/callback.h"
[email protected]200a9c062013-05-20 04:34:379#include "base/memory/weak_ptr.h"
[email protected]abb522162013-06-28 01:54:1610#include "base/time/time.h"
[email protected]752e2cf2013-10-21 21:41:1511#include "base/values.h"
[email protected]9b003482013-05-21 14:00:1712#include "cc/input/top_controls_state.h"
jamesrf313a212015-03-16 21:27:3713#include "cc/output/swap_promise.h"
[email protected]556fd292013-03-18 08:03:0414#include "cc/trees/layer_tree_host_client.h"
[email protected]943528e2013-11-07 05:01:3215#include "cc/trees/layer_tree_host_single_thread_client.h"
[email protected]556fd292013-03-18 08:03:0416#include "cc/trees/layer_tree_settings.h"
jamesrf313a212015-03-16 21:27:3717#include "cc/trees/swap_promise_monitor.h"
skyostil7759d7a2014-09-05 08:22:2318#include "content/common/content_export.h"
danakj6e3bf8012014-12-16 18:27:5319#include "content/renderer/gpu/compositor_dependencies.h"
[email protected]5c30b5e02013-05-30 03:46:0820#include "third_party/WebKit/public/platform/WebLayerTreeView.h"
[email protected]9f4f6a32013-09-04 21:35:1221#include "third_party/skia/include/core/SkBitmap.h"
tfarina3b0452d2014-12-31 15:20:0922#include "ui/gfx/geometry/rect.h"
[email protected]ba91a792013-02-06 09:48:2823
[email protected]4b157662013-05-29 04:05:0524namespace ui {
25struct LatencyInfo;
26}
27
[email protected]ba91a792013-02-06 09:48:2828namespace cc {
enne89e6c3aa2014-10-01 15:07:5929class CopyOutputRequest;
[email protected]200a9c062013-05-20 04:34:3730class InputHandler;
[email protected]f7837a92013-08-21 03:00:0531class Layer;
[email protected]ba91a792013-02-06 09:48:2832class LayerTreeHost;
33}
34
35namespace content {
36class RenderWidget;
37
skyostil7759d7a2014-09-05 08:22:2338class 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]ba91a792013-02-06 09:48:2842 public:
43 // Attempt to construct and initialize a compositor instance for the widget
44 // with the given settings. Returns NULL if initialization fails.
danakj6e3bf8012014-12-16 18:27:5345 static scoped_ptr<RenderWidgetCompositor> Create(
46 RenderWidget* widget,
47 CompositorDependencies* compositor_deps);
[email protected]ba91a792013-02-06 09:48:2848
49 virtual ~RenderWidgetCompositor();
50
[email protected]200a9c062013-05-20 04:34:3751 const base::WeakPtr<cc::InputHandler>& GetInputHandler();
[email protected]971728d2013-10-26 10:39:3152 bool BeginMainFrameRequested() const;
[email protected]24ed0432013-04-24 07:50:3153 void SetNeedsDisplayOnAllLayers();
[email protected]206a3922013-05-17 06:34:1254 void SetRasterizeOnlyVisibleContent();
[email protected]0bc1f572013-04-17 01:46:3155 void SetNeedsRedrawRect(gfx::Rect damage_rect);
[email protected]7d08a9352013-10-15 08:24:5656 // 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]6be422b2013-12-08 06:47:3159 // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped
60 // LatencyInfoSwapPromiseMonitor. During the life time of the
igsollaeab34cc2015-02-20 11:33:3561 // LatencyInfoSwapPromiseMonitor, if SetNeedsCommit() or
62 // SetNeedsUpdateLayers() is called on LayerTreeHost, the original latency
63 // info will be turned into a LatencyInfoSwapPromise.
[email protected]6be422b2013-12-08 06:47:3164 scoped_ptr<cc::SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
65 ui::LatencyInfo* latency);
[email protected]8062ab262014-05-27 16:56:4366 // Calling QueueSwapPromise() to directly queue a SwapPromise into
67 // LayerTreeHost.
68 void QueueSwapPromise(scoped_ptr<cc::SwapPromise> swap_promise);
[email protected]6e89eb72013-07-23 13:28:2269 int GetLayerTreeId() const;
[email protected]586871b2014-07-22 17:05:1170 int GetSourceFrameNumber() const;
igsollaeab34cc2015-02-20 11:33:3571 void SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:1172 void SetNeedsCommit();
[email protected]df09e052013-07-31 18:59:5073 void NotifyInputThrottledUntilCommit();
[email protected]f7837a92013-08-21 03:00:0574 const cc::Layer* GetRootLayer() const;
[email protected]67e703e12014-05-30 05:31:5175 int ScheduleMicroBenchmark(
[email protected]666d7cf2013-10-12 01:30:2976 const std::string& name,
[email protected]752e2cf2013-10-21 21:41:1577 scoped_ptr<base::Value> value,
[email protected]666d7cf2013-10-12 01:30:2978 const base::Callback<void(scoped_ptr<base::Value>)>& callback);
[email protected]67e703e12014-05-30 05:31:5179 bool SendMessageToMicroBenchmark(int id, scoped_ptr<base::Value> value);
danakj018271e32014-12-16 21:17:2680 void StartCompositor();
[email protected]9ed83fe2013-02-27 01:52:2881
[email protected]ba91a792013-02-06 09:48:2882 // WebLayerTreeView implementation.
[email protected]180ef242013-11-07 06:50:4683 virtual void setRootLayer(const blink::WebLayer& layer);
[email protected]ba91a792013-02-06 09:48:2884 virtual void clearRootLayer();
85 virtual void setViewportSize(
[email protected]180ef242013-11-07 06:50:4686 const blink::WebSize& unused_deprecated,
87 const blink::WebSize& device_viewport_size);
[email protected]4a571892014-05-22 05:52:3088 virtual void setViewportSize(const blink::WebSize& device_viewport_size);
[email protected]180ef242013-11-07 06:50:4689 virtual blink::WebSize layoutViewportSize() const;
90 virtual blink::WebSize deviceViewportSize() const;
91 virtual blink::WebFloatPoint adjustEventPointForPinchZoom(
92 const blink::WebFloatPoint& point) const;
[email protected]ba91a792013-02-06 09:48:2893 virtual void setDeviceScaleFactor(float device_scale);
94 virtual float deviceScaleFactor() const;
[email protected]180ef242013-11-07 06:50:4695 virtual void setBackgroundColor(blink::WebColor color);
[email protected]ba91a792013-02-06 09:48:2896 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]180ef242013-11-07 06:50:46101 virtual void startPageScaleAnimation(const blink::WebPoint& destination,
[email protected]ba91a792013-02-06 09:48:28102 bool use_anchor,
103 float new_page_scale,
104 double duration_sec);
[email protected]27a747d2014-04-30 10:23:01105 virtual void heuristicsForGpuRasterizationUpdated(bool matches_heuristics);
[email protected]8b9e52b2014-01-17 16:35:31106 virtual void setNeedsAnimate();
107 virtual bool commitRequested() const;
[email protected]ba91a792013-02-06 09:48:28108 virtual void didStopFlinging();
[email protected]9e4067f42014-05-02 20:57:10109 virtual void compositeAndReadbackAsync(
110 blink::WebCompositeAndReadbackAsyncCallback* callback);
[email protected]ba91a792013-02-06 09:48:28111 virtual void finishAllRendering();
112 virtual void setDeferCommits(bool defer_commits);
[email protected]180ef242013-11-07 06:50:46113 virtual void registerForAnimations(blink::WebLayer* layer);
[email protected]57ac9482013-09-17 21:13:39114 virtual void registerViewportLayers(
ccameron8230b68b2014-11-21 19:25:18115 const blink::WebLayer* overscrollElasticityLayer,
116 const blink::WebLayer* pageScaleLayer,
117 const blink::WebLayer* innerViewportScrollLayer,
118 const blink::WebLayer* outerViewportScrollLayer) override;
mohan.reddyee0b42a2014-10-08 04:53:14119 virtual void clearViewportLayers() override;
[email protected]ebb179b2014-07-16 17:54:41120 virtual void registerSelection(const blink::WebSelectionBound& start,
mohan.reddyee0b42a2014-10-08 04:53:14121 const blink::WebSelectionBound& end) override;
122 virtual void clearSelection() override;
[email protected]ba91a792013-02-06 09:48:28123 virtual void setShowFPSCounter(bool show);
124 virtual void setShowPaintRects(bool show);
[email protected]d3be0282013-02-07 19:00:23125 virtual void setShowDebugBorders(bool show);
[email protected]ba91a792013-02-06 09:48:28126 virtual void setContinuousPaintingEnabled(bool enabled);
[email protected]32802a32013-07-04 11:45:41127 virtual void setShowScrollBottleneckRects(bool show);
aelias6004fe02015-02-07 21:43:01128
majidvpfb80e432015-02-23 14:15:50129 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]ba91a792013-02-06 09:48:28134
135 // cc::LayerTreeHostClient implementation.
caseq7d2f4c92015-02-04 16:43:27136 void WillBeginMainFrame() override;
dcheng6d18e402014-10-21 12:32:52137 void DidBeginMainFrame() override;
138 void BeginMainFrame(const cc::BeginFrameArgs& args) override;
rmcilroy0a19362a2015-02-18 12:34:25139 void BeginMainFrameNotExpectedSoon() override;
dcheng6d18e402014-10-21 12:32:52140 void Layout() override;
miletus7a221752015-02-04 20:44:49141 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
142 const gfx::Vector2dF& outer_delta,
ccameron98be9ac2014-12-09 19:56:32143 const gfx::Vector2dF& elastic_overscroll_delta,
dcheng6d18e402014-10-21 12:32:52144 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;
enne7f8fdde2014-12-10 21:32:09149 void RequestNewOutputSurface() override;
dcheng6d18e402014-10-21 12:32:52150 void DidInitializeOutputSurface() override;
enne7f8fdde2014-12-10 21:32:09151 void DidFailToInitializeOutputSurface() override;
dcheng6d18e402014-10-21 12:32:52152 void WillCommit() override;
153 void DidCommit() override;
154 void DidCommitAndDrawFrame() override;
155 void DidCompleteSwapBuffers() override;
rouslanf7ebd8832015-01-22 01:54:14156 void DidCompletePageScaleAnimation() override;
dcheng6d18e402014-10-21 12:32:52157 void RateLimitSharedMainThreadContext() override;
[email protected]ba91a792013-02-06 09:48:28158
[email protected]943528e2013-11-07 05:01:32159 // cc::LayerTreeHostSingleThreadClient implementation.
dcheng6d18e402014-10-21 12:32:52160 void ScheduleAnimation() override;
161 void DidPostSwapBuffers() override;
162 void DidAbortSwapBuffers() override;
[email protected]943528e2013-11-07 05:01:32163
enne7f8fdde2014-12-10 21:32:09164 enum {
165 OUTPUT_SURFACE_RETRIES_BEFORE_FALLBACK = 4,
166 MAX_OUTPUT_SURFACE_RETRIES = 5,
167 };
168
169 protected:
danakj6e3bf8012014-12-16 18:27:53170 RenderWidgetCompositor(RenderWidget* widget,
171 CompositorDependencies* compositor_deps);
[email protected]ba91a792013-02-06 09:48:28172
danakj6e3bf8012014-12-16 18:27:53173 void Initialize();
enne7f8fdde2014-12-10 21:32:09174 cc::LayerTreeHost* layer_tree_host() { return layer_tree_host_.get(); }
175
176 private:
177 int num_failed_recreate_attempts_;
[email protected]ba91a792013-02-06 09:48:28178 RenderWidget* widget_;
danakj6e3bf8012014-12-16 18:27:53179 CompositorDependencies* compositor_deps_;
[email protected]ba91a792013-02-06 09:48:28180 scoped_ptr<cc::LayerTreeHost> layer_tree_host_;
ernstm50aec922014-08-26 22:16:11181
enne89e6c3aa2014-10-01 15:07:59182 scoped_ptr<cc::CopyOutputRequest> temporary_copy_output_request_;
183
enne7f8fdde2014-12-10 21:32:09184 base::WeakPtrFactory<RenderWidgetCompositor> weak_factory_;
[email protected]ba91a792013-02-06 09:48:28185};
186
187} // namespace content
188
189#endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_