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 8 #ifndef SkCoreBlitters_DEFINED 9 #define SkCoreBlitters_DEFINED 10 11 #include "include/core/SkColor.h" 12 #include "include/core/SkPaint.h" 13 #include "include/core/SkPixmap.h" 14 #include "include/core/SkRefCnt.h" 15 #include "include/private/base/SkAssert.h" 16 #include "include/private/base/SkCPUTypes.h" 17 #include "src/core/SkBlitRow.h" 18 #include "src/core/SkBlitter.h" 19 #include "src/shaders/SkShaderBase.h" 20 21 #include <cstdint> 22 23 class SkArenaAlloc; 24 class SkMatrix; 25 class SkRasterPipeline; 26 class SkShader; 27 class SkSurfaceProps; 28 struct SkIRect; 29 struct SkMask; 30 31 class SkRasterBlitter : public SkBlitter { 32 public: SkRasterBlitter(const SkPixmap & device)33 SkRasterBlitter(const SkPixmap& device) : fDevice(device) {} 34 35 protected: 36 const SkPixmap fDevice; 37 }; 38 39 class SkShaderBlitter : public SkRasterBlitter { 40 public: 41 /** 42 * The storage for shaderContext is owned by the caller, but the object itself is not. 43 * The blitter only ensures that the storage always holds a live object, but it may 44 * exchange that object. 45 */ 46 SkShaderBlitter(const SkPixmap& device, const SkPaint& paint, 47 SkShaderBase::Context* shaderContext); 48 ~SkShaderBlitter() override; 49 50 protected: 51 sk_sp<SkShader> fShader; 52 SkShaderBase::Context* fShaderContext; 53 }; 54 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 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; 66 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; 67 68 protected: 69 SkColor fColor; 70 SkPMColor fPMColor; 71 SkAlpha fSrcA; 72 }; 73 74 class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter { 75 public: SkARGB32_Opaque_Blitter(const SkPixmap & device,const SkPaint & paint)76 SkARGB32_Opaque_Blitter(const SkPixmap& device, const SkPaint& paint) 77 : SkARGB32_Blitter(device, paint) { 78 SkASSERT(paint.getAlpha() == 0xFF); 79 } 80 void blitMask(const SkMask&, const SkIRect&) override; 81 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) 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 }; 85 86 class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter { 87 public: SkARGB32_Black_Blitter(const SkPixmap & device,const SkPaint & paint)88 SkARGB32_Black_Blitter(const SkPixmap& device, const SkPaint& paint) 89 : SkARGB32_Opaque_Blitter(device, paint) { 90 SkASSERT(paint.getColor() == SK_ColorBLACK); 91 } 92 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override; 93 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; 94 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; 95 }; 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 108 private: 109 SkPMColor* fBuffer; 110 SkBlitRow::Proc32 fProc32; 111 SkBlitRow::Proc32 fProc32Blend; 112 bool fShadeDirectlyIntoDevice; 113 }; 114 115 /////////////////////////////////////////////////////////////////////////////////////////////////// 116 117 SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap&, 118 const SkPaint&, 119 const SkMatrix& ctm, 120 SkArenaAlloc*, 121 sk_sp<SkShader> clipShader, 122 const SkSurfaceProps& props); 123 // Use this if you've pre-baked a shader pipeline, including modulating with paint alpha. 124 SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap&, const SkPaint&, 125 const SkRasterPipeline& shaderPipeline, 126 bool shader_is_opaque, 127 SkArenaAlloc*, sk_sp<SkShader> clipShader); 128 129 #endif 130