media/gpu/chromeos: Add FrameResource NativePixmap accessor functions
HasNativePixmap() and GetNativePixmapDmaBuf() give users of FrameResource a way to access an underlying NativePixmapDmaBuf of a frame. The new method replaces the NativePixmapFrameResource-specific method GetNativePixmapDmaBuf(). VideoFrameResource objects will never return true for HasNativePixmap(). Bug: b:277581596 Test: Chrome compiles and links Test: Media unit tests pass. Change-Id: I3c0ac87120556e5c78e055747323db4a1128d12c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5381361 Commit-Queue: Nathan Hebert <nhebert@chromium.org> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Cr-Commit-Position: refs/heads/main@{#1276705}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
b20ad2e642
commit
fdce2f2815
@ -89,6 +89,17 @@ class FrameResource : public base::RefCountedThreadSafe<FrameResource> {
|
||||
virtual scoped_refptr<gfx::NativePixmapDmaBuf> CreateNativePixmapDmaBuf()
|
||||
const = 0;
|
||||
|
||||
// Returns true if |this| is backed by a NativePixmap.
|
||||
bool HasNativePixmap() const {
|
||||
return static_cast<bool>(GetNativePixmapDmaBuf());
|
||||
}
|
||||
|
||||
// Gets the NativePixmapDmaBuf backing |this|. Ownership is retained by
|
||||
// |this| unless the returned value is copied. Then a reference is taken by
|
||||
// the caller.
|
||||
virtual const scoped_refptr<const gfx::NativePixmapDmaBuf>&
|
||||
GetNativePixmapDmaBuf() const = 0;
|
||||
|
||||
// Create a shared GPU memory handle to |this|'s data.
|
||||
virtual gfx::GpuMemoryBufferHandle CreateGpuMemoryBufferHandle() const = 0;
|
||||
|
||||
|
@ -305,6 +305,11 @@ NativePixmapFrameResource::CreateNativePixmapDmaBuf() const {
|
||||
std::move(native_pixmap_handle));
|
||||
}
|
||||
|
||||
const scoped_refptr<const gfx::NativePixmapDmaBuf>&
|
||||
NativePixmapFrameResource::GetNativePixmapDmaBuf() const {
|
||||
return pixmap_;
|
||||
}
|
||||
|
||||
gfx::GpuMemoryBufferHandle
|
||||
NativePixmapFrameResource::CreateGpuMemoryBufferHandle() const {
|
||||
// Duplicate FD's into a new NativePixmapHandle
|
||||
@ -494,9 +499,4 @@ scoped_refptr<VideoFrame> NativePixmapFrameResource::CreateVideoFrame() const {
|
||||
return video_frame;
|
||||
}
|
||||
|
||||
const scoped_refptr<const gfx::NativePixmapDmaBuf>&
|
||||
NativePixmapFrameResource::GetNativePixmapDmaBuf() const {
|
||||
return pixmap_;
|
||||
}
|
||||
|
||||
} // namespace media
|
||||
|
@ -73,6 +73,8 @@ class NativePixmapFrameResource : public FrameResource {
|
||||
int GetDmabufFd(size_t i) const override;
|
||||
scoped_refptr<gfx::NativePixmapDmaBuf> CreateNativePixmapDmaBuf()
|
||||
const override;
|
||||
const scoped_refptr<const gfx::NativePixmapDmaBuf>& GetNativePixmapDmaBuf()
|
||||
const override;
|
||||
// CreateGpuMemoryBufferHandle() will duplicate file descriptors to make a
|
||||
// gfx::GpuMemoryBufferHandle. The GpuMemoryBufferId will match
|
||||
// GetSharedMemoryId(). Doing this helps with identification of original
|
||||
@ -112,11 +114,6 @@ class NativePixmapFrameResource : public FrameResource {
|
||||
// reclamation.
|
||||
scoped_refptr<VideoFrame> CreateVideoFrame() const;
|
||||
|
||||
// Returns a reference to |this|'s backing NativePixmap. Ownership of
|
||||
// the NativePixmap is retained by |this|.
|
||||
const scoped_refptr<const gfx::NativePixmapDmaBuf>& GetNativePixmapDmaBuf()
|
||||
const;
|
||||
|
||||
private:
|
||||
~NativePixmapFrameResource() override;
|
||||
|
||||
|
@ -76,6 +76,14 @@ VideoFrameResource::CreateNativePixmapDmaBuf() const {
|
||||
return media::CreateNativePixmapDmaBuf(frame_.get());
|
||||
}
|
||||
|
||||
const scoped_refptr<const gfx::NativePixmapDmaBuf>&
|
||||
VideoFrameResource::GetNativePixmapDmaBuf() const {
|
||||
// |invalid_dmabuf| is stored as static so we can return a reference to it.
|
||||
static const scoped_refptr<const gfx::NativePixmapDmaBuf> invalid_dmabuf;
|
||||
|
||||
return invalid_dmabuf;
|
||||
}
|
||||
|
||||
gfx::GpuMemoryBufferHandle VideoFrameResource::CreateGpuMemoryBufferHandle()
|
||||
const {
|
||||
return media::CreateGpuMemoryBufferHandle(frame_.get());
|
||||
|
@ -37,6 +37,10 @@ class VideoFrameResource : public FrameResource {
|
||||
int GetDmabufFd(size_t i) const override;
|
||||
scoped_refptr<gfx::NativePixmapDmaBuf> CreateNativePixmapDmaBuf()
|
||||
const override;
|
||||
// GetNativePixmapDmaBuf() always returns an invalid NativePixmap, since there
|
||||
// is no NativePixmap-backed VideoFrame.
|
||||
const scoped_refptr<const gfx::NativePixmapDmaBuf>& GetNativePixmapDmaBuf()
|
||||
const override;
|
||||
gfx::GpuMemoryBufferHandle CreateGpuMemoryBufferHandle() const override;
|
||||
gfx::GpuMemoryBuffer* GetGpuMemoryBuffer() const override;
|
||||
gfx::GenericSharedMemoryId GetSharedMemoryId() const override;
|
||||
|
@ -81,4 +81,14 @@ TEST(VideoFrameResourceTest, WrappingLifecycle) {
|
||||
ASSERT_TRUE(orig->HasAtLeastOneRef());
|
||||
ASSERT_FALSE(orig->HasOneRef());
|
||||
}
|
||||
|
||||
TEST(VideoFrameResourceTest, HasNativePixmap) {
|
||||
const VideoPixelFormat kPixelFormat = PIXEL_FORMAT_NV12;
|
||||
constexpr gfx::Size kCodedSize(320, 240);
|
||||
scoped_refptr<FrameResource> frame =
|
||||
VideoFrameResource::Create(CreateMockDmaBufVideoFrame(
|
||||
kPixelFormat, kCodedSize, /*visible_rect=*/gfx::Rect(kCodedSize),
|
||||
/*natural_size=*/kCodedSize));
|
||||
ASSERT_FALSE(frame->HasNativePixmap());
|
||||
}
|
||||
} // namespace media
|
||||
|
Reference in New Issue
Block a user