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/core/SkSurfaceCharacterization.h"
9
10 #if SK_SUPPORT_GPU
11 #include "src/gpu/GrCaps.h"
12 #include "src/gpu/GrContextThreadSafeProxyPriv.h"
13
14 #ifdef SK_DEBUG
validate() const15 void SkSurfaceCharacterization::validate() const {
16 const GrCaps* caps = fContextInfo->priv().caps();
17
18 GrColorType grCT = SkColorTypeToGrColorType(this->colorType());
19 SkASSERT(fSampleCnt && caps->isFormatAsColorTypeRenderable(grCT, fBackendFormat, fSampleCnt));
20
21 SkASSERT(caps->areColorTypeAndFormatCompatible(grCT, fBackendFormat));
22 }
23 #endif
24
25
operator ==(const SkSurfaceCharacterization & other) const26 bool SkSurfaceCharacterization::operator==(const SkSurfaceCharacterization& other) const {
27 if (!this->isValid() || !other.isValid()) {
28 return false;
29 }
30
31 if (fContextInfo != other.fContextInfo) {
32 return false;
33 }
34
35 return fCacheMaxResourceBytes == other.fCacheMaxResourceBytes &&
36 fOrigin == other.fOrigin &&
37 fImageInfo == other.fImageInfo &&
38 fBackendFormat == other.fBackendFormat &&
39 fSampleCnt == other.fSampleCnt &&
40 fIsTextureable == other.fIsTextureable &&
41 fIsMipMapped == other.fIsMipMapped &&
42 fUsesGLFBO0 == other.fUsesGLFBO0 &&
43 fVulkanSecondaryCBCompatible == other.fVulkanSecondaryCBCompatible &&
44 fIsProtected == other.fIsProtected &&
45 fSurfaceProps == other.fSurfaceProps;
46 }
47
createResized(int width,int height) const48 SkSurfaceCharacterization SkSurfaceCharacterization::createResized(int width, int height) const {
49 const GrCaps* caps = fContextInfo->priv().caps();
50 if (!caps) {
51 return SkSurfaceCharacterization();
52 }
53
54 if (width <= 0 || height <= 0 || width > caps->maxRenderTargetSize() ||
55 height > caps->maxRenderTargetSize()) {
56 return SkSurfaceCharacterization();
57 }
58
59 return SkSurfaceCharacterization(fContextInfo, fCacheMaxResourceBytes,
60 fImageInfo.makeWH(width, height), fBackendFormat, fOrigin,
61 fSampleCnt, fIsTextureable, fIsMipMapped, fUsesGLFBO0,
62 fVulkanSecondaryCBCompatible, fIsProtected, fSurfaceProps);
63 }
64
isCompatible(const GrBackendTexture & backendTex) const65 bool SkSurfaceCharacterization::isCompatible(const GrBackendTexture& backendTex) const {
66 if (!this->isValid() || !backendTex.isValid()) {
67 return false;
68 }
69
70 if (fBackendFormat != backendTex.getBackendFormat()) {
71 return false;
72 }
73
74 if (this->usesGLFBO0()) {
75 // It is a backend texture so can't be wrapping FBO0
76 return false;
77 }
78
79 if (this->vulkanSecondaryCBCompatible()) {
80 return false;
81 }
82
83 if (this->isMipMapped() && !backendTex.hasMipMaps()) {
84 // backend texture is allowed to have mipmaps even if the characterization doesn't require
85 // them.
86 return false;
87 }
88
89 if (this->width() != backendTex.width() || this->height() != backendTex.height()) {
90 return false;
91 }
92
93 if (this->isProtected() != GrProtected(backendTex.isProtected())) {
94 return false;
95 }
96
97 return true;
98 }
99
100
101 #endif
102