SkCoreBlitters.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 SkCoreBlitters_DEFINED
  8. #define SkCoreBlitters_DEFINED
  9. #include "include/core/SkPaint.h"
  10. #include "src/core/SkBlitRow.h"
  11. #include "src/core/SkBlitter.h"
  12. #include "src/core/SkXfermodePriv.h"
  13. #include "src/shaders/SkBitmapProcShader.h"
  14. #include "src/shaders/SkShaderBase.h"
  15. class SkRasterBlitter : public SkBlitter {
  16. public:
  17. SkRasterBlitter(const SkPixmap& device) : fDevice(device) {}
  18. protected:
  19. const SkPixmap fDevice;
  20. private:
  21. typedef SkBlitter INHERITED;
  22. };
  23. class SkShaderBlitter : public SkRasterBlitter {
  24. public:
  25. /**
  26. * The storage for shaderContext is owned by the caller, but the object itself is not.
  27. * The blitter only ensures that the storage always holds a live object, but it may
  28. * exchange that object.
  29. */
  30. SkShaderBlitter(const SkPixmap& device, const SkPaint& paint,
  31. SkShaderBase::Context* shaderContext);
  32. virtual ~SkShaderBlitter();
  33. protected:
  34. uint32_t fShaderFlags;
  35. const SkShader* fShader;
  36. SkShaderBase::Context* fShaderContext;
  37. bool fConstInY;
  38. private:
  39. // illegal
  40. SkShaderBlitter& operator=(const SkShaderBlitter&);
  41. typedef SkRasterBlitter INHERITED;
  42. };
  43. ///////////////////////////////////////////////////////////////////////////////
  44. class SkA8_Coverage_Blitter : public SkRasterBlitter {
  45. public:
  46. SkA8_Coverage_Blitter(const SkPixmap& device, const SkPaint& paint);
  47. void blitH(int x, int y, int width) override;
  48. void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
  49. void blitV(int x, int y, int height, SkAlpha alpha) override;
  50. void blitRect(int x, int y, int width, int height) override;
  51. void blitMask(const SkMask&, const SkIRect&) override;
  52. const SkPixmap* justAnOpaqueColor(uint32_t*) override;
  53. private:
  54. typedef SkRasterBlitter INHERITED;
  55. };
  56. ////////////////////////////////////////////////////////////////
  57. class SkARGB32_Blitter : public SkRasterBlitter {
  58. public:
  59. SkARGB32_Blitter(const SkPixmap& device, const SkPaint& paint);
  60. void blitH(int x, int y, int width) override;
  61. void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
  62. void blitV(int x, int y, int height, SkAlpha alpha) override;
  63. void blitRect(int x, int y, int width, int height) override;
  64. void blitMask(const SkMask&, const SkIRect&) override;
  65. const SkPixmap* justAnOpaqueColor(uint32_t*) override;
  66. void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
  67. void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
  68. protected:
  69. SkColor fColor;
  70. SkPMColor fPMColor;
  71. private:
  72. unsigned fSrcA, fSrcR, fSrcG, fSrcB;
  73. // illegal
  74. SkARGB32_Blitter& operator=(const SkARGB32_Blitter&);
  75. typedef SkRasterBlitter INHERITED;
  76. };
  77. class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter {
  78. public:
  79. SkARGB32_Opaque_Blitter(const SkPixmap& device, const SkPaint& paint)
  80. : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); }
  81. void blitMask(const SkMask&, const SkIRect&) override;
  82. void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
  83. void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
  84. private:
  85. typedef SkARGB32_Blitter INHERITED;
  86. };
  87. class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter {
  88. public:
  89. SkARGB32_Black_Blitter(const SkPixmap& device, const SkPaint& paint)
  90. : INHERITED(device, paint) {}
  91. void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
  92. void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
  93. void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
  94. private:
  95. typedef SkARGB32_Opaque_Blitter INHERITED;
  96. };
  97. class SkARGB32_Shader_Blitter : public SkShaderBlitter {
  98. public:
  99. SkARGB32_Shader_Blitter(const SkPixmap& device, const SkPaint& paint,
  100. SkShaderBase::Context* shaderContext);
  101. ~SkARGB32_Shader_Blitter() override;
  102. void blitH(int x, int y, int width) override;
  103. void blitV(int x, int y, int height, SkAlpha alpha) override;
  104. void blitRect(int x, int y, int width, int height) override;
  105. void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
  106. void blitMask(const SkMask&, const SkIRect&) override;
  107. private:
  108. SkXfermode* fXfermode;
  109. SkPMColor* fBuffer;
  110. SkBlitRow::Proc32 fProc32;
  111. SkBlitRow::Proc32 fProc32Blend;
  112. bool fShadeDirectlyIntoDevice;
  113. // illegal
  114. SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&);
  115. typedef SkShaderBlitter INHERITED;
  116. };
  117. ///////////////////////////////////////////////////////////////////////////////////////////////////
  118. typedef void (*SkS32D16BlendProc)(uint16_t*, const SkPMColor*, int, uint8_t);
  119. class SkRGB565_Shader_Blitter : public SkShaderBlitter {
  120. public:
  121. SkRGB565_Shader_Blitter(const SkPixmap& device, const SkPaint&, SkShaderBase::Context*);
  122. ~SkRGB565_Shader_Blitter() override;
  123. void blitH(int x, int y, int width) override;
  124. void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
  125. static bool Supports(const SkPixmap& device, const SkPaint&);
  126. private:
  127. SkPMColor* fBuffer;
  128. SkS32D16BlendProc fBlend;
  129. SkS32D16BlendProc fBlendCoverage;
  130. typedef SkShaderBlitter INHERITED;
  131. };
  132. ///////////////////////////////////////////////////////////////////////////////
  133. // Neither of these ever returns nullptr, but this first factory may return a SkNullBlitter.
  134. SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap&, const SkPaint&, const SkMatrix& ctm,
  135. SkArenaAlloc*);
  136. // Use this if you've pre-baked a shader pipeline, including modulating with paint alpha.
  137. // This factory never returns an SkNullBlitter.
  138. SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap&, const SkPaint&,
  139. const SkRasterPipeline& shaderPipeline,
  140. bool shader_is_opaque,
  141. SkArenaAlloc*);
  142. #endif