1 // Copyright 2014 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 // This file contains an interface of output pictures for the Vaapi 6 // video decoder. This is implemented by different window system 7 // (X11/Ozone) and used by VaapiVideoDecodeAccelerator to produce 8 // output pictures. 9 10 #ifndef MEDIA_GPU_VAAPI_VAAPI_PICTURE_H_ 11 #define MEDIA_GPU_VAAPI_VAAPI_PICTURE_H_ 12 13 #include <stdint.h> 14 15 #include "base/macros.h" 16 #include "base/memory/ref_counted.h" 17 #include "base/sequence_checker.h" 18 #include "media/gpu/gpu_video_decode_accelerator_helpers.h" 19 #include "media/gpu/media_gpu_export.h" 20 #include "ui/gfx/geometry/size.h" 21 #include "ui/gfx/gpu_memory_buffer.h" 22 23 namespace media { 24 25 using VASurfaceID = unsigned int; 26 27 class VASurface; 28 class VaapiWrapper; 29 30 // Picture is native pixmap abstraction (X11/Ozone). 31 class MEDIA_GPU_EXPORT VaapiPicture { 32 public: 33 virtual ~VaapiPicture(); 34 35 // Uses the buffer of |format|, pointed to by |gpu_memory_buffer_handle| as 36 // the backing storage for this picture. This takes ownership of the handle 37 // and will close it even on failure. Return true on success, false otherwise. 38 virtual bool ImportGpuMemoryBufferHandle( 39 gfx::BufferFormat format, 40 gfx::GpuMemoryBufferHandle gpu_memory_buffer_handle) = 0; 41 42 // Allocates a buffer of |format| to use as backing storage for this picture. 43 // Return true on success. 44 virtual Status Allocate(gfx::BufferFormat format) = 0; 45 picture_buffer_id()46 int32_t picture_buffer_id() const { return picture_buffer_id_; } 47 48 virtual bool AllowOverlay() const; 49 50 // Downloads |va_surface| into the picture, potentially scaling it if needed. 51 virtual bool DownloadFromSurface(scoped_refptr<VASurface> va_surface) = 0; 52 53 // Returns the associated VASurfaceID, if any, or VA_INVALID_ID. 54 virtual VASurfaceID va_surface_id() const; 55 56 protected: 57 VaapiPicture(scoped_refptr<VaapiWrapper> vaapi_wrapper, 58 const MakeGLContextCurrentCallback& make_context_current_cb, 59 const BindGLImageCallback& bind_image_cb, 60 int32_t picture_buffer_id, 61 const gfx::Size& size, 62 const gfx::Size& visible_size, 63 uint32_t texture_id, 64 uint32_t client_texture_id, 65 uint32_t texture_target); 66 67 const scoped_refptr<VaapiWrapper> vaapi_wrapper_; 68 69 const MakeGLContextCurrentCallback make_context_current_cb_; 70 const BindGLImageCallback bind_image_cb_; 71 72 const gfx::Size size_; 73 const gfx::Size visible_size_; 74 const uint32_t texture_id_; 75 const uint32_t client_texture_id_; 76 const uint32_t texture_target_; 77 78 SEQUENCE_CHECKER(sequence_checker_); 79 80 private: 81 const int32_t picture_buffer_id_; 82 83 DISALLOW_COPY_AND_ASSIGN(VaapiPicture); 84 }; 85 86 } // namespace media 87 88 #endif // MEDIA_GPU_VAAPI_VAAPI_PICTURE_H_ 89