Flutter Engine
 
Loading...
Searching...
No Matches
texture_util.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
8
9namespace impeller {
10
11std::shared_ptr<Texture> CreateTexture(
12 const TextureDescriptor& texture_descriptor,
13 const std::vector<uint8_t>& data,
14 const std::shared_ptr<impeller::Context>& context,
15 std::string_view debug_label) {
16 std::shared_ptr<Texture> texture =
17 context->GetResourceAllocator()->CreateTexture(texture_descriptor);
18
19 auto data_mapping =
20 std::make_shared<fml::NonOwnedMapping>(data.data(), data.size());
21 std::shared_ptr<DeviceBuffer> buffer =
22 context->GetResourceAllocator()->CreateBufferWithCopy(*data_mapping);
23
24 std::shared_ptr<CommandBuffer> cmd_buffer = context->CreateCommandBuffer();
25 std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
26 blit_pass->AddCopy(DeviceBuffer::AsBufferView(std::move(buffer)), texture);
27
28 if (!blit_pass->EncodeCommands() ||
29 !context->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok()) {
30 return nullptr;
31 }
32
33 texture->SetLabel(debug_label);
34 return texture;
35}
36
38 const std::shared_ptr<CommandBuffer>& command_buffer,
39 const std::shared_ptr<Context>& context,
40 const std::shared_ptr<Texture>& texture) {
41 std::shared_ptr<BlitPass> blit_pass = command_buffer->CreateBlitPass();
42 bool success = blit_pass->GenerateMipmap(texture);
43 if (!success) {
45 }
46 success = blit_pass->EncodeCommands();
47 if (!success) {
49 }
50 return fml::Status();
51}
52
53} // namespace impeller
static BufferView AsBufferView(std::shared_ptr< DeviceBuffer > buffer)
Create a buffer view of this entire buffer.
FlTexture * texture
fml::Status AddMipmapGeneration(const std::shared_ptr< CommandBuffer > &command_buffer, const std::shared_ptr< Context > &context, const std::shared_ptr< Texture > &texture)
Adds a blit command to the render pass.
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &texture_descriptor, const std::vector< uint8_t > &data, const std::shared_ptr< impeller::Context > &context, std::string_view debug_label)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
std::shared_ptr< const fml::Mapping > data