1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2020 Google LLC 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "include/gpu/GrBackendSemaphore.h" 9cb93a386Sopenharmony_ci 10cb93a386Sopenharmony_ci#ifdef SK_DIRECT3D 11cb93a386Sopenharmony_ci#include "include/gpu/d3d/GrD3DTypes.h" 12cb93a386Sopenharmony_ci 13cb93a386Sopenharmony_ciGrBackendSemaphore::~GrBackendSemaphore() { 14cb93a386Sopenharmony_ci if (fIsInitialized && GrBackendApi::kDirect3D == fBackend) { 15cb93a386Sopenharmony_ci delete fD3DFenceInfo; 16cb93a386Sopenharmony_ci fD3DFenceInfo = nullptr; 17cb93a386Sopenharmony_ci fIsInitialized = false; 18cb93a386Sopenharmony_ci } 19cb93a386Sopenharmony_ci} 20cb93a386Sopenharmony_ci 21cb93a386Sopenharmony_civoid GrBackendSemaphore::assignD3DFenceInfo(const GrD3DFenceInfo& info) { 22cb93a386Sopenharmony_ci SkASSERT(GrBackendApi::kDirect3D == fBackend); 23cb93a386Sopenharmony_ci if (fIsInitialized) { 24cb93a386Sopenharmony_ci *fD3DFenceInfo = info; 25cb93a386Sopenharmony_ci } else { 26cb93a386Sopenharmony_ci fD3DFenceInfo = new GrD3DFenceInfo(info); 27cb93a386Sopenharmony_ci } 28cb93a386Sopenharmony_ci} 29cb93a386Sopenharmony_ci 30cb93a386Sopenharmony_cibool GrBackendSemaphore::getD3DFenceInfo(GrD3DFenceInfo* outInfo) const { 31cb93a386Sopenharmony_ci if (fIsInitialized && GrBackendApi::kDirect3D == fBackend) { 32cb93a386Sopenharmony_ci *outInfo = *fD3DFenceInfo; 33cb93a386Sopenharmony_ci return true; 34cb93a386Sopenharmony_ci } 35cb93a386Sopenharmony_ci return false; 36cb93a386Sopenharmony_ci} 37cb93a386Sopenharmony_ci 38cb93a386Sopenharmony_ciGrBackendSemaphore::GrBackendSemaphore(const GrBackendSemaphore& that) { 39cb93a386Sopenharmony_ci fIsInitialized = false; 40cb93a386Sopenharmony_ci *this = that; 41cb93a386Sopenharmony_ci} 42cb93a386Sopenharmony_ci 43cb93a386Sopenharmony_ciGrBackendSemaphore& GrBackendSemaphore::operator=(const GrBackendSemaphore& that) { 44cb93a386Sopenharmony_ci SkASSERT(!fIsInitialized || fBackend == that.fBackend); 45cb93a386Sopenharmony_ci fBackend = that.fBackend; 46cb93a386Sopenharmony_ci switch (that.fBackend) { 47cb93a386Sopenharmony_ci#ifdef SK_GL 48cb93a386Sopenharmony_ci case GrBackendApi::kOpenGL: 49cb93a386Sopenharmony_ci fGLSync = that.fGLSync; 50cb93a386Sopenharmony_ci break; 51cb93a386Sopenharmony_ci#endif 52cb93a386Sopenharmony_ci#ifdef SK_VULKAN 53cb93a386Sopenharmony_ci case GrBackendApi::kVulkan: 54cb93a386Sopenharmony_ci fVkSemaphore = that.fVkSemaphore; 55cb93a386Sopenharmony_ci break; 56cb93a386Sopenharmony_ci#endif 57cb93a386Sopenharmony_ci#ifdef SK_METAL 58cb93a386Sopenharmony_ci case GrBackendApi::kMetal: 59cb93a386Sopenharmony_ci fMtlEvent = that.fMtlEvent; 60cb93a386Sopenharmony_ci fMtlValue = that.fMtlValue; 61cb93a386Sopenharmony_ci break; 62cb93a386Sopenharmony_ci#endif 63cb93a386Sopenharmony_ci case GrBackendApi::kDirect3D: 64cb93a386Sopenharmony_ci this->assignD3DFenceInfo(*that.fD3DFenceInfo); 65cb93a386Sopenharmony_ci break; 66cb93a386Sopenharmony_ci default: 67cb93a386Sopenharmony_ci SK_ABORT("Unknown GrBackend"); 68cb93a386Sopenharmony_ci } 69cb93a386Sopenharmony_ci fIsInitialized = true; 70cb93a386Sopenharmony_ci return *this; 71cb93a386Sopenharmony_ci} 72cb93a386Sopenharmony_ci 73cb93a386Sopenharmony_ci#endif // SK_DIRECT3D 74