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