skia2/src/gpu/GrPrimitiveProcessor.cpp

89 lines
3.3 KiB
C++
Raw Normal View History

/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrPrimitiveProcessor.h"
#include "GrCoordTransform.h"
/**
* We specialize the vertex code for each of these matrix types.
*/
enum MatrixType {
kNoPersp_MatrixType = 0,
kGeneral_MatrixType = 1,
};
GrPrimitiveProcessor::GrPrimitiveProcessor(ClassID classID) : GrProcessor(classID) {}
const GrPrimitiveProcessor::TextureSampler& GrPrimitiveProcessor::textureSampler(int i) const {
SkASSERT(i >= 0 && i < this->numTextureSamplers());
return this->onTextureSampler(i);
}
uint32_t
GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords,
int numCoords) const {
uint32_t totalKey = 0;
for (int t = 0; t < numCoords; ++t) {
uint32_t key = 0;
const GrCoordTransform* coordTransform = coords[t];
if (coordTransform->getMatrix().hasPerspective()) {
key |= kGeneral_MatrixType;
} else {
key |= kNoPersp_MatrixType;
}
key <<= t;
SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap
totalKey |= key;
}
return totalKey;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
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,
Reland "Remove ability to sample textures in vertex or geometry shaders." This reverts commit 6e2625d9ae89f6709a606bcf1a15b35741393e02. Reason for revert: Chrome fix has landed. This should work now. Original change's description: > Revert "Remove ability to sample textures in vertex or geometry shaders." > > This reverts commit d50d6579d1c00de65b947c0531fa04c043729e49. > > Reason for revert: chromes test gles test context is broken. Need to fix that then reland this > > Original change's description: > > Remove ability to sample textures in vertex or geometry shaders. > > > > Bug: skia: > > Change-Id: I69cd07a4bbe4879e855fb4aa6289a049adf4e059 > > Reviewed-on: https://skia-review.googlesource.com/c/160021 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Chris Dalton <csmartdalton@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,csmartdalton@google.com > > Change-Id: I309dfa5f7118cb8d7280aaf6a88e1df232bd7099 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia: > Reviewed-on: https://skia-review.googlesource.com/c/160163 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> TBR=egdaniel@google.com,bsalomon@google.com,csmartdalton@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia: Change-Id: Id2b5bdf883dbd0236f847649a30d15a492ab481e Reviewed-on: https://skia-review.googlesource.com/c/160461 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-10-08 17:35:08 +00:00
const GrSamplerState& samplerState) {
this->reset(textureType, config, samplerState);
}
GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType,
GrPixelConfig config,
GrSamplerState::Filter filterMode,
Reland "Remove ability to sample textures in vertex or geometry shaders." This reverts commit 6e2625d9ae89f6709a606bcf1a15b35741393e02. Reason for revert: Chrome fix has landed. This should work now. Original change's description: > Revert "Remove ability to sample textures in vertex or geometry shaders." > > This reverts commit d50d6579d1c00de65b947c0531fa04c043729e49. > > Reason for revert: chromes test gles test context is broken. Need to fix that then reland this > > Original change's description: > > Remove ability to sample textures in vertex or geometry shaders. > > > > Bug: skia: > > Change-Id: I69cd07a4bbe4879e855fb4aa6289a049adf4e059 > > Reviewed-on: https://skia-review.googlesource.com/c/160021 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Chris Dalton <csmartdalton@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,csmartdalton@google.com > > Change-Id: I309dfa5f7118cb8d7280aaf6a88e1df232bd7099 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia: > Reviewed-on: https://skia-review.googlesource.com/c/160163 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> TBR=egdaniel@google.com,bsalomon@google.com,csmartdalton@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia: Change-Id: Id2b5bdf883dbd0236f847649a30d15a492ab481e Reviewed-on: https://skia-review.googlesource.com/c/160461 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-10-08 17:35:08 +00:00
GrSamplerState::WrapMode wrapXAndY) {
this->reset(textureType, config, filterMode, wrapXAndY);
}
void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
GrPixelConfig config,
Reland "Remove ability to sample textures in vertex or geometry shaders." This reverts commit 6e2625d9ae89f6709a606bcf1a15b35741393e02. Reason for revert: Chrome fix has landed. This should work now. Original change's description: > Revert "Remove ability to sample textures in vertex or geometry shaders." > > This reverts commit d50d6579d1c00de65b947c0531fa04c043729e49. > > Reason for revert: chromes test gles test context is broken. Need to fix that then reland this > > Original change's description: > > Remove ability to sample textures in vertex or geometry shaders. > > > > Bug: skia: > > Change-Id: I69cd07a4bbe4879e855fb4aa6289a049adf4e059 > > Reviewed-on: https://skia-review.googlesource.com/c/160021 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Chris Dalton <csmartdalton@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,csmartdalton@google.com > > Change-Id: I309dfa5f7118cb8d7280aaf6a88e1df232bd7099 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia: > Reviewed-on: https://skia-review.googlesource.com/c/160163 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> TBR=egdaniel@google.com,bsalomon@google.com,csmartdalton@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia: Change-Id: Id2b5bdf883dbd0236f847649a30d15a492ab481e Reviewed-on: https://skia-review.googlesource.com/c/160461 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-10-08 17:35:08 +00:00
const GrSamplerState& samplerState) {
SkASSERT(kUnknown_GrPixelConfig != config);
fSamplerState = samplerState;
fSamplerState.setFilterMode(clamp_filter(textureType, samplerState.filter()));
fTextureType = textureType;
fConfig = config;
}
void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
GrPixelConfig config,
GrSamplerState::Filter filterMode,
Reland "Remove ability to sample textures in vertex or geometry shaders." This reverts commit 6e2625d9ae89f6709a606bcf1a15b35741393e02. Reason for revert: Chrome fix has landed. This should work now. Original change's description: > Revert "Remove ability to sample textures in vertex or geometry shaders." > > This reverts commit d50d6579d1c00de65b947c0531fa04c043729e49. > > Reason for revert: chromes test gles test context is broken. Need to fix that then reland this > > Original change's description: > > Remove ability to sample textures in vertex or geometry shaders. > > > > Bug: skia: > > Change-Id: I69cd07a4bbe4879e855fb4aa6289a049adf4e059 > > Reviewed-on: https://skia-review.googlesource.com/c/160021 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Chris Dalton <csmartdalton@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,csmartdalton@google.com > > Change-Id: I309dfa5f7118cb8d7280aaf6a88e1df232bd7099 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia: > Reviewed-on: https://skia-review.googlesource.com/c/160163 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> TBR=egdaniel@google.com,bsalomon@google.com,csmartdalton@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia: Change-Id: Id2b5bdf883dbd0236f847649a30d15a492ab481e Reviewed-on: https://skia-review.googlesource.com/c/160461 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-10-08 17:35:08 +00:00
GrSamplerState::WrapMode wrapXAndY) {
SkASSERT(kUnknown_GrPixelConfig != config);
filterMode = clamp_filter(textureType, filterMode);
fSamplerState = GrSamplerState(wrapXAndY, filterMode);
fTextureType = textureType;
fConfig = config;
}