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

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

Issue 2485473003: Remove SurfaceFactory::Create and SurfaceFactory::Destroy (Closed)
Patch Set: surface factory test clean 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() {
Fady Samuel 2016/11/11 19:02:20 Rename this to EvictFrame and make public. Btw, i
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 current_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 DCHECK(local_frame_id.is_valid());
83 if (!current_local_frame_id_.is_valid() ||
84 local_frame_id != current_local_frame_id_) {
85 Create(local_frame_id);
86 }
85 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id); 87 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id);
86 DCHECK(it != surface_map_.end()); 88 DCHECK(it != surface_map_.end());
87 DCHECK(it->second->factory().get() == this); 89 DCHECK(it->second->factory().get() == this);
88 // Tell the SurfaceManager if this is the first frame submitted with this 90 // Tell the SurfaceManager if this is the first frame submitted with this
89 // LocalFrameId. 91 // LocalFrameId.
90 if (!it->second->HasFrame()) { 92 if (!it->second->HasFrame()) {
91 float device_scale_factor = frame.metadata.device_scale_factor; 93 float device_scale_factor = frame.metadata.device_scale_factor;
92 gfx::Size frame_size; 94 gfx::Size frame_size;
93 // CompositorFrames may not be populated with a RenderPass in unit tests. 95 // CompositorFrames may not be populated with a RenderPass in unit tests.
94 if (!frame.render_pass_list.empty()) 96 if (!frame.render_pass_list.empty())
95 frame_size = frame.render_pass_list[0]->output_rect.size(); 97 frame_size = frame.render_pass_list[0]->output_rect.size();
96 manager_->SurfaceCreated(it->second->surface_id(), frame_size, 98 manager_->SurfaceCreated(it->second->surface_id(), frame_size,
97 device_scale_factor); 99 device_scale_factor);
98 } 100 }
99 it->second->QueueFrame(std::move(frame), callback); 101 it->second->QueueFrame(std::move(frame), callback);
100 if (!manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id))) { 102 if (!manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id))) {
101 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); 103 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD);
102 it->second->RunDrawCallbacks(); 104 it->second->RunDrawCallbacks();
103 } 105 }
106 if (current_local_frame_id_.is_valid() &&
107 local_frame_id != current_local_frame_id_)
Fady Samuel 2016/11/11 19:02:20 Add braces. Call SetPreviousFrameSurface here befo
108 Destroy(current_local_frame_id_);
109 current_local_frame_id_ = local_frame_id;
104 } 110 }
105 111
106 void SurfaceFactory::RequestCopyOfSurface( 112 void SurfaceFactory::RequestCopyOfSurface(
107 const LocalFrameId& local_frame_id, 113 const LocalFrameId& local_frame_id,
108 std::unique_ptr<CopyOutputRequest> copy_request) { 114 std::unique_ptr<CopyOutputRequest> copy_request) {
109 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id); 115 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id);
110 if (it == surface_map_.end()) { 116 if (it == surface_map_.end()) {
111 copy_request->SendEmptyResult(); 117 copy_request->SendEmptyResult();
112 return; 118 return;
113 } 119 }
(...skipping 14 matching lines...) Expand all
128 134
129 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { 135 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) {
130 holder_.RefResources(resources); 136 holder_.RefResources(resources);
131 } 137 }
132 138
133 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { 139 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) {
134 holder_.UnrefResources(resources); 140 holder_.UnrefResources(resources);
135 } 141 }
136 142
137 } // namespace cc 143 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698