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.h" | 5 #include "content/renderer/media/android/stream_texture_factory.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "cc/output/context_provider.h" | 8 #include "cc/output/context_provider.h" |
9 #include "content/common/gpu/client/context_provider_command_buffer.h" | 9 #include "content/common/gpu/client/context_provider_command_buffer.h" |
10 #include "gpu/command_buffer/client/gles2_interface.h" | 10 #include "gpu/command_buffer/client/gles2_interface.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 // Release is analogous to the destructor, so there should be no more external | 28 // Release is analogous to the destructor, so there should be no more external |
29 // calls to this object in Release. Therefore there is no need to acquire the | 29 // calls to this object in Release. Therefore there is no need to acquire the |
30 // lock to access |task_runner_|. | 30 // lock to access |task_runner_|. |
31 if (!task_runner_.get() || task_runner_->BelongsToCurrentThread() || | 31 if (!task_runner_.get() || task_runner_->BelongsToCurrentThread() || |
32 !task_runner_->DeleteSoon(FROM_HERE, this)) { | 32 !task_runner_->DeleteSoon(FROM_HERE, this)) { |
33 delete this; | 33 delete this; |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 void StreamTextureProxy::BindToTaskRunner( | 37 void StreamTextureProxy::BindToTaskRunner( |
38 int32_t stream_id, | |
39 const base::Closure& received_frame_cb, | 38 const base::Closure& received_frame_cb, |
40 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | 39 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
41 DCHECK(task_runner.get()); | 40 DCHECK(task_runner.get()); |
42 | 41 |
43 { | 42 { |
44 base::AutoLock lock(lock_); | 43 base::AutoLock lock(lock_); |
45 DCHECK(!task_runner_.get() || (task_runner.get() == task_runner_.get())); | 44 DCHECK(!task_runner_.get() || (task_runner.get() == task_runner_.get())); |
46 task_runner_ = task_runner; | 45 task_runner_ = task_runner; |
47 received_frame_cb_ = received_frame_cb; | 46 received_frame_cb_ = received_frame_cb; |
48 } | 47 } |
49 | 48 |
50 if (task_runner->BelongsToCurrentThread()) { | 49 if (task_runner->BelongsToCurrentThread()) { |
51 BindOnThread(stream_id); | 50 BindOnThread(); |
52 return; | 51 return; |
53 } | 52 } |
54 // Unretained is safe here only because the object is deleted on |loop_| | 53 // Unretained is safe here only because the object is deleted on |loop_| |
55 // thread. | 54 // thread. |
56 task_runner->PostTask(FROM_HERE, | 55 task_runner->PostTask(FROM_HERE, base::Bind(&StreamTextureProxy::BindOnThread, |
57 base::Bind(&StreamTextureProxy::BindOnThread, | 56 base::Unretained(this))); |
58 base::Unretained(this), stream_id)); | |
59 } | 57 } |
60 | 58 |
61 void StreamTextureProxy::BindOnThread(int32_t stream_id) { | 59 void StreamTextureProxy::BindOnThread() { |
62 host_->BindToCurrentThread(stream_id, this); | 60 host_->BindToCurrentThread(this); |
63 } | 61 } |
64 | 62 |
65 void StreamTextureProxy::OnFrameAvailable() { | 63 void StreamTextureProxy::OnFrameAvailable() { |
66 base::AutoLock lock(lock_); | 64 base::AutoLock lock(lock_); |
67 if (!received_frame_cb_.is_null()) | 65 if (!received_frame_cb_.is_null()) |
68 received_frame_cb_.Run(); | 66 received_frame_cb_.Run(); |
69 } | 67 } |
70 | 68 |
| 69 void StreamTextureProxy::EstablishPeer(int player_id, int frame_id) { |
| 70 host_->EstablishPeer(player_id, frame_id); |
| 71 } |
| 72 |
| 73 void StreamTextureProxy::SetStreamTextureSize(const gfx::Size& size) { |
| 74 host_->SetStreamTextureSize(size); |
| 75 } |
| 76 |
| 77 void StreamTextureProxy::ForwardStreamTextureForSurfaceRequest( |
| 78 const base::UnguessableToken& request_token) { |
| 79 host_->ForwardStreamTextureForSurfaceRequest(request_token); |
| 80 } |
| 81 |
71 // static | 82 // static |
72 scoped_refptr<StreamTextureFactory> StreamTextureFactory::Create( | 83 scoped_refptr<StreamTextureFactory> StreamTextureFactory::Create( |
73 scoped_refptr<ContextProviderCommandBuffer> context_provider) { | 84 scoped_refptr<ContextProviderCommandBuffer> context_provider) { |
74 return new StreamTextureFactory(std::move(context_provider)); | 85 return new StreamTextureFactory(std::move(context_provider)); |
75 } | 86 } |
76 | 87 |
77 StreamTextureFactory::StreamTextureFactory( | 88 StreamTextureFactory::StreamTextureFactory( |
78 scoped_refptr<ContextProviderCommandBuffer> context_provider) | 89 scoped_refptr<ContextProviderCommandBuffer> context_provider) |
79 : context_provider_(std::move(context_provider)), | 90 : context_provider_(std::move(context_provider)), |
80 channel_(context_provider_->GetCommandBufferProxy()->channel()) { | 91 channel_(context_provider_->GetCommandBufferProxy()->channel()) { |
81 DCHECK(channel_); | 92 DCHECK(channel_); |
82 } | 93 } |
83 | 94 |
84 StreamTextureFactory::~StreamTextureFactory() {} | 95 StreamTextureFactory::~StreamTextureFactory() {} |
85 | 96 |
86 StreamTextureProxy* StreamTextureFactory::CreateProxy() { | 97 StreamTextureProxy* StreamTextureFactory::CreateProxy( |
87 StreamTextureHost* host = new StreamTextureHost(channel_); | 98 unsigned texture_target, |
| 99 unsigned* texture_id, |
| 100 gpu::Mailbox* texture_mailbox) { |
| 101 int32_t route_id = |
| 102 CreateStreamTexture(texture_target, texture_id, texture_mailbox); |
| 103 if (!route_id) |
| 104 return nullptr; |
| 105 StreamTextureHost* host = new StreamTextureHost(channel_, route_id); |
88 return new StreamTextureProxy(host); | 106 return new StreamTextureProxy(host); |
89 } | 107 } |
90 | 108 |
91 void StreamTextureFactory::EstablishPeer(int32_t stream_id, | |
92 int player_id, | |
93 int frame_id) { | |
94 channel_->Send( | |
95 new GpuStreamTextureMsg_EstablishPeer(stream_id, frame_id, player_id)); | |
96 } | |
97 | |
98 void StreamTextureFactory::ForwardStreamTextureForSurfaceRequest( | |
99 int32_t stream_id, | |
100 const base::UnguessableToken& request_token) { | |
101 channel_->Send(new GpuStreamTextureMsg_ForwardForSurfaceRequest( | |
102 stream_id, request_token)); | |
103 } | |
104 | |
105 unsigned StreamTextureFactory::CreateStreamTexture( | 109 unsigned StreamTextureFactory::CreateStreamTexture( |
106 unsigned texture_target, | 110 unsigned texture_target, |
107 unsigned* texture_id, | 111 unsigned* texture_id, |
108 gpu::Mailbox* texture_mailbox) { | 112 gpu::Mailbox* texture_mailbox) { |
109 GLuint stream_id = 0; | 113 GLuint route_id = 0; |
110 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | 114 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
111 gl->GenTextures(1, texture_id); | 115 gl->GenTextures(1, texture_id); |
112 gl->ShallowFlushCHROMIUM(); | 116 gl->ShallowFlushCHROMIUM(); |
113 stream_id = context_provider_->GetCommandBufferProxy()->CreateStreamTexture( | 117 route_id = context_provider_->GetCommandBufferProxy()->CreateStreamTexture( |
114 *texture_id); | 118 *texture_id); |
115 gl->GenMailboxCHROMIUM(texture_mailbox->name); | 119 if (!route_id) { |
116 gl->ProduceTextureDirectCHROMIUM( | 120 gl->DeleteTextures(1, texture_id); |
117 *texture_id, texture_target, texture_mailbox->name); | 121 // Flush to ensure that the stream texture gets deleted in a timely fashion. |
118 return stream_id; | 122 gl->ShallowFlushCHROMIUM(); |
119 } | 123 *texture_id = 0; |
120 | 124 *texture_mailbox = gpu::Mailbox(); |
121 void StreamTextureFactory::SetStreamTextureSize(int32_t stream_id, | 125 } else { |
122 const gfx::Size& size) { | 126 gl->GenMailboxCHROMIUM(texture_mailbox->name); |
123 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size)); | 127 gl->ProduceTextureDirectCHROMIUM(*texture_id, texture_target, |
| 128 texture_mailbox->name); |
| 129 } |
| 130 return route_id; |
124 } | 131 } |
125 | 132 |
126 gpu::gles2::GLES2Interface* StreamTextureFactory::ContextGL() { | 133 gpu::gles2::GLES2Interface* StreamTextureFactory::ContextGL() { |
127 return context_provider_->ContextGL(); | 134 return context_provider_->ContextGL(); |
128 } | 135 } |
129 | 136 |
130 } // namespace content | 137 } // namespace content |
OLD | NEW |