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/renderers/skcanvas_video_renderer.h" | 5 #include "media/renderers/skcanvas_video_renderer.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_holder.h" | 9 #include "gpu/command_buffer/common/mailbox_holder.h" |
10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 return video_frame->metadata()->GetInteger(VideoFrameMetadata::COLOR_SPACE, | 56 return video_frame->metadata()->GetInteger(VideoFrameMetadata::COLOR_SPACE, |
57 &result) && | 57 &result) && |
58 result == color_space; | 58 result == color_space; |
59 } | 59 } |
60 | 60 |
61 class SyncPointClientImpl : public VideoFrame::SyncPointClient { | 61 class SyncPointClientImpl : public VideoFrame::SyncPointClient { |
62 public: | 62 public: |
63 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl) : gl_(gl) {} | 63 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl) : gl_(gl) {} |
64 ~SyncPointClientImpl() override {} | 64 ~SyncPointClientImpl() override {} |
65 uint32 InsertSyncPoint() override { return gl_->InsertSyncPointCHROMIUM(); } | 65 uint32 InsertSyncPoint() override { return gl_->InsertSyncPointCHROMIUM(); } |
66 void WaitSyncPoint(uint32 sync_point) override { | 66 void WaitSyncPoint(uint32 sync_point, |
67 gl_->WaitSyncPointCHROMIUM(sync_point); | 67 const gpu::SyncToken& sync_token) override { |
| 68 gl_->WaitSyncPointCHROMIUM(sync_point, sync_token.GetConstData()); |
68 } | 69 } |
69 | 70 |
70 private: | 71 private: |
71 gpu::gles2::GLES2Interface* gl_; | 72 gpu::gles2::GLES2Interface* gl_; |
72 | 73 |
73 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncPointClientImpl); | 74 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncPointClientImpl); |
74 }; | 75 }; |
75 | 76 |
76 skia::RefPtr<SkImage> NewSkImageFromVideoFrameYUVTextures( | 77 skia::RefPtr<SkImage> NewSkImageFromVideoFrameYUVTextures( |
77 const VideoFrame* video_frame, | 78 const VideoFrame* video_frame, |
(...skipping 10 matching lines...) Expand all Loading... |
88 (ya_tex_size.height() + 1) / 2); | 89 (ya_tex_size.height() + 1) / 2); |
89 | 90 |
90 unsigned source_textures[3] = {0}; | 91 unsigned source_textures[3] = {0}; |
91 for (size_t i = 0; i < media::VideoFrame::NumPlanes(video_frame->format()); | 92 for (size_t i = 0; i < media::VideoFrame::NumPlanes(video_frame->format()); |
92 ++i) { | 93 ++i) { |
93 // Get the texture from the mailbox and wrap it in a GrTexture. | 94 // Get the texture from the mailbox and wrap it in a GrTexture. |
94 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); | 95 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); |
95 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || | 96 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || |
96 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES || | 97 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES || |
97 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB); | 98 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB); |
98 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); | 99 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point, |
| 100 mailbox_holder.sync_token.GetConstData()); |
99 source_textures[i] = gl->CreateAndConsumeTextureCHROMIUM( | 101 source_textures[i] = gl->CreateAndConsumeTextureCHROMIUM( |
100 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 102 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
101 | 103 |
102 // TODO(dcastagna): avoid this copy once Skia supports native textures | 104 // TODO(dcastagna): avoid this copy once Skia supports native textures |
103 // with a texture target different than TEXTURE_2D. | 105 // with a texture target different than TEXTURE_2D. |
104 // crbug.com/505026 | 106 // crbug.com/505026 |
105 if (mailbox_holder.texture_target != GL_TEXTURE_2D) { | 107 if (mailbox_holder.texture_target != GL_TEXTURE_2D) { |
106 unsigned texture_copy = 0; | 108 unsigned texture_copy = 0; |
107 gl->GenTextures(1, &texture_copy); | 109 gl->GenTextures(1, &texture_copy); |
108 DCHECK(texture_copy); | 110 DCHECK(texture_copy); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // TODO(dcastagna): At the moment Skia doesn't support targets different | 159 // TODO(dcastagna): At the moment Skia doesn't support targets different |
158 // than GL_TEXTURE_2D. Avoid this copy once | 160 // than GL_TEXTURE_2D. Avoid this copy once |
159 // https://code.google.com/p/skia/issues/detail?id=3868 is addressed. | 161 // https://code.google.com/p/skia/issues/detail?id=3868 is addressed. |
160 gl->GenTextures(1, &source_texture); | 162 gl->GenTextures(1, &source_texture); |
161 DCHECK(source_texture); | 163 DCHECK(source_texture); |
162 gl->BindTexture(GL_TEXTURE_2D, source_texture); | 164 gl->BindTexture(GL_TEXTURE_2D, source_texture); |
163 SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( | 165 SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( |
164 gl, video_frame, source_texture, GL_RGBA, GL_UNSIGNED_BYTE, true, | 166 gl, video_frame, source_texture, GL_RGBA, GL_UNSIGNED_BYTE, true, |
165 false); | 167 false); |
166 } else { | 168 } else { |
167 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); | 169 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point, |
| 170 mailbox_holder.sync_token.GetConstData()); |
168 source_texture = gl->CreateAndConsumeTextureCHROMIUM( | 171 source_texture = gl->CreateAndConsumeTextureCHROMIUM( |
169 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 172 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
170 } | 173 } |
171 GrBackendTextureDesc desc; | 174 GrBackendTextureDesc desc; |
172 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 175 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
173 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 176 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
174 desc.fWidth = video_frame->coded_size().width(); | 177 desc.fWidth = video_frame->coded_size().width(); |
175 desc.fHeight = video_frame->coded_size().height(); | 178 desc.fHeight = video_frame->coded_size().height(); |
176 desc.fConfig = kRGBA_8888_GrPixelConfig; | 179 desc.fConfig = kRGBA_8888_GrPixelConfig; |
177 desc.fTextureHandle = source_texture; | 180 desc.fTextureHandle = source_texture; |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 DCHECK(video_frame); | 547 DCHECK(video_frame); |
545 DCHECK(video_frame->HasTextures()); | 548 DCHECK(video_frame->HasTextures()); |
546 DCHECK_EQ(1u, VideoFrame::NumPlanes(video_frame->format())); | 549 DCHECK_EQ(1u, VideoFrame::NumPlanes(video_frame->format())); |
547 | 550 |
548 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); | 551 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); |
549 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || | 552 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || |
550 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB || | 553 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB || |
551 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) | 554 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) |
552 << mailbox_holder.texture_target; | 555 << mailbox_holder.texture_target; |
553 | 556 |
554 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); | 557 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point, |
| 558 mailbox_holder.sync_token.GetConstData()); |
555 uint32 source_texture = gl->CreateAndConsumeTextureCHROMIUM( | 559 uint32 source_texture = gl->CreateAndConsumeTextureCHROMIUM( |
556 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 560 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
557 | 561 |
558 // The video is stored in a unmultiplied format, so premultiply | 562 // The video is stored in a unmultiplied format, so premultiply |
559 // if necessary. | 563 // if necessary. |
560 // Application itself needs to take care of setting the right |flip_y| | 564 // Application itself needs to take care of setting the right |flip_y| |
561 // value down to get the expected result. | 565 // value down to get the expected result. |
562 // "flip_y == true" means to reverse the video orientation while | 566 // "flip_y == true" means to reverse the video orientation while |
563 // "flip_y == false" means to keep the intrinsic orientation. | 567 // "flip_y == false" means to keep the intrinsic orientation. |
564 gl->CopyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, texture, | 568 gl->CopyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, texture, |
565 internal_format, type, flip_y, premultiply_alpha, | 569 internal_format, type, flip_y, premultiply_alpha, |
566 false); | 570 false); |
567 | 571 |
568 gl->DeleteTextures(1, &source_texture); | 572 gl->DeleteTextures(1, &source_texture); |
569 gl->Flush(); | 573 gl->Flush(); |
570 | 574 |
571 SyncPointClientImpl client(gl); | 575 SyncPointClientImpl client(gl); |
572 video_frame->UpdateReleaseSyncPoint(&client); | 576 video_frame->UpdateReleaseSyncPoint(&client); |
573 } | 577 } |
574 | 578 |
575 void SkCanvasVideoRenderer::ResetCache() { | 579 void SkCanvasVideoRenderer::ResetCache() { |
576 // Clear cached values. | 580 // Clear cached values. |
577 last_image_ = nullptr; | 581 last_image_ = nullptr; |
578 last_timestamp_ = kNoTimestamp(); | 582 last_timestamp_ = kNoTimestamp(); |
579 } | 583 } |
580 | 584 |
581 } // namespace media | 585 } // namespace media |
OLD | NEW |