| 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/surface_display_output_surface.h" | 5 #include "cc/surfaces/surface_display_output_surface.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/surfaces/display.h" | 9 #include "cc/surfaces/display.h" |
| 10 #include "cc/surfaces/surface.h" | 10 #include "cc/surfaces/surface.h" |
| 11 #include "cc/surfaces/surface_id_allocator.h" | 11 #include "cc/surfaces/surface_id_allocator.h" |
| 12 #include "cc/surfaces/surface_manager.h" | 12 #include "cc/surfaces/surface_manager.h" |
| 13 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 | 15 |
| 16 SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface( | 16 SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface( |
| 17 SurfaceManager* surface_manager, | 17 SurfaceManager* surface_manager, |
| 18 SurfaceIdAllocator* surface_id_allocator, | 18 SurfaceIdAllocator* surface_id_allocator, |
| 19 Display* display, | 19 Display* display, |
| 20 scoped_refptr<ContextProvider> context_provider, | 20 scoped_refptr<ContextProvider> context_provider, |
| 21 scoped_refptr<ContextProvider> worker_context_provider) | 21 scoped_refptr<ContextProvider> worker_context_provider) |
| 22 : OutputSurface(std::move(context_provider), | 22 : OutputSurface(std::move(context_provider), |
| 23 std::move(worker_context_provider), | 23 std::move(worker_context_provider), |
| 24 nullptr), | 24 nullptr), |
| 25 surface_manager_(surface_manager), | 25 surface_manager_(surface_manager), |
| 26 surface_id_allocator_(surface_id_allocator), | 26 surface_id_allocator_(surface_id_allocator), |
| 27 display_(display), | 27 display_(display) { |
| 28 factory_(surface_manager, this) { | |
| 29 DCHECK(thread_checker_.CalledOnValidThread()); | 28 DCHECK(thread_checker_.CalledOnValidThread()); |
| 30 capabilities_.delegated_rendering = true; | 29 capabilities_.delegated_rendering = true; |
| 31 capabilities_.adjust_deadline_for_parent = true; | 30 capabilities_.adjust_deadline_for_parent = true; |
| 32 capabilities_.can_force_reclaim_resources = true; | 31 capabilities_.can_force_reclaim_resources = true; |
| 33 | 32 |
| 34 // Display and SurfaceDisplayOutputSurface share a GL context, so sync | 33 // Display and SurfaceDisplayOutputSurface share a GL context, so sync |
| 35 // points aren't needed when passing resources between them. | 34 // points aren't needed when passing resources between them. |
| 36 capabilities_.delegated_sync_points_required = false; | 35 capabilities_.delegated_sync_points_required = false; |
| 37 factory_.set_needs_sync_points(false); | |
| 38 } | 36 } |
| 39 | 37 |
| 40 SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface( | 38 SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface( |
| 41 SurfaceManager* surface_manager, | 39 SurfaceManager* surface_manager, |
| 42 SurfaceIdAllocator* surface_id_allocator, | 40 SurfaceIdAllocator* surface_id_allocator, |
| 43 Display* display, | 41 Display* display, |
| 44 scoped_refptr<VulkanContextProvider> vulkan_context_provider) | 42 scoped_refptr<VulkanContextProvider> vulkan_context_provider) |
| 45 : OutputSurface(std::move(vulkan_context_provider)), | 43 : OutputSurface(std::move(vulkan_context_provider)), |
| 46 surface_manager_(surface_manager), | 44 surface_manager_(surface_manager), |
| 47 surface_id_allocator_(surface_id_allocator), | 45 surface_id_allocator_(surface_id_allocator), |
| 48 display_(display), | 46 display_(display) { |
| 49 factory_(surface_manager, this) { | |
| 50 DCHECK(thread_checker_.CalledOnValidThread()); | 47 DCHECK(thread_checker_.CalledOnValidThread()); |
| 51 capabilities_.delegated_rendering = true; | 48 capabilities_.delegated_rendering = true; |
| 52 capabilities_.adjust_deadline_for_parent = true; | 49 capabilities_.adjust_deadline_for_parent = true; |
| 53 capabilities_.can_force_reclaim_resources = true; | 50 capabilities_.can_force_reclaim_resources = true; |
| 54 } | 51 } |
| 55 | 52 |
| 56 SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() { | 53 SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() { |
| 57 DCHECK(thread_checker_.CalledOnValidThread()); | 54 DCHECK(thread_checker_.CalledOnValidThread()); |
| 58 if (HasClient()) | 55 if (HasClient()) |
| 59 DetachFromClient(); | 56 DetachFromClient(); |
| 60 } | 57 } |
| 61 | 58 |
| 62 void SurfaceDisplayOutputSurface::SwapBuffers(CompositorFrame frame) { | 59 void SurfaceDisplayOutputSurface::SwapBuffers(CompositorFrame frame) { |
| 63 gfx::Size frame_size = | 60 gfx::Size frame_size = |
| 64 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); | 61 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); |
| 65 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { | 62 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { |
| 66 if (!delegated_surface_id_.is_null()) { | 63 if (!delegated_surface_id_.is_null()) { |
| 67 factory_.Destroy(delegated_surface_id_); | 64 factory_->Destroy(delegated_surface_id_); |
| 68 } | 65 } |
| 69 delegated_surface_id_ = surface_id_allocator_->GenerateId(); | 66 delegated_surface_id_ = surface_id_allocator_->GenerateId(); |
| 70 factory_.Create(delegated_surface_id_); | 67 factory_->Create(delegated_surface_id_); |
| 71 last_swap_frame_size_ = frame_size; | 68 last_swap_frame_size_ = frame_size; |
| 72 } | 69 } |
| 73 display_->SetSurfaceId(delegated_surface_id_, | 70 display_->SetSurfaceId(delegated_surface_id_, |
| 74 frame.metadata.device_scale_factor); | 71 frame.metadata.device_scale_factor); |
| 75 | 72 |
| 76 factory_.SubmitCompositorFrame( | 73 factory_->SubmitCompositorFrame( |
| 77 delegated_surface_id_, std::move(frame), | 74 delegated_surface_id_, std::move(frame), |
| 78 base::Bind(&SurfaceDisplayOutputSurface::SwapBuffersComplete, | 75 base::Bind(&SurfaceDisplayOutputSurface::SwapBuffersComplete, |
| 79 base::Unretained(this))); | 76 base::Unretained(this))); |
| 80 } | 77 } |
| 81 | 78 |
| 82 bool SurfaceDisplayOutputSurface::BindToClient(OutputSurfaceClient* client) { | 79 bool SurfaceDisplayOutputSurface::BindToClient(OutputSurfaceClient* client) { |
| 83 DCHECK(thread_checker_.CalledOnValidThread()); | 80 DCHECK(thread_checker_.CalledOnValidThread()); |
| 84 | 81 |
| 85 surface_manager_->RegisterSurfaceFactoryClient( | 82 factory_.reset(new SurfaceFactory(surface_id_allocator_->client_id(), |
| 86 surface_id_allocator_->client_id(), this); | 83 surface_manager_, this)); |
| 84 if (!capabilities_.delegated_sync_points_required) |
| 85 factory_->set_needs_sync_points(false); |
| 87 | 86 |
| 88 if (!OutputSurface::BindToClient(client)) | 87 if (!OutputSurface::BindToClient(client)) |
| 89 return false; | 88 return false; |
| 90 | 89 |
| 91 // We want the Display's output surface to hear about lost context, and since | 90 // We want the Display's output surface to hear about lost context, and since |
| 92 // this shares a context with it, we should not be listening for lost context | 91 // this shares a context with it, we should not be listening for lost context |
| 93 // callbacks on the context here. | 92 // callbacks on the context here. |
| 94 if (context_provider()) | 93 if (context_provider()) |
| 95 context_provider()->SetLostContextCallback(base::Closure()); | 94 context_provider()->SetLostContextCallback(base::Closure()); |
| 96 | 95 |
| 97 // Avoid initializing GL context here, as this should be sharing the | 96 // Avoid initializing GL context here, as this should be sharing the |
| 98 // Display's context. | 97 // Display's context. |
| 99 display_->Initialize(this, surface_manager_, | 98 display_->Initialize(this, surface_manager_, |
| 100 surface_id_allocator_->client_id()); | 99 surface_id_allocator_->client_id()); |
| 101 return true; | 100 return true; |
| 102 } | 101 } |
| 103 | 102 |
| 104 void SurfaceDisplayOutputSurface::ForceReclaimResources() { | 103 void SurfaceDisplayOutputSurface::ForceReclaimResources() { |
| 105 if (!delegated_surface_id_.is_null()) { | 104 if (!delegated_surface_id_.is_null()) { |
| 106 factory_.SubmitCompositorFrame(delegated_surface_id_, CompositorFrame(), | 105 factory_->SubmitCompositorFrame(delegated_surface_id_, CompositorFrame(), |
| 107 SurfaceFactory::DrawCallback()); | 106 SurfaceFactory::DrawCallback()); |
| 108 } | 107 } |
| 109 } | 108 } |
| 110 | 109 |
| 111 void SurfaceDisplayOutputSurface::DetachFromClient() { | 110 void SurfaceDisplayOutputSurface::DetachFromClient() { |
| 112 DCHECK(HasClient()); | 111 DCHECK(HasClient()); |
| 113 // Unregister the SurfaceFactoryClient here instead of the dtor so that only | 112 // Unregister the SurfaceFactoryClient here instead of the dtor so that only |
| 114 // one client is alive for this namespace at any given time. | 113 // one client is alive for this namespace at any given time. |
| 115 surface_manager_->UnregisterSurfaceFactoryClient( | |
| 116 surface_id_allocator_->client_id()); | |
| 117 if (!delegated_surface_id_.is_null()) | 114 if (!delegated_surface_id_.is_null()) |
| 118 factory_.Destroy(delegated_surface_id_); | 115 factory_->Destroy(delegated_surface_id_); |
| 119 | 116 |
| 117 factory_.reset(); |
| 120 OutputSurface::DetachFromClient(); | 118 OutputSurface::DetachFromClient(); |
| 121 } | 119 } |
| 122 | 120 |
| 123 void SurfaceDisplayOutputSurface::BindFramebuffer() { | 121 void SurfaceDisplayOutputSurface::BindFramebuffer() { |
| 124 // This is a delegating output surface, no framebuffer/direct drawing support. | 122 // This is a delegating output surface, no framebuffer/direct drawing support. |
| 125 NOTREACHED(); | 123 NOTREACHED(); |
| 126 } | 124 } |
| 127 | 125 |
| 128 uint32_t SurfaceDisplayOutputSurface::GetFramebufferCopyTextureFormat() { | 126 uint32_t SurfaceDisplayOutputSurface::GetFramebufferCopyTextureFormat() { |
| 129 // This is a delegating output surface, no framebuffer/direct drawing support. | 127 // This is a delegating output surface, no framebuffer/direct drawing support. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 153 SetMemoryPolicy(policy); | 151 SetMemoryPolicy(policy); |
| 154 } | 152 } |
| 155 | 153 |
| 156 void SurfaceDisplayOutputSurface::SwapBuffersComplete(SurfaceDrawStatus drawn) { | 154 void SurfaceDisplayOutputSurface::SwapBuffersComplete(SurfaceDrawStatus drawn) { |
| 157 // TODO(danakj): Why the lost check? | 155 // TODO(danakj): Why the lost check? |
| 158 if (!output_surface_lost_) | 156 if (!output_surface_lost_) |
| 159 client_->DidSwapBuffersComplete(); | 157 client_->DidSwapBuffersComplete(); |
| 160 } | 158 } |
| 161 | 159 |
| 162 } // namespace cc | 160 } // namespace cc |
| OLD | NEW |