| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_FRAME_GENERATOR_H_ | 5 #ifndef SERVICES_UI_WS_FRAME_GENERATOR_H_ |
| 6 #define SERVICES_UI_WS_FRAME_GENERATOR_H_ | 6 #define SERVICES_UI_WS_FRAME_GENERATOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <unordered_map> | |
| 10 #include <vector> | |
| 11 | 9 |
| 12 #include "base/macros.h" | 10 #include "base/macros.h" |
| 13 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
| 14 #include "cc/ipc/display_compositor.mojom.h" | 12 #include "cc/ipc/display_compositor.mojom.h" |
| 15 #include "cc/surfaces/frame_sink_id.h" | 13 #include "cc/surfaces/frame_sink_id.h" |
| 16 #include "cc/surfaces/surface_id.h" | 14 #include "cc/surfaces/surface_id.h" |
| 17 #include "cc/surfaces/surface_id_allocator.h" | 15 #include "cc/surfaces/surface_id_allocator.h" |
| 18 #include "cc/surfaces/surface_reference.h" | 16 #include "cc/surfaces/surface_reference.h" |
| 19 #include "services/ui/public/interfaces/window_tree_constants.mojom.h" | 17 #include "services/ui/public/interfaces/window_tree_constants.mojom.h" |
| 18 #include "services/ui/ws/embedded_surface_tracker.h" |
| 20 #include "services/ui/ws/ids.h" | 19 #include "services/ui/ws/ids.h" |
| 21 #include "services/ui/ws/server_window_delegate.h" | 20 #include "services/ui/ws/server_window_delegate.h" |
| 22 #include "services/ui/ws/server_window_tracker.h" | 21 #include "services/ui/ws/server_window_tracker.h" |
| 23 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
| 24 #include "ui/gfx/native_widget_types.h" | 23 #include "ui/gfx/native_widget_types.h" |
| 25 | 24 |
| 26 namespace cc { | 25 namespace cc { |
| 27 class RenderPass; | 26 class RenderPass; |
| 28 class SurfaceId; | 27 class SurfaceId; |
| 29 } | 28 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 69 |
| 71 private: | 70 private: |
| 72 friend class ui::ws::test::FrameGeneratorTest; | 71 friend class ui::ws::test::FrameGeneratorTest; |
| 73 | 72 |
| 74 // cc::mojom::MojoCompositorFrameSinkClient implementation: | 73 // cc::mojom::MojoCompositorFrameSinkClient implementation: |
| 75 void DidReceiveCompositorFrameAck() override; | 74 void DidReceiveCompositorFrameAck() override; |
| 76 void OnBeginFrame(const cc::BeginFrameArgs& begin_frame_arags) override; | 75 void OnBeginFrame(const cc::BeginFrameArgs& begin_frame_arags) override; |
| 77 void ReclaimResources(const cc::ReturnedResourceArray& resources) override; | 76 void ReclaimResources(const cc::ReturnedResourceArray& resources) override; |
| 78 void WillDrawSurface() override; | 77 void WillDrawSurface() override; |
| 79 | 78 |
| 79 // Updates the display surface SurfaceId using new value in |local_frame_id_|. |
| 80 void UpdateDisplaySurfaceId(); |
| 81 |
| 80 // Generates the CompositorFrame. | 82 // Generates the CompositorFrame. |
| 81 cc::CompositorFrame GenerateCompositorFrame(const gfx::Rect& output_rect); | 83 cc::CompositorFrame GenerateCompositorFrame(const gfx::Rect& output_rect); |
| 82 | 84 |
| 83 // DrawWindowTree recursively visits ServerWindows, creating a SurfaceDrawQuad | 85 // DrawWindowTree recursively visits ServerWindows, creating a SurfaceDrawQuad |
| 84 // for each that lacks one. | 86 // for each that lacks one. |
| 85 void DrawWindowTree(cc::RenderPass* pass, | 87 void DrawWindowTree(cc::RenderPass* pass, |
| 86 ServerWindow* window, | 88 ServerWindow* window, |
| 87 const gfx::Vector2d& parent_to_root_origin_offset, | 89 const gfx::Vector2d& parent_to_root_origin_offset, |
| 88 float opacity); | 90 float opacity); |
| 89 | 91 |
| 90 // Finds the parent surface id for |window|. | |
| 91 cc::SurfaceId FindParentSurfaceId(ServerWindow* window); | |
| 92 | |
| 93 // Adds surface reference to local cache and surface manager. | |
| 94 void AddSurfaceReference(const cc::SurfaceId& parent_id, | |
| 95 const cc::SurfaceId& child_id); | |
| 96 | |
| 97 // Does work necessary for adding the first surface reference. | |
| 98 void AddFirstReference(const cc::SurfaceId& surface_id, ServerWindow* window); | |
| 99 | |
| 100 // Finds all Surfaces with references from |old_surface_id| and adds a new | |
| 101 // reference from |new_surface_id|. The caller should remove any references | |
| 102 // to |old_surface_id| afterwards to finish cleanup. | |
| 103 void AddNewParentReferences(const cc::SurfaceId& old_surface_id, | |
| 104 const cc::SurfaceId& new_surface_id); | |
| 105 | |
| 106 // Sends IPC to add references in |references_to_add_|. | |
| 107 void PerformAddSurfaceReferences(); | |
| 108 | |
| 109 // Sends IPC to remove all references in |references_to_remove_|. | |
| 110 void PerformRemoveSurfaceReferences(); | |
| 111 | |
| 112 // Removes any retained references for |frame_sink_id_|. | |
| 113 void RemoveFrameSinkReference(const cc::FrameSinkId& frame_sink_id); | |
| 114 | |
| 115 // Removes all retained references to surfaces. | |
| 116 void RemoveAllSurfaceReferences(); | |
| 117 | |
| 118 cc::mojom::DisplayCompositor* GetDisplayCompositor(); | |
| 119 | |
| 120 // ServerWindowObserver implementation. | 92 // ServerWindowObserver implementation. |
| 121 void OnWindowDestroying(ServerWindow* window) override; | 93 void OnWindowDestroying(ServerWindow* window) override; |
| 122 | 94 |
| 123 FrameGeneratorDelegate* delegate_; | 95 FrameGeneratorDelegate* delegate_; |
| 124 ServerWindow* const root_window_; | 96 ServerWindow* const root_window_; |
| 125 float device_scale_factor_ = 1.f; | 97 float device_scale_factor_ = 1.f; |
| 126 | 98 |
| 127 gfx::Size last_submitted_frame_size_; | 99 gfx::Size last_submitted_frame_size_; |
| 128 cc::LocalFrameId local_frame_id_; | 100 cc::LocalFrameId local_frame_id_; |
| 129 cc::SurfaceIdAllocator id_allocator_; | 101 cc::SurfaceIdAllocator id_allocator_; |
| 130 cc::mojom::MojoCompositorFrameSinkPtr compositor_frame_sink_; | 102 cc::mojom::MojoCompositorFrameSinkPtr compositor_frame_sink_; |
| 131 cc::mojom::DisplayPrivatePtr display_private_; | 103 cc::mojom::DisplayPrivatePtr display_private_; |
| 132 | 104 |
| 133 // Active references held by this client to surfaces that could be embedded in | 105 // Tracks surface references for embedded surfaces. |
| 134 // a CompositorFrame submitted from FrameGenerator. | 106 EmbeddedSurfaceTracker surface_tracker_; |
| 135 std::unordered_map<cc::FrameSinkId, cc::SurfaceReference, cc::FrameSinkIdHash> | |
| 136 active_references_; | |
| 137 | |
| 138 // References to surfaces that should be removed after a CompositorFrame has | |
| 139 // been submitted and the surfaces are not being used. | |
| 140 std::vector<cc::SurfaceReference> references_to_remove_; | |
| 141 | |
| 142 // References that should be added before the next CompositorFrame is | |
| 143 // submitted. | |
| 144 std::vector<cc::SurfaceReference> references_to_add_; | |
| 145 | |
| 146 // If a CompositorFrame for a child surface is submitted before the first | |
| 147 // display root CompositorFrame, we can't add a reference from the unknown | |
| 148 // display root SurfaceId. Track the child SurfaceId here and add a reference | |
| 149 // to it when the display root SurfaceId is available. | |
| 150 std::vector<cc::SurfaceId> waiting_for_references_; | |
| 151 | 107 |
| 152 mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient> binding_; | 108 mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient> binding_; |
| 153 | 109 |
| 154 base::WeakPtrFactory<FrameGenerator> weak_factory_; | 110 base::WeakPtrFactory<FrameGenerator> weak_factory_; |
| 155 | 111 |
| 156 DISALLOW_COPY_AND_ASSIGN(FrameGenerator); | 112 DISALLOW_COPY_AND_ASSIGN(FrameGenerator); |
| 157 }; | 113 }; |
| 158 | 114 |
| 159 } // namespace ws | 115 } // namespace ws |
| 160 | 116 |
| 161 } // namespace ui | 117 } // namespace ui |
| 162 | 118 |
| 163 #endif // SERVICES_UI_WS_FRAME_GENERATOR_H_ | 119 #endif // SERVICES_UI_WS_FRAME_GENERATOR_H_ |
| OLD | NEW |