Home | History | Annotate | Download | only in gpu
      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 }
     55 
     56 #endif // end DEBUG
     57 
     58