blob: 1328c8dceddc782039d627e72c82853bb169c7ba [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"
[email protected]5c30b5e02013-05-30 03:46:0818#include "third_party/WebKit/public/platform/WebLayerTreeView.h"
[email protected]9f4f6a32013-09-04 21:35:1219#include "third_party/skia/include/core/SkBitmap.h"
[email protected]0bc1f572013-04-17 01:46:3120#include "ui/gfx/rect.h"
[email protected]ba91a792013-02-06 09:48:2821
[email protected]4b157662013-05-29 04:05:0522namespace ui {
23struct LatencyInfo;
24}
25
[email protected]ba91a792013-02-06 09:48:2826namespace cc {
[email protected]200a9c062013-05-20 04:34:3727class InputHandler;
[email protected]f7837a92013-08-21 03:00:0528class Layer;
[email protected]ba91a792013-02-06 09:48:2829class LayerTreeHost;
30}
31
32namespace content {
33class RenderWidget;
34
[email protected]180ef242013-11-07 06:50:4635class RenderWidgetCompositor : public blink::WebLayerTreeView,
[email protected]943528e2013-11-07 05:01:3236 public cc::LayerTreeHostClient,
37 public cc::LayerTreeHostSingleThreadClient {
[email protected]ba91a792013-02-06 09:48:2838 public:
39 // Attempt to construct and initialize a compositor instance for the widget
40 // with the given settings. Returns NULL if initialization fails.
[email protected]c5fa4c42013-07-20 05:47:3741 static scoped_ptr<RenderWidgetCompositor> Create(RenderWidget* widget,
42 bool threaded);
[email protected]ba91a792013-02-06 09:48:2843
44 virtual ~RenderWidgetCompositor();
45
[email protected]200a9c062013-05-20 04:34:3746 const base::WeakPtr<cc::InputHandler>& GetInputHandler();
[email protected]9ed83fe2013-02-27 01:52:2847 void SetSuppressScheduleComposite(bool suppress);
[email protected]971728d2013-10-26 10:39:3148 bool BeginMainFrameRequested() const;
[email protected]dfbded22014-06-28 17:57:3249 void UpdateAnimations(base::TimeTicks time);
[email protected]24ed0432013-04-24 07:50:3150 void SetNeedsDisplayOnAllLayers();
[email protected]206a3922013-05-17 06:34:1251 void SetRasterizeOnlyVisibleContent();
[email protected]9b003482013-05-21 14:00:1752 void UpdateTopControlsState(cc::TopControlsState constraints,
53 cc::TopControlsState current,
[email protected]452b4a92013-03-28 21:24:3854 bool animate);
[email protected]d9083762013-03-24 01:36:4055 void SetOverdrawBottomHeight(float overdraw_bottom_height);
[email protected]0bc1f572013-04-17 01:46:3156 void SetNeedsRedrawRect(gfx::Rect damage_rect);
[email protected]7d08a9352013-10-15 08:24:5657 // Like setNeedsRedraw but forces the frame to be drawn, without early-outs.
58 // Redraw will be forced after the next commit
59 void SetNeedsForcedRedraw();
[email protected]6be422b2013-12-08 06:47:3160 // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped
61 // LatencyInfoSwapPromiseMonitor. During the life time of the
62 // LatencyInfoSwapPromiseMonitor, if SetNeedsCommit() or SetNeedsUpdateLayer()
63 // is called on LayerTreeHost, the original latency info will be turned
64 // into a LatencyInfoSwapPromise.
65 scoped_ptr<cc::SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
66 ui::LatencyInfo* latency);
[email protected]8062ab262014-05-27 16:56:4367 // Calling QueueSwapPromise() to directly queue a SwapPromise into
68 // LayerTreeHost.
69 void QueueSwapPromise(scoped_ptr<cc::SwapPromise> swap_promise);
[email protected]6e89eb72013-07-23 13:28:2270 int GetLayerTreeId() const;
[email protected]df09e052013-07-31 18:59:5071 void NotifyInputThrottledUntilCommit();
[email protected]f7837a92013-08-21 03:00:0572 const cc::Layer* GetRootLayer() const;
[email protected]67e703e12014-05-30 05:31:5173 int ScheduleMicroBenchmark(
[email protected]666d7cf2013-10-12 01:30:2974 const std::string& name,
[email protected]752e2cf2013-10-21 21:41:1575 scoped_ptr<base::Value> value,
[email protected]666d7cf2013-10-12 01:30:2976 const base::Callback<void(scoped_ptr<base::Value>)>& callback);
[email protected]67e703e12014-05-30 05:31:5177 bool SendMessageToMicroBenchmark(int id, scoped_ptr<base::Value> value);
[email protected]9ed83fe2013-02-27 01:52:2878
[email protected]ba91a792013-02-06 09:48:2879 // WebLayerTreeView implementation.
80 virtual void setSurfaceReady();
[email protected]180ef242013-11-07 06:50:4681 virtual void setRootLayer(const blink::WebLayer& layer);
[email protected]ba91a792013-02-06 09:48:2882 virtual void clearRootLayer();
83 virtual void setViewportSize(
[email protected]180ef242013-11-07 06:50:4684 const blink::WebSize& unused_deprecated,
85 const blink::WebSize& device_viewport_size);
[email protected]4a571892014-05-22 05:52:3086 virtual void setViewportSize(const blink::WebSize& device_viewport_size);
[email protected]180ef242013-11-07 06:50:4687 virtual blink::WebSize layoutViewportSize() const;
88 virtual blink::WebSize deviceViewportSize() const;
89 virtual blink::WebFloatPoint adjustEventPointForPinchZoom(
90 const blink::WebFloatPoint& point) const;
[email protected]ba91a792013-02-06 09:48:2891 virtual void setDeviceScaleFactor(float device_scale);
92 virtual float deviceScaleFactor() const;
[email protected]180ef242013-11-07 06:50:4693 virtual void setBackgroundColor(blink::WebColor color);
[email protected]ba91a792013-02-06 09:48:2894 virtual void setHasTransparentBackground(bool transparent);
[email protected]9f4f6a32013-09-04 21:35:1295 virtual void setOverhangBitmap(const SkBitmap& bitmap);
[email protected]ba91a792013-02-06 09:48:2896 virtual void setVisible(bool visible);
97 virtual void setPageScaleFactorAndLimits(float page_scale_factor,
98 float minimum,
99 float maximum);
[email protected]180ef242013-11-07 06:50:46100 virtual void startPageScaleAnimation(const blink::WebPoint& destination,
[email protected]ba91a792013-02-06 09:48:28101 bool use_anchor,
102 float new_page_scale,
103 double duration_sec);
[email protected]27a747d2014-04-30 10:23:01104 virtual void heuristicsForGpuRasterizationUpdated(bool matches_heuristics);
[email protected]8b9e52b2014-01-17 16:35:31105 virtual void setNeedsAnimate();
106 virtual bool commitRequested() const;
[email protected]ba91a792013-02-06 09:48:28107 virtual void didStopFlinging();
[email protected]9e4067f42014-05-02 20:57:10108 virtual void compositeAndReadbackAsync(
109 blink::WebCompositeAndReadbackAsyncCallback* callback);
[email protected]ba91a792013-02-06 09:48:28110 virtual void finishAllRendering();
111 virtual void setDeferCommits(bool defer_commits);
[email protected]180ef242013-11-07 06:50:46112 virtual void registerForAnimations(blink::WebLayer* layer);
[email protected]57ac9482013-09-17 21:13:39113 virtual void registerViewportLayers(
[email protected]180ef242013-11-07 06:50:46114 const blink::WebLayer* pageScaleLayer,
115 const blink::WebLayer* innerViewportScrollLayer,
116 const blink::WebLayer* outerViewportScrollLayer) OVERRIDE;
[email protected]57ac9482013-09-17 21:13:39117 virtual void clearViewportLayers() OVERRIDE;
[email protected]ebb179b2014-07-16 17:54:41118 virtual void registerSelection(const blink::WebSelectionBound& start,
119 const blink::WebSelectionBound& end) OVERRIDE;
[email protected]19aec372014-07-01 19:08:49120 virtual void clearSelection() OVERRIDE;
[email protected]ba91a792013-02-06 09:48:28121 virtual void setShowFPSCounter(bool show);
122 virtual void setShowPaintRects(bool show);
[email protected]d3be0282013-02-07 19:00:23123 virtual void setShowDebugBorders(bool show);
[email protected]ba91a792013-02-06 09:48:28124 virtual void setContinuousPaintingEnabled(bool enabled);
[email protected]32802a32013-07-04 11:45:41125 virtual void setShowScrollBottleneckRects(bool show);
[email protected]ba91a792013-02-06 09:48:28126
127 // cc::LayerTreeHostClient implementation.
[email protected]33004772013-11-12 09:49:23128 virtual void WillBeginMainFrame(int frame_id) OVERRIDE;
[email protected]daea3d42013-10-23 17:04:50129 virtual void DidBeginMainFrame() OVERRIDE;
[email protected]e197af302014-02-07 09:36:49130 virtual void Animate(base::TimeTicks frame_begin_time) OVERRIDE;
[email protected]408b5e22013-03-19 09:48:09131 virtual void Layout() OVERRIDE;
[email protected]243e4f12014-02-05 09:18:42132 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta,
[email protected]ba91a792013-02-06 09:48:28133 float page_scale) OVERRIDE;
[email protected]ebc0e1df2013-08-01 02:46:22134 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback)
135 OVERRIDE;
[email protected]da8e3b72b2014-04-25 02:33:45136 virtual void DidInitializeOutputSurface() OVERRIDE;
[email protected]408b5e22013-03-19 09:48:09137 virtual void WillCommit() OVERRIDE;
138 virtual void DidCommit() OVERRIDE;
139 virtual void DidCommitAndDrawFrame() OVERRIDE;
140 virtual void DidCompleteSwapBuffers() OVERRIDE;
[email protected]aeeb3372013-11-05 14:05:54141 virtual void RateLimitSharedMainThreadContext() OVERRIDE;
[email protected]ba91a792013-02-06 09:48:28142
[email protected]943528e2013-11-07 05:01:32143 // cc::LayerTreeHostSingleThreadClient implementation.
[email protected]dfbded22014-06-28 17:57:32144 virtual void ScheduleComposite() OVERRIDE;
145 virtual void ScheduleAnimation() OVERRIDE;
[email protected]4d7e46a2013-11-08 05:33:40146 virtual void DidPostSwapBuffers() OVERRIDE;
147 virtual void DidAbortSwapBuffers() OVERRIDE;
[email protected]943528e2013-11-07 05:01:32148
[email protected]200a9c062013-05-20 04:34:37149 private:
[email protected]c5fa4c42013-07-20 05:47:37150 RenderWidgetCompositor(RenderWidget* widget, bool threaded);
[email protected]ba91a792013-02-06 09:48:28151
[email protected]e96e3432013-12-19 18:56:07152 void Initialize(cc::LayerTreeSettings settings);
[email protected]ba91a792013-02-06 09:48:28153
154 bool threaded_;
[email protected]dfbded22014-06-28 17:57:32155 bool suppress_schedule_composite_;
[email protected]ba91a792013-02-06 09:48:28156 RenderWidget* widget_;
[email protected]ba91a792013-02-06 09:48:28157 scoped_ptr<cc::LayerTreeHost> layer_tree_host_;
[email protected]ba91a792013-02-06 09:48:28158};
159
160} // namespace content
161
162#endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_