GrMtlSampler.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright 2018 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. #ifndef GrMtlSampler_DEFINED
  8. #define GrMtlSampler_DEFINED
  9. #import <Metal/Metal.h>
  10. #include "src/core/SkOpts.h"
  11. #include <atomic>
  12. class GrSamplerState;
  13. class GrMtlGpu;
  14. // A wrapper for a MTLSamplerState object with caching support.
  15. class GrMtlSampler : public SkRefCnt {
  16. public:
  17. static GrMtlSampler* Create(const GrMtlGpu* gpu, const GrSamplerState&, uint32_t maxMipLevel);
  18. ~GrMtlSampler() { fMtlSamplerState = nil; }
  19. id<MTLSamplerState> mtlSampler() const { return fMtlSamplerState; }
  20. typedef uint32_t Key;
  21. // Helpers for hashing GrMtlSampler
  22. static Key GenerateKey(const GrSamplerState&, uint32_t maxMipLevel);
  23. static const Key& GetKey(const GrMtlSampler& sampler) { return sampler.fKey; }
  24. static uint32_t Hash(const Key& key) {
  25. return SkOpts::hash(reinterpret_cast<const uint32_t*>(&key), sizeof(Key));
  26. }
  27. private:
  28. GrMtlSampler(id<MTLSamplerState> mtlSamplerState, Key key)
  29. : fMtlSamplerState(mtlSamplerState)
  30. , fKey(key) {}
  31. id<MTLSamplerState> fMtlSamplerState;
  32. Key fKey;
  33. };
  34. #endif