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

Side by Side Diff: content/browser/android/in_process/context_provider_in_process.cc

Issue 1844843002: android: Remove in-process video path (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove commented out code + rebase again Created 4 years, 8 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 (c) 2013 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 "content/browser/android/in_process/context_provider_in_process.h"
6
7 #include <stddef.h>
8 #include <utility>
9
10 #include "base/bind.h"
11 #include "base/callback_helpers.h"
12 #include "base/strings/stringprintf.h"
13 #include "cc/output/managed_memory_policy.h"
14 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h"
15 #include "gpu/command_buffer/client/gles2_implementation.h"
16 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h"
17 #include "third_party/skia/include/gpu/GrContext.h"
18
19 using gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl;
20
21 namespace content {
22
23 class ContextProviderInProcess::LostContextCallbackProxy
24 : public blink::WebGraphicsContext3D::WebGraphicsContextLostCallback {
25 public:
26 explicit LostContextCallbackProxy(ContextProviderInProcess* provider)
27 : provider_(provider) {
28 provider_->context3d_->setContextLostCallback(this);
29 }
30
31 ~LostContextCallbackProxy() override {
32 provider_->context3d_->setContextLostCallback(nullptr);
33 }
34
35 void onContextLost() override {
36 provider_->OnLostContext();
37 }
38
39 private:
40 ContextProviderInProcess* provider_;
41 };
42
43 // static
44 scoped_refptr<ContextProviderInProcess> ContextProviderInProcess::Create(
45 std::unique_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d,
46 const std::string& debug_name) {
47 if (!context3d)
48 return nullptr;
49 return new ContextProviderInProcess(std::move(context3d), debug_name);
50 }
51
52 ContextProviderInProcess::ContextProviderInProcess(
53 std::unique_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d,
54 const std::string& debug_name)
55 : context3d_(std::move(context3d)), debug_name_(debug_name) {
56 DCHECK(main_thread_checker_.CalledOnValidThread());
57 DCHECK(context3d_);
58 context_thread_checker_.DetachFromThread();
59 }
60
61 ContextProviderInProcess::~ContextProviderInProcess() {
62 DCHECK(main_thread_checker_.CalledOnValidThread() ||
63 context_thread_checker_.CalledOnValidThread());
64 }
65
66 blink::WebGraphicsContext3D* ContextProviderInProcess::WebContext3D() {
67 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
68 DCHECK(context_thread_checker_.CalledOnValidThread());
69
70 return context3d_.get();
71 }
72
73 bool ContextProviderInProcess::BindToCurrentThread() {
74 DCHECK(context3d_);
75
76 // This is called on the thread the context will be used.
77 DCHECK(context_thread_checker_.CalledOnValidThread());
78
79 if (lost_context_callback_proxy_)
80 return true;
81
82 if (!context3d_->InitializeOnCurrentThread())
83 return false;
84
85 InitializeCapabilities();
86
87 const std::string unique_context_name =
88 base::StringPrintf("%s-%p", debug_name_.c_str(), context3d_.get());
89 ContextGL()->TraceBeginCHROMIUM("gpu_toplevel", unique_context_name.c_str());
90
91 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this));
92 return true;
93 }
94
95 void ContextProviderInProcess::DetachFromThread() {
96 context_thread_checker_.DetachFromThread();
97 }
98
99 void ContextProviderInProcess::InitializeCapabilities() {
100 capabilities_.gpu = context3d_->GetImplementation()->capabilities();
101
102 size_t mapped_memory_limit = context3d_->GetMappedMemoryLimit();
103 capabilities_.max_transfer_buffer_usage_bytes =
104 mapped_memory_limit ==
105 WebGraphicsContext3DInProcessCommandBufferImpl::kNoLimit
106 ? std::numeric_limits<size_t>::max()
107 : mapped_memory_limit;
108 }
109
110 cc::ContextProvider::Capabilities
111 ContextProviderInProcess::ContextCapabilities() {
112 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
113 DCHECK(context_thread_checker_.CalledOnValidThread());
114 return capabilities_;
115 }
116
117 ::gpu::gles2::GLES2Interface* ContextProviderInProcess::ContextGL() {
118 DCHECK(context3d_);
119 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
120 DCHECK(context_thread_checker_.CalledOnValidThread());
121
122 return context3d_->GetGLInterface();
123 }
124
125 ::gpu::ContextSupport* ContextProviderInProcess::ContextSupport() {
126 DCHECK(context3d_);
127 if (!lost_context_callback_proxy_)
128 return NULL; // Not bound to anything.
129
130 DCHECK(context_thread_checker_.CalledOnValidThread());
131
132 return context3d_->GetContextSupport();
133 }
134
135 class GrContext* ContextProviderInProcess::GrContext() {
136 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
137 DCHECK(context_thread_checker_.CalledOnValidThread());
138
139 if (gr_context_)
140 return gr_context_->get();
141
142 gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(
143 context3d_->GetGLInterface()));
144 return gr_context_->get();
145 }
146
147 void ContextProviderInProcess::InvalidateGrContext(uint32_t state) {
148 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
149 DCHECK(context_thread_checker_.CalledOnValidThread());
150
151 if (gr_context_)
152 return gr_context_->ResetContext(state);
153 }
154
155 void ContextProviderInProcess::SetupLock() {
156 context3d_->SetLock(&context_lock_);
157 }
158
159 base::Lock* ContextProviderInProcess::GetLock() {
160 return &context_lock_;
161 }
162
163 void ContextProviderInProcess::DeleteCachedResources() {
164 DCHECK(context_thread_checker_.CalledOnValidThread());
165
166 if (gr_context_)
167 gr_context_->FreeGpuResources();
168 }
169
170 void ContextProviderInProcess::OnLostContext() {
171 DCHECK(context_thread_checker_.CalledOnValidThread());
172 if (!lost_context_callback_.is_null())
173 lost_context_callback_.Run();
174 if (gr_context_)
175 gr_context_->OnLostContext();
176 }
177
178 void ContextProviderInProcess::SetLostContextCallback(
179 const LostContextCallback& lost_context_callback) {
180 DCHECK(context_thread_checker_.CalledOnValidThread());
181 DCHECK(lost_context_callback_.is_null() ||
182 lost_context_callback.is_null());
183 lost_context_callback_ = lost_context_callback;
184 }
185
186 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698