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/memory/weak_ptr.h" 9 #include "base/time/time.h" 10 #include "cc/debug/rendering_stats.h" 11 #include "cc/input/top_controls_state.h" 12 #include "cc/trees/layer_tree_host_client.h" 13 #include "cc/trees/layer_tree_settings.h" 14 #include "third_party/WebKit/public/platform/WebLayerTreeView.h" 15 #include "ui/gfx/rect.h" 16 17 namespace ui { 18 struct LatencyInfo; 19 } 20 21 namespace cc { 22 class InputHandler; 23 class LayerTreeHost; 24 } 25 26 namespace content { 27 class RenderWidget; 28 29 class RenderWidgetCompositor : public WebKit::WebLayerTreeView, 30 public cc::LayerTreeHostClient { 31 public: 32 // Attempt to construct and initialize a compositor instance for the widget 33 // with the given settings. Returns NULL if initialization fails. 34 static scoped_ptr<RenderWidgetCompositor> Create(RenderWidget* widget, 35 bool threaded); 36 37 virtual ~RenderWidgetCompositor(); 38 39 const base::WeakPtr<cc::InputHandler>& GetInputHandler(); 40 void SetSuppressScheduleComposite(bool suppress); 41 void Animate(base::TimeTicks time); 42 void Composite(base::TimeTicks frame_begin_time); 43 void SetNeedsDisplayOnAllLayers(); 44 void SetRasterizeOnlyVisibleContent(); 45 void GetRenderingStats(cc::RenderingStats* stats); 46 void UpdateTopControlsState(cc::TopControlsState constraints, 47 cc::TopControlsState current, 48 bool animate); 49 void SetOverdrawBottomHeight(float overdraw_bottom_height); 50 void SetNeedsRedrawRect(gfx::Rect damage_rect); 51 void SetLatencyInfo(const ui::LatencyInfo& latency_info); 52 int GetLayerTreeId() const; 53 void NotifyInputThrottledUntilCommit(); 54 55 // WebLayerTreeView implementation. 56 virtual void setSurfaceReady(); 57 virtual void setRootLayer(const WebKit::WebLayer& layer); 58 virtual void clearRootLayer(); 59 virtual void setViewportSize( 60 const WebKit::WebSize& unused_deprecated, 61 const WebKit::WebSize& device_viewport_size); 62 virtual WebKit::WebSize layoutViewportSize() const; 63 virtual WebKit::WebSize deviceViewportSize() const; 64 virtual WebKit::WebFloatPoint adjustEventPointForPinchZoom( 65 const WebKit::WebFloatPoint& point) const; 66 virtual void setDeviceScaleFactor(float device_scale); 67 virtual float deviceScaleFactor() const; 68 virtual void setBackgroundColor(WebKit::WebColor color); 69 virtual void setHasTransparentBackground(bool transparent); 70 virtual void setVisible(bool visible); 71 virtual void setPageScaleFactorAndLimits(float page_scale_factor, 72 float minimum, 73 float maximum); 74 virtual void startPageScaleAnimation(const WebKit::WebPoint& destination, 75 bool use_anchor, 76 float new_page_scale, 77 double duration_sec); 78 virtual void setNeedsAnimate(); 79 virtual void setNeedsRedraw(); 80 virtual bool commitRequested() const; 81 virtual void didStopFlinging(); 82 virtual bool compositeAndReadback(void *pixels, const WebKit::WebRect& rect); 83 virtual void finishAllRendering(); 84 virtual void setDeferCommits(bool defer_commits); 85 virtual void registerForAnimations(WebKit::WebLayer* layer); 86 virtual void renderingStats(WebKit::WebRenderingStats& stats) const {} 87 virtual void setShowFPSCounter(bool show); 88 virtual void setShowPaintRects(bool show); 89 virtual void setShowDebugBorders(bool show); 90 virtual void setContinuousPaintingEnabled(bool enabled); 91 virtual void setShowScrollBottleneckRects(bool show); 92 93 // cc::LayerTreeHostClient implementation. 94 virtual void WillBeginFrame() OVERRIDE; 95 virtual void DidBeginFrame() OVERRIDE; 96 virtual void Animate(double frame_begin_time) OVERRIDE; 97 virtual void Layout() OVERRIDE; 98 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, 99 float page_scale) OVERRIDE; 100 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) 101 OVERRIDE; 102 virtual void DidInitializeOutputSurface(bool success) OVERRIDE; 103 virtual void WillCommit() OVERRIDE; 104 virtual void DidCommit() OVERRIDE; 105 virtual void DidCommitAndDrawFrame() OVERRIDE; 106 virtual void DidCompleteSwapBuffers() OVERRIDE; 107 virtual void ScheduleComposite() OVERRIDE; 108 virtual scoped_refptr<cc::ContextProvider> 109 OffscreenContextProviderForMainThread() OVERRIDE; 110 virtual scoped_refptr<cc::ContextProvider> 111 OffscreenContextProviderForCompositorThread() OVERRIDE; 112 113 private: 114 RenderWidgetCompositor(RenderWidget* widget, bool threaded); 115 116 bool initialize(cc::LayerTreeSettings settings); 117 118 bool threaded_; 119 bool suppress_schedule_composite_; 120 RenderWidget* widget_; 121 scoped_ptr<cc::LayerTreeHost> layer_tree_host_; 122 }; 123 124 } // namespace content 125 126 #endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_ 127