Line data Source code
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 "GrColorSpaceXform.h"
12 : #include "GrGLSLUniformHandler.h"
13 :
14 : /**
15 : * Helper class to assist with using GrColorSpaceXform within an FP. This manages all of the
16 : * uniforms needed, and can be passed to shader builder functions to automatically generate the
17 : * correct color space transformation code.
18 : */
19 : class GrGLSLColorSpaceXformHelper : public SkNoncopyable {
20 : public:
21 0 : GrGLSLColorSpaceXformHelper() : fValid(false) {}
22 :
23 0 : void emitCode(GrGLSLUniformHandler* uniformHandler, GrColorSpaceXform* colorSpaceXform) {
24 0 : SkASSERT(uniformHandler);
25 0 : if (colorSpaceXform) {
26 : fGamutXformVar = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat44f_GrSLType,
27 0 : kDefault_GrSLPrecision, "ColorXform");
28 0 : fValid = true;
29 : }
30 0 : }
31 :
32 0 : void setData(const GrGLSLProgramDataManager& pdman, GrColorSpaceXform* colorSpaceXform) {
33 0 : pdman.setSkMatrix44(fGamutXformVar, colorSpaceXform->srcToDst());
34 0 : }
35 :
36 0 : bool isValid() const { return fValid; }
37 0 : GrGLSLProgramDataManager::UniformHandle const gamutXformUniform() { return fGamutXformVar; }
38 :
39 : private:
40 : GrGLSLProgramDataManager::UniformHandle fGamutXformVar;
41 : bool fValid;
42 : };
43 :
44 : #endif
|