| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrConfigConversionEffect.h" | 8 #include "GrConfigConversionEffect.h" |
| 9 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 #include "GrInvariantOutput.h" | 10 #include "GrInvariantOutput.h" |
| 11 #include "GrTBackendProcessorFactory.h" | |
| 12 #include "GrSimpleTextureEffect.h" | 11 #include "GrSimpleTextureEffect.h" |
| 12 #include "SkMatrix.h" |
| 13 #include "gl/GrGLProcessor.h" | 13 #include "gl/GrGLProcessor.h" |
| 14 #include "gl/builders/GrGLProgramBuilder.h" | 14 #include "gl/builders/GrGLProgramBuilder.h" |
| 15 #include "SkMatrix.h" | |
| 16 | 15 |
| 17 class GrGLConfigConversionEffect : public GrGLFragmentProcessor { | 16 class GrGLConfigConversionEffect : public GrGLFragmentProcessor { |
| 18 public: | 17 public: |
| 19 GrGLConfigConversionEffect(const GrBackendProcessorFactory& factory, | 18 GrGLConfigConversionEffect(const GrProcessor& processor) { |
| 20 const GrProcessor& processor) | |
| 21 : INHERITED (factory) { | |
| 22 const GrConfigConversionEffect& configConversionEffect = | 19 const GrConfigConversionEffect& configConversionEffect = |
| 23 processor.cast<GrConfigConversionEffect>(); | 20 processor.cast<GrConfigConversionEffect>(); |
| 24 fSwapRedAndBlue = configConversionEffect.swapsRedAndBlue(); | 21 fSwapRedAndBlue = configConversionEffect.swapsRedAndBlue(); |
| 25 fPMConversion = configConversionEffect.pmConversion(); | 22 fPMConversion = configConversionEffect.pmConversion(); |
| 26 } | 23 } |
| 27 | 24 |
| 28 virtual void emitCode(GrGLFPBuilder* builder, | 25 virtual void emitCode(GrGLFPBuilder* builder, |
| 29 const GrFragmentProcessor&, | 26 const GrFragmentProcessor&, |
| 30 const char* outputColor, | 27 const char* outputColor, |
| 31 const char* inputColor, | 28 const char* inputColor, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 99 |
| 103 /////////////////////////////////////////////////////////////////////////////// | 100 /////////////////////////////////////////////////////////////////////////////// |
| 104 | 101 |
| 105 GrConfigConversionEffect::GrConfigConversionEffect(GrTexture* texture, | 102 GrConfigConversionEffect::GrConfigConversionEffect(GrTexture* texture, |
| 106 bool swapRedAndBlue, | 103 bool swapRedAndBlue, |
| 107 PMConversion pmConversion, | 104 PMConversion pmConversion, |
| 108 const SkMatrix& matrix) | 105 const SkMatrix& matrix) |
| 109 : GrSingleTextureEffect(texture, matrix) | 106 : GrSingleTextureEffect(texture, matrix) |
| 110 , fSwapRedAndBlue(swapRedAndBlue) | 107 , fSwapRedAndBlue(swapRedAndBlue) |
| 111 , fPMConversion(pmConversion) { | 108 , fPMConversion(pmConversion) { |
| 109 this->initClassID<GrConfigConversionEffect>(); |
| 112 SkASSERT(kRGBA_8888_GrPixelConfig == texture->config() || | 110 SkASSERT(kRGBA_8888_GrPixelConfig == texture->config() || |
| 113 kBGRA_8888_GrPixelConfig == texture->config()); | 111 kBGRA_8888_GrPixelConfig == texture->config()); |
| 114 // Why did we pollute our texture cache instead of using a GrSingleTextureEf
fect? | 112 // Why did we pollute our texture cache instead of using a GrSingleTextureEf
fect? |
| 115 SkASSERT(swapRedAndBlue || kNone_PMConversion != pmConversion); | 113 SkASSERT(swapRedAndBlue || kNone_PMConversion != pmConversion); |
| 116 } | 114 } |
| 117 | 115 |
| 118 const GrBackendFragmentProcessorFactory& GrConfigConversionEffect::getFactory()
const { | |
| 119 return GrTBackendFragmentProcessorFactory<GrConfigConversionEffect>::getInst
ance(); | |
| 120 } | |
| 121 | |
| 122 bool GrConfigConversionEffect::onIsEqual(const GrFragmentProcessor& s) const { | 116 bool GrConfigConversionEffect::onIsEqual(const GrFragmentProcessor& s) const { |
| 123 const GrConfigConversionEffect& other = s.cast<GrConfigConversionEffect>(); | 117 const GrConfigConversionEffect& other = s.cast<GrConfigConversionEffect>(); |
| 124 return other.fSwapRedAndBlue == fSwapRedAndBlue && | 118 return other.fSwapRedAndBlue == fSwapRedAndBlue && |
| 125 other.fPMConversion == fPMConversion; | 119 other.fPMConversion == fPMConversion; |
| 126 } | 120 } |
| 127 | 121 |
| 128 void GrConfigConversionEffect::onComputeInvariantOutput(GrInvariantOutput* inout
) const { | 122 void GrConfigConversionEffect::onComputeInvariantOutput(GrInvariantOutput* inout
) const { |
| 129 this->updateInvariantOutputForModulation(inout); | 123 this->updateInvariantOutputForModulation(inout); |
| 130 } | 124 } |
| 131 | 125 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 145 swapRB = random->nextBool(); | 139 swapRB = random->nextBool(); |
| 146 } | 140 } |
| 147 return SkNEW_ARGS(GrConfigConversionEffect, | 141 return SkNEW_ARGS(GrConfigConversionEffect, |
| 148 (textures[GrProcessorUnitTest::kSkiaPMText
ureIdx], | 142 (textures[GrProcessorUnitTest::kSkiaPMText
ureIdx], |
| 149 swapRB, | 143 swapRB, |
| 150 pmConv, | 144 pmConv, |
| 151 GrProcessorUnitTest::TestMatrix(random)))
; | 145 GrProcessorUnitTest::TestMatrix(random)))
; |
| 152 } | 146 } |
| 153 | 147 |
| 154 /////////////////////////////////////////////////////////////////////////////// | 148 /////////////////////////////////////////////////////////////////////////////// |
| 149 |
| 150 void GrConfigConversionEffect::getGLProcessorKey(const GrGLCaps& caps, |
| 151 GrProcessorKeyBuilder* b) const
{ |
| 152 GrGLConfigConversionEffect::GenKey(*this, caps, b); |
| 153 } |
| 154 |
| 155 GrGLFragmentProcessor* GrConfigConversionEffect::createGLInstance() const { |
| 156 return SkNEW_ARGS(GrGLConfigConversionEffect, (*this)); |
| 157 } |
| 158 |
| 155 void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
, | 159 void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
, |
| 156 PMConversion* pmTo
UPMRule, | 160 PMConversion* pmTo
UPMRule, |
| 157 PMConversion* upmT
oPMRule) { | 161 PMConversion* upmT
oPMRule) { |
| 158 *pmToUPMRule = kNone_PMConversion; | 162 *pmToUPMRule = kNone_PMConversion; |
| 159 *upmToPMRule = kNone_PMConversion; | 163 *upmToPMRule = kNone_PMConversion; |
| 160 SkAutoTMalloc<uint32_t> data(256 * 256 * 3); | 164 SkAutoTMalloc<uint32_t> data(256 * 256 * 3); |
| 161 uint32_t* srcData = data.get(); | 165 uint32_t* srcData = data.get(); |
| 162 uint32_t* firstRead = data.get() + 256 * 256; | 166 uint32_t* firstRead = data.get() + 256 * 256; |
| 163 uint32_t* secondRead = data.get() + 2 * 256 * 256; | 167 uint32_t* secondRead = data.get() + 2 * 256 * 256; |
| 164 | 168 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 kNone_PMConversion != pmConversion) { | 278 kNone_PMConversion != pmConversion) { |
| 275 // The PM conversions assume colors are 0..255 | 279 // The PM conversions assume colors are 0..255 |
| 276 return NULL; | 280 return NULL; |
| 277 } | 281 } |
| 278 return SkNEW_ARGS(GrConfigConversionEffect, (texture, | 282 return SkNEW_ARGS(GrConfigConversionEffect, (texture, |
| 279 swapRedAndBlue, | 283 swapRedAndBlue, |
| 280 pmConversion, | 284 pmConversion, |
| 281 matrix)); | 285 matrix)); |
| 282 } | 286 } |
| 283 } | 287 } |
| OLD | NEW |