Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | #ifndef SkSurfaceCharacterization_DEFINED |
| 9 | #define SkSurfaceCharacterization_DEFINED |
| 10 | |
| 11 | #include "GrTypes.h" |
| 12 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 13 | #include "SkColorSpace.h" |
| 14 | #include "SkRefCnt.h" |
Robert Phillips | 61e5101 | 2017-11-30 11:22:14 -0500 | [diff] [blame] | 15 | #include "SkSurfaceProps.h" |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 16 | |
Robert Phillips | 61e5101 | 2017-11-30 11:22:14 -0500 | [diff] [blame] | 17 | class SkColorSpace; |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 18 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 19 | #if SK_SUPPORT_GPU |
| 20 | #include "GrContext.h" |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 21 | |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 22 | /** \class SkSurfaceCharacterization |
| 23 | A surface characterization contains all the information Ganesh requires to makes its internal |
| 24 | rendering decisions. When passed into a SkDeferredDisplayListRecorder it will copy the |
| 25 | data and pass it on to the SkDeferredDisplayList if/when it is created. Note that both of |
| 26 | those objects (the Recorder and the DisplayList) will take a ref on the |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 27 | GrContextThreadSafeProxy and SkColorSpace objects. |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 28 | */ |
Robert Phillips | 91749c8 | 2018-04-05 09:38:50 -0400 | [diff] [blame] | 29 | class SK_API SkSurfaceCharacterization { |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 30 | public: |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 31 | enum class Textureable : bool { kNo = false, kYes = true }; |
| 32 | enum class MipMapped : bool { kNo = false, kYes = true }; |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 33 | enum class UsesGLFBO0 : bool { kNo = false, kYes = true }; |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 34 | |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 35 | SkSurfaceCharacterization() |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 36 | : fCacheMaxResourceBytes(0) |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 37 | , fOrigin(kBottomLeft_GrSurfaceOrigin) |
Robert Phillips | 61e5101 | 2017-11-30 11:22:14 -0500 | [diff] [blame] | 38 | , fConfig(kUnknown_GrPixelConfig) |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 39 | , fFSAAType(GrFSAAType::kNone) |
| 40 | , fStencilCnt(0) |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 41 | , fIsTextureable(Textureable::kYes) |
| 42 | , fIsMipMapped(MipMapped::kYes) |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 43 | , fUsesGLFBO0(UsesGLFBO0::kNo) |
Robert Phillips | 61e5101 | 2017-11-30 11:22:14 -0500 | [diff] [blame] | 44 | , fSurfaceProps(0, kUnknown_SkPixelGeometry) { |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 45 | } |
| 46 | |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 47 | SkSurfaceCharacterization(SkSurfaceCharacterization&&) = default; |
| 48 | SkSurfaceCharacterization& operator=(SkSurfaceCharacterization&&) = default; |
| 49 | |
| 50 | SkSurfaceCharacterization(const SkSurfaceCharacterization&) = default; |
| 51 | SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default; |
Robert Phillips | c1267c6 | 2018-04-04 11:12:39 -0400 | [diff] [blame] | 52 | bool operator==(const SkSurfaceCharacterization& other) const; |
| 53 | bool operator!=(const SkSurfaceCharacterization& other) const { |
| 54 | return !(*this == other); |
| 55 | } |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 56 | |
Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 57 | SkSurfaceCharacterization createResized(int width, int height) const; |
Robert Phillips | 94458ee | 2018-03-06 13:41:51 -0500 | [diff] [blame] | 58 | |
Robert Phillips | 61e5101 | 2017-11-30 11:22:14 -0500 | [diff] [blame] | 59 | GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); } |
Robert Phillips | fde6fa0 | 2018-03-02 08:53:14 -0500 | [diff] [blame] | 60 | sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; } |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 61 | size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; } |
| 62 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 63 | bool isValid() const { return kUnknown_SkColorType != fImageInfo.colorType(); } |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 64 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 65 | const SkImageInfo& imageInfo() const { return fImageInfo; } |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 66 | GrSurfaceOrigin origin() const { return fOrigin; } |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 67 | int width() const { return fImageInfo.width(); } |
| 68 | int height() const { return fImageInfo.height(); } |
| 69 | SkColorType colorType() const { return fImageInfo.colorType(); } |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 70 | GrFSAAType fsaaType() const { return fFSAAType; } |
| 71 | int stencilCount() const { return fStencilCnt; } |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 72 | bool isTextureable() const { return Textureable::kYes == fIsTextureable; } |
| 73 | bool isMipMapped() const { return MipMapped::kYes == fIsMipMapped; } |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 74 | bool usesGLFBO0() const { return UsesGLFBO0::kYes == fUsesGLFBO0; } |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 75 | SkColorSpace* colorSpace() const { return fImageInfo.colorSpace(); } |
| 76 | sk_sp<SkColorSpace> refColorSpace() const { return fImageInfo.refColorSpace(); } |
Robert Phillips | 61e5101 | 2017-11-30 11:22:14 -0500 | [diff] [blame] | 77 | const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; } |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 78 | |
| 79 | private: |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 80 | friend class SkSurface_Gpu; // for 'set' & 'config' |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 81 | friend class GrContextThreadSafeProxy; // for private ctor |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 82 | friend class SkDeferredDisplayListRecorder; // for 'config' |
| 83 | friend class SkSurface; // for 'config' |
| 84 | |
| 85 | GrPixelConfig config() const { return fConfig; } |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 86 | |
| 87 | SkSurfaceCharacterization(sk_sp<GrContextThreadSafeProxy> contextInfo, |
| 88 | size_t cacheMaxResourceBytes, |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 89 | const SkImageInfo& ii, |
| 90 | GrSurfaceOrigin origin, |
| 91 | GrPixelConfig config, |
| 92 | GrFSAAType FSAAType, int stencilCnt, |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 93 | Textureable isTextureable, MipMapped isMipMapped, |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 94 | UsesGLFBO0 usesGLFBO0, |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 95 | const SkSurfaceProps& surfaceProps) |
| 96 | : fContextInfo(std::move(contextInfo)) |
| 97 | , fCacheMaxResourceBytes(cacheMaxResourceBytes) |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 98 | , fImageInfo(ii) |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 99 | , fOrigin(origin) |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 100 | , fConfig(config) |
| 101 | , fFSAAType(FSAAType) |
| 102 | , fStencilCnt(stencilCnt) |
| 103 | , fIsTextureable(isTextureable) |
| 104 | , fIsMipMapped(isMipMapped) |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 105 | , fUsesGLFBO0(usesGLFBO0) |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 106 | , fSurfaceProps(surfaceProps) { |
| 107 | } |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 108 | |
Robert Phillips | 61e5101 | 2017-11-30 11:22:14 -0500 | [diff] [blame] | 109 | void set(sk_sp<GrContextThreadSafeProxy> contextInfo, |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 110 | size_t cacheMaxResourceBytes, |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 111 | const SkImageInfo& ii, |
Robert Phillips | 61e5101 | 2017-11-30 11:22:14 -0500 | [diff] [blame] | 112 | GrSurfaceOrigin origin, |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 113 | GrPixelConfig config, |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 114 | GrFSAAType fsaaType, |
| 115 | int stencilCnt, |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 116 | Textureable isTextureable, |
| 117 | MipMapped isMipMapped, |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 118 | UsesGLFBO0 usesGLFBO0, |
Robert Phillips | 61e5101 | 2017-11-30 11:22:14 -0500 | [diff] [blame] | 119 | const SkSurfaceProps& surfaceProps) { |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 120 | SkASSERT(MipMapped::kNo == isMipMapped || Textureable::kYes == isTextureable); |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 121 | SkASSERT(Textureable::kNo == isTextureable || UsesGLFBO0::kNo == usesGLFBO0); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 122 | |
Robert Phillips | 61e5101 | 2017-11-30 11:22:14 -0500 | [diff] [blame] | 123 | fContextInfo = contextInfo; |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 124 | fCacheMaxResourceBytes = cacheMaxResourceBytes; |
| 125 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 126 | fImageInfo = ii; |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 127 | fOrigin = origin; |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 128 | fConfig = config; |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 129 | fFSAAType = fsaaType; |
| 130 | fStencilCnt = stencilCnt; |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 131 | fIsTextureable = isTextureable; |
| 132 | fIsMipMapped = isMipMapped; |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 133 | fUsesGLFBO0 = usesGLFBO0; |
Robert Phillips | 61e5101 | 2017-11-30 11:22:14 -0500 | [diff] [blame] | 134 | fSurfaceProps = surfaceProps; |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 135 | } |
| 136 | |
Robert Phillips | 61e5101 | 2017-11-30 11:22:14 -0500 | [diff] [blame] | 137 | sk_sp<GrContextThreadSafeProxy> fContextInfo; |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 138 | size_t fCacheMaxResourceBytes; |
| 139 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 140 | SkImageInfo fImageInfo; |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 141 | GrSurfaceOrigin fOrigin; |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 142 | GrPixelConfig fConfig; |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 143 | GrFSAAType fFSAAType; |
| 144 | int fStencilCnt; |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 145 | Textureable fIsTextureable; |
| 146 | MipMapped fIsMipMapped; |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 147 | UsesGLFBO0 fUsesGLFBO0; |
Robert Phillips | 61e5101 | 2017-11-30 11:22:14 -0500 | [diff] [blame] | 148 | SkSurfaceProps fSurfaceProps; |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 149 | }; |
| 150 | |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 151 | #else// !SK_SUPPORT_GPU |
| 152 | |
Robert Phillips | 91749c8 | 2018-04-05 09:38:50 -0400 | [diff] [blame] | 153 | class SK_API SkSurfaceCharacterization { |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 154 | public: |
Robert Phillips | 94458ee | 2018-03-06 13:41:51 -0500 | [diff] [blame] | 155 | SkSurfaceCharacterization() : fSurfaceProps(0, kUnknown_SkPixelGeometry) { } |
| 156 | |
| 157 | SkSurfaceCharacterization createResized(int width, int height) const { |
| 158 | return *this; |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 159 | } |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 160 | |
Robert Phillips | c1267c6 | 2018-04-04 11:12:39 -0400 | [diff] [blame] | 161 | bool operator==(const SkSurfaceCharacterization& other) const { return false; } |
| 162 | bool operator!=(const SkSurfaceCharacterization& other) const { |
| 163 | return !(*this == other); |
| 164 | } |
| 165 | |
Robert Phillips | 94458ee | 2018-03-06 13:41:51 -0500 | [diff] [blame] | 166 | size_t cacheMaxResourceBytes() const { return 0; } |
| 167 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 168 | bool isValid() const { return false; } |
| 169 | |
Robert Phillips | 94458ee | 2018-03-06 13:41:51 -0500 | [diff] [blame] | 170 | int width() const { return 0; } |
| 171 | int height() const { return 0; } |
| 172 | int stencilCount() const { return 0; } |
| 173 | bool isTextureable() const { return false; } |
| 174 | bool isMipMapped() const { return false; } |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 175 | bool usesGLFBO0() const { return false; } |
Robert Phillips | 94458ee | 2018-03-06 13:41:51 -0500 | [diff] [blame] | 176 | SkColorSpace* colorSpace() const { return nullptr; } |
| 177 | sk_sp<SkColorSpace> refColorSpace() const { return nullptr; } |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 178 | const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; } |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 179 | |
| 180 | private: |
Robert Phillips | 94458ee | 2018-03-06 13:41:51 -0500 | [diff] [blame] | 181 | SkSurfaceProps fSurfaceProps; |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | #endif |
| 185 | |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 186 | #endif |