| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 | 33 |
| 34 void SurfaceFactory::DestroyAll() { | 34 void SurfaceFactory::DestroyAll() { |
| 35 if (manager_) { | 35 if (manager_) { |
| 36 for (auto& pair : surface_map_) | 36 for (auto& pair : surface_map_) |
| 37 manager_->Destroy(std::move(pair.second)); | 37 manager_->Destroy(std::move(pair.second)); |
| 38 } | 38 } |
| 39 surface_map_.clear(); | 39 surface_map_.clear(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void SurfaceFactory::Create(SurfaceId surface_id) { | 42 void SurfaceFactory::Create(const SurfaceId& surface_id) { |
| 43 std::unique_ptr<Surface> surface(new Surface(surface_id, this)); | 43 std::unique_ptr<Surface> surface(new Surface(surface_id, this)); |
| 44 manager_->RegisterSurface(surface.get()); | 44 manager_->RegisterSurface(surface.get()); |
| 45 DCHECK(!surface_map_.count(surface_id)); | 45 DCHECK(!surface_map_.count(surface_id)); |
| 46 surface_map_[surface_id] = std::move(surface); | 46 surface_map_[surface_id] = std::move(surface); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void SurfaceFactory::Destroy(SurfaceId surface_id) { | 49 void SurfaceFactory::Destroy(const SurfaceId& surface_id) { |
| 50 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | 50 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); |
| 51 DCHECK(it != surface_map_.end()); | 51 DCHECK(it != surface_map_.end()); |
| 52 DCHECK(it->second->factory().get() == this); | 52 DCHECK(it->second->factory().get() == this); |
| 53 std::unique_ptr<Surface> surface(std::move(it->second)); | 53 std::unique_ptr<Surface> surface(std::move(it->second)); |
| 54 surface_map_.erase(it); | 54 surface_map_.erase(it); |
| 55 if (manager_) | 55 if (manager_) |
| 56 manager_->Destroy(std::move(surface)); | 56 manager_->Destroy(std::move(surface)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void SurfaceFactory::SetPreviousFrameSurface(SurfaceId new_id, | 59 void SurfaceFactory::SetPreviousFrameSurface(const SurfaceId& new_id, |
| 60 SurfaceId old_id) { | 60 const SurfaceId& old_id) { |
| 61 OwningSurfaceMap::iterator it = surface_map_.find(new_id); | 61 OwningSurfaceMap::iterator it = surface_map_.find(new_id); |
| 62 DCHECK(it != surface_map_.end()); | 62 DCHECK(it != surface_map_.end()); |
| 63 Surface* old_surface = manager_->GetSurfaceForId(old_id); | 63 Surface* old_surface = manager_->GetSurfaceForId(old_id); |
| 64 if (old_surface) { | 64 if (old_surface) { |
| 65 it->second->SetPreviousFrameSurface(old_surface); | 65 it->second->SetPreviousFrameSurface(old_surface); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 void SurfaceFactory::SubmitCompositorFrame(SurfaceId surface_id, | 69 void SurfaceFactory::SubmitCompositorFrame(const SurfaceId& surface_id, |
| 70 CompositorFrame frame, | 70 CompositorFrame frame, |
| 71 const DrawCallback& callback) { | 71 const DrawCallback& callback) { |
| 72 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); | 72 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); |
| 73 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | 73 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); |
| 74 DCHECK(it != surface_map_.end()); | 74 DCHECK(it != surface_map_.end()); |
| 75 DCHECK(it->second->factory().get() == this); | 75 DCHECK(it->second->factory().get() == this); |
| 76 it->second->QueueFrame(std::move(frame), callback); | 76 it->second->QueueFrame(std::move(frame), callback); |
| 77 if (!manager_->SurfaceModified(surface_id)) { | 77 if (!manager_->SurfaceModified(surface_id)) { |
| 78 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); | 78 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); |
| 79 it->second->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED); | 79 it->second->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 void SurfaceFactory::RequestCopyOfSurface( | 83 void SurfaceFactory::RequestCopyOfSurface( |
| 84 SurfaceId surface_id, | 84 const SurfaceId& surface_id, |
| 85 std::unique_ptr<CopyOutputRequest> copy_request) { | 85 std::unique_ptr<CopyOutputRequest> copy_request) { |
| 86 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | 86 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); |
| 87 if (it == surface_map_.end()) { | 87 if (it == surface_map_.end()) { |
| 88 copy_request->SendEmptyResult(); | 88 copy_request->SendEmptyResult(); |
| 89 return; | 89 return; |
| 90 } | 90 } |
| 91 DCHECK(it->second->factory().get() == this); | 91 DCHECK(it->second->factory().get() == this); |
| 92 it->second->RequestCopyOfOutput(std::move(copy_request)); | 92 it->second->RequestCopyOfOutput(std::move(copy_request)); |
| 93 manager_->SurfaceModified(surface_id); | 93 manager_->SurfaceModified(surface_id); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void SurfaceFactory::WillDrawSurface(SurfaceId id, | 96 void SurfaceFactory::WillDrawSurface(const SurfaceId& id, |
| 97 const gfx::Rect& damage_rect) { | 97 const gfx::Rect& damage_rect) { |
| 98 client_->WillDrawSurface(id, damage_rect); | 98 client_->WillDrawSurface(id, damage_rect); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void SurfaceFactory::ReceiveFromChild( | 101 void SurfaceFactory::ReceiveFromChild( |
| 102 const TransferableResourceArray& resources) { | 102 const TransferableResourceArray& resources) { |
| 103 holder_.ReceiveFromChild(resources); | 103 holder_.ReceiveFromChild(resources); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { | 106 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { |
| 107 holder_.RefResources(resources); | 107 holder_.RefResources(resources); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { | 110 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { |
| 111 holder_.UnrefResources(resources); | 111 holder_.UnrefResources(resources); |
| 112 } | 112 } |
| 113 | 113 |
| 114 } // namespace cc | 114 } // namespace cc |
| OLD | NEW |