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