blob: 684c2bcb14132d44e4aff7dc95036c40a4455341 [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]8062ab262014-05-27 16:56:4312#include "cc/base/swap_promise.h"
[email protected]6be422b2013-12-08 06:47:3113#include "cc/base/swap_promise_monitor.h"
[email protected]9b003482013-05-21 14:00:1714#include "cc/input/top_controls_state.h"
[email protected]556fd292013-03-18 08:03:0415#include "cc/trees/layer_tree_host_client.h"
[email protected]943528e2013-11-07 05:01:3216#include "cc/trees/layer_tree_host_single_thread_client.h"
[email protected]556fd292013-03-18 08:03:0417#include "cc/trees/layer_tree_settings.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]9b003482013-05-21 14:00:1755 void UpdateTopControlsState(cc::TopControlsState constraints,
56 cc::TopControlsState current,
[email protected]452b4a92013-03-28 21:24:3857 bool animate);
dtrainorcb7779b82014-12-04 01:08:0258 void SetTopControlsShrinkBlinkSize(bool shrink);
59 void SetTopControlsHeight(float height);
[email protected]0bc1f572013-04-17 01:46:3160 void SetNeedsRedrawRect(gfx::Rect damage_rect);
[email protected]7d08a9352013-10-15 08:24:5661 // Like setNeedsRedraw but forces the frame to be drawn, without early-outs.
62 // Redraw will be forced after the next commit
63 void SetNeedsForcedRedraw();
[email protected]6be422b2013-12-08 06:47:3164 // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped
65 // LatencyInfoSwapPromiseMonitor. During the life time of the
66 // LatencyInfoSwapPromiseMonitor, if SetNeedsCommit() or SetNeedsUpdateLayer()
67 // is called on LayerTreeHost, the original latency info will be turned
68 // into a LatencyInfoSwapPromise.
69 scoped_ptr<cc::SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
70 ui::LatencyInfo* latency);
[email protected]8062ab262014-05-27 16:56:4371 // Calling QueueSwapPromise() to directly queue a SwapPromise into
72 // LayerTreeHost.
73 void QueueSwapPromise(scoped_ptr<cc::SwapPromise> swap_promise);
[email protected]6e89eb72013-07-23 13:28:2274 int GetLayerTreeId() const;
[email protected]586871b2014-07-22 17:05:1175 int GetSourceFrameNumber() const;
76 void SetNeedsCommit();
[email protected]df09e052013-07-31 18:59:5077 void NotifyInputThrottledUntilCommit();
[email protected]f7837a92013-08-21 03:00:0578 const cc::Layer* GetRootLayer() const;
[email protected]67e703e12014-05-30 05:31:5179 int ScheduleMicroBenchmark(
[email protected]666d7cf2013-10-12 01:30:2980 const std::string& name,
[email protected]752e2cf2013-10-21 21:41:1581 scoped_ptr<base::Value> value,
[email protected]666d7cf2013-10-12 01:30:2982 const base::Callback<void(scoped_ptr<base::Value>)>& callback);
[email protected]67e703e12014-05-30 05:31:5183 bool SendMessageToMicroBenchmark(int id, scoped_ptr<base::Value> value);
danakj018271e32014-12-16 21:17:2684 void StartCompositor();
[email protected]9ed83fe2013-02-27 01:52:2885
[email protected]ba91a792013-02-06 09:48:2886 // WebLayerTreeView implementation.
[email protected]180ef242013-11-07 06:50:4687 virtual void setRootLayer(const blink::WebLayer& layer);
[email protected]ba91a792013-02-06 09:48:2888 virtual void clearRootLayer();
89 virtual void setViewportSize(
[email protected]180ef242013-11-07 06:50:4690 const blink::WebSize& unused_deprecated,
91 const blink::WebSize& device_viewport_size);
[email protected]4a571892014-05-22 05:52:3092 virtual void setViewportSize(const blink::WebSize& device_viewport_size);
[email protected]180ef242013-11-07 06:50:4693 virtual blink::WebSize layoutViewportSize() const;
94 virtual blink::WebSize deviceViewportSize() const;
95 virtual blink::WebFloatPoint adjustEventPointForPinchZoom(
96 const blink::WebFloatPoint& point) const;
[email protected]ba91a792013-02-06 09:48:2897 virtual void setDeviceScaleFactor(float device_scale);
98 virtual float deviceScaleFactor() const;
[email protected]180ef242013-11-07 06:50:4699 virtual void setBackgroundColor(blink::WebColor color);
[email protected]ba91a792013-02-06 09:48:28100 virtual void setHasTransparentBackground(bool transparent);
[email protected]9f4f6a32013-09-04 21:35:12101 virtual void setOverhangBitmap(const SkBitmap& bitmap);
[email protected]ba91a792013-02-06 09:48:28102 virtual void setVisible(bool visible);
103 virtual void setPageScaleFactorAndLimits(float page_scale_factor,
104 float minimum,
105 float maximum);
[email protected]180ef242013-11-07 06:50:46106 virtual void startPageScaleAnimation(const blink::WebPoint& destination,
[email protected]ba91a792013-02-06 09:48:28107 bool use_anchor,
108 float new_page_scale,
109 double duration_sec);
[email protected]27a747d2014-04-30 10:23:01110 virtual void heuristicsForGpuRasterizationUpdated(bool matches_heuristics);
[email protected]8b9e52b2014-01-17 16:35:31111 virtual void setNeedsAnimate();
112 virtual bool commitRequested() const;
[email protected]ba91a792013-02-06 09:48:28113 virtual void didStopFlinging();
[email protected]9e4067f42014-05-02 20:57:10114 virtual void compositeAndReadbackAsync(
115 blink::WebCompositeAndReadbackAsyncCallback* callback);
[email protected]ba91a792013-02-06 09:48:28116 virtual void finishAllRendering();
117 virtual void setDeferCommits(bool defer_commits);
[email protected]180ef242013-11-07 06:50:46118 virtual void registerForAnimations(blink::WebLayer* layer);
[email protected]57ac9482013-09-17 21:13:39119 virtual void registerViewportLayers(
ccameron8230b68b2014-11-21 19:25:18120 const blink::WebLayer* overscrollElasticityLayer,
121 const blink::WebLayer* pageScaleLayer,
122 const blink::WebLayer* innerViewportScrollLayer,
123 const blink::WebLayer* outerViewportScrollLayer) override;
mohan.reddyee0b42a2014-10-08 04:53:14124 virtual void clearViewportLayers() override;
[email protected]ebb179b2014-07-16 17:54:41125 virtual void registerSelection(const blink::WebSelectionBound& start,
mohan.reddyee0b42a2014-10-08 04:53:14126 const blink::WebSelectionBound& end) override;
127 virtual void clearSelection() override;
[email protected]ba91a792013-02-06 09:48:28128 virtual void setShowFPSCounter(bool show);
129 virtual void setShowPaintRects(bool show);
[email protected]d3be0282013-02-07 19:00:23130 virtual void setShowDebugBorders(bool show);
[email protected]ba91a792013-02-06 09:48:28131 virtual void setContinuousPaintingEnabled(bool enabled);
[email protected]32802a32013-07-04 11:45:41132 virtual void setShowScrollBottleneckRects(bool show);
bokan88eae012014-09-09 20:40:42133 virtual void setTopControlsContentOffset(float);
[email protected]ba91a792013-02-06 09:48:28134
135 // cc::LayerTreeHostClient implementation.
dcheng6d18e402014-10-21 12:32:52136 void WillBeginMainFrame(int frame_id) override;
137 void DidBeginMainFrame() override;
138 void BeginMainFrame(const cc::BeginFrameArgs& args) override;
139 void Layout() override;
140 void ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
141 const gfx::Vector2d& outer_delta,
ccameron98be9ac2014-12-09 19:56:32142 const gfx::Vector2dF& elastic_overscroll_delta,
dcheng6d18e402014-10-21 12:32:52143 float page_scale,
144 float top_controls_delta) override;
145 void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
146 float page_scale,
147 float top_controls_delta) override;
enne7f8fdde2014-12-10 21:32:09148 void RequestNewOutputSurface() override;
dcheng6d18e402014-10-21 12:32:52149 void DidInitializeOutputSurface() override;
enne7f8fdde2014-12-10 21:32:09150 void DidFailToInitializeOutputSurface() override;
dcheng6d18e402014-10-21 12:32:52151 void WillCommit() override;
152 void DidCommit() override;
153 void DidCommitAndDrawFrame() override;
154 void DidCompleteSwapBuffers() override;
155 void RateLimitSharedMainThreadContext() override;
[email protected]ba91a792013-02-06 09:48:28156
[email protected]943528e2013-11-07 05:01:32157 // cc::LayerTreeHostSingleThreadClient implementation.
dcheng6d18e402014-10-21 12:32:52158 void ScheduleAnimation() override;
159 void DidPostSwapBuffers() override;
160 void DidAbortSwapBuffers() override;
[email protected]943528e2013-11-07 05:01:32161
enne7f8fdde2014-12-10 21:32:09162 enum {
163 OUTPUT_SURFACE_RETRIES_BEFORE_FALLBACK = 4,
164 MAX_OUTPUT_SURFACE_RETRIES = 5,
165 };
166
167 protected:
danakj6e3bf8012014-12-16 18:27:53168 RenderWidgetCompositor(RenderWidget* widget,
169 CompositorDependencies* compositor_deps);
[email protected]ba91a792013-02-06 09:48:28170
danakj6e3bf8012014-12-16 18:27:53171 void Initialize();
[email protected]ba91a792013-02-06 09:48:28172
enne7f8fdde2014-12-10 21:32:09173 cc::LayerTreeHost* layer_tree_host() { return layer_tree_host_.get(); }
174
175 private:
176 int num_failed_recreate_attempts_;
[email protected]ba91a792013-02-06 09:48:28177 RenderWidget* widget_;
danakj6e3bf8012014-12-16 18:27:53178 CompositorDependencies* compositor_deps_;
[email protected]ba91a792013-02-06 09:48:28179 scoped_ptr<cc::LayerTreeHost> layer_tree_host_;
ernstm50aec922014-08-26 22:16:11180
enne89e6c3aa2014-10-01 15:07:59181 scoped_ptr<cc::CopyOutputRequest> temporary_copy_output_request_;
182
ernstm50aec922014-08-26 22:16:11183 bool send_v8_idle_notification_after_commit_;
184 base::TimeTicks begin_main_frame_time_;
185 // The time interval between BeginMainFrame calls, provided by the scheduler.
186 base::TimeDelta begin_main_frame_interval_;
enne7f8fdde2014-12-10 21:32:09187
188 base::WeakPtrFactory<RenderWidgetCompositor> weak_factory_;
[email protected]ba91a792013-02-06 09:48:28189};
190
191} // namespace content
192
193#endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_