Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
15namespace flutter {
16
18
21 auto res = fml::MakeRefCounted<ColorFilter>();
22 res->AssociateWithDartWrapper(wrapper);
23}
24
25void ColorFilter::initMode(int color, int blend_mode) {
26 filter_ = DlBlendColorFilter::Make(static_cast<DlColor>(color),
27 static_cast<DlBlendMode>(blend_mode));
28}
29
30void ColorFilter::initMatrix(const tonic::Float32List& color_matrix) {
31 FML_CHECK(color_matrix.num_elements() == 20);
32
33 // Flutter still defines the matrix to be biased by 255 in the last column
34 // (translate). skia is normalized, treating the last column as 0...1, so we
35 // post-scale here before calling the skia factory.
36 float matrix[20];
37 memcpy(matrix, color_matrix.data(), sizeof(matrix));
38 matrix[4] *= 1.0f / 255;
39 matrix[9] *= 1.0f / 255;
40 matrix[14] *= 1.0f / 255;
41 matrix[19] *= 1.0f / 255;
42 filter_ = DlMatrixColorFilter::Make(matrix);
43}
44
48
52
54
55} // namespace flutter
SkColor4f color
void initMatrix(const tonic::Float32List &color_matrix)
void initMode(int color, int blend_mode)
~ColorFilter() override
static void Create(Dart_Handle wrapper)
static std::shared_ptr< DlColorFilter > Make(DlColor color, DlBlendMode mode)
static const std::shared_ptr< DlLinearToSrgbGammaColorFilter > kInstance
static std::shared_ptr< DlColorFilter > Make(const float matrix[20])
static const std::shared_ptr< DlSrgbToLinearGammaColorFilter > kInstance
static void ThrowIfUIOperationsProhibited()
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
#define FML_CHECK(condition)
Definition logging.h:85