2020-05-29 16:11:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrBackendSurfaceMutableState_DEFINED
|
|
|
|
#define GrBackendSurfaceMutableState_DEFINED
|
|
|
|
|
|
|
|
#include "include/gpu/GrTypes.h"
|
|
|
|
|
|
|
|
#ifdef SK_VULKAN
|
|
|
|
#include "include/private/GrVkTypesPriv.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Since Skia and clients can both modify gpu textures and their connected state, Skia needs a way
|
|
|
|
* for clients to inform us if they have modifiend any of this state. In order to not need setters
|
|
|
|
* for every single API and state, we use this class to be a generic wrapper around all the mutable
|
|
|
|
* state. This class is used for calls that inform Skia of these texture/image state changes by the
|
|
|
|
* client as well as for requesting state changes to be done by Skia. The backend specific state
|
|
|
|
* that is wrapped by this class are:
|
|
|
|
*
|
|
|
|
* Vulkan: VkImageLayout and QueueFamilyIndex
|
|
|
|
*/
|
2020-09-23 18:23:36 +00:00
|
|
|
class SK_API GrBackendSurfaceMutableState {
|
2020-05-29 16:11:05 +00:00
|
|
|
public:
|
2020-09-23 18:23:36 +00:00
|
|
|
GrBackendSurfaceMutableState() {}
|
|
|
|
|
2020-05-29 16:11:05 +00:00
|
|
|
#ifdef SK_VULKAN
|
|
|
|
GrBackendSurfaceMutableState(VkImageLayout layout, uint32_t queueFamilyIndex)
|
|
|
|
: fVkState(layout, queueFamilyIndex)
|
2020-09-23 18:23:36 +00:00
|
|
|
, fBackend(GrBackend::kVulkan)
|
|
|
|
, fIsValid(true) {}
|
2020-05-29 16:11:05 +00:00
|
|
|
#endif
|
|
|
|
|
2020-09-23 18:23:36 +00:00
|
|
|
GrBackendSurfaceMutableState(const GrBackendSurfaceMutableState& that);
|
|
|
|
GrBackendSurfaceMutableState& operator=(const GrBackendSurfaceMutableState& that);
|
|
|
|
|
2020-05-29 16:11:05 +00:00
|
|
|
#ifdef SK_VULKAN
|
2020-09-23 18:23:36 +00:00
|
|
|
// If this class is not Vulkan backed it will return value of VK_IMAGE_LAYOUT_UNDEFINED.
|
|
|
|
// Otherwise it will return the VkImageLayout.
|
|
|
|
VkImageLayout getVkImageLayout() const {
|
|
|
|
if (this->isValid() && fBackend != GrBackendApi::kVulkan) {
|
|
|
|
return VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
}
|
|
|
|
return fVkState.getImageLayout();
|
|
|
|
}
|
2020-05-29 16:11:05 +00:00
|
|
|
|
2020-09-23 18:23:36 +00:00
|
|
|
// If this class is not Vulkan backed it will return value of VK_QUEUE_FAMILY_IGNORED.
|
|
|
|
// Otherwise it will return the VkImageLayout.
|
|
|
|
uint32_t getQueueFamilyIndex() const {
|
|
|
|
if (this->isValid() && fBackend != GrBackendApi::kVulkan) {
|
|
|
|
return VK_QUEUE_FAMILY_IGNORED;
|
2020-05-29 16:11:05 +00:00
|
|
|
}
|
2020-09-23 18:23:36 +00:00
|
|
|
return fVkState.getQueueFamilyIndex();
|
2020-05-29 16:11:05 +00:00
|
|
|
}
|
2020-09-23 18:23:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Returns true if the backend mutable state has been initialized.
|
|
|
|
bool isValid() const { return fIsValid; }
|
|
|
|
|
|
|
|
GrBackendApi backend() const { return fBackend; }
|
2020-05-29 16:11:05 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class GrBackendSurfaceMutableStateImpl;
|
2020-06-09 21:29:32 +00:00
|
|
|
friend class GrVkGpu;
|
2020-05-29 16:11:05 +00:00
|
|
|
|
2020-09-23 18:23:36 +00:00
|
|
|
#ifdef SK_VULKAN
|
|
|
|
void setVulkanState(VkImageLayout layout, uint32_t queueFamilyIndex) {
|
|
|
|
SkASSERT(!this->isValid() || fBackend == GrBackendApi::kVulkan);
|
|
|
|
fVkState.setImageLayout(layout);
|
|
|
|
fVkState.setQueueFamilyIndex(queueFamilyIndex);
|
|
|
|
fBackend = GrBackendApi::kVulkan;
|
|
|
|
fIsValid = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-29 16:11:05 +00:00
|
|
|
union {
|
|
|
|
char fDummy;
|
|
|
|
#ifdef SK_VULKAN
|
|
|
|
GrVkSharedImageInfo fVkState;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2020-09-23 18:23:36 +00:00
|
|
|
GrBackend fBackend = GrBackendApi::kMock;
|
|
|
|
bool fIsValid = false;
|
2020-05-29 16:11:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|