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