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

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: danakj nits, inc. using raw ptr Created 4 years, 4 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
« no previous file with comments | « content/renderer/render_widget.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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
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_ = output_surface_callback_.Run();
200 DCHECK(output_surface_);
201 }
202 void DidActivate() override {}
203 void DidSwap(cc::CompositorFrameMetadata*) override {
204 output_surface_->RequestCopyOfOutput(std::move(copy_request_));
205 }
206 void DidNotSwap(DidNotSwapReason r) override {
207 // The compositor should always swap in layout test mode.
208 DCHECK(false) << "did not swap for reason " << r;
danakj 2016/07/25 21:16:28 nit: DCHECK(false) == NOTREACHED() (except on chro
jbroman 2016/07/25 21:47:45 Done.
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_ = nullptr;
danakj 2016/07/25 21:16:28 nit: output_surface_from_commit_ would document th
jbroman 2016/07/25 21:47:45 OK. This class is small enough that it's hard to m
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
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 // LayoutTestDependenciesImpl will still be valid, because its lifetime is
279 // tied to RenderThreadImpl, which outlives layout test execution.
280 return base::MakeUnique<CopyRequestSwapPromise>(
281 std::move(request),
282 base::Bind(
283 [](const LayoutTestDependenciesImpl* self, int32_t routing_id) {
danakj 2016/07/25 21:16:28 nit: I think I marginally prefer this be a private
jbroman 2016/07/25 21:47:45 As you command.
284 auto it = self->output_surfaces_.find(routing_id);
285 return it == self->output_surfaces_.end() ? nullptr : it->second;
286 },
287 this, routing_id));
288 }
289
290 private:
291 std::unordered_map<int32_t, cc::TestDelegatingOutputSurface*>
292 output_surfaces_;
230 }; 293 };
231 294
232 void EnableRendererLayoutTestMode() { 295 void EnableRendererLayoutTestMode() {
233 RenderThreadImpl::current()->set_layout_test_dependencies( 296 RenderThreadImpl::current()->set_layout_test_dependencies(
234 base::MakeUnique<LayoutTestDependenciesImpl>()); 297 base::MakeUnique<LayoutTestDependenciesImpl>());
235 298
236 #if defined(OS_WIN) 299 #if defined(OS_WIN)
237 RegisterSideloadedTypefaces(SkFontMgr_New_DirectWrite()); 300 RegisterSideloadedTypefaces(SkFontMgr_New_DirectWrite());
238 #endif 301 #endif
239 } 302 }
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 return result; 563 return result;
501 } 564 }
502 565
503 void SchedulerRunIdleTasks(const base::Closure& callback) { 566 void SchedulerRunIdleTasks(const base::Closure& callback) {
504 scheduler::RendererScheduler* scheduler = 567 scheduler::RendererScheduler* scheduler =
505 content::RenderThreadImpl::current()->GetRendererScheduler(); 568 content::RenderThreadImpl::current()->GetRendererScheduler();
506 scheduler::RunIdleTasksForTesting(scheduler, callback); 569 scheduler::RunIdleTasksForTesting(scheduler, callback);
507 } 570 }
508 571
509 } // namespace content 572 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_widget.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698