Chromium code: Implementation of GPU->GPU Direct picture transfer, do not need to transfer through the CPU

Source: Internet
Author: User

Commit0c4e9d8781aea6e52fdb4a7aee978817910c67ea
Authordongseong.hwang Thu Jan 08 20:11:13 2015
Committercommit bot Thu Jan 08 20:12:02 2015

Media:optimize HW Video to 2D Canvas copy. Currently, when we draws GPUs decoded Video on accelerated 2D Canvas, chromiumreads back pixel from GPUs and then uploads th e Pixel to the GPU to make a skbitmap.it's so inefficient for both speed and battery. On the other hand, only androidcopies Gpu-gpu in this case, but Android doesn ' t has cache mechanism Whichskcanvasvideoren Derer provides. This CL makes all platforms the copy Gpu-gpu with the cache mechanism. Cache Mechanismis useful when 2d canvas draws a video frame many times.e.g. http://craftymind.com/factory/html5video/CanvasVideo.htmlIn addition, fix white video background on Android Loaded. Other Platformsdraw black background thanks to Skcanvasvideorenderer::P aint (). In detail of the changes;1. Implement gpu-gpu copy in Skcanvasvideorenderer::P aint () like previouswebmediaplayerandroid::p aint (). 2. Move duplicated GPU code on WEBMEDIAPLAYERIMPL and Webmediaplayerandroid toskcanvasvideorenderer.perf data on i5 IvyBridge Blink_perf.all:Canvas_draw-video-to-hw-accelerated-canvas-2d15.8x speed up:116.27 runs/s-1847.23 runs/snote:measure after disabling C Ache in skcanvasvideorendererbug=401058, 263667Review url:https://codereview.chromium.org/ 445013002cr-commit-position:refs/heads/[email protected]{#310577}
  • Content/renderer/media/android/webmediaplayer_android.cc[diff]
  • Content/renderer/media/android/webmediaplayer_android.h[diff]
  • Content/renderer/media/webmediaplayer_ms.cc[diff]
  • Content/renderer/render_frame_impl.cc[diff]
  • Media/build.gn[diff]
  • Media/deps[diff]
  • Media/blink/build.gn[diff]
  • Media/blink/deps[diff]
  • Media/blink/media_blink.gyp[diff]
  • Media/blink/webmediaplayer_impl.cc[diff]
  • Media/blink/webmediaplayer_impl.h[diff]
  • Media/blink/webmediaplayer_params.cc[diff]
  • Media/blink/webmediaplayer_params.h[diff]
  • Media/filters/context_3d.h[added-diff]
  • Media/filters/skcanvas_video_renderer.cc[diff]
  • Media/filters/skcanvas_video_renderer.h[diff]
  • Media/filters/skcanvas_video_renderer_unittest.cc[diff]
  • Media/media.gyp[diff]
  • Mojo/services/html_viewer/webmediaplayer_factory.cc[diff]

Copy from video to picture, GPU to GPU direct, no CPU memory required?

//StaticvoidSkcanvasvideorenderer::copyvideoframetexturetogltexture (gpu::gles2::gles2interface* GL, VideoFrame* video_frame,unsigned intTextureunsigned intLevelunsigned intInternal_format,unsigned intTypeBOOLPremultiply_alpha,BOOLflip_y) {Dcheck (Video_frame && video_frame->format () = = Videoframe::native_texture);Constgpu::mailboxholder* Mailbox_holder = Video_frame->mailbox_holder ();         Dcheck (Mailbox_holder->texture_target = = Gl_texture_2d | |  Mailbox_holder->texture_target = = gl_texture_external_oes);  Gl->waitsyncpointchromium (Mailbox_holder->sync_point); UInt32 source_texture = Gl->createandconsumetexturechromium (Mailbox_holder->texture_target, mailbox_holder-& Gt;mailbox. Name);//The video is stored in a unmultiplied format, so premultiply  //if necessary.Gl->pixelstorei (Gl_unpack_premultiply_alpha_chromium, Premultiply_alpha);//application itself needs to take care of setting the right |flip_y|  //value down to get the expected result.  //"flip_y = = true" means to reverse the video orientation while  //"flip_y = = false" means to keep the intrinsic orientation.Gl->pixelstorei (Gl_unpack_flip_y_chromium, flip_y);   Gl->copytexturechromium (gl_texture_2d, Source_texture, TEXTURE, Level, Internal_format, type); Gl->pixelstorei (Gl_unpack_flip_y_chromium,false); Gl->pixelstorei (Gl_unpack_premultiply_alpha_chromium,false); Gl->deletetextures (1, &source_texture);  Gl->flush ();  Syncpointclientimpl Client (GL); Video_frame->updatereleasesyncpoint (&client);}

Main implementation code here, the main drawback is: from the code can be seen, still need GPU internal to GPU memory copy, do not zero-copy (if you can do the GPU memory pointer swap, or c++11 in the move structure, it is better). But obviously it's better than GPU-->CPU-->GPU's transfer efficiency.

In theory, GPU hardware-accelerated webview-to-view GPU snapshot snapshots can be delivered directly.

Chromium code: Implementation of GPU->GPU Direct picture transfer, do not need to transfer through the CPU

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.