| 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 "gl/builders/GrGLProgramBuilder.h" |  | 
| 9 #include "GrYUVtoRGBEffect.h" | 8 #include "GrYUVtoRGBEffect.h" | 
| 10 | 9 | 
| 11 #include "GrCoordTransform.h" | 10 #include "GrCoordTransform.h" | 
| 12 #include "GrInvariantOutput.h" | 11 #include "GrInvariantOutput.h" | 
| 13 #include "GrProcessor.h" | 12 #include "GrProcessor.h" | 
| 14 #include "gl/GrGLProcessor.h" | 13 #include "gl/GrGLProcessor.h" | 
| 15 #include "GrTBackendProcessorFactory.h" | 14 #include "gl/builders/GrGLProgramBuilder.h" | 
| 16 | 15 | 
| 17 namespace { | 16 namespace { | 
| 18 | 17 | 
| 19 class YUVtoRGBEffect : public GrFragmentProcessor { | 18 class YUVtoRGBEffect : public GrFragmentProcessor { | 
| 20 public: | 19 public: | 
| 21     static GrFragmentProcessor* Create(GrTexture* yTexture, GrTexture* uTexture, | 20     static GrFragmentProcessor* Create(GrTexture* yTexture, GrTexture* uTexture, | 
| 22                                        GrTexture* vTexture, SkYUVColorSpace colo
     rSpace) { | 21                                        GrTexture* vTexture, SkYUVColorSpace colo
     rSpace) { | 
| 23         return SkNEW_ARGS(YUVtoRGBEffect, (yTexture, uTexture, vTexture, colorSp
     ace)); | 22         return SkNEW_ARGS(YUVtoRGBEffect, (yTexture, uTexture, vTexture, colorSp
     ace)); | 
| 24     } | 23     } | 
| 25 | 24 | 
| 26     static const char* Name() { return "YUV to RGB"; } | 25     virtual const char* name() const SK_OVERRIDE { return "YUV to RGB"; } | 
| 27 |  | 
| 28     virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
     IDE { |  | 
| 29         return GrTBackendFragmentProcessorFactory<YUVtoRGBEffect>::getInstance()
     ; |  | 
| 30     } |  | 
| 31 | 26 | 
| 32     SkYUVColorSpace getColorSpace() const { | 27     SkYUVColorSpace getColorSpace() const { | 
| 33         return fColorSpace; | 28         return fColorSpace; | 
| 34     } | 29     } | 
| 35 | 30 | 
| 36     class GLProcessor : public GrGLFragmentProcessor { | 31     class GLProcessor : public GrGLFragmentProcessor { | 
| 37     public: | 32     public: | 
| 38         static const GrGLfloat kJPEGConversionMatrix[16]; | 33         static const GrGLfloat kJPEGConversionMatrix[16]; | 
| 39         static const GrGLfloat kRec601ConversionMatrix[16]; | 34         static const GrGLfloat kRec601ConversionMatrix[16]; | 
| 40 | 35 | 
| 41         // this class always generates the same code. | 36         // this class always generates the same code. | 
| 42         static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu
     ilder*) {} | 37         static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu
     ilder*) {} | 
| 43 | 38 | 
| 44         GLProcessor(const GrBackendProcessorFactory& factory, | 39         GLProcessor(const GrProcessor&) {} | 
| 45                     const GrProcessor&) |  | 
| 46         : INHERITED(factory) { |  | 
| 47         } |  | 
| 48 | 40 | 
| 49         virtual void emitCode(GrGLFPBuilder* builder, | 41         virtual void emitCode(GrGLFPBuilder* builder, | 
| 50                               const GrFragmentProcessor&, | 42                               const GrFragmentProcessor&, | 
| 51                               const char* outputColor, | 43                               const char* outputColor, | 
| 52                               const char* inputColor, | 44                               const char* inputColor, | 
| 53                               const TransformedCoordsArray& coords, | 45                               const TransformedCoordsArray& coords, | 
| 54                               const TextureSamplerArray& samplers) SK_OVERRIDE { | 46                               const TextureSamplerArray& samplers) SK_OVERRIDE { | 
| 55             GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder
     (); | 47             GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder
     (); | 
| 56 | 48 | 
| 57             const char* yuvMatrix   = NULL; | 49             const char* yuvMatrix   = NULL; | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 79                     break; | 71                     break; | 
| 80             } | 72             } | 
| 81         } | 73         } | 
| 82 | 74 | 
| 83     private: | 75     private: | 
| 84         GrGLProgramDataManager::UniformHandle fMatrixUni; | 76         GrGLProgramDataManager::UniformHandle fMatrixUni; | 
| 85 | 77 | 
| 86         typedef GrGLFragmentProcessor INHERITED; | 78         typedef GrGLFragmentProcessor INHERITED; | 
| 87     }; | 79     }; | 
| 88 | 80 | 
|  | 81     virtual void getGLProcessorKey(const GrGLCaps& caps, | 
|  | 82                                    GrProcessorKeyBuilder* b) const SK_OVERRIDE { | 
|  | 83         GLProcessor::GenKey(*this, caps, b); | 
|  | 84     } | 
|  | 85 | 
|  | 86     virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE { | 
|  | 87         return SkNEW_ARGS(GLProcessor, (*this)); | 
|  | 88     } | 
|  | 89 | 
| 89 private: | 90 private: | 
| 90     YUVtoRGBEffect(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture
     , | 91     YUVtoRGBEffect(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture
     , | 
| 91                    SkYUVColorSpace colorSpace) | 92                    SkYUVColorSpace colorSpace) | 
| 92      : fCoordTransform(kLocal_GrCoordSet, GrCoordTransform::MakeDivByTextureWHMa
     trix(yTexture), | 93      : fCoordTransform(kLocal_GrCoordSet, GrCoordTransform::MakeDivByTextureWHMa
     trix(yTexture), | 
| 93                        yTexture) | 94                        yTexture) | 
| 94     , fYAccess(yTexture) | 95     , fYAccess(yTexture) | 
| 95     , fUAccess(uTexture) | 96     , fUAccess(uTexture) | 
| 96     , fVAccess(vTexture) | 97     , fVAccess(vTexture) | 
| 97     , fColorSpace(colorSpace) { | 98     , fColorSpace(colorSpace) { | 
|  | 99         this->initClassID<YUVtoRGBEffect>(); | 
| 98         this->addCoordTransform(&fCoordTransform); | 100         this->addCoordTransform(&fCoordTransform); | 
| 99         this->addTextureAccess(&fYAccess); | 101         this->addTextureAccess(&fYAccess); | 
| 100         this->addTextureAccess(&fUAccess); | 102         this->addTextureAccess(&fUAccess); | 
| 101         this->addTextureAccess(&fVAccess); | 103         this->addTextureAccess(&fVAccess); | 
| 102     } | 104     } | 
| 103 | 105 | 
| 104     virtual bool onIsEqual(const GrFragmentProcessor& sBase) const { | 106     virtual bool onIsEqual(const GrFragmentProcessor& sBase) const { | 
| 105         const YUVtoRGBEffect& s = sBase.cast<YUVtoRGBEffect>(); | 107         const YUVtoRGBEffect& s = sBase.cast<YUVtoRGBEffect>(); | 
| 106         return fColorSpace == s.getColorSpace(); | 108         return fColorSpace == s.getColorSpace(); | 
| 107     } | 109     } | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 133     0.0f,    0.0f,    0.0f,    1.0}; | 135     0.0f,    0.0f,    0.0f,    1.0}; | 
| 134 } | 136 } | 
| 135 | 137 | 
| 136 ////////////////////////////////////////////////////////////////////////////// | 138 ////////////////////////////////////////////////////////////////////////////// | 
| 137 | 139 | 
| 138 GrFragmentProcessor* | 140 GrFragmentProcessor* | 
| 139 GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vT
     exture, | 141 GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vT
     exture, | 
| 140                          SkYUVColorSpace colorSpace) { | 142                          SkYUVColorSpace colorSpace) { | 
| 141     return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, colorSpace); | 143     return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, colorSpace); | 
| 142 } | 144 } | 
| OLD | NEW | 
|---|