| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "gm.h" | 8 #include "gm.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkImageInfo.h" | 10 #include "SkImageInfo.h" |
| 11 #include "SkXfermode.h" | 11 #include "SkXfermode.h" |
| 12 | 12 |
| 13 static void draw_rect(SkCanvas* canvas, const SkRect& r, SkColor c, SkColorProfi
leType profile) { | 13 static void draw_rect(SkCanvas* canvas, const SkRect& r, SkColor c, SkColorProfi
leType profile, |
| 14 const SkAlpha aa[]) { |
| 14 const SkIRect ir = r.round(); | 15 const SkIRect ir = r.round(); |
| 15 | 16 |
| 16 SkBitmap bm; | 17 SkBitmap bm; |
| 17 bm.allocN32Pixels(ir.width(), ir.height()); | 18 bm.allocN32Pixels(ir.width(), ir.height()); |
| 18 bm.eraseColor(0xFFFFFFFF); | 19 bm.eraseColor(0xFFFFFFFF); |
| 19 SkPixmap pm; | 20 SkPixmap pm; |
| 20 bm.peekPixels(&pm); | 21 bm.peekPixels(&pm); |
| 21 | 22 |
| 22 uint32_t flags = 0; | 23 uint32_t flags = 0; |
| 23 if (SkColorGetA(c) == 0xFF) { | 24 if (SkColorGetA(c) == 0xFF) { |
| 24 flags |= SkXfermode::kSrcIsOpaque_PM4fFlag; | 25 flags |= SkXfermode::kSrcIsOpaque_PM4fFlag; |
| 25 } | 26 } |
| 26 if (kSRGB_SkColorProfileType == profile) { | 27 if (kSRGB_SkColorProfileType == profile) { |
| 27 flags |= SkXfermode::kDstIsSRGB_PM4fFlag; | 28 flags |= SkXfermode::kDstIsSRGB_PM4fFlag; |
| 28 } | 29 } |
| 29 | 30 |
| 30 const SkXfermode::PM4fState state { nullptr, flags }; | 31 const SkXfermode::PM4fState state { nullptr, flags }; |
| 31 | 32 |
| 32 const SkPM4f src = SkColor4f::FromColor(c).premul(); | 33 const SkPM4f src = SkColor4f::FromColor(c).premul(); |
| 33 auto proc1 = SkXfermode::GetPM4fProc1(SkXfermode::kSrcOver_Mode, flags); | 34 auto proc1 = SkXfermode::GetPM4fProc1(SkXfermode::kSrcOver_Mode, flags); |
| 34 for (int y = 0; y < ir.height()/2; ++y) { | 35 for (int y = 0; y < ir.height()/2; ++y) { |
| 35 proc1(state, pm.writable_addr32(0, y), src, ir.width(), nullptr); | 36 proc1(state, pm.writable_addr32(0, y), src, ir.width(), aa); |
| 36 } | 37 } |
| 37 | 38 |
| 38 SkPM4f srcRow[1000]; | 39 SkPM4f srcRow[1000]; |
| 39 for (int i = 0; i < ir.width(); ++i) { | 40 for (int i = 0; i < ir.width(); ++i) { |
| 40 srcRow[i] = src; | 41 srcRow[i] = src; |
| 41 } | 42 } |
| 42 auto procN = SkXfermode::GetPM4fProcN(SkXfermode::kSrcOver_Mode, flags); | 43 auto procN = SkXfermode::GetPM4fProcN(SkXfermode::kSrcOver_Mode, flags); |
| 43 // +1 to skip a row, so we can see the boundary between proc1 and procN | 44 // +1 to skip a row, so we can see the boundary between proc1 and procN |
| 44 for (int y = ir.height()/2 + 1; y < ir.height(); ++y) { | 45 for (int y = ir.height()/2 + 1; y < ir.height(); ++y) { |
| 45 procN(state, pm.writable_addr32(0, y), srcRow, ir.width(), nullptr); | 46 procN(state, pm.writable_addr32(0, y), srcRow, ir.width(), aa); |
| 46 } | 47 } |
| 47 | 48 |
| 48 canvas->drawBitmap(bm, r.left(), r.top(), nullptr); | 49 canvas->drawBitmap(bm, r.left(), r.top(), nullptr); |
| 49 } | 50 } |
| 50 | 51 |
| 51 /* | 52 /* |
| 52 * Test SkXfer4fProcs directly for src-over, comparing them to current SkColor
blits. | 53 * Test SkXfer4fProcs directly for src-over, comparing them to current SkColor
blits. |
| 53 */ | 54 */ |
| 54 DEF_SIMPLE_GM(xfer4f_srcover, canvas, 580, 380) { | 55 DEF_SIMPLE_GM(xfer4f_srcover, canvas, 580, 760) { |
| 55 const SkScalar W = 50; | 56 const int IW = 50; |
| 57 const SkScalar W = IW; |
| 56 const SkScalar H = 100; | 58 const SkScalar H = 100; |
| 57 | 59 |
| 58 const int profiles[] = { | 60 const int profiles[] = { |
| 59 -1, | 61 -1, |
| 60 kLinear_SkColorProfileType, | 62 kLinear_SkColorProfileType, |
| 61 kSRGB_SkColorProfileType, | 63 kSRGB_SkColorProfileType, |
| 62 }; | 64 }; |
| 63 const SkColor colors[] = { | 65 const SkColor colors[] = { |
| 64 SK_ColorBLACK, SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, | 66 SK_ColorBLACK, SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, |
| 65 0x88000000, 0x88FF0000, 0x8800FF00, 0x880000FF | 67 0x88000000, 0x88FF0000, 0x8800FF00, 0x880000FF |
| 66 }; | 68 }; |
| 69 |
| 70 uint8_t aa_scanline[IW]; |
| 71 for (int i = 0; i < IW; ++i) { |
| 72 aa_scanline[i] = i * 255 / (IW - 1); |
| 73 } |
| 74 uint8_t const* aa_table[] = { nullptr, aa_scanline }; |
| 75 |
| 76 SkBitmap mask; |
| 77 mask.installPixels(SkImageInfo::MakeA8(IW, 1), aa_scanline, IW); |
| 78 |
| 67 canvas->translate(20, 20); | 79 canvas->translate(20, 20); |
| 68 | 80 |
| 69 const SkRect r = SkRect::MakeWH(W, H); | 81 const SkRect r = SkRect::MakeWH(W, H); |
| 70 for (auto profile : profiles) { | 82 for (const uint8_t* aa : aa_table) { |
| 71 canvas->save(); | 83 canvas->save(); |
| 72 for (SkColor c : colors) { | 84 for (auto profile : profiles) { |
| 73 if (profile < 0) { | 85 canvas->save(); |
| 74 SkPaint p; | 86 for (SkColor c : colors) { |
| 75 p.setColor(c); | 87 if (profile < 0) { |
| 76 canvas->drawRect(r, p); | 88 SkPaint p; |
| 77 } else { | 89 p.setColor(c); |
| 78 draw_rect(canvas, r, c, (SkColorProfileType)profile); | 90 if (aa) { |
| 91 canvas->drawBitmapRect(mask, r, &p); |
| 92 } else { |
| 93 canvas->drawRect(r, p); |
| 94 } |
| 95 } else { |
| 96 draw_rect(canvas, r, c, (SkColorProfileType)profile, aa); |
| 97 } |
| 98 canvas->translate(W + 20, 0); |
| 79 } | 99 } |
| 80 canvas->translate(W + 20, 0); | 100 canvas->restore(); |
| 101 canvas->translate(0, H + 20); |
| 81 } | 102 } |
| 82 canvas->restore(); | 103 canvas->restore(); |
| 83 canvas->translate(0, H + 20); | 104 canvas->translate(0, (H + 20) * SK_ARRAY_COUNT(profiles) + 20); |
| 84 } | 105 } |
| 85 } | 106 } |
| OLD | NEW |