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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // We delete the temporary resource if it is not used for 3 seconds. | 51 // We delete the temporary resource if it is not used for 3 seconds. |
52 const int kTemporaryResourceDeletionDelay = 3; // Seconds; | 52 const int kTemporaryResourceDeletionDelay = 3; // Seconds; |
53 | 53 |
54 bool CheckColorSpace(const VideoFrame* video_frame, ColorSpace color_space) { | 54 bool CheckColorSpace(const VideoFrame* video_frame, ColorSpace color_space) { |
55 int result; | 55 int result; |
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 SyncTokenClientImpl : public VideoFrame::SyncTokenClient { |
62 public: | 62 public: |
63 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl) : gl_(gl) {} | 63 explicit SyncTokenClientImpl(gpu::gles2::GLES2Interface* gl) : gl_(gl) {} |
64 ~SyncPointClientImpl() override {} | 64 ~SyncTokenClientImpl() override {} |
65 uint32 InsertSyncPoint() override { return gl_->InsertSyncPointCHROMIUM(); } | 65 uint32 InsertSyncPoint() override { return gl_->InsertSyncPointCHROMIUM(); } |
66 void WaitSyncPoint(uint32 sync_point) override { | 66 void WaitSyncToken(const gpu::SyncToken& sync_token) override { |
67 gl_->WaitSyncPointCHROMIUM(sync_point); | 67 gl_->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
68 } | 68 } |
69 | 69 |
70 private: | 70 private: |
71 gpu::gles2::GLES2Interface* gl_; | 71 gpu::gles2::GLES2Interface* gl_; |
72 | 72 |
73 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncPointClientImpl); | 73 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncTokenClientImpl); |
74 }; | 74 }; |
75 | 75 |
76 skia::RefPtr<SkImage> NewSkImageFromVideoFrameYUVTextures( | 76 skia::RefPtr<SkImage> NewSkImageFromVideoFrameYUVTextures( |
77 const VideoFrame* video_frame, | 77 const VideoFrame* video_frame, |
78 const Context3D& context_3d) { | 78 const Context3D& context_3d) { |
79 // Support only TEXTURE_YUV_420. | 79 // Support only TEXTURE_YUV_420. |
80 DCHECK(video_frame->HasTextures()); | 80 DCHECK(video_frame->HasTextures()); |
81 DCHECK_EQ(media::PIXEL_FORMAT_I420, video_frame->format()); | 81 DCHECK_EQ(media::PIXEL_FORMAT_I420, video_frame->format()); |
82 DCHECK_EQ(3u, media::VideoFrame::NumPlanes(video_frame->format())); | 82 DCHECK_EQ(3u, media::VideoFrame::NumPlanes(video_frame->format())); |
83 | 83 |
84 gpu::gles2::GLES2Interface* gl = context_3d.gl; | 84 gpu::gles2::GLES2Interface* gl = context_3d.gl; |
85 DCHECK(gl); | 85 DCHECK(gl); |
86 gfx::Size ya_tex_size = video_frame->coded_size(); | 86 gfx::Size ya_tex_size = video_frame->coded_size(); |
87 gfx::Size uv_tex_size((ya_tex_size.width() + 1) / 2, | 87 gfx::Size uv_tex_size((ya_tex_size.width() + 1) / 2, |
88 (ya_tex_size.height() + 1) / 2); | 88 (ya_tex_size.height() + 1) / 2); |
89 | 89 |
90 unsigned source_textures[3] = {0}; | 90 unsigned source_textures[3] = {0}; |
91 for (size_t i = 0; i < media::VideoFrame::NumPlanes(video_frame->format()); | 91 for (size_t i = 0; i < media::VideoFrame::NumPlanes(video_frame->format()); |
92 ++i) { | 92 ++i) { |
93 // Get the texture from the mailbox and wrap it in a GrTexture. | 93 // Get the texture from the mailbox and wrap it in a GrTexture. |
94 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); | 94 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); |
95 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || | 95 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || |
96 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES || | 96 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES || |
97 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB); | 97 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB); |
98 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); | 98 gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData()); |
99 source_textures[i] = gl->CreateAndConsumeTextureCHROMIUM( | 99 source_textures[i] = gl->CreateAndConsumeTextureCHROMIUM( |
100 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 100 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
101 | 101 |
102 // TODO(dcastagna): avoid this copy once Skia supports native textures | 102 // TODO(dcastagna): avoid this copy once Skia supports native textures |
103 // with a texture target different than TEXTURE_2D. | 103 // with a texture target different than TEXTURE_2D. |
104 // crbug.com/505026 | 104 // crbug.com/505026 |
105 if (mailbox_holder.texture_target != GL_TEXTURE_2D) { | 105 if (mailbox_holder.texture_target != GL_TEXTURE_2D) { |
106 unsigned texture_copy = 0; | 106 unsigned texture_copy = 0; |
107 gl->GenTextures(1, &texture_copy); | 107 gl->GenTextures(1, &texture_copy); |
108 DCHECK(texture_copy); | 108 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 | 157 // TODO(dcastagna): At the moment Skia doesn't support targets different |
158 // than GL_TEXTURE_2D. Avoid this copy once | 158 // than GL_TEXTURE_2D. Avoid this copy once |
159 // https://code.google.com/p/skia/issues/detail?id=3868 is addressed. | 159 // https://code.google.com/p/skia/issues/detail?id=3868 is addressed. |
160 gl->GenTextures(1, &source_texture); | 160 gl->GenTextures(1, &source_texture); |
161 DCHECK(source_texture); | 161 DCHECK(source_texture); |
162 gl->BindTexture(GL_TEXTURE_2D, source_texture); | 162 gl->BindTexture(GL_TEXTURE_2D, source_texture); |
163 SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( | 163 SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( |
164 gl, video_frame, source_texture, GL_RGBA, GL_UNSIGNED_BYTE, true, | 164 gl, video_frame, source_texture, GL_RGBA, GL_UNSIGNED_BYTE, true, |
165 false); | 165 false); |
166 } else { | 166 } else { |
167 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); | 167 gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData()); |
168 source_texture = gl->CreateAndConsumeTextureCHROMIUM( | 168 source_texture = gl->CreateAndConsumeTextureCHROMIUM( |
169 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 169 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
170 } | 170 } |
171 GrBackendTextureDesc desc; | 171 GrBackendTextureDesc desc; |
172 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 172 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
173 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 173 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
174 desc.fWidth = video_frame->coded_size().width(); | 174 desc.fWidth = video_frame->coded_size().width(); |
175 desc.fHeight = video_frame->coded_size().height(); | 175 desc.fHeight = video_frame->coded_size().height(); |
176 desc.fConfig = kRGBA_8888_GrPixelConfig; | 176 desc.fConfig = kRGBA_8888_GrPixelConfig; |
177 desc.fTextureHandle = source_texture; | 177 desc.fTextureHandle = source_texture; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 canvas->drawImage(last_image_.get(), 0, 0, &paint); | 408 canvas->drawImage(last_image_.get(), 0, 0, &paint); |
409 } | 409 } |
410 | 410 |
411 if (need_transform) | 411 if (need_transform) |
412 canvas->restore(); | 412 canvas->restore(); |
413 // Make sure to flush so we can remove the videoframe from the generator. | 413 // Make sure to flush so we can remove the videoframe from the generator. |
414 canvas->flush(); | 414 canvas->flush(); |
415 | 415 |
416 if (video_frame->HasTextures()) { | 416 if (video_frame->HasTextures()) { |
417 DCHECK(gl); | 417 DCHECK(gl); |
418 SyncPointClientImpl client(gl); | 418 SyncTokenClientImpl client(gl); |
419 video_frame->UpdateReleaseSyncPoint(&client); | 419 video_frame->UpdateReleaseSyncToken(&client); |
420 } | 420 } |
421 } | 421 } |
422 | 422 |
423 void SkCanvasVideoRenderer::Copy(const scoped_refptr<VideoFrame>& video_frame, | 423 void SkCanvasVideoRenderer::Copy(const scoped_refptr<VideoFrame>& video_frame, |
424 SkCanvas* canvas, | 424 SkCanvas* canvas, |
425 const Context3D& context_3d) { | 425 const Context3D& context_3d) { |
426 Paint(video_frame, canvas, gfx::RectF(video_frame->visible_rect()), 0xff, | 426 Paint(video_frame, canvas, gfx::RectF(video_frame->visible_rect()), 0xff, |
427 SkXfermode::kSrc_Mode, media::VIDEO_ROTATION_0, context_3d); | 427 SkXfermode::kSrc_Mode, media::VIDEO_ROTATION_0, context_3d); |
428 } | 428 } |
429 | 429 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 DCHECK(video_frame); | 544 DCHECK(video_frame); |
545 DCHECK(video_frame->HasTextures()); | 545 DCHECK(video_frame->HasTextures()); |
546 DCHECK_EQ(1u, VideoFrame::NumPlanes(video_frame->format())); | 546 DCHECK_EQ(1u, VideoFrame::NumPlanes(video_frame->format())); |
547 | 547 |
548 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); | 548 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); |
549 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || | 549 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || |
550 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB || | 550 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB || |
551 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) | 551 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) |
552 << mailbox_holder.texture_target; | 552 << mailbox_holder.texture_target; |
553 | 553 |
554 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); | 554 gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData()); |
555 uint32 source_texture = gl->CreateAndConsumeTextureCHROMIUM( | 555 uint32 source_texture = gl->CreateAndConsumeTextureCHROMIUM( |
556 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 556 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
557 | 557 |
558 // The video is stored in a unmultiplied format, so premultiply | 558 // The video is stored in a unmultiplied format, so premultiply |
559 // if necessary. | 559 // if necessary. |
560 // Application itself needs to take care of setting the right |flip_y| | 560 // Application itself needs to take care of setting the right |flip_y| |
561 // value down to get the expected result. | 561 // value down to get the expected result. |
562 // "flip_y == true" means to reverse the video orientation while | 562 // "flip_y == true" means to reverse the video orientation while |
563 // "flip_y == false" means to keep the intrinsic orientation. | 563 // "flip_y == false" means to keep the intrinsic orientation. |
564 gl->CopyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, texture, | 564 gl->CopyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, texture, |
565 internal_format, type, flip_y, premultiply_alpha, | 565 internal_format, type, flip_y, premultiply_alpha, |
566 false); | 566 false); |
567 | 567 |
568 gl->DeleteTextures(1, &source_texture); | 568 gl->DeleteTextures(1, &source_texture); |
569 gl->Flush(); | 569 gl->Flush(); |
570 | 570 |
571 SyncPointClientImpl client(gl); | 571 SyncTokenClientImpl client(gl); |
572 video_frame->UpdateReleaseSyncPoint(&client); | 572 video_frame->UpdateReleaseSyncToken(&client); |
573 } | 573 } |
574 | 574 |
575 void SkCanvasVideoRenderer::ResetCache() { | 575 void SkCanvasVideoRenderer::ResetCache() { |
576 // Clear cached values. | 576 // Clear cached values. |
577 last_image_ = nullptr; | 577 last_image_ = nullptr; |
578 last_timestamp_ = kNoTimestamp(); | 578 last_timestamp_ = kNoTimestamp(); |
579 } | 579 } |
580 | 580 |
581 } // namespace media | 581 } // namespace media |
OLD | NEW |