[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / content / renderer / gpu / render_widget_compositor.h
blobc4f8cab9b3b5baa2fd3d3aec73f486da14efbed7
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/input/top_controls_state.h"
13 #include "cc/output/swap_promise.h"
14 #include "cc/trees/layer_tree_host_client.h"
15 #include "cc/trees/layer_tree_host_single_thread_client.h"
16 #include "cc/trees/layer_tree_settings.h"
17 #include "cc/trees/swap_promise_monitor.h"
18 #include "content/common/content_export.h"
19 #include "content/renderer/gpu/compositor_dependencies.h"
20 #include "third_party/WebKit/public/platform/WebLayerTreeView.h"
21 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "ui/gfx/geometry/rect.h"
24 namespace ui {
25 class LatencyInfo;
28 namespace cc {
29 class CopyOutputRequest;
30 class InputHandler;
31 class Layer;
32 class LayerTreeHost;
35 namespace content {
36 class RenderWidget;
38 class CONTENT_EXPORT RenderWidgetCompositor
39 : NON_EXPORTED_BASE(public blink::WebLayerTreeView),
40 NON_EXPORTED_BASE(public cc::LayerTreeHostClient),
41 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) {
42 public:
43 // Attempt to construct and initialize a compositor instance for the widget
44 // with the given settings. Returns NULL if initialization fails.
45 static scoped_ptr<RenderWidgetCompositor> Create(
46 RenderWidget* widget,
47 CompositorDependencies* compositor_deps);
49 virtual ~RenderWidgetCompositor();
51 const base::WeakPtr<cc::InputHandler>& GetInputHandler();
52 bool BeginMainFrameRequested() const;
53 void SetNeedsDisplayOnAllLayers();
54 void SetRasterizeOnlyVisibleContent();
55 void SetNeedsRedrawRect(gfx::Rect damage_rect);
56 // Like setNeedsRedraw but forces the frame to be drawn, without early-outs.
57 // Redraw will be forced after the next commit
58 void SetNeedsForcedRedraw();
59 // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped
60 // LatencyInfoSwapPromiseMonitor. During the life time of the
61 // LatencyInfoSwapPromiseMonitor, if SetNeedsCommit() or
62 // SetNeedsUpdateLayers() is called on LayerTreeHost, the original latency
63 // info will be turned into a LatencyInfoSwapPromise.
64 scoped_ptr<cc::SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
65 ui::LatencyInfo* latency);
66 // Calling QueueSwapPromise() to directly queue a SwapPromise into
67 // LayerTreeHost.
68 void QueueSwapPromise(scoped_ptr<cc::SwapPromise> swap_promise);
69 int GetSourceFrameNumber() const;
70 void SetNeedsUpdateLayers();
71 void SetNeedsCommit();
72 void NotifyInputThrottledUntilCommit();
73 const cc::Layer* GetRootLayer() const;
74 int ScheduleMicroBenchmark(
75 const std::string& name,
76 scoped_ptr<base::Value> value,
77 const base::Callback<void(scoped_ptr<base::Value>)>& callback);
78 bool SendMessageToMicroBenchmark(int id, scoped_ptr<base::Value> value);
79 void StartCompositor();
80 void SetSurfaceIdNamespace(uint32_t surface_id_namespace);
82 // WebLayerTreeView implementation.
83 virtual void setRootLayer(const blink::WebLayer& layer);
84 virtual void clearRootLayer();
85 virtual void attachCompositorAnimationTimeline(
86 blink::WebCompositorAnimationTimeline* compositor_timeline);
87 virtual void detachCompositorAnimationTimeline(
88 blink::WebCompositorAnimationTimeline* compositor_timeline);
89 virtual void setViewportSize(
90 const blink::WebSize& unused_deprecated,
91 const blink::WebSize& device_viewport_size);
92 virtual void setViewportSize(const blink::WebSize& device_viewport_size);
93 virtual blink::WebSize layoutViewportSize() const;
94 virtual blink::WebSize deviceViewportSize() const;
95 virtual blink::WebFloatPoint adjustEventPointForPinchZoom(
96 const blink::WebFloatPoint& point) const;
97 virtual void setDeviceScaleFactor(float device_scale);
98 virtual float deviceScaleFactor() const;
99 virtual void setBackgroundColor(blink::WebColor color);
100 virtual void setHasTransparentBackground(bool transparent);
101 virtual void setVisible(bool visible);
102 virtual void setPageScaleFactorAndLimits(float page_scale_factor,
103 float minimum,
104 float maximum);
105 virtual void startPageScaleAnimation(const blink::WebPoint& destination,
106 bool use_anchor,
107 float new_page_scale,
108 double duration_sec);
109 virtual void heuristicsForGpuRasterizationUpdated(bool matches_heuristics);
110 virtual void setNeedsAnimate();
111 virtual void setNeedsBeginFrame();
112 virtual void setNeedsCompositorUpdate();
113 virtual void didStopFlinging();
114 virtual void layoutAndPaintAsync(
115 blink::WebLayoutAndPaintAsyncCallback* callback);
116 virtual void compositeAndReadbackAsync(
117 blink::WebCompositeAndReadbackAsyncCallback* callback);
118 virtual void finishAllRendering();
119 virtual void setDeferCommits(bool defer_commits);
120 virtual void registerForAnimations(blink::WebLayer* layer);
121 virtual void registerViewportLayers(
122 const blink::WebLayer* overscrollElasticityLayer,
123 const blink::WebLayer* pageScaleLayer,
124 const blink::WebLayer* innerViewportScrollLayer,
125 const blink::WebLayer* outerViewportScrollLayer) override;
126 virtual void clearViewportLayers() override;
127 virtual void registerSelection(const blink::WebSelection& selection) override;
128 virtual void clearSelection() override;
129 virtual int layerTreeId() const;
130 virtual void setShowFPSCounter(bool show);
131 virtual void setShowPaintRects(bool show);
132 virtual void setShowDebugBorders(bool show);
133 virtual void setContinuousPaintingEnabled(bool enabled);
134 virtual void setShowScrollBottleneckRects(bool show);
136 virtual void updateTopControlsState(blink::WebTopControlsState constraints,
137 blink::WebTopControlsState current,
138 bool animate);
139 virtual void setTopControlsHeight(float height, bool shrink);
140 virtual void setTopControlsShownRatio(float);
141 virtual void setHidePinchScrollbarsNearMinScale(bool) override;
143 // cc::LayerTreeHostClient implementation.
144 void WillBeginMainFrame() override;
145 void DidBeginMainFrame() override;
146 void BeginMainFrame(const cc::BeginFrameArgs& args) override;
147 void BeginMainFrameNotExpectedSoon() override;
148 void Layout() override;
149 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
150 const gfx::Vector2dF& outer_delta,
151 const gfx::Vector2dF& elastic_overscroll_delta,
152 float page_scale,
153 float top_controls_delta) override;
154 void RequestNewOutputSurface() override;
155 void DidInitializeOutputSurface() override;
156 void DidFailToInitializeOutputSurface() override;
157 void WillCommit() override;
158 void DidCommit() override;
159 void DidCommitAndDrawFrame() override;
160 void DidCompleteSwapBuffers() override;
161 void DidCompletePageScaleAnimation() override;
162 void RateLimitSharedMainThreadContext() override;
163 void RecordFrameTimingEvents(
164 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events,
165 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events)
166 override;
168 // cc::LayerTreeHostSingleThreadClient implementation.
169 void ScheduleAnimation() override;
170 void DidPostSwapBuffers() override;
171 void DidAbortSwapBuffers() override;
173 enum {
174 OUTPUT_SURFACE_RETRIES_BEFORE_FALLBACK = 4,
175 MAX_OUTPUT_SURFACE_RETRIES = 5,
178 protected:
179 RenderWidgetCompositor(RenderWidget* widget,
180 CompositorDependencies* compositor_deps);
182 void Initialize();
183 cc::LayerTreeHost* layer_tree_host() { return layer_tree_host_.get(); }
185 private:
186 void LayoutAndUpdateLayers();
187 void InvokeLayoutAndPaintCallback();
188 bool CompositeIsSynchronous() const;
189 void SynchronouslyComposite();
191 int num_failed_recreate_attempts_;
192 RenderWidget* widget_;
193 CompositorDependencies* compositor_deps_;
194 scoped_ptr<cc::LayerTreeHost> layer_tree_host_;
196 blink::WebLayoutAndPaintAsyncCallback* layout_and_paint_async_callback_;
197 scoped_ptr<cc::CopyOutputRequest> temporary_copy_output_request_;
199 base::WeakPtrFactory<RenderWidgetCompositor> weak_factory_;
202 } // namespace content
204 #endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_