| 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 "SkBitmapProcShader.h" | 8 #include "SkBitmapProcShader.h" |
| 9 #include "SkColor.h" | 9 #include "SkColor.h" |
| 10 #include "SkColorMatrixFilter.h" | 10 #include "SkColorMatrixFilter.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 return true; | 32 return true; |
| 33 } | 33 } |
| 34 | 34 |
| 35 DEF_TEST(SkColor4f_FromColor, reporter) { | 35 DEF_TEST(SkColor4f_FromColor, reporter) { |
| 36 const struct { | 36 const struct { |
| 37 SkColor fC; | 37 SkColor fC; |
| 38 SkColor4f fC4; | 38 SkColor4f fC4; |
| 39 } recs[] = { | 39 } recs[] = { |
| 40 { SK_ColorBLACK, { 1, 0, 0, 0 } }, | 40 { SK_ColorBLACK, { 0, 0, 0, 1 } }, |
| 41 { SK_ColorWHITE, { 1, 1, 1, 1 } }, | 41 { SK_ColorWHITE, { 1, 1, 1, 1 } }, |
| 42 { SK_ColorRED, { 1, 1, 0, 0 } }, | 42 { SK_ColorRED, { 1, 0, 0, 1 } }, |
| 43 { SK_ColorGREEN, { 1, 0, 1, 0 } }, | 43 { SK_ColorGREEN, { 0, 1, 0, 1 } }, |
| 44 { SK_ColorBLUE, { 1, 0, 0, 1 } }, | 44 { SK_ColorBLUE, { 0, 0, 1, 1 } }, |
| 45 { 0, { 0, 0, 0, 0 } }, | 45 { 0, { 0, 0, 0, 0 } }, |
| 46 { 0x55AAFF00, { 1/3.0f, 2/3.0f, 1, 0 } }, | 46 { 0x55AAFF00, { 2/3.0f, 1, 0, 1 / 3.0f } }, |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 for (const auto& r : recs) { | 49 for (const auto& r : recs) { |
| 50 SkColor4f c4 = SkColor4f::FromColor(r.fC); | 50 SkColor4f c4 = SkColor4f::FromColor(r.fC); |
| 51 REPORTER_ASSERT(reporter, c4 == r.fC4); | 51 REPORTER_ASSERT(reporter, c4 == r.fC4); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 DEF_TEST(Color4f_premul, reporter) { | 55 DEF_TEST(Color4f_premul, reporter) { |
| 56 SkRandom rand; | 56 SkRandom rand; |
| 57 | 57 |
| 58 for (int i = 0; i < 1000000; ++i) { | 58 for (int i = 0; i < 1000000; ++i) { |
| 59 // First just test opaque colors, so that the premul should be exact | 59 // First just test opaque colors, so that the premul should be exact |
| 60 SkColor4f c4 { | 60 SkColor4f c4 { |
| 61 1, rand.nextUScalar1(), rand.nextUScalar1(), rand.nextUScalar1() | 61 rand.nextUScalar1(), rand.nextUScalar1(), rand.nextUScalar1(), 1 |
| 62 }; | 62 }; |
| 63 SkPM4f pm4 = c4.premul(); | 63 SkPM4f pm4 = c4.premul(); |
| 64 REPORTER_ASSERT(reporter, pm4.a() == c4.fA); | 64 REPORTER_ASSERT(reporter, pm4.a() == c4.fA); |
| 65 REPORTER_ASSERT(reporter, pm4.r() == c4.fA * c4.fR); | 65 REPORTER_ASSERT(reporter, pm4.r() == c4.fA * c4.fR); |
| 66 REPORTER_ASSERT(reporter, pm4.g() == c4.fA * c4.fG); | 66 REPORTER_ASSERT(reporter, pm4.g() == c4.fA * c4.fG); |
| 67 REPORTER_ASSERT(reporter, pm4.b() == c4.fA * c4.fB); | 67 REPORTER_ASSERT(reporter, pm4.b() == c4.fA * c4.fB); |
| 68 | 68 |
| 69 // We compare with a tolerance, in case our premul multiply is implement
ed at slightly | 69 // We compare with a tolerance, in case our premul multiply is implement
ed at slightly |
| 70 // different precision than the test code. | 70 // different precision than the test code. |
| 71 c4.fA = rand.nextUScalar1(); | 71 c4.fA = rand.nextUScalar1(); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // | 241 // |
| 242 DEF_TEST(Color4f_xfermode_proc4f, reporter) { | 242 DEF_TEST(Color4f_xfermode_proc4f, reporter) { |
| 243 // TODO: extend xfermodes so that all cases can be tested. | 243 // TODO: extend xfermodes so that all cases can be tested. |
| 244 // | 244 // |
| 245 for (int mode = SkXfermode::kClear_Mode; mode <= SkXfermode::kScreen_Mode; +
+mode) { | 245 for (int mode = SkXfermode::kClear_Mode; mode <= SkXfermode::kScreen_Mode; +
+mode) { |
| 246 SkXfermodeProc proc32 = SkXfermode::GetProc((SkXfermode::Mode)mode); | 246 SkXfermodeProc proc32 = SkXfermode::GetProc((SkXfermode::Mode)mode); |
| 247 SkXfermodeProc4f proc4f = SkXfermode::GetProc4f((SkXfermode::Mode)mode); | 247 SkXfermodeProc4f proc4f = SkXfermode::GetProc4f((SkXfermode::Mode)mode); |
| 248 REPORTER_ASSERT(reporter, compare_procs(proc32, proc4f)); | 248 REPORTER_ASSERT(reporter, compare_procs(proc32, proc4f)); |
| 249 } | 249 } |
| 250 } | 250 } |
| OLD | NEW |