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

Side by Side Diff: cc/test/fake_output_surface.cc

Issue 2151433004: cc: Make LayerTreeHostImpl::SwapBuffers not virtual. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@removedidswap
Patch Set: novirtualswapbuffers: num_draws_ Created 4 years, 5 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/test/fake_output_surface.h ('k') | cc/test/layer_tree_test.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/test/fake_output_surface.h" 5 #include "cc/test/fake_output_surface.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "cc/output/compositor_frame_ack.h" 9 #include "cc/output/compositor_frame_ack.h"
10 #include "cc/output/output_surface_client.h" 10 #include "cc/output/output_surface_client.h"
(...skipping 24 matching lines...) Expand all
35 scoped_refptr<ContextProvider> context_provider, 35 scoped_refptr<ContextProvider> context_provider,
36 scoped_refptr<ContextProvider> worker_context_provider, 36 scoped_refptr<ContextProvider> worker_context_provider,
37 std::unique_ptr<SoftwareOutputDevice> software_device, 37 std::unique_ptr<SoftwareOutputDevice> software_device,
38 bool delegated_rendering) 38 bool delegated_rendering)
39 : OutputSurface(std::move(context_provider), 39 : OutputSurface(std::move(context_provider),
40 std::move(worker_context_provider), 40 std::move(worker_context_provider),
41 std::move(software_device)) { 41 std::move(software_device)) {
42 capabilities_.delegated_rendering = delegated_rendering; 42 capabilities_.delegated_rendering = delegated_rendering;
43 } 43 }
44 44
45 FakeOutputSurface::~FakeOutputSurface() {} 45 FakeOutputSurface::~FakeOutputSurface() = default;
46 46
47 void FakeOutputSurface::SwapBuffers(CompositorFrame frame) { 47 void FakeOutputSurface::SwapBuffers(CompositorFrame frame) {
48 ReturnResourcesHeldByParent();
49
48 std::unique_ptr<CompositorFrame> frame_copy(new CompositorFrame); 50 std::unique_ptr<CompositorFrame> frame_copy(new CompositorFrame);
49 *frame_copy = std::move(frame); 51 *frame_copy = std::move(frame);
50 if (frame_copy->delegated_frame_data || !context_provider()) { 52 if (frame_copy->delegated_frame_data || !context_provider()) {
51 last_sent_frame_ = std::move(frame_copy); 53 last_sent_frame_ = std::move(frame_copy);
52 54
53 if (last_sent_frame_->delegated_frame_data) { 55 if (last_sent_frame_->delegated_frame_data) {
54 resources_held_by_parent_.insert( 56 resources_held_by_parent_.insert(
55 resources_held_by_parent_.end(), 57 resources_held_by_parent_.end(),
56 last_sent_frame_->delegated_frame_data->resource_list.begin(), 58 last_sent_frame_->delegated_frame_data->resource_list.begin(),
57 last_sent_frame_->delegated_frame_data->resource_list.end()); 59 last_sent_frame_->delegated_frame_data->resource_list.end());
(...skipping 30 matching lines...) Expand all
88 if (memory_policy_to_set_at_bind_) { 90 if (memory_policy_to_set_at_bind_) {
89 client_->SetMemoryPolicy(*memory_policy_to_set_at_bind_.get()); 91 client_->SetMemoryPolicy(*memory_policy_to_set_at_bind_.get());
90 memory_policy_to_set_at_bind_ = nullptr; 92 memory_policy_to_set_at_bind_ = nullptr;
91 } 93 }
92 return true; 94 return true;
93 } else { 95 } else {
94 return false; 96 return false;
95 } 97 }
96 } 98 }
97 99
100 void FakeOutputSurface::DetachFromClient() {
101 ReturnResourcesHeldByParent();
102 OutputSurface::DetachFromClient();
103 }
104
98 void FakeOutputSurface::SetTreeActivationCallback( 105 void FakeOutputSurface::SetTreeActivationCallback(
99 const base::Closure& callback) { 106 const base::Closure& callback) {
100 DCHECK(client_); 107 DCHECK(client_);
101 client_->SetTreeActivationCallback(callback); 108 client_->SetTreeActivationCallback(callback);
102 } 109 }
103 110
104 void FakeOutputSurface::ReturnResource(unsigned id, CompositorFrameAck* ack) {
105 TransferableResourceArray::iterator it;
106 for (it = resources_held_by_parent_.begin();
107 it != resources_held_by_parent_.end();
108 ++it) {
109 if (it->id == id)
110 break;
111 }
112 DCHECK(it != resources_held_by_parent_.end());
113 ack->resources.push_back(it->ToReturnedResource());
114 resources_held_by_parent_.erase(it);
115 }
116
117 bool FakeOutputSurface::HasExternalStencilTest() const { 111 bool FakeOutputSurface::HasExternalStencilTest() const {
118 return has_external_stencil_test_; 112 return has_external_stencil_test_;
119 } 113 }
120 114
121 bool FakeOutputSurface::SurfaceIsSuspendForRecycle() const { 115 bool FakeOutputSurface::SurfaceIsSuspendForRecycle() const {
122 return suspended_for_recycle_; 116 return suspended_for_recycle_;
123 } 117 }
124 118
125 OverlayCandidateValidator* FakeOutputSurface::GetOverlayCandidateValidator() 119 OverlayCandidateValidator* FakeOutputSurface::GetOverlayCandidateValidator()
126 const { 120 const {
127 return overlay_candidate_validator_; 121 return overlay_candidate_validator_;
128 } 122 }
129 123
130 void FakeOutputSurface::SetMemoryPolicyToSetAtBind( 124 void FakeOutputSurface::SetMemoryPolicyToSetAtBind(
131 std::unique_ptr<ManagedMemoryPolicy> memory_policy_to_set_at_bind) { 125 std::unique_ptr<ManagedMemoryPolicy> memory_policy_to_set_at_bind) {
132 memory_policy_to_set_at_bind_.swap(memory_policy_to_set_at_bind); 126 memory_policy_to_set_at_bind_.swap(memory_policy_to_set_at_bind);
133 } 127 }
134 128
129 void FakeOutputSurface::ReturnResourcesHeldByParent() {
130 // Check |delegated_frame_data| because we shouldn't reclaim resources
131 // for the Display which does not swap delegated frames.
132 if (last_sent_frame_ && last_sent_frame_->delegated_frame_data) {
133 // Return the last frame's resources immediately.
134 CompositorFrameAck ack;
135 for (const auto& resource : resources_held_by_parent_)
136 ack.resources.push_back(resource.ToReturnedResource());
137 resources_held_by_parent_.clear();
138 client_->ReclaimResources(&ack);
139 }
140 }
141
135 } // namespace cc 142 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/fake_output_surface.h ('k') | cc/test/layer_tree_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698