Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Side by Side Diff: blimp/client/compositor/blimp_compositor.h

Issue 1636163002: Restructure contents of blimp/client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « blimp/client/blimp_startup.cc ('k') | blimp/client/compositor/blimp_compositor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_
6 #define BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_
7
8 #include <vector>
9
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "blimp/client/blimp_client_export.h"
14 #include "blimp/client/input/blimp_input_manager.h"
15 #include "blimp/client/session/render_widget_feature.h"
16 #include "cc/layers/layer_settings.h"
17 #include "cc/trees/layer_tree_host_client.h"
18 #include "cc/trees/layer_tree_settings.h"
19 #include "cc/trees/remote_proto_channel.h"
20 #include "ui/gfx/geometry/size.h"
21 #include "ui/gfx/native_widget_types.h"
22
23 namespace base {
24 class SingleThreadTaskRunner;
25 class Thread;
26 }
27
28 namespace cc {
29 class LayerTreeHost;
30 }
31
32 namespace blimp {
33
34 class BlimpMessage;
35
36 namespace client {
37
38 // BlimpCompositor provides the basic framework and setup to host a
39 // LayerTreeHost. The class that owns the LayerTreeHost is usually called the
40 // compositor, but the LayerTreeHost does the compositing work. The rendering
41 // surface this compositor draws to is defined by the gfx::AcceleratedWidget set
42 // by SetAcceleratedWidget(). This class should only be accessed from the main
43 // thread. Any interaction with the compositing thread should happen through
44 // the LayerTreeHost or RemoteChannelImpl.
45 class BLIMP_CLIENT_EXPORT BlimpCompositor
46 : public cc::LayerTreeHostClient,
47 public cc::RemoteProtoChannel,
48 public RenderWidgetFeature::RenderWidgetFeatureDelegate,
49 public BlimpInputManagerClient {
50 public:
51 // |dp_to_px| is the scale factor required to move from dp (device pixels) to
52 // px. See https://developer.android.com/guide/practices/screens_support.html
53 // for more details.
54 BlimpCompositor(float dp_to_px, RenderWidgetFeature* render_widget_feature);
55
56 ~BlimpCompositor() override;
57
58 // Default layer settings for all Blimp layer instances.
59 static cc::LayerSettings LayerSettings();
60
61 // Sets whether or not this compositor actually draws to the output surface.
62 // Setting this to false will make the compositor drop all of its resources
63 // and the output surface. Setting it to true again will rebuild the output
64 // surface from the gfx::AcceleratedWidget (see SetAcceleratedWidget).
65 void SetVisible(bool visible);
66
67 // Sets the size of the viewport on the compositor.
68 // TODO(dtrainor): Should this be set from the engine all the time?
69 void SetSize(const gfx::Size& size);
70
71 // Lets this compositor know that it can draw to |widget|. This means that,
72 // if this compositor is visible, it will build an output surface and GL
73 // context around |widget| and will draw to it. ReleaseAcceleratedWidget()
74 // *must* be called before SetAcceleratedWidget() is called with the same
75 // gfx::AcceleratedWidget on another compositor.
76 void SetAcceleratedWidget(gfx::AcceleratedWidget widget);
77
78 // Releases the internally stored gfx::AcceleratedWidget and the associated
79 // output surface. This must be called before calling
80 // SetAcceleratedWidget() with the same gfx::AcceleratedWidget on another
81 // compositor.
82 void ReleaseAcceleratedWidget();
83
84 // Forwards the touch event to the |input_manager_|.
85 bool OnTouchEvent(const ui::MotionEvent& motion_event);
86
87 protected:
88 // Populates the cc::LayerTreeSettings used by the cc::LayerTreeHost. Can be
89 // overridden to provide custom settings parameters.
90 virtual void GenerateLayerTreeSettings(cc::LayerTreeSettings* settings);
91
92 private:
93 // LayerTreeHostClient implementation.
94 void WillBeginMainFrame() override;
95 void DidBeginMainFrame() override;
96 void BeginMainFrame(const cc::BeginFrameArgs& args) override;
97 void BeginMainFrameNotExpectedSoon() override;
98 void UpdateLayerTreeHost() override;
99 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
100 const gfx::Vector2dF& outer_delta,
101 const gfx::Vector2dF& elastic_overscroll_delta,
102 float page_scale,
103 float top_controls_delta) override;
104 void RequestNewOutputSurface() override;
105 void DidInitializeOutputSurface() override;
106 void DidFailToInitializeOutputSurface() override;
107 void WillCommit() override;
108 void DidCommit() override;
109 void DidCommitAndDrawFrame() override;
110 void DidCompleteSwapBuffers() override;
111 void DidCompletePageScaleAnimation() override;
112 void RecordFrameTimingEvents(
113 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events,
114 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events)
115 override;
116
117 // RemoteProtoChannel implementation.
118 void SetProtoReceiver(ProtoReceiver* receiver) override;
119 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override;
120
121 // RenderWidgetFeatureDelegate implementation.
122 void OnRenderWidgetInitialized() override;
123 void OnCompositorMessageReceived(
124 scoped_ptr<cc::proto::CompositorMessage> message) override;
125
126 // BlimpInputManagerClient implementation.
127 void SendWebInputEvent(const blink::WebInputEvent& input_event) override;
128
129 // Helper method to build the internal CC compositor instance from |message|.
130 void CreateLayerTreeHost(scoped_ptr<cc::proto::CompositorMessage> message);
131
132 // Creates (if necessary) and returns a TaskRunner for a thread meant to run
133 // compositor rendering.
134 void HandlePendingOutputSurfaceRequest();
135 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner();
136
137 gfx::Size viewport_size_;
138
139 // The scale factor used to convert dp units (device independent pixels) to
140 // pixels.
141 float device_scale_factor_;
142 scoped_ptr<cc::LayerTreeHost> host_;
143 scoped_ptr<cc::LayerTreeSettings> settings_;
144
145 // Lazily created thread that will run the compositor rendering tasks.
146 scoped_ptr<base::Thread> compositor_thread_;
147
148 gfx::AcceleratedWidget window_;
149
150 // Whether or not |host_| should be visible. This is stored in case |host_|
151 // is null when SetVisible() is called or if we don't have a
152 // gfx::AcceleratedWidget to build an output surface from.
153 bool host_should_be_visible_;
154
155 // Whether there is an OutputSurface request pending from the current
156 // |host_|. Becomes |true| if RequestNewOutputSurface is called, and |false|
157 // if |host_| is deleted or we succeed in creating *and* initializing an
158 // OutputSurface (which is essentially the contract with cc).
159 bool output_surface_request_pending_;
160
161 // To be notified of any incoming compositor protos that are specifically sent
162 // to |render_widget_id_|.
163 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_;
164
165 // The bridge to the network layer that does the proto/RenderWidget id work.
166 // BlimpCompositor does not own this and it is expected to outlive this
167 // BlimpCompositor instance.
168 // TODO(dtrainor): Move this to a higher level once we start dealing with
169 // multiple tabs.
170 RenderWidgetFeature* render_widget_feature_;
171
172 // Handles input events for the current render widget. The lifetime of the
173 // input manager is tied to the lifetime of the |host_| which owns the
174 // cc::InputHandler. The input events are forwarded to this input handler by
175 // the manager to be handled by the client compositor for the current render
176 // widget.
177 scoped_ptr<BlimpInputManager> input_manager_;
178
179 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor);
180 };
181
182 } // namespace client
183 } // namespace blimp
184
185 #endif // BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_
OLDNEW
« no previous file with comments | « blimp/client/blimp_startup.cc ('k') | blimp/client/compositor/blimp_compositor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698