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

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

Issue 2337913003: Fork cc::OutputSurface into cc::CompositorFrameSink. (Closed)
Patch Set: cfsfork: android-vulkan Created 4 years, 3 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') | content/test/test_render_view_host.h » ('j') | 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/output/copy_output_request.h"
16 #include "cc/test/pixel_test_output_surface.h" 16 #include "cc/test/pixel_test_output_surface.h"
17 #include "cc/test/test_delegating_output_surface.h" 17 #include "cc/test/test_compositor_frame_sink.h"
18 #include "components/test_runner/test_common.h" 18 #include "components/test_runner/test_common.h"
19 #include "components/test_runner/web_frame_test_proxy.h" 19 #include "components/test_runner/web_frame_test_proxy.h"
20 #include "components/test_runner/web_view_test_proxy.h" 20 #include "components/test_runner/web_view_test_proxy.h"
21 #include "components/test_runner/web_widget_test_proxy.h" 21 #include "components/test_runner/web_widget_test_proxy.h"
22 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" 22 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h"
23 #include "content/browser/renderer_host/render_process_host_impl.h" 23 #include "content/browser/renderer_host/render_process_host_impl.h"
24 #include "content/browser/renderer_host/render_widget_host_impl.h" 24 #include "content/browser/renderer_host/render_widget_host_impl.h"
25 #include "content/common/gpu/client/context_provider_command_buffer.h" 25 #include "content/common/gpu/client/context_provider_command_buffer.h"
26 #include "content/common/site_isolation_policy.h" 26 #include "content/common/site_isolation_policy.h"
27 #include "content/public/common/page_state.h" 27 #include "content/public/common/page_state.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 RendererBlinkPlatformImpl::SetMockDeviceOrientationDataForTesting(data); 219 RendererBlinkPlatformImpl::SetMockDeviceOrientationDataForTesting(data);
220 } 220 }
221 221
222 namespace { 222 namespace {
223 223
224 // Invokes a callback on commit (on the main thread) to obtain the output 224 // Invokes a callback on commit (on the main thread) to obtain the output
225 // surface that should be used, then asks that output surface to submit the copy 225 // surface that should be used, then asks that output surface to submit the copy
226 // request at SwapBuffers time. 226 // request at SwapBuffers time.
227 class CopyRequestSwapPromise : public cc::SwapPromise { 227 class CopyRequestSwapPromise : public cc::SwapPromise {
228 public: 228 public:
229 using FindOutputSurfaceCallback = 229 using FindCompositorFrameSinkCallback =
230 base::Callback<cc::TestDelegatingOutputSurface*()>; 230 base::Callback<cc::TestCompositorFrameSink*()>;
231 CopyRequestSwapPromise(std::unique_ptr<cc::CopyOutputRequest> request, 231 CopyRequestSwapPromise(
232 FindOutputSurfaceCallback output_surface_callback) 232 std::unique_ptr<cc::CopyOutputRequest> request,
233 FindCompositorFrameSinkCallback find_compositor_frame_sink_callback)
233 : copy_request_(std::move(request)), 234 : copy_request_(std::move(request)),
234 output_surface_callback_(std::move(output_surface_callback)) {} 235 find_compositor_frame_sink_callback_(
236 std::move(find_compositor_frame_sink_callback)) {}
235 237
236 // cc::SwapPromise implementation. 238 // cc::SwapPromise implementation.
237 void OnCommit() override { 239 void OnCommit() override {
238 output_surface_from_commit_ = output_surface_callback_.Run(); 240 compositor_frame_sink_from_commit_ =
239 DCHECK(output_surface_from_commit_); 241 find_compositor_frame_sink_callback_.Run();
242 DCHECK(compositor_frame_sink_from_commit_);
240 } 243 }
241 void DidActivate() override {} 244 void DidActivate() override {}
242 void DidSwap(cc::CompositorFrameMetadata*) override { 245 void DidSwap(cc::CompositorFrameMetadata*) override {
243 output_surface_from_commit_->RequestCopyOfOutput(std::move(copy_request_)); 246 compositor_frame_sink_from_commit_->RequestCopyOfOutput(
247 std::move(copy_request_));
244 } 248 }
245 DidNotSwapAction DidNotSwap(DidNotSwapReason r) override { 249 DidNotSwapAction DidNotSwap(DidNotSwapReason r) override {
246 // The compositor should always swap in layout test mode. 250 // The compositor should always swap in layout test mode.
247 NOTREACHED() << "did not swap for reason " << r; 251 NOTREACHED() << "did not swap for reason " << r;
248 return DidNotSwapAction::BREAK_PROMISE; 252 return DidNotSwapAction::BREAK_PROMISE;
249 } 253 }
250 int64_t TraceId() const override { return 0; } 254 int64_t TraceId() const override { return 0; }
251 255
252 private: 256 private:
253 std::unique_ptr<cc::CopyOutputRequest> copy_request_; 257 std::unique_ptr<cc::CopyOutputRequest> copy_request_;
254 FindOutputSurfaceCallback output_surface_callback_; 258 FindCompositorFrameSinkCallback find_compositor_frame_sink_callback_;
255 cc::TestDelegatingOutputSurface* output_surface_from_commit_ = nullptr; 259 cc::TestCompositorFrameSink* compositor_frame_sink_from_commit_ = nullptr;
256 }; 260 };
257 261
258 } // namespace 262 } // namespace
259 263
260 class LayoutTestDependenciesImpl : public LayoutTestDependencies { 264 class LayoutTestDependenciesImpl : public LayoutTestDependencies {
261 public: 265 public:
262 std::unique_ptr<cc::OutputSurface> CreateOutputSurface( 266 std::unique_ptr<cc::CompositorFrameSink> CreateCompositorFrameSink(
263 int32_t routing_id, 267 int32_t routing_id,
264 scoped_refptr<gpu::GpuChannelHost> gpu_channel, 268 scoped_refptr<gpu::GpuChannelHost> gpu_channel,
265 scoped_refptr<cc::ContextProvider> compositor_context_provider, 269 scoped_refptr<cc::ContextProvider> compositor_context_provider,
266 scoped_refptr<cc::ContextProvider> worker_context_provider, 270 scoped_refptr<cc::ContextProvider> worker_context_provider,
267 CompositorDependencies* deps) override { 271 CompositorDependencies* deps) override {
268 // This is for an offscreen context for the compositor. So the default 272 // This is for an offscreen context for the compositor. So the default
269 // framebuffer doesn't need alpha, depth, stencil, antialiasing. 273 // framebuffer doesn't need alpha, depth, stencil, antialiasing.
270 gpu::gles2::ContextCreationAttribHelper attributes; 274 gpu::gles2::ContextCreationAttribHelper attributes;
271 attributes.alpha_size = -1; 275 attributes.alpha_size = -1;
272 attributes.depth_size = 0; 276 attributes.depth_size = 0;
(...skipping 20 matching lines...) Expand all
293 297
294 auto* task_runner = deps->GetCompositorImplThreadTaskRunner().get(); 298 auto* task_runner = deps->GetCompositorImplThreadTaskRunner().get();
295 bool synchronous_composite = !task_runner; 299 bool synchronous_composite = !task_runner;
296 if (!task_runner) 300 if (!task_runner)
297 task_runner = base::ThreadTaskRunnerHandle::Get().get(); 301 task_runner = base::ThreadTaskRunnerHandle::Get().get();
298 302
299 cc::LayerTreeSettings settings = 303 cc::LayerTreeSettings settings =
300 RenderWidgetCompositor::GenerateLayerTreeSettings( 304 RenderWidgetCompositor::GenerateLayerTreeSettings(
301 *base::CommandLine::ForCurrentProcess(), deps, 1.f); 305 *base::CommandLine::ForCurrentProcess(), deps, 1.f);
302 306
303 auto output_surface = base::MakeUnique<cc::TestDelegatingOutputSurface>( 307 auto compositor_frame_sink = base::MakeUnique<cc::TestCompositorFrameSink>(
304 std::move(compositor_context_provider), 308 std::move(compositor_context_provider),
305 std::move(worker_context_provider), std::move(display_output_surface), 309 std::move(worker_context_provider), std::move(display_output_surface),
306 deps->GetSharedBitmapManager(), deps->GetGpuMemoryBufferManager(), 310 deps->GetSharedBitmapManager(), deps->GetGpuMemoryBufferManager(),
307 settings.renderer_settings, task_runner, synchronous_composite, 311 settings.renderer_settings, task_runner, synchronous_composite,
308 false /* force_disable_reclaim_resources */); 312 false /* force_disable_reclaim_resources */);
309 output_surfaces_[routing_id] = output_surface.get(); 313 compositor_frame_sinks_[routing_id] = compositor_frame_sink.get();
310 return std::move(output_surface); 314 return std::move(compositor_frame_sink);
311 } 315 }
312 316
313 std::unique_ptr<cc::SwapPromise> RequestCopyOfOutput( 317 std::unique_ptr<cc::SwapPromise> RequestCopyOfOutput(
314 int32_t routing_id, 318 int32_t routing_id,
315 std::unique_ptr<cc::CopyOutputRequest> request) override { 319 std::unique_ptr<cc::CopyOutputRequest> request) override {
316 // Note that we can't immediately check output_surfaces_, since it may not 320 // Note that we can't immediately check compositor_frame_sinks_, since it
317 // have been created yet. Instead, we wait until OnCommit to find the 321 // may not have been created yet. Instead, we wait until OnCommit to find
318 // currently active OutputSurface for the given RenderWidget routing_id. 322 // the currently active CompositorFrameSink for the given RenderWidget
323 // routing_id.
319 return base::MakeUnique<CopyRequestSwapPromise>( 324 return base::MakeUnique<CopyRequestSwapPromise>(
320 std::move(request), 325 std::move(request),
321 base::Bind( 326 base::Bind(
322 &LayoutTestDependenciesImpl::FindOutputSurface, 327 &LayoutTestDependenciesImpl::FindCompositorFrameSink,
323 // |this| will still be valid, because its lifetime is tied to 328 // |this| will still be valid, because its lifetime is tied to
324 // RenderThreadImpl, which outlives layout test execution. 329 // RenderThreadImpl, which outlives layout test execution.
325 base::Unretained(this), routing_id)); 330 base::Unretained(this), routing_id));
326 } 331 }
327 332
328 private: 333 private:
329 cc::TestDelegatingOutputSurface* FindOutputSurface(int32_t routing_id) { 334 cc::TestCompositorFrameSink* FindCompositorFrameSink(int32_t routing_id) {
330 auto it = output_surfaces_.find(routing_id); 335 auto it = compositor_frame_sinks_.find(routing_id);
331 return it == output_surfaces_.end() ? nullptr : it->second; 336 return it == compositor_frame_sinks_.end() ? nullptr : it->second;
332 } 337 }
333 338
334 // Entries are not removed, so this map can grow. However, it is only used in 339 // Entries are not removed, so this map can grow. However, it is only used in
335 // layout tests, so this memory usage does not occur in production. 340 // layout tests, so this memory usage does not occur in production.
336 // Entries in this map will outlive the output surface, because this object is 341 // Entries in this map will outlive the output surface, because this object is
337 // owned by RenderThreadImpl, which outlives layout test execution. 342 // owned by RenderThreadImpl, which outlives layout test execution.
338 std::unordered_map<int32_t, cc::TestDelegatingOutputSurface*> 343 std::unordered_map<int32_t, cc::TestCompositorFrameSink*>
339 output_surfaces_; 344 compositor_frame_sinks_;
340 }; 345 };
341 346
342 void EnableRendererLayoutTestMode() { 347 void EnableRendererLayoutTestMode() {
343 RenderThreadImpl::current()->set_layout_test_dependencies( 348 RenderThreadImpl::current()->set_layout_test_dependencies(
344 base::MakeUnique<LayoutTestDependenciesImpl>()); 349 base::MakeUnique<LayoutTestDependenciesImpl>());
345 350
346 #if defined(OS_WIN) 351 #if defined(OS_WIN)
347 RegisterSideloadedTypefaces(SkFontMgr_New_DirectWrite()); 352 RegisterSideloadedTypefaces(SkFontMgr_New_DirectWrite());
348 #endif 353 #endif
349 } 354 }
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 return result; 1033 return result;
1029 } 1034 }
1030 1035
1031 void SchedulerRunIdleTasks(const base::Closure& callback) { 1036 void SchedulerRunIdleTasks(const base::Closure& callback) {
1032 blink::scheduler::RendererScheduler* scheduler = 1037 blink::scheduler::RendererScheduler* scheduler =
1033 content::RenderThreadImpl::current()->GetRendererScheduler(); 1038 content::RenderThreadImpl::current()->GetRendererScheduler();
1034 blink::scheduler::RunIdleTasksForTesting(scheduler, callback); 1039 blink::scheduler::RunIdleTasksForTesting(scheduler, callback);
1035 } 1040 }
1036 1041
1037 } // namespace content 1042 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_widget.cc ('k') | content/test/test_render_view_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698