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 
14 class SkBlitRow {
15 public:
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 provide the dithering phase for the start of the scanline
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 (*Proc16)(uint16_t dst[], const SkPMColor src[], int count,
36                            U8CPU alpha, int x, int y);
37 
38     static Proc16 Factory16(unsigned flags);
39 
40     /**
41      *  Function pointer that blends a single src color onto a scaline of dst colors.
42      *
43      *  The x,y params provide the dithering phase for the start of the scanline
44      */
45     typedef void (*ColorProc16)(uint16_t dst[], SkPMColor src, int count, int x, int y);
46 
47     // Note : we ignore the kGlobalAlpha_Flag setting, but do respect kSrcPixelAlpha_Flag
48     static ColorProc16 ColorFactory16(unsigned flags);
49 
50     ///////////// D32 version
51 
52     enum Flags32 {
53         kGlobalAlpha_Flag32     = 1 << 0,
54         kSrcPixelAlpha_Flag32   = 1 << 1
55     };
56 
57     /** Function pointer that blends 32bit colors onto a 32bit destination.
58         @param dst  array of dst 32bit colors
59         @param src  array of src 32bit colors (w/ or w/o alpha)
60         @param count number of colors to blend
61         @param alpha global alpha to be applied to all src colors
62      */
63     typedef void (*Proc32)(uint32_t dst[], const SkPMColor src[], 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[], int count, SkPMColor color);
72 
73     /** These static functions are called by the Factory and Factory32
74         functions, and should return either NULL, or a
75         platform-specific function-ptr to be used in place of the
76         system default.
77      */
78 
79     static Proc32 PlatformProcs32(unsigned flags);
80 
81     static Proc16 PlatformFactory565(unsigned flags);
82     static ColorProc16 PlatformColorFactory565(unsigned flags);
83 
84 private:
85     enum {
86         kFlags16_Mask = 7,
87         kFlags32_Mask = 3
88     };
89 };
90 
91 #endif
92