LCOV - code coverage report
Current view: top level - gfx/skia/skia/include/gpu - GrTestUtils.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 35 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright 2015 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             : #ifndef GrTestUtils_DEFINED
       9             : #define GrTestUtils_DEFINED
      10             : 
      11             : #include "SkTypes.h"
      12             : 
      13             : #if GR_TEST_UTILS
      14             : 
      15             : #include "GrColor.h"
      16             : #include "GrColorSpaceXform.h"
      17             : #include "SkPathEffect.h"
      18             : #include "SkRandom.h"
      19             : #include "SkShader.h"
      20             : #include "SkStrokeRec.h"
      21             : #include "../private/SkTemplates.h"
      22             : 
      23             : struct GrProcessorTestData;
      24             : class GrStyle;
      25             : class SkMatrix;
      26             : class SkPath;
      27             : class SkRRect;
      28             : struct SkRect;
      29             : 
      30             : namespace GrTest {
      31             : /**
      32             :  * Helpers for use in Test functions.
      33             :  */
      34             : const SkMatrix& TestMatrix(SkRandom*);
      35             : const SkMatrix& TestMatrixPreservesRightAngles(SkRandom*);
      36             : const SkMatrix& TestMatrixRectStaysRect(SkRandom*);
      37             : const SkMatrix& TestMatrixInvertible(SkRandom*);
      38             : const SkMatrix& TestMatrixPerspective(SkRandom*);
      39             : const SkRect& TestRect(SkRandom*);
      40             : const SkRect& TestSquare(SkRandom*);
      41             : const SkRRect& TestRRectSimple(SkRandom*);
      42             : const SkPath& TestPath(SkRandom*);
      43             : const SkPath& TestPathConvex(SkRandom*);
      44             : SkStrokeRec TestStrokeRec(SkRandom*);
      45             : /** Creates styles with dash path effects and null path effects */
      46             : void TestStyle(SkRandom*, GrStyle*);
      47             : sk_sp<SkColorSpace> TestColorSpace(SkRandom*);
      48             : sk_sp<GrColorSpaceXform> TestColorXform(SkRandom*);
      49             : 
      50           0 : class TestAsFPArgs {
      51             : public:
      52             :     TestAsFPArgs(GrProcessorTestData*);
      53           0 :     const SkShader::AsFPArgs& args() const { return fArgs; }
      54             : 
      55             : private:
      56             :     SkShader::AsFPArgs fArgs;
      57             :     SkMatrix fViewMatrixStorage;
      58             :     sk_sp<SkColorSpace> fColorSpaceStorage;
      59             : };
      60             : 
      61             : // We have a simplified dash path effect here to avoid relying on SkDashPathEffect which
      62             : // is in the optional build target effects.
      63           0 : class TestDashPathEffect : public SkPathEffect {
      64             : public:
      65           0 :     static sk_sp<SkPathEffect> Make(const SkScalar* intervals, int count, SkScalar phase) {
      66           0 :         return sk_sp<SkPathEffect>(new TestDashPathEffect(intervals, count, phase));
      67             :     }
      68             : 
      69             :     bool filterPath(SkPath* dst, const SkPath&, SkStrokeRec* , const SkRect*) const override;
      70             :     DashType asADash(DashInfo* info) const override;
      71           0 :     Factory getFactory() const override { return nullptr; }
      72           0 :     void toString(SkString*) const override {}
      73             : 
      74             : private:
      75             :     TestDashPathEffect(const SkScalar* intervals, int count, SkScalar phase);
      76             : 
      77             :     int                     fCount;
      78             :     SkAutoTArray<SkScalar>  fIntervals;
      79             :     SkScalar                fPhase;
      80             :     SkScalar                fInitialDashLength;
      81             :     int                     fInitialDashIndex;
      82             :     SkScalar                fIntervalLength;
      83             : };
      84             : 
      85             : }  // namespace GrTest
      86             : 
      87           0 : static inline GrColor GrRandomColor(SkRandom* random) {
      88             :     // There are only a few cases of random colors which interest us
      89             :     enum ColorMode {
      90             :         kAllOnes_ColorMode,
      91             :         kAllZeros_ColorMode,
      92             :         kAlphaOne_ColorMode,
      93             :         kRandom_ColorMode,
      94             :         kLast_ColorMode = kRandom_ColorMode
      95             :     };
      96             : 
      97           0 :     ColorMode colorMode = ColorMode(random->nextULessThan(kLast_ColorMode + 1));
      98           0 :     GrColor color SK_INIT_TO_AVOID_WARNING;
      99           0 :     switch (colorMode) {
     100             :         case kAllOnes_ColorMode:
     101           0 :             color = GrColorPackRGBA(0xFF, 0xFF, 0xFF, 0xFF);
     102           0 :             break;
     103             :         case kAllZeros_ColorMode:
     104           0 :             color = GrColorPackRGBA(0, 0, 0, 0);
     105           0 :             break;
     106             :         case kAlphaOne_ColorMode:
     107           0 :             color = GrColorPackRGBA(random->nextULessThan(256),
     108             :                                     random->nextULessThan(256),
     109             :                                     random->nextULessThan(256),
     110           0 :                                     0xFF);
     111           0 :             break;
     112             :         case kRandom_ColorMode: {
     113           0 :                 uint8_t alpha = random->nextULessThan(256);
     114           0 :                 color = GrColorPackRGBA(random->nextRangeU(0, alpha),
     115             :                                         random->nextRangeU(0, alpha),
     116             :                                         random->nextRangeU(0, alpha),
     117           0 :                                         alpha);
     118           0 :             break;
     119             :         }
     120             :     }
     121           0 :     GrColorIsPMAssert(color);
     122           0 :     return color;
     123             : }
     124             : 
     125           0 : static inline uint8_t GrRandomCoverage(SkRandom* random) {
     126             :     enum CoverageMode {
     127             :         kZero_CoverageMode,
     128             :         kAllOnes_CoverageMode,
     129             :         kRandom_CoverageMode,
     130             :         kLast_CoverageMode = kRandom_CoverageMode
     131             :     };
     132             : 
     133           0 :     CoverageMode colorMode = CoverageMode(random->nextULessThan(kLast_CoverageMode + 1));
     134           0 :     uint8_t coverage SK_INIT_TO_AVOID_WARNING;
     135           0 :     switch (colorMode) {
     136             :         case kZero_CoverageMode:
     137           0 :             coverage = 0;
     138           0 :             break;
     139             :         case kAllOnes_CoverageMode:
     140           0 :             coverage = 0xff;
     141           0 :             break;
     142             :         case kRandom_CoverageMode:
     143           0 :             coverage = random->nextULessThan(256);
     144           0 :             break;
     145             :     }
     146           0 :     return coverage;
     147             : }
     148             : 
     149             : #endif
     150             : #endif

Generated by: LCOV version 1.13