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

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: display-lthi-tests: . 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
« no previous file with comments | « cc/test/test_delegating_output_surface.h ('k') | cc/test/test_gles2_interface.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 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_.reset(
46 new Display(shared_bitmap_manager, gpu_memory_buffer_manager,
47 renderer_settings, std::move(begin_frame_source),
48 std::move(display_output_surface), 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
53 // same process/thread, the LayerTreeHostImpl can reclaim resources from
54 // the Display.
55 capabilities_.can_force_reclaim_resources = true;
34 capabilities_.delegated_sync_points_required = 56 capabilities_.delegated_sync_points_required =
35 !context_shared_with_compositor; 57 !context_shared_with_compositor;
36 58
37 surface_id_allocator_->RegisterSurfaceClientId(surface_manager_.get()); 59 surface_id_allocator_->RegisterSurfaceClientId(surface_manager_.get());
38 } 60 }
39 61
40 TestDelegatingOutputSurface::~TestDelegatingOutputSurface() {} 62 TestDelegatingOutputSurface::~TestDelegatingOutputSurface() {}
41 63
42 bool TestDelegatingOutputSurface::BindToClient(OutputSurfaceClient* client) { 64 bool TestDelegatingOutputSurface::BindToClient(OutputSurfaceClient* client) {
43 if (!OutputSurface::BindToClient(client)) 65 if (!OutputSurface::BindToClient(client))
44 return false; 66 return false;
45 67
46 // We want the Display's output surface to hear about lost context, and since 68 // 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 69 // 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 70 // false), we should not be listening for lost context callbacks on the
49 // context here. 71 // context here.
50 if (!capabilities_.delegated_sync_points_required && context_provider()) 72 if (!capabilities_.delegated_sync_points_required && context_provider())
51 context_provider()->SetLostContextCallback(base::Closure()); 73 context_provider()->SetLostContextCallback(base::Closure());
52 74
53 surface_manager_->RegisterSurfaceFactoryClient( 75 surface_manager_->RegisterSurfaceFactoryClient(
54 surface_id_allocator_->client_id(), this); 76 surface_id_allocator_->client_id(), this);
55 display_->Initialize(&display_client_, surface_manager_.get(), 77 display_->Initialize(this, surface_manager_.get(),
56 surface_id_allocator_->client_id()); 78 surface_id_allocator_->client_id());
79 bound_ = true;
57 return true; 80 return true;
58 } 81 }
59 82
60 void TestDelegatingOutputSurface::DetachFromClient() { 83 void TestDelegatingOutputSurface::DetachFromClient() {
61 if (!delegated_surface_id_.is_null()) 84 // Some tests make BindToClient fail on purpose. ^__^
62 surface_factory_->Destroy(delegated_surface_id_); 85 if (bound_) {
63 surface_manager_->UnregisterSurfaceFactoryClient( 86 if (!delegated_surface_id_.is_null())
64 surface_id_allocator_->client_id()); 87 surface_factory_->Destroy(delegated_surface_id_);
65 88 surface_manager_->UnregisterSurfaceFactoryClient(
89 surface_id_allocator_->client_id());
90 bound_ = false;
91 }
66 display_ = nullptr; 92 display_ = nullptr;
67 surface_factory_ = nullptr; 93 surface_factory_ = nullptr;
68 surface_id_allocator_ = nullptr; 94 surface_id_allocator_ = nullptr;
69 surface_manager_ = nullptr; 95 surface_manager_ = nullptr;
70 weak_ptrs_.InvalidateWeakPtrs(); 96 weak_ptrs_.InvalidateWeakPtrs();
71 OutputSurface::DetachFromClient(); 97 OutputSurface::DetachFromClient();
72 } 98 }
73 99
74 void TestDelegatingOutputSurface::SwapBuffers(CompositorFrame frame) { 100 void TestDelegatingOutputSurface::SwapBuffers(CompositorFrame frame) {
75 if (delegated_surface_id_.is_null()) { 101 if (delegated_surface_id_.is_null()) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void TestDelegatingOutputSurface::ReturnResources( 145 void TestDelegatingOutputSurface::ReturnResources(
120 const ReturnedResourceArray& resources) { 146 const ReturnedResourceArray& resources) {
121 client_->ReclaimResources(resources); 147 client_->ReclaimResources(resources);
122 } 148 }
123 149
124 void TestDelegatingOutputSurface::SetBeginFrameSource( 150 void TestDelegatingOutputSurface::SetBeginFrameSource(
125 BeginFrameSource* begin_frame_source) { 151 BeginFrameSource* begin_frame_source) {
126 client_->SetBeginFrameSource(begin_frame_source); 152 client_->SetBeginFrameSource(begin_frame_source);
127 } 153 }
128 154
155 void TestDelegatingOutputSurface::DisplayOutputSurfaceLost() {
156 DidLoseOutputSurface();
157 }
158
159 void TestDelegatingOutputSurface::DisplaySetMemoryPolicy(
160 const ManagedMemoryPolicy& policy) {
161 SetMemoryPolicy(policy);
162 }
163
129 } // namespace cc 164 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_delegating_output_surface.h ('k') | cc/test/test_gles2_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698