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_monitor.h" 13 #include "cc/debug/rendering_stats.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 "third_party/WebKit/public/platform/WebLayerTreeView.h" 19 #include "third_party/skia/include/core/SkBitmap.h" 20 #include "ui/gfx/rect.h" 21 22 namespace ui { 23 struct LatencyInfo; 24 } 25 26 namespace cc { 27 class InputHandler; 28 class Layer; 29 class LayerTreeHost; 30 } 31 32 namespace content { 33 class RenderWidget; 34 35 class RenderWidgetCompositor : public blink::WebLayerTreeView, 36 public cc::LayerTreeHostClient, 37 public cc::LayerTreeHostSingleThreadClient { 38 public: 39 // Attempt to construct and initialize a compositor instance for the widget 40 // with the given settings. Returns NULL if initialization fails. 41 static scoped_ptr<RenderWidgetCompositor> Create(RenderWidget* widget, 42 bool threaded); 43 44 virtual ~RenderWidgetCompositor(); 45 46 const base::WeakPtr<cc::InputHandler>& GetInputHandler(); 47 void SetSuppressScheduleComposite(bool suppress); 48 bool BeginMainFrameRequested() const; 49 void Animate(base::TimeTicks time); 50 void Composite(base::TimeTicks frame_begin_time); 51 void SetNeedsDisplayOnAllLayers(); 52 void SetRasterizeOnlyVisibleContent(); 53 void GetRenderingStats(cc::RenderingStats* stats); 54 void UpdateTopControlsState(cc::TopControlsState constraints, 55 cc::TopControlsState current, 56 bool animate); 57 void SetOverdrawBottomHeight(float overdraw_bottom_height); 58 void SetNeedsRedrawRect(gfx::Rect damage_rect); 59 // Like setNeedsRedraw but forces the frame to be drawn, without early-outs. 60 // Redraw will be forced after the next commit 61 void SetNeedsForcedRedraw(); 62 // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped 63 // LatencyInfoSwapPromiseMonitor. During the life time of the 64 // LatencyInfoSwapPromiseMonitor, if SetNeedsCommit() or SetNeedsUpdateLayer() 65 // is called on LayerTreeHost, the original latency info will be turned 66 // into a LatencyInfoSwapPromise. 67 scoped_ptr<cc::SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor( 68 ui::LatencyInfo* latency); 69 int GetLayerTreeId() const; 70 void NotifyInputThrottledUntilCommit(); 71 const cc::Layer* GetRootLayer() const; 72 bool ScheduleMicroBenchmark( 73 const std::string& name, 74 scoped_ptr<base::Value> value, 75 const base::Callback<void(scoped_ptr<base::Value>)>& callback); 76 77 // WebLayerTreeView implementation. 78 virtual void setSurfaceReady(); 79 virtual void setRootLayer(const blink::WebLayer& layer); 80 virtual void clearRootLayer(); 81 virtual void setViewportSize( 82 const blink::WebSize& unused_deprecated, 83 const blink::WebSize& device_viewport_size); 84 virtual blink::WebSize layoutViewportSize() const; 85 virtual blink::WebSize deviceViewportSize() const; 86 virtual blink::WebFloatPoint adjustEventPointForPinchZoom( 87 const blink::WebFloatPoint& point) const; 88 virtual void setDeviceScaleFactor(float device_scale); 89 virtual float deviceScaleFactor() const; 90 virtual void setBackgroundColor(blink::WebColor color); 91 virtual void setHasTransparentBackground(bool transparent); 92 virtual void setOverhangBitmap(const SkBitmap& bitmap); 93 virtual void setVisible(bool visible); 94 virtual void setPageScaleFactorAndLimits(float page_scale_factor, 95 float minimum, 96 float maximum); 97 virtual void startPageScaleAnimation(const blink::WebPoint& destination, 98 bool use_anchor, 99 float new_page_scale, 100 double duration_sec); 101 virtual void setNeedsAnimate(); 102 virtual bool commitRequested() const; 103 virtual void didStopFlinging(); 104 virtual bool compositeAndReadback(void *pixels, const blink::WebRect& rect); 105 virtual void finishAllRendering(); 106 virtual void setDeferCommits(bool defer_commits); 107 virtual void registerForAnimations(blink::WebLayer* layer); 108 virtual void registerViewportLayers( 109 const blink::WebLayer* pageScaleLayer, 110 const blink::WebLayer* innerViewportScrollLayer, 111 const blink::WebLayer* outerViewportScrollLayer) OVERRIDE; 112 virtual void clearViewportLayers() OVERRIDE; 113 virtual void renderingStats(blink::WebRenderingStats& stats) const {} 114 virtual void setShowFPSCounter(bool show); 115 virtual void setShowPaintRects(bool show); 116 virtual void setShowDebugBorders(bool show); 117 virtual void setContinuousPaintingEnabled(bool enabled); 118 virtual void setShowScrollBottleneckRects(bool show); 119 120 // cc::LayerTreeHostClient implementation. 121 virtual void WillBeginMainFrame(int frame_id) OVERRIDE; 122 virtual void DidBeginMainFrame() OVERRIDE; 123 virtual void Animate(double frame_begin_time) OVERRIDE; 124 virtual void Layout() OVERRIDE; 125 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, 126 float page_scale) OVERRIDE; 127 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) 128 OVERRIDE; 129 virtual void DidInitializeOutputSurface(bool success) OVERRIDE; 130 virtual void WillCommit() OVERRIDE; 131 virtual void DidCommit() OVERRIDE; 132 virtual void DidCommitAndDrawFrame() OVERRIDE; 133 virtual void DidCompleteSwapBuffers() OVERRIDE; 134 virtual scoped_refptr<cc::ContextProvider> 135 OffscreenContextProvider() OVERRIDE; 136 virtual void RateLimitSharedMainThreadContext() OVERRIDE; 137 138 // cc::LayerTreeHostSingleThreadClient implementation. 139 virtual void ScheduleComposite() OVERRIDE; 140 virtual void ScheduleAnimation() OVERRIDE; 141 virtual void DidPostSwapBuffers() OVERRIDE; 142 virtual void DidAbortSwapBuffers() OVERRIDE; 143 144 private: 145 RenderWidgetCompositor(RenderWidget* widget, bool threaded); 146 147 bool Initialize(cc::LayerTreeSettings settings); 148 149 bool threaded_; 150 bool suppress_schedule_composite_; 151 RenderWidget* widget_; 152 scoped_ptr<cc::LayerTreeHost> layer_tree_host_; 153 }; 154 155 } // namespace content 156 157 #endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_ 158