1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/effects/GrConfigConversionEffect.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,78 @@ 1.4 +/* 1.5 + * Copyright 2012 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef GrConfigConversionEffect_DEFINED 1.12 +#define GrConfigConversionEffect_DEFINED 1.13 + 1.14 +#include "GrSingleTextureEffect.h" 1.15 + 1.16 +class GrEffectStage; 1.17 +class GrGLConfigConversionEffect; 1.18 + 1.19 +/** 1.20 + * This class is used to perform config conversions. Clients may want to read/write data that is 1.21 + * unpremultiplied. Also on some systems reading/writing BGRA or RGBA is faster. In those cases we 1.22 + * read/write using the faster path and perform an R/B swap in the shader if the client data is in 1.23 + * the slower config. 1.24 + */ 1.25 +class GrConfigConversionEffect : public GrSingleTextureEffect { 1.26 +public: 1.27 + /** 1.28 + * The PM->UPM or UPM->PM conversions to apply. 1.29 + */ 1.30 + enum PMConversion { 1.31 + kNone_PMConversion = 0, 1.32 + kMulByAlpha_RoundUp_PMConversion, 1.33 + kMulByAlpha_RoundDown_PMConversion, 1.34 + kDivByAlpha_RoundUp_PMConversion, 1.35 + kDivByAlpha_RoundDown_PMConversion, 1.36 + 1.37 + kPMConversionCnt 1.38 + }; 1.39 + 1.40 + // Installs an effect in the GrEffectStage to perform a config conversion. 1.41 + static const GrEffectRef* Create(GrTexture*, 1.42 + bool swapRedAndBlue, 1.43 + PMConversion pmConversion, 1.44 + const SkMatrix& matrix); 1.45 + 1.46 + static const char* Name() { return "Config Conversion"; } 1.47 + typedef GrGLConfigConversionEffect GLEffect; 1.48 + 1.49 + virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 1.50 + 1.51 + virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; 1.52 + 1.53 + bool swapsRedAndBlue() const { return fSwapRedAndBlue; } 1.54 + PMConversion pmConversion() const { return fPMConversion; } 1.55 + 1.56 + // This function determines whether it is possible to choose PM->UPM and UPM->PM conversions 1.57 + // for which in any PM->UPM->PM->UPM sequence the two UPM values are the same. This means that 1.58 + // if pixels are read back to a UPM buffer, written back to PM to the GPU, and read back again 1.59 + // both reads will produce the same result. This test is quite expensive and should not be run 1.60 + // multiple times for a given context. 1.61 + static void TestForPreservingPMConversions(GrContext* context, 1.62 + PMConversion* PMToUPMRule, 1.63 + PMConversion* UPMToPMRule); 1.64 + 1.65 +private: 1.66 + GrConfigConversionEffect(GrTexture*, 1.67 + bool swapRedAndBlue, 1.68 + PMConversion pmConversion, 1.69 + const SkMatrix& matrix); 1.70 + 1.71 + virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; 1.72 + 1.73 + bool fSwapRedAndBlue; 1.74 + PMConversion fPMConversion; 1.75 + 1.76 + GR_DECLARE_EFFECT_TEST; 1.77 + 1.78 + typedef GrSingleTextureEffect INHERITED; 1.79 +}; 1.80 + 1.81 +#endif