| 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/scheduler/begin_frame_source.h" |
| 12 #include "cc/scheduler/delay_based_time_source.h" |
| 11 #include "cc/test/begin_frame_args_test.h" | 13 #include "cc/test/begin_frame_args_test.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 15 |
| 14 namespace cc { | 16 namespace cc { |
| 15 | 17 |
| 16 FakeCompositorFrameSink::FakeCompositorFrameSink( | 18 FakeCompositorFrameSink::FakeCompositorFrameSink( |
| 17 scoped_refptr<ContextProvider> context_provider, | 19 scoped_refptr<ContextProvider> context_provider, |
| 18 scoped_refptr<ContextProvider> worker_context_provider) | 20 scoped_refptr<ContextProvider> worker_context_provider) |
| 19 : CompositorFrameSink(std::move(context_provider), | 21 : CompositorFrameSink(std::move(context_provider), |
| 20 std::move(worker_context_provider), | 22 std::move(worker_context_provider), |
| 21 nullptr, | 23 nullptr, |
| 22 nullptr), | 24 nullptr), |
| 23 weak_ptr_factory_(this) { | 25 weak_ptr_factory_(this) { |
| 24 gpu_memory_buffer_manager_ = | 26 gpu_memory_buffer_manager_ = |
| 25 context_provider_ ? &test_gpu_memory_buffer_manager_ : nullptr; | 27 context_provider_ ? &test_gpu_memory_buffer_manager_ : nullptr; |
| 26 shared_bitmap_manager_ = | 28 shared_bitmap_manager_ = |
| 27 context_provider_ ? nullptr : &test_shared_bitmap_manager_; | 29 context_provider_ ? nullptr : &test_shared_bitmap_manager_; |
| 28 } | 30 } |
| 29 | 31 |
| 30 FakeCompositorFrameSink::~FakeCompositorFrameSink() = default; | 32 FakeCompositorFrameSink::~FakeCompositorFrameSink() = default; |
| 31 | 33 |
| 34 bool FakeCompositorFrameSink::BindToClient(CompositorFrameSinkClient* client) { |
| 35 if (!CompositorFrameSink::BindToClient(client)) |
| 36 return false; |
| 37 begin_frame_source_ = base::MakeUnique<BackToBackBeginFrameSource>( |
| 38 base::MakeUnique<DelayBasedTimeSource>( |
| 39 base::ThreadTaskRunnerHandle::Get().get())); |
| 40 client_->SetBeginFrameSource(begin_frame_source_.get()); |
| 41 return true; |
| 42 } |
| 43 |
| 32 void FakeCompositorFrameSink::DetachFromClient() { | 44 void FakeCompositorFrameSink::DetachFromClient() { |
| 33 ReturnResourcesHeldByParent(); | 45 ReturnResourcesHeldByParent(); |
| 34 CompositorFrameSink::DetachFromClient(); | 46 CompositorFrameSink::DetachFromClient(); |
| 35 } | 47 } |
| 36 | 48 |
| 37 void FakeCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { | 49 void FakeCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { |
| 38 ReturnResourcesHeldByParent(); | 50 ReturnResourcesHeldByParent(); |
| 39 | 51 |
| 40 last_sent_frame_.reset(new CompositorFrame(std::move(frame))); | 52 last_sent_frame_.reset(new CompositorFrame(std::move(frame))); |
| 41 ++num_sent_frames_; | 53 ++num_sent_frames_; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 67 // Return the last frame's resources immediately. | 79 // Return the last frame's resources immediately. |
| 68 ReturnedResourceArray resources; | 80 ReturnedResourceArray resources; |
| 69 for (const auto& resource : resources_held_by_parent_) | 81 for (const auto& resource : resources_held_by_parent_) |
| 70 resources.push_back(resource.ToReturnedResource()); | 82 resources.push_back(resource.ToReturnedResource()); |
| 71 resources_held_by_parent_.clear(); | 83 resources_held_by_parent_.clear(); |
| 72 client_->ReclaimResources(resources); | 84 client_->ReclaimResources(resources); |
| 73 } | 85 } |
| 74 } | 86 } |
| 75 | 87 |
| 76 } // namespace cc | 88 } // namespace cc |
| OLD | NEW |