| OLD | NEW |
| 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 "ui/compositor/test/in_process_context_factory.h" | 5 #include "ui/compositor/test/in_process_context_factory.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "cc/output/compositor_frame.h" | 14 #include "cc/output/compositor_frame.h" |
| 15 #include "cc/output/context_provider.h" | 15 #include "cc/output/context_provider.h" |
| 16 #include "cc/output/output_surface_client.h" | 16 #include "cc/output/output_surface_client.h" |
| 17 #include "cc/output/texture_mailbox_deleter.h" | 17 #include "cc/output/texture_mailbox_deleter.h" |
| 18 #include "cc/scheduler/begin_frame_source.h" | 18 #include "cc/scheduler/begin_frame_source.h" |
| 19 #include "cc/scheduler/delay_based_time_source.h" | 19 #include "cc/scheduler/delay_based_time_source.h" |
| 20 #include "cc/surfaces/direct_compositor_frame_sink.h" |
| 20 #include "cc/surfaces/display.h" | 21 #include "cc/surfaces/display.h" |
| 21 #include "cc/surfaces/display_scheduler.h" | 22 #include "cc/surfaces/display_scheduler.h" |
| 22 #include "cc/surfaces/surface_display_output_surface.h" | |
| 23 #include "cc/surfaces/surface_id_allocator.h" | 23 #include "cc/surfaces/surface_id_allocator.h" |
| 24 #include "cc/test/pixel_test_output_surface.h" | 24 #include "cc/test/pixel_test_output_surface.h" |
| 25 #include "cc/test/test_shared_bitmap_manager.h" | 25 #include "cc/test/test_shared_bitmap_manager.h" |
| 26 #include "gpu/command_buffer/client/context_support.h" | 26 #include "gpu/command_buffer/client/context_support.h" |
| 27 #include "gpu/command_buffer/client/gles2_interface.h" | 27 #include "gpu/command_buffer/client/gles2_interface.h" |
| 28 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 28 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 29 #include "ui/compositor/compositor_switches.h" | 29 #include "ui/compositor/compositor_switches.h" |
| 30 #include "ui/compositor/layer.h" | 30 #include "ui/compositor/layer.h" |
| 31 #include "ui/compositor/reflector.h" | 31 #include "ui/compositor/reflector.h" |
| 32 #include "ui/compositor/test/in_process_context_provider.h" | 32 #include "ui/compositor/test/in_process_context_provider.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 } // namespace | 100 } // namespace |
| 101 | 101 |
| 102 InProcessContextFactory::InProcessContextFactory( | 102 InProcessContextFactory::InProcessContextFactory( |
| 103 bool context_factory_for_test, | 103 bool context_factory_for_test, |
| 104 cc::SurfaceManager* surface_manager) | 104 cc::SurfaceManager* surface_manager) |
| 105 : next_surface_client_id_(1u), | 105 : next_surface_client_id_(1u), |
| 106 use_test_surface_(true), | 106 use_test_surface_(true), |
| 107 context_factory_for_test_(context_factory_for_test), | 107 context_factory_for_test_(context_factory_for_test), |
| 108 surface_manager_(surface_manager) { | 108 surface_manager_(surface_manager) { |
| 109 DCHECK(surface_manager); |
| 109 DCHECK_NE(gl::GetGLImplementation(), gl::kGLImplementationNone) | 110 DCHECK_NE(gl::GetGLImplementation(), gl::kGLImplementationNone) |
| 110 << "If running tests, ensure that main() is calling " | 111 << "If running tests, ensure that main() is calling " |
| 111 << "gl::GLSurfaceTestSupport::InitializeOneOff()"; | 112 << "gl::GLSurfaceTestSupport::InitializeOneOff()"; |
| 112 } | 113 } |
| 113 | 114 |
| 114 InProcessContextFactory::~InProcessContextFactory() { | 115 InProcessContextFactory::~InProcessContextFactory() { |
| 115 DCHECK(per_compositor_data_.empty()); | 116 DCHECK(per_compositor_data_.empty()); |
| 116 } | 117 } |
| 117 | 118 |
| 118 void InProcessContextFactory::SendOnLostResources() { | 119 void InProcessContextFactory::SendOnLostResources() { |
| 119 FOR_EACH_OBSERVER(ContextFactoryObserver, observer_list_, OnLostResources()); | 120 FOR_EACH_OBSERVER(ContextFactoryObserver, observer_list_, OnLostResources()); |
| 120 } | 121 } |
| 121 | 122 |
| 122 void InProcessContextFactory::CreateOutputSurface( | 123 void InProcessContextFactory::CreateCompositorFrameSink( |
| 123 base::WeakPtr<Compositor> compositor) { | 124 base::WeakPtr<Compositor> compositor) { |
| 124 // Try to reuse existing shared worker context provider. | 125 // Try to reuse existing shared worker context provider. |
| 125 bool shared_worker_context_provider_lost = false; | 126 bool shared_worker_context_provider_lost = false; |
| 126 if (shared_worker_context_provider_) { | 127 if (shared_worker_context_provider_) { |
| 127 // Note: If context is lost, delete reference after releasing the lock. | 128 // Note: If context is lost, delete reference after releasing the lock. |
| 128 base::AutoLock lock(*shared_worker_context_provider_->GetLock()); | 129 base::AutoLock lock(*shared_worker_context_provider_->GetLock()); |
| 129 if (shared_worker_context_provider_->ContextGL() | 130 if (shared_worker_context_provider_->ContextGL() |
| 130 ->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { | 131 ->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { |
| 131 shared_worker_context_provider_lost = true; | 132 shared_worker_context_provider_lost = true; |
| 132 } | 133 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 160 if (use_test_surface_) { | 161 if (use_test_surface_) { |
| 161 bool flipped_output_surface = false; | 162 bool flipped_output_surface = false; |
| 162 display_output_surface = base::MakeUnique<cc::PixelTestOutputSurface>( | 163 display_output_surface = base::MakeUnique<cc::PixelTestOutputSurface>( |
| 163 context_provider, shared_worker_context_provider_, | 164 context_provider, shared_worker_context_provider_, |
| 164 flipped_output_surface); | 165 flipped_output_surface); |
| 165 } else { | 166 } else { |
| 166 display_output_surface = base::MakeUnique<DirectOutputSurface>( | 167 display_output_surface = base::MakeUnique<DirectOutputSurface>( |
| 167 context_provider, shared_worker_context_provider_); | 168 context_provider, shared_worker_context_provider_); |
| 168 } | 169 } |
| 169 | 170 |
| 170 if (surface_manager_) { | 171 std::unique_ptr<cc::DelayBasedBeginFrameSource> begin_frame_source( |
| 171 std::unique_ptr<cc::DelayBasedBeginFrameSource> begin_frame_source( | 172 new cc::DelayBasedBeginFrameSource( |
| 172 new cc::DelayBasedBeginFrameSource( | 173 base::MakeUnique<cc::DelayBasedTimeSource>( |
| 173 base::MakeUnique<cc::DelayBasedTimeSource>( | 174 compositor->task_runner().get()))); |
| 174 compositor->task_runner().get()))); | 175 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( |
| 175 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( | 176 begin_frame_source.get(), compositor->task_runner().get(), |
| 176 begin_frame_source.get(), compositor->task_runner().get(), | 177 display_output_surface->capabilities().max_frames_pending)); |
| 177 display_output_surface->capabilities().max_frames_pending)); | 178 per_compositor_data_[compositor.get()] = base::MakeUnique<cc::Display>( |
| 178 per_compositor_data_[compositor.get()] = base::MakeUnique<cc::Display>( | 179 GetSharedBitmapManager(), GetGpuMemoryBufferManager(), |
| 179 GetSharedBitmapManager(), GetGpuMemoryBufferManager(), | 180 compositor->GetRendererSettings(), std::move(begin_frame_source), |
| 180 compositor->GetRendererSettings(), std::move(begin_frame_source), | 181 std::move(display_output_surface), std::move(scheduler), |
| 181 std::move(display_output_surface), std::move(scheduler), | 182 base::MakeUnique<cc::TextureMailboxDeleter>( |
| 182 base::MakeUnique<cc::TextureMailboxDeleter>( | 183 compositor->task_runner().get())); |
| 183 compositor->task_runner().get())); | |
| 184 | 184 |
| 185 auto* display = per_compositor_data_[compositor.get()].get(); | 185 auto* display = per_compositor_data_[compositor.get()].get(); |
| 186 std::unique_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface( | 186 auto compositor_frame_sink = base::MakeUnique<cc::DirectCompositorFrameSink>( |
| 187 new cc::SurfaceDisplayOutputSurface( | 187 surface_manager_, compositor->surface_id_allocator(), display, |
| 188 surface_manager_, compositor->surface_id_allocator(), display, | 188 context_provider, shared_worker_context_provider_); |
| 189 context_provider, shared_worker_context_provider_)); | 189 compositor->SetCompositorFrameSink(std::move(compositor_frame_sink)); |
| 190 compositor->SetOutputSurface(std::move(surface_output_surface)); | |
| 191 } else { | |
| 192 compositor->SetOutputSurface(std::move(display_output_surface)); | |
| 193 } | |
| 194 } | 190 } |
| 195 | 191 |
| 196 std::unique_ptr<Reflector> InProcessContextFactory::CreateReflector( | 192 std::unique_ptr<Reflector> InProcessContextFactory::CreateReflector( |
| 197 Compositor* mirrored_compositor, | 193 Compositor* mirrored_compositor, |
| 198 Layer* mirroring_layer) { | 194 Layer* mirroring_layer) { |
| 199 return base::WrapUnique(new FakeReflector); | 195 return base::WrapUnique(new FakeReflector); |
| 200 } | 196 } |
| 201 | 197 |
| 202 void InProcessContextFactory::RemoveReflector(Reflector* reflector) { | 198 void InProcessContextFactory::RemoveReflector(Reflector* reflector) { |
| 203 } | 199 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 267 |
| 272 void InProcessContextFactory::AddObserver(ContextFactoryObserver* observer) { | 268 void InProcessContextFactory::AddObserver(ContextFactoryObserver* observer) { |
| 273 observer_list_.AddObserver(observer); | 269 observer_list_.AddObserver(observer); |
| 274 } | 270 } |
| 275 | 271 |
| 276 void InProcessContextFactory::RemoveObserver(ContextFactoryObserver* observer) { | 272 void InProcessContextFactory::RemoveObserver(ContextFactoryObserver* observer) { |
| 277 observer_list_.RemoveObserver(observer); | 273 observer_list_.RemoveObserver(observer); |
| 278 } | 274 } |
| 279 | 275 |
| 280 } // namespace ui | 276 } // namespace ui |
| OLD | NEW |