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 8 #include "base/callback.h" 9 #include "base/memory/weak_ptr.h" 10 #include "base/time/time.h" 11 #include "base/values.h" 12 #include "cc/base/swap_promise.h" 13 #include "cc/base/swap_promise_monitor.h" 14 #include "cc/input/top_controls_state.h" 15 #include "cc/trees/layer_tree_host_client.h" 16 #include "cc/trees/layer_tree_host_single_thread_client.h" 17 #include "cc/trees/layer_tree_settings.h" 18 #include "content/common/content_export.h" 19 #include "third_party/WebKit/public/platform/WebLayerTreeView.h" 20 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "ui/gfx/rect.h" 22 23 namespace ui { 24 struct LatencyInfo; 25 } 26 27 namespace cc { 28 class InputHandler; 29 class Layer; 30 class LayerTreeHost; 31 } 32 33 namespace content { 34 class RenderWidget; 35 36 class CONTENT_EXPORT RenderWidgetCompositor NON_EXPORTED_BASE(public blink::WebLayerTreeView)37 : NON_EXPORTED_BASE(public blink::WebLayerTreeView), 38 NON_EXPORTED_BASE(public cc::LayerTreeHostClient), 39 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { 40 public: 41 // Attempt to construct and initialize a compositor instance for the widget 42 // with the given settings. Returns NULL if initialization fails. 43 static scoped_ptr<RenderWidgetCompositor> Create(RenderWidget* widget, 44 bool threaded); 45 46 virtual ~RenderWidgetCompositor(); 47 48 const base::WeakPtr<cc::InputHandler>& GetInputHandler(); 49 bool BeginMainFrameRequested() const; 50 void SetNeedsDisplayOnAllLayers(); 51 void SetRasterizeOnlyVisibleContent(); 52 void UpdateTopControlsState(cc::TopControlsState constraints, 53 cc::TopControlsState current, 54 bool animate); 55 void SetTopControlsLayoutHeight(float height); 56 void SetNeedsRedrawRect(gfx::Rect damage_rect); 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(); 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); 67 // Calling QueueSwapPromise() to directly queue a SwapPromise into 68 // LayerTreeHost. 69 void QueueSwapPromise(scoped_ptr<cc::SwapPromise> swap_promise); 70 int GetLayerTreeId() const; 71 int GetSourceFrameNumber() const; 72 void SetNeedsCommit(); 73 void NotifyInputThrottledUntilCommit(); 74 const cc::Layer* GetRootLayer() const; 75 int ScheduleMicroBenchmark( 76 const std::string& name, 77 scoped_ptr<base::Value> value, 78 const base::Callback<void(scoped_ptr<base::Value>)>& callback); 79 bool SendMessageToMicroBenchmark(int id, scoped_ptr<base::Value> value); 80 81 // WebLayerTreeView implementation. 82 virtual void setSurfaceReady(); 83 virtual void setRootLayer(const blink::WebLayer& layer); 84 virtual void clearRootLayer(); 85 virtual void setViewportSize( 86 const blink::WebSize& unused_deprecated, 87 const blink::WebSize& device_viewport_size); 88 virtual void setViewportSize(const blink::WebSize& device_viewport_size); 89 virtual blink::WebSize layoutViewportSize() const; 90 virtual blink::WebSize deviceViewportSize() const; 91 virtual blink::WebFloatPoint adjustEventPointForPinchZoom( 92 const blink::WebFloatPoint& point) const; 93 virtual void setDeviceScaleFactor(float device_scale); 94 virtual float deviceScaleFactor() const; 95 virtual void setBackgroundColor(blink::WebColor color); 96 virtual void setHasTransparentBackground(bool transparent); 97 virtual void setOverhangBitmap(const SkBitmap& bitmap); 98 virtual void setVisible(bool visible); 99 virtual void setPageScaleFactorAndLimits(float page_scale_factor, 100 float minimum, 101 float maximum); 102 virtual void startPageScaleAnimation(const blink::WebPoint& destination, 103 bool use_anchor, 104 float new_page_scale, 105 double duration_sec); 106 virtual void heuristicsForGpuRasterizationUpdated(bool matches_heuristics); 107 virtual void setNeedsAnimate(); 108 virtual bool commitRequested() const; 109 virtual void didStopFlinging(); 110 virtual void compositeAndReadbackAsync( 111 blink::WebCompositeAndReadbackAsyncCallback* callback); 112 virtual void finishAllRendering(); 113 virtual void setDeferCommits(bool defer_commits); 114 virtual void registerForAnimations(blink::WebLayer* layer); 115 virtual void registerViewportLayers( 116 const blink::WebLayer* pageScaleLayer, 117 const blink::WebLayer* innerViewportScrollLayer, 118 const blink::WebLayer* outerViewportScrollLayer) OVERRIDE; 119 virtual void clearViewportLayers() OVERRIDE; 120 virtual void registerSelection(const blink::WebSelectionBound& start, 121 const blink::WebSelectionBound& end) OVERRIDE; 122 virtual void clearSelection() OVERRIDE; 123 virtual void setShowFPSCounter(bool show); 124 virtual void setShowPaintRects(bool show); 125 virtual void setShowDebugBorders(bool show); 126 virtual void setContinuousPaintingEnabled(bool enabled); 127 virtual void setShowScrollBottleneckRects(bool show); 128 virtual void setTopControlsContentOffset(float); 129 130 // cc::LayerTreeHostClient implementation. 131 virtual void WillBeginMainFrame(int frame_id) OVERRIDE; 132 virtual void DidBeginMainFrame() OVERRIDE; 133 virtual void BeginMainFrame(const cc::BeginFrameArgs& args) OVERRIDE; 134 virtual void Layout() OVERRIDE; 135 virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta, 136 float page_scale, 137 float top_controls_delta) OVERRIDE; 138 virtual void RequestNewOutputSurface(bool fallback) OVERRIDE; 139 virtual void DidInitializeOutputSurface() OVERRIDE; 140 virtual void WillCommit() OVERRIDE; 141 virtual void DidCommit() OVERRIDE; 142 virtual void DidCommitAndDrawFrame() OVERRIDE; 143 virtual void DidCompleteSwapBuffers() OVERRIDE; 144 virtual void RateLimitSharedMainThreadContext() OVERRIDE; 145 146 // cc::LayerTreeHostSingleThreadClient implementation. 147 virtual void ScheduleAnimation() OVERRIDE; 148 virtual void DidPostSwapBuffers() OVERRIDE; 149 virtual void DidAbortSwapBuffers() OVERRIDE; 150 151 private: 152 RenderWidgetCompositor(RenderWidget* widget, bool threaded); 153 154 void Initialize(cc::LayerTreeSettings settings); 155 156 bool threaded_; 157 RenderWidget* widget_; 158 scoped_ptr<cc::LayerTreeHost> layer_tree_host_; 159 160 bool send_v8_idle_notification_after_commit_; 161 base::TimeTicks begin_main_frame_time_; 162 // The time interval between BeginMainFrame calls, provided by the scheduler. 163 base::TimeDelta begin_main_frame_interval_; 164 }; 165 166 } // namespace content 167 168 #endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_ 169