1 // Copyright 2014 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 COMPONENTS_HTML_VIEWER_WEB_LAYER_TREE_VIEW_IMPL_H_
6 #define COMPONENTS_HTML_VIEWER_WEB_LAYER_TREE_VIEW_IMPL_H_
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/single_thread_task_runner.h"
13 #include "cc/trees/layer_tree_host_client.h"
14 #include "components/view_manager/public/interfaces/gpu.mojom.h"
15 #include "components/view_manager/public/interfaces/surfaces.mojom.h"
16 #include "mojo/cc/output_surface_mojo.h"
17 #include "third_party/WebKit/public/platform/WebLayerTreeView.h"
20 class SingleThreadTaskRunner
;
29 class TaskGraphRunner
;
33 class GpuMemoryBufferManager
;
40 namespace html_viewer
{
42 class WebLayerTreeViewImpl
: public blink::WebLayerTreeView
,
43 public cc::LayerTreeHostClient
,
44 public mojo::OutputSurfaceMojoClient
{
47 scoped_refptr
<base::SingleThreadTaskRunner
> compositor_task_runner
,
48 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager
,
49 cc::TaskGraphRunner
* task_graph_runner
,
50 mojo::SurfacePtr surface
,
51 mojo::GpuPtr gpu_service
);
52 ~WebLayerTreeViewImpl() override
;
54 void set_widget(blink::WebWidget
* widget
) { widget_
= widget
; }
55 void set_view(mojo::View
* view
) { view_
= view
; }
57 // cc::LayerTreeHostClient implementation.
58 void WillBeginMainFrame() override
;
59 void DidBeginMainFrame() override
;
60 void BeginMainFrame(const cc::BeginFrameArgs
& args
) override
;
61 void BeginMainFrameNotExpectedSoon() override
;
62 void Layout() override
;
63 void ApplyViewportDeltas(const gfx::Vector2dF
& inner_delta
,
64 const gfx::Vector2dF
& outer_delta
,
65 const gfx::Vector2dF
& elastic_overscroll_delta
,
67 float top_controls_delta
) override
;
68 void RequestNewOutputSurface() override
;
69 void DidFailToInitializeOutputSurface() override
;
70 void DidInitializeOutputSurface() override
;
71 void WillCommit() override
;
72 void DidCommit() override
;
73 void DidCommitAndDrawFrame() override
;
74 void DidCompleteSwapBuffers() override
;
75 void DidCompletePageScaleAnimation() override
{}
76 void RateLimitSharedMainThreadContext() override
{}
77 void RecordFrameTimingEvents(
78 scoped_ptr
<cc::FrameTimingTracker::CompositeTimingSet
> composite_events
,
79 scoped_ptr
<cc::FrameTimingTracker::MainFrameTimingSet
> main_frame_events
)
82 // blink::WebLayerTreeView implementation.
83 virtual void setRootLayer(const blink::WebLayer
& layer
);
84 virtual void clearRootLayer();
85 virtual void setViewportSize(const blink::WebSize
& device_viewport_size
);
86 virtual blink::WebSize
deviceViewportSize() const;
87 virtual void setDeviceScaleFactor(float);
88 virtual float deviceScaleFactor() const;
89 virtual void setBackgroundColor(blink::WebColor color
);
90 virtual void setHasTransparentBackground(bool has_transparent_background
);
91 virtual void setVisible(bool visible
);
92 virtual void setPageScaleFactorAndLimits(float page_scale_factor
,
95 virtual void startPageScaleAnimation(const blink::WebPoint
& destination
,
99 virtual void heuristicsForGpuRasterizationUpdated(bool matches_heuristic
) {}
100 virtual void setNeedsAnimate();
101 virtual bool commitRequested() const;
102 virtual void didStopFlinging() {}
103 virtual void compositeAndReadbackAsync(
104 blink::WebCompositeAndReadbackAsyncCallback
* callback
) {}
105 virtual void finishAllRendering();
106 virtual void setDeferCommits(bool defer_commits
) {}
107 virtual void registerForAnimations(blink::WebLayer
* layer
);
108 virtual void registerViewportLayers(
109 const blink::WebLayer
* overscrollElasticityLayer
,
110 const blink::WebLayer
* pageScaleLayerLayer
,
111 const blink::WebLayer
* innerViewportScrollLayer
,
112 const blink::WebLayer
* outerViewportScrollLayer
);
113 virtual void clearViewportLayers();
114 virtual void registerSelection(const blink::WebSelection
& selection
) {}
115 virtual void clearSelection() {}
116 virtual void setShowFPSCounter(bool) {}
117 virtual void setShowPaintRects(bool) {}
118 virtual void setShowDebugBorders(bool) {}
119 virtual void setContinuousPaintingEnabled(bool) {}
120 virtual void setShowScrollBottleneckRects(bool) {}
122 // OutputSurfaceMojoClient implementation.
123 void DidCreateSurface(cc::SurfaceId id
) override
;
126 void DidCreateSurfaceOnMainThread(cc::SurfaceId id
);
128 // widget_ and view_ will outlive us.
129 blink::WebWidget
* widget_
;
131 scoped_ptr
<cc::LayerTreeHost
> layer_tree_host_
;
132 scoped_ptr
<cc::OutputSurface
> output_surface_
;
133 scoped_refptr
<base::SingleThreadTaskRunner
>
134 main_thread_compositor_task_runner_
;
135 base::WeakPtr
<WebLayerTreeViewImpl
> main_thread_bound_weak_ptr_
;
137 base::WeakPtrFactory
<WebLayerTreeViewImpl
> weak_factory_
;
138 DISALLOW_COPY_AND_ASSIGN(WebLayerTreeViewImpl
);
141 } // namespace html_viewer
143 #endif // COMPONENTS_HTML_VIEWER_WEB_LAYER_TREE_VIEW_IMPL_H_