0

[//gpu] Disallow further subclassing of SharedImageInterface

This CL makes the SharedImageInterface constructor private with
friending of existing subclasses. The purpose is to ensure that any new
subclassing goes through //gpu OWNERS, and in particular, that clients
use TestSharedImageInterface rather than creating new subclasses for
testing purposes.

Bug: 340303225
Change-Id: I4817eaae3692c51b768c4eecbcd36b66ec7db71a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5676785
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1323331}
This commit is contained in:
Colin Blundell
2024-07-04 14:13:55 +00:00
committed by Chromium LUCI CQ
parent 7f8bed5566
commit 922dd0c0ca
2 changed files with 28 additions and 2 deletions
gpu/command_buffer/client
media/mojo/clients

@ -40,12 +40,20 @@ class D3DSharedFence;
#endif
} // namespace gfx
namespace media {
class MockSharedImageInterface;
}
namespace gpu {
class ClientSharedImage;
class ClientSharedImageInterface;
struct ExportedSharedImage;
class GpuChannelSharedImageInterface;
class GpuMemoryBufferManager;
struct SharedImageCapabilities;
class SharedImageInterfaceHolder;
class SharedImageInterfaceInProcess;
class TestSharedImageInterface;
struct SharedImageMetadata {
viz::SharedImageFormat format;
@ -106,8 +114,6 @@ struct SharedImageInfo {
class GPU_EXPORT SharedImageInterface
: public base::RefCountedThreadSafe<SharedImageInterface> {
public:
SharedImageInterface();
// Creates a shared image of requested |format|, |size| and |color_space|.
// |usage| is a combination of |SharedImageUsage| bits that describes which
// API(s) the image will be used with.
@ -420,6 +426,20 @@ class GPU_EXPORT SharedImageInterface
virtual ~SharedImageInterface();
scoped_refptr<SharedImageInterfaceHolder> holder_;
private:
friend class ClientSharedImageInterface;
friend class GpuChannelSharedImageInterface;
friend class SharedImageInterfaceInProcess;
friend class TestSharedImageInterface;
friend class media::MockSharedImageInterface;
// Make the constructor private to ensure that any new subclassing of this
// interface gets explicit approval from //gpu OWNERS (by adding to the list
// of friends above). In particular, do not subclass this interface for
// testing purposes - use (and extend if necessary) TestSharedImageInterface
// instead.
SharedImageInterface();
};
// |SharedImageInterfaceHolder| provides thread-safe access to

@ -319,6 +319,10 @@ class MockStableVideoDecoderService : public stable::mojom::StableVideoDecoder {
std::unique_ptr<MojoDecoderBufferReader> mojo_decoder_buffer_reader_;
};
} // namespace
// NOTE: This needs to be outside of an anonymous namespace to allow it to be
// friended by SharedImageInterface.
class MockSharedImageInterface : public gpu::SharedImageInterface {
public:
// gpu::SharedImageInterface implementation.
@ -390,6 +394,8 @@ class MockSharedImageInterface : public gpu::SharedImageInterface {
~MockSharedImageInterface() override = default;
};
namespace {
// TestEndpoints groups a few members that result from creating and initializing
// a MojoStableVideoDecoder so that tests can use them to set expectations
// and/or to poke at them to trigger specific paths.