| 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, | 164 gl, video_frame, source_texture, GL_RGBA, GL_UNSIGNED_BYTE, true, |
| 165 SkCanvasVideoRenderer::CopyFrameSingleTextureParams( | 165 false); |
| 166 SkCanvasVideoRenderer::CopyFrameSingleTextureParams::FullCopy, | |
| 167 GL_TEXTURE_2D, source_texture, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0, 0, | |
| 168 true, false)); | |
| 169 } else { | 166 } else { |
| 170 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); | 167 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); |
| 171 source_texture = gl->CreateAndConsumeTextureCHROMIUM( | 168 source_texture = gl->CreateAndConsumeTextureCHROMIUM( |
| 172 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 169 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
| 173 } | 170 } |
| 174 GrBackendTextureDesc desc; | 171 GrBackendTextureDesc desc; |
| 175 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 172 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 176 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 173 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 177 desc.fWidth = video_frame->coded_size().width(); | 174 desc.fWidth = video_frame->coded_size().width(); |
| 178 desc.fHeight = video_frame->coded_size().height(); | 175 desc.fHeight = video_frame->coded_size().height(); |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 case PIXEL_FORMAT_MT21: | 529 case PIXEL_FORMAT_MT21: |
| 533 case PIXEL_FORMAT_UNKNOWN: | 530 case PIXEL_FORMAT_UNKNOWN: |
| 534 NOTREACHED(); | 531 NOTREACHED(); |
| 535 } | 532 } |
| 536 } | 533 } |
| 537 | 534 |
| 538 // static | 535 // static |
| 539 void SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( | 536 void SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( |
| 540 gpu::gles2::GLES2Interface* gl, | 537 gpu::gles2::GLES2Interface* gl, |
| 541 VideoFrame* video_frame, | 538 VideoFrame* video_frame, |
| 542 const CopyFrameSingleTextureParams& params) { | 539 unsigned int texture, |
| 540 unsigned int internal_format, |
| 541 unsigned int type, |
| 542 bool premultiply_alpha, |
| 543 bool flip_y) { |
| 543 DCHECK(video_frame); | 544 DCHECK(video_frame); |
| 544 DCHECK(video_frame->HasTextures()); | 545 DCHECK(video_frame->HasTextures()); |
| 545 DCHECK_EQ(1u, VideoFrame::NumPlanes(video_frame->format())); | 546 DCHECK_EQ(1u, VideoFrame::NumPlanes(video_frame->format())); |
| 546 | 547 |
| 547 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); | 548 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); |
| 548 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || | 549 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || |
| 549 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB || | 550 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB || |
| 550 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) | 551 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) |
| 551 << mailbox_holder.texture_target; | 552 << mailbox_holder.texture_target; |
| 552 | 553 |
| 553 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); | 554 gl->WaitSyncPointCHROMIUM(mailbox_holder.sync_point); |
| 554 uint32 source_texture = gl->CreateAndConsumeTextureCHROMIUM( | 555 uint32 source_texture = gl->CreateAndConsumeTextureCHROMIUM( |
| 555 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 556 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
| 556 | 557 |
| 557 // The video is stored in a unmultiplied format, so premultiply | 558 // The video is stored in a unmultiplied format, so premultiply |
| 558 // if necessary. | 559 // if necessary. |
| 559 // 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| |
| 560 // value down to get the expected result. | 561 // value down to get the expected result. |
| 561 // "flip_y == true" means to reverse the video orientation while | 562 // "flip_y == true" means to reverse the video orientation while |
| 562 // "flip_y == false" means to keep the intrinsic orientation. | 563 // "flip_y == false" means to keep the intrinsic orientation. |
| 563 if (params.copy_type == CopyFrameSingleTextureParams::FullCopy) { | 564 gl->CopyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, texture, |
| 564 DCHECK(!params.xoffset && !params.yoffset); | 565 internal_format, type, flip_y, premultiply_alpha, |
| 565 gl->CopyTextureCHROMIUM(params.target, source_texture, params.texture, | 566 false); |
| 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 } | |
| 577 | 567 |
| 578 gl->DeleteTextures(1, &source_texture); | 568 gl->DeleteTextures(1, &source_texture); |
| 579 gl->Flush(); | 569 gl->Flush(); |
| 580 | 570 |
| 581 SyncPointClientImpl client(gl); | 571 SyncPointClientImpl client(gl); |
| 582 video_frame->UpdateReleaseSyncPoint(&client); | 572 video_frame->UpdateReleaseSyncPoint(&client); |
| 583 } | 573 } |
| 584 | 574 |
| 585 void SkCanvasVideoRenderer::ResetCache() { | 575 void SkCanvasVideoRenderer::ResetCache() { |
| 586 // Clear cached values. | 576 // Clear cached values. |
| 587 last_image_ = nullptr; | 577 last_image_ = nullptr; |
| 588 last_timestamp_ = kNoTimestamp(); | 578 last_timestamp_ = kNoTimestamp(); |
| 589 } | 579 } |
| 590 | 580 |
| 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 | |
| 613 } // namespace media | 581 } // namespace media |
| OLD | NEW |