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