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

Side by Side Diff: blimp/client/core/compositor/delegated_output_surface.cc

Issue 2266863003: blimp: Move BlimpCompositor to use delegated rendering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments + tests. 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
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 "blimp/client/core/compositor/delegated_output_surface.h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/threading/thread_checker.h"
12 #include "cc/output/compositor_frame.h"
13
14 namespace blimp {
15 namespace client {
16
17 DelegatedOutputSurface::MainThreadOnly::MainThreadOnly(
18 DelegatedOutputSurface* output_surface,
19 BlimpOutputSurfaceClient* client)
20 : client(client), weak_ptr_factory(output_surface) {}
21
22 DelegatedOutputSurface::MainThreadOnly::~MainThreadOnly() = default;
23
24 DelegatedOutputSurface::CompositorThreadOnly::CompositorThreadOnly(
25 DelegatedOutputSurface* output_surface,
26 base::WeakPtr<DelegatedOutputSurface> output_surface_weak_ptr)
27 : bound_to_client(false),
28 output_surface_weak_ptr(output_surface_weak_ptr),
29 weak_ptr_factory(output_surface) {}
30
31 DelegatedOutputSurface::CompositorThreadOnly::~CompositorThreadOnly() = default;
32
33 DelegatedOutputSurface::DelegatedOutputSurface(
34 scoped_refptr<cc::ContextProvider> compositor_context_provider,
35 scoped_refptr<cc::ContextProvider> worker_context_provider,
36 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
37 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner,
38 BlimpOutputSurfaceClient* client)
39 : cc::OutputSurface(std::move(compositor_context_provider),
40 std::move(worker_context_provider),
41 nullptr),
42 main_thread_only_(this, client),
43 compositor_thread_only_(this,
44 main_thread_only_.weak_ptr_factory.GetWeakPtr()),
45 main_task_runner_(std::move(main_task_runner)),
46 compositor_task_runner_(std::move(compositor_task_runner)) {
47 DCHECK(IsMainThread());
48 capabilities_.delegated_rendering = true;
49 }
50
51 DelegatedOutputSurface::~DelegatedOutputSurface() = default;
52
53 void DelegatedOutputSurface::ReclaimCompositorResources(
54 const cc::ReturnedResourceArray& resources) {
55 DCHECK(IsMainThread());
56 compositor_task_runner_->PostTask(
57 FROM_HERE,
58 base::Bind(&DelegatedOutputSurface::ReclaimResourcesOnCompositorThread,
59 main().output_surface_weak_ptr, resources));
60 }
61
62 void DelegatedOutputSurface::ReclaimResourcesOnCompositorThread(
63 const cc::ReturnedResourceArray& resources) {
64 DCHECK(IsCompositorThread());
65 cc::OutputSurface::ReclaimResources(resources);
66 }
67
68 uint32_t DelegatedOutputSurface::GetFramebufferCopyTextureFormat() {
69 NOTREACHED() << "Should not be called on delegated output surface";
70 return 0;
71 }
72
73 bool DelegatedOutputSurface::BindToClient(cc::OutputSurfaceClient* client) {
74 DCHECK(IsCompositorThread());
75 DCHECK(!compositor().bound_to_client);
76
77 bool success = cc::OutputSurface::BindToClient(client);
78 if (success) {
79 compositor().bound_to_client = true;
80 main_task_runner_->PostTask(
81 FROM_HERE, base::Bind(&DelegatedOutputSurface::BindOnMainThread,
82 compositor().output_surface_weak_ptr,
83 compositor().weak_ptr_factory.GetWeakPtr()));
84 }
85
86 return success;
87 }
88
89 void DelegatedOutputSurface::SwapBuffers(cc::CompositorFrame frame) {
90 DCHECK(IsCompositorThread());
91
92 main_task_runner_->PostTask(
93 FROM_HERE,
94 base::Bind(&DelegatedOutputSurface::SwapBuffersOnMainThread,
95 compositor().output_surface_weak_ptr, base::Passed(&frame)));
96 }
97
98 void DelegatedOutputSurface::DetachFromClient() {
99 DCHECK(IsCompositorThread());
100 cc::OutputSurface::DetachFromClient();
101
102 if (compositor().bound_to_client == true) {
103 compositor().bound_to_client = false;
104 main_task_runner_->PostTask(
105 FROM_HERE, base::Bind(&DelegatedOutputSurface::DetachOnMainThread,
106 compositor().output_surface_weak_ptr));
107 }
108
109 compositor().weak_ptr_factory.InvalidateWeakPtrs();
110 }
111
112 void DelegatedOutputSurface::BindOnMainThread(
113 base::WeakPtr<DelegatedOutputSurface> output_surface_weak_ptr) {
114 DCHECK(IsMainThread());
115 main().output_surface_weak_ptr = output_surface_weak_ptr;
116 main().client->BindToOutputSurface(this);
117 }
118
119 void DelegatedOutputSurface::SwapBuffersOnMainThread(
120 cc::CompositorFrame frame) {
121 DCHECK(IsMainThread());
122 main().client->SwapCompositorFrame(std::move(frame));
123 compositor_task_runner_->PostTask(
124 FROM_HERE, base::Bind(&cc::OutputSurface::OnSwapBuffersComplete,
125 main().output_surface_weak_ptr));
126 }
127
128 void DelegatedOutputSurface::DetachOnMainThread() {
129 DCHECK(IsMainThread());
130 main().client->UnbindOutputSurface(this);
131 main().weak_ptr_factory.InvalidateWeakPtrs();
132 }
133
134 DelegatedOutputSurface::MainThreadOnly& DelegatedOutputSurface::main() {
135 DCHECK(IsMainThread());
136 return main_thread_only_;
137 }
138
139 DelegatedOutputSurface::CompositorThreadOnly&
140 DelegatedOutputSurface::compositor() {
141 DCHECK(IsCompositorThread());
142 return compositor_thread_only_;
143 }
144
145 bool DelegatedOutputSurface::IsMainThread() const {
146 return main_task_runner_->BelongsToCurrentThread();
147 }
148
149 bool DelegatedOutputSurface::IsCompositorThread() const {
150 return compositor_task_runner_->BelongsToCurrentThread();
151 }
152
153 } // namespace client
154 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698