1 // Copyright 2018 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef MEDIA_GPU_CHROMEOS_PLATFORM_VIDEO_FRAME_UTILS_H_ 6 #define MEDIA_GPU_CHROMEOS_PLATFORM_VIDEO_FRAME_UTILS_H_ 7 8 #include "base/memory/scoped_refptr.h" 9 #include "media/base/video_frame.h" 10 #include "media/gpu/media_gpu_export.h" 11 #include "ui/gfx/buffer_types.h" 12 #include "ui/gfx/linux/native_pixmap_dmabuf.h" 13 14 namespace gfx { 15 struct GpuMemoryBufferHandle; 16 } // namespace gfx 17 18 namespace gpu { 19 class GpuMemoryBufferFactory; 20 } // namespace gpu 21 22 namespace media { 23 24 // Create GpuMemoryBuffer-based media::VideoFrame with |buffer_usage|. 25 // See //media/base/video_frame.h for other parameters. 26 // |gpu_memory_buffer_factory| must outlive the returned VideoFrame. 27 MEDIA_GPU_EXPORT scoped_refptr<VideoFrame> CreateGpuMemoryBufferVideoFrame( 28 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, 29 VideoPixelFormat pixel_format, 30 const gfx::Size& coded_size, 31 const gfx::Rect& visible_rect, 32 const gfx::Size& natural_size, 33 base::TimeDelta timestamp, 34 gfx::BufferUsage buffer_usage); 35 36 // Create platform dependent media::VideoFrame with |buffer_usage|. 37 // See //media/base/video_frame.h for other parameters. 38 // |gpu_memory_buffer_factory| must outlive the returned VideoFrame. 39 MEDIA_GPU_EXPORT scoped_refptr<VideoFrame> CreatePlatformVideoFrame( 40 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, 41 VideoPixelFormat pixel_format, 42 const gfx::Size& coded_size, 43 const gfx::Rect& visible_rect, 44 const gfx::Size& natural_size, 45 base::TimeDelta timestamp, 46 gfx::BufferUsage buffer_usage); 47 48 // Get VideoFrameLayout of platform dependent video frame with |pixel_format|, 49 // |coded_size| and |buffer_usage|. This function is not cost-free as this 50 // allocates a platform dependent video frame. 51 MEDIA_GPU_EXPORT base::Optional<VideoFrameLayout> GetPlatformVideoFrameLayout( 52 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, 53 VideoPixelFormat pixel_format, 54 const gfx::Size& coded_size, 55 gfx::BufferUsage buffer_usage); 56 57 // Create a shared GPU memory handle to the |video_frame|'s data. 58 MEDIA_GPU_EXPORT gfx::GpuMemoryBufferHandle CreateGpuMemoryBufferHandle( 59 const VideoFrame* video_frame); 60 61 // Create a NativePixmap that references the DMA Bufs of |video_frame|. The 62 // returned pixmap is only a DMA Buf container and should not be used for 63 // compositing/scanout. 64 MEDIA_GPU_EXPORT scoped_refptr<gfx::NativePixmapDmaBuf> 65 CreateNativePixmapDmaBuf(const VideoFrame* video_frame); 66 67 } // namespace media 68 69 #endif // MEDIA_GPU_CHROMEOS_PLATFORM_VIDEO_FRAME_UTILS_H_ 70