• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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 
8 #include "include/gpu/GrBackendSemaphore.h"
9 
10 #ifdef SK_DIRECT3D
11 #include "include/gpu/d3d/GrD3DTypes.h"
12 
~GrBackendSemaphore()13 GrBackendSemaphore::~GrBackendSemaphore() {
14     if (fIsInitialized && GrBackendApi::kDirect3D == fBackend) {
15         delete fD3DFenceInfo;
16         fD3DFenceInfo = nullptr;
17         fIsInitialized = false;
18     }
19 }
20 
assignD3DFenceInfo(const GrD3DFenceInfo & info)21 void GrBackendSemaphore::assignD3DFenceInfo(const GrD3DFenceInfo& info) {
22     SkASSERT(GrBackendApi::kDirect3D == fBackend);
23     if (fIsInitialized) {
24         *fD3DFenceInfo = info;
25     } else {
26         fD3DFenceInfo = new GrD3DFenceInfo(info);
27     }
28 }
29 
getD3DFenceInfo(GrD3DFenceInfo * outInfo) const30 bool GrBackendSemaphore::getD3DFenceInfo(GrD3DFenceInfo* outInfo) const {
31     if (fIsInitialized && GrBackendApi::kDirect3D == fBackend) {
32         *outInfo = *fD3DFenceInfo;
33         return true;
34     }
35     return false;
36 }
37 
GrBackendSemaphore(const GrBackendSemaphore & that)38 GrBackendSemaphore::GrBackendSemaphore(const GrBackendSemaphore& that) {
39     fIsInitialized = false;
40     *this = that;
41 }
42 
operator =(const GrBackendSemaphore & that)43 GrBackendSemaphore& GrBackendSemaphore::operator=(const GrBackendSemaphore& that) {
44     SkASSERT(!fIsInitialized || fBackend == that.fBackend);
45     fBackend = that.fBackend;
46     switch (that.fBackend) {
47 #ifdef SK_GL
48     case GrBackendApi::kOpenGL:
49         fGLSync = that.fGLSync;
50         break;
51 #endif
52 #ifdef SK_VULKAN
53     case GrBackendApi::kVulkan:
54         fVkSemaphore = that.fVkSemaphore;
55         break;
56 #endif
57 #ifdef SK_METAL
58     case GrBackendApi::kMetal:
59         fMtlEvent = that.fMtlEvent;
60         fMtlValue = that.fMtlValue;
61         break;
62 #endif
63     case GrBackendApi::kDirect3D:
64         this->assignD3DFenceInfo(*that.fD3DFenceInfo);
65         break;
66     default:
67         SK_ABORT("Unknown GrBackend");
68     }
69     fIsInitialized = true;
70     return *this;
71 }
72 
73 #endif // SK_DIRECT3D
74