Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: content/test/layouttest_support.cc

Issue 2162083005: Use surface copy requests for layout tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove DCHECK left over from debugging Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_test_proxy.h" 21 #include "components/test_runner/web_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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 171 }
171 172
172 void SetMockDeviceMotionData(const WebDeviceMotionData& data) { 173 void SetMockDeviceMotionData(const WebDeviceMotionData& data) {
173 RendererBlinkPlatformImpl::SetMockDeviceMotionDataForTesting(data); 174 RendererBlinkPlatformImpl::SetMockDeviceMotionDataForTesting(data);
174 } 175 }
175 176
176 void SetMockDeviceOrientationData(const WebDeviceOrientationData& data) { 177 void SetMockDeviceOrientationData(const WebDeviceOrientationData& data) {
177 RendererBlinkPlatformImpl::SetMockDeviceOrientationDataForTesting(data); 178 RendererBlinkPlatformImpl::SetMockDeviceOrientationDataForTesting(data);
178 } 179 }
179 180
181 namespace {
182
183 // Invokes a callback on commit (on the main thread) to obtain the output
184 // surface that should be used, then asks that output surface to submit the copy
185 // request at SwapBuffers time.
186 class CopyRequestSwapPromise : public cc::SwapPromise {
187 public:
188 using OutputSurfaceCallback =
danakj 2016/07/22 20:50:26 FindOutputSurfaceCallback?
jbroman 2016/07/25 18:50:55 Done.
189 base::Callback<base::WeakPtr<cc::TestDelegatingOutputSurface>()>;
190 CopyRequestSwapPromise(std::unique_ptr<cc::CopyOutputRequest> request,
191 OutputSurfaceCallback output_surface_callback)
192 : copy_request_(std::move(request)),
193 output_surface_callback_(std::move(output_surface_callback)) {}
194
195 // cc::SwapPromise
danakj 2016/07/22 20:50:27 "cc::SwapPromise implementation."
jbroman 2016/07/25 18:50:55 Done.
196 void OnCommit() override { output_surface_ = output_surface_callback_.Run(); }
197 void DidActivate() override {}
198 void DidSwap(cc::CompositorFrameMetadata*) override {
199 if (output_surface_)
danakj 2016/07/22 20:50:27 Is this ever going to be null in a layout test? Th
jbroman 2016/07/25 18:50:55 Fair enough. I don't think it can happen (and if i
200 output_surface_->RequestCopyOfOutput(std::move(copy_request_));
201 else
202 copy_request_->SendEmptyResult();
203 }
204 void DidNotSwap(DidNotSwapReason r) override {
205 copy_request_->SendEmptyResult();
danakj 2016/07/22 20:50:27 Does this happen outside of test flakiness?
jbroman 2016/07/25 18:50:55 I don't think so, aside from the bug I've already
206 }
207 int64_t TraceId() const override { return 0; }
208
209 private:
210 std::unique_ptr<cc::CopyOutputRequest> copy_request_;
211 OutputSurfaceCallback output_surface_callback_;
212 base::WeakPtr<cc::TestDelegatingOutputSurface> output_surface_;
213 };
214
215 } // namespace
216
180 class LayoutTestDependenciesImpl : public LayoutTestDependencies { 217 class LayoutTestDependenciesImpl : public LayoutTestDependencies {
181 public: 218 public:
182 std::unique_ptr<cc::OutputSurface> CreateOutputSurface( 219 std::unique_ptr<cc::OutputSurface> CreateOutputSurface(
220 int32_t routing_id,
183 scoped_refptr<gpu::GpuChannelHost> gpu_channel, 221 scoped_refptr<gpu::GpuChannelHost> gpu_channel,
184 scoped_refptr<cc::ContextProvider> compositor_context_provider, 222 scoped_refptr<cc::ContextProvider> compositor_context_provider,
185 scoped_refptr<cc::ContextProvider> worker_context_provider, 223 scoped_refptr<cc::ContextProvider> worker_context_provider,
186 CompositorDependencies* deps) override { 224 CompositorDependencies* deps) override {
187 // This is for an offscreen context for the compositor. So the default 225 // This is for an offscreen context for the compositor. So the default
188 // framebuffer doesn't need alpha, depth, stencil, antialiasing. 226 // framebuffer doesn't need alpha, depth, stencil, antialiasing.
189 gpu::gles2::ContextCreationAttribHelper attributes; 227 gpu::gles2::ContextCreationAttribHelper attributes;
190 attributes.alpha_size = -1; 228 attributes.alpha_size = -1;
191 attributes.depth_size = 0; 229 attributes.depth_size = 0;
192 attributes.stencil_size = 0; 230 attributes.stencil_size = 0;
(...skipping 19 matching lines...) Expand all
212 250
213 auto* task_runner = deps->GetCompositorImplThreadTaskRunner().get(); 251 auto* task_runner = deps->GetCompositorImplThreadTaskRunner().get();
214 bool synchronous_composite = !task_runner; 252 bool synchronous_composite = !task_runner;
215 if (!task_runner) 253 if (!task_runner)
216 task_runner = base::ThreadTaskRunnerHandle::Get().get(); 254 task_runner = base::ThreadTaskRunnerHandle::Get().get();
217 255
218 cc::LayerTreeSettings settings = 256 cc::LayerTreeSettings settings =
219 RenderWidgetCompositor::GenerateLayerTreeSettings( 257 RenderWidgetCompositor::GenerateLayerTreeSettings(
220 *base::CommandLine::ForCurrentProcess(), deps, 1.f); 258 *base::CommandLine::ForCurrentProcess(), deps, 1.f);
221 259
222 return base::MakeUnique<cc::TestDelegatingOutputSurface>( 260 auto output_surface = base::MakeUnique<cc::TestDelegatingOutputSurface>(
223 std::move(compositor_context_provider), 261 std::move(compositor_context_provider),
224 std::move(worker_context_provider), std::move(display_output_surface), 262 std::move(worker_context_provider), std::move(display_output_surface),
225 deps->GetSharedBitmapManager(), deps->GetGpuMemoryBufferManager(), 263 deps->GetSharedBitmapManager(), deps->GetGpuMemoryBufferManager(),
226 settings.renderer_settings, task_runner, synchronous_composite); 264 settings.renderer_settings, task_runner, synchronous_composite);
265 output_surfaces_[routing_id] = output_surface->GetWeakPtr();
266 return std::move(output_surface);
227 } 267 }
268
269 std::unique_ptr<cc::SwapPromise> RequestCopyOfOutput(
270 int32_t routing_id,
271 std::unique_ptr<cc::CopyOutputRequest> request) override {
272 // Note that we can't immediately check output_surfaces_, since it may not
273 // have been created yet. Instead, we wait until OnCommit to check what the
274 // last output surface to be requested was. This takes a raw pointer to
danakj 2016/07/22 20:50:26 "wait until OnCommit to find the currently active
jbroman 2016/07/25 18:50:55 Done.
275 // LayoutTestDependenciesImpl, so it must not be destroyed before commit.
danakj 2016/07/22 20:50:27 "so the dependencies must not" ("it" is ambiguous)
jbroman 2016/07/25 18:50:55 Done.
276 return base::MakeUnique<CopyRequestSwapPromise>(
277 std::move(request),
278 base::Bind(
279 [](const LayoutTestDependenciesImpl* self, int32_t routing_id) {
280 auto it = self->output_surfaces_.find(routing_id);
281 return it == self->output_surfaces_.end() ? nullptr : it->second;
282 },
283 this, routing_id));
284 }
285
286 private:
287 std::unordered_map<int32_t, base::WeakPtr<cc::TestDelegatingOutputSurface>>
288 output_surfaces_;
228 }; 289 };
229 290
230 void EnableRendererLayoutTestMode() { 291 void EnableRendererLayoutTestMode() {
231 RenderThreadImpl::current()->set_layout_test_dependencies( 292 RenderThreadImpl::current()->set_layout_test_dependencies(
232 base::MakeUnique<LayoutTestDependenciesImpl>()); 293 base::MakeUnique<LayoutTestDependenciesImpl>());
233 294
234 #if defined(OS_WIN) 295 #if defined(OS_WIN)
235 RegisterSideloadedTypefaces(SkFontMgr_New_DirectWrite()); 296 RegisterSideloadedTypefaces(SkFontMgr_New_DirectWrite());
236 #endif 297 #endif
237 } 298 }
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 return result; 555 return result;
495 } 556 }
496 557
497 void SchedulerRunIdleTasks(const base::Closure& callback) { 558 void SchedulerRunIdleTasks(const base::Closure& callback) {
498 scheduler::RendererScheduler* scheduler = 559 scheduler::RendererScheduler* scheduler =
499 content::RenderThreadImpl::current()->GetRendererScheduler(); 560 content::RenderThreadImpl::current()->GetRendererScheduler();
500 scheduler::RunIdleTasksForTesting(scheduler, callback); 561 scheduler::RunIdleTasksForTesting(scheduler, callback);
501 } 562 }
502 563
503 } // namespace content 564 } // namespace content
OLDNEW
« content/renderer/layout_test_dependencies.h ('K') | « content/renderer/render_widget.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698