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