blob: 88367b329ff8d3912deae28bc4675039bc772a91 [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"
[email protected]5c30b5e02013-05-30 03:46:0819#include "third_party/WebKit/public/platform/WebLayerTreeView.h"
[email protected]9f4f6a32013-09-04 21:35:1220#include "third_party/skia/include/core/SkBitmap.h"
[email protected]0bc1f572013-04-17 01:46:3121#include "ui/gfx/rect.h"
[email protected]ba91a792013-02-06 09:48:2822
[email protected]4b157662013-05-29 04:05:0523namespace ui {
24struct LatencyInfo;
25}
26
[email protected]ba91a792013-02-06 09:48:2827namespace cc {
enne89e6c3aa2014-10-01 15:07:5928class CopyOutputRequest;
[email protected]200a9c062013-05-20 04:34:3729class InputHandler;
[email protected]f7837a92013-08-21 03:00:0530class Layer;
[email protected]ba91a792013-02-06 09:48:2831class LayerTreeHost;
32}
33
34namespace content {
35class RenderWidget;
36
skyostil7759d7a2014-09-05 08:22:2337class CONTENT_EXPORT RenderWidgetCompositor
38 : NON_EXPORTED_BASE(public blink::WebLayerTreeView),
39 NON_EXPORTED_BASE(public cc::LayerTreeHostClient),
40 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) {
[email protected]ba91a792013-02-06 09:48:2841 public:
42 // Attempt to construct and initialize a compositor instance for the widget
43 // with the given settings. Returns NULL if initialization fails.
[email protected]c5fa4c42013-07-20 05:47:3744 static scoped_ptr<RenderWidgetCompositor> Create(RenderWidget* widget,
45 bool threaded);
[email protected]ba91a792013-02-06 09:48:2846
47 virtual ~RenderWidgetCompositor();
48
[email protected]200a9c062013-05-20 04:34:3749 const base::WeakPtr<cc::InputHandler>& GetInputHandler();
[email protected]971728d2013-10-26 10:39:3150 bool BeginMainFrameRequested() const;
[email protected]24ed0432013-04-24 07:50:3151 void SetNeedsDisplayOnAllLayers();
[email protected]206a3922013-05-17 06:34:1252 void SetRasterizeOnlyVisibleContent();
[email protected]9b003482013-05-21 14:00:1753 void UpdateTopControlsState(cc::TopControlsState constraints,
54 cc::TopControlsState current,
[email protected]452b4a92013-03-28 21:24:3855 bool animate);
bokan88eae012014-09-09 20:40:4256 void SetTopControlsLayoutHeight(float height);
[email protected]0bc1f572013-04-17 01:46:3157 void SetNeedsRedrawRect(gfx::Rect damage_rect);
[email protected]7d08a9352013-10-15 08:24:5658 // Like setNeedsRedraw but forces the frame to be drawn, without early-outs.
59 // Redraw will be forced after the next commit
60 void SetNeedsForcedRedraw();
[email protected]6be422b2013-12-08 06:47:3161 // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped
62 // LatencyInfoSwapPromiseMonitor. During the life time of the
63 // LatencyInfoSwapPromiseMonitor, if SetNeedsCommit() or SetNeedsUpdateLayer()
64 // is called on LayerTreeHost, the original latency info will be turned
65 // into a LatencyInfoSwapPromise.
66 scoped_ptr<cc::SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
67 ui::LatencyInfo* latency);
[email protected]8062ab262014-05-27 16:56:4368 // Calling QueueSwapPromise() to directly queue a SwapPromise into
69 // LayerTreeHost.
70 void QueueSwapPromise(scoped_ptr<cc::SwapPromise> swap_promise);
[email protected]6e89eb72013-07-23 13:28:2271 int GetLayerTreeId() const;
[email protected]586871b2014-07-22 17:05:1172 int GetSourceFrameNumber() const;
73 void SetNeedsCommit();
[email protected]df09e052013-07-31 18:59:5074 void NotifyInputThrottledUntilCommit();
[email protected]f7837a92013-08-21 03:00:0575 const cc::Layer* GetRootLayer() const;
[email protected]67e703e12014-05-30 05:31:5176 int ScheduleMicroBenchmark(
[email protected]666d7cf2013-10-12 01:30:2977 const std::string& name,
[email protected]752e2cf2013-10-21 21:41:1578 scoped_ptr<base::Value> value,
[email protected]666d7cf2013-10-12 01:30:2979 const base::Callback<void(scoped_ptr<base::Value>)>& callback);
[email protected]67e703e12014-05-30 05:31:5180 bool SendMessageToMicroBenchmark(int id, scoped_ptr<base::Value> value);
[email protected]9ed83fe2013-02-27 01:52:2881
[email protected]ba91a792013-02-06 09:48:2882 // WebLayerTreeView implementation.
83 virtual void setSurfaceReady();
[email protected]180ef242013-11-07 06:50:4684 virtual void setRootLayer(const blink::WebLayer& layer);
[email protected]ba91a792013-02-06 09:48:2885 virtual void clearRootLayer();
86 virtual void setViewportSize(
[email protected]180ef242013-11-07 06:50:4687 const blink::WebSize& unused_deprecated,
88 const blink::WebSize& device_viewport_size);
[email protected]4a571892014-05-22 05:52:3089 virtual void setViewportSize(const blink::WebSize& device_viewport_size);
[email protected]180ef242013-11-07 06:50:4690 virtual blink::WebSize layoutViewportSize() const;
91 virtual blink::WebSize deviceViewportSize() const;
92 virtual blink::WebFloatPoint adjustEventPointForPinchZoom(
93 const blink::WebFloatPoint& point) const;
[email protected]ba91a792013-02-06 09:48:2894 virtual void setDeviceScaleFactor(float device_scale);
95 virtual float deviceScaleFactor() const;
[email protected]180ef242013-11-07 06:50:4696 virtual void setBackgroundColor(blink::WebColor color);
[email protected]ba91a792013-02-06 09:48:2897 virtual void setHasTransparentBackground(bool transparent);
[email protected]9f4f6a32013-09-04 21:35:1298 virtual void setOverhangBitmap(const SkBitmap& bitmap);
[email protected]ba91a792013-02-06 09:48:2899 virtual void setVisible(bool visible);
100 virtual void setPageScaleFactorAndLimits(float page_scale_factor,
101 float minimum,
102 float maximum);
[email protected]180ef242013-11-07 06:50:46103 virtual void startPageScaleAnimation(const blink::WebPoint& destination,
[email protected]ba91a792013-02-06 09:48:28104 bool use_anchor,
105 float new_page_scale,
106 double duration_sec);
[email protected]27a747d2014-04-30 10:23:01107 virtual void heuristicsForGpuRasterizationUpdated(bool matches_heuristics);
[email protected]8b9e52b2014-01-17 16:35:31108 virtual void setNeedsAnimate();
109 virtual bool commitRequested() const;
[email protected]ba91a792013-02-06 09:48:28110 virtual void didStopFlinging();
[email protected]9e4067f42014-05-02 20:57:10111 virtual void compositeAndReadbackAsync(
112 blink::WebCompositeAndReadbackAsyncCallback* callback);
[email protected]ba91a792013-02-06 09:48:28113 virtual void finishAllRendering();
114 virtual void setDeferCommits(bool defer_commits);
[email protected]180ef242013-11-07 06:50:46115 virtual void registerForAnimations(blink::WebLayer* layer);
[email protected]57ac9482013-09-17 21:13:39116 virtual void registerViewportLayers(
[email protected]180ef242013-11-07 06:50:46117 const blink::WebLayer* pageScaleLayer,
118 const blink::WebLayer* innerViewportScrollLayer,
119 const blink::WebLayer* outerViewportScrollLayer) OVERRIDE;
[email protected]57ac9482013-09-17 21:13:39120 virtual void clearViewportLayers() OVERRIDE;
[email protected]ebb179b2014-07-16 17:54:41121 virtual void registerSelection(const blink::WebSelectionBound& start,
122 const blink::WebSelectionBound& end) OVERRIDE;
[email protected]19aec372014-07-01 19:08:49123 virtual void clearSelection() OVERRIDE;
[email protected]ba91a792013-02-06 09:48:28124 virtual void setShowFPSCounter(bool show);
125 virtual void setShowPaintRects(bool show);
[email protected]d3be0282013-02-07 19:00:23126 virtual void setShowDebugBorders(bool show);
[email protected]ba91a792013-02-06 09:48:28127 virtual void setContinuousPaintingEnabled(bool enabled);
[email protected]32802a32013-07-04 11:45:41128 virtual void setShowScrollBottleneckRects(bool show);
bokan88eae012014-09-09 20:40:42129 virtual void setTopControlsContentOffset(float);
[email protected]ba91a792013-02-06 09:48:28130
131 // cc::LayerTreeHostClient implementation.
[email protected]33004772013-11-12 09:49:23132 virtual void WillBeginMainFrame(int frame_id) OVERRIDE;
[email protected]daea3d42013-10-23 17:04:50133 virtual void DidBeginMainFrame() OVERRIDE;
[email protected]04c5900d2014-08-18 13:38:36134 virtual void BeginMainFrame(const cc::BeginFrameArgs& args) OVERRIDE;
[email protected]408b5e22013-03-19 09:48:09135 virtual void Layout() OVERRIDE;
bokan59379b092014-09-29 13:47:21136 virtual void ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
137 const gfx::Vector2d& outer_delta,
138 float page_scale,
139 float top_controls_delta) OVERRIDE;
bokan88eae012014-09-09 20:40:42140 virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
141 float page_scale,
142 float top_controls_delta) OVERRIDE;
enne2097cab2014-09-25 20:16:31143 virtual void RequestNewOutputSurface(bool fallback) OVERRIDE;
[email protected]da8e3b72b2014-04-25 02:33:45144 virtual void DidInitializeOutputSurface() OVERRIDE;
[email protected]408b5e22013-03-19 09:48:09145 virtual void WillCommit() OVERRIDE;
146 virtual void DidCommit() OVERRIDE;
147 virtual void DidCommitAndDrawFrame() OVERRIDE;
148 virtual void DidCompleteSwapBuffers() OVERRIDE;
[email protected]aeeb3372013-11-05 14:05:54149 virtual void RateLimitSharedMainThreadContext() OVERRIDE;
[email protected]ba91a792013-02-06 09:48:28150
[email protected]943528e2013-11-07 05:01:32151 // cc::LayerTreeHostSingleThreadClient implementation.
[email protected]dfbded22014-06-28 17:57:32152 virtual void ScheduleAnimation() OVERRIDE;
[email protected]4d7e46a2013-11-08 05:33:40153 virtual void DidPostSwapBuffers() OVERRIDE;
154 virtual void DidAbortSwapBuffers() OVERRIDE;
[email protected]943528e2013-11-07 05:01:32155
[email protected]200a9c062013-05-20 04:34:37156 private:
[email protected]c5fa4c42013-07-20 05:47:37157 RenderWidgetCompositor(RenderWidget* widget, bool threaded);
[email protected]ba91a792013-02-06 09:48:28158
[email protected]e96e3432013-12-19 18:56:07159 void Initialize(cc::LayerTreeSettings settings);
[email protected]ba91a792013-02-06 09:48:28160
161 bool threaded_;
162 RenderWidget* widget_;
[email protected]ba91a792013-02-06 09:48:28163 scoped_ptr<cc::LayerTreeHost> layer_tree_host_;
ernstm50aec922014-08-26 22:16:11164
enne89e6c3aa2014-10-01 15:07:59165 scoped_ptr<cc::CopyOutputRequest> temporary_copy_output_request_;
166
ernstm50aec922014-08-26 22:16:11167 bool send_v8_idle_notification_after_commit_;
168 base::TimeTicks begin_main_frame_time_;
169 // The time interval between BeginMainFrame calls, provided by the scheduler.
170 base::TimeDelta begin_main_frame_interval_;
[email protected]ba91a792013-02-06 09:48:28171};
172
173} // namespace content
174
175#endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_