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 if (most_recently_created_surface_id_ != surface_id) | |
mithro-old
2015/10/01 03:00:24
nit: Can you add a comment about why this check is
brianderson
2015/10/07 20:54:48
Done.
| |
57 return; | |
58 | |
59 client_->SetBeginFrameSource(begin_frame_source); | |
60 } | |
61 | |
51 void SurfaceFactory::SubmitCompositorFrame(SurfaceId surface_id, | 62 void SurfaceFactory::SubmitCompositorFrame(SurfaceId surface_id, |
52 scoped_ptr<CompositorFrame> frame, | 63 scoped_ptr<CompositorFrame> frame, |
53 const DrawCallback& callback) { | 64 const DrawCallback& callback) { |
54 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); | 65 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); |
55 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | 66 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); |
56 DCHECK(it != surface_map_.end()); | 67 DCHECK(it != surface_map_.end()); |
57 DCHECK(it->second->factory().get() == this); | 68 DCHECK(it->second->factory().get() == this); |
58 it->second->QueueFrame(frame.Pass(), callback); | 69 it->second->QueueFrame(frame.Pass(), callback); |
59 if (!manager_->SurfaceModified(surface_id)) { | 70 if (!manager_->SurfaceModified(surface_id)) { |
60 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); | 71 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); |
(...skipping 21 matching lines...) Expand all Loading... | |
82 | 93 |
83 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { | 94 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { |
84 holder_.RefResources(resources); | 95 holder_.RefResources(resources); |
85 } | 96 } |
86 | 97 |
87 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { | 98 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { |
88 holder_.UnrefResources(resources); | 99 holder_.UnrefResources(resources); |
89 } | 100 } |
90 | 101 |
91 } // namespace cc | 102 } // namespace cc |
OLD | NEW |