Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / renderer / gpu / render_widget_compositor.h
blob4658e44b5806d6ccc2639a2b0e001b0f9319cb7b
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.
5 #ifndef CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_
6 #define CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_
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 "third_party/WebKit/public/platform/WebLayerTreeView.h"
19 #include "third_party/skia/include/core/SkBitmap.h"
20 #include "ui/gfx/rect.h"
22 namespace ui {
23 struct LatencyInfo;
26 namespace cc {
27 class InputHandler;
28 class Layer;
29 class LayerTreeHost;
32 namespace content {
33 class RenderWidget;
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);
44 virtual ~RenderWidgetCompositor();
46 const base::WeakPtr<cc::InputHandler>& GetInputHandler();
47 bool BeginMainFrameRequested() const;
48 void SetNeedsDisplayOnAllLayers();
49 void SetRasterizeOnlyVisibleContent();
50 void UpdateTopControlsState(cc::TopControlsState constraints,
51 cc::TopControlsState current,
52 bool animate);
53 void SetTopControlsLayoutHeight(float top_controls_layout_height);
54 void SetNeedsRedrawRect(gfx::Rect damage_rect);
55 // Like setNeedsRedraw but forces the frame to be drawn, without early-outs.
56 // Redraw will be forced after the next commit
57 void SetNeedsForcedRedraw();
58 // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped
59 // LatencyInfoSwapPromiseMonitor. During the life time of the
60 // LatencyInfoSwapPromiseMonitor, if SetNeedsCommit() or SetNeedsUpdateLayer()
61 // is called on LayerTreeHost, the original latency info will be turned
62 // into a LatencyInfoSwapPromise.
63 scoped_ptr<cc::SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
64 ui::LatencyInfo* latency);
65 // Calling QueueSwapPromise() to directly queue a SwapPromise into
66 // LayerTreeHost.
67 void QueueSwapPromise(scoped_ptr<cc::SwapPromise> swap_promise);
68 int GetLayerTreeId() const;
69 int GetSourceFrameNumber() const;
70 void SetNeedsCommit();
71 void NotifyInputThrottledUntilCommit();
72 const cc::Layer* GetRootLayer() const;
73 int ScheduleMicroBenchmark(
74 const std::string& name,
75 scoped_ptr<base::Value> value,
76 const base::Callback<void(scoped_ptr<base::Value>)>& callback);
77 bool SendMessageToMicroBenchmark(int id, scoped_ptr<base::Value> value);
79 // WebLayerTreeView implementation.
80 virtual void setSurfaceReady();
81 virtual void setRootLayer(const blink::WebLayer& layer);
82 virtual void clearRootLayer();
83 virtual void setViewportSize(
84 const blink::WebSize& unused_deprecated,
85 const blink::WebSize& device_viewport_size);
86 virtual void setViewportSize(const blink::WebSize& device_viewport_size);
87 virtual blink::WebSize layoutViewportSize() const;
88 virtual blink::WebSize deviceViewportSize() const;
89 virtual blink::WebFloatPoint adjustEventPointForPinchZoom(
90 const blink::WebFloatPoint& point) const;
91 virtual void setDeviceScaleFactor(float device_scale);
92 virtual float deviceScaleFactor() const;
93 virtual void setBackgroundColor(blink::WebColor color);
94 virtual void setHasTransparentBackground(bool transparent);
95 virtual void setOverhangBitmap(const SkBitmap& bitmap);
96 virtual void setVisible(bool visible);
97 virtual void setPageScaleFactorAndLimits(float page_scale_factor,
98 float minimum,
99 float maximum);
100 virtual void startPageScaleAnimation(const blink::WebPoint& destination,
101 bool use_anchor,
102 float new_page_scale,
103 double duration_sec);
104 virtual void heuristicsForGpuRasterizationUpdated(bool matches_heuristics);
105 virtual void setNeedsAnimate();
106 virtual bool commitRequested() const;
107 virtual void didStopFlinging();
108 virtual void compositeAndReadbackAsync(
109 blink::WebCompositeAndReadbackAsyncCallback* callback);
110 virtual void finishAllRendering();
111 virtual void setDeferCommits(bool defer_commits);
112 virtual void registerForAnimations(blink::WebLayer* layer);
113 virtual void registerViewportLayers(
114 const blink::WebLayer* pageScaleLayer,
115 const blink::WebLayer* innerViewportScrollLayer,
116 const blink::WebLayer* outerViewportScrollLayer) OVERRIDE;
117 virtual void clearViewportLayers() OVERRIDE;
118 virtual void registerSelection(const blink::WebSelectionBound& start,
119 const blink::WebSelectionBound& end) OVERRIDE;
120 virtual void clearSelection() OVERRIDE;
121 virtual void setShowFPSCounter(bool show);
122 virtual void setShowPaintRects(bool show);
123 virtual void setShowDebugBorders(bool show);
124 virtual void setContinuousPaintingEnabled(bool enabled);
125 virtual void setShowScrollBottleneckRects(bool show);
127 // cc::LayerTreeHostClient implementation.
128 virtual void WillBeginMainFrame(int frame_id) OVERRIDE;
129 virtual void DidBeginMainFrame() OVERRIDE;
130 virtual void BeginMainFrame(const cc::BeginFrameArgs& args) OVERRIDE;
131 virtual void Layout() OVERRIDE;
132 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta,
133 float page_scale) OVERRIDE;
134 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback)
135 OVERRIDE;
136 virtual void DidInitializeOutputSurface() OVERRIDE;
137 virtual void WillCommit() OVERRIDE;
138 virtual void DidCommit() OVERRIDE;
139 virtual void DidCommitAndDrawFrame() OVERRIDE;
140 virtual void DidCompleteSwapBuffers() OVERRIDE;
141 virtual void RateLimitSharedMainThreadContext() OVERRIDE;
143 // cc::LayerTreeHostSingleThreadClient implementation.
144 virtual void ScheduleAnimation() OVERRIDE;
145 virtual void DidPostSwapBuffers() OVERRIDE;
146 virtual void DidAbortSwapBuffers() OVERRIDE;
148 private:
149 RenderWidgetCompositor(RenderWidget* widget, bool threaded);
151 void Initialize(cc::LayerTreeSettings settings);
153 bool threaded_;
154 RenderWidget* widget_;
155 scoped_ptr<cc::LayerTreeHost> layer_tree_host_;
157 bool send_v8_idle_notification_after_commit_;
158 base::TimeTicks begin_main_frame_time_;
159 // The time interval between BeginMainFrame calls, provided by the scheduler.
160 base::TimeDelta begin_main_frame_interval_;
163 } // namespace content
165 #endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_