1/*
2* Copyright 2016 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
8#ifndef GrVkSampler_DEFINED
9#define GrVkSampler_DEFINED
10
11#include "GrVkResource.h"
12
13#include "vk/GrVkDefines.h"
14
15class GrSamplerParams;
16class GrVkGpu;
17
18
19class GrVkSampler : public GrVkResource {
20public:
21    static GrVkSampler* Create(const GrVkGpu* gpu, const GrSamplerParams&, uint32_t mipLevels);
22
23    VkSampler sampler() const { return fSampler; }
24
25    // Helpers for hashing GrVkSampler
26    static uint16_t GenerateKey(const GrSamplerParams&, uint32_t mipLevels);
27
28    static const uint16_t& GetKey(const GrVkSampler& sampler) { return sampler.fKey; }
29    static uint32_t Hash(const uint16_t& key) { return key; }
30
31#ifdef SK_TRACE_VK_RESOURCES
32    void dumpInfo() const override {
33        SkDebugf("GrVkSampler: %d (%d refs)\n", fSampler, this->getRefCnt());
34    }
35#endif
36
37private:
38    GrVkSampler(VkSampler sampler, uint16_t key) : INHERITED(), fSampler(sampler), fKey(key) {}
39
40    void freeGPUData(const GrVkGpu* gpu) const override;
41
42    VkSampler  fSampler;
43    uint16_t   fKey;
44
45    typedef GrVkResource INHERITED;
46};
47
48#endif
49