| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/public/test/layouttest_support.h" | 5 #include "content/public/test/layouttest_support.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "cc/output/copy_output_request.h" |
| 15 #include "cc/test/pixel_test_output_surface.h" | 16 #include "cc/test/pixel_test_output_surface.h" |
| 16 #include "cc/test/test_delegating_output_surface.h" | 17 #include "cc/test/test_delegating_output_surface.h" |
| 17 #include "components/scheduler/test/renderer_scheduler_test_support.h" | 18 #include "components/scheduler/test/renderer_scheduler_test_support.h" |
| 18 #include "components/test_runner/test_common.h" | 19 #include "components/test_runner/test_common.h" |
| 19 #include "components/test_runner/web_frame_test_proxy.h" | 20 #include "components/test_runner/web_frame_test_proxy.h" |
| 20 #include "components/test_runner/web_view_test_proxy.h" | 21 #include "components/test_runner/web_view_test_proxy.h" |
| 21 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" | 22 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" |
| 22 #include "content/browser/renderer_host/render_process_host_impl.h" | 23 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 23 #include "content/browser/renderer_host/render_widget_host_impl.h" | 24 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 24 #include "content/common/gpu/client/context_provider_command_buffer.h" | 25 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 173 } |
| 173 | 174 |
| 174 void SetMockDeviceMotionData(const WebDeviceMotionData& data) { | 175 void SetMockDeviceMotionData(const WebDeviceMotionData& data) { |
| 175 RendererBlinkPlatformImpl::SetMockDeviceMotionDataForTesting(data); | 176 RendererBlinkPlatformImpl::SetMockDeviceMotionDataForTesting(data); |
| 176 } | 177 } |
| 177 | 178 |
| 178 void SetMockDeviceOrientationData(const WebDeviceOrientationData& data) { | 179 void SetMockDeviceOrientationData(const WebDeviceOrientationData& data) { |
| 179 RendererBlinkPlatformImpl::SetMockDeviceOrientationDataForTesting(data); | 180 RendererBlinkPlatformImpl::SetMockDeviceOrientationDataForTesting(data); |
| 180 } | 181 } |
| 181 | 182 |
| 183 namespace { |
| 184 |
| 185 // Invokes a callback on commit (on the main thread) to obtain the output |
| 186 // surface that should be used, then asks that output surface to submit the copy |
| 187 // request at SwapBuffers time. |
| 188 class CopyRequestSwapPromise : public cc::SwapPromise { |
| 189 public: |
| 190 using FindOutputSurfaceCallback = |
| 191 base::Callback<cc::TestDelegatingOutputSurface*()>; |
| 192 CopyRequestSwapPromise(std::unique_ptr<cc::CopyOutputRequest> request, |
| 193 FindOutputSurfaceCallback output_surface_callback) |
| 194 : copy_request_(std::move(request)), |
| 195 output_surface_callback_(std::move(output_surface_callback)) {} |
| 196 |
| 197 // cc::SwapPromise implementation. |
| 198 void OnCommit() override { |
| 199 output_surface_from_commit_ = output_surface_callback_.Run(); |
| 200 DCHECK(output_surface_from_commit_); |
| 201 } |
| 202 void DidActivate() override {} |
| 203 void DidSwap(cc::CompositorFrameMetadata*) override { |
| 204 output_surface_from_commit_->RequestCopyOfOutput(std::move(copy_request_)); |
| 205 } |
| 206 void DidNotSwap(DidNotSwapReason r) override { |
| 207 // The compositor should always swap in layout test mode. |
| 208 NOTREACHED() << "did not swap for reason " << r; |
| 209 } |
| 210 int64_t TraceId() const override { return 0; } |
| 211 |
| 212 private: |
| 213 std::unique_ptr<cc::CopyOutputRequest> copy_request_; |
| 214 FindOutputSurfaceCallback output_surface_callback_; |
| 215 cc::TestDelegatingOutputSurface* output_surface_from_commit_ = nullptr; |
| 216 }; |
| 217 |
| 218 } // namespace |
| 219 |
| 182 class LayoutTestDependenciesImpl : public LayoutTestDependencies { | 220 class LayoutTestDependenciesImpl : public LayoutTestDependencies { |
| 183 public: | 221 public: |
| 184 std::unique_ptr<cc::OutputSurface> CreateOutputSurface( | 222 std::unique_ptr<cc::OutputSurface> CreateOutputSurface( |
| 223 int32_t routing_id, |
| 185 scoped_refptr<gpu::GpuChannelHost> gpu_channel, | 224 scoped_refptr<gpu::GpuChannelHost> gpu_channel, |
| 186 scoped_refptr<cc::ContextProvider> compositor_context_provider, | 225 scoped_refptr<cc::ContextProvider> compositor_context_provider, |
| 187 scoped_refptr<cc::ContextProvider> worker_context_provider, | 226 scoped_refptr<cc::ContextProvider> worker_context_provider, |
| 188 CompositorDependencies* deps) override { | 227 CompositorDependencies* deps) override { |
| 189 // This is for an offscreen context for the compositor. So the default | 228 // This is for an offscreen context for the compositor. So the default |
| 190 // framebuffer doesn't need alpha, depth, stencil, antialiasing. | 229 // framebuffer doesn't need alpha, depth, stencil, antialiasing. |
| 191 gpu::gles2::ContextCreationAttribHelper attributes; | 230 gpu::gles2::ContextCreationAttribHelper attributes; |
| 192 attributes.alpha_size = -1; | 231 attributes.alpha_size = -1; |
| 193 attributes.depth_size = 0; | 232 attributes.depth_size = 0; |
| 194 attributes.stencil_size = 0; | 233 attributes.stencil_size = 0; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 214 | 253 |
| 215 auto* task_runner = deps->GetCompositorImplThreadTaskRunner().get(); | 254 auto* task_runner = deps->GetCompositorImplThreadTaskRunner().get(); |
| 216 bool synchronous_composite = !task_runner; | 255 bool synchronous_composite = !task_runner; |
| 217 if (!task_runner) | 256 if (!task_runner) |
| 218 task_runner = base::ThreadTaskRunnerHandle::Get().get(); | 257 task_runner = base::ThreadTaskRunnerHandle::Get().get(); |
| 219 | 258 |
| 220 cc::LayerTreeSettings settings = | 259 cc::LayerTreeSettings settings = |
| 221 RenderWidgetCompositor::GenerateLayerTreeSettings( | 260 RenderWidgetCompositor::GenerateLayerTreeSettings( |
| 222 *base::CommandLine::ForCurrentProcess(), deps, 1.f); | 261 *base::CommandLine::ForCurrentProcess(), deps, 1.f); |
| 223 | 262 |
| 224 return base::MakeUnique<cc::TestDelegatingOutputSurface>( | 263 auto output_surface = base::MakeUnique<cc::TestDelegatingOutputSurface>( |
| 225 std::move(compositor_context_provider), | 264 std::move(compositor_context_provider), |
| 226 std::move(worker_context_provider), std::move(display_output_surface), | 265 std::move(worker_context_provider), std::move(display_output_surface), |
| 227 deps->GetSharedBitmapManager(), deps->GetGpuMemoryBufferManager(), | 266 deps->GetSharedBitmapManager(), deps->GetGpuMemoryBufferManager(), |
| 228 settings.renderer_settings, task_runner, synchronous_composite); | 267 settings.renderer_settings, task_runner, synchronous_composite); |
| 268 output_surfaces_[routing_id] = output_surface.get(); |
| 269 return std::move(output_surface); |
| 229 } | 270 } |
| 271 |
| 272 std::unique_ptr<cc::SwapPromise> RequestCopyOfOutput( |
| 273 int32_t routing_id, |
| 274 std::unique_ptr<cc::CopyOutputRequest> request) override { |
| 275 // Note that we can't immediately check output_surfaces_, since it may not |
| 276 // have been created yet. Instead, we wait until OnCommit to find the |
| 277 // currently active OutputSurface for the given RenderWidget routing_id. |
| 278 return base::MakeUnique<CopyRequestSwapPromise>( |
| 279 std::move(request), |
| 280 base::Bind( |
| 281 &LayoutTestDependenciesImpl::FindOutputSurface, |
| 282 // |this| will still be valid, because its lifetime is tied to |
| 283 // RenderThreadImpl, which outlives layout test execution. |
| 284 base::Unretained(this), routing_id)); |
| 285 } |
| 286 |
| 287 private: |
| 288 cc::TestDelegatingOutputSurface* FindOutputSurface(int32_t routing_id) { |
| 289 auto it = output_surfaces_.find(routing_id); |
| 290 return it == output_surfaces_.end() ? nullptr : it->second; |
| 291 } |
| 292 |
| 293 // Entries are not removed, so this map can grow. However, it is only used in |
| 294 // layout tests, so this memory usage does not occur in production. |
| 295 // Entries in this map will outlive the output surface, because this object is |
| 296 // owned by RenderThreadImpl, which outlives layout test execution. |
| 297 std::unordered_map<int32_t, cc::TestDelegatingOutputSurface*> |
| 298 output_surfaces_; |
| 230 }; | 299 }; |
| 231 | 300 |
| 232 void EnableRendererLayoutTestMode() { | 301 void EnableRendererLayoutTestMode() { |
| 233 RenderThreadImpl::current()->set_layout_test_dependencies( | 302 RenderThreadImpl::current()->set_layout_test_dependencies( |
| 234 base::MakeUnique<LayoutTestDependenciesImpl>()); | 303 base::MakeUnique<LayoutTestDependenciesImpl>()); |
| 235 | 304 |
| 236 #if defined(OS_WIN) | 305 #if defined(OS_WIN) |
| 237 RegisterSideloadedTypefaces(SkFontMgr_New_DirectWrite()); | 306 RegisterSideloadedTypefaces(SkFontMgr_New_DirectWrite()); |
| 238 #endif | 307 #endif |
| 239 } | 308 } |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 return result; | 569 return result; |
| 501 } | 570 } |
| 502 | 571 |
| 503 void SchedulerRunIdleTasks(const base::Closure& callback) { | 572 void SchedulerRunIdleTasks(const base::Closure& callback) { |
| 504 scheduler::RendererScheduler* scheduler = | 573 scheduler::RendererScheduler* scheduler = |
| 505 content::RenderThreadImpl::current()->GetRendererScheduler(); | 574 content::RenderThreadImpl::current()->GetRendererScheduler(); |
| 506 scheduler::RunIdleTasksForTesting(scheduler, callback); | 575 scheduler::RunIdleTasksForTesting(scheduler, callback); |
| 507 } | 576 } |
| 508 | 577 |
| 509 } // namespace content | 578 } // namespace content |
| OLD | NEW |