GrPrimitiveProcessor.cpp 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  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. #include "src/gpu/GrPrimitiveProcessor.h"
  8. #include "src/gpu/GrCoordTransform.h"
  9. /**
  10. * We specialize the vertex code for each of these matrix types.
  11. */
  12. enum MatrixType {
  13. kNoPersp_MatrixType = 0,
  14. kGeneral_MatrixType = 1,
  15. };
  16. GrPrimitiveProcessor::GrPrimitiveProcessor(ClassID classID) : GrProcessor(classID) {}
  17. const GrPrimitiveProcessor::TextureSampler& GrPrimitiveProcessor::textureSampler(int i) const {
  18. SkASSERT(i >= 0 && i < this->numTextureSamplers());
  19. return this->onTextureSampler(i);
  20. }
  21. uint32_t
  22. GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords,
  23. int numCoords) const {
  24. uint32_t totalKey = 0;
  25. for (int t = 0; t < numCoords; ++t) {
  26. uint32_t key = 0;
  27. const GrCoordTransform* coordTransform = coords[t];
  28. if (coordTransform->getMatrix().hasPerspective()) {
  29. key |= kGeneral_MatrixType;
  30. } else {
  31. key |= kNoPersp_MatrixType;
  32. }
  33. key <<= t;
  34. SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap
  35. totalKey |= key;
  36. }
  37. return totalKey;
  38. }
  39. ///////////////////////////////////////////////////////////////////////////////////////////////////
  40. static inline GrSamplerState::Filter clamp_filter(GrTextureType type,
  41. GrSamplerState::Filter requestedFilter) {
  42. if (GrTextureTypeHasRestrictedSampling(type)) {
  43. return SkTMin(requestedFilter, GrSamplerState::Filter::kBilerp);
  44. }
  45. return requestedFilter;
  46. }
  47. GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType,
  48. GrPixelConfig config,
  49. const GrSamplerState& samplerState,
  50. const GrSwizzle& swizzle,
  51. uint32_t extraSamplerKey) {
  52. this->reset(textureType, config, samplerState, swizzle, extraSamplerKey);
  53. }
  54. GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType,
  55. GrPixelConfig config,
  56. GrSamplerState::Filter filterMode,
  57. GrSamplerState::WrapMode wrapXAndY,
  58. const GrSwizzle& swizzle) {
  59. this->reset(textureType, config, filterMode, wrapXAndY, swizzle);
  60. }
  61. void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
  62. GrPixelConfig config,
  63. const GrSamplerState& samplerState,
  64. const GrSwizzle& swizzle,
  65. uint32_t extraSamplerKey) {
  66. SkASSERT(kUnknown_GrPixelConfig != config);
  67. fSamplerState = samplerState;
  68. fSamplerState.setFilterMode(clamp_filter(textureType, samplerState.filter()));
  69. fSwizzle = swizzle;
  70. fTextureType = textureType;
  71. fConfig = config;
  72. fExtraSamplerKey = extraSamplerKey;
  73. SkASSERT(!fExtraSamplerKey || textureType == GrTextureType::kExternal);
  74. }
  75. void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
  76. GrPixelConfig config,
  77. GrSamplerState::Filter filterMode,
  78. GrSamplerState::WrapMode wrapXAndY,
  79. const GrSwizzle& swizzle) {
  80. SkASSERT(kUnknown_GrPixelConfig != config);
  81. filterMode = clamp_filter(textureType, filterMode);
  82. fSamplerState = GrSamplerState(wrapXAndY, filterMode);
  83. fSwizzle = swizzle;
  84. fTextureType = textureType;
  85. fConfig = config;
  86. }