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/blink/skcanvas_video_renderer.h" | 5 #include "media/blink/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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 gpu::gles2::GLES2Interface* gl = context_3d.gl; | 154 gpu::gles2::GLES2Interface* gl = context_3d.gl; |
155 unsigned source_texture = 0; | 155 unsigned source_texture = 0; |
156 if (mailbox_holder.texture_target != GL_TEXTURE_2D) { | 156 if (mailbox_holder.texture_target != GL_TEXTURE_2D) { |
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, |
165 false); | 165 SkCanvasVideoRenderer::CopyFrameSingleTextureParams( |
| 166 SkCanvasVideoRenderer::CopyFrameSingleTextureParams::FullCopy, |
| 167 GL_TEXTURE_2D, source_texture, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0, 0, |
| 168 true, false)); |
166 } else { | 169 } else { |
167 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); | 170 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); |
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(); |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 case PIXEL_FORMAT_MT21: | 542 case PIXEL_FORMAT_MT21: |
540 case PIXEL_FORMAT_UNKNOWN: | 543 case PIXEL_FORMAT_UNKNOWN: |
541 NOTREACHED(); | 544 NOTREACHED(); |
542 } | 545 } |
543 } | 546 } |
544 | 547 |
545 // static | 548 // static |
546 void SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( | 549 void SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( |
547 gpu::gles2::GLES2Interface* gl, | 550 gpu::gles2::GLES2Interface* gl, |
548 VideoFrame* video_frame, | 551 VideoFrame* video_frame, |
549 unsigned int texture, | 552 const CopyFrameSingleTextureParams& params) { |
550 unsigned int internal_format, | |
551 unsigned int type, | |
552 bool premultiply_alpha, | |
553 bool flip_y) { | |
554 DCHECK(video_frame); | 553 DCHECK(video_frame); |
555 DCHECK(video_frame->HasTextures()); | 554 DCHECK(video_frame->HasTextures()); |
556 DCHECK_EQ(1u, VideoFrame::NumPlanes(video_frame->format())); | 555 DCHECK_EQ(1u, VideoFrame::NumPlanes(video_frame->format())); |
557 | 556 |
558 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); | 557 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); |
559 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || | 558 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || |
560 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB || | 559 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB || |
561 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) | 560 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) |
562 << mailbox_holder.texture_target; | 561 << mailbox_holder.texture_target; |
563 | 562 |
564 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); | 563 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); |
565 uint32 source_texture = gl->CreateAndConsumeTextureCHROMIUM( | 564 uint32 source_texture = gl->CreateAndConsumeTextureCHROMIUM( |
566 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 565 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
567 | 566 |
568 // The video is stored in a unmultiplied format, so premultiply | 567 // The video is stored in a unmultiplied format, so premultiply |
569 // if necessary. | 568 // if necessary. |
570 // Application itself needs to take care of setting the right |flip_y| | 569 // Application itself needs to take care of setting the right |flip_y| |
571 // value down to get the expected result. | 570 // value down to get the expected result. |
572 // "flip_y == true" means to reverse the video orientation while | 571 // "flip_y == true" means to reverse the video orientation while |
573 // "flip_y == false" means to keep the intrinsic orientation. | 572 // "flip_y == false" means to keep the intrinsic orientation. |
574 gl->CopyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, texture, | 573 if (params.copy_type == CopyFrameSingleTextureParams::FullCopy) { |
575 internal_format, type, | 574 DCHECK(!params.xoffset && !params.yoffset); |
576 flip_y, premultiply_alpha, false); | 575 gl->CopyTextureCHROMIUM(params.target, source_texture, params.texture, |
| 576 params.internal_format, params.type, params.flip_y, |
| 577 params.premultiply_alpha, false); |
| 578 } else { |
| 579 DCHECK_EQ(static_cast<unsigned int>(GL_FALSE), params.internal_format); |
| 580 DCHECK_EQ(static_cast<unsigned int>(GL_FALSE), params.type); |
| 581 gl->CopySubTextureCHROMIUM(params.target, source_texture, params.texture, |
| 582 params.xoffset, params.yoffset, 0, 0, |
| 583 video_frame->natural_size().width(), |
| 584 video_frame->natural_size().height(), |
| 585 params.flip_y, params.premultiply_alpha, false); |
| 586 } |
577 | 587 |
578 gl->DeleteTextures(1, &source_texture); | 588 gl->DeleteTextures(1, &source_texture); |
579 gl->Flush(); | 589 gl->Flush(); |
580 | 590 |
581 SyncPointClientImpl client(gl); | 591 SyncPointClientImpl client(gl); |
582 video_frame->UpdateReleaseSyncPoint(&client); | 592 video_frame->UpdateReleaseSyncPoint(&client); |
583 } | 593 } |
584 | 594 |
585 void SkCanvasVideoRenderer::ResetCache() { | 595 void SkCanvasVideoRenderer::ResetCache() { |
586 // Clear cached values. | 596 // Clear cached values. |
587 last_image_ = nullptr; | 597 last_image_ = nullptr; |
588 last_timestamp_ = kNoTimestamp(); | 598 last_timestamp_ = kNoTimestamp(); |
589 } | 599 } |
590 | 600 |
591 } // namespace media | 601 } // namespace media |
OLD | NEW |