OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 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 #include "gm.h" | |
9 #include "SkCanvas.h" | |
10 #include "SkImageInfo.h" | |
11 #include "SkXfer4f.h" | |
12 | |
13 static void draw_rect(SkCanvas* canvas, const SkRect& r, SkColor c, SkColorProfi leType profile) { | |
14 const SkIRect ir = r.round(); | |
15 | |
16 SkBitmap bm; | |
17 bm.allocN32Pixels(ir.width(), ir.height()); | |
18 bm.eraseColor(0xFFFFFFFF); | |
19 SkPixmap pm; | |
20 bm.peekPixels(&pm); | |
21 | |
22 uint32_t flags = 0; | |
23 if (SkColorGetA(c) == 0xFF) { | |
24 flags |= kSrcIsOpaque_SkXfer4fFlag; | |
25 } | |
26 if (kSRGB_SkColorProfileType == profile) { | |
27 flags |= kDstIsSRGB_SkXfer4fFlag; | |
28 } | |
29 | |
30 const SkPM4f src = SkPM4f::FromPMColor(SkPreMultiplyColor(c)); | |
mtklein
2016/01/29 15:23:00
Just had a thought that we might want to generally
reed1
2016/01/29 22:35:27
Totally agree, was just being lazy since I already
| |
31 auto proc1 = SkPM4fXfer1ProcFactory(SkXfermode::kSrcOver_Mode, flags); | |
32 for (int y = 0; y < ir.height()/2; ++y) { | |
33 proc1(pm.writable_addr32(0, y), src, ir.width()); | |
34 } | |
35 | |
36 SkPM4f srcRow[1000]; | |
37 for (int i = 0; i < ir.width(); ++i) { | |
38 srcRow[i] = src; | |
39 } | |
40 auto procN = SkPM4fXferNProcFactory(SkXfermode::kSrcOver_Mode, flags); | |
41 // +1 to skip a row, so we can see the boundary between proc1 and procN | |
42 for (int y = ir.height()/2 + 1; y < ir.height(); ++y) { | |
43 procN(pm.writable_addr32(0, y), srcRow, ir.width()); | |
44 } | |
45 | |
46 canvas->drawBitmap(bm, r.left(), r.top(), nullptr); | |
47 } | |
48 | |
49 /* | |
50 * Test SkXfer4fProcs directly for src-over, comparing them to current SkColor blits. | |
51 */ | |
52 DEF_SIMPLE_GM(xfer4f_srcover, canvas, 580, 380) { | |
53 const SkScalar W = 50; | |
54 const SkScalar H = 100; | |
55 | |
56 const int profiles[] = { | |
57 -1, | |
58 kLinear_SkColorProfileType, | |
59 kSRGB_SkColorProfileType, | |
60 }; | |
61 const SkColor colors[] = { | |
62 SK_ColorBLACK, SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, | |
63 0x88000000, 0x88FF0000, 0x8800FF00, 0x880000FF | |
64 }; | |
65 canvas->translate(20, 20); | |
66 | |
67 const SkRect r = SkRect::MakeWH(W, H); | |
68 for (auto profile : profiles) { | |
69 canvas->save(); | |
70 for (SkColor c : colors) { | |
71 if (profile < 0) { | |
72 SkPaint p; | |
73 p.setColor(c); | |
74 canvas->drawRect(r, p); | |
75 } else { | |
76 draw_rect(canvas, r, c, (SkColorProfileType)profile); | |
77 } | |
78 canvas->translate(W + 20, 0); | |
79 } | |
80 canvas->restore(); | |
81 canvas->translate(0, H + 20); | |
82 } | |
83 } | |
OLD | NEW |