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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 gpu::gles2::GLES2Interface* gl = context_3d.gl; | 155 gpu::gles2::GLES2Interface* gl = context_3d.gl; |
156 unsigned source_texture = 0; | 156 unsigned source_texture = 0; |
157 if (mailbox_holder.texture_target != GL_TEXTURE_2D) { | 157 if (mailbox_holder.texture_target != GL_TEXTURE_2D) { |
158 // TODO(dcastagna): At the moment Skia doesn't support targets different | 158 // TODO(dcastagna): At the moment Skia doesn't support targets different |
159 // than GL_TEXTURE_2D. Avoid this copy once | 159 // than GL_TEXTURE_2D. Avoid this copy once |
160 // https://code.google.com/p/skia/issues/detail?id=3868 is addressed. | 160 // https://code.google.com/p/skia/issues/detail?id=3868 is addressed. |
161 gl->GenTextures(1, &source_texture); | 161 gl->GenTextures(1, &source_texture); |
162 DCHECK(source_texture); | 162 DCHECK(source_texture); |
163 gl->BindTexture(GL_TEXTURE_2D, source_texture); | 163 gl->BindTexture(GL_TEXTURE_2D, source_texture); |
164 SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( | 164 SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( |
165 gl, video_frame, source_texture, GL_RGBA, GL_UNSIGNED_BYTE, true, | 165 gl, video_frame, |
166 false); | 166 SkCanvasVideoRenderer::CopyFrameSingleTextureParams( |
| 167 SkCanvasVideoRenderer::CopyFrameSingleTextureParams::FullCopy, |
| 168 GL_TEXTURE_2D, source_texture, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0, 0, |
| 169 true, false)); |
167 } else { | 170 } else { |
168 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); | 171 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); |
169 source_texture = gl->CreateAndConsumeTextureCHROMIUM( | 172 source_texture = gl->CreateAndConsumeTextureCHROMIUM( |
170 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 173 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
171 } | 174 } |
172 GrBackendTextureDesc desc; | 175 GrBackendTextureDesc desc; |
173 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 176 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
174 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 177 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
175 desc.fWidth = video_frame->coded_size().width(); | 178 desc.fWidth = video_frame->coded_size().width(); |
176 desc.fHeight = video_frame->coded_size().height(); | 179 desc.fHeight = video_frame->coded_size().height(); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 case PIXEL_FORMAT_MT21: | 535 case PIXEL_FORMAT_MT21: |
533 case PIXEL_FORMAT_UNKNOWN: | 536 case PIXEL_FORMAT_UNKNOWN: |
534 NOTREACHED(); | 537 NOTREACHED(); |
535 } | 538 } |
536 } | 539 } |
537 | 540 |
538 // static | 541 // static |
539 void SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( | 542 void SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( |
540 gpu::gles2::GLES2Interface* gl, | 543 gpu::gles2::GLES2Interface* gl, |
541 VideoFrame* video_frame, | 544 VideoFrame* video_frame, |
542 unsigned int texture, | 545 const CopyFrameSingleTextureParams& params) { |
543 unsigned int internal_format, | |
544 unsigned int type, | |
545 bool premultiply_alpha, | |
546 bool flip_y) { | |
547 DCHECK(video_frame); | 546 DCHECK(video_frame); |
548 DCHECK(video_frame->HasTextures()); | 547 DCHECK(video_frame->HasTextures()); |
549 DCHECK_EQ(1u, VideoFrame::NumPlanes(video_frame->format())); | 548 DCHECK_EQ(1u, VideoFrame::NumPlanes(video_frame->format())); |
550 | 549 |
551 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); | 550 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); |
552 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || | 551 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || |
553 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB || | 552 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB || |
554 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) | 553 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) |
555 << mailbox_holder.texture_target; | 554 << mailbox_holder.texture_target; |
556 | 555 |
557 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); | 556 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); |
558 uint32 source_texture = gl->CreateAndConsumeTextureCHROMIUM( | 557 uint32 source_texture = gl->CreateAndConsumeTextureCHROMIUM( |
559 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 558 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
560 | 559 |
561 // The video is stored in a unmultiplied format, so premultiply | 560 // The video is stored in a unmultiplied format, so premultiply |
562 // if necessary. | 561 // if necessary. |
563 // Application itself needs to take care of setting the right |flip_y| | 562 // Application itself needs to take care of setting the right |flip_y| |
564 // value down to get the expected result. | 563 // value down to get the expected result. |
565 // "flip_y == true" means to reverse the video orientation while | 564 // "flip_y == true" means to reverse the video orientation while |
566 // "flip_y == false" means to keep the intrinsic orientation. | 565 // "flip_y == false" means to keep the intrinsic orientation. |
567 gl->CopyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, texture, | 566 if (params.copy_type == CopyFrameSingleTextureParams::FullCopy) { |
568 internal_format, type, flip_y, premultiply_alpha, | 567 DCHECK(!params.xoffset && !params.yoffset); |
569 false); | 568 gl->CopyTextureCHROMIUM(params.target, source_texture, params.texture, |
| 569 params.internal_format, params.type, params.flip_y, |
| 570 params.premultiply_alpha, false); |
| 571 } else { |
| 572 DCHECK_EQ(static_cast<unsigned int>(GL_FALSE), params.internal_format); |
| 573 DCHECK_EQ(static_cast<unsigned int>(GL_FALSE), params.type); |
| 574 gl->CopySubTextureCHROMIUM(params.target, source_texture, params.texture, |
| 575 params.xoffset, params.yoffset, 0, 0, |
| 576 video_frame->natural_size().width(), |
| 577 video_frame->natural_size().height(), |
| 578 params.flip_y, params.premultiply_alpha, false); |
| 579 } |
570 | 580 |
571 gl->DeleteTextures(1, &source_texture); | 581 gl->DeleteTextures(1, &source_texture); |
572 gl->Flush(); | 582 gl->Flush(); |
573 | 583 |
574 SyncPointClientImpl client(gl); | 584 SyncPointClientImpl client(gl); |
575 video_frame->UpdateReleaseSyncPoint(&client); | 585 video_frame->UpdateReleaseSyncPoint(&client); |
576 } | 586 } |
577 | 587 |
578 void SkCanvasVideoRenderer::ResetCache() { | 588 void SkCanvasVideoRenderer::ResetCache() { |
579 // Clear cached values. | 589 // Clear cached values. |
580 last_image_ = nullptr; | 590 last_image_ = nullptr; |
581 last_timestamp_ = kNoTimestamp(); | 591 last_timestamp_ = kNoTimestamp(); |
582 } | 592 } |
583 | 593 |
| 594 SkCanvasVideoRenderer::CopyFrameSingleTextureParams:: |
| 595 CopyFrameSingleTextureParams(CopyType copy_type, |
| 596 unsigned target, |
| 597 unsigned texture, |
| 598 unsigned internal_format, |
| 599 unsigned type, |
| 600 int level, |
| 601 int xoffset, |
| 602 int yoffset, |
| 603 bool premultiply_alpha, |
| 604 bool flip_y) |
| 605 : copy_type(copy_type), |
| 606 target(target), |
| 607 texture(texture), |
| 608 internal_format(internal_format), |
| 609 type(type), |
| 610 level(level), |
| 611 xoffset(xoffset), |
| 612 yoffset(yoffset), |
| 613 premultiply_alpha(premultiply_alpha), |
| 614 flip_y(flip_y) {} |
| 615 |
584 } // namespace media | 616 } // namespace media |
OLD | NEW |