Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: cc/trees/layer_tree_host.h

Issue 1057283003: Remove parts of //cc we aren't using (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/latency_info_swap_promise_monitor.cc ('k') | cc/trees/layer_tree_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 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.
4
5 #ifndef CC_TREES_LAYER_TREE_HOST_H_
6 #define CC_TREES_LAYER_TREE_HOST_H_
7
8 #include <limits>
9 #include <set>
10 #include <string>
11 #include <vector>
12
13 #include "base/basictypes.h"
14 #include "base/cancelable_callback.h"
15 #include "base/containers/hash_tables.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/weak_ptr.h"
19 #include "base/time/time.h"
20 #include "base/timer/timer.h"
21 #include "cc/animation/animation_events.h"
22 #include "cc/base/cc_export.h"
23 #include "cc/base/scoped_ptr_vector.h"
24 #include "cc/debug/micro_benchmark.h"
25 #include "cc/debug/micro_benchmark_controller.h"
26 #include "cc/input/input_handler.h"
27 #include "cc/input/layer_selection_bound.h"
28 #include "cc/input/scrollbar.h"
29 #include "cc/input/top_controls_state.h"
30 #include "cc/layers/layer_lists.h"
31 #include "cc/output/output_surface.h"
32 #include "cc/output/renderer_capabilities.h"
33 #include "cc/output/swap_promise.h"
34 #include "cc/resources/resource_format.h"
35 #include "cc/resources/scoped_ui_resource.h"
36 #include "cc/surfaces/surface_sequence.h"
37 #include "cc/trees/layer_tree_host_client.h"
38 #include "cc/trees/layer_tree_host_common.h"
39 #include "cc/trees/layer_tree_settings.h"
40 #include "cc/trees/proxy.h"
41 #include "cc/trees/swap_promise_monitor.h"
42 #include "third_party/skia/include/core/SkColor.h"
43 #include "ui/gfx/geometry/rect.h"
44
45 namespace gpu {
46 class GpuMemoryBufferManager;
47 }
48
49 namespace cc {
50 class AnimationRegistrar;
51 class BeginFrameSource;
52 class HeadsUpDisplayLayer;
53 class Layer;
54 class LayerTreeHostImpl;
55 class LayerTreeHostImplClient;
56 class LayerTreeHostSingleThreadClient;
57 class PrioritizedResource;
58 class PrioritizedResourceManager;
59 class Region;
60 class RenderingStatsInstrumentation;
61 class ResourceProvider;
62 class ResourceUpdateQueue;
63 class SharedBitmapManager;
64 class TaskGraphRunner;
65 class TopControlsManager;
66 class UIResourceRequest;
67 struct PendingPageScaleAnimation;
68 struct RenderingStats;
69 struct ScrollAndScaleSet;
70 enum class GpuRasterizationStatus;
71
72 class CC_EXPORT LayerTreeHost {
73 public:
74 // The SharedBitmapManager will be used on the compositor thread.
75 static scoped_ptr<LayerTreeHost> CreateThreaded(
76 LayerTreeHostClient* client,
77 SharedBitmapManager* shared_bitmap_manager,
78 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
79 TaskGraphRunner* task_graph_runner,
80 const LayerTreeSettings& settings,
81 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
82 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
83 scoped_ptr<BeginFrameSource> external_begin_frame_source);
84
85 static scoped_ptr<LayerTreeHost> CreateSingleThreaded(
86 LayerTreeHostClient* client,
87 LayerTreeHostSingleThreadClient* single_thread_client,
88 SharedBitmapManager* shared_bitmap_manager,
89 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
90 TaskGraphRunner* task_graph_runner,
91 const LayerTreeSettings& settings,
92 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
93 scoped_ptr<BeginFrameSource> external_begin_frame_source);
94 virtual ~LayerTreeHost();
95
96 void SetLayerTreeHostClientReady();
97
98 // LayerTreeHost interface to Proxy.
99 void WillBeginMainFrame();
100 void DidBeginMainFrame();
101 void BeginMainFrame(const BeginFrameArgs& args);
102 void BeginMainFrameNotExpectedSoon();
103 void AnimateLayers(base::TimeTicks monotonic_frame_begin_time);
104 void DidStopFlinging();
105 void Layout();
106 void BeginCommitOnImplThread(LayerTreeHostImpl* host_impl);
107 void FinishCommitOnImplThread(LayerTreeHostImpl* host_impl);
108 void WillCommit();
109 void CommitComplete();
110 void SetOutputSurface(scoped_ptr<OutputSurface> output_surface);
111 void RequestNewOutputSurface();
112 void DidInitializeOutputSurface();
113 void DidFailToInitializeOutputSurface();
114 virtual scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl(
115 LayerTreeHostImplClient* client);
116 void DidLoseOutputSurface();
117 bool output_surface_lost() const { return output_surface_lost_; }
118 void DidCommitAndDrawFrame() { client_->DidCommitAndDrawFrame(); }
119 void DidCompleteSwapBuffers() { client_->DidCompleteSwapBuffers(); }
120 void DeleteContentsTexturesOnImplThread(ResourceProvider* resource_provider);
121 bool UpdateLayers(ResourceUpdateQueue* queue);
122
123 // Called when the compositor completed page scale animation.
124 void DidCompletePageScaleAnimation();
125
126 LayerTreeHostClient* client() { return client_; }
127 const base::WeakPtr<InputHandler>& GetInputHandler() {
128 return input_handler_weak_ptr_;
129 }
130
131 void NotifyInputThrottledUntilCommit();
132
133 void Composite(base::TimeTicks frame_begin_time);
134
135 void FinishAllRendering();
136
137 void SetDeferCommits(bool defer_commits);
138
139 int source_frame_number() const { return source_frame_number_; }
140
141 void SetNeedsDisplayOnAllLayers();
142
143 void CollectRenderingStats(RenderingStats* stats) const;
144
145 RenderingStatsInstrumentation* rendering_stats_instrumentation() const {
146 return rendering_stats_instrumentation_.get();
147 }
148
149 const RendererCapabilities& GetRendererCapabilities() const;
150
151 void SetNeedsAnimate();
152 virtual void SetNeedsUpdateLayers();
153 virtual void SetNeedsCommit();
154 virtual void SetNeedsFullTreeSync();
155 void SetNeedsRedraw();
156 void SetNeedsRedrawRect(const gfx::Rect& damage_rect);
157 bool CommitRequested() const;
158 bool BeginMainFrameRequested() const;
159
160 void SetNextCommitWaitsForActivation();
161
162 void SetNextCommitForcesRedraw();
163
164 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> events);
165
166 void SetRootLayer(scoped_refptr<Layer> root_layer);
167 Layer* root_layer() { return root_layer_.get(); }
168 const Layer* root_layer() const { return root_layer_.get(); }
169 const Layer* overscroll_elasticity_layer() const {
170 return overscroll_elasticity_layer_.get();
171 }
172 const Layer* page_scale_layer() const { return page_scale_layer_.get(); }
173 void RegisterViewportLayers(scoped_refptr<Layer> overscroll_elasticity_layer,
174 scoped_refptr<Layer> page_scale_layer,
175 scoped_refptr<Layer> inner_viewport_scroll_layer,
176 scoped_refptr<Layer> outer_viewport_scroll_layer);
177 Layer* inner_viewport_scroll_layer() const {
178 return inner_viewport_scroll_layer_.get();
179 }
180 Layer* outer_viewport_scroll_layer() const {
181 return outer_viewport_scroll_layer_.get();
182 }
183
184 void RegisterSelection(const LayerSelectionBound& start,
185 const LayerSelectionBound& end);
186
187 const LayerTreeSettings& settings() const { return settings_; }
188
189 void SetDebugState(const LayerTreeDebugState& debug_state);
190 const LayerTreeDebugState& debug_state() const { return debug_state_; }
191
192 bool has_gpu_rasterization_trigger() const {
193 return has_gpu_rasterization_trigger_;
194 }
195 void SetHasGpuRasterizationTrigger(bool has_trigger);
196 bool UseGpuRasterization() const;
197 GpuRasterizationStatus GetGpuRasterizationStatus() const;
198
199 void SetViewportSize(const gfx::Size& device_viewport_size);
200 void SetTopControlsHeight(float height, bool shrink);
201 void SetTopControlsShownRatio(float ratio);
202
203 gfx::Size device_viewport_size() const { return device_viewport_size_; }
204
205 void ApplyPageScaleDeltaFromImplSide(float page_scale_delta);
206 void SetPageScaleFactorAndLimits(float page_scale_factor,
207 float min_page_scale_factor,
208 float max_page_scale_factor);
209 float page_scale_factor() const { return page_scale_factor_; }
210 gfx::Vector2dF elastic_overscroll() const { return elastic_overscroll_; }
211
212 SkColor background_color() const { return background_color_; }
213 void set_background_color(SkColor color) { background_color_ = color; }
214
215 void set_has_transparent_background(bool transparent) {
216 has_transparent_background_ = transparent;
217 }
218
219 PrioritizedResourceManager* contents_texture_manager() const {
220 return contents_texture_manager_.get();
221 }
222
223 void SetVisible(bool visible);
224 bool visible() const { return visible_; }
225
226 void SetThrottleFrameProduction(bool throttle);
227
228 void StartPageScaleAnimation(const gfx::Vector2d& target_offset,
229 bool use_anchor,
230 float scale,
231 base::TimeDelta duration);
232
233 void ApplyScrollAndScale(ScrollAndScaleSet* info);
234 void SetImplTransform(const gfx::Transform& transform);
235
236 // Virtual for tests.
237 virtual void StartRateLimiter();
238 virtual void StopRateLimiter();
239
240 void RateLimit();
241
242 bool AlwaysUsePartialTextureUpdates();
243 size_t MaxPartialTextureUpdates() const;
244 bool RequestPartialTextureUpdate();
245
246 void SetDeviceScaleFactor(float device_scale_factor);
247 float device_scale_factor() const { return device_scale_factor_; }
248
249 void UpdateTopControlsState(TopControlsState constraints,
250 TopControlsState current,
251 bool animate);
252
253 HeadsUpDisplayLayer* hud_layer() const { return hud_layer_.get(); }
254
255 Proxy* proxy() const { return proxy_.get(); }
256
257 AnimationRegistrar* animation_registrar() const {
258 return animation_registrar_.get();
259 }
260
261 bool in_paint_layer_contents() const { return in_paint_layer_contents_; }
262
263 // CreateUIResource creates a resource given a bitmap. The bitmap is
264 // generated via an interface function, which is called when initializing the
265 // resource and when the resource has been lost (due to lost context). The
266 // parameter of the interface is a single boolean, which indicates whether the
267 // resource has been lost or not. CreateUIResource returns an Id of the
268 // resource, which is always positive.
269 virtual UIResourceId CreateUIResource(UIResourceClient* client);
270 // Deletes a UI resource. May safely be called more than once.
271 virtual void DeleteUIResource(UIResourceId id);
272 // Put the recreation of all UI resources into the resource queue after they
273 // were evicted on the impl thread.
274 void RecreateUIResources();
275
276 virtual gfx::Size GetUIResourceSize(UIResourceId id) const;
277
278 bool UsingSharedMemoryResources();
279 int id() const { return id_; }
280
281 // Returns the id of the benchmark on success, 0 otherwise.
282 int ScheduleMicroBenchmark(const std::string& benchmark_name,
283 scoped_ptr<base::Value> value,
284 const MicroBenchmark::DoneCallback& callback);
285 // Returns true if the message was successfully delivered and handled.
286 bool SendMessageToMicroBenchmark(int id, scoped_ptr<base::Value> value);
287
288 // When a SwapPromiseMonitor is created on the main thread, it calls
289 // InsertSwapPromiseMonitor() to register itself with LayerTreeHost.
290 // When the monitor is destroyed, it calls RemoveSwapPromiseMonitor()
291 // to unregister itself.
292 void InsertSwapPromiseMonitor(SwapPromiseMonitor* monitor);
293 void RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor);
294
295 // Call this function when you expect there to be a swap buffer.
296 // See swap_promise.h for how to use SwapPromise.
297 void QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise);
298
299 void BreakSwapPromises(SwapPromise::DidNotSwapReason reason);
300
301 size_t num_queued_swap_promises() const { return swap_promise_list_.size(); }
302
303 void set_surface_id_namespace(uint32_t id_namespace);
304 SurfaceSequence CreateSurfaceSequence();
305
306 void SetChildrenNeedBeginFrames(bool children_need_begin_frames) const;
307 void SendBeginFramesToChildren(const BeginFrameArgs& args) const;
308
309 protected:
310 LayerTreeHost(LayerTreeHostClient* client,
311 SharedBitmapManager* shared_bitmap_manager,
312 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
313 TaskGraphRunner* task_graph_runner,
314 const LayerTreeSettings& settings);
315 void InitializeThreaded(
316 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
317 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
318 scoped_ptr<BeginFrameSource> external_begin_frame_source);
319 void InitializeSingleThreaded(
320 LayerTreeHostSingleThreadClient* single_thread_client,
321 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
322 scoped_ptr<BeginFrameSource> external_begin_frame_source);
323 void InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing);
324 void SetOutputSurfaceLostForTesting(bool is_lost) {
325 output_surface_lost_ = is_lost;
326 }
327
328 MicroBenchmarkController micro_benchmark_controller_;
329
330 private:
331 void InitializeProxy(scoped_ptr<Proxy> proxy);
332
333 void PaintLayerContents(
334 const RenderSurfaceLayerList& render_surface_layer_list,
335 ResourceUpdateQueue* queue,
336 bool* did_paint_content,
337 bool* need_more_updates);
338 void PaintMasksForRenderSurface(Layer* render_surface_layer,
339 ResourceUpdateQueue* queue,
340 bool* did_paint_content,
341 bool* need_more_updates);
342 bool UpdateLayers(Layer* root_layer, ResourceUpdateQueue* queue);
343 void UpdateHudLayer();
344 void TriggerPrepaint();
345
346 void ReduceMemoryUsage();
347
348 void PrioritizeTextures(
349 const RenderSurfaceLayerList& render_surface_layer_list);
350 void SetPrioritiesForSurfaces(size_t surface_memory_bytes);
351 void SetPrioritiesForLayers(const RenderSurfaceLayerList& update_list);
352 size_t CalculateMemoryForRenderSurfaces(
353 const RenderSurfaceLayerList& update_list);
354
355 bool AnimateLayersRecursive(Layer* current, base::TimeTicks time);
356
357 struct UIResourceClientData {
358 UIResourceClient* client;
359 gfx::Size size;
360 };
361
362 typedef base::hash_map<UIResourceId, UIResourceClientData>
363 UIResourceClientMap;
364 UIResourceClientMap ui_resource_client_map_;
365 int next_ui_resource_id_;
366
367 typedef std::vector<UIResourceRequest> UIResourceRequestQueue;
368 UIResourceRequestQueue ui_resource_request_queue_;
369
370 void RecordGpuRasterizationHistogram();
371 void CalculateLCDTextMetricsCallback(Layer* layer);
372
373 void NotifySwapPromiseMonitorsOfSetNeedsCommit();
374
375 bool inside_begin_main_frame_;
376 bool needs_full_tree_sync_;
377
378 base::CancelableClosure prepaint_callback_;
379
380 LayerTreeHostClient* client_;
381 scoped_ptr<Proxy> proxy_;
382
383 int source_frame_number_;
384 scoped_ptr<RenderingStatsInstrumentation> rendering_stats_instrumentation_;
385
386 bool output_surface_lost_;
387
388 scoped_refptr<Layer> root_layer_;
389 scoped_refptr<HeadsUpDisplayLayer> hud_layer_;
390
391 scoped_ptr<PrioritizedResourceManager> contents_texture_manager_;
392 scoped_ptr<PrioritizedResource> surface_memory_placeholder_;
393
394 base::WeakPtr<InputHandler> input_handler_weak_ptr_;
395 base::WeakPtr<TopControlsManager> top_controls_manager_weak_ptr_;
396
397 const LayerTreeSettings settings_;
398 LayerTreeDebugState debug_state_;
399
400 gfx::Size device_viewport_size_;
401 bool top_controls_shrink_blink_size_;
402 float top_controls_height_;
403 float top_controls_shown_ratio_;
404 float device_scale_factor_;
405
406 bool visible_;
407
408 base::OneShotTimer<LayerTreeHost> rate_limit_timer_;
409
410 float page_scale_factor_;
411 float min_page_scale_factor_;
412 float max_page_scale_factor_;
413 gfx::Vector2dF elastic_overscroll_;
414 bool has_gpu_rasterization_trigger_;
415 bool content_is_suitable_for_gpu_rasterization_;
416 bool gpu_rasterization_histogram_recorded_;
417
418 SkColor background_color_;
419 bool has_transparent_background_;
420
421 typedef ScopedPtrVector<PrioritizedResource> TextureList;
422 size_t partial_texture_update_requests_;
423
424 scoped_ptr<AnimationRegistrar> animation_registrar_;
425
426 scoped_ptr<PendingPageScaleAnimation> pending_page_scale_animation_;
427
428 // If set, then page scale animation has completed, but the client hasn't been
429 // notified about it yet.
430 bool did_complete_scale_animation_;
431
432 bool in_paint_layer_contents_;
433
434 int id_;
435 bool next_commit_forces_redraw_;
436
437 scoped_refptr<Layer> overscroll_elasticity_layer_;
438 scoped_refptr<Layer> page_scale_layer_;
439 scoped_refptr<Layer> inner_viewport_scroll_layer_;
440 scoped_refptr<Layer> outer_viewport_scroll_layer_;
441
442 LayerSelectionBound selection_start_;
443 LayerSelectionBound selection_end_;
444
445 SharedBitmapManager* shared_bitmap_manager_;
446 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_;
447 TaskGraphRunner* task_graph_runner_;
448
449 ScopedPtrVector<SwapPromise> swap_promise_list_;
450 std::set<SwapPromiseMonitor*> swap_promise_monitor_;
451
452 uint32_t surface_id_namespace_;
453 uint32_t next_surface_sequence_;
454
455 DISALLOW_COPY_AND_ASSIGN(LayerTreeHost);
456 };
457
458 } // namespace cc
459
460 #endif // CC_TREES_LAYER_TREE_HOST_H_
OLDNEW
« no previous file with comments | « cc/trees/latency_info_swap_promise_monitor.cc ('k') | cc/trees/layer_tree_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698