| OLD | NEW |
| 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 SERVICES_UI_WS_SERVER_WINDOW_COMPOSITOR_FRAME_SINK_H_ | 5 #ifndef SERVICES_UI_WS_SERVER_WINDOW_COMPOSITOR_FRAME_SINK_H_ |
| 6 #define SERVICES_UI_WS_SERVER_WINDOW_COMPOSITOR_FRAME_SINK_H_ | 6 #define SERVICES_UI_WS_SERVER_WINDOW_COMPOSITOR_FRAME_SINK_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "cc/ipc/compositor_frame.mojom.h" | 13 #include "cc/ipc/compositor_frame.mojom.h" |
| 14 #include "cc/ipc/mojo_compositor_frame_sink.mojom.h" | 14 #include "cc/ipc/mojo_compositor_frame_sink.mojom.h" |
| 15 #include "cc/output/context_provider.h" | 15 #include "cc/output/context_provider.h" |
| 16 #include "cc/scheduler/begin_frame_source.h" |
| 16 #include "cc/surfaces/display.h" | 17 #include "cc/surfaces/display.h" |
| 17 #include "cc/surfaces/display_client.h" | 18 #include "cc/surfaces/display_client.h" |
| 18 #include "cc/surfaces/frame_sink_id.h" | 19 #include "cc/surfaces/frame_sink_id.h" |
| 19 #include "cc/surfaces/surface_factory.h" | 20 #include "cc/surfaces/surface_factory.h" |
| 20 #include "cc/surfaces/surface_factory_client.h" | 21 #include "cc/surfaces/surface_factory_client.h" |
| 21 #include "cc/surfaces/surface_id.h" | 22 #include "cc/surfaces/surface_id.h" |
| 22 #include "cc/surfaces/surface_id_allocator.h" | 23 #include "cc/surfaces/surface_id_allocator.h" |
| 23 #include "mojo/public/cpp/bindings/binding.h" | 24 #include "mojo/public/cpp/bindings/binding.h" |
| 24 #include "services/ui/public/interfaces/window_tree.mojom.h" | |
| 25 #include "services/ui/surfaces/surfaces_context_provider.h" | 25 #include "services/ui/surfaces/surfaces_context_provider.h" |
| 26 #include "services/ui/ws/ids.h" | 26 #include "services/ui/ws/ids.h" |
| 27 | 27 |
| 28 namespace base { | 28 namespace base { |
| 29 class SingleThreadTaskRunner; | 29 class SingleThreadTaskRunner; |
| 30 } | 30 } |
| 31 | 31 |
| 32 namespace gpu { | 32 namespace gpu { |
| 33 class GpuMemoryBufferManager; | 33 class GpuMemoryBufferManager; |
| 34 } | 34 } |
| 35 | 35 |
| 36 namespace ui { | 36 namespace ui { |
| 37 | 37 |
| 38 class DisplayCompositor; | 38 class DisplayCompositor; |
| 39 | 39 |
| 40 namespace ws { | 40 namespace ws { |
| 41 | 41 |
| 42 class ServerWindow; | 42 class ServerWindow; |
| 43 class ServerWindowCompositorFrameSinkManager; | |
| 44 | 43 |
| 45 // Server side representation of a WindowSurface. | 44 // Server side representation of a WindowSurface. |
| 46 class ServerWindowCompositorFrameSink | 45 class ServerWindowCompositorFrameSink |
| 47 : public cc::mojom::MojoCompositorFrameSink, | 46 : public cc::mojom::MojoCompositorFrameSink, |
| 48 public cc::DisplayClient, | 47 public cc::DisplayClient, |
| 49 public cc::SurfaceFactoryClient { | 48 public cc::mojom::MojoCompositorFrameSinkPrivate, |
| 49 public cc::SurfaceFactoryClient, |
| 50 public cc::BeginFrameObserver { |
| 50 public: | 51 public: |
| 52 // TODO(fsamuel): DisplayCompositor should own |
| 53 // ServerWindowCompositorFrameSink. ServerWindowCompositorFrameSink should not |
| 54 // refer to ServerWindowCompositorFrameSinkManager. |
| 51 ServerWindowCompositorFrameSink( | 55 ServerWindowCompositorFrameSink( |
| 52 ServerWindowCompositorFrameSinkManager* manager, | 56 scoped_refptr<DisplayCompositor> display_compositor, |
| 53 const cc::FrameSinkId& frame_sink_id, | 57 const cc::FrameSinkId& frame_sink_id, |
| 54 gfx::AcceleratedWidget widget, | 58 gfx::AcceleratedWidget widget, |
| 55 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 59 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 56 scoped_refptr<SurfacesContextProvider> context_provider, | 60 scoped_refptr<SurfacesContextProvider> context_provider, |
| 57 cc::mojom::MojoCompositorFrameSinkRequest request, | 61 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 58 cc::mojom::MojoCompositorFrameSinkClientPtr client); | 62 cc::mojom::MojoCompositorFrameSinkClientPtr client); |
| 59 | 63 |
| 60 ~ServerWindowCompositorFrameSink() override; | 64 ~ServerWindowCompositorFrameSink() override; |
| 61 | 65 |
| 62 // cc::mojom::MojoCompositorFrameSink: | 66 // cc::mojom::MojoCompositorFrameSink: |
| 63 void SetNeedsBeginFrame(bool needs_begin_frame) override; | 67 void SetNeedsBeginFrame(bool needs_begin_frame) override; |
| 64 void SubmitCompositorFrame(cc::CompositorFrame frame) override; | 68 void SubmitCompositorFrame(cc::CompositorFrame frame) override; |
| 65 | 69 |
| 70 // cc::mojom::MojoCompositorFrameSinkPrivate: |
| 71 void AddChildFrameSink(const cc::FrameSinkId& child_frame_sink_id) override; |
| 72 void RemoveChildFrameSink( |
| 73 const cc::FrameSinkId& child_frame_sink_id) override; |
| 74 |
| 66 private: | 75 private: |
| 67 void InitDisplay(gfx::AcceleratedWidget widget, | 76 void InitDisplay(gfx::AcceleratedWidget widget, |
| 68 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 77 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 69 scoped_refptr<SurfacesContextProvider> context_provider); | 78 scoped_refptr<SurfacesContextProvider> context_provider); |
| 70 | 79 |
| 71 void DidReceiveCompositorFrameAck(); | 80 void DidReceiveCompositorFrameAck(); |
| 72 | 81 |
| 73 // DisplayClient implementation. | 82 // cc::DisplayClient implementation. |
| 74 void DisplayOutputSurfaceLost() override; | 83 void DisplayOutputSurfaceLost() override; |
| 75 void DisplayWillDrawAndSwap(bool will_draw_and_swap, | 84 void DisplayWillDrawAndSwap(bool will_draw_and_swap, |
| 76 const cc::RenderPassList& render_passes) override; | 85 const cc::RenderPassList& render_passes) override; |
| 77 void DisplayDidDrawAndSwap() override; | 86 void DisplayDidDrawAndSwap() override; |
| 78 | 87 |
| 79 // SurfaceFactoryClient implementation. | 88 // cc::SurfaceFactoryClient implementation. |
| 80 void ReturnResources(const cc::ReturnedResourceArray& resources) override; | 89 void ReturnResources(const cc::ReturnedResourceArray& resources) override; |
| 81 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override; | 90 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override; |
| 82 | 91 |
| 92 // cc::BeginFrameObserver implementation. |
| 93 void OnBeginFrame(const cc::BeginFrameArgs& args) override; |
| 94 const cc::BeginFrameArgs& LastUsedBeginFrameArgs() const override; |
| 95 void OnBeginFrameSourcePausedChanged(bool paused) override; |
| 96 |
| 97 void UpdateNeedsBeginFramesInternal(); |
| 98 |
| 83 const cc::FrameSinkId frame_sink_id_; | 99 const cc::FrameSinkId frame_sink_id_; |
| 84 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 100 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 85 | 101 |
| 86 ServerWindowCompositorFrameSinkManager* manager_; // Owns this. | 102 // TODO(fsamuel): We hold a reference to DisplayCompositor so we can talk to |
| 103 // SurfaceManager in the destructor. In the future, DisplayCompositor will own |
| 104 // ServerWindowCompositorFrameSink. |
| 105 scoped_refptr<DisplayCompositor> display_compositor_; |
| 87 | 106 |
| 88 gfx::Size last_submitted_frame_size_; | 107 gfx::Size last_submitted_frame_size_; |
| 89 // ServerWindowCompositorFrameSink holds a cc::Display if it created with | 108 // ServerWindowCompositorFrameSink holds a cc::Display if it created with |
| 90 // non-null gfx::AcceleratedWidget. In the window server, the display root | 109 // non-null gfx::AcceleratedWidget. In the window server, the display root |
| 91 // window's CompositorFrameSink will have a valid gfx::AcceleratedWidget. | 110 // window's CompositorFrameSink will have a valid gfx::AcceleratedWidget. |
| 92 std::unique_ptr<cc::Display> display_; | 111 std::unique_ptr<cc::Display> display_; |
| 93 | 112 |
| 94 cc::LocalFrameId local_frame_id_; | 113 cc::LocalFrameId local_frame_id_; |
| 95 cc::SurfaceIdAllocator surface_id_allocator_; | 114 cc::SurfaceIdAllocator surface_id_allocator_; |
| 96 cc::SurfaceFactory surface_factory_; | 115 cc::SurfaceFactory surface_factory_; |
| 97 // Counts the number of CompositorFrames that have been submitted and have not | 116 // Counts the number of CompositorFrames that have been submitted and have not |
| 98 // yet received an ACK. | 117 // yet received an ACK. |
| 99 int ack_pending_count_ = 0; | 118 int ack_pending_count_ = 0; |
| 100 cc::ReturnedResourceArray surface_returned_resources_; | 119 cc::ReturnedResourceArray surface_returned_resources_; |
| 101 | 120 |
| 121 // The begin frame source being observered. Null if none. |
| 122 cc::BeginFrameSource* begin_frame_source_ = nullptr; |
| 123 |
| 124 // The last begin frame args generated by the begin frame source. |
| 125 cc::BeginFrameArgs last_begin_frame_args_; |
| 126 |
| 127 // Whether a request for begin frames has been issued. |
| 128 bool needs_begin_frame_ = false; |
| 129 |
| 130 // Whether or not a frame observer has been added. |
| 131 bool added_frame_observer_ = false; |
| 132 |
| 102 cc::mojom::MojoCompositorFrameSinkClientPtr client_; | 133 cc::mojom::MojoCompositorFrameSinkClientPtr client_; |
| 103 mojo::Binding<MojoCompositorFrameSink> binding_; | 134 mojo::Binding<cc::mojom::MojoCompositorFrameSink> binding_; |
| 104 | 135 |
| 105 DISALLOW_COPY_AND_ASSIGN(ServerWindowCompositorFrameSink); | 136 DISALLOW_COPY_AND_ASSIGN(ServerWindowCompositorFrameSink); |
| 106 }; | 137 }; |
| 107 | 138 |
| 108 } // namespace ws | 139 } // namespace ws |
| 109 | 140 |
| 110 } // namespace ui | 141 } // namespace ui |
| 111 | 142 |
| 112 #endif // SERVICES_UI_WS_SERVER_WINDOW_COMPOSITOR_FRAME_SINK_H_ | 143 #endif // SERVICES_UI_WS_SERVER_WINDOW_COMPOSITOR_FRAME_SINK_H_ |
| OLD | NEW |