Flutter Engine
The Flutter Engine
GrMtlDepthStencil.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 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 GrMtlDepthStencil_DEFINED
9#define GrMtlDepthStencil_DEFINED
10
11#import <Metal/Metal.h>
12
13#include "include/gpu/GrTypes.h"
14#include "src/core/SkChecksum.h"
16#include <atomic>
17
18class GrMtlGpu;
20
21// A wrapper for a MTLDepthStencilState object with caching support.
23public:
25
26 ~GrMtlDepthStencil() override { fMtlDepthStencilState = nil; }
27
28 id<MTLDepthStencilState> mtlDepthStencil() const { return fMtlDepthStencilState; }
29
30 struct Key {
31 struct Face {
32 uint32_t fReadMask;
33 uint32_t fWriteMask;
34 uint32_t fOps;
35 };
38
39 bool operator==(const Key& that) const {
40 return this->fFront.fReadMask == that.fFront.fReadMask &&
41 this->fFront.fWriteMask == that.fFront.fWriteMask &&
42 this->fFront.fOps == that.fFront.fOps &&
43 this->fBack.fReadMask == that.fBack.fReadMask &&
44 this->fBack.fWriteMask == that.fBack.fWriteMask &&
45 this->fBack.fOps == that.fBack.fOps;
46 }
47 };
48
49 // Helpers for hashing GrMtlDepthStencil
51
52 static const Key& GetKey(const GrMtlDepthStencil& depthStencil) { return depthStencil.fKey; }
53 static uint32_t Hash(const Key& key) {
54 return SkChecksum::Hash32(&key, sizeof(Key));
55 }
56
57#ifdef SK_TRACE_MANAGED_RESOURCES
58 /** output a human-readable dump of this resource's information
59 */
60 void dumpInfo() const override {
61 SkDebugf("GrMtlDepthStencil: %p (%ld refs)\n", fMtlDepthStencilState,
62 CFGetRetainCount((CFTypeRef)fMtlDepthStencilState));
63 }
64#endif
65
66 void freeGPUData() const override {
67 fMtlDepthStencilState = nil;
68 }
69
70private:
71 GrMtlDepthStencil(id<MTLDepthStencilState> mtlDepthStencilState, Key key)
72 : fMtlDepthStencilState(mtlDepthStencilState)
73 , fKey(key) {}
74
75 mutable id<MTLDepthStencilState> fMtlDepthStencilState;
76 Key fKey;
77};
78
79#endif
TArray< uint32_t > Key
GrSurfaceOrigin
Definition: GrTypes.h:147
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
void freeGPUData() const override
static Key GenerateKey(const GrStencilSettings &, GrSurfaceOrigin)
static uint32_t Hash(const Key &key)
static const Key & GetKey(const GrMtlDepthStencil &depthStencil)
static GrMtlDepthStencil * Create(const GrMtlGpu *, const GrStencilSettings &, GrSurfaceOrigin)
id< MTLDepthStencilState > mtlDepthStencil() const
~GrMtlDepthStencil() override
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)
Definition: SkChecksum.cpp:113
bool operator==(const Key &that) const