base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / mojo / services / html_viewer / weblayertreeview_impl.h
blob3212643c8366082ff44852d8a459cc59208838df
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;
35 namespace html_viewer {
37 class WebLayerTreeViewImpl : public blink::WebLayerTreeView,
38 public cc::LayerTreeHostClient,
39 public mojo::OutputSurfaceMojoClient {
40 public:
41 WebLayerTreeViewImpl(
42 scoped_refptr<base::MessageLoopProxy> compositor_message_loop_proxy,
43 mojo::SurfacesServicePtr surfaces_service,
44 mojo::GpuPtr gpu_service);
45 virtual ~WebLayerTreeViewImpl();
47 void set_widget(blink::WebWidget* widget) { widget_ = widget; }
48 void set_view(mojo::View* view) { view_ = view; }
50 // cc::LayerTreeHostClient implementation.
51 void WillBeginMainFrame(int frame_id) override;
52 void DidBeginMainFrame() override;
53 void BeginMainFrame(const cc::BeginFrameArgs& args) override;
54 void Layout() override;
55 void ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
56 const gfx::Vector2d& outer_delta,
57 const gfx::Vector2dF& elastic_overscroll_delta,
58 float page_scale,
59 float top_controls_delta) override;
60 void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
61 float page_scale,
62 float top_controls_delta) override;
63 void RequestNewOutputSurface() override;
64 void DidFailToInitializeOutputSurface() override;
65 void DidInitializeOutputSurface() override;
66 void WillCommit() override;
67 void DidCommit() override;
68 void DidCommitAndDrawFrame() override;
69 void DidCompleteSwapBuffers() override;
70 void RateLimitSharedMainThreadContext() override {}
72 // blink::WebLayerTreeView implementation.
73 virtual void setRootLayer(const blink::WebLayer& layer);
74 virtual void clearRootLayer();
75 virtual void setViewportSize(const blink::WebSize& device_viewport_size);
76 virtual blink::WebSize deviceViewportSize() const;
77 virtual void setDeviceScaleFactor(float);
78 virtual float deviceScaleFactor() const;
79 virtual void setBackgroundColor(blink::WebColor color);
80 virtual void setHasTransparentBackground(bool has_transparent_background);
81 virtual void setOverhangBitmap(const SkBitmap& bitmap);
82 virtual void setVisible(bool visible);
83 virtual void setPageScaleFactorAndLimits(float page_scale_factor,
84 float minimum,
85 float maximum);
86 virtual void startPageScaleAnimation(const blink::WebPoint& destination,
87 bool use_anchor,
88 float new_page_scale,
89 double duration_sec);
90 virtual void heuristicsForGpuRasterizationUpdated(bool matches_heuristic) {}
91 virtual void setTopControlsContentOffset(float offset) {}
92 virtual void setNeedsAnimate();
93 virtual bool commitRequested() const;
94 virtual void didStopFlinging() {}
95 virtual void compositeAndReadbackAsync(
96 blink::WebCompositeAndReadbackAsyncCallback* callback) {}
97 virtual void finishAllRendering();
98 virtual void setDeferCommits(bool defer_commits) {}
99 virtual void registerForAnimations(blink::WebLayer* layer);
100 virtual void registerViewportLayers(
101 const blink::WebLayer* overscrollElasticityLayer,
102 const blink::WebLayer* pageScaleLayerLayer,
103 const blink::WebLayer* innerViewportScrollLayer,
104 const blink::WebLayer* outerViewportScrollLayer);
105 virtual void clearViewportLayers();
106 virtual void registerSelection(const blink::WebSelectionBound& start,
107 const blink::WebSelectionBound& end) {}
108 virtual void clearSelection() {}
109 virtual void setShowFPSCounter(bool) {}
110 virtual void setShowPaintRects(bool) {}
111 virtual void setShowDebugBorders(bool) {}
112 virtual void setContinuousPaintingEnabled(bool) {}
113 virtual void setShowScrollBottleneckRects(bool) {}
115 // OutputSurfaceMojoClient implementation.
116 void DidCreateSurface(cc::SurfaceId id) override;
118 private:
119 void OnSurfaceConnectionCreated(mojo::SurfacePtr surface,
120 uint32_t id_namespace);
121 void DidCreateSurfaceOnMainThread(cc::SurfaceId id);
123 // widget_ and view_ will outlive us.
124 blink::WebWidget* widget_;
125 mojo::View* view_;
126 scoped_ptr<cc::LayerTreeHost> layer_tree_host_;
127 mojo::SurfacesServicePtr surfaces_service_;
128 scoped_ptr<cc::OutputSurface> output_surface_;
129 mojo::GpuPtr gpu_service_;
130 scoped_refptr<base::SingleThreadTaskRunner>
131 main_thread_compositor_task_runner_;
132 base::WeakPtr<WebLayerTreeViewImpl> main_thread_bound_weak_ptr_;
134 base::WeakPtrFactory<WebLayerTreeViewImpl> weak_factory_;
135 DISALLOW_COPY_AND_ASSIGN(WebLayerTreeViewImpl);
138 } // namespace html_viewer
140 #endif // MOJO_SERVICES_HTML_VIEWER_WEBLAYERTREEVIEW_IMPL_H_