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

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

Issue 2087383002: Fix destruction order between SurfaceManger and OffscreenCanvasSurfaceImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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"
(...skipping 14 matching lines...) Expand all
25 25
26 SurfaceFactory::~SurfaceFactory() { 26 SurfaceFactory::~SurfaceFactory() {
27 if (!surface_map_.empty()) { 27 if (!surface_map_.empty()) {
28 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() 28 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size()
29 << " entries in map on destruction."; 29 << " entries in map on destruction.";
30 } 30 }
31 DestroyAll(); 31 DestroyAll();
32 } 32 }
33 33
34 void SurfaceFactory::DestroyAll() { 34 void SurfaceFactory::DestroyAll() {
35 if (manager_) {
35 for (auto& pair : surface_map_) 36 for (auto& pair : surface_map_)
36 manager_->Destroy(std::move(pair.second)); 37 manager_->Destroy(std::move(pair.second));
38
37 surface_map_.clear(); 39 surface_map_.clear();
40 }
38 } 41 }
39 42
40 void SurfaceFactory::Create(SurfaceId surface_id) { 43 void SurfaceFactory::Create(SurfaceId surface_id) {
41 std::unique_ptr<Surface> surface(new Surface(surface_id, this)); 44 std::unique_ptr<Surface> surface(new Surface(surface_id, this));
42 manager_->RegisterSurface(surface.get()); 45 if (manager_)
46 manager_->RegisterSurface(surface.get());
43 DCHECK(!surface_map_.count(surface_id)); 47 DCHECK(!surface_map_.count(surface_id));
44 surface_map_[surface_id] = std::move(surface); 48 surface_map_[surface_id] = std::move(surface);
45 } 49 }
46 50
47 void SurfaceFactory::Destroy(SurfaceId surface_id) { 51 void SurfaceFactory::Destroy(SurfaceId surface_id) {
48 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); 52 OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
49 DCHECK(it != surface_map_.end()); 53 DCHECK(it != surface_map_.end());
50 DCHECK(it->second->factory().get() == this); 54 DCHECK(it->second->factory().get() == this);
51 std::unique_ptr<Surface> surface(std::move(it->second)); 55 std::unique_ptr<Surface> surface(std::move(it->second));
52 surface_map_.erase(it); 56 surface_map_.erase(it);
53 manager_->Destroy(std::move(surface)); 57 if (manager_)
58 manager_->Destroy(std::move(surface));
54 } 59 }
55 60
56 void SurfaceFactory::SetPreviousFrameSurface(SurfaceId new_id, 61 void SurfaceFactory::SetPreviousFrameSurface(SurfaceId new_id,
57 SurfaceId old_id) { 62 SurfaceId old_id) {
58 OwningSurfaceMap::iterator it = surface_map_.find(new_id); 63 OwningSurfaceMap::iterator it = surface_map_.find(new_id);
59 DCHECK(it != surface_map_.end()); 64 DCHECK(it != surface_map_.end());
60 Surface* old_surface = manager_->GetSurfaceForId(old_id); 65 Surface* old_surface = manager_->GetSurfaceForId(old_id);
Justin Novosad 2016/06/22 20:47:09 Do you need a null check on manager_ here?
xlai (Olivia) 2016/06/23 14:49:38 I don't think we should put manager_ nullity check
61 if (old_surface) { 66 if (old_surface) {
62 it->second->SetPreviousFrameSurface(old_surface); 67 it->second->SetPreviousFrameSurface(old_surface);
63 } 68 }
64 } 69 }
65 70
66 void SurfaceFactory::SetSurfaceGpuMemoryBufferClientId( 71 void SurfaceFactory::SetSurfaceGpuMemoryBufferClientId(
67 SurfaceId surface_id, 72 SurfaceId surface_id,
68 int gpu_memory_buffer_client_id) { 73 int gpu_memory_buffer_client_id) {
69 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); 74 OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
70 DCHECK(it != surface_map_.end()); 75 DCHECK(it != surface_map_.end());
71 it->second->SetGpuMemoryBufferClientId(gpu_memory_buffer_client_id); 76 it->second->SetGpuMemoryBufferClientId(gpu_memory_buffer_client_id);
72 } 77 }
73 78
74 void SurfaceFactory::SubmitCompositorFrame( 79 void SurfaceFactory::SubmitCompositorFrame(
75 SurfaceId surface_id, 80 SurfaceId surface_id,
76 std::unique_ptr<CompositorFrame> frame, 81 std::unique_ptr<CompositorFrame> frame,
77 const DrawCallback& callback) { 82 const DrawCallback& callback) {
78 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); 83 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame");
79 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); 84 OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
80 DCHECK(it != surface_map_.end()); 85 DCHECK(it != surface_map_.end());
81 DCHECK(it->second->factory().get() == this); 86 DCHECK(it->second->factory().get() == this);
82 it->second->QueueFrame(std::move(frame), callback); 87 it->second->QueueFrame(std::move(frame), callback);
83 if (!manager_->SurfaceModified(surface_id)) { 88 if (!manager_->SurfaceModified(surface_id)) {
Justin Novosad 2016/06/22 20:47:09 and here
84 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); 89 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD);
85 it->second->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED); 90 it->second->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED);
86 } 91 }
87 } 92 }
88 93
89 void SurfaceFactory::RequestCopyOfSurface( 94 void SurfaceFactory::RequestCopyOfSurface(
90 SurfaceId surface_id, 95 SurfaceId surface_id,
91 std::unique_ptr<CopyOutputRequest> copy_request) { 96 std::unique_ptr<CopyOutputRequest> copy_request) {
92 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); 97 OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
93 if (it == surface_map_.end()) { 98 if (it == surface_map_.end()) {
94 copy_request->SendEmptyResult(); 99 copy_request->SendEmptyResult();
95 return; 100 return;
96 } 101 }
97 DCHECK(it->second->factory().get() == this); 102 DCHECK(it->second->factory().get() == this);
98 it->second->RequestCopyOfOutput(std::move(copy_request)); 103 it->second->RequestCopyOfOutput(std::move(copy_request));
99 manager_->SurfaceModified(surface_id); 104 manager_->SurfaceModified(surface_id);
Justin Novosad 2016/06/22 20:47:09 and here?
100 } 105 }
101 106
102 void SurfaceFactory::WillDrawSurface(SurfaceId id, 107 void SurfaceFactory::WillDrawSurface(SurfaceId id,
103 const gfx::Rect& damage_rect) { 108 const gfx::Rect& damage_rect) {
104 client_->WillDrawSurface(id, damage_rect); 109 client_->WillDrawSurface(id, damage_rect);
105 } 110 }
106 111
107 void SurfaceFactory::ReceiveFromChild( 112 void SurfaceFactory::ReceiveFromChild(
108 const TransferableResourceArray& resources) { 113 const TransferableResourceArray& resources) {
109 holder_.ReceiveFromChild(resources); 114 holder_.ReceiveFromChild(resources);
110 } 115 }
111 116
112 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { 117 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) {
113 holder_.RefResources(resources); 118 holder_.RefResources(resources);
114 } 119 }
115 120
116 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { 121 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) {
117 holder_.UnrefResources(resources); 122 holder_.UnrefResources(resources);
118 } 123 }
119 124
120 } // namespace cc 125 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698