| OLD | NEW |
| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 explicit StreamTextureProxyImpl( | 32 explicit StreamTextureProxyImpl( |
| 33 StreamTextureFactorySynchronousImpl::ContextProvider* provider); | 33 StreamTextureFactorySynchronousImpl::ContextProvider* provider); |
| 34 virtual ~StreamTextureProxyImpl(); | 34 virtual ~StreamTextureProxyImpl(); |
| 35 | 35 |
| 36 // StreamTextureProxy implementation: | 36 // StreamTextureProxy implementation: |
| 37 virtual void BindToCurrentThread(int32 stream_id) OVERRIDE; | 37 virtual void BindToCurrentThread(int32 stream_id) OVERRIDE; |
| 38 virtual void SetClient(cc::VideoFrameProvider::Client* client) OVERRIDE; | 38 virtual void SetClient(cc::VideoFrameProvider::Client* client) OVERRIDE; |
| 39 virtual void Release() OVERRIDE; | 39 virtual void Release() OVERRIDE; |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 void BindOnCompositorThread(int stream_id); | |
| 43 void OnFrameAvailable(); | 42 void OnFrameAvailable(); |
| 44 | 43 |
| 45 scoped_refptr<base::MessageLoopProxy> loop_; | 44 scoped_refptr<base::MessageLoopProxy> loop_; |
| 46 base::Lock client_lock_; | 45 base::Lock client_lock_; |
| 47 cc::VideoFrameProvider::Client* client_; | 46 cc::VideoFrameProvider::Client* client_; |
| 48 base::Closure callback_; | 47 base::Closure callback_; |
| 49 | 48 |
| 50 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> | 49 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> |
| 51 context_provider_; | 50 context_provider_; |
| 52 scoped_refptr<gfx::SurfaceTexture> surface_texture_; | 51 scoped_refptr<gfx::SurfaceTexture> surface_texture_; |
| 53 | 52 |
| 54 float current_matrix_[16]; | 53 float current_matrix_[16]; |
| 55 bool has_updated_; | 54 bool has_updated_; |
| 56 | 55 |
| 57 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); | 56 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); |
| 58 }; | 57 }; |
| 59 | 58 |
| 60 StreamTextureProxyImpl::StreamTextureProxyImpl( | 59 StreamTextureProxyImpl::StreamTextureProxyImpl( |
| 61 StreamTextureFactorySynchronousImpl::ContextProvider* provider) | 60 StreamTextureFactorySynchronousImpl::ContextProvider* provider) |
| 62 : context_provider_(provider), has_updated_(false) { | 61 : context_provider_(provider), has_updated_(false) { |
| 63 DCHECK(RenderThreadImpl::current()); | |
| 64 loop_ = RenderThreadImpl::current()->compositor_message_loop_proxy(); | |
| 65 std::fill(current_matrix_, current_matrix_ + 16, 0); | 62 std::fill(current_matrix_, current_matrix_ + 16, 0); |
| 66 } | 63 } |
| 67 | 64 |
| 68 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} | 65 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} |
| 69 | 66 |
| 70 void StreamTextureProxyImpl::Release() { | 67 void StreamTextureProxyImpl::Release() { |
| 71 SetClient(NULL); | 68 SetClient(NULL); |
| 72 if (!loop_->BelongsToCurrentThread()) | 69 if (loop_.get() && !loop_->BelongsToCurrentThread()) |
| 73 loop_->DeleteSoon(FROM_HERE, this); | 70 loop_->DeleteSoon(FROM_HERE, this); |
| 74 else | 71 else |
| 75 delete this; | 72 delete this; |
| 76 } | 73 } |
| 77 | 74 |
| 78 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { | 75 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { |
| 79 base::AutoLock lock(client_lock_); | 76 base::AutoLock lock(client_lock_); |
| 80 client_ = client; | 77 client_ = client; |
| 81 } | 78 } |
| 82 | 79 |
| 83 void StreamTextureProxyImpl::BindToCurrentThread(int stream_id) { | 80 void StreamTextureProxyImpl::BindToCurrentThread(int stream_id) { |
| 84 if (loop_->BelongsToCurrentThread()) { | 81 loop_ = base::MessageLoopProxy::current(); |
| 85 BindOnCompositorThread(stream_id); | |
| 86 return; | |
| 87 } | |
| 88 | |
| 89 // Weakptr is only used on compositor thread loop, so this is safe. | |
| 90 loop_->PostTask(FROM_HERE, | |
| 91 base::Bind(&StreamTextureProxyImpl::BindOnCompositorThread, | |
| 92 AsWeakPtr(), | |
| 93 stream_id)); | |
| 94 } | |
| 95 | |
| 96 void StreamTextureProxyImpl::BindOnCompositorThread(int stream_id) { | |
| 97 surface_texture_ = context_provider_->GetSurfaceTexture(stream_id); | 82 surface_texture_ = context_provider_->GetSurfaceTexture(stream_id); |
| 98 if (!surface_texture_) { | 83 if (!surface_texture_) { |
| 99 LOG(ERROR) << "Failed to get SurfaceTexture for stream."; | 84 LOG(ERROR) << "Failed to get SurfaceTexture for stream."; |
| 100 return; | 85 return; |
| 101 } | 86 } |
| 102 | 87 |
| 103 callback_ = | 88 callback_ = |
| 104 base::Bind(&StreamTextureProxyImpl::OnFrameAvailable, AsWeakPtr()); | 89 base::Bind(&StreamTextureProxyImpl::OnFrameAvailable, AsWeakPtr()); |
| 105 surface_texture_->SetFrameAvailableCallback(callback_); | 90 surface_texture_->SetFrameAvailableCallback(callback_); |
| 106 } | 91 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 void StreamTextureFactorySynchronousImpl::SetStreamTextureSize( | 176 void StreamTextureFactorySynchronousImpl::SetStreamTextureSize( |
| 192 int32 stream_id, | 177 int32 stream_id, |
| 193 const gfx::Size& size) {} | 178 const gfx::Size& size) {} |
| 194 | 179 |
| 195 gpu::gles2::GLES2Interface* StreamTextureFactorySynchronousImpl::ContextGL() { | 180 gpu::gles2::GLES2Interface* StreamTextureFactorySynchronousImpl::ContextGL() { |
| 196 DCHECK(context_provider_); | 181 DCHECK(context_provider_); |
| 197 return context_provider_->ContextGL(); | 182 return context_provider_->ContextGL(); |
| 198 } | 183 } |
| 199 | 184 |
| 200 } // namespace content | 185 } // namespace content |
| OLD | NEW |