aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu/GrColorSpaceXform.h
blob: c1fb166f47cce383eb8574a6a672ed4e500326cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrColorSpaceXform_DEFINED
#define GrColorSpaceXform_DEFINED

#include "SkImageInfo.h"
#include "SkRefCnt.h"

class SkColorSpace;
class SkMatrix44;

 /**
  * Represents a color gamut transformation (as a 4x4 color matrix)
  */
class GrColorSpaceXform : public SkRefCnt {
public:
    GrColorSpaceXform(const SkMatrix44& srcToDst, SkAlphaType srcAlphaType);

    static sk_sp<GrColorSpaceXform> Make(SkColorSpace* src, SkColorSpace* dst,
                                         SkAlphaType srcAlphaType);

    const float* srcToDst() { return fSrcToDst; }
    SkAlphaType alphaType() const { return fSrcAlphaType; }

    /**
     * GrGLSLFragmentProcessor::GenKey() must call this and include the returned value in its
     * computed key.
     */
    static uint32_t XformKey(GrColorSpaceXform* xform) {
        if (!xform) {
            return 0;
        }
        // Code generation just depends on whether the alpha type is premul or not
        return kPremul_SkAlphaType == xform->fSrcAlphaType ? 1 : 2;
    }

private:
    // We store the column-major form of the srcToDst matrix, for easy uploading to uniforms
    float fSrcToDst[16];

    // Alpha type of the source. If it's premul, we need special handling
    SkAlphaType fSrcAlphaType;
};

#endif