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 "media/gpu/ipc/service/gpu_video_decode_accelerator.h" | 5 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 IPC::Sender* sender_; | 154 IPC::Sender* sender_; |
155 }; | 155 }; |
156 | 156 |
157 GpuVideoDecodeAccelerator::GpuVideoDecodeAccelerator( | 157 GpuVideoDecodeAccelerator::GpuVideoDecodeAccelerator( |
158 int32_t host_route_id, | 158 int32_t host_route_id, |
159 gpu::GpuCommandBufferStub* stub, | 159 gpu::GpuCommandBufferStub* stub, |
160 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 160 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
161 const AndroidOverlayMojoFactoryCB& overlay_factory_cb) | 161 const AndroidOverlayMojoFactoryCB& overlay_factory_cb) |
162 : host_route_id_(host_route_id), | 162 : host_route_id_(host_route_id), |
163 stub_(stub), | 163 stub_(stub), |
164 texture_target_(0), | |
165 textures_per_buffer_(0), | 164 textures_per_buffer_(0), |
166 filter_removed_(base::WaitableEvent::ResetPolicy::MANUAL, | 165 filter_removed_(base::WaitableEvent::ResetPolicy::MANUAL, |
167 base::WaitableEvent::InitialState::NOT_SIGNALED), | 166 base::WaitableEvent::InitialState::NOT_SIGNALED), |
168 child_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 167 child_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
169 io_task_runner_(io_task_runner), | 168 io_task_runner_(io_task_runner), |
170 overlay_factory_cb_(overlay_factory_cb), | 169 overlay_factory_cb_(overlay_factory_cb), |
171 weak_factory_for_io_(this) { | 170 weak_factory_for_io_(this) { |
172 DCHECK(stub_); | 171 DCHECK(stub_); |
173 stub_->AddDestructionObserver(this); | 172 stub_->AddDestructionObserver(this); |
174 get_gl_context_cb_ = base::Bind(&GetGLContext, stub_->AsWeakPtr()); | 173 get_gl_context_cb_ = base::Bind(&GetGLContext, stub_->AsWeakPtr()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 dimensions.GetArea() > limits::kMaxCanvas) { | 233 dimensions.GetArea() > limits::kMaxCanvas) { |
235 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); | 234 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); |
236 return; | 235 return; |
237 } | 236 } |
238 if (!Send(new AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers( | 237 if (!Send(new AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers( |
239 host_route_id_, requested_num_of_buffers, format, textures_per_buffer, | 238 host_route_id_, requested_num_of_buffers, format, textures_per_buffer, |
240 dimensions, texture_target))) { | 239 dimensions, texture_target))) { |
241 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers) " | 240 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers) " |
242 << "failed"; | 241 << "failed"; |
243 } | 242 } |
244 texture_dimensions_ = dimensions; | |
245 textures_per_buffer_ = textures_per_buffer; | 243 textures_per_buffer_ = textures_per_buffer; |
246 texture_target_ = texture_target; | |
247 } | 244 } |
248 | 245 |
249 void GpuVideoDecodeAccelerator::DismissPictureBuffer( | 246 void GpuVideoDecodeAccelerator::DismissPictureBuffer( |
250 int32_t picture_buffer_id) { | 247 int32_t picture_buffer_id) { |
251 // Notify client that picture buffer is now unused. | 248 // Notify client that picture buffer is now unused. |
252 if (!Send(new AcceleratedVideoDecoderHostMsg_DismissPictureBuffer( | 249 if (!Send(new AcceleratedVideoDecoderHostMsg_DismissPictureBuffer( |
253 host_route_id_, picture_buffer_id))) { | 250 host_route_id_, picture_buffer_id))) { |
254 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_DismissPictureBuffer) " | 251 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_DismissPictureBuffer) " |
255 << "failed"; | 252 << "failed"; |
256 } | 253 } |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 // Runs on IO thread if VDA::TryToSetupDecodeOnSeparateThread() succeeded, | 392 // Runs on IO thread if VDA::TryToSetupDecodeOnSeparateThread() succeeded, |
396 // otherwise on the main thread. | 393 // otherwise on the main thread. |
397 void GpuVideoDecodeAccelerator::OnDecode( | 394 void GpuVideoDecodeAccelerator::OnDecode( |
398 const BitstreamBuffer& bitstream_buffer) { | 395 const BitstreamBuffer& bitstream_buffer) { |
399 DCHECK(video_decode_accelerator_); | 396 DCHECK(video_decode_accelerator_); |
400 video_decode_accelerator_->Decode(bitstream_buffer); | 397 video_decode_accelerator_->Decode(bitstream_buffer); |
401 } | 398 } |
402 | 399 |
403 void GpuVideoDecodeAccelerator::OnAssignPictureBuffers( | 400 void GpuVideoDecodeAccelerator::OnAssignPictureBuffers( |
404 const std::vector<int32_t>& buffer_ids, | 401 const std::vector<int32_t>& buffer_ids, |
405 const std::vector<PictureBuffer::TextureIds>& texture_ids) { | 402 const std::vector<PictureBuffer::TextureIds>& texture_ids, |
403 uint32_t texture_target, | |
404 VideoPixelFormat format, | |
405 const gfx::Size& dimensions) { | |
406 if (buffer_ids.size() != texture_ids.size()) { | 406 if (buffer_ids.size() != texture_ids.size()) { |
407 NotifyError(VideoDecodeAccelerator::INVALID_ARGUMENT); | 407 NotifyError(VideoDecodeAccelerator::INVALID_ARGUMENT); |
408 return; | 408 return; |
409 } | 409 } |
410 | 410 |
411 gpu::gles2::GLES2Decoder* command_decoder = stub_->decoder(); | 411 gpu::gles2::GLES2Decoder* command_decoder = stub_->decoder(); |
412 gpu::gles2::TextureManager* texture_manager = | 412 gpu::gles2::TextureManager* texture_manager = |
413 command_decoder->GetContextGroup()->texture_manager(); | 413 command_decoder->GetContextGroup()->texture_manager(); |
414 | 414 |
415 std::vector<PictureBuffer> buffers; | 415 std::vector<PictureBuffer> buffers; |
(...skipping 16 matching lines...) Expand all Loading... | |
432 } | 432 } |
433 for (size_t j = 0; j < textures_per_buffer_; j++) { | 433 for (size_t j = 0; j < textures_per_buffer_; j++) { |
434 gpu::gles2::TextureRef* texture_ref = | 434 gpu::gles2::TextureRef* texture_ref = |
435 texture_manager->GetTexture(buffer_texture_ids[j]); | 435 texture_manager->GetTexture(buffer_texture_ids[j]); |
436 if (!texture_ref) { | 436 if (!texture_ref) { |
437 DLOG(ERROR) << "Failed to find texture id " << buffer_texture_ids[j]; | 437 DLOG(ERROR) << "Failed to find texture id " << buffer_texture_ids[j]; |
438 NotifyError(VideoDecodeAccelerator::INVALID_ARGUMENT); | 438 NotifyError(VideoDecodeAccelerator::INVALID_ARGUMENT); |
439 return; | 439 return; |
440 } | 440 } |
441 gpu::gles2::Texture* info = texture_ref->texture(); | 441 gpu::gles2::Texture* info = texture_ref->texture(); |
442 if (info->target() != texture_target_) { | 442 if (info->target() != texture_target) { |
443 DLOG(ERROR) << "Texture target mismatch for texture id " | 443 DLOG(ERROR) << "Texture target mismatch for texture id " |
444 << buffer_texture_ids[j]; | 444 << buffer_texture_ids[j]; |
445 NotifyError(VideoDecodeAccelerator::INVALID_ARGUMENT); | 445 NotifyError(VideoDecodeAccelerator::INVALID_ARGUMENT); |
446 return; | 446 return; |
447 } | 447 } |
448 if (texture_target_ == GL_TEXTURE_EXTERNAL_OES || | 448 if (texture_target == GL_TEXTURE_EXTERNAL_OES || |
449 texture_target_ == GL_TEXTURE_RECTANGLE_ARB) { | 449 texture_target == GL_TEXTURE_RECTANGLE_ARB) { |
450 // These textures have their dimensions defined by the underlying | 450 // These textures have their dimensions defined by the underlying |
451 // storage. | 451 // storage. |
452 // Use |texture_dimensions_| for this size. | 452 // Use |dimensions| for this size. |
453 texture_manager->SetLevelInfo(texture_ref, texture_target_, 0, GL_RGBA, | 453 texture_manager->SetLevelInfo( |
454 texture_dimensions_.width(), | 454 texture_ref, texture_target, 0, GL_RGBA, dimensions.width(), |
455 texture_dimensions_.height(), 1, 0, | 455 dimensions.height(), 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect()); |
456 GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect()); | |
457 } else { | 456 } else { |
458 // For other targets, texture dimensions should already be defined. | 457 // For other targets, texture dimensions should already be defined. |
459 GLsizei width = 0, height = 0; | 458 GLsizei width = 0, height = 0; |
460 info->GetLevelSize(texture_target_, 0, &width, &height, nullptr); | 459 info->GetLevelSize(texture_target, 0, &width, &height, nullptr); |
461 if (width != texture_dimensions_.width() || | 460 if (width != dimensions.width() || height != dimensions.height()) { |
462 height != texture_dimensions_.height()) { | |
463 DLOG(ERROR) << "Size mismatch for texture id " | 461 DLOG(ERROR) << "Size mismatch for texture id " |
464 << buffer_texture_ids[j]; | 462 << buffer_texture_ids[j]; |
465 NotifyError(VideoDecodeAccelerator::INVALID_ARGUMENT); | 463 NotifyError(VideoDecodeAccelerator::INVALID_ARGUMENT); |
466 return; | 464 return; |
467 } | 465 } |
468 | 466 |
469 // TODO(dshwang): after moving to D3D11, remove this. crbug.com/438691 | 467 // TODO(dshwang): after moving to D3D11, remove this. crbug.com/438691 |
470 GLenum format = | 468 GLenum format = |
471 video_decode_accelerator_.get()->GetSurfaceInternalFormat(); | 469 video_decode_accelerator_.get()->GetSurfaceInternalFormat(); |
472 if (format != GL_RGBA) { | 470 if (format != GL_RGBA) { |
473 DCHECK(format == GL_BGRA_EXT); | 471 DCHECK(format == GL_BGRA_EXT); |
474 texture_manager->SetLevelInfo(texture_ref, texture_target_, 0, format, | 472 texture_manager->SetLevelInfo(texture_ref, texture_target, 0, format, |
475 width, height, 1, 0, format, | 473 width, height, 1, 0, format, |
476 GL_UNSIGNED_BYTE, gfx::Rect()); | 474 GL_UNSIGNED_BYTE, gfx::Rect()); |
477 } | 475 } |
478 } | 476 } |
479 service_ids.push_back(texture_ref->service_id()); | 477 service_ids.push_back(texture_ref->service_id()); |
480 current_textures.push_back(texture_ref); | 478 current_textures.push_back(texture_ref); |
481 } | 479 } |
482 textures.push_back(current_textures); | 480 textures.push_back(current_textures); |
483 buffers.push_back(PictureBuffer(buffer_ids[i], texture_dimensions_, | 481 buffers.push_back(PictureBuffer(buffer_ids[i], dimensions, |
liberato (no reviews please)
2017/05/16 17:25:24
i think that this should pass in |texture_target|
Chandan
2017/05/17 12:07:06
Done.
| |
484 buffer_texture_ids, service_ids)); | 482 buffer_texture_ids, service_ids)); |
485 } | 483 } |
486 { | 484 { |
487 DebugAutoLock auto_lock(debug_uncleared_textures_lock_); | 485 DebugAutoLock auto_lock(debug_uncleared_textures_lock_); |
488 for (uint32_t i = 0; i < buffer_ids.size(); ++i) | 486 for (uint32_t i = 0; i < buffer_ids.size(); ++i) |
489 uncleared_textures_[buffer_ids[i]] = textures[i]; | 487 uncleared_textures_[buffer_ids[i]] = textures[i]; |
490 } | 488 } |
491 video_decode_accelerator_->AssignPictureBuffers(buffers); | 489 video_decode_accelerator_->AssignPictureBuffers(buffers); |
492 } | 490 } |
493 | 491 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 for (auto texture_ref : it->second) { | 531 for (auto texture_ref : it->second) { |
534 GLenum target = texture_ref->texture()->target(); | 532 GLenum target = texture_ref->texture()->target(); |
535 gpu::gles2::TextureManager* texture_manager = | 533 gpu::gles2::TextureManager* texture_manager = |
536 stub_->decoder()->GetContextGroup()->texture_manager(); | 534 stub_->decoder()->GetContextGroup()->texture_manager(); |
537 texture_manager->SetLevelCleared(texture_ref.get(), target, 0, true); | 535 texture_manager->SetLevelCleared(texture_ref.get(), target, 0, true); |
538 } | 536 } |
539 uncleared_textures_.erase(it); | 537 uncleared_textures_.erase(it); |
540 } | 538 } |
541 | 539 |
542 } // namespace media | 540 } // namespace media |
OLD | NEW |