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"
35 class RenderWidgetCompositor
: public blink::WebLayerTreeView
,
36 public cc::LayerTreeHostClient
,
37 public cc::LayerTreeHostSingleThreadClient
{
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
,
44 virtual ~RenderWidgetCompositor();
46 const base::WeakPtr
<cc::InputHandler
>& GetInputHandler();
47 void SetSuppressScheduleComposite(bool suppress
);
48 bool BeginMainFrameRequested() const;
49 void SetNeedsDisplayOnAllLayers();
50 void SetRasterizeOnlyVisibleContent();
51 void UpdateTopControlsState(cc::TopControlsState constraints
,
52 cc::TopControlsState current
,
54 void SetOverdrawBottomHeight(float overdraw_bottom_height
);
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 SetNeedsUpdateLayer()
62 // is called on LayerTreeHost, the original latency info will be turned
63 // into a LatencyInfoSwapPromise.
64 scoped_ptr
<cc::SwapPromiseMonitor
> CreateLatencyInfoSwapPromiseMonitor(
65 ui::LatencyInfo
* latency
);
66 // Calling QueueSwapPromise() to directly queue a SwapPromise into
68 void QueueSwapPromise(scoped_ptr
<cc::SwapPromise
> swap_promise
);
69 int GetLayerTreeId() const;
70 int GetSourceFrameNumber() const;
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
);
80 // WebLayerTreeView implementation.
81 virtual void setSurfaceReady();
82 virtual void setRootLayer(const blink::WebLayer
& layer
);
83 virtual void clearRootLayer();
84 virtual void setViewportSize(
85 const blink::WebSize
& unused_deprecated
,
86 const blink::WebSize
& device_viewport_size
);
87 virtual void setViewportSize(const blink::WebSize
& device_viewport_size
);
88 virtual blink::WebSize
layoutViewportSize() const;
89 virtual blink::WebSize
deviceViewportSize() const;
90 virtual blink::WebFloatPoint
adjustEventPointForPinchZoom(
91 const blink::WebFloatPoint
& point
) const;
92 virtual void setDeviceScaleFactor(float device_scale
);
93 virtual float deviceScaleFactor() const;
94 virtual void setBackgroundColor(blink::WebColor color
);
95 virtual void setHasTransparentBackground(bool transparent
);
96 virtual void setOverhangBitmap(const SkBitmap
& bitmap
);
97 virtual void setVisible(bool visible
);
98 virtual void setPageScaleFactorAndLimits(float page_scale_factor
,
101 virtual void startPageScaleAnimation(const blink::WebPoint
& destination
,
103 float new_page_scale
,
104 double duration_sec
);
105 virtual void heuristicsForGpuRasterizationUpdated(bool matches_heuristics
);
106 virtual void setNeedsAnimate();
107 virtual bool commitRequested() const;
108 virtual void didStopFlinging();
109 virtual void compositeAndReadbackAsync(
110 blink::WebCompositeAndReadbackAsyncCallback
* callback
);
111 virtual void finishAllRendering();
112 virtual void setDeferCommits(bool defer_commits
);
113 virtual void registerForAnimations(blink::WebLayer
* layer
);
114 virtual void registerViewportLayers(
115 const blink::WebLayer
* pageScaleLayer
,
116 const blink::WebLayer
* innerViewportScrollLayer
,
117 const blink::WebLayer
* outerViewportScrollLayer
) OVERRIDE
;
118 virtual void clearViewportLayers() OVERRIDE
;
119 virtual void registerSelection(const blink::WebSelectionBound
& start
,
120 const blink::WebSelectionBound
& end
) OVERRIDE
;
121 virtual void clearSelection() OVERRIDE
;
122 virtual void setShowFPSCounter(bool show
);
123 virtual void setShowPaintRects(bool show
);
124 virtual void setShowDebugBorders(bool show
);
125 virtual void setContinuousPaintingEnabled(bool enabled
);
126 virtual void setShowScrollBottleneckRects(bool show
);
128 // cc::LayerTreeHostClient implementation.
129 virtual void WillBeginMainFrame(int frame_id
) OVERRIDE
;
130 virtual void DidBeginMainFrame() OVERRIDE
;
131 virtual void BeginMainFrame(const cc::BeginFrameArgs
& args
) OVERRIDE
;
132 virtual void Layout() OVERRIDE
;
133 virtual void ApplyScrollAndScale(const gfx::Vector2d
& scroll_delta
,
134 float page_scale
) OVERRIDE
;
135 virtual scoped_ptr
<cc::OutputSurface
> CreateOutputSurface(bool fallback
)
137 virtual void DidInitializeOutputSurface() OVERRIDE
;
138 virtual void WillCommit() OVERRIDE
;
139 virtual void DidCommit() OVERRIDE
;
140 virtual void DidCommitAndDrawFrame() OVERRIDE
;
141 virtual void DidCompleteSwapBuffers() OVERRIDE
;
142 virtual void RateLimitSharedMainThreadContext() OVERRIDE
;
144 // cc::LayerTreeHostSingleThreadClient implementation.
145 virtual void ScheduleComposite() OVERRIDE
;
146 virtual void ScheduleAnimation() OVERRIDE
;
147 virtual void DidPostSwapBuffers() OVERRIDE
;
148 virtual void DidAbortSwapBuffers() OVERRIDE
;
151 RenderWidgetCompositor(RenderWidget
* widget
, bool threaded
);
153 void Initialize(cc::LayerTreeSettings settings
);
156 bool suppress_schedule_composite_
;
157 RenderWidget
* widget_
;
158 scoped_ptr
<cc::LayerTreeHost
> layer_tree_host_
;
161 } // namespace content
163 #endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_H_