| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "cc/surfaces/direct_compositor_frame_sink.h" | 5 #include "cc/surfaces/direct_compositor_frame_sink.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
| 9 #include "cc/output/compositor_frame_sink_client.h" | 9 #include "cc/output/compositor_frame_sink_client.h" |
| 10 #include "cc/surfaces/display.h" | 10 #include "cc/surfaces/display.h" |
| 11 #include "cc/surfaces/frame_sink_id.h" | 11 #include "cc/surfaces/frame_sink_id.h" |
| 12 #include "cc/surfaces/surface.h" | 12 #include "cc/surfaces/surface.h" |
| 13 #include "cc/surfaces/surface_id_allocator.h" | 13 #include "cc/surfaces/surface_id_allocator.h" |
| 14 #include "cc/surfaces/surface_manager.h" | 14 #include "cc/surfaces/surface_manager.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 | 17 |
| 18 DirectCompositorFrameSink::DirectCompositorFrameSink( | 18 DirectCompositorFrameSink::DirectCompositorFrameSink( |
| 19 const FrameSinkId& frame_sink_id, | 19 const FrameSinkId& frame_sink_id, |
| 20 SurfaceManager* surface_manager, | 20 SurfaceManager* surface_manager, |
| 21 Display* display, | 21 Display* display, |
| 22 scoped_refptr<ContextProvider> context_provider, | 22 scoped_refptr<ContextProvider> context_provider, |
| 23 scoped_refptr<ContextProvider> worker_context_provider) | 23 scoped_refptr<ContextProvider> worker_context_provider) |
| 24 : CompositorFrameSink(std::move(context_provider), | 24 : CompositorFrameSink(std::move(context_provider), |
| 25 std::move(worker_context_provider)), | 25 std::move(worker_context_provider)), |
| 26 frame_sink_id_(frame_sink_id), | 26 frame_sink_id_(frame_sink_id), |
| 27 surface_manager_(surface_manager), | 27 surface_manager_(surface_manager), |
| 28 surface_id_allocator_(frame_sink_id), | |
| 29 display_(display), | 28 display_(display), |
| 30 factory_(frame_sink_id, surface_manager, this) { | 29 factory_(frame_sink_id, surface_manager, this) { |
| 31 DCHECK(thread_checker_.CalledOnValidThread()); | 30 DCHECK(thread_checker_.CalledOnValidThread()); |
| 32 capabilities_.can_force_reclaim_resources = true; | 31 capabilities_.can_force_reclaim_resources = true; |
| 33 // Display and DirectCompositorFrameSink share a GL context, so sync | 32 // Display and DirectCompositorFrameSink share a GL context, so sync |
| 34 // points aren't needed when passing resources between them. | 33 // points aren't needed when passing resources between them. |
| 35 capabilities_.delegated_sync_points_required = false; | 34 capabilities_.delegated_sync_points_required = false; |
| 36 factory_.set_needs_sync_points(false); | 35 factory_.set_needs_sync_points(false); |
| 37 } | 36 } |
| 38 | 37 |
| 39 DirectCompositorFrameSink::DirectCompositorFrameSink( | 38 DirectCompositorFrameSink::DirectCompositorFrameSink( |
| 40 const FrameSinkId& frame_sink_id, | 39 const FrameSinkId& frame_sink_id, |
| 41 SurfaceManager* surface_manager, | 40 SurfaceManager* surface_manager, |
| 42 Display* display, | 41 Display* display, |
| 43 scoped_refptr<VulkanContextProvider> vulkan_context_provider) | 42 scoped_refptr<VulkanContextProvider> vulkan_context_provider) |
| 44 : CompositorFrameSink(std::move(vulkan_context_provider)), | 43 : CompositorFrameSink(std::move(vulkan_context_provider)), |
| 45 frame_sink_id_(frame_sink_id), | 44 frame_sink_id_(frame_sink_id), |
| 46 surface_manager_(surface_manager), | 45 surface_manager_(surface_manager), |
| 47 surface_id_allocator_(frame_sink_id_), | |
| 48 display_(display), | 46 display_(display), |
| 49 factory_(frame_sink_id_, surface_manager, this) { | 47 factory_(frame_sink_id_, surface_manager, this) { |
| 50 DCHECK(thread_checker_.CalledOnValidThread()); | 48 DCHECK(thread_checker_.CalledOnValidThread()); |
| 51 capabilities_.can_force_reclaim_resources = true; | 49 capabilities_.can_force_reclaim_resources = true; |
| 52 } | 50 } |
| 53 | 51 |
| 54 DirectCompositorFrameSink::~DirectCompositorFrameSink() { | 52 DirectCompositorFrameSink::~DirectCompositorFrameSink() { |
| 55 DCHECK(thread_checker_.CalledOnValidThread()); | 53 DCHECK(thread_checker_.CalledOnValidThread()); |
| 56 if (HasClient()) | 54 if (HasClient()) |
| 57 DetachFromClient(); | 55 DetachFromClient(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 76 // Display's context. | 74 // Display's context. |
| 77 display_->Initialize(this, surface_manager_, frame_sink_id_); | 75 display_->Initialize(this, surface_manager_, frame_sink_id_); |
| 78 return true; | 76 return true; |
| 79 } | 77 } |
| 80 | 78 |
| 81 void DirectCompositorFrameSink::DetachFromClient() { | 79 void DirectCompositorFrameSink::DetachFromClient() { |
| 82 DCHECK(HasClient()); | 80 DCHECK(HasClient()); |
| 83 // Unregister the SurfaceFactoryClient here instead of the dtor so that only | 81 // Unregister the SurfaceFactoryClient here instead of the dtor so that only |
| 84 // one client is alive for this namespace at any given time. | 82 // one client is alive for this namespace at any given time. |
| 85 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | 83 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
| 86 if (!delegated_surface_id_.is_null()) | 84 if (!delegated_local_frame_id_.is_null()) |
| 87 factory_.Destroy(delegated_surface_id_); | 85 factory_.Destroy(delegated_local_frame_id_); |
| 88 | 86 |
| 89 CompositorFrameSink::DetachFromClient(); | 87 CompositorFrameSink::DetachFromClient(); |
| 90 } | 88 } |
| 91 | 89 |
| 92 void DirectCompositorFrameSink::SwapBuffers(CompositorFrame frame) { | 90 void DirectCompositorFrameSink::SwapBuffers(CompositorFrame frame) { |
| 93 gfx::Size frame_size = | 91 gfx::Size frame_size = |
| 94 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); | 92 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); |
| 95 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { | 93 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { |
| 96 if (!delegated_surface_id_.is_null()) { | 94 if (!delegated_local_frame_id_.is_null()) { |
| 97 factory_.Destroy(delegated_surface_id_); | 95 factory_.Destroy(delegated_local_frame_id_); |
| 98 } | 96 } |
| 99 delegated_surface_id_ = surface_id_allocator_.GenerateId(); | 97 delegated_local_frame_id_ = surface_id_allocator_.GenerateId(); |
| 100 factory_.Create(delegated_surface_id_); | 98 factory_.Create(delegated_local_frame_id_); |
| 101 last_swap_frame_size_ = frame_size; | 99 last_swap_frame_size_ = frame_size; |
| 102 } | 100 } |
| 103 display_->SetSurfaceId(delegated_surface_id_, | 101 display_->SetSurfaceId(SurfaceId(frame_sink_id_, delegated_local_frame_id_), |
| 104 frame.metadata.device_scale_factor); | 102 frame.metadata.device_scale_factor); |
| 105 | 103 |
| 106 factory_.SubmitCompositorFrame( | 104 factory_.SubmitCompositorFrame( |
| 107 delegated_surface_id_, std::move(frame), | 105 delegated_local_frame_id_, std::move(frame), |
| 108 base::Bind(&DirectCompositorFrameSink::DidDrawCallback, | 106 base::Bind(&DirectCompositorFrameSink::DidDrawCallback, |
| 109 base::Unretained(this))); | 107 base::Unretained(this))); |
| 110 } | 108 } |
| 111 | 109 |
| 112 void DirectCompositorFrameSink::ForceReclaimResources() { | 110 void DirectCompositorFrameSink::ForceReclaimResources() { |
| 113 if (!delegated_surface_id_.is_null()) { | 111 if (!delegated_local_frame_id_.is_null()) { |
| 114 factory_.SubmitCompositorFrame(delegated_surface_id_, CompositorFrame(), | 112 factory_.SubmitCompositorFrame(delegated_local_frame_id_, CompositorFrame(), |
| 115 SurfaceFactory::DrawCallback()); | 113 SurfaceFactory::DrawCallback()); |
| 116 } | 114 } |
| 117 } | 115 } |
| 118 | 116 |
| 119 void DirectCompositorFrameSink::ReturnResources( | 117 void DirectCompositorFrameSink::ReturnResources( |
| 120 const ReturnedResourceArray& resources) { | 118 const ReturnedResourceArray& resources) { |
| 121 if (client_) | 119 if (client_) |
| 122 client_->ReclaimResources(resources); | 120 client_->ReclaimResources(resources); |
| 123 } | 121 } |
| 124 | 122 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 145 // be drawn. | 143 // be drawn. |
| 146 } | 144 } |
| 147 | 145 |
| 148 void DirectCompositorFrameSink::DidDrawCallback() { | 146 void DirectCompositorFrameSink::DidDrawCallback() { |
| 149 // TODO(danakj): Why the lost check? | 147 // TODO(danakj): Why the lost check? |
| 150 if (!is_lost_) | 148 if (!is_lost_) |
| 151 client_->DidSwapBuffersComplete(); | 149 client_->DidSwapBuffersComplete(); |
| 152 } | 150 } |
| 153 | 151 |
| 154 } // namespace cc | 152 } // namespace cc |
| OLD | NEW |