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/public/interfaces/gpu/gpu.mojom.h"
16 #include "mojo/services/public/interfaces/surfaces/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
,
55 float top_controls_delta
) override
;
56 void ApplyViewportDeltas(const gfx::Vector2d
& scroll_delta
,
58 float top_controls_delta
) override
;
59 void RequestNewOutputSurface(bool fallback
) override
;
60 void DidInitializeOutputSurface() override
;
61 void WillCommit() override
;
62 void DidCommit() override
;
63 void DidCommitAndDrawFrame() override
;
64 void DidCompleteSwapBuffers() override
;
65 void RateLimitSharedMainThreadContext() override
{}
67 // blink::WebLayerTreeView implementation.
68 virtual void setSurfaceReady() override
;
69 virtual void setRootLayer(const blink::WebLayer
& layer
) override
;
70 virtual void clearRootLayer() override
;
71 virtual void setViewportSize(
72 const blink::WebSize
& device_viewport_size
) override
;
73 virtual blink::WebSize
deviceViewportSize() const override
;
74 virtual void setDeviceScaleFactor(float) override
;
75 virtual float deviceScaleFactor() const override
;
76 virtual void setBackgroundColor(blink::WebColor color
) override
;
77 virtual void setHasTransparentBackground(
78 bool has_transparent_background
) override
;
79 virtual void setOverhangBitmap(const SkBitmap
& bitmap
) override
;
80 virtual void setVisible(bool visible
) override
;
81 virtual void setPageScaleFactorAndLimits(float page_scale_factor
,
83 float maximum
) override
;
84 virtual void startPageScaleAnimation(const blink::WebPoint
& destination
,
87 double duration_sec
) override
;
88 virtual void heuristicsForGpuRasterizationUpdated(bool matches_heuristic
) {}
89 virtual void setTopControlsContentOffset(float offset
) {}
90 virtual void setNeedsAnimate() override
;
91 virtual bool commitRequested() const override
;
92 virtual void didStopFlinging() {}
93 virtual void compositeAndReadbackAsync(
94 blink::WebCompositeAndReadbackAsyncCallback
* callback
) {}
95 virtual void finishAllRendering() override
;
96 virtual void setDeferCommits(bool defer_commits
) {}
97 virtual void registerForAnimations(blink::WebLayer
* layer
) override
;
98 virtual void registerViewportLayers(
99 const blink::WebLayer
* page_scale_layer
,
100 const blink::WebLayer
* inner_viewport_scroll_layer
,
101 const blink::WebLayer
* outer_viewport_scroll_layer
) override
;
102 virtual void clearViewportLayers() override
;
103 virtual void registerSelection(const blink::WebSelectionBound
& start
,
104 const blink::WebSelectionBound
& end
) {}
105 virtual void clearSelection() {}
106 virtual void setShowFPSCounter(bool) {}
107 virtual void setShowPaintRects(bool) {}
108 virtual void setShowDebugBorders(bool) {}
109 virtual void setContinuousPaintingEnabled(bool) {}
110 virtual void setShowScrollBottleneckRects(bool) {}
112 // OutputSurfaceMojoClient implementation.
113 void DidCreateSurface(cc::SurfaceId id
) override
;
116 void OnSurfaceConnectionCreated(SurfacePtr surface
, uint32_t id_namespace
);
117 void DidCreateSurfaceOnMainThread(cc::SurfaceId id
);
119 // widget_ and view_ will outlive us.
120 blink::WebWidget
* widget_
;
122 scoped_ptr
<cc::LayerTreeHost
> layer_tree_host_
;
123 SurfacesServicePtr surfaces_service_
;
124 scoped_ptr
<cc::OutputSurface
> output_surface_
;
126 scoped_refptr
<base::SingleThreadTaskRunner
>
127 main_thread_compositor_task_runner_
;
128 base::WeakPtr
<WebLayerTreeViewImpl
> main_thread_bound_weak_ptr_
;
130 base::WeakPtrFactory
<WebLayerTreeViewImpl
> weak_factory_
;
131 DISALLOW_COPY_AND_ASSIGN(WebLayerTreeViewImpl
);
136 #endif // MOJO_SERVICES_HTML_VIEWER_WEBLAYERTREEVIEW_IMPL_H_