[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 1 | // 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] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 8 | #include "base/callback.h" |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 9 | #include "base/memory/weak_ptr.h" |
[email protected] | abb52216 | 2013-06-28 01:54:16 | [diff] [blame] | 10 | #include "base/time/time.h" |
[email protected] | 752e2cf | 2013-10-21 21:41:15 | [diff] [blame] | 11 | #include "base/values.h" |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 12 | #include "cc/base/swap_promise_monitor.h" |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 13 | #include "cc/input/top_controls_state.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 14 | #include "cc/trees/layer_tree_host_client.h" |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 15 | #include "cc/trees/layer_tree_host_single_thread_client.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 16 | #include "cc/trees/layer_tree_settings.h" |
[email protected] | 5c30b5e0 | 2013-05-30 03:46:08 | [diff] [blame] | 17 | #include "third_party/WebKit/public/platform/WebLayerTreeView.h" |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 18 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | 0bc1f57 | 2013-04-17 01:46:31 | [diff] [blame] | 19 | #include "ui/gfx/rect.h" |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 20 | |
[email protected] | 4b15766 | 2013-05-29 04:05:05 | [diff] [blame] | 21 | namespace ui { |
| 22 | struct LatencyInfo; |
| 23 | } |
| 24 | |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 25 | namespace cc { |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 26 | class InputHandler; |
[email protected] | f7837a9 | 2013-08-21 03:00:05 | [diff] [blame] | 27 | class Layer; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 28 | class LayerTreeHost; |
| 29 | } |
| 30 | |
| 31 | namespace content { |
| 32 | class RenderWidget; |
| 33 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 34 | class RenderWidgetCompositor : public blink::WebLayerTreeView, |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 35 | public cc::LayerTreeHostClient, |
| 36 | public cc::LayerTreeHostSingleThreadClient { |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 37 | public: |
| 38 | // Attempt to construct and initialize a compositor instance for the widget |
| 39 | // with the given settings. Returns NULL if initialization fails. |
[email protected] | c5fa4c4 | 2013-07-20 05:47:37 | [diff] [blame] | 40 | static scoped_ptr<RenderWidgetCompositor> Create(RenderWidget* widget, |
| 41 | bool threaded); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 42 | |
| 43 | virtual ~RenderWidgetCompositor(); |
| 44 | |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 45 | const base::WeakPtr<cc::InputHandler>& GetInputHandler(); |
[email protected] | 9ed83fe | 2013-02-27 01:52:28 | [diff] [blame] | 46 | void SetSuppressScheduleComposite(bool suppress); |
[email protected] | 971728d | 2013-10-26 10:39:31 | [diff] [blame] | 47 | bool BeginMainFrameRequested() const; |
[email protected] | e197af30 | 2014-02-07 09:36:49 | [diff] [blame] | 48 | void UpdateAnimations(base::TimeTicks time); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 49 | void Composite(base::TimeTicks frame_begin_time); |
[email protected] | 24ed043 | 2013-04-24 07:50:31 | [diff] [blame] | 50 | void SetNeedsDisplayOnAllLayers(); |
[email protected] | 206a392 | 2013-05-17 06:34:12 | [diff] [blame] | 51 | void SetRasterizeOnlyVisibleContent(); |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 52 | void UpdateTopControlsState(cc::TopControlsState constraints, |
| 53 | cc::TopControlsState current, |
[email protected] | 452b4a9 | 2013-03-28 21:24:38 | [diff] [blame] | 54 | bool animate); |
[email protected] | d908376 | 2013-03-24 01:36:40 | [diff] [blame] | 55 | void SetOverdrawBottomHeight(float overdraw_bottom_height); |
[email protected] | 0bc1f57 | 2013-04-17 01:46:31 | [diff] [blame] | 56 | void SetNeedsRedrawRect(gfx::Rect damage_rect); |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 57 | // 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] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 60 | // 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] | 6e89eb7 | 2013-07-23 13:28:22 | [diff] [blame] | 67 | int GetLayerTreeId() const; |
[email protected] | df09e05 | 2013-07-31 18:59:50 | [diff] [blame] | 68 | void NotifyInputThrottledUntilCommit(); |
[email protected] | f7837a9 | 2013-08-21 03:00:05 | [diff] [blame] | 69 | const cc::Layer* GetRootLayer() const; |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 70 | bool ScheduleMicroBenchmark( |
| 71 | const std::string& name, |
[email protected] | 752e2cf | 2013-10-21 21:41:15 | [diff] [blame] | 72 | scoped_ptr<base::Value> value, |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 73 | const base::Callback<void(scoped_ptr<base::Value>)>& callback); |
[email protected] | 9ed83fe | 2013-02-27 01:52:28 | [diff] [blame] | 74 | |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 75 | // WebLayerTreeView implementation. |
| 76 | virtual void setSurfaceReady(); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 77 | virtual void setRootLayer(const blink::WebLayer& layer); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 78 | virtual void clearRootLayer(); |
| 79 | virtual void setViewportSize( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 80 | const blink::WebSize& unused_deprecated, |
| 81 | const blink::WebSize& device_viewport_size); |
| 82 | virtual blink::WebSize layoutViewportSize() const; |
| 83 | virtual blink::WebSize deviceViewportSize() const; |
| 84 | virtual blink::WebFloatPoint adjustEventPointForPinchZoom( |
| 85 | const blink::WebFloatPoint& point) const; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 86 | virtual void setDeviceScaleFactor(float device_scale); |
| 87 | virtual float deviceScaleFactor() const; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 88 | virtual void setBackgroundColor(blink::WebColor color); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 89 | virtual void setHasTransparentBackground(bool transparent); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 90 | virtual void setOverhangBitmap(const SkBitmap& bitmap); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 91 | virtual void setVisible(bool visible); |
| 92 | virtual void setPageScaleFactorAndLimits(float page_scale_factor, |
| 93 | float minimum, |
| 94 | float maximum); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 95 | virtual void startPageScaleAnimation(const blink::WebPoint& destination, |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 96 | bool use_anchor, |
| 97 | float new_page_scale, |
| 98 | double duration_sec); |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 99 | virtual void setNeedsAnimate(); |
| 100 | virtual bool commitRequested() const; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 101 | virtual void didStopFlinging(); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 102 | virtual bool compositeAndReadback(void *pixels, const blink::WebRect& rect); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 103 | virtual void finishAllRendering(); |
| 104 | virtual void setDeferCommits(bool defer_commits); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 105 | virtual void registerForAnimations(blink::WebLayer* layer); |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 106 | virtual void registerViewportLayers( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 107 | const blink::WebLayer* pageScaleLayer, |
| 108 | const blink::WebLayer* innerViewportScrollLayer, |
| 109 | const blink::WebLayer* outerViewportScrollLayer) OVERRIDE; |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 110 | virtual void clearViewportLayers() OVERRIDE; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 111 | virtual void setShowFPSCounter(bool show); |
| 112 | virtual void setShowPaintRects(bool show); |
[email protected] | d3be028 | 2013-02-07 19:00:23 | [diff] [blame] | 113 | virtual void setShowDebugBorders(bool show); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 114 | virtual void setContinuousPaintingEnabled(bool enabled); |
[email protected] | 32802a3 | 2013-07-04 11:45:41 | [diff] [blame] | 115 | virtual void setShowScrollBottleneckRects(bool show); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 116 | |
| 117 | // cc::LayerTreeHostClient implementation. |
[email protected] | 3300477 | 2013-11-12 09:49:23 | [diff] [blame] | 118 | virtual void WillBeginMainFrame(int frame_id) OVERRIDE; |
[email protected] | daea3d4 | 2013-10-23 17:04:50 | [diff] [blame] | 119 | virtual void DidBeginMainFrame() OVERRIDE; |
[email protected] | e197af30 | 2014-02-07 09:36:49 | [diff] [blame] | 120 | virtual void Animate(base::TimeTicks frame_begin_time) OVERRIDE; |
[email protected] | 408b5e2 | 2013-03-19 09:48:09 | [diff] [blame] | 121 | virtual void Layout() OVERRIDE; |
[email protected] | 243e4f1 | 2014-02-05 09:18:42 | [diff] [blame] | 122 | virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 123 | float page_scale) OVERRIDE; |
[email protected] | ebc0e1df | 2013-08-01 02:46:22 | [diff] [blame] | 124 | virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) |
| 125 | OVERRIDE; |
[email protected] | da8e3b72b | 2014-04-25 02:33:45 | [diff] [blame^] | 126 | virtual void DidInitializeOutputSurface() OVERRIDE; |
[email protected] | 408b5e2 | 2013-03-19 09:48:09 | [diff] [blame] | 127 | virtual void WillCommit() OVERRIDE; |
| 128 | virtual void DidCommit() OVERRIDE; |
| 129 | virtual void DidCommitAndDrawFrame() OVERRIDE; |
| 130 | virtual void DidCompleteSwapBuffers() OVERRIDE; |
[email protected] | aeeb337 | 2013-11-05 14:05:54 | [diff] [blame] | 131 | virtual void RateLimitSharedMainThreadContext() OVERRIDE; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 132 | |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 133 | // cc::LayerTreeHostSingleThreadClient implementation. |
| 134 | virtual void ScheduleComposite() OVERRIDE; |
[email protected] | e3067e3 | 2013-11-22 07:51:45 | [diff] [blame] | 135 | virtual void ScheduleAnimation() OVERRIDE; |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 136 | virtual void DidPostSwapBuffers() OVERRIDE; |
| 137 | virtual void DidAbortSwapBuffers() OVERRIDE; |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 138 | |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 139 | private: |
[email protected] | c5fa4c4 | 2013-07-20 05:47:37 | [diff] [blame] | 140 | RenderWidgetCompositor(RenderWidget* widget, bool threaded); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 141 | |
[email protected] | e96e343 | 2013-12-19 18:56:07 | [diff] [blame] | 142 | void Initialize(cc::LayerTreeSettings settings); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 143 | |
| 144 | bool threaded_; |
[email protected] | 9ed83fe | 2013-02-27 01:52:28 | [diff] [blame] | 145 | bool suppress_schedule_composite_; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 146 | RenderWidget* widget_; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 147 | scoped_ptr<cc::LayerTreeHost> layer_tree_host_; |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | } // namespace content |
| 151 | |
| 152 | #endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_ |