Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: cc/surfaces/surface_factory.cc

Issue 2383373002: Reduce SurfaceIdAllocator usage and tie SurfaceFactory to a single FrameSinkId (Closed)
Patch Set: Rebased Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/surfaces/surface_factory.h ('k') | cc/surfaces/surface_factory_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(SurfaceManager* manager, 18 SurfaceFactory::SurfaceFactory(const FrameSinkId& frame_sink_id,
19 SurfaceManager* manager,
19 SurfaceFactoryClient* client) 20 SurfaceFactoryClient* client)
20 : manager_(manager), 21 : frame_sink_id_(frame_sink_id),
22 manager_(manager),
21 client_(client), 23 client_(client),
22 holder_(client), 24 holder_(client),
23 needs_sync_points_(true) { 25 needs_sync_points_(true) {}
24 }
25 26
26 SurfaceFactory::~SurfaceFactory() { 27 SurfaceFactory::~SurfaceFactory() {
27 if (!surface_map_.empty()) { 28 if (!surface_map_.empty()) {
28 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() 29 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size()
29 << " entries in map on destruction."; 30 << " entries in map on destruction.";
30 } 31 }
31 DestroyAll(); 32 DestroyAll();
32 } 33 }
33 34
34 void SurfaceFactory::DestroyAll() { 35 void SurfaceFactory::DestroyAll() {
35 if (manager_) { 36 if (manager_) {
36 for (auto& pair : surface_map_) 37 for (auto& pair : surface_map_)
37 manager_->Destroy(std::move(pair.second)); 38 manager_->Destroy(std::move(pair.second));
38 } 39 }
39 surface_map_.clear(); 40 surface_map_.clear();
40 } 41 }
41 42
42 void SurfaceFactory::Create(const SurfaceId& surface_id) { 43 void SurfaceFactory::Create(const SurfaceId& surface_id) {
44 DCHECK(surface_id.frame_sink_id() == frame_sink_id_);
43 std::unique_ptr<Surface> surface(new Surface(surface_id, this)); 45 std::unique_ptr<Surface> surface(new Surface(surface_id, this));
44 manager_->RegisterSurface(surface.get()); 46 manager_->RegisterSurface(surface.get());
45 DCHECK(!surface_map_.count(surface_id)); 47 DCHECK(!surface_map_.count(surface_id));
46 surface_map_[surface_id] = std::move(surface); 48 surface_map_[surface_id] = std::move(surface);
47 } 49 }
48 50
49 void SurfaceFactory::Destroy(const SurfaceId& surface_id) { 51 void SurfaceFactory::Destroy(const SurfaceId& surface_id) {
52 DCHECK(surface_id.frame_sink_id() == frame_sink_id_);
50 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); 53 OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
51 DCHECK(it != surface_map_.end()); 54 DCHECK(it != surface_map_.end());
52 DCHECK(it->second->factory().get() == this); 55 DCHECK(it->second->factory().get() == this);
53 std::unique_ptr<Surface> surface(std::move(it->second)); 56 std::unique_ptr<Surface> surface(std::move(it->second));
54 surface_map_.erase(it); 57 surface_map_.erase(it);
55 if (manager_) 58 if (manager_)
56 manager_->Destroy(std::move(surface)); 59 manager_->Destroy(std::move(surface));
57 } 60 }
58 61
59 void SurfaceFactory::SetPreviousFrameSurface(const SurfaceId& new_id, 62 void SurfaceFactory::SetPreviousFrameSurface(const SurfaceId& new_id,
60 const SurfaceId& old_id) { 63 const SurfaceId& old_id) {
64 DCHECK(new_id.frame_sink_id() == frame_sink_id_);
65 DCHECK(old_id.frame_sink_id() == frame_sink_id_);
61 OwningSurfaceMap::iterator it = surface_map_.find(new_id); 66 OwningSurfaceMap::iterator it = surface_map_.find(new_id);
62 DCHECK(it != surface_map_.end()); 67 DCHECK(it != surface_map_.end());
63 Surface* old_surface = manager_->GetSurfaceForId(old_id); 68 Surface* old_surface = manager_->GetSurfaceForId(old_id);
64 if (old_surface) { 69 if (old_surface) {
65 it->second->SetPreviousFrameSurface(old_surface); 70 it->second->SetPreviousFrameSurface(old_surface);
66 } 71 }
67 } 72 }
68 73
69 void SurfaceFactory::SubmitCompositorFrame(const SurfaceId& surface_id, 74 void SurfaceFactory::SubmitCompositorFrame(const SurfaceId& surface_id,
70 CompositorFrame frame, 75 CompositorFrame frame,
71 const DrawCallback& callback) { 76 const DrawCallback& callback) {
72 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); 77 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame");
78 DCHECK(surface_id.frame_sink_id() == frame_sink_id_);
73 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); 79 OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
74 DCHECK(it != surface_map_.end()); 80 DCHECK(it != surface_map_.end());
75 DCHECK(it->second->factory().get() == this); 81 DCHECK(it->second->factory().get() == this);
76 it->second->QueueFrame(std::move(frame), callback); 82 it->second->QueueFrame(std::move(frame), callback);
77 if (!manager_->SurfaceModified(surface_id)) { 83 if (!manager_->SurfaceModified(surface_id)) {
78 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); 84 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD);
79 it->second->RunDrawCallbacks(); 85 it->second->RunDrawCallbacks();
80 } 86 }
81 } 87 }
82 88
83 void SurfaceFactory::RequestCopyOfSurface( 89 void SurfaceFactory::RequestCopyOfSurface(
84 const SurfaceId& surface_id, 90 const SurfaceId& surface_id,
85 std::unique_ptr<CopyOutputRequest> copy_request) { 91 std::unique_ptr<CopyOutputRequest> copy_request) {
92 DCHECK(surface_id.frame_sink_id() == frame_sink_id_);
86 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); 93 OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
87 if (it == surface_map_.end()) { 94 if (it == surface_map_.end()) {
88 copy_request->SendEmptyResult(); 95 copy_request->SendEmptyResult();
89 return; 96 return;
90 } 97 }
91 DCHECK(it->second->factory().get() == this); 98 DCHECK(it->second->factory().get() == this);
92 it->second->RequestCopyOfOutput(std::move(copy_request)); 99 it->second->RequestCopyOfOutput(std::move(copy_request));
93 manager_->SurfaceModified(surface_id); 100 manager_->SurfaceModified(surface_id);
94 } 101 }
95 102
96 void SurfaceFactory::WillDrawSurface(const SurfaceId& id, 103 void SurfaceFactory::WillDrawSurface(const SurfaceId& id,
97 const gfx::Rect& damage_rect) { 104 const gfx::Rect& damage_rect) {
105 DCHECK(id.frame_sink_id() == frame_sink_id_);
98 client_->WillDrawSurface(id, damage_rect); 106 client_->WillDrawSurface(id, damage_rect);
99 } 107 }
100 108
101 void SurfaceFactory::ReceiveFromChild( 109 void SurfaceFactory::ReceiveFromChild(
102 const TransferableResourceArray& resources) { 110 const TransferableResourceArray& resources) {
103 holder_.ReceiveFromChild(resources); 111 holder_.ReceiveFromChild(resources);
104 } 112 }
105 113
106 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { 114 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) {
107 holder_.RefResources(resources); 115 holder_.RefResources(resources);
108 } 116 }
109 117
110 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { 118 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) {
111 holder_.UnrefResources(resources); 119 holder_.UnrefResources(resources);
112 } 120 }
113 121
114 } // namespace cc 122 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_factory.h ('k') | cc/surfaces/surface_factory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698