OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_RENDERER_GPU_RENDERER_COMPOSITOR_FRAME_SINK_H_ | 5 #ifndef CONTENT_RENDERER_GPU_RENDERER_COMPOSITOR_FRAME_SINK_H_ |
6 #define CONTENT_RENDERER_GPU_RENDERER_COMPOSITOR_FRAME_SINK_H_ | 6 #define CONTENT_RENDERER_GPU_RENDERER_COMPOSITOR_FRAME_SINK_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
17 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "cc/input/selection.h" | 20 #include "cc/input/selection.h" |
21 #include "cc/ipc/mojo_compositor_frame_sink.mojom.h" | |
22 #include "cc/output/begin_frame_args.h" | 21 #include "cc/output/begin_frame_args.h" |
23 #include "cc/output/compositor_frame_sink.h" | 22 #include "cc/output/compositor_frame_sink.h" |
24 #include "cc/scheduler/begin_frame_source.h" | 23 #include "cc/scheduler/begin_frame_source.h" |
25 #include "cc/surfaces/local_surface_id.h" | 24 #include "cc/surfaces/local_surface_id.h" |
26 #include "cc/surfaces/local_surface_id_allocator.h" | 25 #include "cc/surfaces/local_surface_id_allocator.h" |
27 #include "content/renderer/gpu/compositor_forwarding_message_filter.h" | 26 #include "content/renderer/gpu/compositor_forwarding_message_filter.h" |
28 #include "ipc/ipc_sync_message_filter.h" | 27 #include "ipc/ipc_sync_message_filter.h" |
29 #include "mojo/public/cpp/bindings/binding.h" | |
30 #include "ui/gfx/selection_bound.h" | 28 #include "ui/gfx/selection_bound.h" |
31 | 29 |
32 namespace IPC { | 30 namespace IPC { |
33 class Message; | 31 class Message; |
34 } | 32 } |
35 | 33 |
36 namespace cc { | 34 namespace cc { |
37 class CompositorFrame; | 35 class CompositorFrame; |
38 class ContextProvider; | 36 class ContextProvider; |
39 } | 37 } |
40 | 38 |
41 namespace content { | 39 namespace content { |
42 class FrameSwapMessageQueue; | 40 class FrameSwapMessageQueue; |
43 | 41 |
44 // This class can be created only on the main thread, but then becomes pinned | 42 // This class can be created only on the main thread, but then becomes pinned |
45 // to a fixed thread when BindToClient is called. | 43 // to a fixed thread when BindToClient is called. |
46 class RendererCompositorFrameSink | 44 class RendererCompositorFrameSink |
47 : NON_EXPORTED_BASE(public cc::CompositorFrameSink), | 45 : NON_EXPORTED_BASE(public cc::CompositorFrameSink), |
48 NON_EXPORTED_BASE(public base::NonThreadSafe), | 46 NON_EXPORTED_BASE(public base::NonThreadSafe), |
49 NON_EXPORTED_BASE(public cc::mojom::MojoCompositorFrameSinkClient), | |
50 public cc::ExternalBeginFrameSourceClient { | 47 public cc::ExternalBeginFrameSourceClient { |
51 public: | 48 public: |
52 RendererCompositorFrameSink( | 49 RendererCompositorFrameSink( |
53 int32_t routing_id, | 50 int32_t routing_id, |
| 51 uint32_t compositor_frame_sink_id, |
54 std::unique_ptr<cc::SyntheticBeginFrameSource> | 52 std::unique_ptr<cc::SyntheticBeginFrameSource> |
55 synthetic_begin_frame_source, | 53 synthetic_begin_frame_source, |
56 scoped_refptr<cc::ContextProvider> context_provider, | 54 scoped_refptr<cc::ContextProvider> context_provider, |
57 scoped_refptr<cc::ContextProvider> worker_context_provider, | 55 scoped_refptr<cc::ContextProvider> worker_context_provider, |
58 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 56 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
59 cc::SharedBitmapManager* shared_bitmap_manager, | 57 cc::SharedBitmapManager* shared_bitmap_manager, |
60 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue); | 58 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue); |
61 RendererCompositorFrameSink( | 59 RendererCompositorFrameSink( |
62 int32_t routing_id, | 60 int32_t routing_id, |
| 61 uint32_t compositor_frame_sink_id, |
63 std::unique_ptr<cc::SyntheticBeginFrameSource> | 62 std::unique_ptr<cc::SyntheticBeginFrameSource> |
64 synthetic_begin_frame_source, | 63 synthetic_begin_frame_source, |
65 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, | 64 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, |
66 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue); | 65 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue); |
67 ~RendererCompositorFrameSink() override; | 66 ~RendererCompositorFrameSink() override; |
68 | 67 |
69 // cc::CompositorFrameSink implementation. | 68 // cc::CompositorFrameSink implementation. |
70 bool BindToClient(cc::CompositorFrameSinkClient* client) override; | 69 bool BindToClient(cc::CompositorFrameSinkClient* client) override; |
71 void DetachFromClient() override; | 70 void DetachFromClient() override; |
72 void SubmitCompositorFrame(cc::CompositorFrame frame) override; | 71 void SubmitCompositorFrame(cc::CompositorFrame frame) override; |
73 | 72 |
| 73 protected: |
| 74 uint32_t compositor_frame_sink_id_; |
| 75 |
74 private: | 76 private: |
75 class RendererCompositorFrameSinkProxy | 77 class RendererCompositorFrameSinkProxy |
76 : public base::RefCountedThreadSafe<RendererCompositorFrameSinkProxy> { | 78 : public base::RefCountedThreadSafe<RendererCompositorFrameSinkProxy> { |
77 public: | 79 public: |
78 explicit RendererCompositorFrameSinkProxy( | 80 explicit RendererCompositorFrameSinkProxy( |
79 RendererCompositorFrameSink* compositor_frame_sink) | 81 RendererCompositorFrameSink* compositor_frame_sink) |
80 : compositor_frame_sink_(compositor_frame_sink) {} | 82 : compositor_frame_sink_(compositor_frame_sink) {} |
81 void ClearCompositorFrameSink() { compositor_frame_sink_ = NULL; } | 83 void ClearCompositorFrameSink() { compositor_frame_sink_ = NULL; } |
82 void OnMessageReceived(const IPC::Message& message) { | 84 void OnMessageReceived(const IPC::Message& message) { |
83 if (compositor_frame_sink_) | 85 if (compositor_frame_sink_) |
84 compositor_frame_sink_->OnMessageReceived(message); | 86 compositor_frame_sink_->OnMessageReceived(message); |
85 } | 87 } |
86 | 88 |
87 private: | 89 private: |
88 friend class base::RefCountedThreadSafe<RendererCompositorFrameSinkProxy>; | 90 friend class base::RefCountedThreadSafe<RendererCompositorFrameSinkProxy>; |
89 ~RendererCompositorFrameSinkProxy() {} | 91 ~RendererCompositorFrameSinkProxy() {} |
90 RendererCompositorFrameSink* compositor_frame_sink_; | 92 RendererCompositorFrameSink* compositor_frame_sink_; |
91 | 93 |
92 DISALLOW_COPY_AND_ASSIGN(RendererCompositorFrameSinkProxy); | 94 DISALLOW_COPY_AND_ASSIGN(RendererCompositorFrameSinkProxy); |
93 }; | 95 }; |
94 | 96 |
95 void OnMessageReceived(const IPC::Message& message); | 97 void OnMessageReceived(const IPC::Message& message); |
96 void OnBeginFrameIPC(const cc::BeginFrameArgs& args); | 98 void OnReclaimCompositorResources(uint32_t compositor_frame_sink_id, |
| 99 bool is_swap_ack, |
| 100 const cc::ReturnedResourceArray& resources); |
| 101 void OnSetBeginFrameSourcePaused(bool paused); |
| 102 void OnBeginFrame(const cc::BeginFrameArgs& args); |
| 103 bool Send(IPC::Message* message); |
97 | 104 |
98 bool ShouldAllocateNewLocalSurfaceId(const cc::CompositorFrame& frame); | 105 bool ShouldAllocateNewLocalSurfaceId(const cc::CompositorFrame& frame); |
99 void UpdateFrameData(const cc::CompositorFrame& frame); | 106 void UpdateFrameData(const cc::CompositorFrame& frame); |
100 | 107 |
101 // cc::mojom::MojoCompositorFrameSinkClient implementation. | |
102 void DidReceiveCompositorFrameAck( | |
103 const cc::ReturnedResourceArray& resources) override; | |
104 void OnBeginFrame(const cc::BeginFrameArgs& args) override; | |
105 void ReclaimResources(const cc::ReturnedResourceArray& resources) override; | |
106 | |
107 // cc::ExternalBeginFrameSourceClient implementation. | 108 // cc::ExternalBeginFrameSourceClient implementation. |
108 void OnNeedsBeginFrames(bool need_begin_frames) override; | 109 void OnNeedsBeginFrames(bool need_begin_frames) override; |
109 void OnDidFinishFrame(const cc::BeginFrameAck& ack) override; | 110 void OnDidFinishFrame(const cc::BeginFrameAck& ack) override; |
110 | 111 |
111 void EstablishMojoConnection(); | |
112 | |
113 scoped_refptr<CompositorForwardingMessageFilter> | 112 scoped_refptr<CompositorForwardingMessageFilter> |
114 compositor_frame_sink_filter_; | 113 compositor_frame_sink_filter_; |
115 CompositorForwardingMessageFilter::Handler | 114 CompositorForwardingMessageFilter::Handler |
116 compositor_frame_sink_filter_handler_; | 115 compositor_frame_sink_filter_handler_; |
117 scoped_refptr<RendererCompositorFrameSinkProxy> compositor_frame_sink_proxy_; | 116 scoped_refptr<RendererCompositorFrameSinkProxy> compositor_frame_sink_proxy_; |
118 scoped_refptr<IPC::SyncMessageFilter> message_sender_; | 117 scoped_refptr<IPC::SyncMessageFilter> message_sender_; |
119 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue_; | 118 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue_; |
120 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source_; | 119 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source_; |
121 std::unique_ptr<cc::ExternalBeginFrameSource> external_begin_frame_source_; | 120 std::unique_ptr<cc::ExternalBeginFrameSource> external_begin_frame_source_; |
122 int routing_id_; | 121 int routing_id_; |
123 | 122 |
124 cc::LocalSurfaceId local_surface_id_; | 123 cc::LocalSurfaceId local_surface_id_; |
125 cc::LocalSurfaceIdAllocator id_allocator_; | 124 cc::LocalSurfaceIdAllocator id_allocator_; |
126 struct { | 125 struct { |
127 gfx::Size frame_size; | 126 gfx::Size frame_size; |
128 float device_scale_factor; | 127 float device_scale_factor; |
129 #ifdef OS_ANDROID | 128 #ifdef OS_ANDROID |
130 float top_controls_height; | 129 float top_controls_height; |
131 float top_controls_shown_ratio; | 130 float top_controls_shown_ratio; |
132 float bottom_controls_height; | 131 float bottom_controls_height; |
133 float bottom_controls_shown_ratio; | 132 float bottom_controls_shown_ratio; |
134 cc::Selection<gfx::SelectionBound> viewport_selection; | 133 cc::Selection<gfx::SelectionBound> viewport_selection; |
135 bool has_transparent_background; | 134 bool has_transparent_background; |
136 #endif | 135 #endif |
137 } current_frame_data_; | 136 } current_frame_data_; |
138 | 137 |
139 base::ThreadChecker thread_checker_; | 138 base::ThreadChecker thread_checker_; |
140 | |
141 cc::mojom::MojoCompositorFrameSinkPtr sink_; | |
142 cc::mojom::MojoCompositorFrameSinkPtrInfo sink_ptr_info_; | |
143 cc::mojom::MojoCompositorFrameSinkClientRequest sink_client_request_; | |
144 mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient> sink_client_binding_; | |
145 | |
146 bool bound_ = false; | 139 bool bound_ = false; |
147 }; | 140 }; |
148 | 141 |
149 } // namespace content | 142 } // namespace content |
150 | 143 |
151 #endif // CONTENT_RENDERER_GPU_RENDERER_COMPOSITOR_FRAME_SINK_H_ | 144 #endif // CONTENT_RENDERER_GPU_RENDERER_COMPOSITOR_FRAME_SINK_H_ |
OLD | NEW |