Flutter Engine
The Flutter Engine
dl_color_source.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 "flutter/display_list/effects/dl_color_source.h"
6
7#include "flutter/display_list/dl_sampling_options.h"
8#include "flutter/display_list/effects/dl_runtime_effect.h"
9#include "flutter/fml/logging.h"
10
11namespace flutter {
12
13static void DlGradientDeleter(void* p) {
14 // Some of our target environments would prefer a sized delete,
15 // but other target environments do not have that operator.
16 // Use an unsized delete until we get better agreement in the
17 // environments.
18 // See https://github.com/flutter/flutter/issues/100327
19 ::operator delete(p);
20}
21
22std::shared_ptr<DlLinearGradientColorSource> DlColorSource::MakeLinear(
23 const SkPoint start_point,
24 const SkPoint end_point,
25 uint32_t stop_count,
26 const DlColor* colors,
27 const float* stops,
28 DlTileMode tile_mode,
29 const SkMatrix* matrix) {
30 size_t needed = sizeof(DlLinearGradientColorSource) +
31 (stop_count * (sizeof(uint32_t) + sizeof(float)));
32
33 void* storage = ::operator new(needed);
34
35 std::shared_ptr<DlLinearGradientColorSource> ret;
36 ret.reset(new (storage)
37 DlLinearGradientColorSource(start_point, end_point, stop_count,
38 colors, stops, tile_mode, matrix),
40 return ret;
41}
42
43std::shared_ptr<DlRadialGradientColorSource> DlColorSource::MakeRadial(
44 SkPoint center,
45 SkScalar radius,
46 uint32_t stop_count,
47 const DlColor* colors,
48 const float* stops,
49 DlTileMode tile_mode,
50 const SkMatrix* matrix) {
51 size_t needed = sizeof(DlRadialGradientColorSource) +
52 (stop_count * (sizeof(uint32_t) + sizeof(float)));
53
54 void* storage = ::operator new(needed);
55
56 std::shared_ptr<DlRadialGradientColorSource> ret;
57 ret.reset(new (storage) DlRadialGradientColorSource(
58 center, radius, stop_count, colors, stops, tile_mode, matrix),
60 return ret;
61}
62
63std::shared_ptr<DlConicalGradientColorSource> DlColorSource::MakeConical(
64 SkPoint start_center,
65 SkScalar start_radius,
66 SkPoint end_center,
67 SkScalar end_radius,
68 uint32_t stop_count,
69 const DlColor* colors,
70 const float* stops,
71 DlTileMode tile_mode,
72 const SkMatrix* matrix) {
73 size_t needed = sizeof(DlConicalGradientColorSource) +
74 (stop_count * (sizeof(uint32_t) + sizeof(float)));
75
76 void* storage = ::operator new(needed);
77
78 std::shared_ptr<DlConicalGradientColorSource> ret;
79 ret.reset(new (storage) DlConicalGradientColorSource(
80 start_center, start_radius, end_center, end_radius, stop_count,
81 colors, stops, tile_mode, matrix),
83 return ret;
84}
85
86std::shared_ptr<DlSweepGradientColorSource> DlColorSource::MakeSweep(
87 SkPoint center,
88 SkScalar start,
89 SkScalar end,
90 uint32_t stop_count,
91 const DlColor* colors,
92 const float* stops,
93 DlTileMode tile_mode,
94 const SkMatrix* matrix) {
95 size_t needed = sizeof(DlSweepGradientColorSource) +
96 (stop_count * (sizeof(uint32_t) + sizeof(float)));
97
98 void* storage = ::operator new(needed);
99
100 std::shared_ptr<DlSweepGradientColorSource> ret;
101 ret.reset(new (storage)
102 DlSweepGradientColorSource(center, start, end, stop_count,
103 colors, stops, tile_mode, matrix),
105 return ret;
106}
107
108std::shared_ptr<DlRuntimeEffectColorSource> DlColorSource::MakeRuntimeEffect(
109 sk_sp<DlRuntimeEffect> runtime_effect,
110 std::vector<std::shared_ptr<DlColorSource>> samplers,
111 std::shared_ptr<std::vector<uint8_t>> uniform_data) {
112 FML_DCHECK(uniform_data != nullptr);
113 return std::make_shared<DlRuntimeEffectColorSource>(
114 std::move(runtime_effect), std::move(samplers), std::move(uniform_data));
115}
116
117} // namespace flutter
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)
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)
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)
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)
float SkScalar
Definition: extension.cpp:12
glong glong end
#define FML_DCHECK(condition)
Definition: logging.h:103
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
PODArray< SkColor > colors
Definition: SkRecords.h:276
static void DlGradientDeleter(void *p)