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

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

Issue 1450423002: Add glue between the client and engine for Blimp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blimp_ipc2
Patch Set: Made the BlackHoleBlimpMessageProcessor official! Created 5 years, 1 month 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ 5 #ifndef BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_
6 #define BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ 6 #define BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_
7 7
8 #include <vector>
9
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "blimp/client/blimp_client_export.h"
14 #include "blimp/client/render_widget_message_processor.h"
11 #include "cc/trees/layer_tree_host_client.h" 15 #include "cc/trees/layer_tree_host_client.h"
12 #include "cc/trees/layer_tree_settings.h" 16 #include "cc/trees/layer_tree_settings.h"
17 #include "cc/trees/remote_proto_channel.h"
13 #include "ui/gfx/geometry/size.h" 18 #include "ui/gfx/geometry/size.h"
14 #include "ui/gfx/native_widget_types.h" 19 #include "ui/gfx/native_widget_types.h"
15 20
16 namespace base { 21 namespace base {
17 class SingleThreadTaskRunner; 22 class SingleThreadTaskRunner;
18 class Thread; 23 class Thread;
19 } 24 }
20 25
21 namespace cc { 26 namespace cc {
22 class LayerTreeHost; 27 class LayerTreeHost;
23 } 28 }
24 29
25 namespace blimp { 30 namespace blimp {
26 31
32 class BlimpMessage;
33
27 // BlimpCompositor provides the basic framework and setup to host a 34 // BlimpCompositor provides the basic framework and setup to host a
28 // LayerTreeHost (compositor). The rendering surface this compositor draws to 35 // LayerTreeHost (compositor). The rendering surface this compositor draws to
29 // is defined by the gfx::AcceleratedWidget returned by 36 // is defined by the gfx::AcceleratedWidget set by SetAcceleratedWidget().
30 // BlimpCompositor::GetWindow(). 37 class BLIMP_CLIENT_EXPORT BlimpCompositor
31 class BlimpCompositor : public cc::LayerTreeHostClient { 38 : public cc::LayerTreeHostClient,
39 public cc::RemoteProtoChannel,
40 public RenderWidgetMessageProcessor::RenderWidgetMessageDelegate {
41
32 public: 42 public:
33 ~BlimpCompositor() override; 43 ~BlimpCompositor() override;
34 44
45 // Sets whether or not this compositor actually draws to the output surface.
46 // Setting this to false will make the compositor drop all of it's resources
47 // and the output surface. Setting it to true again will rebuild the output
48 // surface from the gfx::AcceleratedWidget (see SetAcceleratedWidget).
35 void SetVisible(bool visible); 49 void SetVisible(bool visible);
Khushal 2015/11/19 19:28:24 We would want to inform the engine of the visibili
David Trainor- moved to gerrit 2015/11/20 17:58:53 Yeah we'll inform the engine via another route. I
Khushal 2015/11/23 17:40:11 Right now the LTH expects you to make it invisible
50
51 // Sets the size of the viewport on the compositor.
52 // TODO(dtrainor): Should this be pulled from the engine all the time?
36 void SetSize(const gfx::Size& size); 53 void SetSize(const gfx::Size& size);
37 54
55 // Lets this compositor know that it can draw to |widget|. This means that,
56 // if this compositor is visible, it will build an output surface and GL
57 // context around |widget| and will draw to it. ReleaseAcceleratedWidget()
58 // *must* be called before SetAcceleratedWidget() is called with the same
59 // gfx::AcceleratedWidget on another compositor.
Khushal 2015/11/19 19:28:24 Is this for when we have multiple tabs? I think w
David Trainor- moved to gerrit 2015/11/20 17:58:53 Yeah that's what we talked about, but since there'
Khushal 2015/11/23 17:40:11 Makes sense.
60 void SetAcceleratedWidget(gfx::AcceleratedWidget widget);
61
62 // Releases the internally stored gfx::AcceleratedWidget and the associated
63 // output surface. This should be called before calling
64 // SetAcceleratedWidget() with the same gfx::AcceleratedWidget on another
65 // compositor.
66 void ReleaseAcceleratedWidget();
67
68 protected:
69 // |dp_to_px| is the scale factor required to move from dp (device pixels) to
70 // px.
71 explicit BlimpCompositor(float dp_to_px);
72
73 // Populates the cc::LayerTreeSettings used by the cc::LayerTreeHost. Can be
74 // overridden to provide custom settings parameters.
75 virtual void GenerateLayerTreeSettings(cc::LayerTreeSettings* settings);
76
77 private:
38 // LayerTreeHostClient implementation. 78 // LayerTreeHostClient implementation.
39 void WillBeginMainFrame() override; 79 void WillBeginMainFrame() override;
40 void DidBeginMainFrame() override; 80 void DidBeginMainFrame() override;
41 void BeginMainFrame(const cc::BeginFrameArgs& args) override; 81 void BeginMainFrame(const cc::BeginFrameArgs& args) override;
42 void BeginMainFrameNotExpectedSoon() override; 82 void BeginMainFrameNotExpectedSoon() override;
43 void UpdateLayerTreeHost() override; 83 void UpdateLayerTreeHost() override;
44 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, 84 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
45 const gfx::Vector2dF& outer_delta, 85 const gfx::Vector2dF& outer_delta,
46 const gfx::Vector2dF& elastic_overscroll_delta, 86 const gfx::Vector2dF& elastic_overscroll_delta,
47 float page_scale, 87 float page_scale,
48 float top_controls_delta) override; 88 float top_controls_delta) override;
49 void RequestNewOutputSurface() override; 89 void RequestNewOutputSurface() override;
50 void DidInitializeOutputSurface() override; 90 void DidInitializeOutputSurface() override;
51 void DidFailToInitializeOutputSurface() override; 91 void DidFailToInitializeOutputSurface() override;
52 void WillCommit() override; 92 void WillCommit() override;
53 void DidCommit() override; 93 void DidCommit() override;
54 void DidCommitAndDrawFrame() override; 94 void DidCommitAndDrawFrame() override;
55 void DidCompleteSwapBuffers() override; 95 void DidCompleteSwapBuffers() override;
56 void DidCompletePageScaleAnimation() override; 96 void DidCompletePageScaleAnimation() override;
57 void RecordFrameTimingEvents( 97 void RecordFrameTimingEvents(
58 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, 98 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events,
59 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) 99 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events)
60 override; 100 override;
61 101
62 protected: 102 // RemoteProtoChannel implementation.
63 // |dp_to_px| is the scale factor required to move from dp (device pixels) to 103 void SetProtoReceiver(ProtoReceiver* receiver) override;
64 // px. 104 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override;
65 explicit BlimpCompositor(float dp_to_px);
66 105
67 // Returns a widget for use in constructing this compositor's OutputSurface. 106 // RenderWidgetMessageDelegate implementation.
68 // Will only ever be called while this compositor is visible. 107 void OnRenderWidgetInitialized() override;
69 virtual gfx::AcceleratedWidget GetWindow() = 0; 108 void OnCompositorMessageReceived(
109 scoped_ptr<cc::proto::CompositorMessage> message) override;
70 110
71 // Populates the cc::LayerTreeSettings used by the cc::LayerTreeHost. Can be 111 // Helper method to build the internal CC compositor instance from |message|.
72 // overridden to provide custom settings parameters. 112 void CreateLayerTreeHost(scoped_ptr<cc::proto::CompositorMessage> message);
73 virtual void GenerateLayerTreeSettings(cc::LayerTreeSettings* settings);
74 113
75 private:
76 // Creates (if necessary) and returns a TaskRunner for a thread meant to run 114 // Creates (if necessary) and returns a TaskRunner for a thread meant to run
77 // compositor rendering. 115 // compositor rendering.
78 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner(); 116 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner();
79 117
80 gfx::Size viewport_size_; 118 gfx::Size viewport_size_;
81 119
82 // The scale factor used to convert dp units (device independent pixels) to 120 // The scale factor used to convert dp units (device independent pixels) to
83 // pixels. 121 // pixels.
84 float device_scale_factor_; 122 float device_scale_factor_;
85 scoped_ptr<cc::LayerTreeHost> host_; 123 scoped_ptr<cc::LayerTreeHost> host_;
86 scoped_ptr<cc::LayerTreeSettings> settings_; 124 scoped_ptr<cc::LayerTreeSettings> settings_;
87 125
88 // Lazily created thread that will run the compositor rendering tasks. 126 // Lazily created thread that will run the compositor rendering tasks.
89 scoped_ptr<base::Thread> compositor_thread_; 127 scoped_ptr<base::Thread> compositor_thread_;
90 128
129 gfx::AcceleratedWidget window_;
130
131 // Whether or not |host_| should be visible. This is stored in case |host_|
132 // is null when SetVisible() is called or if we don't have a
133 // gfx::AcceleratedWidget to build an output surface from.
134 bool host_should_be_visible_;
135
136 // Whether there is an OutputSurface request pending from the current
137 // |host_|. Becomes |true| if RequestNewOutputSurface is called, and |false|
138 // if |host_| is deleted or we succeed in creating *and* initializing an
139 // OutputSurface (which is essentially the contract with cc).
140 bool output_surface_request_pending_;
141
142 // To be notified of any incoming compositor protos that are specifically sent
143 // to |render_widget_id_|.
144 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_;
145
146 // The bridge to the network layer that does the proto/RenderWidget id work.
147 // TODO(dtrainor): Move this to a higher level once we start dealing with
148 // multiple tabs.
149 RenderWidgetMessageProcessor render_widget_processor_;
150
91 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); 151 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor);
92 }; 152 };
93 153
94 } // namespace blimp 154 } // namespace blimp
95 155
96 #endif // BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ 156 #endif // BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698