1 /*
2  * Copyright 2016 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkColorMatrixFilter_DEFINED
9 #define SkColorMatrixFilter_DEFINED
10 
11 #include "SkColorFilter.h"
12 
13 class SkColorMatrixFilterRowMajor255 : public SkColorFilter {
14 public:
SkColorMatrixFilterRowMajor255()15     SkColorMatrixFilterRowMajor255() {}
16     explicit SkColorMatrixFilterRowMajor255(const SkScalar array[20]);
17 
18     /** Creates a color matrix filter that returns the same value in all four channels. */
19     static sk_sp<SkColorFilter> MakeSingleChannelOutput(const SkScalar row[5]);
20 
21     uint32_t getFlags() const override;
22     bool asColorMatrix(SkScalar matrix[20]) const override;
23     sk_sp<SkColorFilter> onMakeComposed(sk_sp<SkColorFilter>) const override;
24 
25 #if SK_SUPPORT_GPU
26     std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(
27             GrContext*, const GrColorSpaceInfo&) const override;
28 #endif
29 
30     SK_TO_STRING_OVERRIDE()
31 
32     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorMatrixFilter)
33 
34 protected:
35     void flatten(SkWriteBuffer&) const override;
36 
37 private:
38     void onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
39                         bool shaderIsOpaque) const override;
40 
41     SkScalar        fMatrix[20];
42     float           fTranspose[20]; // for Sk4s
43     uint32_t        fFlags;
44 
45     void initState();
46 
47     typedef SkColorFilter INHERITED;
48 };
49 
50 #endif
51