Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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"
21
22#define FLT_FORWARD(mock, real, method) \
23 EXPECT_CALL(*mock, method()) \
24 .WillRepeatedly(::testing::Return(real->method()));
25
26namespace impeller {
27namespace testing {
28
30 public:
32 : DeviceBuffer(desc) {}
33
34 MOCK_METHOD(bool, SetLabel, (std::string_view label), (override));
35
38 (std::string_view label, Range range),
39 (override));
40
41 MOCK_METHOD(uint8_t*, OnGetContents, (), (const, override));
42
45 (const uint8_t* source, Range source_range, size_t offset),
46 (override));
47};
48
49class MockAllocator : public Allocator {
50 public:
52 MOCK_METHOD(std::shared_ptr<DeviceBuffer>,
54 (const DeviceBufferDescriptor& desc),
55 (override));
56 MOCK_METHOD(std::shared_ptr<Texture>,
58 (const TextureDescriptor& desc, bool threadsafe),
59 (override));
60};
61
62class MockBlitPass : public BlitPass {
63 public:
64 MOCK_METHOD(bool, IsValid, (), (const, override));
65 MOCK_METHOD(bool, EncodeCommands, (), (const, override));
66 MOCK_METHOD(void, OnSetLabel, (std::string_view label), (override));
67
70 (const std::shared_ptr<Texture>& source,
71 const std::shared_ptr<Texture>& destination),
72 (override));
73
76 (std::shared_ptr<Texture> source,
77 std::shared_ptr<Texture> destination,
78 IRect source_region,
79 IPoint destination_origin,
80 std::string_view label),
81 (override));
82
85 (std::shared_ptr<Texture> source,
86 std::shared_ptr<DeviceBuffer> destination,
87 IRect source_region,
88 size_t destination_offset,
89 std::string_view label),
90 (override));
93 (BufferView source,
94 std::shared_ptr<Texture> destination,
95 IRect destination_rect,
96 std::string_view label,
97 uint32_t mip_level,
98 uint32_t slice,
99 bool convert_to_read),
100 (override));
103 (std::shared_ptr<Texture> texture, std::string_view label),
104 (override));
105};
106
108 public:
109 MockRenderPass(std::shared_ptr<const Context> context,
110 const RenderTarget& target)
111 : RenderPass(std::move(context), target) {}
112 MOCK_METHOD(bool, IsValid, (), (const, override));
115 (const Context& context),
116 (const, override));
117 MOCK_METHOD(void, OnSetLabel, (std::string_view label), (override));
118};
119
121 public:
122 MOCK_METHOD(bool, IsValid, (), (const, override));
125 (PipelineDescriptor descriptor, bool async, bool threadsafe),
126 (override));
129 (ComputePipelineDescriptor descriptor, bool async),
130 (override));
133 (const PipelineDescriptor& descriptor),
134 (override));
137 (std::shared_ptr<const ShaderFunction> function),
138 (override));
139};
140
141class MockCommandBuffer : public CommandBuffer {
142 public:
143 explicit MockCommandBuffer(std::weak_ptr<const Context> context)
144 : CommandBuffer(std::move(context)) {}
145 MOCK_METHOD(bool, IsValid, (), (const, override));
146 MOCK_METHOD(void, SetLabel, (std::string_view label), (const, override));
147 MOCK_METHOD(std::shared_ptr<BlitPass>, OnCreateBlitPass, (), (override));
149 OnSubmitCommands,
150 (bool block_on_schedule, CompletionCallback callback),
151 (override));
152 MOCK_METHOD(void, OnWaitUntilCompleted, (), (override));
153 MOCK_METHOD(void, OnWaitUntilScheduled, (), (override));
154 MOCK_METHOD(std::shared_ptr<ComputePass>,
155 OnCreateComputePass,
156 (),
157 (override));
158 MOCK_METHOD(std::shared_ptr<RenderPass>,
159 OnCreateRenderPass,
160 (RenderTarget render_target),
161 (override));
162};
163
165 public:
167
169
170 MOCK_METHOD(std::string, DescribeGpuModel, (), (const, override));
171
172 MOCK_METHOD(bool, IsValid, (), (const, override));
173
174 MOCK_METHOD(void, Shutdown, (), (override));
175
176 MOCK_METHOD(std::shared_ptr<Allocator>,
178 (),
179 (const, override));
180
181 MOCK_METHOD(std::shared_ptr<ShaderLibrary>,
183 (),
184 (const, override));
185
186 MOCK_METHOD(std::shared_ptr<SamplerLibrary>,
188 (),
189 (const, override));
190
191 MOCK_METHOD(std::shared_ptr<PipelineLibrary>,
193 (),
194 (const, override));
195
196 MOCK_METHOD(std::shared_ptr<CommandBuffer>,
198 (),
199 (const, override));
200
201 MOCK_METHOD(const std::shared_ptr<const Capabilities>&,
203 (),
204 (const, override));
205
206 MOCK_METHOD(std::shared_ptr<CommandQueue>,
208 (),
209 (const, override));
210
213 (),
214 (const, override));
215};
216
217class MockTexture : public Texture {
218 public:
219 explicit MockTexture(const TextureDescriptor& desc) : Texture(desc) {}
220 MOCK_METHOD(void, SetLabel, (std::string_view label), (override));
222 SetLabel,
223 (std::string_view label, std::string_view trailing),
224 (override));
225 MOCK_METHOD(bool, IsValid, (), (const, override));
226 MOCK_METHOD(ISize, GetSize, (), (const, override));
228 OnSetContents,
229 (const uint8_t* contents, size_t length, size_t slice),
230 (override));
232 OnSetContents,
233 (std::shared_ptr<const fml::Mapping> mapping, size_t slice),
234 (override));
235};
236
238 public:
239 MOCK_METHOD(bool, SupportsOffscreenMSAA, (), (const, override));
240 MOCK_METHOD(bool, SupportsImplicitResolvingMSAA, (), (const, override));
241 MOCK_METHOD(bool, SupportsSSBO, (), (const, override));
242 MOCK_METHOD(bool, SupportsTextureToTextureBlits, (), (const, override));
243 MOCK_METHOD(bool, SupportsFramebufferFetch, (), (const, override));
244 MOCK_METHOD(bool, SupportsCompute, (), (const, override));
245 MOCK_METHOD(bool, SupportsComputeSubgroups, (), (const, override));
246 MOCK_METHOD(bool, SupportsReadFromResolve, (), (const, override));
247 MOCK_METHOD(bool, SupportsDecalSamplerAddressMode, (), (const, override));
248 MOCK_METHOD(bool, SupportsDeviceTransientTextures, (), (const, override));
249 MOCK_METHOD(bool, SupportsTriangleFan, (), (const override));
250 MOCK_METHOD(bool, SupportsPrimitiveRestart, (), (const override));
251 MOCK_METHOD(bool, Supports32BitPrimitiveIndices, (), (const override));
252 MOCK_METHOD(bool, SupportsExtendedRangeFormats, (), (const override));
258 MOCK_METHOD(size_t, GetMinimumUniformAlignment, (), (const override));
259 MOCK_METHOD(bool, NeedsPartitionedHostBuffer, (), (const, override));
260};
261
263 public:
265 Submit,
266 (const std::vector<std::shared_ptr<CommandBuffer>>& buffers,
267 const CompletionCallback& cb,
268 bool block_on_schedule),
269 (override));
270};
271
273 public:
276 (const SamplerDescriptor& descriptor),
277 (override));
278};
279
280class MockSampler : public Sampler {
281 public:
282 explicit MockSampler(const SamplerDescriptor& desc) : Sampler(desc) {}
283};
284
285} // namespace testing
286} // namespace impeller
287
288#endif // FLUTTER_IMPELLER_RENDERER_TESTING_MOCKS_H_
An object that allocates device memory.
Definition allocator.h:24
virtual std::shared_ptr< Texture > OnCreateTexture(const TextureDescriptor &desc, bool threadsafe=false)=0
virtual ISize GetMaxTextureSizeSupported() const =0
virtual std::shared_ptr< DeviceBuffer > OnCreateBuffer(const DeviceBufferDescriptor &desc)=0
Blit passes encode blit into the underlying command buffer.
Definition blit_pass.h:27
virtual bool EncodeCommands() const =0
Encode the recorded commands to the underlying command buffer.
virtual bool ResizeTexture(const std::shared_ptr< Texture > &source, const std::shared_ptr< Texture > &destination)=0
Resize the [source] texture into the [destination] texture.
virtual bool OnCopyTextureToTextureCommand(std::shared_ptr< Texture > source, std::shared_ptr< Texture > destination, IRect source_region, IPoint destination_origin, std::string_view label)=0
virtual bool OnGenerateMipmapCommand(std::shared_ptr< Texture > texture, std::string_view label)=0
virtual bool IsValid() const =0
virtual bool OnCopyBufferToTextureCommand(BufferView source, std::shared_ptr< Texture > destination, IRect destination_region, std::string_view label, uint32_t mip_level, uint32_t slice, bool convert_to_read)=0
virtual bool OnCopyTextureToBufferCommand(std::shared_ptr< Texture > source, std::shared_ptr< DeviceBuffer > destination, IRect source_region, size_t destination_offset, std::string_view label)=0
virtual void OnSetLabel(std::string_view label)=0
virtual PixelFormat GetDefaultStencilFormat() const =0
Returns a supported PixelFormat for textures that store stencil information. May include a depth chan...
virtual size_t GetMinimumUniformAlignment() const =0
The minimum alignment of uniform value offsets in bytes.
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 SupportsTriangleFan() const =0
Whether the primitive type TriangleFan is supported by the backend.
virtual bool SupportsComputeSubgroups() const =0
Whether the context backend supports configuring ComputePass command subgroups.
virtual bool NeedsPartitionedHostBuffer() const =0
Whether the host buffer should use separate device buffers for indexes from other data.
virtual bool Supports32BitPrimitiveIndices() const =0
Whether 32-bit values are supported in index buffers used to draw primitives.
virtual PixelFormat GetDefaultGlyphAtlasFormat() const =0
Returns the default pixel format for the alpha bitmap glyph atlas.
virtual bool SupportsPrimitiveRestart() const =0
Whether primitive restart is supported.
virtual PixelFormat GetDefaultColorFormat() const =0
Returns a supported PixelFormat for textures that store 4-channel colors (red/green/blue/alpha).
virtual ISize GetMaximumRenderPassAttachmentSize() const =0
Return the maximum size of a render pass attachment.
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 SupportsExtendedRangeFormats() const =0
Whether the XR formats are supported on this device.
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={}, bool block_on_schedule=false)
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:65
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 RuntimeStageBackend GetRuntimeStageBackend() const =0
Retrieve the runtime stage for this context type.
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(std::string_view label)=0
virtual bool OnCopyHostBuffer(const uint8_t *source, Range source_range, size_t offset)=0
virtual bool HasPipeline(const PipelineDescriptor &descriptor)=0
virtual void RemovePipelinesWithEntryPoint(std::shared_ptr< const ShaderFunction > function)=0
virtual bool IsValid() const =0
PipelineFuture< PipelineDescriptor > GetPipeline(std::optional< PipelineDescriptor > descriptor, bool async=true)
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition render_pass.h:30
virtual bool OnEncodeCommands(const Context &context) const =0
virtual void OnSetLabel(std::string_view label)=0
virtual bool IsValid() const =0
virtual raw_ptr< const Sampler > GetSampler(const SamplerDescriptor &descriptor)=0
Retrieve a backend specific sampler object for the given sampler descriptor.
A wrapper around a raw ptr that adds additional unopt mode only checks.
Definition raw_ptr.h:15
MOCK_METHOD(ISize, GetMaxTextureSizeSupported,(),(const, override))
MOCK_METHOD(std::shared_ptr< Texture >, OnCreateTexture,(const TextureDescriptor &desc, bool threadsafe),(override))
MOCK_METHOD(std::shared_ptr< DeviceBuffer >, OnCreateBuffer,(const DeviceBufferDescriptor &desc),(override))
MOCK_METHOD(bool, OnCopyBufferToTextureCommand,(BufferView source, std::shared_ptr< Texture > destination, IRect destination_rect, std::string_view label, uint32_t mip_level, uint32_t slice, bool convert_to_read),(override))
MOCK_METHOD(bool, OnCopyTextureToBufferCommand,(std::shared_ptr< Texture > source, std::shared_ptr< DeviceBuffer > destination, IRect source_region, size_t destination_offset, std::string_view label),(override))
MOCK_METHOD(bool, EncodeCommands,(),(const, override))
MOCK_METHOD(bool, OnGenerateMipmapCommand,(std::shared_ptr< Texture > texture, std::string_view label),(override))
MOCK_METHOD(bool, ResizeTexture,(const std::shared_ptr< Texture > &source, const std::shared_ptr< Texture > &destination),(override))
MOCK_METHOD(void, OnSetLabel,(std::string_view label),(override))
MOCK_METHOD(bool, IsValid,(),(const, override))
MOCK_METHOD(bool, OnCopyTextureToTextureCommand,(std::shared_ptr< Texture > source, std::shared_ptr< Texture > destination, IRect source_region, IPoint destination_origin, std::string_view label),(override))
MOCK_METHOD(bool, Supports32BitPrimitiveIndices,(),(const override))
MOCK_METHOD(bool, SupportsDecalSamplerAddressMode,(),(const, override))
MOCK_METHOD(bool, SupportsOffscreenMSAA,(),(const, override))
MOCK_METHOD(PixelFormat, GetDefaultGlyphAtlasFormat,(),(const, override))
MOCK_METHOD(bool, NeedsPartitionedHostBuffer,(),(const, override))
MOCK_METHOD(bool, SupportsPrimitiveRestart,(),(const override))
MOCK_METHOD(bool, SupportsFramebufferFetch,(),(const, override))
MOCK_METHOD(bool, SupportsSSBO,(),(const, override))
MOCK_METHOD(size_t, GetMinimumUniformAlignment,(),(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(ISize, GetMaximumRenderPassAttachmentSize,(),(const override))
MOCK_METHOD(PixelFormat, GetDefaultColorFormat,(),(const, override))
MOCK_METHOD(bool, SupportsExtendedRangeFormats,(),(const override))
MOCK_METHOD(bool, SupportsTriangleFan,(),(const override))
MOCK_METHOD(bool, SupportsCompute,(),(const, override))
MOCK_METHOD(void, OnWaitUntilScheduled,(),(override))
MOCK_METHOD(void, SetLabel,(std::string_view label),(const, override))
MOCK_METHOD(void, OnWaitUntilCompleted,(),(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(bool, OnSubmitCommands,(bool block_on_schedule, CompletionCallback callback),(override))
MOCK_METHOD(std::shared_ptr< RenderPass >, OnCreateRenderPass,(RenderTarget render_target),(override))
MockCommandBuffer(std::weak_ptr< const Context > context)
Definition mocks.h:143
MOCK_METHOD(fml::Status, Submit,(const std::vector< std::shared_ptr< CommandBuffer > > &buffers, const CompletionCallback &cb, bool block_on_schedule),(override))
MOCK_METHOD(bool, OnCopyHostBuffer,(const uint8_t *source, Range source_range, size_t offset),(override))
MOCK_METHOD(uint8_t *, OnGetContents,(),(const, override))
MOCK_METHOD(bool, SetLabel,(std::string_view label, Range range),(override))
MockDeviceBuffer(const DeviceBufferDescriptor &desc)
Definition mocks.h:31
MOCK_METHOD(bool, SetLabel,(std::string_view label),(override))
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))
MOCK_METHOD(RuntimeStageBackend, GetRuntimeStageBackend,(),(const, override))
MOCK_METHOD(PipelineFuture< PipelineDescriptor >, GetPipeline,(PipelineDescriptor descriptor, bool async, bool threadsafe),(override))
MOCK_METHOD(void, RemovePipelinesWithEntryPoint,(std::shared_ptr< const ShaderFunction > function),(override))
MOCK_METHOD(bool, HasPipeline,(const PipelineDescriptor &descriptor),(override))
MOCK_METHOD(PipelineFuture< ComputePipelineDescriptor >, GetPipeline,(ComputePipelineDescriptor descriptor, bool async),(override))
MOCK_METHOD(bool, IsValid,(),(const, override))
MockRenderPass(std::shared_ptr< const Context > context, const RenderTarget &target)
Definition mocks.h:109
MOCK_METHOD(void, OnSetLabel,(std::string_view label),(override))
MOCK_METHOD(bool, IsValid,(),(const, override))
MOCK_METHOD(bool, OnEncodeCommands,(const Context &context),(const, override))
MockSampler(const SamplerDescriptor &desc)
Definition mocks.h:282
MOCK_METHOD(raw_ptr< const Sampler >, GetSampler,(const SamplerDescriptor &descriptor),(override))
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:219
MOCK_METHOD(ISize, GetSize,(),(const, override))
MOCK_METHOD(void, SetLabel,(std::string_view label, std::string_view trailing),(override))
MOCK_METHOD(bool, OnSetContents,(const uint8_t *contents, size_t length, size_t slice),(override))
MOCK_METHOD(bool, IsValid,(),(const, override))
uint32_t * target
FlutterDesktopBinaryReply callback
size_t length
FlTexture * texture
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition formats.h:99
Definition ref_ptr.h:261
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...