Flutter Engine
The Flutter Engine
GrGLSLColorSpaceXformHelper.h
Go to the documentation of this file.
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 GrGLSLColorSpaceXformHelper_DEFINED
9#define GrGLSLColorSpaceXformHelper_DEFINED
10
11#include "modules/skcms/skcms.h"
16
17/**
18 * Helper class to assist with using GrColorSpaceXform within an FP. This manages all of the
19 * uniforms needed, and can be passed to shader builder functions to automatically generate the
20 * correct color space transformation code.
21 */
23public:
25
26 void emitCode(GrGLSLUniformHandler* uniformHandler, const GrColorSpaceXform* colorSpaceXform,
27 uint32_t visibility = kFragment_GrShaderFlag) {
28 SkASSERT(uniformHandler);
29 if (colorSpaceXform) {
30 fFlags = colorSpaceXform->fSteps.flags;
31 if (this->applySrcTF()) {
32 fSrcTFVar = uniformHandler->addUniformArray(nullptr, visibility, SkSLType::kFloat,
33 "SrcTF", kNumTransferFnCoeffs);
34 fSrcTFType = skcms_TransferFunction_getType(&colorSpaceXform->fSteps.srcTF);
35 }
36 if (this->applyGamutXform()) {
37 fGamutXformVar = uniformHandler->addUniform(nullptr, visibility, SkSLType::kFloat3x3,
38 "ColorXform");
39 }
40 if (this->applyDstTF()) {
41 fDstTFVar = uniformHandler->addUniformArray(nullptr, visibility, SkSLType::kFloat,
42 "DstTF", kNumTransferFnCoeffs);
43 fDstTFType = skcms_TransferFunction_getType(&colorSpaceXform->fSteps.dstTFInv);
44 }
45 }
46 }
47
48 void setData(const GrGLSLProgramDataManager& pdman, const GrColorSpaceXform* colorSpaceXform) {
49 if (this->applySrcTF()) {
50 pdman.set1fv(fSrcTFVar, kNumTransferFnCoeffs, &colorSpaceXform->fSteps.srcTF.g);
51 }
52 if (this->applyGamutXform()) {
53 pdman.setMatrix3f(fGamutXformVar, colorSpaceXform->fSteps.src_to_dst_matrix);
54 }
55 if (this->applyDstTF()) {
56 pdman.set1fv(fDstTFVar, kNumTransferFnCoeffs, &colorSpaceXform->fSteps.dstTFInv.g);
57 }
58 }
59
60 bool isNoop() const { return (0 == fFlags.mask()); }
61
62 bool applyUnpremul() const { return fFlags.unpremul; }
63 bool applySrcTF() const { return fFlags.linearize; }
64 bool applyGamutXform() const { return fFlags.gamut_transform; }
65 bool applyDstTF() const { return fFlags.encode; }
66 bool applyPremul() const { return fFlags.premul; }
67
68 skcms_TFType srcTFType() const { return fSrcTFType; }
69 skcms_TFType dstTFType() const { return fDstTFType; }
70
71 GrGLSLProgramDataManager::UniformHandle srcTFUniform() const { return fSrcTFVar; }
72 GrGLSLProgramDataManager::UniformHandle gamutXformUniform() const { return fGamutXformVar; }
73 GrGLSLProgramDataManager::UniformHandle dstTFUniform() const { return fDstTFVar; }
74
75private:
76 static const int kNumTransferFnCoeffs = 7;
77
78 GrGLSLProgramDataManager::UniformHandle fSrcTFVar;
79 GrGLSLProgramDataManager::UniformHandle fGamutXformVar;
80 GrGLSLProgramDataManager::UniformHandle fDstTFVar;
82 skcms_TFType fSrcTFType;
83 skcms_TFType fDstTFType;
84};
85
86#endif
@ kFragment_GrShaderFlag
Definition: GrTypesPriv.h:287
#define SkASSERT(cond)
Definition: SkAssert.h:116
GrGLSLProgramDataManager::UniformHandle gamutXformUniform() const
GrGLSLProgramDataManager::UniformHandle srcTFUniform() const
void setData(const GrGLSLProgramDataManager &pdman, const GrColorSpaceXform *colorSpaceXform)
void emitCode(GrGLSLUniformHandler *uniformHandler, const GrColorSpaceXform *colorSpaceXform, uint32_t visibility=kFragment_GrShaderFlag)
GrGLSLProgramDataManager::UniformHandle dstTFUniform() const
virtual void setMatrix3f(UniformHandle, const float matrix[]) const =0
virtual void set1fv(UniformHandle, int arrayCount, const float v[]) const =0
UniformHandle addUniformArray(const GrProcessor *owner, uint32_t visibility, SkSLType type, const char *name, int arrayCount, const char **outName=nullptr)
UniformHandle addUniform(const GrProcessor *owner, uint32_t visibility, SkSLType type, const char *name, const char **outName=nullptr)
skcms_TFType skcms_TransferFunction_getType(const skcms_TransferFunction *tf)
Definition: skcms.cc:183
skcms_TFType
Definition: skcms_public.h:54
constexpr uint32_t mask() const
skcms_TransferFunction srcTF
skcms_TransferFunction dstTFInv