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