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 MOJO_SERVICES_HTML_VIEWER_WEBLAYERTREEVIEW_IMPL_H_
6 #define MOJO_SERVICES_HTML_VIEWER_WEBLAYERTREEVIEW_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 "mojo/cc/output_surface_mojo.h"
15 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h"
16 #include "mojo/services/surfaces/public/interfaces/surfaces_service.mojom.h"
17 #include "third_party/WebKit/public/platform/WebLayerTreeView.h"
20 class MessageLoopProxy
;
34 class WebLayerTreeViewImpl
: public blink::WebLayerTreeView
,
35 public cc::LayerTreeHostClient
,
36 public OutputSurfaceMojoClient
{
39 scoped_refptr
<base::MessageLoopProxy
> compositor_message_loop_proxy
,
40 SurfacesServicePtr surfaces_service
,
42 virtual ~WebLayerTreeViewImpl();
44 void set_widget(blink::WebWidget
* widget
) { widget_
= widget
; }
45 void set_view(View
* view
) { view_
= view
; }
47 // cc::LayerTreeHostClient implementation.
48 void WillBeginMainFrame(int frame_id
) override
;
49 void DidBeginMainFrame() override
;
50 void BeginMainFrame(const cc::BeginFrameArgs
& args
) override
;
51 void Layout() override
;
52 void ApplyViewportDeltas(const gfx::Vector2d
& inner_delta
,
53 const gfx::Vector2d
& outer_delta
,
54 const gfx::Vector2dF
& elastic_overscroll_delta
,
56 float top_controls_delta
) override
;
57 void ApplyViewportDeltas(const gfx::Vector2d
& scroll_delta
,
59 float top_controls_delta
) override
;
60 void RequestNewOutputSurface() override
;
61 void DidFailToInitializeOutputSurface() override
;
62 void DidInitializeOutputSurface() override
;
63 void WillCommit() override
;
64 void DidCommit() override
;
65 void DidCommitAndDrawFrame() override
;
66 void DidCompleteSwapBuffers() override
;
67 void RateLimitSharedMainThreadContext() override
{}
69 // blink::WebLayerTreeView implementation.
70 virtual void setSurfaceReady();
71 virtual void setRootLayer(const blink::WebLayer
& layer
);
72 virtual void clearRootLayer();
73 virtual void setViewportSize(const blink::WebSize
& device_viewport_size
);
74 virtual blink::WebSize
deviceViewportSize() const;
75 virtual void setDeviceScaleFactor(float);
76 virtual float deviceScaleFactor() const;
77 virtual void setBackgroundColor(blink::WebColor color
);
78 virtual void setHasTransparentBackground(bool has_transparent_background
);
79 virtual void setOverhangBitmap(const SkBitmap
& bitmap
);
80 virtual void setVisible(bool visible
);
81 virtual void setPageScaleFactorAndLimits(float page_scale_factor
,
84 virtual void startPageScaleAnimation(const blink::WebPoint
& destination
,
88 virtual void heuristicsForGpuRasterizationUpdated(bool matches_heuristic
) {}
89 virtual void setTopControlsContentOffset(float offset
) {}
90 virtual void setNeedsAnimate();
91 virtual bool commitRequested() const;
92 virtual void didStopFlinging() {}
93 virtual void compositeAndReadbackAsync(
94 blink::WebCompositeAndReadbackAsyncCallback
* callback
) {}
95 virtual void finishAllRendering();
96 virtual void setDeferCommits(bool defer_commits
) {}
97 virtual void registerForAnimations(blink::WebLayer
* layer
);
98 virtual void registerViewportLayers(
99 const blink::WebLayer
* overscrollElasticityLayer
,
100 const blink::WebLayer
* pageScaleLayerLayer
,
101 const blink::WebLayer
* innerViewportScrollLayer
,
102 const blink::WebLayer
* outerViewportScrollLayer
);
103 virtual void clearViewportLayers();
104 virtual void registerSelection(const blink::WebSelectionBound
& start
,
105 const blink::WebSelectionBound
& end
) {}
106 virtual void clearSelection() {}
107 virtual void setShowFPSCounter(bool) {}
108 virtual void setShowPaintRects(bool) {}
109 virtual void setShowDebugBorders(bool) {}
110 virtual void setContinuousPaintingEnabled(bool) {}
111 virtual void setShowScrollBottleneckRects(bool) {}
113 // OutputSurfaceMojoClient implementation.
114 void DidCreateSurface(cc::SurfaceId id
) override
;
117 void OnSurfaceConnectionCreated(SurfacePtr surface
, uint32_t id_namespace
);
118 void DidCreateSurfaceOnMainThread(cc::SurfaceId id
);
120 // widget_ and view_ will outlive us.
121 blink::WebWidget
* widget_
;
123 scoped_ptr
<cc::LayerTreeHost
> layer_tree_host_
;
124 SurfacesServicePtr surfaces_service_
;
125 scoped_ptr
<cc::OutputSurface
> output_surface_
;
127 scoped_refptr
<base::SingleThreadTaskRunner
>
128 main_thread_compositor_task_runner_
;
129 base::WeakPtr
<WebLayerTreeViewImpl
> main_thread_bound_weak_ptr_
;
131 base::WeakPtrFactory
<WebLayerTreeViewImpl
> weak_factory_
;
132 DISALLOW_COPY_AND_ASSIGN(WebLayerTreeViewImpl
);
137 #endif // MOJO_SERVICES_HTML_VIEWER_WEBLAYERTREEVIEW_IMPL_H_