| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "SkColorFilter.h" | 9 #include "SkColorFilter.h" |
| 10 #include "Test.h" | 10 #include "Test.h" |
| 11 | 11 |
| 12 #if SK_SUPPORT_GPU | 12 #if SK_SUPPORT_GPU |
| 13 | 13 |
| 14 #include "GrContext.h" | 14 #include "GrContext.h" |
| 15 #include "GrContextFactory.h" | |
| 16 #include "GrFragmentProcessor.h" | 15 #include "GrFragmentProcessor.h" |
| 17 #include "GrInvariantOutput.h" | 16 #include "GrInvariantOutput.h" |
| 18 #include "SkGr.h" | 17 #include "SkGr.h" |
| 19 | 18 |
| 20 static GrColor filterColor(const GrColor& color, uint32_t flags) { | 19 static GrColor filterColor(const GrColor& color, uint32_t flags) { |
| 21 uint32_t mask = 0; | 20 uint32_t mask = 0; |
| 22 if (flags & kR_GrColorComponentFlag) { | 21 if (flags & kR_GrColorComponentFlag) { |
| 23 mask = 0xFF << GrColor_SHIFT_R; | 22 mask = 0xFF << GrColor_SHIFT_R; |
| 24 } | 23 } |
| 25 if (flags & kG_GrColorComponentFlag) { | 24 if (flags & kG_GrColorComponentFlag) { |
| 26 mask |= 0xFF << GrColor_SHIFT_G; | 25 mask |= 0xFF << GrColor_SHIFT_G; |
| 27 } | 26 } |
| 28 if (flags & kB_GrColorComponentFlag) { | 27 if (flags & kB_GrColorComponentFlag) { |
| 29 mask |= 0xFF << GrColor_SHIFT_B; | 28 mask |= 0xFF << GrColor_SHIFT_B; |
| 30 } | 29 } |
| 31 if (flags & kA_GrColorComponentFlag) { | 30 if (flags & kA_GrColorComponentFlag) { |
| 32 mask |= 0xFF << GrColor_SHIFT_A; | 31 mask |= 0xFF << GrColor_SHIFT_A; |
| 33 } | 32 } |
| 34 return color & mask; | 33 return color & mask; |
| 35 } | 34 } |
| 36 | 35 |
| 37 static void test_getConstantColorComponents(skiatest::Reporter* reporter, GrCont
ext* grContext) { | 36 DEF_GPUTEST_FOR_ALL_CONTEXTS(GpuColorFilter, reporter, context) { |
| 38 struct GetConstantComponentTestCase { | 37 struct GetConstantComponentTestCase { |
| 39 // "Shape drawn with" | 38 // "Shape drawn with" |
| 40 uint32_t inputComponents; // "rgb of", "red of", "alpha of", ... | 39 uint32_t inputComponents; // "rgb of", "red of", "alpha of", ... |
| 41 GrColor inputColor; // "[color]" | 40 GrColor inputColor; // "[color]" |
| 42 | 41 |
| 43 SkColor filterColor; // "with filter color [color]" | 42 SkColor filterColor; // "with filter color [color]" |
| 44 SkXfermode::Mode filterMode; // "in mode [mode]" | 43 SkXfermode::Mode filterMode; // "in mode [mode]" |
| 45 | 44 |
| 46 // "produces" | 45 // "produces" |
| 47 uint32_t outputComponents; // "rgb of", "red of", "alpha of", ... | 46 uint32_t outputComponents; // "rgb of", "red of", "alpha of", ... |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 94 |
| 96 // An unknown color with known alpha and red component filtered with Mul
tiply produces an unknown color with known red and alpha. | 95 // An unknown color with known alpha and red component filtered with Mul
tiply produces an unknown color with known red and alpha. |
| 97 { kR|kA , gr_whiteTrans, SkColorSetARGB(128, 200, 200, 200), SkXfermode:
:kModulate_Mode, kR|kA, GrColorPackRGBA(50, 0, 0, 64) } | 96 { kR|kA , gr_whiteTrans, SkColorSetARGB(128, 200, 200, 200), SkXfermode:
:kModulate_Mode, kR|kA, GrColorPackRGBA(50, 0, 0, 64) } |
| 98 }; | 97 }; |
| 99 | 98 |
| 100 GrPaint paint; | 99 GrPaint paint; |
| 101 for (size_t i = 0; i < SK_ARRAY_COUNT(filterTests); ++i) { | 100 for (size_t i = 0; i < SK_ARRAY_COUNT(filterTests); ++i) { |
| 102 const GetConstantComponentTestCase& test = filterTests[i]; | 101 const GetConstantComponentTestCase& test = filterTests[i]; |
| 103 SkAutoTUnref<SkColorFilter> cf( | 102 SkAutoTUnref<SkColorFilter> cf( |
| 104 SkColorFilter::CreateModeFilter(test.filterColor, test.filterMode)); | 103 SkColorFilter::CreateModeFilter(test.filterColor, test.filterMode)); |
| 105 SkAutoTUnref<const GrFragmentProcessor> fp( cf->asFragmentProcessor(grCo
ntext)); | 104 SkAutoTUnref<const GrFragmentProcessor> fp( cf->asFragmentProcessor(cont
ext)); |
| 106 REPORTER_ASSERT(reporter, fp); | 105 REPORTER_ASSERT(reporter, fp); |
| 107 GrInvariantOutput inout(test.inputColor, | 106 GrInvariantOutput inout(test.inputColor, |
| 108 static_cast<GrColorComponentFlags>(test.inputCom
ponents), | 107 static_cast<GrColorComponentFlags>(test.inputCom
ponents), |
| 109 false); | 108 false); |
| 110 fp->computeInvariantOutput(&inout); | 109 fp->computeInvariantOutput(&inout); |
| 111 REPORTER_ASSERT(reporter, filterColor(inout.color(), inout.validFlags())
== | 110 REPORTER_ASSERT(reporter, filterColor(inout.color(), inout.validFlags())
== |
| 112 test.outputColor); | 111 test.outputColor); |
| 113 REPORTER_ASSERT(reporter, test.outputComponents == inout.validFlags()); | 112 REPORTER_ASSERT(reporter, test.outputComponents == inout.validFlags()); |
| 114 } | 113 } |
| 115 } | 114 } |
| 116 | 115 |
| 117 DEF_GPUTEST(GpuColorFilter, reporter, factory) { | |
| 118 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | |
| 119 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); | |
| 120 | |
| 121 GrContext* grContext = factory->get(glType); | |
| 122 if (nullptr == grContext) { | |
| 123 continue; | |
| 124 } | |
| 125 | |
| 126 test_getConstantColorComponents(reporter, grContext); | |
| 127 } | |
| 128 } | |
| 129 | |
| 130 #endif | 116 #endif |
| OLD | NEW |