1 /* 2 * Copyright 2015 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 SkXfermode_proccoeff_DEFINED 9 #define SkXfermode_proccoeff_DEFINED 10 11 #include "SkXfermode.h" 12 #include "SkReadBuffer.h" 13 #include "SkWriteBuffer.h" 14 15 struct ProcCoeff { 16 SkXfermodeProc fProc; 17 SkXfermodeProc4f fProc4f; 18 SkXfermode::Coeff fSC; 19 SkXfermode::Coeff fDC; 20 }; 21 22 #define CANNOT_USE_COEFF SkXfermode::Coeff(-1) 23 24 class SK_API SkProcCoeffXfermode : public SkXfermode { 25 public: SkProcCoeffXfermode(const ProcCoeff & rec,Mode mode)26 SkProcCoeffXfermode(const ProcCoeff& rec, Mode mode) { 27 fMode = mode; 28 fProc = rec.fProc; 29 // these may be valid, or may be CANNOT_USE_COEFF 30 fSrcCoeff = rec.fSC; 31 fDstCoeff = rec.fDC; 32 } 33 34 void xfer32(SkPMColor dst[], const SkPMColor src[], int count, 35 const SkAlpha aa[]) const override; 36 void xfer16(uint16_t dst[], const SkPMColor src[], int count, 37 const SkAlpha aa[]) const override; 38 void xferA8(SkAlpha dst[], const SkPMColor src[], int count, 39 const SkAlpha aa[]) const override; 40 41 bool asMode(Mode* mode) const override; 42 43 bool supportsCoverageAsAlpha() const override; 44 45 bool isOpaque(SkXfermode::SrcColorOpacity opacityType) const override; 46 47 #if SK_SUPPORT_GPU 48 const GrFragmentProcessor* getFragmentProcessorForImageFilter( 49 const GrFragmentProcessor*) const override; 50 GrXPFactory* asXPFactory() const override; 51 #endif 52 53 SK_TO_STRING_OVERRIDE() 54 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkProcCoeffXfermode) 55 56 protected: 57 void flatten(SkWriteBuffer& buffer) const override; 58 getMode()59 Mode getMode() const { return fMode; } 60 getProc()61 SkXfermodeProc getProc() const { return fProc; } 62 63 private: 64 SkXfermodeProc fProc; 65 Mode fMode; 66 Coeff fSrcCoeff, fDstCoeff; 67 68 friend class SkXfermode; 69 70 typedef SkXfermode INHERITED; 71 }; 72 73 #endif // #ifndef SkXfermode_proccoeff_DEFINED 74