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

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

Issue 2485473003: Remove SurfaceFactory::Create and SurfaceFactory::Destroy (Closed)
Patch Set: up 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()) {
30 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size()
31 << " entries in map on destruction.";
32 }
33 DestroyAll(); 29 DestroyAll();
34 } 30 }
35 31
36 void SurfaceFactory::DestroyAll() { 32 void SurfaceFactory::DestroyAll() {
37 if (manager_) { 33 if (manager_) {
38 for (auto& pair : surface_map_) 34 for (auto& pair : surface_map_)
39 manager_->Destroy(std::move(pair.second)); 35 manager_->Destroy(std::move(pair.second));
40 } 36 }
41 surface_map_.clear(); 37 surface_map_.clear();
38 last_local_frame_id_ = LocalFrameId();
42 } 39 }
43 40
44 void SurfaceFactory::Reset() { 41 void SurfaceFactory::Reset() {
45 DestroyAll(); 42 DestroyAll();
46 // Disown Surfaces that are still alive so that they don't try to unref 43 // Disown Surfaces that are still alive so that they don't try to unref
47 // resources that we're not tracking any more. 44 // resources that we're not tracking any more.
48 weak_factory_.InvalidateWeakPtrs(); 45 weak_factory_.InvalidateWeakPtrs();
49 holder_.Reset(); 46 holder_.Reset();
50 } 47 }
51 48
(...skipping 23 matching lines...) Expand all
75 manager_->GetSurfaceForId(SurfaceId(frame_sink_id_, old_id)); 72 manager_->GetSurfaceForId(SurfaceId(frame_sink_id_, old_id));
76 if (old_surface) { 73 if (old_surface) {
77 it->second->SetPreviousFrameSurface(old_surface); 74 it->second->SetPreviousFrameSurface(old_surface);
78 } 75 }
79 } 76 }
80 77
81 void SurfaceFactory::SubmitCompositorFrame(const LocalFrameId& local_frame_id, 78 void SurfaceFactory::SubmitCompositorFrame(const LocalFrameId& local_frame_id,
82 CompositorFrame frame, 79 CompositorFrame frame,
83 const DrawCallback& callback) { 80 const DrawCallback& callback) {
84 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); 81 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame");
82 if (local_frame_id != last_local_frame_id_) {
83 if (!last_local_frame_id_.is_null())
84 Destroy(last_local_frame_id_);
85 Create(local_frame_id);
86 }
87 last_local_frame_id_ = local_frame_id;
85 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id); 88 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id);
86 DCHECK(it != surface_map_.end()); 89 DCHECK(it != surface_map_.end());
87 DCHECK(it->second->factory().get() == this); 90 DCHECK(it->second->factory().get() == this);
88 // Tell the SurfaceManager if this is the first frame submitted with this 91 // Tell the SurfaceManager if this is the first frame submitted with this
89 // LocalFrameId. 92 // LocalFrameId.
90 if (!it->second->HasFrame()) { 93 if (!it->second->HasFrame()) {
91 float device_scale_factor = frame.metadata.device_scale_factor; 94 float device_scale_factor = frame.metadata.device_scale_factor;
92 gfx::Size frame_size; 95 gfx::Size frame_size;
93 // CompositorFrames may not be populated with a RenderPass in unit tests. 96 // CompositorFrames may not be populated with a RenderPass in unit tests.
94 if (!frame.render_pass_list.empty()) 97 if (!frame.render_pass_list.empty())
(...skipping 16 matching lines...) Expand all
111 copy_request->SendEmptyResult(); 114 copy_request->SendEmptyResult();
112 return; 115 return;
113 } 116 }
114 DCHECK(it->second->factory().get() == this); 117 DCHECK(it->second->factory().get() == this);
115 it->second->RequestCopyOfOutput(std::move(copy_request)); 118 it->second->RequestCopyOfOutput(std::move(copy_request));
116 manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id)); 119 manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id));
117 } 120 }
118 121
119 void SurfaceFactory::WillDrawSurface(const LocalFrameId& id, 122 void SurfaceFactory::WillDrawSurface(const LocalFrameId& id,
120 const gfx::Rect& damage_rect) { 123 const gfx::Rect& damage_rect) {
121 client_->WillDrawSurface(id, damage_rect); 124 if (client_)
Fady Samuel 2016/11/08 22:23:59 Is this necessary?
Saman Sami 2016/11/11 17:49:58 Removed
125 client_->WillDrawSurface(id, damage_rect);
122 } 126 }
123 127
124 void SurfaceFactory::ReceiveFromChild( 128 void SurfaceFactory::ReceiveFromChild(
125 const TransferableResourceArray& resources) { 129 const TransferableResourceArray& resources) {
126 holder_.ReceiveFromChild(resources); 130 holder_.ReceiveFromChild(resources);
127 } 131 }
128 132
129 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { 133 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) {
130 holder_.RefResources(resources); 134 holder_.RefResources(resources);
131 } 135 }
132 136
133 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { 137 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) {
134 holder_.UnrefResources(resources); 138 holder_.UnrefResources(resources);
135 } 139 }
136 140
137 } // namespace cc 141 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698