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

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

Issue 2485473003: Remove SurfaceFactory::Create and SurfaceFactory::Destroy (Closed)
Patch Set: more evict Created 4 years, 1 month 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"
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(const FrameSinkId& frame_sink_id, 18 SurfaceFactory::SurfaceFactory(const FrameSinkId& frame_sink_id,
19 SurfaceManager* manager, 19 SurfaceManager* manager,
20 SurfaceFactoryClient* client) 20 SurfaceFactoryClient* client)
21 : frame_sink_id_(frame_sink_id), 21 : frame_sink_id_(frame_sink_id),
22 manager_(manager), 22 manager_(manager),
23 client_(client), 23 client_(client),
24 holder_(client), 24 holder_(client),
25 needs_sync_points_(true), 25 needs_sync_points_(true),
26 weak_factory_(this) {} 26 weak_factory_(this) {}
27 27
28 SurfaceFactory::~SurfaceFactory() { 28 SurfaceFactory::~SurfaceFactory() {
29 if (!surface_map_.empty()) { 29 EvictFrame();
danakj 2016/11/12 00:27:21 Is there a reason to support having a surface here
30 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size()
31 << " entries in map on destruction.";
32 }
33 DestroyAll();
34 } 30 }
35 31
36 void SurfaceFactory::DestroyAll() { 32 void SurfaceFactory::EvictFrame() {
37 if (manager_) { 33 if (!current_surface_)
38 for (auto& pair : surface_map_) 34 return;
39 manager_->Destroy(std::move(pair.second)); 35 if (manager_)
40 } 36 manager_->Destroy(std::move(current_surface_));
41 surface_map_.clear(); 37 current_surface_.reset();
42 } 38 }
43 39
44 void SurfaceFactory::Reset() { 40 void SurfaceFactory::Reset() {
45 DestroyAll(); 41 EvictFrame();
46 // Disown Surfaces that are still alive so that they don't try to unref 42 // Disown Surfaces that are still alive so that they don't try to unref
47 // resources that we're not tracking any more. 43 // resources that we're not tracking any more.
48 weak_factory_.InvalidateWeakPtrs(); 44 weak_factory_.InvalidateWeakPtrs();
49 holder_.Reset(); 45 holder_.Reset();
50 } 46 }
51 47
52 void SurfaceFactory::Create(const LocalFrameId& local_frame_id) {
53 auto surface(base::MakeUnique<Surface>(
54 SurfaceId(frame_sink_id_, local_frame_id), weak_factory_.GetWeakPtr()));
55 manager_->RegisterSurface(surface.get());
56 DCHECK(!surface_map_.count(local_frame_id));
57 surface_map_[local_frame_id] = std::move(surface);
58 }
59
60 void SurfaceFactory::Destroy(const LocalFrameId& local_frame_id) {
61 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id);
62 DCHECK(it != surface_map_.end());
63 DCHECK(it->second->factory().get() == this);
64 std::unique_ptr<Surface> surface(std::move(it->second));
65 surface_map_.erase(it);
66 if (manager_)
67 manager_->Destroy(std::move(surface));
68 }
69
70 void SurfaceFactory::SetPreviousFrameSurface(const LocalFrameId& new_id,
71 const LocalFrameId& old_id) {
72 OwningSurfaceMap::iterator it = surface_map_.find(new_id);
73 DCHECK(it != surface_map_.end());
74 Surface* old_surface =
75 manager_->GetSurfaceForId(SurfaceId(frame_sink_id_, old_id));
76 if (old_surface) {
77 it->second->SetPreviousFrameSurface(old_surface);
78 }
79 }
80
81 void SurfaceFactory::SubmitCompositorFrame(const LocalFrameId& local_frame_id, 48 void SurfaceFactory::SubmitCompositorFrame(const LocalFrameId& local_frame_id,
82 CompositorFrame frame, 49 CompositorFrame frame,
83 const DrawCallback& callback) { 50 const DrawCallback& callback) {
84 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); 51 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame");
85 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id); 52 DCHECK(local_frame_id.is_valid());
86 DCHECK(it != surface_map_.end()); 53 std::unique_ptr<Surface> surface;
87 DCHECK(it->second->factory().get() == this); 54 bool create_new_surface =
55 (!current_surface_ ||
56 local_frame_id != current_surface_->surface_id().local_frame_id());
57 if (create_new_surface)
58 surface = Create(local_frame_id);
59 else
60 surface = std::move(current_surface_);
88 // Tell the SurfaceManager if this is the first frame submitted with this 61 // Tell the SurfaceManager if this is the first frame submitted with this
89 // LocalFrameId. 62 // LocalFrameId.
90 if (!it->second->HasFrame()) { 63 if (!surface->HasFrame()) {
91 float device_scale_factor = frame.metadata.device_scale_factor; 64 float device_scale_factor = frame.metadata.device_scale_factor;
92 gfx::Size frame_size; 65 gfx::Size frame_size;
93 // CompositorFrames may not be populated with a RenderPass in unit tests. 66 // CompositorFrames may not be populated with a RenderPass in unit tests.
94 if (!frame.render_pass_list.empty()) 67 if (!frame.render_pass_list.empty())
95 frame_size = frame.render_pass_list[0]->output_rect.size(); 68 frame_size = frame.render_pass_list[0]->output_rect.size();
96 manager_->SurfaceCreated(it->second->surface_id(), frame_size, 69 manager_->SurfaceCreated(surface->surface_id(), frame_size,
97 device_scale_factor); 70 device_scale_factor);
98 } 71 }
99 it->second->QueueFrame(std::move(frame), callback); 72 surface->QueueFrame(std::move(frame), callback);
100 if (!manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id))) { 73 if (!manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id))) {
101 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); 74 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD);
102 it->second->RunDrawCallbacks(); 75 surface->RunDrawCallbacks();
103 } 76 }
77 if (current_surface_ && create_new_surface) {
78 surface->SetPreviousFrameSurface(current_surface_.get());
piman 2016/11/12 00:19:10 I think doing this implicitly makes sense, but I'm
danakj 2016/11/12 00:27:21 Should on linux with --disable-gpu
79 Destroy(std::move(current_surface_));
80 }
81 current_surface_ = std::move(surface);
104 } 82 }
105 83
106 void SurfaceFactory::RequestCopyOfSurface( 84 void SurfaceFactory::RequestCopyOfSurface(
107 const LocalFrameId& local_frame_id,
108 std::unique_ptr<CopyOutputRequest> copy_request) { 85 std::unique_ptr<CopyOutputRequest> copy_request) {
109 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id); 86 if (!current_surface_) {
110 if (it == surface_map_.end()) {
111 copy_request->SendEmptyResult(); 87 copy_request->SendEmptyResult();
112 return; 88 return;
113 } 89 }
114 DCHECK(it->second->factory().get() == this); 90 DCHECK(current_surface_->factory().get() == this);
115 it->second->RequestCopyOfOutput(std::move(copy_request)); 91 current_surface_->RequestCopyOfOutput(std::move(copy_request));
116 manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id)); 92 manager_->SurfaceModified(current_surface_->surface_id());
117 } 93 }
118 94
119 void SurfaceFactory::WillDrawSurface(const LocalFrameId& id, 95 void SurfaceFactory::WillDrawSurface(const LocalFrameId& id,
120 const gfx::Rect& damage_rect) { 96 const gfx::Rect& damage_rect) {
121 client_->WillDrawSurface(id, damage_rect); 97 client_->WillDrawSurface(id, damage_rect);
122 } 98 }
123 99
124 void SurfaceFactory::ReceiveFromChild( 100 void SurfaceFactory::ReceiveFromChild(
125 const TransferableResourceArray& resources) { 101 const TransferableResourceArray& resources) {
126 holder_.ReceiveFromChild(resources); 102 holder_.ReceiveFromChild(resources);
127 } 103 }
128 104
129 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { 105 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) {
130 holder_.RefResources(resources); 106 holder_.RefResources(resources);
131 } 107 }
132 108
133 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { 109 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) {
134 holder_.UnrefResources(resources); 110 holder_.UnrefResources(resources);
135 } 111 }
136 112
113 std::unique_ptr<Surface> SurfaceFactory::Create(
114 const LocalFrameId& local_frame_id) {
115 auto surface = base::MakeUnique<Surface>(
116 SurfaceId(frame_sink_id_, local_frame_id), weak_factory_.GetWeakPtr());
117 manager_->RegisterSurface(surface.get());
118 return surface;
119 }
120
121 void SurfaceFactory::Destroy(std::unique_ptr<Surface> surface) {
122 if (manager_)
danakj 2016/11/12 00:27:21 I'm confused by the if (manager_) checks sometimes
Saman Sami 2016/11/14 23:39:01 I have no idea. I didn't write this. We can get ri
danakj 2016/11/15 00:43:40 I would greatly appreciate that we do, unneeded nu
123 manager_->Destroy(std::move(surface));
124 }
125
137 } // namespace cc 126 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698