| OLD | NEW | 
|   1 /* |   1 /* | 
|   2  * Copyright 2014 Google Inc. |   2  * Copyright 2014 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 "GrCoordTransform.h" |   8 #include "GrCoordTransform.h" | 
|   9 #include "GrContext.h" |   9 #include "GrContext.h" | 
|  10 #include "GrDrawTargetCaps.h" |  10 #include "GrDrawTargetCaps.h" | 
|  11 #include "GrGpu.h" |  11 #include "GrGpu.h" | 
|  12  |  12  | 
|  13 void GrCoordTransform::reset(GrCoordSet sourceCoords, const SkMatrix& m, const G
    rTexture* texture) { |  13 void GrCoordTransform::reset(GrCoordSet sourceCoords, const SkMatrix& m, const G
    rTexture* texture) { | 
|  14     SkASSERT(texture); |  14     SkASSERT(texture); | 
|  15     SkASSERT(!fInProcessor); |  15     SkASSERT(!fInProcessor); | 
|  16  |  16  | 
|  17     fSourceCoords = sourceCoords; |  17     fSourceCoords = sourceCoords; | 
|  18     fMatrix = m; |  18     fMatrix = m; | 
|  19     fReverseY = kBottomLeft_GrSurfaceOrigin == texture->origin(); |  19     fReverseY = kBottomLeft_GrSurfaceOrigin == texture->origin(); | 
|  20  |  20  | 
|  21     // Always start at kDefault. Then if precisions differ we see if the precisi
    on needs to be |  21     // Always start at kDefault. Then if precisions differ we see if the precisi
    on needs to be | 
|  22     // increased. Our rule is that we want at least 4 subpixel values in the rep
    resentation for |  22     // increased. Our rule is that we want at least 4 subpixel values in the rep
    resentation for | 
|  23     // coords between 0 to 1. Note that this still might not be enough when draw
    ing with repeat |  23     // coords between 0 to 1. Note that this still might not be enough when draw
    ing with repeat | 
|  24     // or mirror-repeat modes but that case can be arbitrarily bad.  |  24     // or mirror-repeat modes but that case can be arbitrarily bad.  | 
|  25     fPrecision = GrShaderVar::kDefault_Precision; |  25     fPrecision = kDefault_GrSLPrecision; | 
|  26     if (texture->getContext()) { |  26     if (texture->getContext()) { | 
|  27         const GrDrawTargetCaps* caps = texture->getContext()->getGpu()->caps(); |  27         const GrDrawTargetCaps* caps = texture->getContext()->getGpu()->caps(); | 
|  28         if (caps->floatPrecisionVaries()) { |  28         if (caps->floatPrecisionVaries()) { | 
|  29             int maxD = SkTMax(texture->width(), texture->height()); |  29             int maxD = SkTMax(texture->width(), texture->height()); | 
|  30             const GrDrawTargetCaps::PrecisionInfo* info; |  30             const GrDrawTargetCaps::PrecisionInfo* info; | 
|  31             info = &caps->getFloatShaderPrecisionInfo(kFragment_GrShaderType, fP
    recision); |  31             info = &caps->getFloatShaderPrecisionInfo(kFragment_GrShaderType, fP
    recision); | 
|  32             do { |  32             do { | 
|  33                 SkASSERT(info->supported()); |  33                 SkASSERT(info->supported()); | 
|  34                 // Make sure there is at least 2 bits of subpixel precision in t
    he range of |  34                 // Make sure there is at least 2 bits of subpixel precision in t
    he range of | 
|  35                 // texture coords from 0.5 to 1.0. |  35                 // texture coords from 0.5 to 1.0. | 
|  36                 if ((2 << info->fBits) / maxD > 4) { |  36                 if ((2 << info->fBits) / maxD > 4) { | 
|  37                     break; |  37                     break; | 
|  38                 } |  38                 } | 
|  39                 if (GrShaderVar::kHigh_Precision == fPrecision) { |  39                 if (kHigh_GrSLPrecision == fPrecision) { | 
|  40                     break; |  40                     break; | 
|  41                 } |  41                 } | 
|  42                 GrShaderVar::Precision nextP = static_cast<GrShaderVar::Precisio
    n>(fPrecision + 1); |  42                 GrSLPrecision nextP = static_cast<GrSLPrecision>(fPrecision + 1)
    ; | 
|  43                 info = &caps->getFloatShaderPrecisionInfo(kFragment_GrShaderType
    , nextP); |  43                 info = &caps->getFloatShaderPrecisionInfo(kFragment_GrShaderType
    , nextP); | 
|  44                 if (!info->supported()) { |  44                 if (!info->supported()) { | 
|  45                     break; |  45                     break; | 
|  46                 } |  46                 } | 
|  47                 fPrecision = nextP; |  47                 fPrecision = nextP; | 
|  48             } while (true); |  48             } while (true); | 
|  49         } |  49         } | 
|  50     } |  50     } | 
|  51 } |  51 } | 
|  52  |  52  | 
|  53 void GrCoordTransform::reset(GrCoordSet sourceCoords, |  53 void GrCoordTransform::reset(GrCoordSet sourceCoords, | 
|  54                              const SkMatrix& m, |  54                              const SkMatrix& m, | 
|  55                              GrShaderVar::Precision precision) { |  55                              GrSLPrecision precision) { | 
|  56     SkASSERT(!fInProcessor); |  56     SkASSERT(!fInProcessor); | 
|  57     fSourceCoords = sourceCoords; |  57     fSourceCoords = sourceCoords; | 
|  58     fMatrix = m; |  58     fMatrix = m; | 
|  59     fReverseY = false; |  59     fReverseY = false; | 
|  60     fPrecision = precision; |  60     fPrecision = precision; | 
|  61 } |  61 } | 
| OLD | NEW |