#include "include/gpu/ganesh/GrBackendSurface.h"
#include "include/core/SkTextureCompressionType.h"
#include "include/gpu/ganesh/GrTypes.h"
#include "include/gpu/MutableTextureState.h"
#include "include/private/base/SkAssert.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/gpu/GpuTypesPriv.h"
#include "src/gpu/ganesh/GrBackendSurfacePriv.h"
#include "src/gpu/ganesh/GrUtil.h"
#ifdef SK_DIRECT3D
#include "include/gpu/ganesh/d3d/GrD3DTypes.h"
#include "src/gpu/ganesh/d3d/GrD3DResourceState.h"
#include "src/gpu/ganesh/d3d/GrD3DUtil.h"
#endif
#include <algorithm>
#include <new>
GrBackendFormat::GrBackendFormat() : … { … }
GrBackendFormat::~GrBackendFormat() = default;
GrBackendFormat::GrBackendFormat(const GrBackendFormat& that)
: … { … }
GrBackendFormat& GrBackendFormat::operator=(const GrBackendFormat& that) { … }
#ifdef SK_DIRECT3D
GrBackendFormat::GrBackendFormat(DXGI_FORMAT dxgiFormat)
: fBackend(GrBackendApi::kDirect3D)
, fValid(true)
, fDxgiFormat(dxgiFormat)
, fTextureType(GrTextureType::k2D) {
}
bool GrBackendFormat::asDxgiFormat(DXGI_FORMAT* dxgiFormat) const {
if (this->isValid() && GrBackendApi::kDirect3D == fBackend) {
*dxgiFormat = fDxgiFormat;
return true;
}
return false;
}
#endif
GrBackendFormat::GrBackendFormat(GrColorType colorType, SkTextureCompressionType compression,
bool isStencilFormat)
: … { … }
uint32_t GrBackendFormat::channelMask() const { … }
GrColorFormatDesc GrBackendFormat::desc() const { … }
#ifdef SK_DEBUG
bool GrBackendFormat::validateMock() const { … }
#endif
GrColorType GrBackendFormat::asMockColorType() const { … }
SkTextureCompressionType GrBackendFormat::asMockCompressionType() const { … }
bool GrBackendFormat::isMockStencilFormat() const { … }
GrBackendFormat GrBackendFormat::makeTexture2D() const { … }
GrBackendFormat GrBackendFormat::MakeMock(GrColorType colorType,
SkTextureCompressionType compression,
bool isStencilFormat) { … }
bool GrBackendFormat::operator==(const GrBackendFormat& that) const { … }
#if defined(SK_DEBUG) || defined(GPU_TEST_UTILS)
#include "include/core/SkString.h"
SkString GrBackendFormat::toStr() const { … }
#endif
GrBackendTexture::GrBackendTexture() : … { … }
#ifdef SK_DIRECT3D
GrBackendTexture::GrBackendTexture(int width,
int height,
const GrD3DTextureResourceInfo& d3dInfo,
std::string_view label)
: GrBackendTexture(width,
height,
d3dInfo,
sk_sp<GrD3DResourceState>(new GrD3DResourceState(
static_cast<D3D12_RESOURCE_STATES>(d3dInfo.fResourceState))),
label) {}
GrBackendTexture::GrBackendTexture(int width,
int height,
const GrD3DTextureResourceInfo& d3dInfo,
sk_sp<GrD3DResourceState> state,
std::string_view label)
: fIsValid(true)
, fWidth(width)
, fHeight(height)
, fLabel(label)
, fMipmapped(skgpu::Mipmapped(d3dInfo.fLevelCount > 1))
, fBackend(GrBackendApi::kDirect3D)
, fTextureType(GrTextureType::k2D)
, fD3DInfo(d3dInfo, state.release()) {}
#endif
GrBackendTexture::GrBackendTexture(int width,
int height,
skgpu::Mipmapped mipmapped,
const GrMockTextureInfo& mockInfo,
std::string_view label)
: … { … }
GrBackendTexture::~GrBackendTexture() { … }
void GrBackendTexture::cleanup() { … }
GrBackendTexture::GrBackendTexture(const GrBackendTexture& that) : … { … }
GrBackendTexture& GrBackendTexture::operator=(const GrBackendTexture& that) { … }
sk_sp<skgpu::MutableTextureState> GrBackendTexture::getMutableState() const { … }
#ifdef SK_DIRECT3D
bool GrBackendTexture::getD3DTextureResourceInfo(GrD3DTextureResourceInfo* outInfo) const {
if (this->isValid() && GrBackendApi::kDirect3D == fBackend) {
*outInfo = fD3DInfo.snapTextureResourceInfo();
return true;
}
return false;
}
void GrBackendTexture::setD3DResourceState(GrD3DResourceStateEnum state) {
if (this->isValid() && GrBackendApi::kDirect3D == fBackend) {
fD3DInfo.setResourceState(state);
}
}
sk_sp<GrD3DResourceState> GrBackendTexture::getGrD3DResourceState() const {
if (this->isValid() && GrBackendApi::kDirect3D == fBackend) {
return fD3DInfo.getGrD3DResourceState();
}
return nullptr;
}
#endif
bool GrBackendTexture::getMockTextureInfo(GrMockTextureInfo* outInfo) const { … }
void GrBackendTexture::setMutableState(const skgpu::MutableTextureState& state) { … }
bool GrBackendTexture::isProtected() const { … }
bool GrBackendTexture::isSameTexture(const GrBackendTexture& that) { … }
GrBackendFormat GrBackendTexture::getBackendFormat() const { … }
#if defined(GPU_TEST_UTILS)
bool GrBackendTexture::TestingOnly_Equals(const GrBackendTexture& t0, const GrBackendTexture& t1) {
if (!t0.isValid() || !t1.isValid()) {
return false;
}
if (t0.fWidth != t1.fWidth ||
t0.fHeight != t1.fHeight ||
t0.fMipmapped != t1.fMipmapped ||
t0.fBackend != t1.fBackend) {
return false;
}
switch (t0.fBackend) {
case GrBackendApi::kOpenGL:
case GrBackendApi::kVulkan:
case GrBackendApi::kMetal:
return t0.fTextureData->equal(t1.fTextureData.get());
case GrBackendApi::kMock:
return t0.fMockInfo == t1.fMockInfo;
#ifdef SK_DIRECT3D
case GrBackendApi::kDirect3D:
return t0.fD3DInfo == t1.fD3DInfo;
#endif
default:
return false;
}
}
#endif
GrBackendRenderTarget::GrBackendRenderTarget() : … { … }
#ifdef SK_DIRECT3D
GrBackendRenderTarget::GrBackendRenderTarget(int width, int height,
const GrD3DTextureResourceInfo& d3dInfo)
: GrBackendRenderTarget(
width, height, d3dInfo,
sk_sp<GrD3DResourceState>(new GrD3DResourceState(
static_cast<D3D12_RESOURCE_STATES>(d3dInfo.fResourceState)))) {}
GrBackendRenderTarget::GrBackendRenderTarget(int width,
int height,
const GrD3DTextureResourceInfo& d3dInfo,
sk_sp<GrD3DResourceState> state)
: fIsValid(true)
, fWidth(width)
, fHeight(height)
, fSampleCnt(std::max(1U, d3dInfo.fSampleCount))
, fStencilBits(0)
, fBackend(GrBackendApi::kDirect3D)
, fD3DInfo(d3dInfo, state.release()) {}
#endif
GrBackendRenderTarget::GrBackendRenderTarget(int width,
int height,
int sampleCnt,
int stencilBits,
const GrMockRenderTargetInfo& mockInfo)
: … { … }
GrBackendRenderTarget::~GrBackendRenderTarget() { … }
void GrBackendRenderTarget::cleanup() { … }
GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTarget& that) : … { … }
GrBackendRenderTarget& GrBackendRenderTarget::operator=(const GrBackendRenderTarget& that) { … }
sk_sp<skgpu::MutableTextureState> GrBackendRenderTarget::getMutableState() const { … }
#ifdef SK_DIRECT3D
bool GrBackendRenderTarget::getD3DTextureResourceInfo(GrD3DTextureResourceInfo* outInfo) const {
if (this->isValid() && GrBackendApi::kDirect3D == fBackend) {
*outInfo = fD3DInfo.snapTextureResourceInfo();
return true;
}
return false;
}
void GrBackendRenderTarget::setD3DResourceState(GrD3DResourceStateEnum state) {
if (this->isValid() && GrBackendApi::kDirect3D == fBackend) {
fD3DInfo.setResourceState(state);
}
}
sk_sp<GrD3DResourceState> GrBackendRenderTarget::getGrD3DResourceState() const {
if (this->isValid() && GrBackendApi::kDirect3D == fBackend) {
return fD3DInfo.getGrD3DResourceState();
}
return nullptr;
}
#endif
GrBackendFormat GrBackendRenderTarget::getBackendFormat() const { … }
bool GrBackendRenderTarget::getMockRenderTargetInfo(GrMockRenderTargetInfo* outInfo) const { … }
void GrBackendRenderTarget::setMutableState(const skgpu::MutableTextureState& state) { … }
bool GrBackendRenderTarget::isProtected() const { … }
#if defined(GPU_TEST_UTILS)
bool GrBackendRenderTarget::TestingOnly_Equals(const GrBackendRenderTarget& r0,
const GrBackendRenderTarget& r1) {
if (!r0.isValid() || !r1.isValid()) {
return false;
}
if (r0.fWidth != r1.fWidth ||
r0.fHeight != r1.fHeight ||
r0.fSampleCnt != r1.fSampleCnt ||
r0.fStencilBits != r1.fStencilBits ||
r0.fBackend != r1.fBackend) {
return false;
}
switch (r0.fBackend) {
case GrBackendApi::kOpenGL:
case GrBackendApi::kVulkan:
case GrBackendApi::kMetal:
return r0.fRTData->equal(r1.fRTData.get());
case GrBackendApi::kMock:
return r0.fMockInfo == r1.fMockInfo;
#ifdef SK_DIRECT3D
case GrBackendApi::kDirect3D:
return r0.fD3DInfo == r1.fD3DInfo;
#endif
default:
return false;
}
SkASSERT(0);
return false;
}
#endif
GrBackendFormatData::~GrBackendFormatData() { … }
GrBackendTextureData::~GrBackendTextureData() { … }
GrBackendRenderTargetData::~GrBackendRenderTargetData() { … }