| 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/chromium/GrSurfaceCharacterization.h" |
| 9 |
|
| 10 |
#include "include/core/SkColorSpace.h" |
| 11 |
#include "include/private/gpu/ganesh/GrTypesPriv.h" |
| 12 |
#include "src/gpu/ganesh/GrCaps.h" |
| 13 |
#include "src/gpu/ganesh/GrContextThreadSafeProxyPriv.h" |
| 14 |
|
| 15 |
#ifdef SK_DEBUG |
| 16 |
void GrSurfaceCharacterization::validate() const { |
| 17 |
const GrCaps* caps = fContextInfo->priv().caps(); |
| 18 |
|
| 19 |
GrColorType grCT = SkColorTypeToGrColorType(this->colorType()); |
| 20 |
SkASSERT(fSampleCnt && caps->isFormatAsColorTypeRenderable(grCT, fBackendFormat, fSampleCnt)); |
| 21 |
|
| 22 |
SkASSERT(caps->areColorTypeAndFormatCompatible(grCT, fBackendFormat)); |
| 23 |
|
| 24 |
SkASSERT(skgpu::Mipmapped::kNo == fIsMipmapped || Textureable::kYes == fIsTextureable); |
| 25 |
SkASSERT(Textureable::kNo == fIsTextureable || UsesGLFBO0::kNo == fUsesGLFBO0); |
| 26 |
auto backend = fBackendFormat.backend(); |
| 27 |
SkASSERT(UsesGLFBO0::kNo == fUsesGLFBO0 || backend == GrBackendApi::kOpenGL); |
| 28 |
SkASSERT((VulkanSecondaryCBCompatible::kNo == fVulkanSecondaryCBCompatible && |
| 29 |
VkRTSupportsInputAttachment::kNo == fVkRTSupportsInputAttachment) || |
| 30 |
backend == GrBackendApi::kVulkan); |
| 31 |
SkASSERT(VulkanSecondaryCBCompatible::kNo == fVulkanSecondaryCBCompatible || |
| 32 |
VkRTSupportsInputAttachment::kNo == fVkRTSupportsInputAttachment); |
| 33 |
SkASSERT(Textureable::kNo == fIsTextureable || |
| 34 |
VulkanSecondaryCBCompatible::kNo == fVulkanSecondaryCBCompatible); |
| 35 |
} |
| 36 |
#endif |
| 37 |
|
| 38 |
|
| 39 |
bool GrSurfaceCharacterization::operator==(const GrSurfaceCharacterization& other) const { |
| 40 |
if (!this->isValid() || !other.isValid()) { |
| 41 |
return false; |
| 42 |
} |
| 43 |
|
| 44 |
if (fContextInfo != other.fContextInfo) { |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
return fCacheMaxResourceBytes == other.fCacheMaxResourceBytes && |
| 49 |
fOrigin == other.fOrigin && |
| 50 |
fImageInfo == other.fImageInfo && |
| 51 |
fBackendFormat == other.fBackendFormat && |
| 52 |
fSampleCnt == other.fSampleCnt && |
| 53 |
fIsTextureable == other.fIsTextureable && |
| 54 |
fIsMipmapped == other.fIsMipmapped && |
| 55 |
fUsesGLFBO0 == other.fUsesGLFBO0 && |
| 56 |
fVulkanSecondaryCBCompatible == other.fVulkanSecondaryCBCompatible && |
| 57 |
fIsProtected == other.fIsProtected && |
| 58 |
fSurfaceProps == other.fSurfaceProps; |
| 59 |
} |
| 60 |
|
| 61 |
GrSurfaceCharacterization GrSurfaceCharacterization::createResized(int width, int height) const { |
| 62 |
const GrCaps* caps = fContextInfo->priv().caps(); |
| 63 |
if (!caps) { |
| 64 |
return GrSurfaceCharacterization(); |
| 65 |
} |
| 66 |
|
| 67 |
if (width <= 0 || height <= 0 || width > caps->maxRenderTargetSize() || |
| 68 |
height > caps->maxRenderTargetSize()) { |
| 69 |
return GrSurfaceCharacterization(); |
| 70 |
} |
| 71 |
|
| 72 |
return GrSurfaceCharacterization(fContextInfo, |
| 73 |
fCacheMaxResourceBytes, |
| 74 |
fImageInfo.makeWH(width, height), |
| 75 |
fBackendFormat, |
| 76 |
fOrigin, |
| 77 |
fSampleCnt, |
| 78 |
fIsTextureable, |
| 79 |
fIsMipmapped, |
| 80 |
fUsesGLFBO0, |
| 81 |
fVkRTSupportsInputAttachment, |
| 82 |
fVulkanSecondaryCBCompatible, |
| 83 |
fIsProtected, |
| 84 |
fSurfaceProps); |
| 85 |
} |
| 86 |
|
| 87 |
GrSurfaceCharacterization GrSurfaceCharacterization::createColorSpace( |
| 88 |
sk_sp<SkColorSpace> cs) const { |
| 89 |
if (!this->isValid()) { |
| 90 |
return GrSurfaceCharacterization(); |
| 91 |
} |
| 92 |
|
| 93 |
return GrSurfaceCharacterization(fContextInfo, |
| 94 |
fCacheMaxResourceBytes, |
| 95 |
fImageInfo.makeColorSpace(std::move(cs)), |
| 96 |
fBackendFormat, |
| 97 |
fOrigin, |
| 98 |
fSampleCnt, |
| 99 |
fIsTextureable, |
| 100 |
fIsMipmapped, |
| 101 |
fUsesGLFBO0, |
| 102 |
fVkRTSupportsInputAttachment, |
| 103 |
fVulkanSecondaryCBCompatible, |
| 104 |
fIsProtected, |
| 105 |
fSurfaceProps); |
| 106 |
} |
| 107 |
|
| 108 |
GrSurfaceCharacterization GrSurfaceCharacterization::createBackendFormat( |
| 109 |
SkColorType colorType, |
| 110 |
const GrBackendFormat& backendFormat) const { |
| 111 |
if (!this->isValid()) { |
| 112 |
return GrSurfaceCharacterization(); |
| 113 |
} |
| 114 |
|
| 115 |
SkImageInfo newII = fImageInfo.makeColorType(colorType); |
| 116 |
|
| 117 |
return GrSurfaceCharacterization(fContextInfo, |
| 118 |
fCacheMaxResourceBytes, |
| 119 |
newII, |
| 120 |
backendFormat, |
| 121 |
fOrigin, |
| 122 |
fSampleCnt, |
| 123 |
fIsTextureable, |
| 124 |
fIsMipmapped, |
| 125 |
fUsesGLFBO0, |
| 126 |
fVkRTSupportsInputAttachment, |
| 127 |
fVulkanSecondaryCBCompatible, |
| 128 |
fIsProtected, |
| 129 |
fSurfaceProps); |
| 130 |
} |
| 131 |
|
| 132 |
GrSurfaceCharacterization GrSurfaceCharacterization::createFBO0(bool usesGLFBO0) const { |
| 133 |
if (!this->isValid()) { |
| 134 |
return GrSurfaceCharacterization(); |
| 135 |
} |
| 136 |
|
| 137 |
// We can't create an FBO0 characterization that is textureable or has any non-gl specific flags |
| 138 |
if (fIsTextureable == Textureable::kYes || |
| 139 |
fVkRTSupportsInputAttachment == VkRTSupportsInputAttachment::kYes || |
| 140 |
fVulkanSecondaryCBCompatible == VulkanSecondaryCBCompatible::kYes) { |
| 141 |
return GrSurfaceCharacterization(); |
| 142 |
} |
| 143 |
|
| 144 |
return GrSurfaceCharacterization(fContextInfo, |
| 145 |
fCacheMaxResourceBytes, |
| 146 |
fImageInfo, |
| 147 |
fBackendFormat, |
| 148 |
fOrigin, |
| 149 |
fSampleCnt, |
| 150 |
fIsTextureable, |
| 151 |
fIsMipmapped, |
| 152 |
usesGLFBO0 ? UsesGLFBO0::kYes : UsesGLFBO0::kNo, |
| 153 |
fVkRTSupportsInputAttachment, |
| 154 |
fVulkanSecondaryCBCompatible, |
| 155 |
fIsProtected, |
| 156 |
fSurfaceProps); |
| 157 |
} |