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 "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
| 8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
| 9 #include "cc/output/copy_output_request.h" | 9 #include "cc/output/copy_output_request.h" |
| 10 #include "cc/surfaces/surface.h" | 10 #include "cc/surfaces/surface.h" |
| 11 #include "cc/surfaces/surface_factory_client.h" | |
| 11 #include "cc/surfaces/surface_manager.h" | 12 #include "cc/surfaces/surface_manager.h" |
| 12 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
| 13 | 14 |
| 14 namespace cc { | 15 namespace cc { |
| 15 SurfaceFactory::SurfaceFactory(SurfaceManager* manager, | 16 SurfaceFactory::SurfaceFactory(SurfaceManager* manager, |
| 16 SurfaceFactoryClient* client) | 17 SurfaceFactoryClient* client) |
| 17 : manager_(manager), | 18 : manager_(manager), |
| 18 client_(client), | 19 client_(client), |
| 19 holder_(client), | 20 holder_(client), |
| 20 needs_sync_points_(true) { | 21 needs_sync_points_(true) { |
| 21 } | 22 } |
| 22 | 23 |
| 23 SurfaceFactory::~SurfaceFactory() { | 24 SurfaceFactory::~SurfaceFactory() { |
| 24 if (!surface_map_.empty()) { | 25 if (!surface_map_.empty()) { |
| 25 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() | 26 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() |
| 26 << " entries in map on destruction."; | 27 << " entries in map on destruction."; |
| 27 } | 28 } |
| 28 DestroyAll(); | 29 DestroyAll(); |
| 30 client_->SetBeginFrameSource(nullptr); | |
| 29 } | 31 } |
| 30 | 32 |
| 31 void SurfaceFactory::DestroyAll() { | 33 void SurfaceFactory::DestroyAll() { |
| 32 for (auto it = surface_map_.begin(); it != surface_map_.end(); ++it) | 34 for (auto it = surface_map_.begin(); it != surface_map_.end(); ++it) |
| 33 manager_->Destroy(surface_map_.take(it)); | 35 manager_->Destroy(surface_map_.take(it)); |
| 34 surface_map_.clear(); | 36 surface_map_.clear(); |
| 35 } | 37 } |
| 36 | 38 |
| 37 void SurfaceFactory::Create(SurfaceId surface_id) { | 39 void SurfaceFactory::Create(SurfaceId surface_id) { |
| 38 scoped_ptr<Surface> surface(new Surface(surface_id, this)); | 40 scoped_ptr<Surface> surface(new Surface(surface_id, this)); |
| 39 manager_->RegisterSurface(surface.get()); | 41 manager_->RegisterSurface(surface.get()); |
| 40 DCHECK(!surface_map_.count(surface_id)); | 42 DCHECK(!surface_map_.count(surface_id)); |
| 41 surface_map_.add(surface_id, surface.Pass()); | 43 surface_map_.add(surface_id, surface.Pass()); |
| 44 most_recently_created_surface_id_ = surface_id; | |
| 42 } | 45 } |
| 43 | 46 |
| 44 void SurfaceFactory::Destroy(SurfaceId surface_id) { | 47 void SurfaceFactory::Destroy(SurfaceId surface_id) { |
| 45 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | 48 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); |
| 46 DCHECK(it != surface_map_.end()); | 49 DCHECK(it != surface_map_.end()); |
| 47 DCHECK(it->second->factory().get() == this); | 50 DCHECK(it->second->factory().get() == this); |
| 48 manager_->Destroy(surface_map_.take_and_erase(it)); | 51 manager_->Destroy(surface_map_.take_and_erase(it)); |
| 49 } | 52 } |
| 50 | 53 |
| 54 void SurfaceFactory::SetBeginFrameSource(SurfaceId surface_id, | |
| 55 BeginFrameSource* begin_frame_source) { | |
| 56 // There may be multiple live surfaces associated with this SurfaceFactory, | |
| 57 // so we need to have a single source of truth to make a stable decision | |
| 58 // regarding which BeginFrameSource to use here. | |
| 59 if (most_recently_created_surface_id_ != surface_id) | |
| 60 return; | |
| 61 | |
| 62 client_->SetBeginFrameSource(begin_frame_source); | |
|
jbauman
2015/10/02 19:21:40
I'd prefer to pass the SurfaceId to the client and
brianderson
2015/10/07 20:54:49
Done.
| |
| 63 } | |
| 64 | |
| 51 void SurfaceFactory::SubmitCompositorFrame(SurfaceId surface_id, | 65 void SurfaceFactory::SubmitCompositorFrame(SurfaceId surface_id, |
| 52 scoped_ptr<CompositorFrame> frame, | 66 scoped_ptr<CompositorFrame> frame, |
| 53 const DrawCallback& callback) { | 67 const DrawCallback& callback) { |
| 54 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); | 68 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); |
| 55 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | 69 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); |
| 56 DCHECK(it != surface_map_.end()); | 70 DCHECK(it != surface_map_.end()); |
| 57 DCHECK(it->second->factory().get() == this); | 71 DCHECK(it->second->factory().get() == this); |
| 58 it->second->QueueFrame(frame.Pass(), callback); | 72 it->second->QueueFrame(frame.Pass(), callback); |
| 59 if (!manager_->SurfaceModified(surface_id)) { | 73 if (!manager_->SurfaceModified(surface_id)) { |
| 60 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); | 74 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 82 | 96 |
| 83 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { | 97 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { |
| 84 holder_.RefResources(resources); | 98 holder_.RefResources(resources); |
| 85 } | 99 } |
| 86 | 100 |
| 87 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { | 101 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { |
| 88 holder_.UnrefResources(resources); | 102 holder_.UnrefResources(resources); |
| 89 } | 103 } |
| 90 | 104 |
| 91 } // namespace cc | 105 } // namespace cc |
| OLD | NEW |