7 #include "flutter/fml/logging.h"
18 const std::shared_ptr<impeller::Context>& context) {
20 FML_DLOG(ERROR) <<
"Invalid gradient data.";
29 context->GetResourceAllocator()->CreateTexture(texture_descriptor);
31 FML_DLOG(ERROR) <<
"Could not create Impeller texture.";
36 std::make_shared<fml::DataMapping>(gradient_data.
color_bytes);
38 context->GetResourceAllocator()->CreateBufferWithCopy(*data_mapping);
40 auto cmd_buffer = context->CreateCommandBuffer();
41 auto blit_pass = cmd_buffer->CreateBlitPass();
44 if (!blit_pass->EncodeCommands() ||
45 !context->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok()) {
54 const std::vector<Scalar>& stops) {
55 FML_DCHECK(stops.size() == colors.size());
57 std::vector<StopData> result;
58 result.reserve(stops.size());
60 for (
auto i = 0u; i < stops.size(); i++) {
61 Scalar delta = stops[i] - last_stop;
62 Scalar inverse_delta = delta == 0.0f ? 0.0 : 1.0 / delta;
64 .
color = colors[i], .stop = stops[i], .inverse_delta = inverse_delta});
71 const std::vector<Color>& colors,
72 const std::vector<Scalar>& stops,
75 FML_DCHECK(stops.size() == colors.size());
80 Scalar cur_stop = stops[i];
81 Scalar delta = cur_stop - last_stop;
82 Scalar inverse_delta = delta == 0.0f ? 0.0 : 1.0 / delta;
83 frag_info_colors[index] = colors[i];
85 frag_info_stop_pairs[index / 2].x = cur_stop;
86 frag_info_stop_pairs[index / 2].y = inverse_delta;
88 frag_info_stop_pairs[index / 2].z = cur_stop;
89 frag_info_stop_pairs[index / 2].w = inverse_delta;
static BufferView AsBufferView(std::shared_ptr< DeviceBuffer > buffer)
Create a buffer view of this entire buffer.
std::string SPrintF(const char *format,...)
int PopulateUniformGradientColors(const std::vector< Color > &colors, const std::vector< Scalar > &stops, Vector4 frag_info_colors[kMaxUniformGradientStops], Vector4 frag_info_stop_pairs[kMaxUniformGradientStops/2])
Populate 2 arrays with the colors and stop data for a gradient.
std::vector< StopData > CreateGradientColors(const std::vector< Color > &colors, const std::vector< Scalar > &stops)
Populate a vector with the color and stop data for a gradient.
std::shared_ptr< Texture > CreateGradientTexture(const GradientData &gradient_data, const std::shared_ptr< impeller::Context > &context)
Create a host visible texture that contains the gradient defined by the provided gradient data.
static constexpr uint32_t kMaxUniformGradientStops
std::vector< uint8_t > color_bytes
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...