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