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

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

Issue 2144393003: cc: Allow TestDelegatingOutputSurface to be used for non-pixel tests. (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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "cc/test/test_delegating_output_surface.h"
6
7 #include <stdint.h>
8 #include <utility>
9
10 #include "cc/output/begin_frame_args.h"
11 #include "cc/output/compositor_frame_ack.h"
12 #include "cc/test/begin_frame_args_test.h"
13
14 static constexpr uint32_t kCompositorClientId = 1;
15
16 namespace cc {
17
18 TestDelegatingOutputSurface::TestDelegatingOutputSurface(
19 scoped_refptr<ContextProvider> compositor_context_provider,
20 scoped_refptr<ContextProvider> worker_context_provider,
21 std::unique_ptr<Display> display,
22 bool context_shared_with_compositor,
23 bool allow_force_reclaim_resources)
24 : OutputSurface(std::move(compositor_context_provider),
25 std::move(worker_context_provider),
26 nullptr),
27 surface_manager_(new SurfaceManager),
28 surface_id_allocator_(new SurfaceIdAllocator(kCompositorClientId)),
29 surface_factory_(new SurfaceFactory(surface_manager_.get(), this)),
30 display_(std::move(display)),
31 weak_ptrs_(this) {
32 CHECK(display_);
33 capabilities_.delegated_rendering = true;
34 capabilities_.can_force_reclaim_resources = allow_force_reclaim_resources;
35 capabilities_.delegated_sync_points_required =
36 !context_shared_with_compositor;
37
38 surface_id_allocator_->RegisterSurfaceClientId(surface_manager_.get());
39 }
40
41 TestDelegatingOutputSurface::~TestDelegatingOutputSurface() {}
42
43 bool TestDelegatingOutputSurface::BindToClient(OutputSurfaceClient* client) {
44 if (!OutputSurface::BindToClient(client))
45 return false;
46
47 // We want the Display's output surface to hear about lost context, and since
48 // this shares a context with it (when delegated_sync_points_required is
49 // false), we should not be listening for lost context callbacks on the
50 // context here.
51 if (!capabilities_.delegated_sync_points_required && context_provider())
52 context_provider()->SetLostContextCallback(base::Closure());
53
54 surface_manager_->RegisterSurfaceFactoryClient(
55 surface_id_allocator_->client_id(), this);
56 display_->Initialize(&display_client_, surface_manager_.get(),
57 surface_id_allocator_->client_id());
58 return true;
59 }
60
61 void TestDelegatingOutputSurface::DetachFromClient() {
62 if (!delegated_surface_id_.is_null())
63 surface_factory_->Destroy(delegated_surface_id_);
64 surface_manager_->UnregisterSurfaceFactoryClient(
65 surface_id_allocator_->client_id());
66
67 display_ = nullptr;
68 surface_factory_ = nullptr;
69 surface_id_allocator_ = nullptr;
70 surface_manager_ = nullptr;
71 weak_ptrs_.InvalidateWeakPtrs();
72 OutputSurface::DetachFromClient();
73 }
74
75 void TestDelegatingOutputSurface::SwapBuffers(CompositorFrame frame) {
76 if (delegated_surface_id_.is_null()) {
77 delegated_surface_id_ = surface_id_allocator_->GenerateId();
78 surface_factory_->Create(delegated_surface_id_);
79 }
80 display_->SetSurfaceId(delegated_surface_id_,
81 frame.metadata.device_scale_factor);
82
83 gfx::Size frame_size =
84 frame.delegated_frame_data->render_pass_list.back()->output_rect.size();
85 display_->Resize(frame_size);
86
87 surface_factory_->SubmitCompositorFrame(
88 delegated_surface_id_, std::move(frame),
89 base::Bind(&TestDelegatingOutputSurface::DrawCallback,
90 weak_ptrs_.GetWeakPtr()));
91
92 if (!display_->has_scheduler())
93 display_->DrawAndSwap();
94 }
95
96 void TestDelegatingOutputSurface::DrawCallback(SurfaceDrawStatus) {
97 client_->DidSwapBuffersComplete();
98 }
99
100 void TestDelegatingOutputSurface::ForceReclaimResources() {
101 if (capabilities_.can_force_reclaim_resources &&
102 !delegated_surface_id_.is_null()) {
103 surface_factory_->SubmitCompositorFrame(delegated_surface_id_,
104 CompositorFrame(),
105 SurfaceFactory::DrawCallback());
106 }
107 }
108
109 void TestDelegatingOutputSurface::BindFramebuffer() {
110 // This is a delegating output surface, no framebuffer/direct drawing support.
111 NOTREACHED();
112 }
113
114 uint32_t TestDelegatingOutputSurface::GetFramebufferCopyTextureFormat() {
115 // This is a delegating output surface, no framebuffer/direct drawing support.
116 NOTREACHED();
117 return 0;
118 }
119
120 void TestDelegatingOutputSurface::ReturnResources(
121 const ReturnedResourceArray& resources) {
122 CompositorFrameAck ack;
123 ack.resources = resources;
124 client_->ReclaimResources(&ack);
125 }
126
127 void TestDelegatingOutputSurface::SetBeginFrameSource(
128 BeginFrameSource* begin_frame_source) {
129 client_->SetBeginFrameSource(begin_frame_source);
130 }
131
132 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_delegating_output_surface.h ('k') | content/browser/compositor/gpu_process_transport_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698