OLD | NEW |
(Empty) | |
| 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 G
rTexture* 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 precisi
on needs to be |
| 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 |
| 24 // or mirror-repeat modes but that case can be arbitrarily bad. |
| 25 fPrecision = GrShaderVar::kDefault_Precision; |
| 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, fP
recision); |
| 32 do { |
| 33 SkASSERT(info->supported()); |
| 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. |
| 36 if ((2 << info->fBits) / maxD > 4) { |
| 37 break; |
| 38 } |
| 39 if (GrShaderVar::kHigh_Precision == fPrecision) { |
| 40 break; |
| 41 } |
| 42 GrShaderVar::Precision nextP = static_cast<GrShaderVar::Precisio
n>(fPrecision + 1); |
| 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, |
| 55 GrShaderVar::Precision precision) { |
| 56 SkASSERT(!fInProcessor); |
| 57 fSourceCoords = sourceCoords; |
| 58 fMatrix = m; |
| 59 fReverseY = false; |
| 60 fPrecision = precision; |
| 61 } |
OLD | NEW |