Home | History | Annotate | Download | only in core
      1 #ifndef SkBlitRow_DEFINED
      2 #define SkBlitRow_DEFINED
      3 
      4 #include "SkBitmap.h"
      5 #include "SkColor.h"
      6 
      7 class SkBlitRow {
      8 public:
      9     enum Flags16 {
     10         //! If set, the alpha parameter will be != 255
     11         kGlobalAlpha_Flag   = 0x01,
     12         //! If set, the src colors may have alpha != 255
     13         kSrcPixelAlpha_Flag = 0x02,
     14         //! If set, the resulting 16bit colors should be dithered
     15         kDither_Flag        = 0x04
     16     };
     17 
     18     /** Function pointer that reads a scanline of src SkPMColors, and writes
     19         a corresponding scanline of 16bit colors (specific format based on the
     20         config passed to the Factory.
     21 
     22         The x,y params are useful just for dithering
     23 
     24         @param alpha A global alpha to be applied to all of the src colors
     25         @param x The x coordinate of the beginning of the scanline
     26         @param y THe y coordinate of the scanline
     27      */
     28     typedef void (*Proc)(uint16_t* SK_RESTRICT dst,
     29                          const SkPMColor* SK_RESTRICT src,
     30                          int count, U8CPU alpha, int x, int y);
     31 
     32    /** Function pointer that blends a single color with a row of 32-bit colors
     33        onto a 32-bit destination
     34    */
     35    typedef void (*ColorProc)(SkPMColor* dst, const SkPMColor* src, int count,
     36                              SkPMColor color);
     37 
     38     //! Public entry-point to return a blit function ptr
     39     static Proc Factory(unsigned flags, SkBitmap::Config);
     40 
     41     ///////////// D32 version
     42 
     43     enum Flags32 {
     44         kGlobalAlpha_Flag32     = 1 << 0,
     45         kSrcPixelAlpha_Flag32   = 1 << 1,
     46     };
     47 
     48     /** Function pointer that blends 32bit colors onto a 32bit destination.
     49         @param dst  array of dst 32bit colors
     50         @param src  array of src 32bit colors (w/ or w/o alpha)
     51         @param count number of colors to blend
     52         @param alpha global alpha to be applied to all src colors
     53      */
     54     typedef void (*Proc32)(uint32_t* SK_RESTRICT dst,
     55                          const SkPMColor* SK_RESTRICT src,
     56                          int count, U8CPU alpha);
     57 
     58     static Proc32 Factory32(unsigned flags32);
     59 
     60     /** Blend a single color onto a row of S32 pixels, writing the result
     61         into a row of D32 pixels. src and dst may be the same memory, but
     62         if they are not, they may not overlap.
     63      */
     64     static void Color32(SkPMColor dst[], const SkPMColor src[],
     65                         int count, SkPMColor color);
     66 
     67     static ColorProc ColorProcFactory();
     68 
     69     /** These static functions are called by the Factory and Factory32
     70         functions, and should return either NULL, or a
     71         platform-specific function-ptr to be used in place of the
     72         system default.
     73      */
     74 
     75     static Proc32 PlatformProcs32(unsigned flags);
     76     static Proc PlatformProcs565(unsigned flags);
     77     static Proc PlatformProcs4444(unsigned flags);
     78     static ColorProc PlatformColorProc();
     79 
     80 private:
     81     enum {
     82         kFlags16_Mask = 7,
     83         kFlags32_Mask = 3
     84     };
     85 };
     86 
     87 /**
     88  *  Factory for blitmask procs
     89  */
     90 class SkBlitMask {
     91 public:
     92     /**
     93      *  Function pointer that blits the mask into a device (dst) colorized
     94      *  by color. The number of pixels to blit is specified by width and height,
     95      *  but each scanline is offset by dstRB (rowbytes) and srcRB respectively.
     96      */
     97     typedef void (*Proc)(void* dst, size_t dstRB, SkBitmap::Config dstConfig,
     98                         const uint8_t* mask, size_t maskRB, SkColor color,
     99                         int width, int height);
    100 
    101     /* Public entry-point to return a blitmask function ptr
    102      */
    103     static Proc Factory(SkBitmap::Config dstConfig, SkColor color);
    104 
    105     /* return either platform specific optimized blitmask function-ptr,
    106      * or NULL if no optimized
    107      */
    108     static Proc PlatformProcs(SkBitmap::Config dstConfig, SkColor color);
    109 };
    110 
    111 
    112 #endif
    113