SkXfermodePriv.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2006 The Android Open Source Project
  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. #ifndef SkXfermodePriv_DEFINED
  8. #define SkXfermodePriv_DEFINED
  9. #include "include/core/SkBlendMode.h"
  10. #include "include/core/SkColor.h"
  11. #include "include/core/SkRefCnt.h"
  12. class GrFragmentProcessor;
  13. class GrTexture;
  14. class GrXPFactory;
  15. class SkRasterPipeline;
  16. class SkString;
  17. class SkXfermode : public SkRefCnt {
  18. public:
  19. virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
  20. const SkAlpha aa[]) const = 0;
  21. /** Return an SkXfermode object for the specified mode.
  22. */
  23. static sk_sp<SkXfermode> Make(SkBlendMode);
  24. /**
  25. * Skia maintains global xfermode objects corresponding to each BlendMode. This returns a
  26. * ptr to that global xfermode (or null if the mode is srcover). Thus the caller may use
  27. * the returned ptr, but it should leave its refcnt untouched.
  28. */
  29. static SkXfermode* Peek(SkBlendMode mode) {
  30. sk_sp<SkXfermode> xfer = Make(mode);
  31. if (!xfer) {
  32. SkASSERT(SkBlendMode::kSrcOver == mode);
  33. return nullptr;
  34. }
  35. SkASSERT(!xfer->unique());
  36. return xfer.get();
  37. }
  38. enum SrcColorOpacity {
  39. // The src color is known to be opaque (alpha == 255)
  40. kOpaque_SrcColorOpacity = 0,
  41. // The src color is known to be fully transparent (color == 0)
  42. kTransparentBlack_SrcColorOpacity = 1,
  43. // The src alpha is known to be fully transparent (alpha == 0)
  44. kTransparentAlpha_SrcColorOpacity = 2,
  45. // The src color opacity is unknown
  46. kUnknown_SrcColorOpacity = 3
  47. };
  48. static bool IsOpaque(SkBlendMode, SrcColorOpacity);
  49. protected:
  50. SkXfermode() {}
  51. };
  52. #endif