Skia
2D Graphics Library
GrBackendSurfaceMutableState.h
Go to the documentation of this file.
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 
28 public:
30 
31 #ifdef SK_VULKAN
32  GrBackendSurfaceMutableState(VkImageLayout layout, uint32_t queueFamilyIndex)
33  : fVkState(layout, queueFamilyIndex)
34  , fBackend(GrBackend::kVulkan)
35  , fIsValid(true) {}
36 #endif
37 
40 
41 #ifdef SK_VULKAN
42  // If this class is not Vulkan backed it will return value of VK_IMAGE_LAYOUT_UNDEFINED.
43  // Otherwise it will return the VkImageLayout.
44  VkImageLayout getVkImageLayout() const {
45  if (this->isValid() && fBackend != GrBackendApi::kVulkan) {
46  return VK_IMAGE_LAYOUT_UNDEFINED;
47  }
48  return fVkState.getImageLayout();
49  }
50 
51  // If this class is not Vulkan backed it will return value of VK_QUEUE_FAMILY_IGNORED.
52  // Otherwise it will return the VkImageLayout.
53  uint32_t getQueueFamilyIndex() const {
54  if (this->isValid() && fBackend != GrBackendApi::kVulkan) {
55  return VK_QUEUE_FAMILY_IGNORED;
56  }
57  return fVkState.getQueueFamilyIndex();
58  }
59 #endif
60 
61  // Returns true if the backend mutable state has been initialized.
62  bool isValid() const { return fIsValid; }
63 
64  GrBackendApi backend() const { return fBackend; }
65 
66 private:
67  friend class GrBackendSurfaceMutableStateImpl;
68  friend class GrVkGpu;
69 
70 #ifdef SK_VULKAN
71  void setVulkanState(VkImageLayout layout, uint32_t queueFamilyIndex) {
72  SkASSERT(!this->isValid() || fBackend == GrBackendApi::kVulkan);
73  fVkState.setImageLayout(layout);
74  fVkState.setQueueFamilyIndex(queueFamilyIndex);
75  fBackend = GrBackendApi::kVulkan;
76  fIsValid = true;
77  }
78 #endif
79 
80  union {
81  char fDummy;
82 #ifdef SK_VULKAN
83  GrVkSharedImageInfo fVkState;
84 #endif
85  };
86 
87  GrBackend fBackend = GrBackendApi::kMock;
88  bool fIsValid = false;
89 };
90 
91 #endif
GrBackendSurfaceMutableState::GrBackendSurfaceMutableState
GrBackendSurfaceMutableState()
Definition: GrBackendSurfaceMutableState.h:29
GrBackendSurfaceMutableState::operator=
GrBackendSurfaceMutableState & operator=(const GrBackendSurfaceMutableState &that)
GrBackendSurfaceMutableState::GrBackendSurfaceMutableState
GrBackendSurfaceMutableState(const GrBackendSurfaceMutableState &that)
SK_API
#define SK_API
Definition: SkTypes.h:181
SkASSERT
#define SkASSERT(cond)
Definition: SkTypes.h:460
GrBackendApi::kVulkan
@ kVulkan
GrBackendSurfaceMutableState::fDummy
char fDummy
Definition: GrBackendSurfaceMutableState.h:81
GrBackendApi
GrBackendApi
Possible 3D APIs that may be used by Ganesh.
Definition: GrTypes.h:135
GrTypes.h
GrBackendSurfaceMutableState::backend
GrBackendApi backend() const
Definition: GrBackendSurfaceMutableState.h:64
GrBackendSurfaceMutableState
Since Skia and clients can both modify gpu textures and their connected state, Skia needs a way for c...
Definition: GrBackendSurfaceMutableState.h:27
GrBackendSurfaceMutableState::isValid
bool isValid() const
Definition: GrBackendSurfaceMutableState.h:62
GrBackendApi::kMock
@ kMock
Mock is a backend that does not draw anything.