egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 "GrInvariantOutput.h" |
| 9 | |
| 10 | #ifdef SK_DEBUG |
| 11 | |
| 12 | void GrInvariantOutput::validate() const { |
| 13 | if (fIsSingleComponent) { |
| 14 | SkASSERT(0 == fValidFlags || kRGBA_GrColorComponentFlags == fValidFlags); |
| 15 | if (kRGBA_GrColorComponentFlags == fValidFlags) { |
| 16 | SkASSERT(this->colorComponentsAllEqual()); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | SkASSERT(this->validPreMulColor()); |
| 21 | |
| 22 | // If we claim that we are not using the input color we must not be modulating the input. |
| 23 | SkASSERT(fNonMulStageFound || fWillUseInputColor); |
| 24 | } |
| 25 | |
| 26 | bool GrInvariantOutput::colorComponentsAllEqual() const { |
| 27 | unsigned colorA = GrColorUnpackA(fColor); |
| 28 | return(GrColorUnpackR(fColor) == colorA && |
| 29 | GrColorUnpackG(fColor) == colorA && |
| 30 | GrColorUnpackB(fColor) == colorA); |
| 31 | } |
| 32 | |
| 33 | bool GrInvariantOutput::validPreMulColor() const { |
| 34 | if (kA_GrColorComponentFlag & fValidFlags) { |
| 35 | float c[4]; |
| 36 | GrColorToRGBAFloat(fColor, c); |
| 37 | if (kR_GrColorComponentFlag & fValidFlags) { |
| 38 | if (c[0] > c[3]) { |
| 39 | return false; |
| 40 | } |
| 41 | } |
| 42 | if (kG_GrColorComponentFlag & fValidFlags) { |
| 43 | if (c[1] > c[3]) { |
| 44 | return false; |
| 45 | } |
| 46 | } |
| 47 | if (kB_GrColorComponentFlag & fValidFlags) { |
| 48 | if (c[2] > c[3]) { |
| 49 | return false; |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | return true; |
| 54 | } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 55 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 56 | #endif // end DEBUG |
| 57 | |