| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 return false; | 137 return false; |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 unsigned texture_id = | 141 unsigned texture_id = |
| 142 static_cast<unsigned>((bitmap->getTexture())->getTextureHandle()); | 142 static_cast<unsigned>((bitmap->getTexture())->getTextureHandle()); |
| 143 // If CopyVideoFrameTextureToGLTexture() changes the state of the | 143 // If CopyVideoFrameTextureToGLTexture() changes the state of the |
| 144 // |texture_id|, it's needed to invalidate the state cached in skia, | 144 // |texture_id|, it's needed to invalidate the state cached in skia, |
| 145 // but currently the state isn't changed. | 145 // but currently the state isn't changed. |
| 146 SkCanvasVideoRenderer::CopyVideoFrameTextureToGLTexture( | 146 SkCanvasVideoRenderer::CopyVideoFrameTextureToGLTexture( |
| 147 context_3d.gl, video_frame, texture_id, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 147 context_3d.gl, video_frame, texture_id, GL_RGBA, GL_UNSIGNED_BYTE, true, |
| 148 true, false); | 148 false); |
| 149 bitmap->notifyPixelsChanged(); | 149 bitmap->notifyPixelsChanged(); |
| 150 return true; | 150 return true; |
| 151 } | 151 } |
| 152 | 152 |
| 153 class SyncPointClientImpl : public VideoFrame::SyncPointClient { | 153 class SyncPointClientImpl : public VideoFrame::SyncPointClient { |
| 154 public: | 154 public: |
| 155 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl) : gl_(gl) {} | 155 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl) : gl_(gl) {} |
| 156 ~SyncPointClientImpl() override {} | 156 ~SyncPointClientImpl() override {} |
| 157 uint32 InsertSyncPoint() override { return gl_->InsertSyncPointCHROMIUM(); } | 157 uint32 InsertSyncPoint() override { return gl_->InsertSyncPointCHROMIUM(); } |
| 158 void WaitSyncPoint(uint32 sync_point) override { | 158 void WaitSyncPoint(uint32 sync_point) override { |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 case VideoFrame::NV12: | 595 case VideoFrame::NV12: |
| 596 NOTREACHED(); | 596 NOTREACHED(); |
| 597 } | 597 } |
| 598 } | 598 } |
| 599 | 599 |
| 600 // static | 600 // static |
| 601 void SkCanvasVideoRenderer::CopyVideoFrameTextureToGLTexture( | 601 void SkCanvasVideoRenderer::CopyVideoFrameTextureToGLTexture( |
| 602 gpu::gles2::GLES2Interface* gl, | 602 gpu::gles2::GLES2Interface* gl, |
| 603 VideoFrame* video_frame, | 603 VideoFrame* video_frame, |
| 604 unsigned int texture, | 604 unsigned int texture, |
| 605 unsigned int level, | |
| 606 unsigned int internal_format, | 605 unsigned int internal_format, |
| 607 unsigned int type, | 606 unsigned int type, |
| 608 bool premultiply_alpha, | 607 bool premultiply_alpha, |
| 609 bool flip_y) { | 608 bool flip_y) { |
| 610 DCHECK(video_frame && video_frame->format() == VideoFrame::NATIVE_TEXTURE); | 609 DCHECK(video_frame && video_frame->format() == VideoFrame::NATIVE_TEXTURE); |
| 611 const gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder(); | 610 const gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder(); |
| 612 DCHECK(mailbox_holder->texture_target == GL_TEXTURE_2D || | 611 DCHECK(mailbox_holder->texture_target == GL_TEXTURE_2D || |
| 613 mailbox_holder->texture_target == GL_TEXTURE_RECTANGLE_ARB || | 612 mailbox_holder->texture_target == GL_TEXTURE_RECTANGLE_ARB || |
| 614 mailbox_holder->texture_target == GL_TEXTURE_EXTERNAL_OES); | 613 mailbox_holder->texture_target == GL_TEXTURE_EXTERNAL_OES); |
| 615 | 614 |
| 616 gl->WaitSyncPointCHROMIUM(mailbox_holder->sync_point); | 615 gl->WaitSyncPointCHROMIUM(mailbox_holder->sync_point); |
| 617 uint32 source_texture = gl->CreateAndConsumeTextureCHROMIUM( | 616 uint32 source_texture = gl->CreateAndConsumeTextureCHROMIUM( |
| 618 mailbox_holder->texture_target, mailbox_holder->mailbox.name); | 617 mailbox_holder->texture_target, mailbox_holder->mailbox.name); |
| 619 | 618 |
| 620 // The video is stored in a unmultiplied format, so premultiply | 619 // The video is stored in a unmultiplied format, so premultiply |
| 621 // if necessary. | 620 // if necessary. |
| 622 gl->PixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, premultiply_alpha); | 621 gl->PixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, premultiply_alpha); |
| 623 // Application itself needs to take care of setting the right |flip_y| | 622 // Application itself needs to take care of setting the right |flip_y| |
| 624 // value down to get the expected result. | 623 // value down to get the expected result. |
| 625 // "flip_y == true" means to reverse the video orientation while | 624 // "flip_y == true" means to reverse the video orientation while |
| 626 // "flip_y == false" means to keep the intrinsic orientation. | 625 // "flip_y == false" means to keep the intrinsic orientation. |
| 627 gl->PixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); | 626 gl->PixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); |
| 628 gl->CopyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, texture, level, | 627 gl->CopyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, texture, |
| 629 internal_format, type); | 628 internal_format, type); |
| 630 gl->PixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); | 629 gl->PixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); |
| 631 gl->PixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, false); | 630 gl->PixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, false); |
| 632 | 631 |
| 633 gl->DeleteTextures(1, &source_texture); | 632 gl->DeleteTextures(1, &source_texture); |
| 634 gl->Flush(); | 633 gl->Flush(); |
| 635 | 634 |
| 636 SyncPointClientImpl client(gl); | 635 SyncPointClientImpl client(gl); |
| 637 video_frame->UpdateReleaseSyncPoint(&client); | 636 video_frame->UpdateReleaseSyncPoint(&client); |
| 638 } | 637 } |
| 639 | 638 |
| 640 void SkCanvasVideoRenderer::ResetLastFrame() { | 639 void SkCanvasVideoRenderer::ResetLastFrame() { |
| 641 last_frame_.reset(); | 640 last_frame_.reset(); |
| 642 last_frame_timestamp_ = media::kNoTimestamp(); | 641 last_frame_timestamp_ = media::kNoTimestamp(); |
| 643 } | 642 } |
| 644 | 643 |
| 645 void SkCanvasVideoRenderer::ResetAcceleratedLastFrame() { | 644 void SkCanvasVideoRenderer::ResetAcceleratedLastFrame() { |
| 646 accelerated_last_frame_.reset(); | 645 accelerated_last_frame_.reset(); |
| 647 accelerated_generator_ = nullptr; | 646 accelerated_generator_ = nullptr; |
| 648 accelerated_last_frame_timestamp_ = media::kNoTimestamp(); | 647 accelerated_last_frame_timestamp_ = media::kNoTimestamp(); |
| 649 } | 648 } |
| 650 | 649 |
| 651 } // namespace media | 650 } // namespace media |
| OLD | NEW |