| Flutter Impeller |

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
5 #include "impeller/renderer/texture_util.h"
6 #include "impeller/renderer/blit_pass.h"
7 #include "impeller/renderer/command_buffer.h"
8
9 namespace impeller {
10
11 std::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
37 fml::Status AddMipmapGeneration(
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) {
44 return fml::Status(fml::StatusCode::kUnknown, "");
45 }
46 success = blit_pass->EncodeCommands();
47 if (!success) {
48 return fml::Status(fml::StatusCode::kUnknown, "");
49 }
50 return fml::Status();
51 }
52
53 } // namespace impeller
blit_pass.h
impeller::DeviceBuffer::AsBufferView
static BufferView AsBufferView(std::shared_ptr< DeviceBuffer > buffer)
Create a buffer view of this entire buffer.
Definition: device_buffer.cc:18
command_buffer.h
impeller
Definition: allocation.cc:12
impeller::AddMipmapGeneration
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.
Definition: texture_util.cc:37
impeller::CreateTexture
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)
Definition: texture_util.cc:11
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:38
data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:67
texture_util.h