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" |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 9 | #include "GrCaps.h" |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 10 | #include "GrContext.h" |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 11 | #include "GrGpu.h" |
| 12 | |
Brian Salomon | 2ebd0c8 | 2016-10-03 17:15:28 -0400 | [diff] [blame] | 13 | void GrCoordTransform::reset(const SkMatrix& m, const GrTexture* texture, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame^] | 14 | GrSamplerParams::FilterMode filter) { |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 15 | SkASSERT(texture); |
| 16 | SkASSERT(!fInProcessor); |
| 17 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 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 |
bsalomon | 9f876a3 | 2014-12-09 10:51:07 -0800 | [diff] [blame] | 23 | // coords between 0 to 1 when bi- or tri-lerping and 1 value when nearest filtering. Note that |
| 24 | // this still might not be enough when drawing with repeat or mirror-repeat modes but that case |
| 25 | // can be arbitrarily bad. |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame^] | 26 | int subPixelThresh = filter > GrSamplerParams::kNone_FilterMode ? 4 : 1; |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 27 | fPrecision = kDefault_GrSLPrecision; |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 28 | if (texture->getContext()) { |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 29 | const GrShaderCaps* caps = texture->getContext()->caps()->shaderCaps(); |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 30 | if (caps->floatPrecisionVaries()) { |
| 31 | int maxD = SkTMax(texture->width(), texture->height()); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 32 | const GrShaderCaps::PrecisionInfo* info; |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 33 | info = &caps->getFloatShaderPrecisionInfo(kFragment_GrShaderType, fPrecision); |
| 34 | do { |
| 35 | SkASSERT(info->supported()); |
| 36 | // Make sure there is at least 2 bits of subpixel precision in the range of |
| 37 | // texture coords from 0.5 to 1.0. |
bsalomon | 9f876a3 | 2014-12-09 10:51:07 -0800 | [diff] [blame] | 38 | if ((2 << info->fBits) / maxD > subPixelThresh) { |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 39 | break; |
| 40 | } |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 41 | if (kHigh_GrSLPrecision == fPrecision) { |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 42 | break; |
| 43 | } |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 44 | GrSLPrecision nextP = static_cast<GrSLPrecision>(fPrecision + 1); |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 45 | info = &caps->getFloatShaderPrecisionInfo(kFragment_GrShaderType, nextP); |
| 46 | if (!info->supported()) { |
| 47 | break; |
| 48 | } |
| 49 | fPrecision = nextP; |
| 50 | } while (true); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
Brian Salomon | 2ebd0c8 | 2016-10-03 17:15:28 -0400 | [diff] [blame] | 55 | void GrCoordTransform::reset(const SkMatrix& m, GrSLPrecision precision) { |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 56 | SkASSERT(!fInProcessor); |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 57 | fMatrix = m; |
| 58 | fReverseY = false; |
| 59 | fPrecision = precision; |
| 60 | } |