Chromium Code Reviews| 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 const CompositorFrame& frame = surface->GetActiveFrame(); | |
|
vmpstr
2017/02/07 22:46:20
DCHECK that it hasactiveframe
Fady Samuel
2017/02/08 00:52:50
Done.
| |
| 120 // CompositorFrames may not be populated with a RenderPass in unit tests. | |
|
vmpstr
2017/02/07 22:46:20
nit: this reads like unittests are not allowed to
Fady Samuel
2017/02/08 00:52:50
Done.
| |
| 121 gfx::Size frame_size; | |
| 122 if (!frame.render_pass_list.empty()) | |
| 123 frame_size = frame.render_pass_list.back()->output_rect.size(); | |
| 124 | |
| 125 // SurfaceCreated only applies for the first Surface activation. Thus, | |
| 126 // SurfaceFactory stops observing new activations after the first one. | |
| 127 manager_->SurfaceCreated(SurfaceInfo( | |
| 128 surface->surface_id(), frame.metadata.device_scale_factor, frame_size)); | |
| 129 surface->RemoveObserver(this); | |
|
vmpstr
2017/02/07 22:46:20
Is there a doc describing who observes whom and fo
Fady Samuel
2017/02/08 00:52:50
SurfaceFactory is going away soon, but SurfaceDepe
| |
| 130 } | |
| 131 | |
| 132 void SurfaceFactory::OnSurfaceChanged( | |
| 133 Surface* pending_surface, | |
| 134 const SurfaceDependencies& added_dependencies, | |
| 135 const SurfaceDependencies& removed_dependencies) {} | |
| 136 | |
| 137 void SurfaceFactory::OnSurfaceDiscarded(Surface* pending_surface) {} | |
| 138 | |
| 123 std::unique_ptr<Surface> SurfaceFactory::Create( | 139 std::unique_ptr<Surface> SurfaceFactory::Create( |
| 124 const LocalSurfaceId& local_surface_id) { | 140 const LocalSurfaceId& local_surface_id) { |
| 125 auto surface = base::MakeUnique<Surface>( | 141 auto surface = base::MakeUnique<Surface>( |
| 126 SurfaceId(frame_sink_id_, local_surface_id), weak_factory_.GetWeakPtr()); | 142 SurfaceId(frame_sink_id_, local_surface_id), weak_factory_.GetWeakPtr()); |
| 127 manager_->RegisterSurface(surface.get()); | 143 manager_->RegisterSurface(surface.get()); |
| 144 // Observe a Surface from the time it's created until it's activated for the | |
| 145 // first time. | |
| 146 surface->AddObserver(this); | |
| 128 return surface; | 147 return surface; |
| 129 } | 148 } |
| 130 | 149 |
| 131 void SurfaceFactory::Destroy(std::unique_ptr<Surface> surface) { | 150 void SurfaceFactory::Destroy(std::unique_ptr<Surface> surface) { |
| 151 surface->RemoveObserver(this); | |
| 132 if (manager_) | 152 if (manager_) |
| 133 manager_->Destroy(std::move(surface)); | 153 manager_->Destroy(std::move(surface)); |
| 134 } | 154 } |
| 135 | 155 |
| 136 } // namespace cc | 156 } // namespace cc |
| OLD | NEW |