| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chromecast/renderer/media/hole_frame_factory.h" | 5 #include "media/renderers/video_overlay_factory.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "gpu/GLES2/gl2extchromium.h" | 9 #include "gpu/GLES2/gl2extchromium.h" |
| 10 #include "gpu/command_buffer/client/gles2_interface.h" | 10 #include "gpu/command_buffer/client/gles2_interface.h" |
| 11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
| 12 #include "media/renderers/gpu_video_accelerator_factories.h" | 12 #include "media/renderers/gpu_video_accelerator_factories.h" |
| 13 | 13 |
| 14 namespace chromecast { | |
| 15 namespace media { | 14 namespace media { |
| 16 | 15 |
| 17 HoleFrameFactory::HoleFrameFactory( | 16 VideoOverlayFactory::VideoOverlayFactory( |
| 18 ::media::GpuVideoAcceleratorFactories* gpu_factories) | 17 GpuVideoAcceleratorFactories* gpu_factories) |
| 19 : gpu_factories_(gpu_factories), texture_(0), image_id_(0) { | 18 : gpu_factories_(gpu_factories), texture_(0), image_id_(0) { |
| 20 if (gpu_factories_) { | 19 if (gpu_factories_) { |
| 21 std::unique_ptr<::media::GpuVideoAcceleratorFactories::ScopedGLContextLock> | 20 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 22 lock(gpu_factories_->GetGLContextLock()); | 21 std::unique_ptr<GpuVideoAcceleratorFactories::ScopedGLContextLock> lock( |
| 22 gpu_factories_->GetGLContextLock()); |
| 23 CHECK(lock); | 23 CHECK(lock); |
| 24 gpu::gles2::GLES2Interface* gl = lock->ContextGL(); | 24 gpu::gles2::GLES2Interface* gl = lock->ContextGL(); |
| 25 | 25 |
| 26 gl->GenTextures(1, &texture_); | 26 gl->GenTextures(1, &texture_); |
| 27 gl->BindTexture(GL_TEXTURE_2D, texture_); | 27 gl->BindTexture(GL_TEXTURE_2D, texture_); |
| 28 image_id_ = gl->CreateGpuMemoryBufferImageCHROMIUM(1, 1, GL_RGBA, | 28 image_id_ = gl->CreateGpuMemoryBufferImageCHROMIUM(1, 1, GL_RGBA, |
| 29 GL_READ_WRITE_CHROMIUM); | 29 GL_READ_WRITE_CHROMIUM); |
| 30 CHECK(image_id_); | 30 CHECK(image_id_); |
| 31 gl->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id_); | 31 gl->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id_); |
| 32 | 32 |
| 33 gl->GenMailboxCHROMIUM(mailbox_.name); | 33 gl->GenMailboxCHROMIUM(mailbox_.name); |
| 34 gl->ProduceTextureDirectCHROMIUM(texture_, GL_TEXTURE_2D, mailbox_.name); | 34 gl->ProduceTextureDirectCHROMIUM(texture_, GL_TEXTURE_2D, mailbox_.name); |
| 35 | 35 |
| 36 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); | 36 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); |
| 37 gl->ShallowFlushCHROMIUM(); | 37 gl->ShallowFlushCHROMIUM(); |
| 38 gl->GenSyncTokenCHROMIUM(fence_sync, sync_token_.GetData()); | 38 gl->GenSyncTokenCHROMIUM(fence_sync, sync_token_.GetData()); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 HoleFrameFactory::~HoleFrameFactory() { | 42 VideoOverlayFactory::~VideoOverlayFactory() { |
| 43 if (texture_) { | 43 if (texture_) { |
| 44 std::unique_ptr<::media::GpuVideoAcceleratorFactories::ScopedGLContextLock> | 44 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 45 lock(gpu_factories_->GetGLContextLock()); | 45 std::unique_ptr<GpuVideoAcceleratorFactories::ScopedGLContextLock> lock( |
| 46 gpu_factories_->GetGLContextLock()); |
| 46 CHECK(lock); | 47 CHECK(lock); |
| 47 gpu::gles2::GLES2Interface* gl = lock->ContextGL(); | 48 gpu::gles2::GLES2Interface* gl = lock->ContextGL(); |
| 48 gl->BindTexture(GL_TEXTURE_2D, texture_); | 49 gl->BindTexture(GL_TEXTURE_2D, texture_); |
| 49 gl->ReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id_); | 50 gl->ReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id_); |
| 50 gl->DeleteTextures(1, &texture_); | 51 gl->DeleteTextures(1, &texture_); |
| 51 gl->DestroyImageCHROMIUM(image_id_); | 52 gl->DestroyImageCHROMIUM(image_id_); |
| 52 } | 53 } |
| 53 } | 54 } |
| 54 | 55 |
| 55 scoped_refptr<::media::VideoFrame> HoleFrameFactory::CreateHoleFrame( | 56 scoped_refptr<VideoFrame> VideoOverlayFactory::CreateFrame( |
| 56 const gfx::Size& size) { | 57 const gfx::Size& size) { |
| 57 // No texture => audio device. size empty => video has one dimension = 0. | 58 // No texture => audio device. size empty => video has one dimension = 0. |
| 58 // Dimension 0 case triggers a DCHECK later on in TextureMailbox if we push | 59 // Dimension 0 case triggers a DCHECK later on in TextureMailbox if we push |
| 59 // through the overlay path. | 60 // through the overlay path. |
| 60 if (!texture_ || size.IsEmpty()) { | 61 if (!texture_ || size.IsEmpty()) { |
| 61 LOG(INFO) << "Create black frame " << size.width() << "x" << size.height(); | 62 DVLOG(1) << "Create black frame " << size.width() << "x" << size.height(); |
| 62 return ::media::VideoFrame::CreateBlackFrame(gfx::Size(1, 1)); | 63 return VideoFrame::CreateBlackFrame(gfx::Size(1, 1)); |
| 63 } | 64 } |
| 64 | 65 |
| 65 LOG(INFO) << "Create hole frame " << size.width() << "x" << size.height(); | 66 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 66 gpu::MailboxHolder holders[::media::VideoFrame::kMaxPlanes] = { | 67 DVLOG(1) << "Create hole frame " << size.width() << "x" << size.height(); |
| 68 gpu::MailboxHolder holders[VideoFrame::kMaxPlanes] = { |
| 67 gpu::MailboxHolder(mailbox_, sync_token_, GL_TEXTURE_2D)}; | 69 gpu::MailboxHolder(mailbox_, sync_token_, GL_TEXTURE_2D)}; |
| 68 scoped_refptr<::media::VideoFrame> frame = | 70 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTextures( |
| 69 ::media::VideoFrame::WrapNativeTextures( | 71 PIXEL_FORMAT_XRGB, holders, VideoFrame::ReleaseMailboxCB(), |
| 70 ::media::PIXEL_FORMAT_XRGB, holders, | 72 size, // coded_size |
| 71 ::media::VideoFrame::ReleaseMailboxCB(), | 73 gfx::Rect(size), // visible rect |
| 72 size, // coded_size | 74 size, // natural size |
| 73 gfx::Rect(size), // visible rect | 75 base::TimeDelta()); // timestamp |
| 74 size, // natural size | |
| 75 base::TimeDelta()); // timestamp | |
| 76 CHECK(frame); | 76 CHECK(frame); |
| 77 frame->metadata()->SetBoolean(::media::VideoFrameMetadata::ALLOW_OVERLAY, | 77 frame->metadata()->SetBoolean(VideoFrameMetadata::ALLOW_OVERLAY, true); |
| 78 true); | |
| 79 return frame; | 78 return frame; |
| 80 } | 79 } |
| 81 | 80 |
| 82 } // namespace media | 81 } // namespace media |
| 83 } // namespace chromecast | |
| OLD | NEW |