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

Side by Side Diff: content/renderer/media/android/stream_texture_factory_synchronous_impl.cc

Issue 1547073003: Switch to standard integer types in content/renderer/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/renderer/media/android/stream_texture_factory_synchronous_impl .h" 5 #include "content/renderer/media/android/stream_texture_factory_synchronous_impl .h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/process/process_handle.h" 14 #include "base/process/process_handle.h"
14 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
15 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
16 #include "cc/output/context_provider.h" 17 #include "cc/output/context_provider.h"
17 #include "content/common/android/surface_texture_peer.h" 18 #include "content/common/android/surface_texture_peer.h"
18 #include "content/renderer/render_thread_impl.h" 19 #include "content/renderer/render_thread_impl.h"
19 #include "gpu/command_buffer/client/gles2_interface.h" 20 #include "gpu/command_buffer/client/gles2_interface.h"
20 #include "ui/gl/android/surface_texture.h" 21 #include "ui/gl/android/surface_texture.h"
21 22
22 using gpu::gles2::GLES2Interface; 23 using gpu::gles2::GLES2Interface;
23 24
24 namespace content { 25 namespace content {
25 26
26 namespace { 27 namespace {
27 28
28 class StreamTextureProxyImpl 29 class StreamTextureProxyImpl
29 : public StreamTextureProxy, 30 : public StreamTextureProxy,
30 public base::SupportsWeakPtr<StreamTextureProxyImpl> { 31 public base::SupportsWeakPtr<StreamTextureProxyImpl> {
31 public: 32 public:
32 explicit StreamTextureProxyImpl( 33 explicit StreamTextureProxyImpl(
33 StreamTextureFactorySynchronousImpl::ContextProvider* provider); 34 StreamTextureFactorySynchronousImpl::ContextProvider* provider);
34 ~StreamTextureProxyImpl() override; 35 ~StreamTextureProxyImpl() override;
35 36
36 // StreamTextureProxy implementation: 37 // StreamTextureProxy implementation:
37 void BindToLoop(int32 stream_id, 38 void BindToLoop(int32_t stream_id,
38 cc::VideoFrameProvider::Client* client, 39 cc::VideoFrameProvider::Client* client,
39 scoped_refptr<base::SingleThreadTaskRunner> loop) override; 40 scoped_refptr<base::SingleThreadTaskRunner> loop) override;
40 void Release() override; 41 void Release() override;
41 42
42 private: 43 private:
43 void BindOnThread(int32 stream_id); 44 void BindOnThread(int32_t stream_id);
44 void OnFrameAvailable(); 45 void OnFrameAvailable();
45 46
46 // Protects access to |client_| and |loop_|. 47 // Protects access to |client_| and |loop_|.
47 base::Lock lock_; 48 base::Lock lock_;
48 cc::VideoFrameProvider::Client* client_; 49 cc::VideoFrameProvider::Client* client_;
49 scoped_refptr<base::SingleThreadTaskRunner> loop_; 50 scoped_refptr<base::SingleThreadTaskRunner> loop_;
50 51
51 // Accessed on the |loop_| thread only. 52 // Accessed on the |loop_| thread only.
52 base::Closure callback_; 53 base::Closure callback_;
53 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> 54 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>
(...skipping 23 matching lines...) Expand all
77 // Release is analogous to the destructor, so there should be no more external 78 // Release is analogous to the destructor, so there should be no more external
78 // calls to this object in Release. Therefore there is no need to acquire the 79 // calls to this object in Release. Therefore there is no need to acquire the
79 // lock to access |loop_|. 80 // lock to access |loop_|.
80 if (!loop_.get() || loop_->BelongsToCurrentThread() || 81 if (!loop_.get() || loop_->BelongsToCurrentThread() ||
81 !loop_->DeleteSoon(FROM_HERE, this)) { 82 !loop_->DeleteSoon(FROM_HERE, this)) {
82 delete this; 83 delete this;
83 } 84 }
84 } 85 }
85 86
86 void StreamTextureProxyImpl::BindToLoop( 87 void StreamTextureProxyImpl::BindToLoop(
87 int32 stream_id, 88 int32_t stream_id,
88 cc::VideoFrameProvider::Client* client, 89 cc::VideoFrameProvider::Client* client,
89 scoped_refptr<base::SingleThreadTaskRunner> loop) { 90 scoped_refptr<base::SingleThreadTaskRunner> loop) {
90 DCHECK(loop.get()); 91 DCHECK(loop.get());
91 92
92 { 93 {
93 base::AutoLock lock(lock_); 94 base::AutoLock lock(lock_);
94 DCHECK(!loop_.get() || (loop.get() == loop_.get())); 95 DCHECK(!loop_.get() || (loop.get() == loop_.get()));
95 loop_ = loop; 96 loop_ = loop;
96 client_ = client; 97 client_ = client;
97 } 98 }
98 99
99 if (loop->BelongsToCurrentThread()) { 100 if (loop->BelongsToCurrentThread()) {
100 BindOnThread(stream_id); 101 BindOnThread(stream_id);
101 return; 102 return;
102 } 103 }
103 // Unretained is safe here only because the object is deleted on |loop_| 104 // Unretained is safe here only because the object is deleted on |loop_|
104 // thread. 105 // thread.
105 loop->PostTask(FROM_HERE, 106 loop->PostTask(FROM_HERE,
106 base::Bind(&StreamTextureProxyImpl::BindOnThread, 107 base::Bind(&StreamTextureProxyImpl::BindOnThread,
107 base::Unretained(this), 108 base::Unretained(this),
108 stream_id)); 109 stream_id));
109 } 110 }
110 111
111 void StreamTextureProxyImpl::BindOnThread(int32 stream_id) { 112 void StreamTextureProxyImpl::BindOnThread(int32_t stream_id) {
112 surface_texture_ = context_provider_->GetSurfaceTexture(stream_id); 113 surface_texture_ = context_provider_->GetSurfaceTexture(stream_id);
113 if (!surface_texture_.get()) { 114 if (!surface_texture_.get()) {
114 LOG(ERROR) << "Failed to get SurfaceTexture for stream."; 115 LOG(ERROR) << "Failed to get SurfaceTexture for stream.";
115 return; 116 return;
116 } 117 }
117 118
118 callback_ = 119 callback_ =
119 base::Bind(&StreamTextureProxyImpl::OnFrameAvailable, AsWeakPtr()); 120 base::Bind(&StreamTextureProxyImpl::OnFrameAvailable, AsWeakPtr());
120 surface_texture_->SetFrameAvailableCallback(callback_); 121 surface_texture_->SetFrameAvailableCallback(callback_);
121 } 122 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 context_provider_ = create_context_provider_callback_.Run(); 172 context_provider_ = create_context_provider_callback_.Run();
172 173
173 if (!context_provider_.get()) 174 if (!context_provider_.get())
174 return NULL; 175 return NULL;
175 176
176 if (observer_ && !had_proxy) 177 if (observer_ && !had_proxy)
177 context_provider_->AddObserver(observer_); 178 context_provider_->AddObserver(observer_);
178 return new StreamTextureProxyImpl(context_provider_.get()); 179 return new StreamTextureProxyImpl(context_provider_.get());
179 } 180 }
180 181
181 void StreamTextureFactorySynchronousImpl::EstablishPeer(int32 stream_id, 182 void StreamTextureFactorySynchronousImpl::EstablishPeer(int32_t stream_id,
182 int player_id, 183 int player_id,
183 int frame_id) { 184 int frame_id) {
184 DCHECK(context_provider_.get()); 185 DCHECK(context_provider_.get());
185 scoped_refptr<gfx::SurfaceTexture> surface_texture = 186 scoped_refptr<gfx::SurfaceTexture> surface_texture =
186 context_provider_->GetSurfaceTexture(stream_id); 187 context_provider_->GetSurfaceTexture(stream_id);
187 if (surface_texture.get()) { 188 if (surface_texture.get()) {
188 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( 189 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer(
189 base::GetCurrentProcessHandle(), 190 base::GetCurrentProcessHandle(),
190 surface_texture, 191 surface_texture,
191 frame_id_, 192 frame_id_,
(...skipping 11 matching lines...) Expand all
203 gl->GenTextures(1, texture_id); 204 gl->GenTextures(1, texture_id);
204 gl->ShallowFlushCHROMIUM(); 205 gl->ShallowFlushCHROMIUM();
205 stream_id = context_provider_->CreateStreamTexture(*texture_id); 206 stream_id = context_provider_->CreateStreamTexture(*texture_id);
206 gl->GenMailboxCHROMIUM(texture_mailbox->name); 207 gl->GenMailboxCHROMIUM(texture_mailbox->name);
207 gl->ProduceTextureDirectCHROMIUM( 208 gl->ProduceTextureDirectCHROMIUM(
208 *texture_id, texture_target, texture_mailbox->name); 209 *texture_id, texture_target, texture_mailbox->name);
209 return stream_id; 210 return stream_id;
210 } 211 }
211 212
212 void StreamTextureFactorySynchronousImpl::SetStreamTextureSize( 213 void StreamTextureFactorySynchronousImpl::SetStreamTextureSize(
213 int32 stream_id, 214 int32_t stream_id,
214 const gfx::Size& size) {} 215 const gfx::Size& size) {}
215 216
216 gpu::gles2::GLES2Interface* StreamTextureFactorySynchronousImpl::ContextGL() { 217 gpu::gles2::GLES2Interface* StreamTextureFactorySynchronousImpl::ContextGL() {
217 DCHECK(context_provider_.get()); 218 DCHECK(context_provider_.get());
218 return context_provider_->ContextGL(); 219 return context_provider_->ContextGL();
219 } 220 }
220 221
221 void StreamTextureFactorySynchronousImpl::AddObserver( 222 void StreamTextureFactorySynchronousImpl::AddObserver(
222 StreamTextureFactoryContextObserver* obs) { 223 StreamTextureFactoryContextObserver* obs) {
223 DCHECK(!observer_); 224 DCHECK(!observer_);
224 observer_ = obs; 225 observer_ = obs;
225 if (context_provider_.get()) 226 if (context_provider_.get())
226 context_provider_->AddObserver(obs); 227 context_provider_->AddObserver(obs);
227 } 228 }
228 229
229 void StreamTextureFactorySynchronousImpl::RemoveObserver( 230 void StreamTextureFactorySynchronousImpl::RemoveObserver(
230 StreamTextureFactoryContextObserver* obs) { 231 StreamTextureFactoryContextObserver* obs) {
231 DCHECK_EQ(observer_, obs); 232 DCHECK_EQ(observer_, obs);
232 observer_ = NULL; 233 observer_ = NULL;
233 if (context_provider_.get()) 234 if (context_provider_.get())
234 context_provider_->RemoveObserver(obs); 235 context_provider_->RemoveObserver(obs);
235 } 236 }
236 237
237 } // namespace content 238 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698