| 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_factory.h" | 5 #include "cc/surfaces/surface_factory.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); | 58 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); |
| 59 DCHECK(local_surface_id.is_valid()); | 59 DCHECK(local_surface_id.is_valid()); |
| 60 std::unique_ptr<Surface> surface; | 60 std::unique_ptr<Surface> surface; |
| 61 bool create_new_surface = | 61 bool create_new_surface = |
| 62 (!current_surface_ || | 62 (!current_surface_ || |
| 63 local_surface_id != current_surface_->surface_id().local_surface_id()); | 63 local_surface_id != current_surface_->surface_id().local_surface_id()); |
| 64 if (!create_new_surface) { | 64 if (!create_new_surface) { |
| 65 surface = std::move(current_surface_); | 65 surface = std::move(current_surface_); |
| 66 } else { | 66 } else { |
| 67 surface = Create(local_surface_id); | 67 surface = Create(local_surface_id); |
| 68 gfx::Size frame_size; | |
| 69 // CompositorFrames may not be populated with a RenderPass in unit tests. | |
| 70 if (!frame.render_pass_list.empty()) | |
| 71 frame_size = frame.render_pass_list.back()->output_rect.size(); | |
| 72 manager_->SurfaceCreated(SurfaceInfo( | |
| 73 surface->surface_id(), frame.metadata.device_scale_factor, frame_size)); | |
| 74 } | 68 } |
| 75 surface->QueueFrame(std::move(frame), callback); | 69 surface->QueueFrame(std::move(frame), callback); |
| 70 |
| 76 if (!manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_surface_id))) { | 71 if (!manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_surface_id))) { |
| 77 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); | 72 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); |
| 78 surface->RunDrawCallbacks(); | 73 surface->RunDrawCallbacks(); |
| 79 } | 74 } |
| 80 if (current_surface_ && create_new_surface) { | 75 if (current_surface_ && create_new_surface) { |
| 81 surface->SetPreviousFrameSurface(current_surface_.get()); | 76 surface->SetPreviousFrameSurface(current_surface_.get()); |
| 82 Destroy(std::move(current_surface_)); | 77 Destroy(std::move(current_surface_)); |
| 83 } | 78 } |
| 84 current_surface_ = std::move(surface); | 79 current_surface_ = std::move(surface); |
| 85 } | 80 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 113 } | 108 } |
| 114 | 109 |
| 115 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { | 110 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { |
| 116 holder_.RefResources(resources); | 111 holder_.RefResources(resources); |
| 117 } | 112 } |
| 118 | 113 |
| 119 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { | 114 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { |
| 120 holder_.UnrefResources(resources); | 115 holder_.UnrefResources(resources); |
| 121 } | 116 } |
| 122 | 117 |
| 118 void SurfaceFactory::OnSurfaceActivated(Surface* surface) { |
| 119 DCHECK(surface->HasActiveFrame()); |
| 120 const CompositorFrame& frame = surface->GetActiveFrame(); |
| 121 // CompositorFrames might not be populated with a RenderPass in unit tests. |
| 122 gfx::Size frame_size; |
| 123 if (!frame.render_pass_list.empty()) |
| 124 frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 125 |
| 126 // SurfaceCreated only applies for the first Surface activation. Thus, |
| 127 // SurfaceFactory stops observing new activations after the first one. |
| 128 manager_->SurfaceCreated(SurfaceInfo( |
| 129 surface->surface_id(), frame.metadata.device_scale_factor, frame_size)); |
| 130 surface->RemoveObserver(this); |
| 131 } |
| 132 |
| 133 void SurfaceFactory::OnSurfaceDependenciesChanged( |
| 134 Surface* pending_surface, |
| 135 const SurfaceDependencies& added_dependencies, |
| 136 const SurfaceDependencies& removed_dependencies) {} |
| 137 |
| 138 void SurfaceFactory::OnSurfaceDiscarded(Surface* pending_surface) {} |
| 139 |
| 123 std::unique_ptr<Surface> SurfaceFactory::Create( | 140 std::unique_ptr<Surface> SurfaceFactory::Create( |
| 124 const LocalSurfaceId& local_surface_id) { | 141 const LocalSurfaceId& local_surface_id) { |
| 125 auto surface = base::MakeUnique<Surface>( | 142 auto surface = base::MakeUnique<Surface>( |
| 126 SurfaceId(frame_sink_id_, local_surface_id), weak_factory_.GetWeakPtr()); | 143 SurfaceId(frame_sink_id_, local_surface_id), weak_factory_.GetWeakPtr()); |
| 127 manager_->RegisterSurface(surface.get()); | 144 manager_->RegisterSurface(surface.get()); |
| 145 // Observe a Surface from the time it's created until it's activated for the |
| 146 // first time. |
| 147 surface->AddObserver(this); |
| 128 return surface; | 148 return surface; |
| 129 } | 149 } |
| 130 | 150 |
| 131 void SurfaceFactory::Destroy(std::unique_ptr<Surface> surface) { | 151 void SurfaceFactory::Destroy(std::unique_ptr<Surface> surface) { |
| 152 surface->RemoveObserver(this); |
| 132 if (manager_) | 153 if (manager_) |
| 133 manager_->Destroy(std::move(surface)); | 154 manager_->Destroy(std::move(surface)); |
| 134 } | 155 } |
| 135 | 156 |
| 136 } // namespace cc | 157 } // namespace cc |
| OLD | NEW |