Flutter Engine
The Flutter Engine
GrMtlSampler.h
Go to the documentation of this file.
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
8#ifndef GrMtlSampler_DEFINED
9#define GrMtlSampler_DEFINED
10
11#import <Metal/Metal.h>
12
13#include "src/core/SkChecksum.h"
15#include <atomic>
16
17class GrSamplerState;
18class GrMtlGpu;
19
20// A wrapper for a MTLSamplerState object with caching support.
22public:
23 static GrMtlSampler* Create(const GrMtlGpu* gpu, GrSamplerState);
24 ~GrMtlSampler() override { fMtlSamplerState = nil; }
25
26 id<MTLSamplerState> mtlSampler() const { return fMtlSamplerState; }
27
28 typedef uint32_t Key;
29
30 // Helpers for hashing GrMtlSampler
32
33 static const Key& GetKey(const GrMtlSampler& sampler) { return sampler.fKey; }
34 static uint32_t Hash(const Key& key) {
35 return SkChecksum::Hash32(&key, sizeof(Key));
36 }
37
38#ifdef SK_TRACE_MANAGED_RESOURCES
39 /** output a human-readable dump of this resource's information
40 */
41 void dumpInfo() const override {
42 SkDebugf("GrMtlSampler: %p (%ld refs)\n", fMtlSamplerState,
43 CFGetRetainCount((CFTypeRef)fMtlSamplerState));
44 }
45#endif
46
47 void freeGPUData() const override {
48 fMtlSamplerState = nil;
49 }
50
51private:
52 GrMtlSampler(id<MTLSamplerState> mtlSamplerState, Key key)
53 : fMtlSamplerState(mtlSamplerState)
54 , fKey(key) {}
55
56 mutable id<MTLSamplerState> fMtlSamplerState;
57 Key fKey;
58};
59
60#endif
TArray< uint32_t > Key
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static uint32_t Hash(const Key &key)
Definition: GrMtlSampler.h:34
static const Key & GetKey(const GrMtlSampler &sampler)
Definition: GrMtlSampler.h:33
uint32_t Key
Definition: GrMtlSampler.h:28
id< MTLSamplerState > mtlSampler() const
Definition: GrMtlSampler.h:26
~GrMtlSampler() override
Definition: GrMtlSampler.h:24
static Key GenerateKey(GrSamplerState)
Definition: GrMtlSampler.mm:85
void freeGPUData() const override
Definition: GrMtlSampler.h:47
static GrMtlSampler * Create(const GrMtlGpu *gpu, GrSamplerState)
Definition: GrMtlSampler.mm:45
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)
Definition: SkChecksum.cpp:113