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

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

Issue 614073005: Allow CopyOutputRequests on all render passes of a surface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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.h" 5 #include "cc/surfaces/surface.h"
6 6
7 #include "cc/output/compositor_frame.h" 7 #include "cc/output/compositor_frame.h"
8 #include "cc/output/copy_output_request.h" 8 #include "cc/output/copy_output_request.h"
9 #include "cc/surfaces/surface_factory.h" 9 #include "cc/surfaces/surface_factory.h"
10 #include "cc/surfaces/surface_manager.h" 10 #include "cc/surfaces/surface_manager.h"
11 11
12 namespace cc { 12 namespace cc {
13 13
14 // The frame index starts at 2 so that empty frames will be treated as 14 // The frame index starts at 2 so that empty frames will be treated as
15 // completely damaged the first time they're drawn from. 15 // completely damaged the first time they're drawn from.
16 static const int kFrameIndexStart = 2; 16 static const int kFrameIndexStart = 2;
17 17
18 Surface::Surface(SurfaceId id, const gfx::Size& size, SurfaceFactory* factory) 18 Surface::Surface(SurfaceId id, const gfx::Size& size, SurfaceFactory* factory)
19 : surface_id_(id), 19 : surface_id_(id),
20 size_(size), 20 size_(size),
21 factory_(factory->AsWeakPtr()), 21 factory_(factory->AsWeakPtr()),
22 frame_index_(kFrameIndexStart) { 22 frame_index_(kFrameIndexStart) {
23 } 23 }
24 24
25 Surface::~Surface() { 25 Surface::~Surface() {
26 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); 26 ClearCopyRequests();
27 it != copy_requests_.end();
28 ++it) {
29 (*it)->SendEmptyResult();
30 }
31 copy_requests_.clear();
32 if (current_frame_ && factory_) { 27 if (current_frame_ && factory_) {
33 ReturnedResourceArray current_resources; 28 ReturnedResourceArray current_resources;
34 TransferableResource::ReturnResources( 29 TransferableResource::ReturnResources(
35 current_frame_->delegated_frame_data->resource_list, 30 current_frame_->delegated_frame_data->resource_list,
36 &current_resources); 31 &current_resources);
37 factory_->UnrefResources(current_resources); 32 factory_->UnrefResources(current_resources);
38 } 33 }
39 } 34 }
40 35
41 void Surface::QueueFrame(scoped_ptr<CompositorFrame> frame, 36 void Surface::QueueFrame(scoped_ptr<CompositorFrame> frame,
42 const base::Closure& callback) { 37 const base::Closure& callback) {
43 DCHECK(factory_); 38 DCHECK(factory_);
44 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); 39 ClearCopyRequests();
45 it != copy_requests_.end();
46 ++it) {
47 (*it)->SendEmptyResult();
48 }
49 copy_requests_.clear();
50
51 TakeLatencyInfo(&frame->metadata.latency_info); 40 TakeLatencyInfo(&frame->metadata.latency_info);
52 scoped_ptr<CompositorFrame> previous_frame = current_frame_.Pass(); 41 scoped_ptr<CompositorFrame> previous_frame = current_frame_.Pass();
53 current_frame_ = frame.Pass(); 42 current_frame_ = frame.Pass();
54 factory_->ReceiveFromChild( 43 factory_->ReceiveFromChild(
55 current_frame_->delegated_frame_data->resource_list); 44 current_frame_->delegated_frame_data->resource_list);
56 ++frame_index_; 45 ++frame_index_;
57 46
58 if (previous_frame) { 47 if (previous_frame) {
59 ReturnedResourceArray previous_resources; 48 ReturnedResourceArray previous_resources;
60 TransferableResource::ReturnResources( 49 TransferableResource::ReturnResources(
61 previous_frame->delegated_frame_data->resource_list, 50 previous_frame->delegated_frame_data->resource_list,
62 &previous_resources); 51 &previous_resources);
63 factory_->UnrefResources(previous_resources); 52 factory_->UnrefResources(previous_resources);
64 } 53 }
65 if (!draw_callback_.is_null()) 54 if (!draw_callback_.is_null())
66 draw_callback_.Run(); 55 draw_callback_.Run();
67 draw_callback_ = callback; 56 draw_callback_ = callback;
68 factory_->manager()->DidSatisfySequences( 57 factory_->manager()->DidSatisfySequences(
69 surface_id_, &current_frame_->metadata.satisfies_sequences); 58 surface_id_, &current_frame_->metadata.satisfies_sequences);
70 } 59 }
71 60
72 void Surface::RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> copy_request) { 61 void Surface::RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> copy_request) {
73 copy_requests_.push_back(copy_request.Pass()); 62 if (current_frame_ &&
63 !current_frame_->delegated_frame_data->render_pass_list.empty())
64 current_frame_->delegated_frame_data->render_pass_list.back()
65 ->copy_requests.push_back(copy_request.Pass());
66 else
67 copy_request->SendEmptyResult();
74 } 68 }
75 69
76 void Surface::TakeCopyOutputRequests( 70 void Surface::TakeCopyOutputRequests(
77 ScopedPtrVector<CopyOutputRequest>* copy_requests) { 71 std::multimap<RenderPassId, CopyOutputRequest*>* copy_requests) {
78 DCHECK(copy_requests->empty()); 72 DCHECK(copy_requests->empty());
79 copy_requests->swap(copy_requests_); 73 if (current_frame_) {
74 for (auto* render_pass :
75 current_frame_->delegated_frame_data->render_pass_list) {
76 while (!render_pass->copy_requests.empty()) {
77 scoped_ptr<CopyOutputRequest> request =
78 render_pass->copy_requests.take_back();
79 render_pass->copy_requests.pop_back();
80 copy_requests->insert(
81 std::make_pair(render_pass->id, request.release()));
82 }
83 }
84 }
80 } 85 }
81 86
82 const CompositorFrame* Surface::GetEligibleFrame() { 87 const CompositorFrame* Surface::GetEligibleFrame() {
83 return current_frame_.get(); 88 return current_frame_.get();
84 } 89 }
85 90
86 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) { 91 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) {
87 if (!current_frame_) 92 if (!current_frame_)
88 return; 93 return;
89 if (latency_info->empty()) { 94 if (latency_info->empty()) {
90 current_frame_->metadata.latency_info.swap(*latency_info); 95 current_frame_->metadata.latency_info.swap(*latency_info);
91 return; 96 return;
92 } 97 }
93 std::copy(current_frame_->metadata.latency_info.begin(), 98 std::copy(current_frame_->metadata.latency_info.begin(),
94 current_frame_->metadata.latency_info.end(), 99 current_frame_->metadata.latency_info.end(),
95 std::back_inserter(*latency_info)); 100 std::back_inserter(*latency_info));
96 current_frame_->metadata.latency_info.clear(); 101 current_frame_->metadata.latency_info.clear();
97 } 102 }
98 103
99 void Surface::RunDrawCallbacks() { 104 void Surface::RunDrawCallbacks() {
100 if (!draw_callback_.is_null()) { 105 if (!draw_callback_.is_null()) {
101 base::Closure callback = draw_callback_; 106 base::Closure callback = draw_callback_;
102 draw_callback_ = base::Closure(); 107 draw_callback_ = base::Closure();
103 callback.Run(); 108 callback.Run();
104 } 109 }
105 } 110 }
106 111
112 void Surface::ClearCopyRequests() {
113 if (current_frame_) {
114 for (auto* render_pass :
115 current_frame_->delegated_frame_data->render_pass_list) {
116 for (auto* copy_request : render_pass->copy_requests)
117 copy_request->SendEmptyResult();
118 }
119 }
120 }
121
107 } // namespace cc 122 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698