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

Side by Side Diff: content/common/gpu/client/context_provider_command_buffer.cc

Issue 1936773002: Move attributes and context type out to ContextProviderCommandBuffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rmwgc3d
Patch Set: attributes: rebase Created 4 years, 7 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 (c) 2013 The Chromium Authors. All rights reserved. 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 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 "content/common/gpu/client/context_provider_command_buffer.h" 5 #include "content/common/gpu/client/context_provider_command_buffer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback_helpers.h" 14 #include "base/callback_helpers.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "cc/output/managed_memory_policy.h" 17 #include "cc/output/managed_memory_policy.h"
18 #include "content/common/gpu/client/command_buffer_metrics.h"
18 #include "gpu/command_buffer/client/gles2_implementation.h" 19 #include "gpu/command_buffer/client/gles2_implementation.h"
19 #include "gpu/command_buffer/client/gles2_trace_implementation.h" 20 #include "gpu/command_buffer/client/gles2_trace_implementation.h"
20 #include "gpu/command_buffer/client/gpu_switches.h" 21 #include "gpu/command_buffer/client/gpu_switches.h"
21 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h" 22 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h"
22 #include "third_party/skia/include/gpu/GrContext.h" 23 #include "third_party/skia/include/gpu/GrContext.h"
23 24
24 namespace content { 25 namespace content {
25 26
26 ContextProviderCommandBuffer::SharedProviders::SharedProviders() = default; 27 ContextProviderCommandBuffer::SharedProviders::SharedProviders() = default;
27 ContextProviderCommandBuffer::SharedProviders::~SharedProviders() = default; 28 ContextProviderCommandBuffer::SharedProviders::~SharedProviders() = default;
(...skipping 13 matching lines...) Expand all
41 42
42 void onContextLost() override { provider_->OnLostContext(); } 43 void onContextLost() override { provider_->OnLostContext(); }
43 44
44 private: 45 private:
45 ContextProviderCommandBuffer* provider_; 46 ContextProviderCommandBuffer* provider_;
46 }; 47 };
47 48
48 ContextProviderCommandBuffer::ContextProviderCommandBuffer( 49 ContextProviderCommandBuffer::ContextProviderCommandBuffer(
49 std::unique_ptr<WebGraphicsContext3DCommandBufferImpl> context3d, 50 std::unique_ptr<WebGraphicsContext3DCommandBufferImpl> context3d,
50 const gpu::SharedMemoryLimits& memory_limits, 51 const gpu::SharedMemoryLimits& memory_limits,
52 const gpu::gles2::ContextCreationAttribHelper& attributes,
51 ContextProviderCommandBuffer* shared_context_provider, 53 ContextProviderCommandBuffer* shared_context_provider,
52 CommandBufferContextType type) 54 command_buffer_metrics::ContextType type)
53 : shared_providers_(shared_context_provider 55 : shared_providers_(shared_context_provider
54 ? shared_context_provider->shared_providers_ 56 ? shared_context_provider->shared_providers_
55 : new SharedProviders), 57 : new SharedProviders),
56 context3d_(std::move(context3d)), 58 context3d_(std::move(context3d)),
57 memory_limits_(memory_limits), 59 memory_limits_(memory_limits),
58 context_type_(type), 60 attributes_(attributes),
59 debug_name_(CommandBufferContextTypeToString(type)) { 61 context_type_(type) {
60 DCHECK(main_thread_checker_.CalledOnValidThread()); 62 DCHECK(main_thread_checker_.CalledOnValidThread());
61 DCHECK(context3d_); 63 DCHECK(context3d_);
62 context_thread_checker_.DetachFromThread(); 64 context_thread_checker_.DetachFromThread();
63 } 65 }
64 66
65 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { 67 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() {
66 DCHECK(main_thread_checker_.CalledOnValidThread() || 68 DCHECK(main_thread_checker_.CalledOnValidThread() ||
67 context_thread_checker_.CalledOnValidThread()); 69 context_thread_checker_.CalledOnValidThread());
68 70
69 { 71 {
(...skipping 20 matching lines...) Expand all
90 return context3d_->GetCommandBufferProxy(); 92 return context3d_->GetCommandBufferProxy();
91 } 93 }
92 94
93 bool ContextProviderCommandBuffer::BindToCurrentThread() { 95 bool ContextProviderCommandBuffer::BindToCurrentThread() {
94 // This is called on the thread the context will be used. 96 // This is called on the thread the context will be used.
95 DCHECK(context_thread_checker_.CalledOnValidThread()); 97 DCHECK(context_thread_checker_.CalledOnValidThread());
96 98
97 if (lost_context_callback_proxy_) 99 if (lost_context_callback_proxy_)
98 return true; 100 return true;
99 101
100 context3d_->SetContextType(context_type_);
101
102 // It's possible to be running BindToCurrentThread on two contexts 102 // It's possible to be running BindToCurrentThread on two contexts
103 // on different threads at the same time, but which will be in the same share 103 // on different threads at the same time, but which will be in the same share
104 // group. To ensure they end up in the same group, hold the lock on the 104 // group. To ensure they end up in the same group, hold the lock on the
105 // shared_providers_ (which they will share) after querying the group, until 105 // shared_providers_ (which they will share) after querying the group, until
106 // this context has been added to the list. 106 // this context has been added to the list.
107 { 107 {
108 ContextProviderCommandBuffer* shared_context_provider = nullptr; 108 ContextProviderCommandBuffer* shared_context_provider = nullptr;
109 gpu::CommandBufferProxyImpl* shared_command_buffer = nullptr; 109 gpu::CommandBufferProxyImpl* shared_command_buffer = nullptr;
110 scoped_refptr<gpu::gles2::ShareGroup> share_group; 110 scoped_refptr<gpu::gles2::ShareGroup> share_group;
111 111
112 base::AutoLock hold(shared_providers_->lock); 112 base::AutoLock hold(shared_providers_->lock);
113 113
114 if (!shared_providers_->list.empty()) { 114 if (!shared_providers_->list.empty()) {
115 shared_context_provider = shared_providers_->list.front(); 115 shared_context_provider = shared_providers_->list.front();
116 shared_command_buffer = 116 shared_command_buffer =
117 shared_context_provider->context3d_->GetCommandBufferProxy(); 117 shared_context_provider->context3d_->GetCommandBufferProxy();
118 share_group = shared_context_provider->context3d_->GetImplementation() 118 share_group = shared_context_provider->context3d_->GetImplementation()
119 ->share_group(); 119 ->share_group();
120 } 120 }
121 121
122 if (!context3d_->InitializeOnCurrentThread( 122 if (!context3d_->InitializeOnCurrentThread(
123 memory_limits_, shared_command_buffer, std::move(share_group))) 123 memory_limits_, shared_command_buffer, std::move(share_group),
124 attributes_, context_type_))
124 return false; 125 return false;
125 126
126 // If any context in the share group has been lost, then abort and don't 127 // If any context in the share group has been lost, then abort and don't
127 // continue since we need to go back to the caller of the constructor to 128 // continue since we need to go back to the caller of the constructor to
128 // find the correct share group. 129 // find the correct share group.
129 // This may happen in between the share group being chosen at the 130 // This may happen in between the share group being chosen at the
130 // constructor, and getting to run this BindToCurrentThread method which 131 // constructor, and getting to run this BindToCurrentThread method which
131 // can be on some other thread. 132 // can be on some other thread.
132 // We intentionally call this *after* creating the command buffer via the 133 // We intentionally call this *after* creating the command buffer via the
133 // GpuChannelHost. Once that has happened, the service knows we are in the 134 // GpuChannelHost. Once that has happened, the service knows we are in the
(...skipping 12 matching lines...) Expand all
146 147
147 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 148 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
148 switches::kEnableGpuClientTracing)) { 149 switches::kEnableGpuClientTracing)) {
149 // This wraps the real GLES2Implementation and we should always use this 150 // This wraps the real GLES2Implementation and we should always use this
150 // instead when it's present. 151 // instead when it's present.
151 trace_impl_.reset(new gpu::gles2::GLES2TraceImplementation( 152 trace_impl_.reset(new gpu::gles2::GLES2TraceImplementation(
152 context3d_->GetImplementation())); 153 context3d_->GetImplementation()));
153 } 154 }
154 155
155 // Do this last once the context is set up. 156 // Do this last once the context is set up.
157 std::string type_name =
158 command_buffer_metrics::ContextTypeToString(context_type_);
156 std::string unique_context_name = 159 std::string unique_context_name =
157 base::StringPrintf("%s-%p", debug_name_.c_str(), context3d_.get()); 160 base::StringPrintf("%s-%p", type_name.c_str(), context3d_.get());
158 ContextGL()->TraceBeginCHROMIUM("gpu_toplevel", unique_context_name.c_str()); 161 ContextGL()->TraceBeginCHROMIUM("gpu_toplevel", unique_context_name.c_str());
159 return true; 162 return true;
160 } 163 }
161 164
162 void ContextProviderCommandBuffer::DetachFromThread() { 165 void ContextProviderCommandBuffer::DetachFromThread() {
163 context_thread_checker_.DetachFromThread(); 166 context_thread_checker_.DetachFromThread();
164 } 167 }
165 168
166 gpu::gles2::GLES2Interface* ContextProviderCommandBuffer::ContextGL() { 169 gpu::gles2::GLES2Interface* ContextProviderCommandBuffer::ContextGL() {
167 DCHECK(context3d_); 170 DCHECK(context3d_);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 gr_context_->FreeGpuResources(); 228 gr_context_->FreeGpuResources();
226 } 229 }
227 230
228 void ContextProviderCommandBuffer::OnLostContext() { 231 void ContextProviderCommandBuffer::OnLostContext() {
229 DCHECK(context_thread_checker_.CalledOnValidThread()); 232 DCHECK(context_thread_checker_.CalledOnValidThread());
230 233
231 if (!lost_context_callback_.is_null()) 234 if (!lost_context_callback_.is_null())
232 lost_context_callback_.Run(); 235 lost_context_callback_.Run();
233 if (gr_context_) 236 if (gr_context_)
234 gr_context_->OnLostContext(); 237 gr_context_->OnLostContext();
238
239 gpu::CommandBuffer::State state = GetCommandBufferProxy()->GetLastState();
240 command_buffer_metrics::UmaRecordContextLost(context_type_, state.error,
241 state.context_lost_reason);
235 } 242 }
236 243
237 void ContextProviderCommandBuffer::SetLostContextCallback( 244 void ContextProviderCommandBuffer::SetLostContextCallback(
238 const LostContextCallback& lost_context_callback) { 245 const LostContextCallback& lost_context_callback) {
239 DCHECK(context_thread_checker_.CalledOnValidThread()); 246 DCHECK(context_thread_checker_.CalledOnValidThread());
240 DCHECK(lost_context_callback_.is_null() || 247 DCHECK(lost_context_callback_.is_null() ||
241 lost_context_callback.is_null()); 248 lost_context_callback.is_null());
242 lost_context_callback_ = lost_context_callback; 249 lost_context_callback_ = lost_context_callback;
243 } 250 }
244 251
245 } // namespace content 252 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698