Debian Codegraph @

src/gpu/ganesh/mtl/GrMtlBackendSemaphore.mm

raw
1 /*
2 * Copyright 2024 Google LLC
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 "include/gpu/ganesh/mtl/GrMtlBackendSemaphore.h"
8
9 #include "include/gpu/ganesh/GrTypes.h"
10 #include "include/private/base/SkAssert.h"
11 #include "src/gpu/ganesh/GrBackendSemaphorePriv.h"
12
13 #if !__has_feature(objc_arc)
14 #error This file must be compiled with Arc. Use -fobjc-arc flag
15 #endif
16
17 class GrMtlBackendSemaphoreData final : public GrBackendSemaphoreData {
18 public:
19 GrMtlBackendSemaphoreData(GrMTLHandle event, uint64_t value) : fEvent(event), fValue(value) {}
20
21 GrMTLHandle event() const { return fEvent; }
22 uint64_t value() const { return fValue; }
23
24 private:
25 void copyTo(AnySemaphoreData& data) const override {
26 data.emplace<GrMtlBackendSemaphoreData>(fEvent, fValue);
27 }
28
29 #if defined(SK_DEBUG)
30 GrBackendApi type() const override { return GrBackendApi::kMetal; }
31 #endif
32
33 GrMTLHandle fEvent;
34 uint64_t fValue;
35 };
36
37 static const GrMtlBackendSemaphoreData* get_and_cast_data(const GrBackendSemaphore& sem) {
38 auto data = GrBackendSemaphorePriv::GetBackendData(sem);
39 SkASSERT(!data || data->type() == GrBackendApi::kMetal);
40 return static_cast<const GrMtlBackendSemaphoreData*>(data);
41 }
42
43 namespace GrBackendSemaphores {
44 GrBackendSemaphore MakeMtl(GrMTLHandle event, uint64_t value) {
45 GrMtlBackendSemaphoreData data(event, value);
46 return GrBackendSemaphorePriv::MakeGrBackendSemaphore(GrBackendApi::kMetal, data);
47 }
48
49 GrMTLHandle GetMtlHandle(const GrBackendSemaphore& sem) {
50 SkASSERT(sem.backend() == GrBackendApi::kMetal);
51 const GrMtlBackendSemaphoreData* data = get_and_cast_data(sem);
52 SkASSERT(data);
53 return data->event();
54 }
55
56 uint64_t GetMtlValue(const GrBackendSemaphore& sem) {
57 SkASSERT(sem.backend() == GrBackendApi::kMetal);
58 const GrMtlBackendSemaphoreData* data = get_and_cast_data(sem);
59 SkASSERT(data);
60 return data->value();
61 }
62 } // namespace GrBackendSemaphores