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 #include "include/private/GrVkTypesPriv.h"
9 
10 #include "src/gpu/vk/GrVkImageLayout.h"
11 
cleanup()12 void GrVkBackendSurfaceInfo::cleanup() {
13     SkSafeUnref(fLayout);
14     fLayout = nullptr;
15 };
16 
assign(const GrVkBackendSurfaceInfo & that,bool isThisValid)17 void GrVkBackendSurfaceInfo::assign(const GrVkBackendSurfaceInfo& that, bool isThisValid) {
18     fImageInfo = that.fImageInfo;
19     GrVkImageLayout* oldLayout = fLayout;
20     fLayout = SkSafeRef(that.fLayout);
21     if (isThisValid) {
22         SkSafeUnref(oldLayout);
23     }
24 }
25 
setImageLayout(VkImageLayout layout)26 void GrVkBackendSurfaceInfo::setImageLayout(VkImageLayout layout) {
27     SkASSERT(fLayout);
28     fLayout->setImageLayout(layout);
29 }
30 
getGrVkImageLayout() const31 sk_sp<GrVkImageLayout> GrVkBackendSurfaceInfo::getGrVkImageLayout() const {
32     SkASSERT(fLayout);
33     return sk_ref_sp(fLayout);
34 }
35 
snapImageInfo() const36 GrVkImageInfo GrVkBackendSurfaceInfo::snapImageInfo() const {
37     return GrVkImageInfo(fImageInfo, fLayout->getImageLayout());
38 }
39 
40 #if GR_TEST_UTILS
operator ==(const GrVkBackendSurfaceInfo & that) const41 bool GrVkBackendSurfaceInfo::operator==(const GrVkBackendSurfaceInfo& that) const {
42     GrVkImageInfo cpyInfoThis = fImageInfo;
43     GrVkImageInfo cpyInfoThat = that.fImageInfo;
44     // We don't care about the fImageLayout here since we require they use the same
45     // GrVkImageLayout.
46     cpyInfoThis.fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
47     cpyInfoThat.fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
48     return cpyInfoThis == cpyInfoThat && fLayout == that.fLayout;
49 }
50 #endif
51