blob: 5bb36fcf76a6fbf8f908398efcf8890a03179b17 [file] [log] [blame]
bsalomon17168df2014-12-09 09:00:49 -08001/*
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
13void 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.
bsalomonc0bd6482014-12-09 10:04:14 -080025 fPrecision = kDefault_GrSLPrecision;
bsalomon17168df2014-12-09 09:00:49 -080026 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 }
bsalomonc0bd6482014-12-09 10:04:14 -080039 if (kHigh_GrSLPrecision == fPrecision) {
bsalomon17168df2014-12-09 09:00:49 -080040 break;
41 }
bsalomonc0bd6482014-12-09 10:04:14 -080042 GrSLPrecision nextP = static_cast<GrSLPrecision>(fPrecision + 1);
bsalomon17168df2014-12-09 09:00:49 -080043 info = &caps->getFloatShaderPrecisionInfo(kFragment_GrShaderType, nextP);
44 if (!info->supported()) {
45 break;
46 }
47 fPrecision = nextP;
48 } while (true);
49 }
50 }
51}
52
53void GrCoordTransform::reset(GrCoordSet sourceCoords,
54 const SkMatrix& m,
bsalomonc0bd6482014-12-09 10:04:14 -080055 GrSLPrecision precision) {
bsalomon17168df2014-12-09 09:00:49 -080056 SkASSERT(!fInProcessor);
57 fSourceCoords = sourceCoords;
58 fMatrix = m;
59 fReverseY = false;
60 fPrecision = precision;
61}