Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
mocks.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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 FLUTTER_IMPELLER_RENDERER_TESTING_MOCKS_H_
6#define FLUTTER_IMPELLER_RENDERER_TESTING_MOCKS_H_
7
8#include "gmock/gmock.h"
18
19namespace impeller {
20namespace testing {
21
23 public:
25 : DeviceBuffer(desc) {}
26
27 MOCK_METHOD(bool, SetLabel, (const std::string& label), (override));
28
31 (const std::string& label, Range range),
32 (override));
33
34 MOCK_METHOD(uint8_t*, OnGetContents, (), (const, override));
35
38 (const uint8_t* source, Range source_range, size_t offset),
39 (override));
40};
41
42class MockAllocator : public Allocator {
43 public:
45 MOCK_METHOD(std::shared_ptr<DeviceBuffer>,
47 (const DeviceBufferDescriptor& desc),
48 (override));
49 MOCK_METHOD(std::shared_ptr<Texture>,
51 (const TextureDescriptor& desc),
52 (override));
53};
54
55class MockBlitPass : public BlitPass {
56 public:
57 MOCK_METHOD(bool, IsValid, (), (const, override));
60 (const std::shared_ptr<Allocator>& transients_allocator),
61 (const, override));
62 MOCK_METHOD(void, OnSetLabel, (std::string label), (override));
63
66 (std::shared_ptr<Texture> source,
67 std::shared_ptr<Texture> destination,
68 IRect source_region,
69 IPoint destination_origin,
70 std::string label),
71 (override));
72
75 (std::shared_ptr<Texture> source,
76 std::shared_ptr<DeviceBuffer> destination,
77 IRect source_region,
78 size_t destination_offset,
79 std::string label),
80 (override));
84 std::shared_ptr<Texture> destination,
85 IPoint destination_origin,
86 std::string label),
87 (override));
90 (std::shared_ptr<Texture> texture, std::string label),
91 (override));
92};
93
94class MockRenderPass : public RenderPass {
95 public:
96 MockRenderPass(std::shared_ptr<const Context> context,
97 const RenderTarget& target)
98 : RenderPass(std::move(context), target) {}
99 MOCK_METHOD(bool, IsValid, (), (const, override));
102 (const Context& context),
103 (const, override));
104 MOCK_METHOD(void, OnSetLabel, (std::string label), (override));
105};
106
107class MockCommandBuffer : public CommandBuffer {
108 public:
109 explicit MockCommandBuffer(std::weak_ptr<const Context> context)
110 : CommandBuffer(std::move(context)) {}
111 MOCK_METHOD(bool, IsValid, (), (const, override));
112 MOCK_METHOD(void, SetLabel, (const std::string& label), (const, override));
113 MOCK_METHOD(std::shared_ptr<BlitPass>, OnCreateBlitPass, (), (override));
115 OnSubmitCommands,
117 (override));
118 MOCK_METHOD(void, OnWaitUntilScheduled, (), (override));
119 MOCK_METHOD(std::shared_ptr<ComputePass>,
120 OnCreateComputePass,
121 (),
122 (override));
123 MOCK_METHOD(std::shared_ptr<RenderPass>,
124 OnCreateRenderPass,
125 (RenderTarget render_target),
126 (override));
127};
128
130 public:
132
133 MOCK_METHOD(std::string, DescribeGpuModel, (), (const, override));
134
135 MOCK_METHOD(bool, IsValid, (), (const, override));
136
137 MOCK_METHOD(void, Shutdown, (), (override));
138
139 MOCK_METHOD(std::shared_ptr<Allocator>,
141 (),
142 (const, override));
143
144 MOCK_METHOD(std::shared_ptr<ShaderLibrary>,
146 (),
147 (const, override));
148
149 MOCK_METHOD(std::shared_ptr<SamplerLibrary>,
151 (),
152 (const, override));
153
154 MOCK_METHOD(std::shared_ptr<PipelineLibrary>,
156 (),
157 (const, override));
158
159 MOCK_METHOD(std::shared_ptr<CommandBuffer>,
161 (),
162 (const, override));
163
164 MOCK_METHOD(const std::shared_ptr<const Capabilities>&,
166 (),
167 (const, override));
168
169 MOCK_METHOD(std::shared_ptr<CommandQueue>,
171 (),
172 (const, override));
173};
174
175class MockTexture : public Texture {
176 public:
177 explicit MockTexture(const TextureDescriptor& desc) : Texture(desc) {}
178 MOCK_METHOD(void, SetLabel, (std::string_view label), (override));
179 MOCK_METHOD(bool, IsValid, (), (const, override));
180 MOCK_METHOD(ISize, GetSize, (), (const, override));
183 (const uint8_t* contents, size_t length, size_t slice),
184 (override));
187 (std::shared_ptr<const fml::Mapping> mapping, size_t slice),
188 (override));
189};
190
192 public:
193 MOCK_METHOD(bool, SupportsOffscreenMSAA, (), (const, override));
194 MOCK_METHOD(bool, SupportsImplicitResolvingMSAA, (), (const, override));
195 MOCK_METHOD(bool, SupportsSSBO, (), (const, override));
196 MOCK_METHOD(bool, SupportsBufferToTextureBlits, (), (const, override));
197 MOCK_METHOD(bool, SupportsTextureToTextureBlits, (), (const, override));
198 MOCK_METHOD(bool, SupportsFramebufferFetch, (), (const, override));
199 MOCK_METHOD(bool, SupportsCompute, (), (const, override));
200 MOCK_METHOD(bool, SupportsComputeSubgroups, (), (const, override));
201 MOCK_METHOD(bool, SupportsReadFromResolve, (), (const, override));
202 MOCK_METHOD(bool, SupportsDecalSamplerAddressMode, (), (const, override));
203 MOCK_METHOD(bool, SupportsDeviceTransientTextures, (), (const, override));
208};
209
211 public:
213 Submit,
214 (const std::vector<std::shared_ptr<CommandBuffer>>& buffers,
215 const CompletionCallback& cb),
216 (override));
217};
218
220 public:
221 MOCK_METHOD(const std::unique_ptr<const Sampler>&,
223 (SamplerDescriptor descriptor),
224 (override));
225};
226
227class MockSampler : public Sampler {
228 public:
229 explicit MockSampler(const SamplerDescriptor& desc) : Sampler(desc) {}
230};
231
232} // namespace testing
233} // namespace impeller
234
235#endif // FLUTTER_IMPELLER_RENDERER_TESTING_MOCKS_H_
An object that allocates device memory.
Definition allocator.h:22
virtual ISize GetMaxTextureSizeSupported() const =0
virtual std::shared_ptr< Texture > OnCreateTexture(const TextureDescriptor &desc)=0
virtual std::shared_ptr< DeviceBuffer > OnCreateBuffer(const DeviceBufferDescriptor &desc)=0
Blit passes encode blit into the underlying command buffer.
Definition blit_pass.h:26
virtual bool EncodeCommands(const std::shared_ptr< Allocator > &transients_allocator) const =0
Encode the recorded commands to the underlying command buffer.
virtual bool OnCopyTextureToBufferCommand(std::shared_ptr< Texture > source, std::shared_ptr< DeviceBuffer > destination, IRect source_region, size_t destination_offset, std::string label)=0
virtual bool OnCopyBufferToTextureCommand(BufferView source, std::shared_ptr< Texture > destination, IPoint destination_origin, std::string label)=0
virtual void OnSetLabel(std::string label)=0
virtual bool IsValid() const =0
virtual bool OnGenerateMipmapCommand(std::shared_ptr< Texture > texture, std::string label)=0
virtual bool OnCopyTextureToTextureCommand(std::shared_ptr< Texture > source, std::shared_ptr< Texture > destination, IRect source_region, IPoint destination_origin, std::string label)=0
virtual PixelFormat GetDefaultStencilFormat() const =0
Returns a supported PixelFormat for textures that store stencil information. May include a depth chan...
virtual bool SupportsOffscreenMSAA() const =0
Whether the context backend supports attaching offscreen MSAA color/stencil textures.
virtual bool SupportsImplicitResolvingMSAA() const =0
Whether the context backend supports multisampled rendering to the on-screen surface without requirin...
virtual bool SupportsFramebufferFetch() const =0
Whether the context backend is able to support pipelines with shaders that read from the framebuffer ...
virtual bool SupportsDecalSamplerAddressMode() const =0
Whether the context backend supports SamplerAddressMode::Decal.
virtual bool SupportsReadFromResolve() const =0
Whether the context backend supports binding the current RenderPass attachments. This is supported if...
virtual bool SupportsComputeSubgroups() const =0
Whether the context backend supports configuring ComputePass command subgroups.
virtual PixelFormat GetDefaultGlyphAtlasFormat() const =0
Returns the default pixel format for the alpha bitmap glyph atlas.
virtual PixelFormat GetDefaultColorFormat() const =0
Returns a supported PixelFormat for textures that store 4-channel colors (red/green/blue/alpha).
virtual bool SupportsBufferToTextureBlits() const =0
Whether the context backend supports blitting from a given DeviceBuffer view to a texture region (via...
virtual bool SupportsDeviceTransientTextures() const =0
Whether the context backend supports allocating StorageMode::kDeviceTransient (aka "memoryless") text...
virtual bool SupportsCompute() const =0
Whether the context backend supports ComputePass.
virtual bool SupportsSSBO() const =0
Whether the context backend supports binding Shader Storage Buffer Objects (SSBOs) to pipelines.
virtual PixelFormat GetDefaultDepthStencilFormat() const =0
Returns a supported PixelFormat for textures that store both a stencil and depth component....
virtual bool SupportsTextureToTextureBlits() const =0
Whether the context backend supports blitting from one texture region to another texture region (via ...
A collection of encoded commands to be submitted to the GPU for execution. A command buffer is obtain...
std::function< void(Status)> CompletionCallback
An interface for submitting command buffers to the GPU for encoding and execution.
std::function< void(CommandBuffer::Status)> CompletionCallback
virtual fml::Status Submit(const std::vector< std::shared_ptr< CommandBuffer > > &buffers, const CompletionCallback &completion_callback={})
Submit one or more command buffer objects to be encoded and executed on the GPU.
To do anything rendering related with Impeller, you need a context.
Definition context.h:46
virtual std::shared_ptr< CommandQueue > GetCommandQueue() const =0
Return the graphics queue for submitting command buffers.
virtual const std::shared_ptr< const Capabilities > & GetCapabilities() const =0
Get the capabilities of Impeller context. All optionally supported feature of the platform,...
virtual BackendType GetBackendType() const =0
Get the graphics backend of an Impeller context.
virtual std::shared_ptr< PipelineLibrary > GetPipelineLibrary() const =0
Returns the library of pipelines used by render or compute commands.
virtual void Shutdown()=0
Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent mess...
virtual std::shared_ptr< ShaderLibrary > GetShaderLibrary() const =0
Returns the library of shaders used to specify the programmable stages of a pipeline.
virtual std::shared_ptr< SamplerLibrary > GetSamplerLibrary() const =0
Returns the library of combined image samplers used in shaders.
virtual std::shared_ptr< CommandBuffer > CreateCommandBuffer() const =0
Create a new command buffer. Command buffers can be used to encode graphics, blit,...
virtual std::string DescribeGpuModel() const =0
virtual std::shared_ptr< Allocator > GetResourceAllocator() const =0
Returns the allocator used to create textures and buffers on the device.
virtual bool IsValid() const =0
Determines if a context is valid. If the caller ever receives an invalid context, they must discard i...
virtual uint8_t * OnGetContents() const =0
virtual bool SetLabel(const std::string &label)=0
virtual bool OnCopyHostBuffer(const uint8_t *source, Range source_range, size_t offset)=0
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition render_pass.h:33
virtual void OnSetLabel(std::string label)=0
virtual bool OnEncodeCommands(const Context &context) const =0
virtual bool IsValid() const =0
virtual const std::unique_ptr< const Sampler > & GetSampler(SamplerDescriptor descriptor)=0
Retrieve a backend specific sampler object for the given sampler descriptor.
virtual void SetLabel(std::string_view label)=0
virtual ISize GetSize() const =0
virtual bool OnSetContents(const uint8_t *contents, size_t length, size_t slice)=0
virtual bool IsValid() const =0
MOCK_METHOD(ISize, GetMaxTextureSizeSupported,(),(const, override))
MOCK_METHOD(std::shared_ptr< DeviceBuffer >, OnCreateBuffer,(const DeviceBufferDescriptor &desc),(override))
MOCK_METHOD(std::shared_ptr< Texture >, OnCreateTexture,(const TextureDescriptor &desc),(override))
MOCK_METHOD(void, OnSetLabel,(std::string label),(override))
MOCK_METHOD(bool, EncodeCommands,(const std::shared_ptr< Allocator > &transients_allocator),(const, override))
MOCK_METHOD(bool, OnGenerateMipmapCommand,(std::shared_ptr< Texture > texture, std::string label),(override))
MOCK_METHOD(bool, OnCopyBufferToTextureCommand,(BufferView source, std::shared_ptr< Texture > destination, IPoint destination_origin, std::string label),(override))
MOCK_METHOD(bool, OnCopyTextureToBufferCommand,(std::shared_ptr< Texture > source, std::shared_ptr< DeviceBuffer > destination, IRect source_region, size_t destination_offset, std::string label),(override))
MOCK_METHOD(bool, OnCopyTextureToTextureCommand,(std::shared_ptr< Texture > source, std::shared_ptr< Texture > destination, IRect source_region, IPoint destination_origin, std::string label),(override))
MOCK_METHOD(bool, IsValid,(),(const, override))
MOCK_METHOD(bool, SupportsDecalSamplerAddressMode,(),(const, override))
MOCK_METHOD(bool, SupportsOffscreenMSAA,(),(const, override))
MOCK_METHOD(PixelFormat, GetDefaultGlyphAtlasFormat,(),(const, override))
MOCK_METHOD(bool, SupportsFramebufferFetch,(),(const, override))
MOCK_METHOD(bool, SupportsSSBO,(),(const, override))
MOCK_METHOD(bool, SupportsBufferToTextureBlits,(),(const, override))
MOCK_METHOD(bool, SupportsTextureToTextureBlits,(),(const, override))
MOCK_METHOD(bool, SupportsImplicitResolvingMSAA,(),(const, override))
MOCK_METHOD(bool, SupportsReadFromResolve,(),(const, override))
MOCK_METHOD(bool, SupportsDeviceTransientTextures,(),(const, override))
MOCK_METHOD(PixelFormat, GetDefaultDepthStencilFormat,(),(const, override))
MOCK_METHOD(PixelFormat, GetDefaultStencilFormat,(),(const, override))
MOCK_METHOD(bool, SupportsComputeSubgroups,(),(const, override))
MOCK_METHOD(PixelFormat, GetDefaultColorFormat,(),(const, override))
MOCK_METHOD(bool, SupportsCompute,(),(const, override))
MOCK_METHOD(void, OnWaitUntilScheduled,(),(override))
MOCK_METHOD(bool, OnSubmitCommands,(CompletionCallback callback),(override))
MOCK_METHOD(void, SetLabel,(const std::string &label),(const, override))
MOCK_METHOD(bool, IsValid,(),(const, override))
MOCK_METHOD(std::shared_ptr< ComputePass >, OnCreateComputePass,(),(override))
MOCK_METHOD(std::shared_ptr< BlitPass >, OnCreateBlitPass,(),(override))
MOCK_METHOD(std::shared_ptr< RenderPass >, OnCreateRenderPass,(RenderTarget render_target),(override))
MockCommandBuffer(std::weak_ptr< const Context > context)
Definition mocks.h:109
MOCK_METHOD(fml::Status, Submit,(const std::vector< std::shared_ptr< CommandBuffer > > &buffers, const CompletionCallback &cb),(override))
MOCK_METHOD(bool, SetLabel,(const std::string &label),(override))
MOCK_METHOD(bool, OnCopyHostBuffer,(const uint8_t *source, Range source_range, size_t offset),(override))
MOCK_METHOD(bool, SetLabel,(const std::string &label, Range range),(override))
MOCK_METHOD(uint8_t *, OnGetContents,(),(const, override))
MockDeviceBuffer(const DeviceBufferDescriptor &desc)
Definition mocks.h:24
MOCK_METHOD(std::shared_ptr< PipelineLibrary >, GetPipelineLibrary,(),(const, override))
MOCK_METHOD(std::shared_ptr< ShaderLibrary >, GetShaderLibrary,(),(const, override))
MOCK_METHOD(std::shared_ptr< CommandQueue >, GetCommandQueue,(),(const, override))
MOCK_METHOD(const std::shared_ptr< const Capabilities > &, GetCapabilities,(),(const, override))
MOCK_METHOD(std::shared_ptr< CommandBuffer >, CreateCommandBuffer,(),(const, override))
MOCK_METHOD(std::shared_ptr< SamplerLibrary >, GetSamplerLibrary,(),(const, override))
MOCK_METHOD(std::string, DescribeGpuModel,(),(const, override))
MOCK_METHOD(std::shared_ptr< Allocator >, GetResourceAllocator,(),(const, override))
MOCK_METHOD(bool, IsValid,(),(const, override))
MOCK_METHOD(void, Shutdown,(),(override))
MOCK_METHOD(Context::BackendType, GetBackendType,(),(const, override))
MockRenderPass(std::shared_ptr< const Context > context, const RenderTarget &target)
Definition mocks.h:96
MOCK_METHOD(bool, IsValid,(),(const, override))
MOCK_METHOD(bool, OnEncodeCommands,(const Context &context),(const, override))
MOCK_METHOD(void, OnSetLabel,(std::string label),(override))
MOCK_METHOD(const std::unique_ptr< const Sampler > &, GetSampler,(SamplerDescriptor descriptor),(override))
MockSampler(const SamplerDescriptor &desc)
Definition mocks.h:229
MOCK_METHOD(void, SetLabel,(std::string_view label),(override))
MOCK_METHOD(bool, OnSetContents,(std::shared_ptr< const fml::Mapping > mapping, size_t slice),(override))
MockTexture(const TextureDescriptor &desc)
Definition mocks.h:177
MOCK_METHOD(ISize, GetSize,(),(const, override))
MOCK_METHOD(bool, OnSetContents,(const uint8_t *contents, size_t length, size_t slice),(override))
MOCK_METHOD(bool, IsValid,(),(const, override))
SkBitmap source
Definition examples.cpp:28
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
uint32_t * target
size_t length
FlTexture * texture
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition formats.h:100
Definition ref_ptr.h:256
Point offset
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...