blob: 53285a27eb40d8cb234b9dc002566190606fc4d5 [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.
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, 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 }
39 if (GrShaderVar::kHigh_Precision == fPrecision) {
40 break;
41 }
42 GrShaderVar::Precision nextP = static_cast<GrShaderVar::Precision>(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
53void 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}