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#ifndef GrBackendSurfaceMutableState_DEFINED
9#define GrBackendSurfaceMutableState_DEFINED
10
11#include "include/gpu/GrTypes.h"
12
13#ifdef SK_VULKAN
14#include "include/private/GrVkTypesPriv.h"
15#endif
16
17/**
18 * Since Skia and clients can both modify gpu textures and their connected state, Skia needs a way
19 * for clients to inform us if they have modifiend any of this state. In order to not need setters
20 * for every single API and state, we use this class to be a generic wrapper around all the mutable
21 * state. This class is used for calls that inform Skia of these texture/image state changes by the
22 * client as well as for requesting state changes to be done by Skia. The backend specific state
23 * that is wrapped by this class are:
24 *
25 * Vulkan: VkImageLayout and QueueFamilyIndex
26 */
27class GrBackendSurfaceMutableState {
28public:
29#ifdef SK_VULKAN
30 GrBackendSurfaceMutableState(VkImageLayout layout, uint32_t queueFamilyIndex)
31 : fVkState(layout, queueFamilyIndex)
32 , fBackend(GrBackend::kVulkan) {}
33#endif
34
35 GrBackendSurfaceMutableState& operator=(const GrBackendSurfaceMutableState& that) {
36 switch (fBackend) {
37 case GrBackend::kVulkan:
38#ifdef SK_VULKAN
39 SkASSERT(that.fBackend == GrBackend::kVulkan);
40 fVkState = that.fVkState;
41#endif
42 break;
43
44 default:
45 (void)that;
46 SkUNREACHABLE;
47 }
48 fBackend = that.fBackend;
49 return *this;
50 }
51
52private:
53 friend class GrBackendSurfaceMutableStateImpl;
54 friend class GrVkGpu;
55
56 union {
57 char fDummy;
58#ifdef SK_VULKAN
59 GrVkSharedImageInfo fVkState;
60#endif
61 };
62
63 GrBackend fBackend;
64};
65
66#endif
67