Update mojo sdk to rev 59145288bae55b0fce4276b017df6a1117bcf00f
[chromium-blink-merge.git] / mojo / services / html_viewer / weblayertreeview_impl.h
blob0d6cc21c460bedd7cf5ee86c47ec6df83e74eef1
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"
19 namespace base {
20 class MessageLoopProxy;
23 namespace blink {
24 class WebWidget;
27 namespace cc {
28 class LayerTreeHost;
31 namespace mojo {
32 class View;
34 class WebLayerTreeViewImpl : public blink::WebLayerTreeView,
35 public cc::LayerTreeHostClient,
36 public OutputSurfaceMojoClient {
37 public:
38 WebLayerTreeViewImpl(
39 scoped_refptr<base::MessageLoopProxy> compositor_message_loop_proxy,
40 SurfacesServicePtr surfaces_service,
41 GpuPtr gpu_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,
55 float page_scale,
56 float top_controls_delta) override;
57 void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
58 float page_scale,
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,
82 float minimum,
83 float maximum);
84 virtual void startPageScaleAnimation(const blink::WebPoint& destination,
85 bool use_anchor,
86 float new_page_scale,
87 double duration_sec);
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;
116 private:
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_;
122 View* view_;
123 scoped_ptr<cc::LayerTreeHost> layer_tree_host_;
124 SurfacesServicePtr surfaces_service_;
125 scoped_ptr<cc::OutputSurface> output_surface_;
126 GpuPtr gpu_service_;
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);
135 } // namespace mojo
137 #endif // MOJO_SERVICES_HTML_VIEWER_WEBLAYERTREEVIEW_IMPL_H_