blob: 32790b99654459e97b81244dd7f9c62644d0e0dd [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
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,
Greg Daniel2c3398d2019-06-19 11:58:01 -040059 const GrSwizzle& swizzle,
Greg Daniel7a82edf2018-12-04 10:54:34 -050060 uint32_t extraSamplerKey) {
Greg Daniel2c3398d2019-06-19 11:58:01 -040061 this->reset(textureType, config, samplerState, swizzle, extraSamplerKey);
Brian Salomon7eae3e02018-08-07 14:02:38 +000062}
63
64GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType,
65 GrPixelConfig config,
Brian Salomone782f842018-07-31 13:53:11 -040066 GrSamplerState::Filter filterMode,
Greg Daniel2c3398d2019-06-19 11:58:01 -040067 GrSamplerState::WrapMode wrapXAndY,
68 const GrSwizzle& swizzle) {
69 this->reset(textureType, config, filterMode, wrapXAndY, swizzle);
Brian Salomone782f842018-07-31 13:53:11 -040070}
71
Brian Salomon7eae3e02018-08-07 14:02:38 +000072void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
73 GrPixelConfig config,
Greg Daniel7a82edf2018-12-04 10:54:34 -050074 const GrSamplerState& samplerState,
Greg Daniel2c3398d2019-06-19 11:58:01 -040075 const GrSwizzle& swizzle,
Greg Daniel7a82edf2018-12-04 10:54:34 -050076 uint32_t extraSamplerKey) {
Brian Salomon7eae3e02018-08-07 14:02:38 +000077 SkASSERT(kUnknown_GrPixelConfig != config);
Brian Salomone782f842018-07-31 13:53:11 -040078 fSamplerState = samplerState;
Brian Salomon7eae3e02018-08-07 14:02:38 +000079 fSamplerState.setFilterMode(clamp_filter(textureType, samplerState.filter()));
Greg Daniel2c3398d2019-06-19 11:58:01 -040080 fSwizzle = swizzle;
Brian Salomon7eae3e02018-08-07 14:02:38 +000081 fTextureType = textureType;
82 fConfig = config;
Greg Daniel7a82edf2018-12-04 10:54:34 -050083 fExtraSamplerKey = extraSamplerKey;
84 SkASSERT(!fExtraSamplerKey || textureType == GrTextureType::kExternal);
Brian Salomone782f842018-07-31 13:53:11 -040085}
86
Brian Salomon7eae3e02018-08-07 14:02:38 +000087void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
88 GrPixelConfig config,
Brian Salomone782f842018-07-31 13:53:11 -040089 GrSamplerState::Filter filterMode,
Greg Daniel2c3398d2019-06-19 11:58:01 -040090 GrSamplerState::WrapMode wrapXAndY,
91 const GrSwizzle& swizzle) {
Brian Salomon7eae3e02018-08-07 14:02:38 +000092 SkASSERT(kUnknown_GrPixelConfig != config);
93 filterMode = clamp_filter(textureType, filterMode);
Brian Salomone782f842018-07-31 13:53:11 -040094 fSamplerState = GrSamplerState(wrapXAndY, filterMode);
Greg Daniel2c3398d2019-06-19 11:58:01 -040095 fSwizzle = swizzle;
Brian Salomon7eae3e02018-08-07 14:02:38 +000096 fTextureType = textureType;
97 fConfig = config;
Brian Salomone782f842018-07-31 13:53:11 -040098}