2015-02-12 22:20:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrPrimitiveProcessor.h"
|
2015-02-12 22:20:52 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrCoordTransform.h"
|
2015-02-12 22:20:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* We specialize the vertex code for each of these matrix types.
|
|
|
|
*/
|
|
|
|
enum MatrixType {
|
|
|
|
kNoPersp_MatrixType = 0,
|
|
|
|
kGeneral_MatrixType = 1,
|
|
|
|
};
|
|
|
|
|
2018-07-31 17:53:11 +00:00
|
|
|
GrPrimitiveProcessor::GrPrimitiveProcessor(ClassID classID) : GrProcessor(classID) {}
|
|
|
|
|
|
|
|
const GrPrimitiveProcessor::TextureSampler& GrPrimitiveProcessor::textureSampler(int i) const {
|
|
|
|
SkASSERT(i >= 0 && i < this->numTextureSamplers());
|
|
|
|
return this->onTextureSampler(i);
|
|
|
|
}
|
2018-06-19 18:33:47 +00:00
|
|
|
|
2015-02-12 22:20:52 +00:00
|
|
|
uint32_t
|
2015-08-20 14:25:02 +00:00
|
|
|
GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords,
|
|
|
|
int numCoords) const {
|
2015-02-12 22:20:52 +00:00
|
|
|
uint32_t totalKey = 0;
|
2015-08-20 14:25:02 +00:00
|
|
|
for (int t = 0; t < numCoords; ++t) {
|
2015-02-12 22:20:52 +00:00
|
|
|
uint32_t key = 0;
|
|
|
|
const GrCoordTransform* coordTransform = coords[t];
|
|
|
|
if (coordTransform->getMatrix().hasPerspective()) {
|
|
|
|
key |= kGeneral_MatrixType;
|
|
|
|
} else {
|
|
|
|
key |= kNoPersp_MatrixType;
|
|
|
|
}
|
2018-06-06 21:16:05 +00:00
|
|
|
key <<= t;
|
2015-02-12 22:20:52 +00:00
|
|
|
SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap
|
|
|
|
totalKey |= key;
|
|
|
|
}
|
|
|
|
return totalKey;
|
|
|
|
}
|
2018-07-31 17:53:11 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-07 14:02:38 +00:00
|
|
|
static inline GrSamplerState::Filter clamp_filter(GrTextureType type,
|
|
|
|
GrSamplerState::Filter requestedFilter) {
|
|
|
|
if (GrTextureTypeHasRestrictedSampling(type)) {
|
|
|
|
return SkTMin(requestedFilter, GrSamplerState::Filter::kBilerp);
|
|
|
|
}
|
|
|
|
return requestedFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType,
|
|
|
|
GrPixelConfig config,
|
2018-12-04 15:54:34 +00:00
|
|
|
const GrSamplerState& samplerState,
|
2019-06-19 15:58:01 +00:00
|
|
|
const GrSwizzle& swizzle,
|
2018-12-04 15:54:34 +00:00
|
|
|
uint32_t extraSamplerKey) {
|
2019-06-19 15:58:01 +00:00
|
|
|
this->reset(textureType, config, samplerState, swizzle, extraSamplerKey);
|
2018-07-31 17:53:11 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 14:02:38 +00:00
|
|
|
GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType,
|
|
|
|
GrPixelConfig config,
|
2018-07-31 17:53:11 +00:00
|
|
|
GrSamplerState::Filter filterMode,
|
2019-06-19 15:58:01 +00:00
|
|
|
GrSamplerState::WrapMode wrapXAndY,
|
|
|
|
const GrSwizzle& swizzle) {
|
|
|
|
this->reset(textureType, config, filterMode, wrapXAndY, swizzle);
|
2018-07-31 17:53:11 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 14:02:38 +00:00
|
|
|
void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
|
|
|
|
GrPixelConfig config,
|
2018-12-04 15:54:34 +00:00
|
|
|
const GrSamplerState& samplerState,
|
2019-06-19 15:58:01 +00:00
|
|
|
const GrSwizzle& swizzle,
|
2018-12-04 15:54:34 +00:00
|
|
|
uint32_t extraSamplerKey) {
|
2018-08-07 14:02:38 +00:00
|
|
|
SkASSERT(kUnknown_GrPixelConfig != config);
|
2018-07-31 17:53:11 +00:00
|
|
|
fSamplerState = samplerState;
|
2018-08-07 14:02:38 +00:00
|
|
|
fSamplerState.setFilterMode(clamp_filter(textureType, samplerState.filter()));
|
2019-06-19 15:58:01 +00:00
|
|
|
fSwizzle = swizzle;
|
2018-08-07 14:02:38 +00:00
|
|
|
fTextureType = textureType;
|
|
|
|
fConfig = config;
|
2018-12-04 15:54:34 +00:00
|
|
|
fExtraSamplerKey = extraSamplerKey;
|
|
|
|
SkASSERT(!fExtraSamplerKey || textureType == GrTextureType::kExternal);
|
2018-07-31 17:53:11 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 14:02:38 +00:00
|
|
|
void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
|
|
|
|
GrPixelConfig config,
|
2018-07-31 17:53:11 +00:00
|
|
|
GrSamplerState::Filter filterMode,
|
2019-06-19 15:58:01 +00:00
|
|
|
GrSamplerState::WrapMode wrapXAndY,
|
|
|
|
const GrSwizzle& swizzle) {
|
2018-08-07 14:02:38 +00:00
|
|
|
SkASSERT(kUnknown_GrPixelConfig != config);
|
|
|
|
filterMode = clamp_filter(textureType, filterMode);
|
2018-07-31 17:53:11 +00:00
|
|
|
fSamplerState = GrSamplerState(wrapXAndY, filterMode);
|
2019-06-19 15:58:01 +00:00
|
|
|
fSwizzle = swizzle;
|
2018-08-07 14:02:38 +00:00
|
|
|
fTextureType = textureType;
|
|
|
|
fConfig = config;
|
2018-07-31 17:53:11 +00:00
|
|
|
}
|