| 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_output_surface.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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "cc/output/output_surface_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 FakeOutputSurface::FakeOutputSurface( | 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 bool delegated_rendering) | 19 bool delegated_rendering) |
| 20 : FakeOutputSurface(std::move(context_provider), | 20 : FakeCompositorFrameSink(std::move(context_provider), |
| 21 std::move(worker_context_provider), | 21 std::move(worker_context_provider), |
| 22 nullptr, | 22 nullptr, |
| 23 delegated_rendering) {} | 23 delegated_rendering) {} |
| 24 | 24 |
| 25 FakeOutputSurface::FakeOutputSurface( | 25 FakeCompositorFrameSink::FakeCompositorFrameSink( |
| 26 scoped_refptr<ContextProvider> context_provider, | 26 scoped_refptr<ContextProvider> context_provider, |
| 27 scoped_refptr<ContextProvider> worker_context_provider, | 27 scoped_refptr<ContextProvider> worker_context_provider, |
| 28 std::unique_ptr<SoftwareOutputDevice> software_device, | 28 std::unique_ptr<SoftwareOutputDevice> software_device, |
| 29 bool delegated_rendering) | 29 bool delegated_rendering) |
| 30 : OutputSurface(std::move(context_provider), | 30 : CompositorFrameSink(std::move(context_provider), |
| 31 std::move(worker_context_provider), | 31 std::move(worker_context_provider), |
| 32 std::move(software_device)) { | 32 std::move(software_device)) { |
| 33 capabilities_.delegated_rendering = delegated_rendering; | 33 capabilities_.delegated_rendering = delegated_rendering; |
| 34 } | 34 } |
| 35 | 35 |
| 36 FakeOutputSurface::~FakeOutputSurface() = default; | 36 FakeCompositorFrameSink::~FakeCompositorFrameSink() = default; |
| 37 | 37 |
| 38 void FakeOutputSurface::SwapBuffers(CompositorFrame frame) { | 38 void FakeCompositorFrameSink::SwapBuffers(CompositorFrame frame) { |
| 39 ReturnResourcesHeldByParent(); | 39 ReturnResourcesHeldByParent(); |
| 40 | 40 |
| 41 last_sent_frame_.reset(new CompositorFrame(std::move(frame))); | 41 last_sent_frame_.reset(new CompositorFrame(std::move(frame))); |
| 42 ++num_sent_frames_; | 42 ++num_sent_frames_; |
| 43 | 43 |
| 44 if (last_sent_frame_->delegated_frame_data) { | 44 if (last_sent_frame_->delegated_frame_data) { |
| 45 auto* frame_data = last_sent_frame_->delegated_frame_data.get(); | 45 auto* frame_data = last_sent_frame_->delegated_frame_data.get(); |
| 46 last_swap_rect_ = frame_data->render_pass_list.back()->damage_rect; | 46 last_swap_rect_ = frame_data->render_pass_list.back()->damage_rect; |
| 47 last_swap_rect_valid_ = true; | 47 last_swap_rect_valid_ = true; |
| 48 } else if (context_provider()) { | 48 } else if (context_provider()) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 59 auto* frame_data = last_sent_frame_->delegated_frame_data.get(); | 59 auto* frame_data = last_sent_frame_->delegated_frame_data.get(); |
| 60 resources_held_by_parent_.insert(resources_held_by_parent_.end(), | 60 resources_held_by_parent_.insert(resources_held_by_parent_.end(), |
| 61 frame_data->resource_list.begin(), | 61 frame_data->resource_list.begin(), |
| 62 frame_data->resource_list.end()); | 62 frame_data->resource_list.end()); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 PostSwapBuffersComplete(); | 66 PostSwapBuffersComplete(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void FakeOutputSurface::BindFramebuffer() { | 69 void FakeCompositorFrameSink::BindFramebuffer() { |
| 70 if (framebuffer_) { | 70 if (framebuffer_) { |
| 71 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, | 71 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, |
| 72 framebuffer_); | 72 framebuffer_); |
| 73 } else { | 73 } else { |
| 74 OutputSurface::BindFramebuffer(); | 74 CompositorFrameSink::BindFramebuffer(); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 uint32_t FakeOutputSurface::GetFramebufferCopyTextureFormat() { | 78 uint32_t FakeCompositorFrameSink::GetFramebufferCopyTextureFormat() { |
| 79 if (framebuffer_) | 79 if (framebuffer_) |
| 80 return framebuffer_format_; | 80 return framebuffer_format_; |
| 81 else | 81 else |
| 82 return GL_RGB; | 82 return GL_RGB; |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool FakeOutputSurface::BindToClient(OutputSurfaceClient* client) { | 85 bool FakeCompositorFrameSink::BindToClient(CompositorFrameSinkClient* client) { |
| 86 if (OutputSurface::BindToClient(client)) { | 86 if (CompositorFrameSink::BindToClient(client)) { |
| 87 client_ = client; | 87 client_ = client; |
| 88 return true; | 88 return true; |
| 89 } else { | 89 } else { |
| 90 return false; | 90 return false; |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 void FakeOutputSurface::DetachFromClient() { | 94 void FakeCompositorFrameSink::DetachFromClient() { |
| 95 ReturnResourcesHeldByParent(); | 95 ReturnResourcesHeldByParent(); |
| 96 OutputSurface::DetachFromClient(); | 96 CompositorFrameSink::DetachFromClient(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool FakeOutputSurface::HasExternalStencilTest() const { | 99 bool FakeCompositorFrameSink::HasExternalStencilTest() const { |
| 100 return has_external_stencil_test_; | 100 return has_external_stencil_test_; |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool FakeOutputSurface::SurfaceIsSuspendForRecycle() const { | 103 bool FakeCompositorFrameSink::SurfaceIsSuspendForRecycle() const { |
| 104 return suspended_for_recycle_; | 104 return suspended_for_recycle_; |
| 105 } | 105 } |
| 106 | 106 |
| 107 OverlayCandidateValidator* FakeOutputSurface::GetOverlayCandidateValidator() | 107 OverlayCandidateValidator* |
| 108 const { | 108 FakeCompositorFrameSink::GetOverlayCandidateValidator() const { |
| 109 return overlay_candidate_validator_; | 109 return overlay_candidate_validator_; |
| 110 } | 110 } |
| 111 | 111 |
| 112 void FakeOutputSurface::ReturnResourcesHeldByParent() { | 112 void FakeCompositorFrameSink::ReturnResourcesHeldByParent() { |
| 113 // Check |delegated_frame_data| because we shouldn't reclaim resources | 113 // Check |delegated_frame_data| because we shouldn't reclaim resources |
| 114 // for the Display which does not swap delegated frames. | 114 // for the Display which does not swap delegated frames. |
| 115 if (last_sent_frame_ && last_sent_frame_->delegated_frame_data) { | 115 if (last_sent_frame_ && last_sent_frame_->delegated_frame_data) { |
| 116 // Return the last frame's resources immediately. | 116 // Return the last frame's resources immediately. |
| 117 ReturnedResourceArray resources; | 117 ReturnedResourceArray resources; |
| 118 for (const auto& resource : resources_held_by_parent_) | 118 for (const auto& resource : resources_held_by_parent_) |
| 119 resources.push_back(resource.ToReturnedResource()); | 119 resources.push_back(resource.ToReturnedResource()); |
| 120 resources_held_by_parent_.clear(); | 120 resources_held_by_parent_.clear(); |
| 121 client_->ReclaimResources(resources); | 121 client_->ReclaimResources(resources); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 } // namespace cc | 125 } // namespace cc |
| OLD | NEW |