blob: 672056c6020aa4efb37ea7b933b27bbc4b2685e1 [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
8#include "GrPrimitiveProcessor.h"
9
10#include "GrCoordTransform.h"
11
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
wangyixa7f4c432015-08-20 07:25:02 -070028GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords,
29 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,
57 GrPixelConfig config,
Greg Daniel7a82edf2018-12-04 10:54:34 -050058 const GrSamplerState& samplerState,
59 uint32_t extraSamplerKey) {
60 this->reset(textureType, config, samplerState, extraSamplerKey);
Brian Salomon7eae3e02018-08-07 14:02:38 +000061}
62
63GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType,
64 GrPixelConfig config,
Brian Salomone782f842018-07-31 13:53:11 -040065 GrSamplerState::Filter filterMode,
Greg Daniel0f70be82018-10-08 17:35:08 +000066 GrSamplerState::WrapMode wrapXAndY) {
67 this->reset(textureType, config, filterMode, wrapXAndY);
Brian Salomone782f842018-07-31 13:53:11 -040068}
69
Brian Salomon7eae3e02018-08-07 14:02:38 +000070void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
71 GrPixelConfig config,
Greg Daniel7a82edf2018-12-04 10:54:34 -050072 const GrSamplerState& samplerState,
73 uint32_t extraSamplerKey) {
Brian Salomon7eae3e02018-08-07 14:02:38 +000074 SkASSERT(kUnknown_GrPixelConfig != config);
Brian Salomone782f842018-07-31 13:53:11 -040075 fSamplerState = samplerState;
Brian Salomon7eae3e02018-08-07 14:02:38 +000076 fSamplerState.setFilterMode(clamp_filter(textureType, samplerState.filter()));
77 fTextureType = textureType;
78 fConfig = config;
Greg Daniel7a82edf2018-12-04 10:54:34 -050079 fExtraSamplerKey = extraSamplerKey;
80 SkASSERT(!fExtraSamplerKey || textureType == GrTextureType::kExternal);
Brian Salomone782f842018-07-31 13:53:11 -040081}
82
Brian Salomon7eae3e02018-08-07 14:02:38 +000083void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
84 GrPixelConfig config,
Brian Salomone782f842018-07-31 13:53:11 -040085 GrSamplerState::Filter filterMode,
Greg Daniel0f70be82018-10-08 17:35:08 +000086 GrSamplerState::WrapMode wrapXAndY) {
Brian Salomon7eae3e02018-08-07 14:02:38 +000087 SkASSERT(kUnknown_GrPixelConfig != config);
88 filterMode = clamp_filter(textureType, filterMode);
Brian Salomone782f842018-07-31 13:53:11 -040089 fSamplerState = GrSamplerState(wrapXAndY, filterMode);
Brian Salomon7eae3e02018-08-07 14:02:38 +000090 fTextureType = textureType;
91 fConfig = config;
Brian Salomone782f842018-07-31 13:53:11 -040092}