Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/gpu/stream_texture_host_android.h" | 5 #include "content/renderer/gpu/stream_texture_host_android.h" |
| 6 | 6 |
| 7 #include "base/unguessable_token.h" | 7 #include "base/unguessable_token.h" |
| 8 #include "content/renderer/render_thread_impl.h" | 8 #include "content/renderer/render_thread_impl.h" |
| 9 #include "gpu/ipc/client/gpu_channel_host.h" | 9 #include "gpu/ipc/client/gpu_channel_host.h" |
| 10 #include "gpu/ipc/common/gpu_messages.h" | 10 #include "gpu/ipc/common/gpu_messages.h" |
| 11 #include "ipc/ipc_message_macros.h" | 11 #include "ipc/ipc_message_macros.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 StreamTextureHost::StreamTextureHost(scoped_refptr<gpu::GpuChannelHost> channel, | 15 StreamTextureHost::StreamTextureHost(scoped_refptr<gpu::GpuChannelHost> channel, |
| 16 int32_t route_id) | 16 int32_t route_id) |
| 17 : route_id_(route_id), | 17 : route_id_(route_id), |
| 18 listener_(NULL), | 18 listener_(NULL), |
|
watk
2016/11/23 20:26:07
nit: can you make this nullptr for consistency wit
tguilbert
2016/11/23 20:43:13
Done.
| |
| 19 channel_(std::move(channel)), | 19 channel_(std::move(channel)), |
| 20 weak_ptr_factory_(this) { | 20 weak_ptr_factory_(this) { |
| 21 DCHECK(channel_); | 21 DCHECK(channel_); |
| 22 DCHECK(route_id_); | |
| 22 } | 23 } |
| 23 | 24 |
| 24 StreamTextureHost::~StreamTextureHost() { | 25 StreamTextureHost::~StreamTextureHost() { |
| 25 if (channel_.get() && route_id_) | 26 if (!channel_.get()) |
| 26 channel_->RemoveRoute(route_id_); | 27 return; |
| 28 | |
| 29 channel_->RemoveRoute(route_id_); | |
| 27 } | 30 } |
| 28 | 31 |
| 29 bool StreamTextureHost::BindToCurrentThread(Listener* listener) { | 32 bool StreamTextureHost::BindToCurrentThread(Listener* listener) { |
| 30 listener_ = listener; | 33 listener_ = listener; |
| 31 if (channel_.get() && route_id_) { | 34 if (!channel_.get()) |
|
watk
2016/11/23 20:26:07
All the if (!channel_.get())s can be replace with
tguilbert
2016/11/23 20:43:13
Woops yes.
| |
| 32 channel_->AddRoute(route_id_, weak_ptr_factory_.GetWeakPtr()); | 35 return false; |
| 33 channel_->Send(new GpuStreamTextureMsg_StartListening(route_id_)); | |
| 34 return true; | |
| 35 } | |
| 36 | 36 |
| 37 return false; | 37 channel_->AddRoute(route_id_, weak_ptr_factory_.GetWeakPtr()); |
| 38 channel_->Send(new GpuStreamTextureMsg_StartListening(route_id_)); | |
| 39 | |
| 40 return true; | |
| 38 } | 41 } |
| 39 | 42 |
| 40 bool StreamTextureHost::OnMessageReceived(const IPC::Message& message) { | 43 bool StreamTextureHost::OnMessageReceived(const IPC::Message& message) { |
| 41 bool handled = true; | 44 bool handled = true; |
| 42 IPC_BEGIN_MESSAGE_MAP(StreamTextureHost, message) | 45 IPC_BEGIN_MESSAGE_MAP(StreamTextureHost, message) |
| 43 IPC_MESSAGE_HANDLER(GpuStreamTextureMsg_FrameAvailable, | 46 IPC_MESSAGE_HANDLER(GpuStreamTextureMsg_FrameAvailable, OnFrameAvailable); |
| 44 OnFrameAvailable); | |
| 45 IPC_MESSAGE_UNHANDLED(handled = false) | 47 IPC_MESSAGE_UNHANDLED(handled = false) |
| 46 IPC_END_MESSAGE_MAP() | 48 IPC_END_MESSAGE_MAP() |
| 47 DCHECK(handled); | 49 DCHECK(handled); |
| 48 return handled; | 50 return handled; |
| 49 } | 51 } |
| 50 | 52 |
| 51 void StreamTextureHost::OnChannelError() { | 53 void StreamTextureHost::OnChannelError() { |
| 54 channel_ = nullptr; | |
| 52 } | 55 } |
| 53 | 56 |
| 54 void StreamTextureHost::OnFrameAvailable() { | 57 void StreamTextureHost::OnFrameAvailable() { |
| 55 if (listener_) | 58 if (!listener_) |
| 56 listener_->OnFrameAvailable(); | 59 return; |
|
watk
2016/11/23 20:26:07
Re your question: think it's a personal preference
tguilbert
2016/11/23 20:43:13
Ok. I also preferred the old way. Changing it back
| |
| 60 | |
| 61 listener_->OnFrameAvailable(); | |
| 57 } | 62 } |
| 58 | 63 |
| 59 void StreamTextureHost::EstablishPeer(int player_id, int frame_id) { | 64 void StreamTextureHost::EstablishPeer(int player_id, int frame_id) { |
| 60 if (route_id_) { | 65 if (!channel_.get()) |
| 61 channel_->Send( | 66 return; |
| 62 new GpuStreamTextureMsg_EstablishPeer(route_id_, frame_id, player_id)); | 67 |
| 63 } | 68 channel_->Send( |
| 69 new GpuStreamTextureMsg_EstablishPeer(route_id_, frame_id, player_id)); | |
| 64 } | 70 } |
| 65 | 71 |
| 66 void StreamTextureHost::SetStreamTextureSize(const gfx::Size& size) { | 72 void StreamTextureHost::SetStreamTextureSize(const gfx::Size& size) { |
| 67 if (route_id_) | 73 if (!channel_.get()) |
| 68 channel_->Send(new GpuStreamTextureMsg_SetSize(route_id_, size)); | 74 return; |
| 75 | |
| 76 channel_->Send(new GpuStreamTextureMsg_SetSize(route_id_, size)); | |
| 69 } | 77 } |
| 70 | 78 |
| 71 void StreamTextureHost::ForwardStreamTextureForSurfaceRequest( | 79 void StreamTextureHost::ForwardStreamTextureForSurfaceRequest( |
| 72 const base::UnguessableToken& request_token) { | 80 const base::UnguessableToken& request_token) { |
| 73 if (route_id_) { | 81 if (!channel_.get()) |
| 74 channel_->Send(new GpuStreamTextureMsg_ForwardForSurfaceRequest( | 82 return; |
| 75 route_id_, request_token)); | 83 |
| 76 } | 84 channel_->Send(new GpuStreamTextureMsg_ForwardForSurfaceRequest( |
| 85 route_id_, request_token)); | |
| 77 } | 86 } |
| 78 | 87 |
| 79 } // namespace content | 88 } // namespace content |
| OLD | NEW |