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

Side by Side Diff: cc/test/test_delegating_output_surface.cc

Issue 2161323002: cc: Make LayerTreeHostImpl unittests use a delegating output surface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "cc/test/test_delegating_output_surface.h" 5 #include "cc/test/test_delegating_output_surface.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "cc/output/begin_frame_args.h" 10 #include "cc/output/begin_frame_args.h"
11 #include "cc/output/texture_mailbox_deleter.h"
11 #include "cc/test/begin_frame_args_test.h" 12 #include "cc/test/begin_frame_args_test.h"
12 13
13 static constexpr uint32_t kCompositorClientId = 1; 14 static constexpr uint32_t kCompositorClientId = 1;
14 15
15 namespace cc { 16 namespace cc {
16 17
17 TestDelegatingOutputSurface::TestDelegatingOutputSurface( 18 TestDelegatingOutputSurface::TestDelegatingOutputSurface(
18 scoped_refptr<ContextProvider> compositor_context_provider, 19 scoped_refptr<ContextProvider> compositor_context_provider,
19 scoped_refptr<ContextProvider> worker_context_provider, 20 scoped_refptr<ContextProvider> worker_context_provider,
20 std::unique_ptr<Display> display, 21 std::unique_ptr<OutputSurface> display_output_surface,
21 bool context_shared_with_compositor, 22 SharedBitmapManager* shared_bitmap_manager,
22 bool allow_force_reclaim_resources) 23 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
24 const RendererSettings& renderer_settings,
25 base::SingleThreadTaskRunner* task_runner,
26 bool synchronous_composite)
23 : OutputSurface(std::move(compositor_context_provider), 27 : OutputSurface(std::move(compositor_context_provider),
24 std::move(worker_context_provider), 28 std::move(worker_context_provider),
25 nullptr), 29 nullptr),
26 surface_manager_(new SurfaceManager), 30 surface_manager_(new SurfaceManager),
27 surface_id_allocator_(new SurfaceIdAllocator(kCompositorClientId)), 31 surface_id_allocator_(new SurfaceIdAllocator(kCompositorClientId)),
28 surface_factory_(new SurfaceFactory(surface_manager_.get(), this)), 32 surface_factory_(new SurfaceFactory(surface_manager_.get(), this)),
29 display_(std::move(display)),
30 weak_ptrs_(this) { 33 weak_ptrs_(this) {
31 CHECK(display_); 34 std::unique_ptr<SyntheticBeginFrameSource> begin_frame_source;
35 std::unique_ptr<DisplayScheduler> scheduler;
36 if (!synchronous_composite) {
37 begin_frame_source.reset(new DelayBasedBeginFrameSource(
38 base::MakeUnique<DelayBasedTimeSource>(task_runner)));
39 scheduler.reset(new DisplayScheduler(
40 begin_frame_source.get(), task_runner,
41 display_output_surface->capabilities().max_frames_pending));
42 }
43 const bool context_shared_with_compositor =
44 display_output_surface->context_provider() == context_provider();
45 display_ = base::MakeUnique<Display>(
vmpstr 2016/07/19 23:27:02 display_.reset(new Display(
danakj 2016/07/20 01:03:25 Done.
46 shared_bitmap_manager, gpu_memory_buffer_manager, renderer_settings,
47 std::move(begin_frame_source), std::move(display_output_surface),
48 std::move(scheduler),
49 base::MakeUnique<TextureMailboxDeleter>(task_runner)),
50
32 capabilities_.delegated_rendering = true; 51 capabilities_.delegated_rendering = true;
33 capabilities_.can_force_reclaim_resources = allow_force_reclaim_resources; 52 // Since this OutputSurface and the Display are tightly coupled and in the
vmpstr 2016/07/19 23:27:02 This isn't a complete sentence? Or am I parsing it
danakj 2016/07/20 01:03:25 Done.
53 // same process/thread.
54 capabilities_.can_force_reclaim_resources = true;
34 capabilities_.delegated_sync_points_required = 55 capabilities_.delegated_sync_points_required =
35 !context_shared_with_compositor; 56 !context_shared_with_compositor;
36 57
37 surface_id_allocator_->RegisterSurfaceClientId(surface_manager_.get()); 58 surface_id_allocator_->RegisterSurfaceClientId(surface_manager_.get());
38 } 59 }
39 60
40 TestDelegatingOutputSurface::~TestDelegatingOutputSurface() {} 61 TestDelegatingOutputSurface::~TestDelegatingOutputSurface() {}
41 62
42 bool TestDelegatingOutputSurface::BindToClient(OutputSurfaceClient* client) { 63 bool TestDelegatingOutputSurface::BindToClient(OutputSurfaceClient* client) {
43 if (!OutputSurface::BindToClient(client)) 64 if (!OutputSurface::BindToClient(client))
44 return false; 65 return false;
45 66
46 // We want the Display's output surface to hear about lost context, and since 67 // We want the Display's output surface to hear about lost context, and since
47 // this shares a context with it (when delegated_sync_points_required is 68 // this shares a context with it (when delegated_sync_points_required is
48 // false), we should not be listening for lost context callbacks on the 69 // false), we should not be listening for lost context callbacks on the
49 // context here. 70 // context here.
50 if (!capabilities_.delegated_sync_points_required && context_provider()) 71 if (!capabilities_.delegated_sync_points_required && context_provider())
51 context_provider()->SetLostContextCallback(base::Closure()); 72 context_provider()->SetLostContextCallback(base::Closure());
52 73
53 surface_manager_->RegisterSurfaceFactoryClient( 74 surface_manager_->RegisterSurfaceFactoryClient(
54 surface_id_allocator_->client_id(), this); 75 surface_id_allocator_->client_id(), this);
55 display_->Initialize(&display_client_, surface_manager_.get(), 76 display_->Initialize(this, surface_manager_.get(),
56 surface_id_allocator_->client_id()); 77 surface_id_allocator_->client_id());
78 bound_ = true;
57 return true; 79 return true;
58 } 80 }
59 81
60 void TestDelegatingOutputSurface::DetachFromClient() { 82 void TestDelegatingOutputSurface::DetachFromClient() {
61 if (!delegated_surface_id_.is_null()) 83 // Some tests make BindToClient fail on purpose. ^__^
62 surface_factory_->Destroy(delegated_surface_id_); 84 if (bound_) {
63 surface_manager_->UnregisterSurfaceFactoryClient( 85 if (!delegated_surface_id_.is_null())
64 surface_id_allocator_->client_id()); 86 surface_factory_->Destroy(delegated_surface_id_);
65 87 surface_manager_->UnregisterSurfaceFactoryClient(
88 surface_id_allocator_->client_id());
89 }
vmpstr 2016/07/19 23:27:02 bound_ = false; for posterity?
danakj 2016/07/20 01:03:25 Done.
66 display_ = nullptr; 90 display_ = nullptr;
67 surface_factory_ = nullptr; 91 surface_factory_ = nullptr;
68 surface_id_allocator_ = nullptr; 92 surface_id_allocator_ = nullptr;
69 surface_manager_ = nullptr; 93 surface_manager_ = nullptr;
70 weak_ptrs_.InvalidateWeakPtrs(); 94 weak_ptrs_.InvalidateWeakPtrs();
71 OutputSurface::DetachFromClient(); 95 OutputSurface::DetachFromClient();
72 } 96 }
73 97
74 void TestDelegatingOutputSurface::SwapBuffers(CompositorFrame frame) { 98 void TestDelegatingOutputSurface::SwapBuffers(CompositorFrame frame) {
75 if (delegated_surface_id_.is_null()) { 99 if (delegated_surface_id_.is_null()) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void TestDelegatingOutputSurface::ReturnResources( 143 void TestDelegatingOutputSurface::ReturnResources(
120 const ReturnedResourceArray& resources) { 144 const ReturnedResourceArray& resources) {
121 client_->ReclaimResources(resources); 145 client_->ReclaimResources(resources);
122 } 146 }
123 147
124 void TestDelegatingOutputSurface::SetBeginFrameSource( 148 void TestDelegatingOutputSurface::SetBeginFrameSource(
125 BeginFrameSource* begin_frame_source) { 149 BeginFrameSource* begin_frame_source) {
126 client_->SetBeginFrameSource(begin_frame_source); 150 client_->SetBeginFrameSource(begin_frame_source);
127 } 151 }
128 152
153 void TestDelegatingOutputSurface::DisplayOutputSurfaceLost() {
154 DidLoseOutputSurface();
155 }
156
157 void TestDelegatingOutputSurface::DisplaySetMemoryPolicy(
158 const ManagedMemoryPolicy& policy) {
159 SetMemoryPolicy(policy);
160 }
161
129 } // namespace cc 162 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698