5#ifndef FLUTTER_DISPLAY_LIST_EFFECTS_DL_COLOR_SOURCE_H_
6#define FLUTTER_DISPLAY_LIST_EFFECTS_DL_COLOR_SOURCE_H_
12#include "flutter/display_list/display_list.h"
13#include "flutter/display_list/dl_attributes.h"
14#include "flutter/display_list/dl_color.h"
15#include "flutter/display_list/dl_sampling_options.h"
16#include "flutter/display_list/dl_tile_mode.h"
17#include "flutter/display_list/effects/dl_runtime_effect.h"
18#include "flutter/display_list/image/dl_image.h"
19#include "flutter/fml/logging.h"
23#ifdef IMPELLER_ENABLE_3D
27class DlSceneColorSource;
33class DlColorColorSource;
34class DlImageColorSource;
35class DlLinearGradientColorSource;
36class DlRadialGradientColorSource;
37class DlConicalGradientColorSource;
38class DlSweepGradientColorSource;
39class DlRuntimeEffectColorSource;
59#ifdef IMPELLER_ENABLE_3D
66 static std::shared_ptr<DlLinearGradientColorSource>
MakeLinear(
75 static std::shared_ptr<DlRadialGradientColorSource>
MakeRadial(
84 static std::shared_ptr<DlConicalGradientColorSource>
MakeConical(
95 static std::shared_ptr<DlSweepGradientColorSource>
MakeSweep(
107 std::vector<std::shared_ptr<DlColorSource>> samplers,
108 std::shared_ptr<std::vector<uint8_t>> uniform_data);
168#ifdef IMPELLER_ENABLE_3D
169 virtual const DlSceneColorSource* asScene()
const {
return nullptr; }
185 std::shared_ptr<DlColorSource>
shared()
const override {
186 return std::make_shared<DlColorColorSource>(color_);
192 size_t size()
const override {
return sizeof(*this); }
202 return color_ == that->color_;
215 return matrix_.
isIdentity() ? nullptr : &matrix_;
241 return image_ ? image_->isUIThreadSafe() :
true;
246 std::shared_ptr<DlColorSource>
shared()
const override {
251 return std::make_shared<DlImageColorSource>(image_, horizontal_tile_mode_,
257 size_t size()
const override {
return sizeof(*this); }
259 bool is_opaque()
const override {
return image_->isOpaque(); }
270 return (image_->Equals(that->image_) &&
matrix() == that->matrix() &&
271 horizontal_tile_mode_ == that->horizontal_tile_mode_ &&
272 vertical_tile_mode_ == that->vertical_tile_mode_ &&
273 sampling_ == that->sampling_);
292 for (uint32_t
i = 0;
i < stop_count_;
i++) {
293 if (my_colors[
i].getAlpha() < 255) {
305 return reinterpret_cast<const DlColor*
>(
pod());
320 return stop_count_ * (
sizeof(
DlColor) +
sizeof(
float));
323 virtual const void*
pod()
const = 0;
326 if (mode_ != other_base->mode_ ||
matrix() != other_base->
matrix() ||
327 stop_count_ != other_base->stop_count_) {
330 static_assert(
sizeof(
colors()[0]) == 4);
331 static_assert(
sizeof(
stops()[0]) == 4);
332 int num_bytes = stop_count_ * 4;
333 return (memcmp(
colors(), other_base->
colors(), num_bytes) == 0 &&
334 memcmp(
stops(), other_base->
stops(), num_bytes) == 0);
339 const float* stop_data) {
341 memcpy(color_storage, color_data, stop_count_ *
sizeof(*color_data));
342 float* stop_storage =
reinterpret_cast<float*
>(color_storage + stop_count_);
344 memcpy(stop_storage, stop_data, stop_count_ *
sizeof(*stop_data));
346 float div = stop_count_ - 1;
350 for (uint32_t
i = 0;
i < stop_count_;
i++) {
351 stop_storage[
i] =
i / div;
358 uint32_t stop_count_;
376 std::shared_ptr<DlColorSource>
shared()
const override {
385 virtual const void*
pod()
const override {
return this + 1; }
390 return (start_point_ == that->start_point_ &&
408 explicit DlLinearGradientColorSource(
409 const DlLinearGradientColorSource*
source)
435 std::shared_ptr<DlColorSource>
shared()
const override {
449 virtual const void*
pod()
const override {
return this + 1; }
454 return (center_ == that->center_ && radius_ == that->radius_ &&
472 explicit DlRadialGradientColorSource(
473 const DlRadialGradientColorSource*
source)
499 std::shared_ptr<DlColorSource>
shared()
const override {
500 return MakeConical(start_center_, start_radius_, end_center_, end_radius_,
516 virtual const void*
pod()
const override {
return this + 1; }
521 return (start_center_ == that->start_center_ &&
522 start_radius_ == that->start_radius_ &&
523 end_center_ == that->end_center_ &&
524 end_radius_ == that->end_radius_ &&
base_equals_(that));
545 explicit DlConicalGradientColorSource(
546 const DlConicalGradientColorSource*
source)
576 std::shared_ptr<DlColorSource>
shared()
const override {
591 virtual const void*
pod()
const override {
return this + 1; }
596 return (center_ == that->center_ && start_ == that->start_ &&
616 explicit DlSweepGradientColorSource(
const DlSweepGradientColorSource*
source)
640 std::vector<std::shared_ptr<DlColorSource>>
samplers,
647 for (
const auto& sampler : samplers_) {
648 if (!sampler->isUIThreadSafe()) {
659 std::shared_ptr<DlColorSource>
shared()
const override {
660 return std::make_shared<DlRuntimeEffectColorSource>(
661 runtime_effect_, samplers_, uniform_data_);
667 size_t size()
const override {
return sizeof(*this); }
672 return runtime_effect_;
674 const std::vector<std::shared_ptr<DlColorSource>>
samplers()
const {
678 return uniform_data_;
685 if (runtime_effect_ != that->runtime_effect_) {
688 if (uniform_data_ != that->uniform_data_) {
691 if (samplers_.size() != that->samplers_.size()) {
694 for (
size_t i = 0;
i < samplers_.size();
i++) {
695 if (samplers_[
i] != that->samplers_[
i]) {
704 std::vector<std::shared_ptr<DlColorSource>> samplers_;
705 std::shared_ptr<std::vector<uint8_t>> uniform_data_;
710#ifdef IMPELLER_ENABLE_3D
711class DlSceneColorSource final :
public DlColorSource {
713 DlSceneColorSource(std::shared_ptr<impeller::scene::Node> node,
715 : node_(
std::move(node)), camera_matrix_(camera_matrix) {}
717 bool isUIThreadSafe()
const override {
return true; }
719 const DlSceneColorSource* asScene()
const override {
return this; }
721 std::shared_ptr<DlColorSource> shared()
const override {
722 return std::make_shared<DlSceneColorSource>(node_, camera_matrix_);
726 size_t size()
const override {
return sizeof(*this); }
728 bool is_opaque()
const override {
return false; }
730 std::shared_ptr<impeller::scene::Node> scene_node()
const {
return node_; }
735 bool equals_(DlColorSource
const& other)
const override {
736 FML_DCHECK(other.type() == DlColorSourceType::kScene);
737 auto that =
static_cast<DlSceneColorSource const*
>(&other);
738 if (node_ != that->node_) {
745 std::shared_ptr<impeller::scene::Node> node_;
@ kColor
hue and saturation of source with luminosity of destination
virtual T type() const =0
bool equals_(DlColorSource const &other) const override
bool isUIThreadSafe() const override
If the underlying platform data held by this object is held in a way that it can be stored and potent...
DlColorColorSource(DlColor color)
DlColorSourceType type() const override
const DlColorColorSource * asColor() const override
std::shared_ptr< DlColorSource > shared() const override
size_t size() const override
bool is_opaque() const override
virtual const DlRuntimeEffectColorSource * asRuntimeEffect() const
static std::shared_ptr< DlConicalGradientColorSource > MakeConical(SkPoint start_center, SkScalar start_radius, SkPoint end_center, SkScalar end_radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
virtual bool isUIThreadSafe() const =0
If the underlying platform data held by this object is held in a way that it can be stored and potent...
static std::shared_ptr< DlRuntimeEffectColorSource > MakeRuntimeEffect(sk_sp< DlRuntimeEffect > runtime_effect, std::vector< std::shared_ptr< DlColorSource > > samplers, std::shared_ptr< std::vector< uint8_t > > uniform_data)
virtual const DlRadialGradientColorSource * asRadialGradient() const
static std::shared_ptr< DlLinearGradientColorSource > MakeLinear(const SkPoint start_point, const SkPoint end_point, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
static std::shared_ptr< DlSweepGradientColorSource > MakeSweep(SkPoint center, SkScalar start, SkScalar end, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
virtual const DlLinearGradientColorSource * asLinearGradient() const
virtual const DlImageColorSource * asImage() const
virtual bool is_opaque() const =0
virtual const DlColorColorSource * asColor() const
virtual const DlSweepGradientColorSource * asSweepGradient() const
virtual bool isGradient() const
If the underlying platform data represents a gradient.
virtual const DlConicalGradientColorSource * asConicalGradient() const
static std::shared_ptr< DlRadialGradientColorSource > MakeRadial(SkPoint center, SkScalar radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
std::shared_ptr< DlColorSource > shared() const override
SkScalar end_radius() const
bool equals_(DlColorSource const &other) const override
SkPoint end_center() const
bool isUIThreadSafe() const override
If the underlying platform data held by this object is held in a way that it can be stored and potent...
const DlConicalGradientColorSource * asConicalGradient() const override
SkPoint start_center() const
virtual const void * pod() const override
size_t size() const override
DlColorSourceType type() const override
SkScalar start_radius() const
void store_color_stops(void *pod, const DlColor *color_data, const float *stop_data)
DlGradientColorSourceBase(uint32_t stop_count, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
DlTileMode tile_mode() const
bool is_opaque() const override
const DlColor * colors() const
const float * stops() const
bool isGradient() const override
If the underlying platform data represents a gradient.
bool base_equals_(DlGradientColorSourceBase const *other_base) const
virtual const void * pod() const =0
size_t vector_sizes() const
DlImageColorSource(sk_sp< const DlImage > image, DlTileMode horizontal_tile_mode, DlTileMode vertical_tile_mode, DlImageSampling sampling=DlImageSampling::kLinear, const SkMatrix *matrix=nullptr)
bool equals_(DlColorSource const &other) const override
std::shared_ptr< DlColorSource > shared() const override
bool isUIThreadSafe() const override
If the underlying platform data held by this object is held in a way that it can be stored and potent...
DlImageSampling sampling() const
size_t size() const override
std::shared_ptr< DlColorSource > with_sampling(DlImageSampling sampling) const
DlColorSourceType type() const override
bool is_opaque() const override
DlTileMode vertical_tile_mode() const
const DlImageColorSource * asImage() const override
DlTileMode horizontal_tile_mode() const
sk_sp< const DlImage > image() const
size_t size() const override
const SkPoint & start_point() const
virtual const void * pod() const override
bool isUIThreadSafe() const override
If the underlying platform data held by this object is held in a way that it can be stored and potent...
const DlLinearGradientColorSource * asLinearGradient() const override
DlColorSourceType type() const override
std::shared_ptr< DlColorSource > shared() const override
bool equals_(DlColorSource const &other) const override
const SkPoint & end_point() const
const SkMatrix * matrix_ptr() const
const SkMatrix & matrix() const
DlMatrixColorSourceBase(const SkMatrix *matrix)
DlColorSourceType type() const override
std::shared_ptr< DlColorSource > shared() const override
bool equals_(DlColorSource const &other) const override
size_t size() const override
bool isUIThreadSafe() const override
If the underlying platform data held by this object is held in a way that it can be stored and potent...
virtual const void * pod() const override
const DlRadialGradientColorSource * asRadialGradient() const override
std::shared_ptr< DlColorSource > shared() const override
DlRuntimeEffectColorSource(sk_sp< DlRuntimeEffect > runtime_effect, std::vector< std::shared_ptr< DlColorSource > > samplers, std::shared_ptr< std::vector< uint8_t > > uniform_data)
bool is_opaque() const override
bool isUIThreadSafe() const override
If the underlying platform data held by this object is held in a way that it can be stored and potent...
const std::shared_ptr< std::vector< uint8_t > > uniform_data() const
const DlRuntimeEffectColorSource * asRuntimeEffect() const override
DlColorSourceType type() const override
bool equals_(DlColorSource const &other) const override
const sk_sp< DlRuntimeEffect > runtime_effect() const
const std::vector< std::shared_ptr< DlColorSource > > samplers() const
size_t size() const override
virtual const void * pod() const override
DlColorSourceType type() const override
bool equals_(DlColorSource const &other) const override
bool isUIThreadSafe() const override
If the underlying platform data held by this object is held in a way that it can be stored and potent...
size_t size() const override
std::shared_ptr< DlColorSource > shared() const override
const DlSweepGradientColorSource * asSweepGradient() const override
#define FML_DCHECK(condition)
#define FML_DISALLOW_COPY_ASSIGN_AND_MOVE(TypeName)
unsigned useCenter Optional< SkMatrix > matrix
PODArray< SkColor > colors
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
constexpr int getAlpha() const
A 4x4 matrix using column-major storage.