blob: 70a812b28cf6c1e7ef5a434a36b09176d8ba54d7 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrPrimitiveProcessor.h"
joshualitt8072caa2015-02-12 14:20:52 -08009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/gpu/GrCoordTransform.h"
joshualitt8072caa2015-02-12 14:20:52 -080011
12/**
joshualitt8072caa2015-02-12 14:20:52 -080013 * We specialize the vertex code for each of these matrix types.
14 */
15enum MatrixType {
16 kNoPersp_MatrixType = 0,
17 kGeneral_MatrixType = 1,
18};
19
Brian Salomone782f842018-07-31 13:53:11 -040020GrPrimitiveProcessor::GrPrimitiveProcessor(ClassID classID) : GrProcessor(classID) {}
21
22const GrPrimitiveProcessor::TextureSampler& GrPrimitiveProcessor::textureSampler(int i) const {
23 SkASSERT(i >= 0 && i < this->numTextureSamplers());
24 return this->onTextureSampler(i);
25}
Brian Salomon92be2f72018-06-19 14:33:47 -040026
joshualitt8072caa2015-02-12 14:20:52 -080027uint32_t
Ethan Nicholasd4efe682019-08-29 16:10:13 -040028GrPrimitiveProcessor::getTransformKey(const SkTArray<GrCoordTransform*, true>& coords,
wangyixa7f4c432015-08-20 07:25:02 -070029 int numCoords) const {
joshualitt8072caa2015-02-12 14:20:52 -080030 uint32_t totalKey = 0;
wangyixa7f4c432015-08-20 07:25:02 -070031 for (int t = 0; t < numCoords; ++t) {
joshualitt8072caa2015-02-12 14:20:52 -080032 uint32_t key = 0;
33 const GrCoordTransform* coordTransform = coords[t];
34 if (coordTransform->getMatrix().hasPerspective()) {
35 key |= kGeneral_MatrixType;
36 } else {
37 key |= kNoPersp_MatrixType;
38 }
Brian Salomon969bdef2018-06-06 17:16:05 -040039 key <<= t;
joshualitt8072caa2015-02-12 14:20:52 -080040 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap
41 totalKey |= key;
42 }
43 return totalKey;
44}
Brian Salomone782f842018-07-31 13:53:11 -040045
46///////////////////////////////////////////////////////////////////////////////////////////////////
47
Brian Salomon7eae3e02018-08-07 14:02:38 +000048static inline GrSamplerState::Filter clamp_filter(GrTextureType type,
49 GrSamplerState::Filter requestedFilter) {
50 if (GrTextureTypeHasRestrictedSampling(type)) {
51 return SkTMin(requestedFilter, GrSamplerState::Filter::kBilerp);
52 }
53 return requestedFilter;
Brian Salomonaf874832018-08-03 11:53:40 -040054}
55
Brian Salomon7eae3e02018-08-07 14:02:38 +000056GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType,
Greg Daniel7a82edf2018-12-04 10:54:34 -050057 const GrSamplerState& samplerState,
Greg Daniel2c3398d2019-06-19 11:58:01 -040058 const GrSwizzle& swizzle,
Greg Daniel7a82edf2018-12-04 10:54:34 -050059 uint32_t extraSamplerKey) {
Brian Salomon67529b22019-08-13 15:31:04 -040060 this->reset(textureType, samplerState, swizzle, extraSamplerKey);
Brian Salomon7eae3e02018-08-07 14:02:38 +000061}
62
63GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType,
Brian Salomone782f842018-07-31 13:53:11 -040064 GrSamplerState::Filter filterMode,
Greg Daniel2c3398d2019-06-19 11:58:01 -040065 GrSamplerState::WrapMode wrapXAndY,
66 const GrSwizzle& swizzle) {
Brian Salomon67529b22019-08-13 15:31:04 -040067 this->reset(textureType, filterMode, wrapXAndY, swizzle);
Brian Salomone782f842018-07-31 13:53:11 -040068}
69
Brian Salomon7eae3e02018-08-07 14:02:38 +000070void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
Greg Daniel7a82edf2018-12-04 10:54:34 -050071 const GrSamplerState& samplerState,
Greg Daniel2c3398d2019-06-19 11:58:01 -040072 const GrSwizzle& swizzle,
Greg Daniel7a82edf2018-12-04 10:54:34 -050073 uint32_t extraSamplerKey) {
Brian Salomone782f842018-07-31 13:53:11 -040074 fSamplerState = samplerState;
Brian Salomon7eae3e02018-08-07 14:02:38 +000075 fSamplerState.setFilterMode(clamp_filter(textureType, samplerState.filter()));
Greg Daniel2c3398d2019-06-19 11:58:01 -040076 fSwizzle = swizzle;
Brian Salomon7eae3e02018-08-07 14:02:38 +000077 fTextureType = textureType;
Greg Daniel7a82edf2018-12-04 10:54:34 -050078 fExtraSamplerKey = extraSamplerKey;
Brian Salomon67529b22019-08-13 15:31:04 -040079 fIsInitialized = true;
Brian Salomone782f842018-07-31 13:53:11 -040080}
81
Brian Salomon7eae3e02018-08-07 14:02:38 +000082void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
Brian Salomone782f842018-07-31 13:53:11 -040083 GrSamplerState::Filter filterMode,
Greg Daniel2c3398d2019-06-19 11:58:01 -040084 GrSamplerState::WrapMode wrapXAndY,
85 const GrSwizzle& swizzle) {
Brian Salomon7eae3e02018-08-07 14:02:38 +000086 filterMode = clamp_filter(textureType, filterMode);
Brian Salomone782f842018-07-31 13:53:11 -040087 fSamplerState = GrSamplerState(wrapXAndY, filterMode);
Greg Daniel2c3398d2019-06-19 11:58:01 -040088 fSwizzle = swizzle;
Brian Salomon7eae3e02018-08-07 14:02:38 +000089 fTextureType = textureType;
Brian Salomon67529b22019-08-13 15:31:04 -040090 fIsInitialized = true;
Brian Salomone782f842018-07-31 13:53:11 -040091}