OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrYUVtoRGBEffect.h" | 8 #include "GrYUVtoRGBEffect.h" |
9 | 9 |
10 #include "GrCoordTransform.h" | 10 #include "GrCoordTransform.h" |
11 #include "GrInvariantOutput.h" | 11 #include "GrInvariantOutput.h" |
12 #include "GrProcessor.h" | 12 #include "GrProcessor.h" |
13 #include "gl/GrGLFragmentProcessor.h" | 13 #include "gl/GrGLFragmentProcessor.h" |
14 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 14 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
15 #include "glsl/GrGLSLProgramBuilder.h" | 15 #include "glsl/GrGLSLProgramBuilder.h" |
16 #include "glsl/GrGLSLProgramDataManager.h" | 16 #include "glsl/GrGLSLProgramDataManager.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 class YUVtoRGBEffect : public GrFragmentProcessor { | 20 class YUVtoRGBEffect : public GrFragmentProcessor { |
21 public: | 21 public: |
22 static GrFragmentProcessor* Create(GrTexture* yTexture, GrTexture* uTexture, | 22 static GrFragmentProcessor* Create(GrTexture* yTexture, GrTexture* uTexture, |
23 GrTexture* vTexture, const SkISize sizes[
3], | 23 GrTexture* vTexture, const SkISize sizes[
3], |
24 SkYUVColorSpace colorSpace) { | 24 SkYUVColorSpace colorSpace, GrRenderTarge
t* dst) { |
25 SkScalar w[3], h[3]; | 25 SkScalar w[3], h[3]; |
26 w[0] = SkIntToScalar(sizes[0].fWidth) / SkIntToScalar(yTexture->width()
); | 26 w[0] = SkIntToScalar(sizes[0].fWidth) / SkIntToScalar(yTexture->width()
); |
27 h[0] = SkIntToScalar(sizes[0].fHeight) / SkIntToScalar(yTexture->height(
)); | 27 h[0] = SkIntToScalar(sizes[0].fHeight) / SkIntToScalar(yTexture->height(
)); |
28 w[1] = SkIntToScalar(sizes[1].fWidth) / SkIntToScalar(uTexture->width()
); | 28 w[1] = SkIntToScalar(sizes[1].fWidth) / SkIntToScalar(uTexture->width()
); |
29 h[1] = SkIntToScalar(sizes[1].fHeight) / SkIntToScalar(uTexture->height(
)); | 29 h[1] = SkIntToScalar(sizes[1].fHeight) / SkIntToScalar(uTexture->height(
)); |
30 w[2] = SkIntToScalar(sizes[2].fWidth) / SkIntToScalar(vTexture->width()
); | 30 w[2] = SkIntToScalar(sizes[2].fWidth) / SkIntToScalar(vTexture->width()
); |
31 h[2] = SkIntToScalar(sizes[2].fHeight) / SkIntToScalar(vTexture->height(
)); | 31 h[2] = SkIntToScalar(sizes[2].fHeight) / SkIntToScalar(vTexture->height(
)); |
32 SkMatrix yuvMatrix[3]; | 32 SkMatrix yuvMatrix[3]; |
33 yuvMatrix[0] = GrCoordTransform::MakeDivByTextureWHMatrix(yTexture); | 33 yuvMatrix[0] = GrCoordTransform::MakeDivByTextureWHMatrix(yTexture); |
34 yuvMatrix[1] = yuvMatrix[0]; | 34 yuvMatrix[1] = yuvMatrix[0]; |
35 yuvMatrix[1].preScale(w[1] / w[0], h[1] / h[0]); | 35 yuvMatrix[1].preScale(w[1] / w[0], h[1] / h[0]); |
36 yuvMatrix[2] = yuvMatrix[0]; | 36 yuvMatrix[2] = yuvMatrix[0]; |
37 yuvMatrix[2].preScale(w[2] / w[0], h[2] / h[0]); | 37 yuvMatrix[2].preScale(w[2] / w[0], h[2] / h[0]); |
38 GrTextureParams::FilterMode uvFilterMode = | 38 GrTextureParams::FilterMode uvFilterMode = |
39 ((sizes[1].fWidth != sizes[0].fWidth) || | 39 ((sizes[1].fWidth != sizes[0].fWidth) || |
40 (sizes[1].fHeight != sizes[0].fHeight) || | 40 (sizes[1].fHeight != sizes[0].fHeight) || |
41 (sizes[2].fWidth != sizes[0].fWidth) || | 41 (sizes[2].fWidth != sizes[0].fWidth) || |
42 (sizes[2].fHeight != sizes[0].fHeight)) ? | 42 (sizes[2].fHeight != sizes[0].fHeight)) ? |
43 GrTextureParams::kBilerp_FilterMode : | 43 GrTextureParams::kBilerp_FilterMode : |
44 GrTextureParams::kNone_FilterMode; | 44 GrTextureParams::kNone_FilterMode; |
45 return new YUVtoRGBEffect(yTexture, uTexture, vTexture, yuvMatrix, uvFil
terMode, | 45 return new YUVtoRGBEffect(yTexture, uTexture, vTexture, yuvMatrix, uvFil
terMode, |
46 colorSpace); | 46 colorSpace, dst); |
47 } | 47 } |
48 | 48 |
49 const char* name() const override { return "YUV to RGB"; } | 49 const char* name() const override { return "YUV to RGB"; } |
50 | 50 |
51 SkYUVColorSpace getColorSpace() const { | 51 SkYUVColorSpace getColorSpace() const { |
52 return fColorSpace; | 52 return fColorSpace; |
53 } | 53 } |
54 | 54 |
55 class GLProcessor : public GrGLFragmentProcessor { | 55 class GLProcessor : public GrGLFragmentProcessor { |
56 public: | 56 public: |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 101 |
102 private: | 102 private: |
103 GrGLSLProgramDataManager::UniformHandle fMatrixUni; | 103 GrGLSLProgramDataManager::UniformHandle fMatrixUni; |
104 | 104 |
105 typedef GrGLFragmentProcessor INHERITED; | 105 typedef GrGLFragmentProcessor INHERITED; |
106 }; | 106 }; |
107 | 107 |
108 private: | 108 private: |
109 YUVtoRGBEffect(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture
, | 109 YUVtoRGBEffect(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture
, |
110 const SkMatrix yuvMatrix[3], GrTextureParams::FilterMode uvFi
lterMode, | 110 const SkMatrix yuvMatrix[3], GrTextureParams::FilterMode uvFi
lterMode, |
111 SkYUVColorSpace colorSpace) | 111 SkYUVColorSpace colorSpace, GrRenderTarget* dst) |
112 : fYTransform(kLocal_GrCoordSet, yuvMatrix[0], yTexture, GrTextureParams::kN
one_FilterMode) | 112 : fYTransform(kLocal_GrCoordSet, yuvMatrix[0], yTexture, GrTextureParams::kN
one_FilterMode) |
113 , fYAccess(yTexture) | 113 , fYAccess(yTexture, GrTextureParams::kNone_FilterMode,SkShader::kClamp_Tile
Mode, dst) |
114 , fUTransform(kLocal_GrCoordSet, yuvMatrix[1], uTexture, uvFilterMode) | 114 , fUTransform(kLocal_GrCoordSet, yuvMatrix[1], uTexture, uvFilterMode) |
115 , fUAccess(uTexture, uvFilterMode) | 115 , fUAccess(uTexture, uvFilterMode,SkShader::kClamp_TileMode, dst) |
116 , fVTransform(kLocal_GrCoordSet, yuvMatrix[2], vTexture, uvFilterMode) | 116 , fVTransform(kLocal_GrCoordSet, yuvMatrix[2], vTexture, uvFilterMode) |
117 , fVAccess(vTexture, uvFilterMode) | 117 , fVAccess(vTexture, uvFilterMode, SkShader::kClamp_TileMode, dst) |
118 , fColorSpace(colorSpace) { | 118 , fColorSpace(colorSpace) { |
119 this->initClassID<YUVtoRGBEffect>(); | 119 this->initClassID<YUVtoRGBEffect>(); |
120 this->addCoordTransform(&fYTransform); | 120 this->addCoordTransform(&fYTransform); |
121 this->addTextureAccess(&fYAccess); | 121 this->addTextureAccess(&fYAccess); |
122 this->addCoordTransform(&fUTransform); | 122 this->addCoordTransform(&fUTransform); |
123 this->addTextureAccess(&fUAccess); | 123 this->addTextureAccess(&fUAccess); |
124 this->addCoordTransform(&fVTransform); | 124 this->addCoordTransform(&fVTransform); |
125 this->addTextureAccess(&fVAccess); | 125 this->addTextureAccess(&fVAccess); |
126 } | 126 } |
127 | 127 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 1.164f, 0.0f, 1.793f, -0.96925f, | 168 1.164f, 0.0f, 1.793f, -0.96925f, |
169 1.164f, -0.213f, -0.533f, 0.30025f, | 169 1.164f, -0.213f, -0.533f, 0.30025f, |
170 1.164f, 2.112f, 0.0f, -1.12875f, | 170 1.164f, 2.112f, 0.0f, -1.12875f, |
171 0.0f, 0.0f, 0.0f, 1.0f}; | 171 0.0f, 0.0f, 0.0f, 1.0f}; |
172 } | 172 } |
173 | 173 |
174 ////////////////////////////////////////////////////////////////////////////// | 174 ////////////////////////////////////////////////////////////////////////////// |
175 | 175 |
176 GrFragmentProcessor* | 176 GrFragmentProcessor* |
177 GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vT
exture, | 177 GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vT
exture, |
178 const SkISize sizes[3], SkYUVColorSpace colorSpace) { | 178 const SkISize sizes[3], SkYUVColorSpace colorSpace, |
| 179 GrRenderTarget* dst) { |
179 SkASSERT(yTexture && uTexture && vTexture && sizes); | 180 SkASSERT(yTexture && uTexture && vTexture && sizes); |
180 return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, sizes, colorSpac
e); | 181 return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, sizes, colorSpac
e, dst); |
181 } | 182 } |
OLD | NEW |