blob: 65ed14b9ae11e07510220f1bfa4c9f0f5cb88f3f [file] [log] [blame]
joshualitt8072caa2015-02-12 14:20:52 -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
Robert Phillips787fd9d2021-03-22 14:48:09 -04008#include "src/gpu/GrGeometryProcessor.h"
joshualitt8072caa2015-02-12 14:20:52 -08009
Brian Salomon7eabfe82019-12-02 14:20:20 -050010#include "src/gpu/GrFragmentProcessor.h"
joshualitt8072caa2015-02-12 14:20:52 -080011
12/**
Michael Ludwige88320b2020-06-24 09:04:56 -040013 * We specialize the vertex or fragment coord transform code for these matrix types, and where
14 * the transform code is applied.
joshualitt8072caa2015-02-12 14:20:52 -080015 */
Michael Ludwige88320b2020-06-24 09:04:56 -040016enum SampleFlag {
Brian Osman48d7f7c2021-03-03 13:38:08 -050017 kExplicitlySampled_Flag = 0b0001, // GrFP::isSampledWithExplicitCoords()
Brian Osman83dae922021-04-28 10:44:06 -040018 kUniform_SampleMatrix_Flag = 0b0010, // GrFP::sampleUsage()::isUniformMatrix()
Michael Ludwige88320b2020-06-24 09:04:56 -040019
20 // Currently, sample(matrix) only specializes on no-perspective or general.
21 // FIXME add new flags as more matrix types are supported.
Brian Osman83dae922021-04-28 10:44:06 -040022 kPersp_Matrix_Flag = 0b0100, // GrFP::sampleUsage()::fHasPerspective
joshualitt8072caa2015-02-12 14:20:52 -080023};
24
Robert Phillips787fd9d2021-03-22 14:48:09 -040025GrGeometryProcessor::GrGeometryProcessor(ClassID classID) : GrProcessor(classID) {}
Brian Salomone782f842018-07-31 13:53:11 -040026
Robert Phillips787fd9d2021-03-22 14:48:09 -040027const GrGeometryProcessor::TextureSampler& GrGeometryProcessor::textureSampler(int i) const {
Brian Salomone782f842018-07-31 13:53:11 -040028 SkASSERT(i >= 0 && i < this->numTextureSamplers());
29 return this->onTextureSampler(i);
30}
Brian Salomon92be2f72018-06-19 14:33:47 -040031
Robert Phillips787fd9d2021-03-22 14:48:09 -040032uint32_t GrGeometryProcessor::ComputeCoordTransformsKey(const GrFragmentProcessor& fp) {
Michael Ludwige7e25ac2020-06-26 12:53:03 -040033 // This is highly coupled with the code in GrGLSLGeometryProcessor::collectTransforms().
Michael Ludwige88320b2020-06-24 09:04:56 -040034
35 uint32_t key = 0;
36 if (fp.isSampledWithExplicitCoords()) {
37 key |= kExplicitlySampled_Flag;
joshualitt8072caa2015-02-12 14:20:52 -080038 }
Brian Osman83dae922021-04-28 10:44:06 -040039 if (fp.sampleUsage().isUniformMatrix()) {
40 key |= kUniform_SampleMatrix_Flag;
Michael Ludwige88320b2020-06-24 09:04:56 -040041 }
Brian Osman1298bc42020-06-30 13:39:35 -040042 if (fp.sampleUsage().fHasPerspective) {
Michael Ludwige88320b2020-06-24 09:04:56 -040043 key |= kPersp_Matrix_Flag;
44 }
45
46 return key;
joshualitt8072caa2015-02-12 14:20:52 -080047}
Brian Salomone782f842018-07-31 13:53:11 -040048
49///////////////////////////////////////////////////////////////////////////////////////////////////
50
Brian Salomon7eae3e02018-08-07 14:02:38 +000051static inline GrSamplerState::Filter clamp_filter(GrTextureType type,
52 GrSamplerState::Filter requestedFilter) {
53 if (GrTextureTypeHasRestrictedSampling(type)) {
Brian Salomona3b02f52020-07-15 16:02:01 -040054 return std::min(requestedFilter, GrSamplerState::Filter::kLinear);
Brian Salomon7eae3e02018-08-07 14:02:38 +000055 }
56 return requestedFilter;
Brian Salomonaf874832018-08-03 11:53:40 -040057}
58
Robert Phillips787fd9d2021-03-22 14:48:09 -040059GrGeometryProcessor::TextureSampler::TextureSampler(GrSamplerState samplerState,
60 const GrBackendFormat& backendFormat,
61 const GrSwizzle& swizzle) {
Robert Phillips323471e2019-11-11 11:33:37 -050062 this->reset(samplerState, backendFormat, swizzle);
Brian Salomon7eae3e02018-08-07 14:02:38 +000063}
64
Robert Phillips787fd9d2021-03-22 14:48:09 -040065void GrGeometryProcessor::TextureSampler::reset(GrSamplerState samplerState,
66 const GrBackendFormat& backendFormat,
67 const GrSwizzle& swizzle) {
Brian Salomone782f842018-07-31 13:53:11 -040068 fSamplerState = samplerState;
Robert Phillipsf272bea2019-10-17 08:56:16 -040069 fSamplerState.setFilterMode(clamp_filter(backendFormat.textureType(), samplerState.filter()));
70 fBackendFormat = backendFormat;
Greg Daniel2c3398d2019-06-19 11:58:01 -040071 fSwizzle = swizzle;
Brian Salomon67529b22019-08-13 15:31:04 -040072 fIsInitialized = true;
Brian Salomone782f842018-07-31 13:53:11 -040073}