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_factory_client.h" |
12 #include "cc/surfaces/surface_manager.h" | 12 #include "cc/surfaces/surface_manager.h" |
13 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
14 | 14 |
15 namespace cc { | 15 namespace cc { |
16 SurfaceFactory::SurfaceFactory(SurfaceManager* manager, | 16 SurfaceFactory::SurfaceFactory(SurfaceManager* manager, |
17 SurfaceFactoryClient* client) | 17 SurfaceFactoryClient* client) |
18 : manager_(manager), | 18 : manager_(manager), |
19 client_(client), | 19 client_(client), |
20 holder_(client), | 20 holder_(client), |
21 needs_sync_points_(true) { | 21 needs_sync_points_(true) { |
22 } | 22 } |
23 | 23 |
24 SurfaceFactory::~SurfaceFactory() { | 24 SurfaceFactory::~SurfaceFactory() { |
25 if (!surface_map_.empty()) { | 25 if (!surface_map_.empty()) { |
26 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() | 26 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() |
27 << " entries in map on destruction."; | 27 << " entries in map on destruction."; |
28 } | 28 } |
29 DestroyAll(); | 29 DestroyAll(); |
| 30 client_->SetBeginFrameSource(SurfaceId(), nullptr); |
30 } | 31 } |
31 | 32 |
32 void SurfaceFactory::DestroyAll() { | 33 void SurfaceFactory::DestroyAll() { |
33 for (auto it = surface_map_.begin(); it != surface_map_.end(); ++it) | 34 for (auto it = surface_map_.begin(); it != surface_map_.end(); ++it) |
34 manager_->Destroy(surface_map_.take(it)); | 35 manager_->Destroy(surface_map_.take(it)); |
35 surface_map_.clear(); | 36 surface_map_.clear(); |
36 } | 37 } |
37 | 38 |
38 void SurfaceFactory::Create(SurfaceId surface_id) { | 39 void SurfaceFactory::Create(SurfaceId surface_id) { |
39 scoped_ptr<Surface> surface(new Surface(surface_id, this)); | 40 scoped_ptr<Surface> surface(new Surface(surface_id, this)); |
40 manager_->RegisterSurface(surface.get()); | 41 manager_->RegisterSurface(surface.get()); |
41 DCHECK(!surface_map_.count(surface_id)); | 42 DCHECK(!surface_map_.count(surface_id)); |
42 surface_map_.add(surface_id, surface.Pass()); | 43 surface_map_.add(surface_id, surface.Pass()); |
43 } | 44 } |
44 | 45 |
45 void SurfaceFactory::Destroy(SurfaceId surface_id) { | 46 void SurfaceFactory::Destroy(SurfaceId surface_id) { |
46 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | 47 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); |
47 DCHECK(it != surface_map_.end()); | 48 DCHECK(it != surface_map_.end()); |
48 DCHECK(it->second->factory().get() == this); | 49 DCHECK(it->second->factory().get() == this); |
49 manager_->Destroy(surface_map_.take_and_erase(it)); | 50 manager_->Destroy(surface_map_.take_and_erase(it)); |
50 } | 51 } |
51 | 52 |
| 53 void SurfaceFactory::SetBeginFrameSource(SurfaceId surface_id, |
| 54 BeginFrameSource* begin_frame_source) { |
| 55 client_->SetBeginFrameSource(surface_id, begin_frame_source); |
| 56 } |
| 57 |
52 void SurfaceFactory::SubmitCompositorFrame(SurfaceId surface_id, | 58 void SurfaceFactory::SubmitCompositorFrame(SurfaceId surface_id, |
53 scoped_ptr<CompositorFrame> frame, | 59 scoped_ptr<CompositorFrame> frame, |
54 const DrawCallback& callback) { | 60 const DrawCallback& callback) { |
55 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); | 61 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); |
56 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | 62 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); |
57 DCHECK(it != surface_map_.end()); | 63 DCHECK(it != surface_map_.end()); |
58 DCHECK(it->second->factory().get() == this); | 64 DCHECK(it->second->factory().get() == this); |
59 it->second->QueueFrame(frame.Pass(), callback); | 65 it->second->QueueFrame(frame.Pass(), callback); |
60 if (!manager_->SurfaceModified(surface_id)) { | 66 if (!manager_->SurfaceModified(surface_id)) { |
61 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); | 67 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); |
(...skipping 26 matching lines...) Expand all Loading... |
88 | 94 |
89 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { | 95 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { |
90 holder_.RefResources(resources); | 96 holder_.RefResources(resources); |
91 } | 97 } |
92 | 98 |
93 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { | 99 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { |
94 holder_.UnrefResources(resources); | 100 holder_.UnrefResources(resources); |
95 } | 101 } |
96 | 102 |
97 } // namespace cc | 103 } // namespace cc |
OLD | NEW |