Commit 87b9684b authored by Gil Dekel's avatar Gil Dekel Committed by Commit Bot

media/gpu: Add CreateContextAndScopedVASurface()

This CL adds the function CreateContextAndScopedVASurface() to the
VaapiWrapper, which attempts to create a context and surface and return
a std::unique_ptr<ScopedVASurface> to the client.

This CL is needed for the following change: https://crrev.com/c/1672404

Bug: 868400, 980379
Test: jpeg_decode_accelerator_unittest
Change-Id: Ic98ec612aed7ae221698e42f5b77378bbb0fc26d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1693361
Commit-Queue: Gil Dekel <gildekel@chromium.org>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarAndres Calderon Jaramillo <andrescj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#675806}
parent 96c7f23a
......@@ -124,9 +124,8 @@ TEST_F(VaapiUtilsTest, BadScopedVABufferMapping) {
// This test exercises the creation of a valid ScopedVASurface.
TEST_F(VaapiUtilsTest, ScopedVASurface) {
const gfx::Size coded_size(64, 64);
vaapi_wrapper_->CreateContext(VA_RT_FORMAT_YUV420, coded_size);
auto scoped_va_surface =
vaapi_wrapper_->CreateScopedVASurface(VA_RT_FORMAT_YUV420, coded_size);
auto scoped_va_surface = vaapi_wrapper_->CreateContextAndScopedVASurface(
VA_RT_FORMAT_YUV420, coded_size);
ASSERT_TRUE(scoped_va_surface);
EXPECT_TRUE(scoped_va_surface->IsValid());
......@@ -135,13 +134,20 @@ TEST_F(VaapiUtilsTest, ScopedVASurface) {
EXPECT_EQ(coded_size, scoped_va_surface->size());
}
// This test exercises the creation of a bad ScopedVASurface with an invalid
// This test exercises the creation of a ScopedVASurface with an invalid
// size.
TEST_F(VaapiUtilsTest, BadScopedVASurface) {
TEST_F(VaapiUtilsTest, ScopedVASurfaceInvalidSizeRequest) {
const gfx::Size invalid_size(0, 0);
vaapi_wrapper_->CreateContext(VA_RT_FORMAT_YUV420, invalid_size);
EXPECT_FALSE(
vaapi_wrapper_->CreateScopedVASurface(VA_RT_FORMAT_YUV420, invalid_size));
EXPECT_FALSE(vaapi_wrapper_->CreateContextAndScopedVASurface(
VA_RT_FORMAT_YUV420, invalid_size));
}
// This test exercises the creation of a ScopedVASurface with an invalid
// RT format.
TEST_F(VaapiUtilsTest, ScopedVASurfaceInvalidRTFormatRequest) {
const gfx::Size coded_size(64, 64);
EXPECT_FALSE(vaapi_wrapper_->CreateContextAndScopedVASurface(
kInvalidVaRtFormat, coded_size));
}
} // namespace media
......@@ -1294,6 +1294,27 @@ bool VaapiWrapper::CreateContextAndSurfaces(
return success;
}
std::unique_ptr<ScopedVASurface> VaapiWrapper::CreateContextAndScopedVASurface(
unsigned int va_format,
const gfx::Size& size) {
if (va_context_id_ != VA_INVALID_ID) {
LOG(ERROR) << "The current context should be destroyed before creating a "
"new one";
return nullptr;
}
std::unique_ptr<ScopedVASurface> scoped_va_surface =
CreateScopedVASurface(va_format, size);
if (!scoped_va_surface)
return nullptr;
if (CreateContext(va_format, size))
return scoped_va_surface;
DestroyContext();
return nullptr;
}
void VaapiWrapper::DestroyContextAndSurfaces(
std::vector<VASurfaceID> va_surfaces) {
DestroyContext();
......
......@@ -156,6 +156,15 @@ class MEDIA_GPU_EXPORT VaapiWrapper
const gfx::Size& size,
size_t num_surfaces,
std::vector<VASurfaceID>* va_surfaces);
// Creates a single VASurfaceID of |va_format| and |size| and, if
// successful, creates a |va_context_id_| of the same format and size. Returns
// a ScopedVASurface containing the created VASurfaceID, the |va_format|, and
// |size|, or nullptr if creation failed.
std::unique_ptr<ScopedVASurface> CreateContextAndScopedVASurface(
unsigned int va_format,
const gfx::Size& size);
// Releases the |va_surfaces| and destroys |va_context_id_|.
virtual void DestroyContextAndSurfaces(std::vector<VASurfaceID> va_surfaces);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment