Flutter Engine
color_filter.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/lib/ui/painting/color_filter.h"
6 
7 #include <cstring>
8 
9 #include "flutter/lib/ui/ui_dart_state.h"
14 
15 namespace flutter {
16 
17 static void ColorFilter_constructor(Dart_NativeArguments args) {
20 }
21 
23 
24 #define FOR_EACH_BINDING(V) \
25  V(ColorFilter, initMode) \
26  V(ColorFilter, initMatrix) \
27  V(ColorFilter, initSrgbToLinearGamma) \
28  V(ColorFilter, initLinearToSrgbGamma)
29 
31 
32 void ColorFilter::RegisterNatives(tonic::DartLibraryNatives* natives) {
33  natives->Register(
34  {{"ColorFilter_constructor", ColorFilter_constructor, 1, true},
36 }
37 
39  return fml::MakeRefCounted<ColorFilter>();
40 }
41 
42 void ColorFilter::initMode(int color, int blend_mode) {
43  filter_ = SkColorFilters::Blend(static_cast<SkColor>(color),
44  static_cast<SkBlendMode>(blend_mode));
45 }
46 
48  const float array[20]) {
49  float tmp[20];
50  memcpy(tmp, array, sizeof(tmp));
51  tmp[4] *= 1.0f / 255;
52  tmp[9] *= 1.0f / 255;
53  tmp[14] *= 1.0f / 255;
54  tmp[19] *= 1.0f / 255;
55  return SkColorFilters::Matrix(tmp);
56 }
57 
58 void ColorFilter::initMatrix(const tonic::Float32List& color_matrix) {
59  FML_CHECK(color_matrix.num_elements() == 20);
60 
61  filter_ = MakeColorMatrixFilter255(color_matrix.data());
62 }
63 
65  filter_ = SkColorFilters::LinearToSRGBGamma();
66 }
67 
69  filter_ = SkColorFilters::SRGBToLinearGamma();
70 }
71 
72 ColorFilter::~ColorFilter() = default;
73 
74 } // namespace flutter
G_BEGIN_DECLS FlValue * args
~ColorFilter() override
void DartCallConstructor(Sig func, Dart_NativeArguments args)
Definition: dart_args.h:218
static void ColorFilter_constructor(Dart_NativeArguments args)
Definition: color_filter.cc:17
#define DART_NATIVE_CALLBACK(CLASS, METHOD)
IMPLEMENT_WRAPPERTYPEINFO(ui, Scene)
static void ThrowIfUIOperationsProhibited()
void initMode(int color, int blend_mode)
Definition: color_filter.cc:42
static sk_sp< SkColorFilter > MakeColorMatrixFilter255(const float array[20])
Definition: color_filter.cc:47
#define FML_CHECK(condition)
Definition: logging.h:68
#define DART_REGISTER_NATIVE(CLASS, METHOD)
static fml::RefPtr< ColorFilter > Create()
Definition: color_filter.cc:38
#define FOR_EACH_BINDING(V)
Definition: color_filter.cc:24
void initMatrix(const tonic::Float32List &color_matrix)
Definition: color_filter.cc:58