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/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| 11 #include "cc/output/copy_output_request.h" | 11 #include "cc/output/copy_output_request.h" |
| 12 #include "cc/surfaces/surface.h" | 12 #include "cc/surfaces/surface.h" |
| 13 #include "cc/surfaces/surface_factory_client.h" | 13 #include "cc/surfaces/surface_factory_client.h" |
| 14 #include "cc/surfaces/surface_manager.h" | 14 #include "cc/surfaces/surface_manager.h" |
| 15 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
| 16 | 16 |
| 17 namespace cc { | 17 namespace cc { |
| 18 SurfaceFactory::SurfaceFactory(const FrameSinkId& frame_sink_id, | 18 SurfaceFactory::SurfaceFactory(const FrameSinkId& frame_sink_id, |
| 19 SurfaceManager* manager, | 19 SurfaceManager* manager, |
| 20 SurfaceFactoryClient* client) | 20 SurfaceFactoryClient* client) |
| 21 : frame_sink_id_(frame_sink_id), | 21 : frame_sink_id_(frame_sink_id), |
| 22 manager_(manager), | 22 manager_(manager), |
| 23 client_(client), | 23 client_(client), |
| 24 holder_(client), | 24 holder_(client), |
| 25 needs_sync_points_(true), | 25 needs_sync_points_(true), |
| 26 weak_factory_(this) {} | 26 weak_factory_(this) {} |
| 27 | 27 |
| 28 SurfaceFactory::~SurfaceFactory() { | 28 SurfaceFactory::~SurfaceFactory() { |
| 29 if (!surface_map_.empty()) { | |
|
danakj
2016/11/10 23:57:58
Can we enforce this still?
Fady Samuel
2016/11/11 00:03:01
Why? What does that solve? This CL eliminates expl
danakj
2016/11/11 00:10:47
Cuz this is why there's all the null checks unless
Saman Sami
2016/11/11 17:49:58
I got rid of the null checks. I still don't have t
| |
| 30 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() | |
| 31 << " entries in map on destruction."; | |
| 32 } | |
| 33 DestroyAll(); | 29 DestroyAll(); |
| 34 } | 30 } |
| 35 | 31 |
| 36 void SurfaceFactory::DestroyAll() { | 32 void SurfaceFactory::DestroyAll() { |
| 37 if (manager_) { | 33 if (manager_) { |
| 38 for (auto& pair : surface_map_) | 34 for (auto& pair : surface_map_) |
| 39 manager_->Destroy(std::move(pair.second)); | 35 manager_->Destroy(std::move(pair.second)); |
| 40 } | 36 } |
| 41 surface_map_.clear(); | 37 surface_map_.clear(); |
| 38 last_local_frame_id_.reset(); | |
| 42 } | 39 } |
| 43 | 40 |
| 44 void SurfaceFactory::Reset() { | 41 void SurfaceFactory::Reset() { |
| 45 DestroyAll(); | 42 DestroyAll(); |
| 46 // Disown Surfaces that are still alive so that they don't try to unref | 43 // Disown Surfaces that are still alive so that they don't try to unref |
| 47 // resources that we're not tracking any more. | 44 // resources that we're not tracking any more. |
| 48 weak_factory_.InvalidateWeakPtrs(); | 45 weak_factory_.InvalidateWeakPtrs(); |
| 49 holder_.Reset(); | 46 holder_.Reset(); |
| 50 } | 47 } |
| 51 | 48 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 75 manager_->GetSurfaceForId(SurfaceId(frame_sink_id_, old_id)); | 72 manager_->GetSurfaceForId(SurfaceId(frame_sink_id_, old_id)); |
| 76 if (old_surface) { | 73 if (old_surface) { |
| 77 it->second->SetPreviousFrameSurface(old_surface); | 74 it->second->SetPreviousFrameSurface(old_surface); |
| 78 } | 75 } |
| 79 } | 76 } |
| 80 | 77 |
| 81 void SurfaceFactory::SubmitCompositorFrame(const LocalFrameId& local_frame_id, | 78 void SurfaceFactory::SubmitCompositorFrame(const LocalFrameId& local_frame_id, |
| 82 CompositorFrame frame, | 79 CompositorFrame frame, |
| 83 const DrawCallback& callback) { | 80 const DrawCallback& callback) { |
| 84 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); | 81 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); |
| 82 if (!last_local_frame_id_ || local_frame_id != *last_local_frame_id_) { | |
| 83 Create(local_frame_id); | |
| 84 } | |
| 85 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id); | 85 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id); |
| 86 DCHECK(it != surface_map_.end()); | 86 DCHECK(it != surface_map_.end()); |
| 87 DCHECK(it->second->factory().get() == this); | 87 DCHECK(it->second->factory().get() == this); |
| 88 // Tell the SurfaceManager if this is the first frame submitted with this | 88 // Tell the SurfaceManager if this is the first frame submitted with this |
| 89 // LocalFrameId. | 89 // LocalFrameId. |
| 90 if (!it->second->HasFrame()) { | 90 if (!it->second->HasFrame()) { |
| 91 float device_scale_factor = frame.metadata.device_scale_factor; | 91 float device_scale_factor = frame.metadata.device_scale_factor; |
| 92 gfx::Size frame_size; | 92 gfx::Size frame_size; |
| 93 // CompositorFrames may not be populated with a RenderPass in unit tests. | 93 // CompositorFrames may not be populated with a RenderPass in unit tests. |
| 94 if (!frame.render_pass_list.empty()) | 94 if (!frame.render_pass_list.empty()) |
| 95 frame_size = frame.render_pass_list[0]->output_rect.size(); | 95 frame_size = frame.render_pass_list[0]->output_rect.size(); |
| 96 manager_->SurfaceCreated(it->second->surface_id(), frame_size, | 96 manager_->SurfaceCreated(it->second->surface_id(), frame_size, |
| 97 device_scale_factor); | 97 device_scale_factor); |
| 98 } | 98 } |
| 99 it->second->QueueFrame(std::move(frame), callback); | 99 it->second->QueueFrame(std::move(frame), callback); |
| 100 if (!manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id))) { | 100 if (!manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id))) { |
| 101 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); | 101 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); |
| 102 it->second->RunDrawCallbacks(); | 102 it->second->RunDrawCallbacks(); |
| 103 } | 103 } |
| 104 if (last_local_frame_id_ && local_frame_id != *last_local_frame_id_) | |
| 105 Destroy(*last_local_frame_id_); | |
| 106 last_local_frame_id_ = local_frame_id; | |
|
danakj
2016/11/10 23:57:58
instead of last_ maybe this is current_ ? last sou
Saman Sami
2016/11/11 17:49:59
Done.
| |
| 104 } | 107 } |
| 105 | 108 |
| 106 void SurfaceFactory::RequestCopyOfSurface( | 109 void SurfaceFactory::RequestCopyOfSurface( |
| 107 const LocalFrameId& local_frame_id, | 110 const LocalFrameId& local_frame_id, |
| 108 std::unique_ptr<CopyOutputRequest> copy_request) { | 111 std::unique_ptr<CopyOutputRequest> copy_request) { |
| 109 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id); | 112 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id); |
| 110 if (it == surface_map_.end()) { | 113 if (it == surface_map_.end()) { |
| 111 copy_request->SendEmptyResult(); | 114 copy_request->SendEmptyResult(); |
| 112 return; | 115 return; |
| 113 } | 116 } |
| 114 DCHECK(it->second->factory().get() == this); | 117 DCHECK(it->second->factory().get() == this); |
| 115 it->second->RequestCopyOfOutput(std::move(copy_request)); | 118 it->second->RequestCopyOfOutput(std::move(copy_request)); |
| 116 manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id)); | 119 manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id)); |
| 117 } | 120 } |
| 118 | 121 |
| 119 void SurfaceFactory::WillDrawSurface(const LocalFrameId& id, | 122 void SurfaceFactory::WillDrawSurface(const LocalFrameId& id, |
| 120 const gfx::Rect& damage_rect) { | 123 const gfx::Rect& damage_rect) { |
| 121 client_->WillDrawSurface(id, damage_rect); | 124 if (client_) |
|
Fady Samuel
2016/11/10 23:33:37
Is this check necessary?
Saman Sami
2016/11/11 17:49:58
Removed
| |
| 125 client_->WillDrawSurface(id, damage_rect); | |
| 122 } | 126 } |
| 123 | 127 |
| 124 void SurfaceFactory::ReceiveFromChild( | 128 void SurfaceFactory::ReceiveFromChild( |
| 125 const TransferableResourceArray& resources) { | 129 const TransferableResourceArray& resources) { |
| 126 holder_.ReceiveFromChild(resources); | 130 holder_.ReceiveFromChild(resources); |
| 127 } | 131 } |
| 128 | 132 |
| 129 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { | 133 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { |
| 130 holder_.RefResources(resources); | 134 holder_.RefResources(resources); |
| 131 } | 135 } |
| 132 | 136 |
| 133 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { | 137 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { |
| 134 holder_.UnrefResources(resources); | 138 holder_.UnrefResources(resources); |
| 135 } | 139 } |
| 136 | 140 |
| 137 } // namespace cc | 141 } // namespace cc |
| OLD | NEW |