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

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

Issue 1916923004: Request context sharing via content::ContextProviderCommandBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sharegroup: . 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 "gpu/command_buffer/client/gles2_implementation.h" 18 #include "gpu/command_buffer/client/gles2_implementation.h"
19 #include "gpu/command_buffer/client/gles2_trace_implementation.h" 19 #include "gpu/command_buffer/client/gles2_trace_implementation.h"
20 #include "gpu/command_buffer/client/gpu_switches.h" 20 #include "gpu/command_buffer/client/gpu_switches.h"
21 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h" 21 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h"
22 #include "third_party/skia/include/gpu/GrContext.h" 22 #include "third_party/skia/include/gpu/GrContext.h"
23 23
24 namespace content { 24 namespace content {
25 25
26 ContextProviderCommandBuffer::SharedProviders::SharedProviders() = default;
27 ContextProviderCommandBuffer::SharedProviders::~SharedProviders() = default;
28
26 class ContextProviderCommandBuffer::LostContextCallbackProxy 29 class ContextProviderCommandBuffer::LostContextCallbackProxy
27 : public WebGraphicsContext3DCommandBufferImpl:: 30 : public WebGraphicsContext3DCommandBufferImpl::
28 WebGraphicsContextLostCallback { 31 WebGraphicsContextLostCallback {
29 public: 32 public:
30 explicit LostContextCallbackProxy(ContextProviderCommandBuffer* provider) 33 explicit LostContextCallbackProxy(ContextProviderCommandBuffer* provider)
31 : provider_(provider) { 34 : provider_(provider) {
32 provider_->context3d_->SetContextLostCallback(this); 35 provider_->context3d_->SetContextLostCallback(this);
33 } 36 }
34 37
35 ~LostContextCallbackProxy() override { 38 ~LostContextCallbackProxy() override {
36 provider_->context3d_->SetContextLostCallback(nullptr); 39 provider_->context3d_->SetContextLostCallback(nullptr);
37 } 40 }
38 41
39 void onContextLost() override { provider_->OnLostContext(); } 42 void onContextLost() override { provider_->OnLostContext(); }
40 43
41 private: 44 private:
42 ContextProviderCommandBuffer* provider_; 45 ContextProviderCommandBuffer* provider_;
43 }; 46 };
44 47
45 ContextProviderCommandBuffer::ContextProviderCommandBuffer( 48 ContextProviderCommandBuffer::ContextProviderCommandBuffer(
46 std::unique_ptr<WebGraphicsContext3DCommandBufferImpl> context3d, 49 std::unique_ptr<WebGraphicsContext3DCommandBufferImpl> context3d,
47 const gpu::SharedMemoryLimits& memory_limits, 50 const gpu::SharedMemoryLimits& memory_limits,
51 ContextProviderCommandBuffer* shared_context_provider,
48 CommandBufferContextType type) 52 CommandBufferContextType type)
49 : context3d_(std::move(context3d)), 53 : shared_providers_(shared_context_provider
54 ? shared_context_provider->shared_providers_
55 : new SharedProviders),
56 context3d_(std::move(context3d)),
50 memory_limits_(memory_limits), 57 memory_limits_(memory_limits),
51 context_type_(type), 58 context_type_(type),
52 debug_name_(CommandBufferContextTypeToString(type)) { 59 debug_name_(CommandBufferContextTypeToString(type)) {
53 DCHECK(main_thread_checker_.CalledOnValidThread()); 60 DCHECK(main_thread_checker_.CalledOnValidThread());
54 DCHECK(context3d_); 61 DCHECK(context3d_);
55 context_thread_checker_.DetachFromThread(); 62 context_thread_checker_.DetachFromThread();
56 } 63 }
57 64
58 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { 65 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() {
59 DCHECK(main_thread_checker_.CalledOnValidThread() || 66 DCHECK(main_thread_checker_.CalledOnValidThread() ||
60 context_thread_checker_.CalledOnValidThread()); 67 context_thread_checker_.CalledOnValidThread());
61 68
69 {
70 base::AutoLock hold(shared_providers_->lock);
71 auto it = std::find(shared_providers_->list.begin(),
72 shared_providers_->list.end(), this);
73 if (it != shared_providers_->list.end())
74 shared_providers_->list.erase(it);
75 }
76
62 // Destroy references to the context3d_ before leaking it. 77 // Destroy references to the context3d_ before leaking it.
63 // TODO(danakj): Delete this. 78 // TODO(danakj): Delete this.
64 if (context3d_->GetCommandBufferProxy()) 79 if (context3d_->GetCommandBufferProxy())
65 context3d_->GetCommandBufferProxy()->SetLock(nullptr); 80 context3d_->GetCommandBufferProxy()->SetLock(nullptr);
66 81
67 if (lost_context_callback_proxy_) { 82 if (lost_context_callback_proxy_) {
68 // Disconnect lost callbacks during destruction. 83 // Disconnect lost callbacks during destruction.
69 lost_context_callback_proxy_.reset(); 84 lost_context_callback_proxy_.reset();
70 } 85 }
71 } 86 }
(...skipping 12 matching lines...) Expand all
84 } 99 }
85 100
86 bool ContextProviderCommandBuffer::BindToCurrentThread() { 101 bool ContextProviderCommandBuffer::BindToCurrentThread() {
87 // This is called on the thread the context will be used. 102 // This is called on the thread the context will be used.
88 DCHECK(context_thread_checker_.CalledOnValidThread()); 103 DCHECK(context_thread_checker_.CalledOnValidThread());
89 104
90 if (lost_context_callback_proxy_) 105 if (lost_context_callback_proxy_)
91 return true; 106 return true;
92 107
93 context3d_->SetContextType(context_type_); 108 context3d_->SetContextType(context_type_);
94 if (!context3d_->InitializeOnCurrentThread(memory_limits_)) 109
95 return false; 110 ContextProviderCommandBuffer* shared_context_provider = nullptr;
111 gpu::CommandBufferProxyImpl* shared_command_buffer = nullptr;
piman 2016/04/27 22:09:33 nit: move both of those inside the AutoLock scope
danakj 2016/04/28 00:25:58 Done. I forget why I moved these out to start with
112 scoped_refptr<gpu::gles2::ShareGroup> share_group;
113
114 // It's possible to be running BindToCurrentThread on two contexts
115 // on different threads at the same time, but which will be in the same share
116 // group. To ensure they end up in the same group, hold the lock on the
117 // shared_providers_ (which they will share) after querying the group, until
118 // this context has been added to the list.
119 {
120 base::AutoLock hold(shared_providers_->lock);
121
122 if (!shared_providers_->list.empty()) {
123 shared_context_provider = shared_providers_->list.front();
124 shared_command_buffer =
125 shared_context_provider->context3d_->GetCommandBufferProxy();
126 share_group = shared_context_provider->context3d_->GetImplementation()
127 ->share_group();
128
129 // If any context in the share group has been lost, then abort and don't
130 // continue since we need to go back to the caller of the constructor to
131 // find the correct share group.
132 // This may happen in between the share group being chosen at the
133 // constructor, and getting to run this BindToCurrentThread method which
134 // can be on some other thread.
135 if (share_group->IsLost())
136 return false;
137 }
138
139 if (!context3d_->InitializeOnCurrentThread(
140 memory_limits_, shared_command_buffer, std::move(share_group)))
141 return false;
142
143 shared_providers_->list.push_back(this);
144 }
145
96 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); 146 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this));
97 147
98 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 148 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
99 switches::kEnableGpuClientTracing)) { 149 switches::kEnableGpuClientTracing)) {
100 // This wraps the real GLES2Implementation and we should always use this 150 // This wraps the real GLES2Implementation and we should always use this
101 // instead when it's present. 151 // instead when it's present.
102 trace_impl_.reset(new gpu::gles2::GLES2TraceImplementation( 152 trace_impl_.reset(new gpu::gles2::GLES2TraceImplementation(
103 context3d_->GetImplementation())); 153 context3d_->GetImplementation()));
104 } 154 }
105 155
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 237
188 void ContextProviderCommandBuffer::SetLostContextCallback( 238 void ContextProviderCommandBuffer::SetLostContextCallback(
189 const LostContextCallback& lost_context_callback) { 239 const LostContextCallback& lost_context_callback) {
190 DCHECK(context_thread_checker_.CalledOnValidThread()); 240 DCHECK(context_thread_checker_.CalledOnValidThread());
191 DCHECK(lost_context_callback_.is_null() || 241 DCHECK(lost_context_callback_.is_null() ||
192 lost_context_callback.is_null()); 242 lost_context_callback.is_null());
193 lost_context_callback_ = lost_context_callback; 243 lost_context_callback_ = lost_context_callback;
194 } 244 }
195 245
196 } // namespace content 246 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698