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 "src/gpu/GrGeometryProcessor.h"
9
10 #include "src/gpu/GrFragmentProcessor.h"
11
12 /**
13 * We specialize the vertex or fragment coord transform code for these matrix types, and where
14 * the transform code is applied.
15 */
16 enum SampleFlag {
17 kExplicitlySampled_Flag = 0b0001, // GrFP::isSampledWithExplicitCoords()
18 kUniform_SampleMatrix_Flag = 0b0010, // GrFP::sampleUsage()::isUniformMatrix()
19
20 // Currently, sample(matrix) only specializes on no-perspective or general.
21 // FIXME add new flags as more matrix types are supported.
22 kPersp_Matrix_Flag = 0b0100, // GrFP::sampleUsage()::fHasPerspective
23 };
24
GrGeometryProcessor(ClassID classID)25 GrGeometryProcessor::GrGeometryProcessor(ClassID classID) : GrProcessor(classID) {}
26
textureSampler(int i) const27 const GrGeometryProcessor::TextureSampler& GrGeometryProcessor::textureSampler(int i) const {
28 SkASSERT(i >= 0 && i < this->numTextureSamplers());
29 return this->onTextureSampler(i);
30 }
31
ComputeCoordTransformsKey(const GrFragmentProcessor & fp)32 uint32_t GrGeometryProcessor::ComputeCoordTransformsKey(const GrFragmentProcessor& fp) {
33 // This is highly coupled with the code in GrGLSLGeometryProcessor::collectTransforms().
34
35 uint32_t key = 0;
36 if (fp.isSampledWithExplicitCoords()) {
37 key |= kExplicitlySampled_Flag;
38 }
39 if (fp.sampleUsage().isUniformMatrix()) {
40 key |= kUniform_SampleMatrix_Flag;
41 }
42 if (fp.sampleUsage().fHasPerspective) {
43 key |= kPersp_Matrix_Flag;
44 }
45
46 return key;
47 }
48
49 ///////////////////////////////////////////////////////////////////////////////////////////////////
50
clamp_filter(GrTextureType type,GrSamplerState::Filter requestedFilter)51 static inline GrSamplerState::Filter clamp_filter(GrTextureType type,
52 GrSamplerState::Filter requestedFilter) {
53 if (GrTextureTypeHasRestrictedSampling(type)) {
54 return std::min(requestedFilter, GrSamplerState::Filter::kLinear);
55 }
56 return requestedFilter;
57 }
58
TextureSampler(GrSamplerState samplerState,const GrBackendFormat & backendFormat,const GrSwizzle & swizzle)59 GrGeometryProcessor::TextureSampler::TextureSampler(GrSamplerState samplerState,
60 const GrBackendFormat& backendFormat,
61 const GrSwizzle& swizzle) {
62 this->reset(samplerState, backendFormat, swizzle);
63 }
64
reset(GrSamplerState samplerState,const GrBackendFormat & backendFormat,const GrSwizzle & swizzle)65 void GrGeometryProcessor::TextureSampler::reset(GrSamplerState samplerState,
66 const GrBackendFormat& backendFormat,
67 const GrSwizzle& swizzle) {
68 fSamplerState = samplerState;
69 fSamplerState.setFilterMode(clamp_filter(backendFormat.textureType(), samplerState.filter()));
70 fBackendFormat = backendFormat;
71 fSwizzle = swizzle;
72 fIsInitialized = true;
73 }
74