Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: src/core/SkBlitMask_D32.cpp

Issue 1278253003: Sk4px blit mask. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: note overflow Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkBlitMask.h ('k') | src/core/SkOpts.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBlitMask.h" 8 #include "SkBlitMask.h"
9 #include "SkColor.h" 9 #include "SkColor.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 11 #include "SkOpts.h"
12 static void D32_A8_Color(void* SK_RESTRICT dst, size_t dstRB,
13 const void* SK_RESTRICT maskPtr, size_t maskRB,
14 SkColor color, int width, int height) {
15 SkPMColor pmc = SkPreMultiplyColor(color);
16 size_t dstOffset = dstRB - (width << 2);
17 size_t maskOffset = maskRB - width;
18 SkPMColor* SK_RESTRICT device = (SkPMColor *)dst;
19 const uint8_t* SK_RESTRICT mask = (const uint8_t*)maskPtr;
20
21 do {
22 int w = width;
23 do {
24 unsigned aa = *mask++;
25 *device = SkBlendARGB32(pmc, *device, aa);
26 device += 1;
27 } while (--w != 0);
28 device = (uint32_t*)((char*)device + dstOffset);
29 mask += maskOffset;
30 } while (--height != 0);
31 }
32
33 static void D32_A8_Opaque(void* SK_RESTRICT dst, size_t dstRB,
34 const void* SK_RESTRICT maskPtr, size_t maskRB,
35 SkColor color, int width, int height) {
36 SkPMColor pmc = SkPreMultiplyColor(color);
37 SkPMColor* SK_RESTRICT device = (SkPMColor*)dst;
38 const uint8_t* SK_RESTRICT mask = (const uint8_t*)maskPtr;
39
40 maskRB -= width;
41 dstRB -= (width << 2);
42 do {
43 int w = width;
44 do {
45 unsigned aa = *mask++;
46 *device = SkAlphaMulQ(pmc, SkAlpha255To256(aa)) + SkAlphaMulQ(*devic e, SkAlpha255To256(255 - aa));
47 device += 1;
48 } while (--w != 0);
49 device = (uint32_t*)((char*)device + dstRB);
50 mask += maskRB;
51 } while (--height != 0);
52 }
53
54 static void D32_A8_Black(void* SK_RESTRICT dst, size_t dstRB,
55 const void* SK_RESTRICT maskPtr, size_t maskRB,
56 SkColor, int width, int height) {
57 SkPMColor* SK_RESTRICT device = (SkPMColor*)dst;
58 const uint8_t* SK_RESTRICT mask = (const uint8_t*)maskPtr;
59
60 maskRB -= width;
61 dstRB -= (width << 2);
62 do {
63 int w = width;
64 do {
65 unsigned aa = *mask++;
66 *device = (aa << SK_A32_SHIFT) + SkAlphaMulQ(*device, SkAlpha255To25 6(255 - aa));
67 device += 1;
68 } while (--w != 0);
69 device = (uint32_t*)((char*)device + dstRB);
70 mask += maskRB;
71 } while (--height != 0);
72 }
73 12
74 SkBlitMask::BlitLCD16RowProc SkBlitMask::BlitLCD16RowFactory(bool isOpaque) { 13 SkBlitMask::BlitLCD16RowProc SkBlitMask::BlitLCD16RowFactory(bool isOpaque) {
75 BlitLCD16RowProc proc = PlatformBlitRowProcs16(isOpaque); 14 BlitLCD16RowProc proc = PlatformBlitRowProcs16(isOpaque);
76 if (proc) { 15 if (proc) {
77 return proc; 16 return proc;
78 } 17 }
79 18
80 if (isOpaque) { 19 if (isOpaque) {
81 return SkBlitLCD16OpaqueRow; 20 return SkBlitLCD16OpaqueRow;
82 } else { 21 } else {
(...skipping 22 matching lines...) Expand all
105 44
106 do { 45 do {
107 proc(dstRow, srcRow, color, width, opaqueDst); 46 proc(dstRow, srcRow, color, width, opaqueDst);
108 dstRow = (SkPMColor*)((char*)dstRow + dstRB); 47 dstRow = (SkPMColor*)((char*)dstRow + dstRB);
109 srcRow = (const uint16_t*)((const char*)srcRow + maskRB); 48 srcRow = (const uint16_t*)((const char*)srcRow + maskRB);
110 } while (--height != 0); 49 } while (--height != 0);
111 } 50 }
112 51
113 /////////////////////////////////////////////////////////////////////////////// 52 ///////////////////////////////////////////////////////////////////////////////
114 53
115 static SkBlitMask::ColorProc D32_A8_Factory(SkColor color) { 54 bool SkBlitMask::BlitColor(const SkPixmap& device, const SkMask& mask,
116 if (SK_ColorBLACK == color) { 55 const SkIRect& clip, SkColor color) {
117 return D32_A8_Black; 56 int x = clip.fLeft, y = clip.fTop;
118 } else if (0xFF == SkColorGetA(color)) {
119 return D32_A8_Opaque;
120 } else {
121 return D32_A8_Color;
122 }
123 }
124 57
125 SkBlitMask::ColorProc SkBlitMask::ColorFactory(SkColorType ct, 58 if (device.colorType() == kN32_SkColorType && mask.fFormat == SkMask::kA8_Fo rmat) {
126 SkMask::Format format, 59 SkOpts::blit_mask_d32_a8(device.writable_addr32(x,y), device.rowBytes(),
127 SkColor color) { 60 (const SkAlpha*)mask.getAddr(x,y), mask.fRowByt es,
128 ColorProc proc = PlatformColorProcs(ct, format, color); 61 color, clip.width(), clip.height());
129 if (proc) { 62 return true;
130 return proc;
131 } 63 }
132 64
133 switch (ct) { 65 if (device.colorType() == kN32_SkColorType && mask.fFormat == SkMask::kLCD16 _Format) {
134 case kN32_SkColorType: 66 // TODO: Is this reachable code? Seems like no.
135 switch (format) { 67 D32_LCD16_Proc(device.writable_addr32(x,y), device.rowBytes(),
136 case SkMask::kA8_Format: 68 mask.getAddr(x,y), mask.fRowBytes,
137 return D32_A8_Factory(color); 69 color, clip.width(), clip.height());
138 case SkMask::kLCD16_Format:
139 return D32_LCD16_Proc;
140 default:
141 break;
142 }
143 break;
144 default:
145 break;
146 }
147 return NULL;
148 }
149
150 bool SkBlitMask::BlitColor(const SkPixmap& device, const SkMask& mask,
151 const SkIRect& clip, SkColor color) {
152 ColorProc proc = ColorFactory(device.colorType(), mask.fFormat, color);
153 if (proc) {
154 int x = clip.fLeft;
155 int y = clip.fTop;
156 proc(device.writable_addr32(x, y), device.rowBytes(), mask.getAddr(x, y) ,
157 mask.fRowBytes, color, clip.width(), clip.height());
158 return true; 70 return true;
159 } 71 }
72
160 return false; 73 return false;
161 } 74 }
162 75
163 /////////////////////////////////////////////////////////////////////////////// 76 ///////////////////////////////////////////////////////////////////////////////
164 /////////////////////////////////////////////////////////////////////////////// 77 ///////////////////////////////////////////////////////////////////////////////
165 78
166 static void BW_RowProc_Blend(SkPMColor* SK_RESTRICT dst, 79 static void BW_RowProc_Blend(SkPMColor* SK_RESTRICT dst,
167 const uint8_t* SK_RESTRICT mask, 80 const uint8_t* SK_RESTRICT mask,
168 const SkPMColor* SK_RESTRICT src, int count) { 81 const SkPMColor* SK_RESTRICT src, int count) {
169 int i, octuple = (count + 7) >> 3; 82 int i, octuple = (count + 7) >> 3;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 if (flags & kSrcIsOpaque_RowFlag) { 302 if (flags & kSrcIsOpaque_RowFlag) {
390 index |= 1; 303 index |= 1;
391 } 304 }
392 SkASSERT((size_t)index < SK_ARRAY_COUNT(gProcs)); 305 SkASSERT((size_t)index < SK_ARRAY_COUNT(gProcs));
393 return gProcs[index]; 306 return gProcs[index];
394 default: 307 default:
395 break; 308 break;
396 } 309 }
397 return NULL; 310 return NULL;
398 } 311 }
OLDNEW
« no previous file with comments | « src/core/SkBlitMask.h ('k') | src/core/SkOpts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698