Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: media/renderers/video_overlay_factory.cc

Issue 2298913002: Garcefully handle glCreateGpuMemoryBufferImageCHROMIUM failure. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/renderers/video_overlay_factory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "media/renderers/video_overlay_factory.h" 5 #include "media/renderers/video_overlay_factory.h"
6 6
7 #include "gpu/GLES2/gl2extchromium.h" 7 #include "gpu/GLES2/gl2extchromium.h"
8 #include "gpu/command_buffer/client/gles2_interface.h" 8 #include "gpu/command_buffer/client/gles2_interface.h"
9 #include "gpu/command_buffer/common/mailbox.h" 9 #include "gpu/command_buffer/common/mailbox.h"
10 #include "gpu/command_buffer/common/sync_token.h" 10 #include "gpu/command_buffer/common/sync_token.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 media { 14 namespace media {
15 15
16 class VideoOverlayFactory::Texture { 16 class VideoOverlayFactory::Texture {
17 public: 17 public:
18 explicit Texture(GpuVideoAcceleratorFactories* gpu_factories) 18 explicit Texture(GpuVideoAcceleratorFactories* gpu_factories)
19 : gpu_factories_(gpu_factories), texture_id_(0), image_id_(0) { 19 : gpu_factories_(gpu_factories), image_id_(0), texture_id_(0) {
20 DCHECK(gpu_factories_); 20 DCHECK(gpu_factories_);
21 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread()); 21 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread());
22 22
23 std::unique_ptr<GpuVideoAcceleratorFactories::ScopedGLContextLock> lock( 23 std::unique_ptr<GpuVideoAcceleratorFactories::ScopedGLContextLock> lock(
24 gpu_factories_->GetGLContextLock()); 24 gpu_factories_->GetGLContextLock());
25 CHECK(lock); 25 if (lock) {
26 gpu::gles2::GLES2Interface* gl = lock->ContextGL(); 26 gpu::gles2::GLES2Interface* gl = lock->ContextGL();
27 image_id_ = gl->CreateGpuMemoryBufferImageCHROMIUM(
28 1, 1, GL_RGBA, GL_READ_WRITE_CHROMIUM);
29 if (image_id_) {
30 gl->GenTextures(1, &texture_id_);
31 gl->BindTexture(GL_TEXTURE_2D, texture_id_);
32 gl->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id_);
27 33
28 gl->GenTextures(1, &texture_id_); 34 gl->GenMailboxCHROMIUM(mailbox_.name);
29 gl->BindTexture(GL_TEXTURE_2D, texture_id_); 35 gl->ProduceTextureDirectCHROMIUM(texture_id_, GL_TEXTURE_2D,
30 image_id_ = gl->CreateGpuMemoryBufferImageCHROMIUM(1, 1, GL_RGBA, 36 mailbox_.name);
31 GL_READ_WRITE_CHROMIUM);
32 CHECK(image_id_);
33 gl->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id_);
34 37
35 gl->GenMailboxCHROMIUM(mailbox_.name); 38 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM();
36 gl->ProduceTextureDirectCHROMIUM(texture_id_, GL_TEXTURE_2D, mailbox_.name); 39 gl->ShallowFlushCHROMIUM();
37 40 gl->GenSyncTokenCHROMIUM(fence_sync, sync_token_.GetData());
38 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); 41 }
39 gl->ShallowFlushCHROMIUM(); 42 }
40 gl->GenSyncTokenCHROMIUM(fence_sync, sync_token_.GetData());
41 } 43 }
42 44
43 ~Texture() { 45 ~Texture() {
44 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread()); 46 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread());
45 47
46 std::unique_ptr<GpuVideoAcceleratorFactories::ScopedGLContextLock> lock( 48 if (image_id_) {
47 gpu_factories_->GetGLContextLock()); 49 std::unique_ptr<GpuVideoAcceleratorFactories::ScopedGLContextLock> lock(
48 CHECK(lock); 50 gpu_factories_->GetGLContextLock());
49 gpu::gles2::GLES2Interface* gl = lock->ContextGL(); 51 if (lock) {
50 gl->BindTexture(GL_TEXTURE_2D, texture_id_); 52 gpu::gles2::GLES2Interface* gl = lock->ContextGL();
51 gl->ReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id_); 53 gl->BindTexture(GL_TEXTURE_2D, texture_id_);
52 gl->DeleteTextures(1, &texture_id_); 54 gl->ReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id_);
53 gl->DestroyImageCHROMIUM(image_id_); 55 gl->DeleteTextures(1, &texture_id_);
56 gl->DestroyImageCHROMIUM(image_id_);
57 }
58 }
54 } 59 }
55 60
61 bool IsValid() const { return image_id_ != 0; }
62
56 private: 63 private:
57 friend class VideoOverlayFactory; 64 friend class VideoOverlayFactory;
58 GpuVideoAcceleratorFactories* gpu_factories_; 65 GpuVideoAcceleratorFactories* gpu_factories_;
59 66
67 GLuint image_id_;
60 GLuint texture_id_; 68 GLuint texture_id_;
61 GLuint image_id_;
62 gpu::Mailbox mailbox_; 69 gpu::Mailbox mailbox_;
63 gpu::SyncToken sync_token_; 70 gpu::SyncToken sync_token_;
64 }; 71 };
65 72
66 VideoOverlayFactory::VideoOverlayFactory( 73 VideoOverlayFactory::VideoOverlayFactory(
67 GpuVideoAcceleratorFactories* gpu_factories) 74 GpuVideoAcceleratorFactories* gpu_factories)
68 : gpu_factories_(gpu_factories) {} 75 : gpu_factories_(gpu_factories) {}
69 76
70 VideoOverlayFactory::~VideoOverlayFactory() {} 77 VideoOverlayFactory::~VideoOverlayFactory() {}
71 78
72 scoped_refptr<VideoFrame> VideoOverlayFactory::CreateFrame( 79 scoped_refptr<VideoFrame> VideoOverlayFactory::CreateFrame(
73 const gfx::Size& size) { 80 const gfx::Size& size) {
74 // Frame size empty => video has one dimension = 0. 81 // Frame size empty => video has one dimension = 0.
75 // Dimension 0 case triggers a DCHECK later on in TextureMailbox if we push 82 // Dimension 0 case triggers a DCHECK later on in TextureMailbox if we push
76 // through the overlay path. 83 // through the overlay path.
77 if (size.IsEmpty() || !gpu_factories_) { 84 Texture* texture = size.IsEmpty() ? nullptr : GetTexture();
85 if (!texture) {
78 DVLOG(1) << "Create black frame " << size.width() << "x" << size.height(); 86 DVLOG(1) << "Create black frame " << size.width() << "x" << size.height();
79 return VideoFrame::CreateBlackFrame(gfx::Size(1, 1)); 87 return VideoFrame::CreateBlackFrame(gfx::Size(1, 1));
80 } 88 }
81 89
82 DCHECK(gpu_factories_); 90 DCHECK(texture);
83 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread()); 91 DCHECK(texture->IsValid());
84 92 DVLOG(2) << "Create video overlay frame: " << size.ToString();
85 // Lazily create overlay texture.
86 if (!texture_)
87 texture_.reset(new Texture(gpu_factories_));
88
89 DVLOG(1) << "Create video overlay frame: " << size.ToString();
90 gpu::MailboxHolder holders[VideoFrame::kMaxPlanes] = {gpu::MailboxHolder( 93 gpu::MailboxHolder holders[VideoFrame::kMaxPlanes] = {gpu::MailboxHolder(
91 texture_->mailbox_, texture_->sync_token_, GL_TEXTURE_2D)}; 94 texture->mailbox_, texture->sync_token_, GL_TEXTURE_2D)};
92 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTextures( 95 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTextures(
93 PIXEL_FORMAT_XRGB, holders, VideoFrame::ReleaseMailboxCB(), 96 PIXEL_FORMAT_XRGB, holders, VideoFrame::ReleaseMailboxCB(),
94 size, // coded_size 97 size, // coded_size
95 gfx::Rect(size), // visible rect 98 gfx::Rect(size), // visible rect
96 size, // natural size 99 size, // natural size
97 base::TimeDelta()); // timestamp 100 base::TimeDelta()); // timestamp
98 CHECK(frame); 101 CHECK(frame);
99 frame->metadata()->SetBoolean(VideoFrameMetadata::ALLOW_OVERLAY, true); 102 frame->metadata()->SetBoolean(VideoFrameMetadata::ALLOW_OVERLAY, true);
100 // TODO(halliwell): this is to block idle suspend behaviour on Chromecast. 103 // TODO(halliwell): this is to block idle suspend behaviour on Chromecast.
101 // Find a better way to do this. 104 // Find a better way to do this.
102 frame->metadata()->SetBoolean(VideoFrameMetadata::DECODER_OWNS_FRAME, true); 105 frame->metadata()->SetBoolean(VideoFrameMetadata::DECODER_OWNS_FRAME, true);
103 return frame; 106 return frame;
104 } 107 }
105 108
109 VideoOverlayFactory::Texture* VideoOverlayFactory::GetTexture() {
110 if (!gpu_factories_)
111 return nullptr;
112
113 // Lazily create overlay texture.
114 if (!texture_)
115 texture_.reset(new Texture(gpu_factories_));
116
117 return texture_->IsValid() ? texture_.get() : nullptr;
118 }
119
106 } // namespace media 120 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/video_overlay_factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698