OLD | NEW |
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_compositor_frame_sink.h" | 5 #include "cc/test/fake_compositor_frame_sink.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
9 #include "cc/output/compositor_frame_sink_client.h" | 9 #include "cc/output/compositor_frame_sink_client.h" |
10 #include "cc/resources/returned_resource.h" | 10 #include "cc/resources/returned_resource.h" |
11 #include "cc/test/begin_frame_args_test.h" | 11 #include "cc/test/begin_frame_args_test.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 | 15 |
16 FakeCompositorFrameSink::FakeCompositorFrameSink( | 16 FakeCompositorFrameSink::FakeCompositorFrameSink( |
17 scoped_refptr<ContextProvider> context_provider, | 17 scoped_refptr<ContextProvider> context_provider, |
18 scoped_refptr<ContextProvider> worker_context_provider) | 18 scoped_refptr<ContextProvider> worker_context_provider) |
19 : CompositorFrameSink(std::move(context_provider), | 19 : CompositorFrameSink(std::move(context_provider), |
20 std::move(worker_context_provider)), | 20 std::move(worker_context_provider)), |
21 weak_ptr_factory_(this) {} | 21 weak_ptr_factory_(this) {} |
22 | 22 |
23 FakeCompositorFrameSink::~FakeCompositorFrameSink() = default; | 23 FakeCompositorFrameSink::~FakeCompositorFrameSink() = default; |
24 | 24 |
25 void FakeCompositorFrameSink::DetachFromClient() { | 25 void FakeCompositorFrameSink::DetachFromClient() { |
26 ReturnResourcesHeldByParent(); | 26 ReturnResourcesHeldByParent(); |
27 CompositorFrameSink::DetachFromClient(); | 27 CompositorFrameSink::DetachFromClient(); |
28 } | 28 } |
29 | 29 |
30 void FakeCompositorFrameSink::SwapBuffers(CompositorFrame frame) { | 30 void FakeCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { |
31 ReturnResourcesHeldByParent(); | 31 ReturnResourcesHeldByParent(); |
32 | 32 |
33 last_sent_frame_.reset(new CompositorFrame(std::move(frame))); | 33 last_sent_frame_.reset(new CompositorFrame(std::move(frame))); |
34 ++num_sent_frames_; | 34 ++num_sent_frames_; |
35 | 35 |
36 if (last_sent_frame_->delegated_frame_data) { | 36 if (last_sent_frame_->delegated_frame_data) { |
37 auto* frame_data = last_sent_frame_->delegated_frame_data.get(); | 37 auto* frame_data = last_sent_frame_->delegated_frame_data.get(); |
38 last_swap_rect_ = frame_data->render_pass_list.back()->damage_rect; | 38 last_swap_rect_ = frame_data->render_pass_list.back()->damage_rect; |
39 last_swap_rect_valid_ = true; | 39 last_swap_rect_valid_ = true; |
40 } else { | 40 } else { |
41 last_swap_rect_ = gfx::Rect(); | 41 last_swap_rect_ = gfx::Rect(); |
42 last_swap_rect_valid_ = false; | 42 last_swap_rect_valid_ = false; |
43 } | 43 } |
44 | 44 |
45 if (last_sent_frame_->delegated_frame_data || !context_provider()) { | 45 if (last_sent_frame_->delegated_frame_data || !context_provider()) { |
46 if (last_sent_frame_->delegated_frame_data) { | 46 if (last_sent_frame_->delegated_frame_data) { |
47 auto* frame_data = last_sent_frame_->delegated_frame_data.get(); | 47 auto* frame_data = last_sent_frame_->delegated_frame_data.get(); |
48 resources_held_by_parent_.insert(resources_held_by_parent_.end(), | 48 resources_held_by_parent_.insert(resources_held_by_parent_.end(), |
49 frame_data->resource_list.begin(), | 49 frame_data->resource_list.begin(), |
50 frame_data->resource_list.end()); | 50 frame_data->resource_list.end()); |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 base::ThreadTaskRunnerHandle::Get()->PostTask( | 54 base::ThreadTaskRunnerHandle::Get()->PostTask( |
55 FROM_HERE, base::Bind(&FakeCompositorFrameSink::SwapBuffersAck, | 55 FROM_HERE, |
56 weak_ptr_factory_.GetWeakPtr())); | 56 base::Bind(&FakeCompositorFrameSink::DidReceiveCompositorFrameAck, |
| 57 weak_ptr_factory_.GetWeakPtr())); |
57 } | 58 } |
58 | 59 |
59 void FakeCompositorFrameSink::SwapBuffersAck() { | 60 void FakeCompositorFrameSink::DidReceiveCompositorFrameAck() { |
60 client_->DidSwapBuffersComplete(); | 61 client_->DidReceiveCompositorFrameAck(); |
61 } | 62 } |
62 | 63 |
63 void FakeCompositorFrameSink::ReturnResourcesHeldByParent() { | 64 void FakeCompositorFrameSink::ReturnResourcesHeldByParent() { |
64 // Check |delegated_frame_data| because we shouldn't reclaim resources | 65 // Check |delegated_frame_data| because we shouldn't reclaim resources |
65 // for the Display which does not swap delegated frames. | 66 // for the Display which does not swap delegated frames. |
66 if (last_sent_frame_ && last_sent_frame_->delegated_frame_data) { | 67 if (last_sent_frame_ && last_sent_frame_->delegated_frame_data) { |
67 // Return the last frame's resources immediately. | 68 // Return the last frame's resources immediately. |
68 ReturnedResourceArray resources; | 69 ReturnedResourceArray resources; |
69 for (const auto& resource : resources_held_by_parent_) | 70 for (const auto& resource : resources_held_by_parent_) |
70 resources.push_back(resource.ToReturnedResource()); | 71 resources.push_back(resource.ToReturnedResource()); |
71 resources_held_by_parent_.clear(); | 72 resources_held_by_parent_.clear(); |
72 client_->ReclaimResources(resources); | 73 client_->ReclaimResources(resources); |
73 } | 74 } |
74 } | 75 } |
75 | 76 |
76 } // namespace cc | 77 } // namespace cc |
OLD | NEW |