Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / content / renderer / gpu / render_widget_compositor.h
blob6bd0d0c1dd43350ed2d7e2ea24eae36690de883e
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::WebFloatPoint adjustEventPointForPinchZoom(
94 const blink::WebFloatPoint& point) const;
95 virtual void setDeviceScaleFactor(float device_scale);
96 virtual float deviceScaleFactor() const;
97 virtual void setBackgroundColor(blink::WebColor color);
98 virtual void setHasTransparentBackground(bool transparent);
99 virtual void setVisible(bool visible);
100 virtual void setPageScaleFactorAndLimits(float page_scale_factor,
101 float minimum,
102 float maximum);
103 virtual void startPageScaleAnimation(const blink::WebPoint& destination,
104 bool use_anchor,
105 float new_page_scale,
106 double duration_sec);
107 virtual void heuristicsForGpuRasterizationUpdated(bool matches_heuristics);
108 virtual void setNeedsAnimate();
109 virtual void setNeedsBeginFrame();
110 virtual void setNeedsCompositorUpdate();
111 virtual void didStopFlinging();
112 virtual void layoutAndPaintAsync(
113 blink::WebLayoutAndPaintAsyncCallback* callback);
114 virtual void compositeAndReadbackAsync(
115 blink::WebCompositeAndReadbackAsyncCallback* callback);
116 virtual void setDeferCommits(bool defer_commits);
117 virtual void registerForAnimations(blink::WebLayer* layer);
118 virtual void registerViewportLayers(
119 const blink::WebLayer* overscrollElasticityLayer,
120 const blink::WebLayer* pageScaleLayer,
121 const blink::WebLayer* innerViewportScrollLayer,
122 const blink::WebLayer* outerViewportScrollLayer) override;
123 virtual void clearViewportLayers() override;
124 virtual void registerSelection(const blink::WebSelection& selection) override;
125 virtual void clearSelection() override;
126 virtual int layerTreeId() const;
127 virtual void setShowFPSCounter(bool show);
128 virtual void setShowPaintRects(bool show);
129 virtual void setShowDebugBorders(bool show);
130 virtual void setShowScrollBottleneckRects(bool show);
132 virtual void updateTopControlsState(blink::WebTopControlsState constraints,
133 blink::WebTopControlsState current,
134 bool animate);
135 virtual void setTopControlsHeight(float height, bool shrink);
136 virtual void setTopControlsShownRatio(float);
137 virtual void setHidePinchScrollbarsNearMinScale(bool) override;
139 // cc::LayerTreeHostClient implementation.
140 void WillBeginMainFrame() override;
141 void DidBeginMainFrame() override;
142 void BeginMainFrame(const cc::BeginFrameArgs& args) override;
143 void BeginMainFrameNotExpectedSoon() override;
144 void Layout() override;
145 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
146 const gfx::Vector2dF& outer_delta,
147 const gfx::Vector2dF& elastic_overscroll_delta,
148 float page_scale,
149 float top_controls_delta) override;
150 void RequestNewOutputSurface() override;
151 void DidInitializeOutputSurface() override;
152 void DidFailToInitializeOutputSurface() override;
153 void WillCommit() override;
154 void DidCommit() override;
155 void DidCommitAndDrawFrame() override;
156 void DidCompleteSwapBuffers() override;
157 void DidCompletePageScaleAnimation() override;
158 void RateLimitSharedMainThreadContext() override;
159 void RecordFrameTimingEvents(
160 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events,
161 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events)
162 override;
164 // cc::LayerTreeHostSingleThreadClient implementation.
165 void ScheduleAnimation() override;
166 void DidPostSwapBuffers() override;
167 void DidAbortSwapBuffers() override;
169 enum {
170 OUTPUT_SURFACE_RETRIES_BEFORE_FALLBACK = 4,
171 MAX_OUTPUT_SURFACE_RETRIES = 5,
174 protected:
175 RenderWidgetCompositor(RenderWidget* widget,
176 CompositorDependencies* compositor_deps);
178 void Initialize();
179 cc::LayerTreeHost* layer_tree_host() { return layer_tree_host_.get(); }
181 private:
182 void LayoutAndUpdateLayers();
183 void InvokeLayoutAndPaintCallback();
184 bool CompositeIsSynchronous() const;
185 void SynchronouslyComposite();
187 int num_failed_recreate_attempts_;
188 RenderWidget* widget_;
189 CompositorDependencies* compositor_deps_;
190 scoped_ptr<cc::LayerTreeHost> layer_tree_host_;
192 blink::WebLayoutAndPaintAsyncCallback* layout_and_paint_async_callback_;
193 scoped_ptr<cc::CopyOutputRequest> temporary_copy_output_request_;
195 base::WeakPtrFactory<RenderWidgetCompositor> weak_factory_;
198 } // namespace content
200 #endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_