| 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/media/renderer_gpu_video_decoder_factories.h" | 5 #include "content/renderer/media/renderer_gpu_video_decoder_factories.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
| 8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 vda_.reset(gpu_channel_host_->CreateVideoDecoder( | 91 vda_.reset(gpu_channel_host_->CreateVideoDecoder( |
| 92 context_->GetCommandBufferProxy()->GetRouteID(), | 92 context_->GetCommandBufferProxy()->GetRouteID(), |
| 93 profile, client)); | 93 profile, client)); |
| 94 } | 94 } |
| 95 async_waiter_.Signal(); | 95 async_waiter_.Signal(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool RendererGpuVideoDecoderFactories::CreateTextures( | 98 bool RendererGpuVideoDecoderFactories::CreateTextures( |
| 99 int32 count, const gfx::Size& size, | 99 int32 count, const gfx::Size& size, |
| 100 std::vector<uint32>* texture_ids, | 100 std::vector<uint32>* texture_ids, |
| 101 std::vector<gpu::Mailbox>* texture_mailboxes, |
| 101 uint32 texture_target) { | 102 uint32 texture_target) { |
| 102 DCHECK(!message_loop_->BelongsToCurrentThread()); | 103 DCHECK(!message_loop_->BelongsToCurrentThread()); |
| 103 message_loop_->PostTask(FROM_HERE, base::Bind( | 104 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 104 &RendererGpuVideoDecoderFactories::AsyncCreateTextures, this, | 105 &RendererGpuVideoDecoderFactories::AsyncCreateTextures, this, |
| 105 count, size, texture_target)); | 106 count, size, texture_target)); |
| 106 | 107 |
| 107 base::WaitableEvent* objects[] = {&aborted_waiter_, &async_waiter_}; | 108 base::WaitableEvent* objects[] = {&aborted_waiter_, &async_waiter_}; |
| 108 if (base::WaitableEvent::WaitMany(objects, arraysize(objects)) == 0) | 109 if (base::WaitableEvent::WaitMany(objects, arraysize(objects)) == 0) |
| 109 return false; | 110 return false; |
| 110 texture_ids->swap(created_textures_); | 111 texture_ids->swap(created_textures_); |
| 112 texture_mailboxes->swap(created_texture_mailboxes_); |
| 111 return true; | 113 return true; |
| 112 } | 114 } |
| 113 | 115 |
| 114 void RendererGpuVideoDecoderFactories::AsyncCreateTextures( | 116 void RendererGpuVideoDecoderFactories::AsyncCreateTextures( |
| 115 int32 count, const gfx::Size& size, uint32 texture_target) { | 117 int32 count, const gfx::Size& size, uint32 texture_target) { |
| 116 DCHECK(message_loop_->BelongsToCurrentThread()); | 118 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 117 DCHECK(texture_target); | 119 DCHECK(texture_target); |
| 118 | 120 |
| 119 if (!context_) { | 121 if (!context_) { |
| 120 async_waiter_.Signal(); | 122 async_waiter_.Signal(); |
| 121 return; | 123 return; |
| 122 } | 124 } |
| 123 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); | 125 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); |
| 124 created_textures_.resize(count); | 126 created_textures_.resize(count); |
| 127 created_texture_mailboxes_.resize(count); |
| 125 gles2->GenTextures(count, &created_textures_[0]); | 128 gles2->GenTextures(count, &created_textures_[0]); |
| 126 for (int i = 0; i < count; ++i) { | 129 for (int i = 0; i < count; ++i) { |
| 127 gles2->ActiveTexture(GL_TEXTURE0); | 130 gles2->ActiveTexture(GL_TEXTURE0); |
| 128 uint32 texture_id = created_textures_[i]; | 131 uint32 texture_id = created_textures_[i]; |
| 129 gles2->BindTexture(texture_target, texture_id); | 132 gles2->BindTexture(texture_target, texture_id); |
| 130 gles2->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 133 gles2->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 131 gles2->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 134 gles2->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 132 gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 135 gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 133 gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 136 gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 134 if (texture_target == GL_TEXTURE_2D) { | 137 if (texture_target == GL_TEXTURE_2D) { |
| 135 gles2->TexImage2D(texture_target, 0, GL_RGBA, size.width(), size.height(), | 138 gles2->TexImage2D(texture_target, 0, GL_RGBA, size.width(), size.height(), |
| 136 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 139 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 137 } | 140 } |
| 141 gles2->GenMailboxCHROMIUM(created_texture_mailboxes_[i].name); |
| 138 } | 142 } |
| 139 // We need a glFlush here to guarantee the decoder (in the GPU process) can | 143 // We need a glFlush here to guarantee the decoder (in the GPU process) can |
| 140 // use the texture ids we return here. Since textures are expected to be | 144 // use the texture ids we return here. Since textures are expected to be |
| 141 // reused, this should not be unacceptably expensive. | 145 // reused, this should not be unacceptably expensive. |
| 142 gles2->Flush(); | 146 gles2->Flush(); |
| 143 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); | 147 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
| 144 async_waiter_.Signal(); | 148 async_waiter_.Signal(); |
| 145 } | 149 } |
| 146 | 150 |
| 147 void RendererGpuVideoDecoderFactories::DeleteTexture(uint32 texture_id) { | 151 void RendererGpuVideoDecoderFactories::DeleteTexture(uint32 texture_id) { |
| 148 DCHECK(!message_loop_->BelongsToCurrentThread()); | 152 DCHECK(!message_loop_->BelongsToCurrentThread()); |
| 149 message_loop_->PostTask(FROM_HERE, base::Bind( | 153 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 150 &RendererGpuVideoDecoderFactories::AsyncDeleteTexture, this, texture_id)); | 154 &RendererGpuVideoDecoderFactories::AsyncDeleteTexture, this, texture_id)); |
| 151 } | 155 } |
| 152 | 156 |
| 153 void RendererGpuVideoDecoderFactories::AsyncDeleteTexture(uint32 texture_id) { | 157 void RendererGpuVideoDecoderFactories::AsyncDeleteTexture(uint32 texture_id) { |
| 154 DCHECK(message_loop_->BelongsToCurrentThread()); | 158 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 155 if (!context_) | 159 if (!context_) |
| 156 return; | 160 return; |
| 157 | 161 |
| 158 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); | 162 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); |
| 159 gles2->DeleteTextures(1, &texture_id); | 163 gles2->DeleteTextures(1, &texture_id); |
| 160 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); | 164 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
| 161 } | 165 } |
| 162 | 166 |
| 167 uint32 RendererGpuVideoDecoderFactories::ProduceTextureToMailbox( |
| 168 const gpu::Mailbox& mailbox, |
| 169 uint32 texture_id) { |
| 170 uint32 sync_point = 0; |
| 171 if (message_loop_->BelongsToCurrentThread()) { |
| 172 AsyncProduceTextureToMailbox(mailbox, texture_id, &sync_point); |
| 173 return sync_point; |
| 174 } |
| 175 |
| 176 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 177 &RendererGpuVideoDecoderFactories::AsyncProduceTextureToMailbox, |
| 178 this, |
| 179 mailbox, |
| 180 texture_id, |
| 181 &sync_point)); |
| 182 base::WaitableEvent* objects[] = {&aborted_waiter_, &async_waiter_}; |
| 183 base::WaitableEvent::WaitMany(objects, arraysize(objects)); |
| 184 return sync_point; |
| 185 } |
| 186 |
| 187 void RendererGpuVideoDecoderFactories::AsyncProduceTextureToMailbox( |
| 188 const gpu::Mailbox& mailbox, uint32 texture_id, uint32* sync_point) { |
| 189 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 190 |
| 191 *sync_point = 0; |
| 192 if (!context_) { |
| 193 async_waiter_.Signal(); |
| 194 return; |
| 195 } |
| 196 |
| 197 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); |
| 198 gles2->BindTexture(GL_TEXTURE_2D, texture_id); |
| 199 gles2->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 200 *sync_point = gles2->InsertSyncPointCHROMIUM(); |
| 201 } |
| 202 |
| 203 void RendererGpuVideoDecoderFactories::ConsumeMailboxToTexture( |
| 204 const gpu::Mailbox& mailbox, uint32 texture_id, uint32 sync_point) { |
| 205 if (message_loop_->BelongsToCurrentThread()) { |
| 206 AsyncConsumeMailboxToTexture(mailbox, texture_id, sync_point); |
| 207 return; |
| 208 } |
| 209 |
| 210 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 211 &RendererGpuVideoDecoderFactories::AsyncConsumeMailboxToTexture, |
| 212 this, |
| 213 mailbox, |
| 214 texture_id, |
| 215 sync_point)); |
| 216 base::WaitableEvent* objects[] = {&aborted_waiter_, &async_waiter_}; |
| 217 base::WaitableEvent::WaitMany(objects, arraysize(objects)); |
| 218 } |
| 219 |
| 220 void RendererGpuVideoDecoderFactories::AsyncConsumeMailboxToTexture( |
| 221 const gpu::Mailbox& mailbox, uint32 texture_id, uint32 sync_point) { |
| 222 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 223 if (!context_) { |
| 224 async_waiter_.Signal(); |
| 225 return; |
| 226 } |
| 227 |
| 228 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); |
| 229 gles2->WaitSyncPointCHROMIUM(sync_point); |
| 230 gles2->BindTexture(GL_TEXTURE_2D, texture_id); |
| 231 gles2->ConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 232 } |
| 233 |
| 163 void RendererGpuVideoDecoderFactories::ReadPixels( | 234 void RendererGpuVideoDecoderFactories::ReadPixels( |
| 164 uint32 texture_id, uint32 texture_target, const gfx::Size& size, | 235 uint32 texture_id, uint32 texture_target, const gfx::Size& size, |
| 165 const SkBitmap& pixels) { | 236 const SkBitmap& pixels) { |
| 166 // SkBitmaps use the SkPixelRef object to refcount the underlying pixels. | 237 // SkBitmaps use the SkPixelRef object to refcount the underlying pixels. |
| 167 // Multiple SkBitmaps can share a SkPixelRef instance. We use this to | 238 // Multiple SkBitmaps can share a SkPixelRef instance. We use this to |
| 168 // ensure that the underlying pixels in the SkBitmap passed in remain valid | 239 // ensure that the underlying pixels in the SkBitmap passed in remain valid |
| 169 // until the AsyncReadPixels() call completes. | 240 // until the AsyncReadPixels() call completes. |
| 170 read_pixels_bitmap_.setPixelRef(pixels.pixelRef()); | 241 read_pixels_bitmap_.setPixelRef(pixels.pixelRef()); |
| 171 | 242 |
| 172 if (!message_loop_->BelongsToCurrentThread()) { | 243 if (!message_loop_->BelongsToCurrentThread()) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 return aborted_waiter_.IsSignaled(); | 322 return aborted_waiter_.IsSignaled(); |
| 252 } | 323 } |
| 253 | 324 |
| 254 void RendererGpuVideoDecoderFactories::AsyncDestroyVideoDecodeAccelerator() { | 325 void RendererGpuVideoDecoderFactories::AsyncDestroyVideoDecodeAccelerator() { |
| 255 // OK to release because Destroy() will delete the VDA instance. | 326 // OK to release because Destroy() will delete the VDA instance. |
| 256 if (vda_) | 327 if (vda_) |
| 257 vda_.release()->Destroy(); | 328 vda_.release()->Destroy(); |
| 258 } | 329 } |
| 259 | 330 |
| 260 } // namespace content | 331 } // namespace content |
| OLD | NEW |