Remove aura enum from DesktopMediaID to fix desktop mirroring audio (CrOS).
[chromium-blink-merge.git] / content / renderer / gpu / render_widget_compositor.h
blob91522ae5678247ec5a8caad45b80c6b65a17d7f8
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 struct 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 didStopFlinging();
112 virtual void layoutAndPaintAsync(
113 blink::WebLayoutAndPaintAsyncCallback* callback);
114 virtual void compositeAndReadbackAsync(
115 blink::WebCompositeAndReadbackAsyncCallback* callback);
116 virtual void finishAllRendering();
117 virtual void setDeferCommits(bool defer_commits);
118 virtual void registerForAnimations(blink::WebLayer* layer);
119 virtual void registerViewportLayers(
120 const blink::WebLayer* overscrollElasticityLayer,
121 const blink::WebLayer* pageScaleLayer,
122 const blink::WebLayer* innerViewportScrollLayer,
123 const blink::WebLayer* outerViewportScrollLayer) override;
124 virtual void clearViewportLayers() override;
125 virtual void registerSelection(const blink::WebSelection& selection) override;
126 virtual void clearSelection() override;
127 virtual int layerTreeId() const;
128 virtual void setShowFPSCounter(bool show);
129 virtual void setShowPaintRects(bool show);
130 virtual void setShowDebugBorders(bool show);
131 virtual void setContinuousPaintingEnabled(bool enabled);
132 virtual void setShowScrollBottleneckRects(bool show);
134 virtual void updateTopControlsState(blink::WebTopControlsState constraints,
135 blink::WebTopControlsState current,
136 bool animate);
137 virtual void setTopControlsHeight(float height, bool shrink);
138 virtual void setTopControlsShownRatio(float);
140 // cc::LayerTreeHostClient implementation.
141 void WillBeginMainFrame() override;
142 void DidBeginMainFrame() override;
143 void BeginMainFrame(const cc::BeginFrameArgs& args) override;
144 void BeginMainFrameNotExpectedSoon() override;
145 void Layout() override;
146 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
147 const gfx::Vector2dF& outer_delta,
148 const gfx::Vector2dF& elastic_overscroll_delta,
149 float page_scale,
150 float top_controls_delta) override;
151 void RequestNewOutputSurface() override;
152 void DidInitializeOutputSurface() override;
153 void DidFailToInitializeOutputSurface() override;
154 void WillCommit() override;
155 void DidCommit() override;
156 void DidCommitAndDrawFrame() override;
157 void DidCompleteSwapBuffers() override;
158 void DidCompletePageScaleAnimation() override;
159 void RateLimitSharedMainThreadContext() override;
160 void RecordFrameTimingEvents(
161 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events,
162 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events)
163 override;
165 // cc::LayerTreeHostSingleThreadClient implementation.
166 void ScheduleAnimation() override;
167 void DidPostSwapBuffers() override;
168 void DidAbortSwapBuffers() override;
170 enum {
171 OUTPUT_SURFACE_RETRIES_BEFORE_FALLBACK = 4,
172 MAX_OUTPUT_SURFACE_RETRIES = 5,
175 protected:
176 RenderWidgetCompositor(RenderWidget* widget,
177 CompositorDependencies* compositor_deps);
179 void Initialize();
180 cc::LayerTreeHost* layer_tree_host() { return layer_tree_host_.get(); }
182 private:
183 void LayoutAndUpdateLayers();
184 void InvokeLayoutAndPaintCallback();
185 bool CompositeIsSynchronous() const;
186 void SynchronouslyComposite();
188 int num_failed_recreate_attempts_;
189 RenderWidget* widget_;
190 CompositorDependencies* compositor_deps_;
191 scoped_ptr<cc::LayerTreeHost> layer_tree_host_;
193 blink::WebLayoutAndPaintAsyncCallback* layout_and_paint_async_callback_;
194 scoped_ptr<cc::CopyOutputRequest> temporary_copy_output_request_;
196 base::WeakPtrFactory<RenderWidgetCompositor> weak_factory_;
199 } // namespace content
201 #endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_