Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
context_spy.cc
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#include <memory>
8
10
11namespace impeller {
12namespace testing {
13
15 const std::vector<std::shared_ptr<CommandBuffer>>& buffers,
16 const CompletionCallback& completion_callback) {
17 if (completion_callback) {
18 completion_callback(CommandBuffer::Status::kCompleted);
19 }
20 return fml::Status();
21}
22
23std::shared_ptr<ContextSpy> ContextSpy::Make() {
24 return std::shared_ptr<ContextSpy>(new ContextSpy());
25}
26
27std::shared_ptr<ContextMock> ContextSpy::MakeContext(
28 const std::shared_ptr<Context>& real_context) {
29 std::shared_ptr<ContextMock> mock_context =
30 std::make_shared<::testing::NiceMock<ContextMock>>();
31 std::shared_ptr<ContextSpy> shared_this = shared_from_this();
32
33 ON_CALL(*mock_context, IsValid).WillByDefault([real_context]() {
34 return real_context->IsValid();
35 });
36
37 ON_CALL(*mock_context, GetBackendType)
38 .WillByDefault([real_context]() -> Context::BackendType {
39 return real_context->GetBackendType();
40 });
41
42 ON_CALL(*mock_context, GetCapabilities)
43 .WillByDefault(
44 [real_context]() -> const std::shared_ptr<const Capabilities>& {
45 return real_context->GetCapabilities();
46 });
47
48 ON_CALL(*mock_context, UpdateOffscreenLayerPixelFormat)
49 .WillByDefault([real_context](PixelFormat format) {
50 return real_context->UpdateOffscreenLayerPixelFormat(format);
51 });
52
53 ON_CALL(*mock_context, GetResourceAllocator).WillByDefault([real_context]() {
54 return real_context->GetResourceAllocator();
55 });
56
57 ON_CALL(*mock_context, GetShaderLibrary).WillByDefault([real_context]() {
58 return real_context->GetShaderLibrary();
59 });
60
61 ON_CALL(*mock_context, GetSamplerLibrary).WillByDefault([real_context]() {
62 return real_context->GetSamplerLibrary();
63 });
64
65 ON_CALL(*mock_context, GetPipelineLibrary).WillByDefault([real_context]() {
66 return real_context->GetPipelineLibrary();
67 });
68
69 ON_CALL(*mock_context, GetCommandQueue).WillByDefault([shared_this]() {
70 return shared_this->command_queue_;
71 });
72
74 .WillByDefault([real_context, shared_this]() {
75 auto real_buffer = real_context->CreateCommandBuffer();
76 auto spy = std::make_shared<::testing::NiceMock<CommandBufferMock>>(
77 real_context);
78
79 ON_CALL(*spy, IsValid).WillByDefault([real_buffer]() {
80 return real_buffer->IsValid();
81 });
82
83 ON_CALL(*spy, SetLabel)
84 .WillByDefault([real_buffer](const std::string& label) {
85 return real_buffer->SetLabel(label);
86 });
87
88 ON_CALL(*spy, OnCreateRenderPass)
89 .WillByDefault([real_buffer, shared_this,
90 real_context](const RenderTarget& render_target) {
91 std::shared_ptr<RenderPass> result =
93 real_buffer.get(), render_target);
94 std::shared_ptr<RecordingRenderPass> recorder =
95 std::make_shared<RecordingRenderPass>(result, real_context,
96 render_target);
97 shared_this->render_passes_.push_back(recorder);
98 return recorder;
99 });
100
101 ON_CALL(*spy, OnCreateBlitPass).WillByDefault([real_buffer]() {
102 return CommandBufferMock::ForwardOnCreateBlitPass(real_buffer.get());
103 });
104
105 ON_CALL(*spy, OnSubmitCommands)
106 .WillByDefault(
109 real_buffer.get(), std::move(callback));
110 });
111
112 ON_CALL(*spy, OnWaitUntilScheduled).WillByDefault([real_buffer]() {
114 real_buffer.get());
115 });
116
117 ON_CALL(*spy, OnCreateComputePass).WillByDefault([real_buffer]() {
119 real_buffer.get());
120 });
121
122 return spy;
123 });
124
125 return mock_context;
126}
127
128} // namespace testing
129
130} // namespace impeller
std::function< void(Status)> CompletionCallback
std::function< void(CommandBuffer::Status)> CompletionCallback
static std::shared_ptr< BlitPass > ForwardOnCreateBlitPass(CommandBuffer *command_buffer)
static std::shared_ptr< RenderPass > ForwardOnCreateRenderPass(CommandBuffer *command_buffer, const RenderTarget &render_target)
static std::shared_ptr< ComputePass > ForwardOnCreateComputePass(CommandBuffer *command_buffer)
static bool ForwardOnSubmitCommands(CommandBuffer *command_buffer, CompletionCallback callback)
static void ForwardOnWaitUntilScheduled(CommandBuffer *command_buffer)
static std::shared_ptr< ContextSpy > Make()
std::shared_ptr< ContextMock > MakeContext(const std::shared_ptr< Context > &real_context)
fml::Status Submit(const std::vector< std::shared_ptr< CommandBuffer > > &buffers, const CompletionCallback &completion_callback={}) override
Submit one or more command buffer objects to be encoded and executed on the GPU.
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
GAsyncResult * result
uint32_t uint32_t * format
static MockContext mock_context
Definition mock_epoxy.cc:51
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition formats.h:100
static id< MTLCommandBuffer > CreateCommandBuffer(id< MTLCommandQueue > queue)