| 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" |
| 12 |
#include "src/core/SkColorSpacePriv.h" |
| 13 |
#include "src/core/SkColorSpaceXformSteps.h" |
| 14 |
#include "src/gpu/ganesh/GrColorSpaceXform.h" |
| 15 |
#include "src/gpu/ganesh/glsl/GrGLSLUniformHandler.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 |
*/ |
| 22 |
class GrGLSLColorSpaceXformHelper : public SkNoncopyable { |
| 23 |
public: |
| 24 |
GrGLSLColorSpaceXformHelper() {} |
| 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.fFlags; |
| 31 |
if (this->applySrcTF()) { |
| 32 |
fSrcTFVar = uniformHandler->addUniformArray(nullptr, visibility, SkSLType::kFloat, |
| 33 |
"SrcTF", kNumTransferFnCoeffs); |
| 34 |
fSrcTFType = skcms_TransferFunction_getType(&colorSpaceXform->fSteps.fSrcTF); |
| 35 |
} |
| 36 |
if (this->applySrcOOTF()) { |
| 37 |
fSrcOOTFVar = uniformHandler->addUniform(nullptr, visibility, SkSLType::kFloat4, |
| 38 |
"SrcOOTF"); |
| 39 |
} |
| 40 |
if (this->applyGamutXform()) { |
| 41 |
fGamutXformVar = uniformHandler->addUniform(nullptr, visibility, SkSLType::kFloat3x3, |
| 42 |
"ColorXform"); |
| 43 |
} |
| 44 |
if (this->applyDstOOTF()) { |
| 45 |
fDstOOTFVar = uniformHandler->addUniform(nullptr, visibility, SkSLType::kFloat4, |
| 46 |
"DstOOTF"); |
| 47 |
} |
| 48 |
if (this->applyDstTF()) { |
| 49 |
fDstTFVar = uniformHandler->addUniformArray(nullptr, visibility, SkSLType::kFloat, |
| 50 |
"DstTF", kNumTransferFnCoeffs); |
| 51 |
fDstTFType = skcms_TransferFunction_getType(&colorSpaceXform->fSteps.fDstTFInv); |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
void setData(const GrGLSLProgramDataManager& pdman, const GrColorSpaceXform* colorSpaceXform) { |
| 57 |
if (this->applySrcTF()) { |
| 58 |
pdman.set1fv(fSrcTFVar, kNumTransferFnCoeffs, &colorSpaceXform->fSteps.fSrcTF.g); |
| 59 |
} |
| 60 |
if (this->applySrcOOTF()) { |
| 61 |
pdman.set4fv(fSrcOOTFVar, 1, colorSpaceXform->fSteps.fSrcOotf); |
| 62 |
} |
| 63 |
if (this->applyGamutXform()) { |
| 64 |
pdman.setMatrix3f(fGamutXformVar, colorSpaceXform->fSteps.fSrcToDstMatrix); |
| 65 |
} |
| 66 |
if (this->applyDstOOTF()) { |
| 67 |
pdman.set4fv(fDstOOTFVar, 1, colorSpaceXform->fSteps.fDstOotf); |
| 68 |
} |
| 69 |
if (this->applyDstTF()) { |
| 70 |
pdman.set1fv(fDstTFVar, kNumTransferFnCoeffs, &colorSpaceXform->fSteps.fDstTFInv.g); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
bool isNoop() const { return (0 == fFlags.mask()); } |
| 75 |
|
| 76 |
bool applyUnpremul() const { return fFlags.unpremul; } |
| 77 |
bool applySrcTF() const { return fFlags.linearize; } |
| 78 |
bool applySrcOOTF() const { return fFlags.src_ootf; } |
| 79 |
bool applyGamutXform() const { return fFlags.gamut_transform; } |
| 80 |
bool applyDstOOTF() const { return fFlags.dst_ootf; } |
| 81 |
bool applyDstTF() const { return fFlags.encode; } |
| 82 |
bool applyPremul() const { return fFlags.premul; } |
| 83 |
|
| 84 |
skcms_TFType srcTFType() const { return fSrcTFType; } |
| 85 |
skcms_TFType dstTFType() const { return fDstTFType; } |
| 86 |
|
| 87 |
GrGLSLProgramDataManager::UniformHandle srcTFUniform() const { return fSrcTFVar; } |
| 88 |
GrGLSLProgramDataManager::UniformHandle srcOOTFUniform() const { return fSrcOOTFVar; } |
| 89 |
GrGLSLProgramDataManager::UniformHandle gamutXformUniform() const { return fGamutXformVar; } |
| 90 |
GrGLSLProgramDataManager::UniformHandle dstOOTFUniform() const { return fDstOOTFVar; } |
| 91 |
GrGLSLProgramDataManager::UniformHandle dstTFUniform() const { return fDstTFVar; } |
| 92 |
|
| 93 |
private: |
| 94 |
static const int kNumTransferFnCoeffs = 7; |
| 95 |
|
| 96 |
GrGLSLProgramDataManager::UniformHandle fSrcTFVar; |
| 97 |
GrGLSLProgramDataManager::UniformHandle fSrcOOTFVar; |
| 98 |
GrGLSLProgramDataManager::UniformHandle fGamutXformVar; |
| 99 |
GrGLSLProgramDataManager::UniformHandle fDstOOTFVar; |
| 100 |
GrGLSLProgramDataManager::UniformHandle fDstTFVar; |
| 101 |
SkColorSpaceXformSteps::Flags fFlags; |
| 102 |
skcms_TFType fSrcTFType; |
| 103 |
skcms_TFType fDstTFType; |
| 104 |
}; |
| 105 |
|
| 106 |
#endif |