Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / blimp / client / compositor / blimp_compositor.h
blobffd3905a0864d71540ebe140a9735b7cee533e2f
1 // Copyright 2015 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 BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_
6 #define BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "cc/trees/layer_tree_host_client.h"
12 #include "cc/trees/layer_tree_settings.h"
13 #include "ui/gfx/geometry/size.h"
14 #include "ui/gfx/native_widget_types.h"
16 namespace base {
17 class SingleThreadTaskRunner;
18 class Thread;
21 namespace cc {
22 class LayerTreeHost;
25 namespace blimp {
27 // BlimpCompositor provides the basic framework and setup to host a
28 // LayerTreeHost (compositor). The rendering surface this compositor draws to
29 // is defined by the gfx::AcceleratedWidget returned by
30 // BlimpCompositor::GetWindow().
31 class BlimpCompositor : public cc::LayerTreeHostClient {
32 public:
33 ~BlimpCompositor() override;
35 void SetVisible(bool visible);
36 void SetSize(const gfx::Size& size);
38 // LayerTreeHostClient implementation.
39 void WillBeginMainFrame() override;
40 void DidBeginMainFrame() override;
41 void BeginMainFrame(const cc::BeginFrameArgs& args) override;
42 void BeginMainFrameNotExpectedSoon() override;
43 void Layout() override;
44 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
45 const gfx::Vector2dF& outer_delta,
46 const gfx::Vector2dF& elastic_overscroll_delta,
47 float page_scale,
48 float top_controls_delta) override;
49 void RequestNewOutputSurface() override;
50 void DidInitializeOutputSurface() override;
51 void DidFailToInitializeOutputSurface() override;
52 void WillCommit() override;
53 void DidCommit() override;
54 void DidCommitAndDrawFrame() override;
55 void DidCompleteSwapBuffers() override;
56 void DidCompletePageScaleAnimation() override;
57 void RecordFrameTimingEvents(
58 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events,
59 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events)
60 override;
62 protected:
63 // |dp_to_px| is the scale factor required to move from dp (device pixels) to
64 // px.
65 explicit BlimpCompositor(float dp_to_px);
67 // Returns a widget for use in constructing this compositor's OutputSurface.
68 // Will only ever be called while this compositor is visible.
69 virtual gfx::AcceleratedWidget GetWindow() = 0;
71 // Populates the cc::LayerTreeSettings used by the cc::LayerTreeHost. Can be
72 // overridden to provide custom settings parameters.
73 virtual void GenerateLayerTreeSettings(cc::LayerTreeSettings* settings);
75 private:
76 // Creates (if necessary) and returns a TaskRunner for a thread meant to run
77 // compositor rendering.
78 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner();
80 gfx::Size viewport_size_;
82 // The scale factor used to convert dp units (device independent pixels) to
83 // pixels.
84 float device_scale_factor_;
85 scoped_ptr<cc::LayerTreeHost> host_;
86 scoped_ptr<cc::LayerTreeSettings> settings_;
88 // Lazily created thread that will run the compositor rendering tasks.
89 scoped_ptr<base::Thread> compositor_thread_;
91 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor);
94 } // namespace blimp
96 #endif // BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_