reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 8 | #ifndef GrGpu_DEFINED |
| 9 | #define GrGpu_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkPath.h" |
| 12 | #include "include/core/SkSurface.h" |
| 13 | #include "include/gpu/GrTypes.h" |
| 14 | #include "include/private/SkTArray.h" |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 15 | #include "src/core/SkSpan.h" |
Stephen White | f3d5d44 | 2020-04-08 10:35:58 -0400 | [diff] [blame] | 16 | #include "src/core/SkTInternalLList.h" |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrAttachment.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrCaps.h" |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrOpsRenderPass.h" |
Brian Salomon | 05487ab | 2020-12-23 20:32:22 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrPixmap.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrSamplePatternDictionary.h" |
Brian Salomon | 3ec1f54 | 2019-06-17 17:54:57 +0000 | [diff] [blame] | 22 | #include "src/gpu/GrSwizzle.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/GrTextureProducer.h" |
| 24 | #include "src/gpu/GrXferProcessor.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 25 | |
Brian Salomon | 05487ab | 2020-12-23 20:32:22 -0500 | [diff] [blame] | 26 | class GrAttachment; |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 27 | class GrBackendRenderTarget; |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 28 | class GrBackendSemaphore; |
Brian Salomon | 05487ab | 2020-12-23 20:32:22 -0500 | [diff] [blame] | 29 | struct GrContextOptions; |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 30 | class GrDirectContext; |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 31 | class GrGpuBuffer; |
reed | f9ad558 | 2015-06-25 21:29:25 -0700 | [diff] [blame] | 32 | class GrGLContext; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 33 | class GrPath; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 34 | class GrPathRenderer; |
| 35 | class GrPathRendererChain; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 36 | class GrPathRendering; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 37 | class GrPipeline; |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 38 | class GrPrimitiveProcessor; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 39 | class GrRenderTarget; |
Jim Van Verth | 7e829b2 | 2020-07-30 17:04:35 -0400 | [diff] [blame] | 40 | class GrRingBuffer; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 41 | class GrSemaphore; |
Greg Daniel | a58db7f | 2020-07-15 09:17:59 -0400 | [diff] [blame] | 42 | class GrStagingBufferManager; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 43 | class GrStencilSettings; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 44 | class GrSurface; |
| 45 | class GrTexture; |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 46 | class SkJSONWriter; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | |
Brian Osman | cbdc261 | 2020-11-23 15:30:48 -0500 | [diff] [blame] | 48 | namespace SkSL { |
| 49 | class Compiler; |
| 50 | } |
| 51 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 52 | class GrGpu : public SkRefCnt { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 53 | public: |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 54 | GrGpu(GrDirectContext* direct); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 55 | ~GrGpu() override; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 56 | |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 57 | GrDirectContext* getContext() { return fContext; } |
| 58 | const GrDirectContext* getContext() const { return fContext; } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * Gets the capabilities of the draw target. |
| 62 | */ |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 63 | const GrCaps* caps() const { return fCaps.get(); } |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 64 | sk_sp<const GrCaps> refCaps() const { return fCaps; } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 65 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 66 | GrPathRendering* pathRendering() { return fPathRendering.get(); } |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 67 | |
Greg Daniel | a58db7f | 2020-07-15 09:17:59 -0400 | [diff] [blame] | 68 | virtual GrStagingBufferManager* stagingBufferManager() { return nullptr; } |
| 69 | |
Jim Van Verth | 7e829b2 | 2020-07-30 17:04:35 -0400 | [diff] [blame] | 70 | virtual GrRingBuffer* uniformsRingBuffer() { return nullptr; } |
| 71 | |
Brian Osman | cbdc261 | 2020-11-23 15:30:48 -0500 | [diff] [blame] | 72 | SkSL::Compiler* shaderCompiler() const { return fCompiler.get(); } |
| 73 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 74 | enum class DisconnectType { |
| 75 | // No cleanup should be attempted, immediately cease making backend API calls |
| 76 | kAbandon, |
| 77 | // Free allocated resources (not known by GrResourceCache) before returning and |
| 78 | // ensure no backend backend 3D API calls will be made after disconnect() returns. |
| 79 | kCleanup, |
| 80 | }; |
| 81 | |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 82 | // Called by context when the underlying backend context is already or will be destroyed |
| 83 | // before GrDirectContext. |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 84 | virtual void disconnect(DisconnectType); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 85 | |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 86 | // Called by GrDirectContext::isContextLost. Returns true if the backend Gpu object has gotten |
| 87 | // into an unrecoverable, lost state. |
Greg Daniel | 6e35a00 | 2020-04-01 13:29:59 -0400 | [diff] [blame] | 88 | virtual bool isDeviceLost() const { return false; } |
| 89 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 90 | /** |
| 91 | * The GrGpu object normally assumes that no outsider is setting state |
| 92 | * within the underlying 3D API's context/device/whatever. This call informs |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 93 | * the GrGpu that the state was modified and it shouldn't make assumptions |
| 94 | * about the state. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 95 | */ |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 96 | void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |= state; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 97 | |
| 98 | /** |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 99 | * Creates a texture object. If renderable is kYes then the returned texture can |
bsalomon | 6d467ec | 2014-11-18 07:36:19 -0800 | [diff] [blame] | 100 | * be used as a render target by calling GrTexture::asRenderTarget(). Not all |
| 101 | * pixel configs can be used as render targets. Support for configs as textures |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 102 | * or render targets can be checked using GrCaps. |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 103 | * |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 104 | * @param dimensions dimensions of the texture to be created. |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 105 | * @param format the format for the texture (not currently used). |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 106 | * @param renderable should the resulting texture be renderable |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 107 | * @param renderTargetSampleCnt The number of samples to use for rendering if renderable is |
| 108 | * kYes. If renderable is kNo then this must be 1. |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 109 | * @param budgeted does this texture count against the resource cache budget? |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 110 | * @param isProtected should the texture be created as protected. |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 111 | * @param texels array of mipmap levels containing texel data to load. |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 112 | * If level i has pixels then it is assumed that its dimensions are |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 113 | * max(1, floor(dimensions.fWidth / 2)) by |
| 114 | * max(1, floor(dimensions.fHeight / 2)). |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 115 | * If texels[i].fPixels == nullptr for all i <= mipLevelCount or |
| 116 | * mipLevelCount is 0 then the texture's contents are uninitialized. |
| 117 | * If a level has non-null pixels, its row bytes must be a multiple of the |
| 118 | * config's bytes-per-pixel. The row bytes must be tight to the |
| 119 | * level width if !caps->writePixelsRowBytesSupport(). |
| 120 | * If mipLevelCount > 1 and texels[i].fPixels != nullptr for any i > 0 |
| 121 | * then all levels must have non-null pixels. All levels must have |
| 122 | * non-null pixels if GrCaps::createTextureMustSpecifyAllLevels() is true. |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 123 | * @param textureColorType The color type interpretation of the texture for the purpose of |
| 124 | * of uploading texel data. |
| 125 | * @param srcColorType The color type of data in texels[]. |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 126 | * @param texelLevelCount the number of levels in 'texels'. May be 0, 1, or |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 127 | * floor(max((log2(dimensions.fWidth), log2(dimensions.fHeight)))). It |
| 128 | * must be the latter if GrCaps::createTextureMustSpecifyAllLevels() is |
| 129 | * true. |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 130 | * @return The texture object if successful, otherwise nullptr. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 131 | */ |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 132 | sk_sp<GrTexture> createTexture(SkISize dimensions, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 133 | const GrBackendFormat& format, |
| 134 | GrRenderable renderable, |
| 135 | int renderTargetSampleCnt, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 136 | SkBudgeted budgeted, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 137 | GrProtected isProtected, |
| 138 | GrColorType textureColorType, |
| 139 | GrColorType srcColorType, |
| 140 | const GrMipLevel texels[], |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 141 | int texelLevelCount); |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 142 | |
Brian Salomon | c7dced5 | 2019-07-18 15:02:01 +0000 | [diff] [blame] | 143 | /** |
| 144 | * Simplified createTexture() interface for when there is no initial texel data to upload. |
| 145 | */ |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 146 | sk_sp<GrTexture> createTexture(SkISize dimensions, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 147 | const GrBackendFormat& format, |
| 148 | GrRenderable renderable, |
| 149 | int renderTargetSampleCnt, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 150 | GrMipmapped mipMapped, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 151 | SkBudgeted budgeted, |
| 152 | GrProtected isProtected); |
Brian Salomon | c7dced5 | 2019-07-18 15:02:01 +0000 | [diff] [blame] | 153 | |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 154 | sk_sp<GrTexture> createCompressedTexture(SkISize dimensions, |
| 155 | const GrBackendFormat& format, |
| 156 | SkBudgeted budgeted, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 157 | GrMipmapped mipMapped, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 158 | GrProtected isProtected, |
Robert Phillips | e4720c6 | 2020-01-14 14:33:24 -0500 | [diff] [blame] | 159 | const void* data, size_t dataSize); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 160 | |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 161 | /** |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 162 | * Implements GrResourceProvider::wrapBackendTexture |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 163 | */ |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 164 | sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture&, |
| 165 | GrWrapOwnership, |
| 166 | GrWrapCacheable, |
| 167 | GrIOType); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 168 | |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 169 | sk_sp<GrTexture> wrapCompressedBackendTexture(const GrBackendTexture&, |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 170 | GrWrapOwnership, |
| 171 | GrWrapCacheable); |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 172 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 173 | /** |
| 174 | * Implements GrResourceProvider::wrapRenderableBackendTexture |
| 175 | */ |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 176 | sk_sp<GrTexture> wrapRenderableBackendTexture(const GrBackendTexture&, |
| 177 | int sampleCnt, |
| 178 | GrWrapOwnership, |
| 179 | GrWrapCacheable); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 180 | |
| 181 | /** |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 182 | * Implements GrResourceProvider::wrapBackendRenderTarget |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 183 | */ |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 184 | sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 185 | |
| 186 | /** |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 187 | * Implements GrResourceProvider::wrapVulkanSecondaryCBAsRenderTarget |
| 188 | */ |
| 189 | sk_sp<GrRenderTarget> wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&, |
| 190 | const GrVkDrawableInfo&); |
| 191 | |
| 192 | /** |
csmartdalton | 485a120 | 2016-07-13 10:16:32 -0700 | [diff] [blame] | 193 | * Creates a buffer in GPU memory. For a client-side buffer use GrBuffer::CreateCPUBacked. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 194 | * |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 195 | * @param size size of buffer to create. |
| 196 | * @param intendedType hint to the graphics subsystem about what the buffer will be used for. |
| 197 | * @param accessPattern hint to the graphics subsystem about how the data will be accessed. |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 198 | * @param data optional data with which to initialize the buffer. |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 199 | * |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 200 | * @return the buffer if successful, otherwise nullptr. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 201 | */ |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 202 | sk_sp<GrGpuBuffer> createBuffer(size_t size, GrGpuBufferType intendedType, |
| 203 | GrAccessPattern accessPattern, const void* data = nullptr); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 204 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 205 | /** |
Greg Daniel | 242536f | 2020-02-13 14:12:46 -0500 | [diff] [blame] | 206 | * Resolves MSAA. The resolveRect must already be in the native destination space. |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 207 | */ |
Jim Van Verth | bb61fe3 | 2020-07-07 16:39:04 -0400 | [diff] [blame] | 208 | void resolveRenderTarget(GrRenderTarget*, const SkIRect& resolveRect); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 209 | |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 210 | /** |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 211 | * Uses the base of the texture to recompute the contents of the other levels. |
| 212 | */ |
| 213 | bool regenerateMipMapLevels(GrTexture*); |
| 214 | |
| 215 | /** |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 216 | * If the backend API has stateful texture bindings, this resets them back to defaults. |
| 217 | */ |
| 218 | void resetTextureBindings(); |
| 219 | |
| 220 | /** |
Brian Salomon | 9b009bb | 2018-02-14 13:53:55 -0500 | [diff] [blame] | 221 | * Reads a rectangle of pixels from a render target. No sRGB/linear conversions are performed. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 222 | * |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 223 | * @param surface The surface to read from |
| 224 | * @param left left edge of the rectangle to read (inclusive) |
| 225 | * @param top top edge of the rectangle to read (inclusive) |
| 226 | * @param width width of rectangle to read in pixels. |
| 227 | * @param height height of rectangle to read in pixels. |
| 228 | * @param surfaceColorType the color type for this use of the surface. |
| 229 | * @param dstColorType the color type of the destination buffer. |
| 230 | * @param buffer memory to read the rectangle into. |
| 231 | * @param rowBytes the number of bytes between consecutive rows. Must be a multiple of |
| 232 | * dstColorType's bytes-per-pixel. Must be tight to width if |
| 233 | * !caps->readPixelsRowBytesSupport(). |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 234 | * |
| 235 | * @return true if the read succeeded, false if not. The read can fail |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 236 | * because of the surface doesn't support reading, the color type |
| 237 | * is not allowed for the format of the surface or if the rectangle |
| 238 | * read is not contained in the surface. |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 239 | */ |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 240 | bool readPixels(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 241 | GrColorType surfaceColorType, GrColorType dstColorType, void* buffer, |
| 242 | size_t rowBytes); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 243 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 244 | /** |
Brian Salomon | 9b009bb | 2018-02-14 13:53:55 -0500 | [diff] [blame] | 245 | * Updates the pixels in a rectangle of a surface. No sRGB/linear conversions are performed. |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 246 | * |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 247 | * @param surface The surface to write to. |
| 248 | * @param left left edge of the rectangle to write (inclusive) |
| 249 | * @param top top edge of the rectangle to write (inclusive) |
| 250 | * @param width width of rectangle to write in pixels. |
| 251 | * @param height height of rectangle to write in pixels. |
| 252 | * @param surfaceColorType the color type for this use of the surface. |
| 253 | * @param srcColorType the color type of the source buffer. |
| 254 | * @param texels array of mipmap levels containing texture data. Row bytes must be a |
| 255 | * multiple of srcColorType's bytes-per-pixel. Must be tight to level |
| 256 | * width if !caps->writePixelsRowBytesSupport(). |
| 257 | * @param mipLevelCount number of levels in 'texels' |
| 258 | * @param prepForTexSampling After doing write pixels should the surface be prepared for texture |
| 259 | * sampling. This is currently only used by Vulkan for inline uploads |
| 260 | * to set that layout back to sampled after doing the upload. Inline |
| 261 | * uploads currently can happen between draws in a single op so it is |
| 262 | * not trivial to break up the GrOpsTask into two tasks when we see |
| 263 | * an inline upload. However, once we are able to support doing that |
| 264 | * we can remove this parameter. |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 265 | * |
| 266 | * @return true if the write succeeded, false if not. The read can fail |
| 267 | * because of the surface doesn't support writing (e.g. read only), |
| 268 | * the color type is not allowed for the format of the surface or |
| 269 | * if the rectangle written is not contained in the surface. |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 270 | */ |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 271 | bool writePixels(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 272 | GrColorType surfaceColorType, GrColorType srcColorType, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 273 | const GrMipLevel texels[], int mipLevelCount, bool prepForTexSampling = false); |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 274 | |
| 275 | /** |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 276 | * Helper for the case of a single level. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 277 | */ |
| 278 | bool writePixels(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 279 | GrColorType surfaceColorType, GrColorType srcColorType, const void* buffer, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 280 | size_t rowBytes, bool prepForTexSampling = false) { |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 281 | GrMipLevel mipLevel = {buffer, rowBytes}; |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 282 | return this->writePixels(surface, left, top, width, height, surfaceColorType, srcColorType, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 283 | &mipLevel, 1, prepForTexSampling); |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | /** |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 287 | * Updates the pixels in a rectangle of a texture using a buffer. If the texture is MIP mapped, |
| 288 | * the base level is written to. |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 289 | * |
| 290 | * @param texture The texture to write to. |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 291 | * @param left left edge of the rectangle to write (inclusive) |
| 292 | * @param top top edge of the rectangle to write (inclusive) |
| 293 | * @param width width of rectangle to write in pixels. |
| 294 | * @param height height of rectangle to write in pixels. |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 295 | * @param textureColorType the color type for this use of the surface. |
Brian Salomon | c320b15 | 2018-02-20 14:05:36 -0500 | [diff] [blame] | 296 | * @param bufferColorType the color type of the transfer buffer's pixel data |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 297 | * @param transferBuffer GrBuffer to read pixels from (type must be "kXferCpuToGpu") |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 298 | * @param offset offset from the start of the buffer |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 299 | * @param rowBytes number of bytes between consecutive rows in the buffer. Must be a |
| 300 | * multiple of bufferColorType's bytes-per-pixel. Must be tight to width |
| 301 | * if !caps->writePixelsRowBytesSupport(). |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 302 | */ |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 303 | bool transferPixelsTo(GrTexture* texture, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 304 | GrColorType textureColorType, GrColorType bufferColorType, |
| 305 | GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 306 | |
| 307 | /** |
| 308 | * Reads the pixels from a rectangle of a surface into a buffer. Use |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 309 | * GrCaps::SupportedRead::fOffsetAlignmentForTransferBuffer to determine the requirements for |
| 310 | * the buffer offset alignment. If the surface is a MIP mapped texture, the base level is read. |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 311 | * |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 312 | * If successful the row bytes in the buffer is always: |
| 313 | * GrColorTypeBytesPerPixel(bufferColorType) * width |
| 314 | * |
| 315 | * Asserts that the caller has passed a properly aligned offset and that the buffer is |
| 316 | * large enough to hold the result |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 317 | * |
| 318 | * @param surface The surface to read from. |
| 319 | * @param left left edge of the rectangle to read (inclusive) |
| 320 | * @param top top edge of the rectangle to read (inclusive) |
| 321 | * @param width width of rectangle to read in pixels. |
| 322 | * @param height height of rectangle to read in pixels. |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 323 | * @param surfaceColorType the color type for this use of the surface. |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 324 | * @param bufferColorType the color type of the transfer buffer's pixel data |
| 325 | * @param transferBuffer GrBuffer to write pixels to (type must be "kXferGpuToCpu") |
| 326 | * @param offset offset from the start of the buffer |
| 327 | */ |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 328 | bool transferPixelsFrom(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 329 | GrColorType surfaceColorType, GrColorType bufferColorType, |
| 330 | GrGpuBuffer* transferBuffer, size_t offset); |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 331 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 332 | // Called to perform a surface to surface copy. Fallbacks to issuing a draw from the src to dst |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 333 | // take place at higher levels and this function implement faster copy paths. The rect |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 334 | // and point are pre-clipped. The src rect and implied dst rect are guaranteed to be within the |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 335 | // src/dst bounds and non-empty. They must also be in their exact device space coords, including |
| 336 | // already being transformed for origin if need be. If canDiscardOutsideDstRect is set to true |
| 337 | // then we don't need to preserve any data on the dst surface outside of the copy. |
| 338 | bool copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 339 | const SkIPoint& dstPoint); |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 340 | |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 341 | // Queries the per-pixel HW sample locations for the given render target, and then finds or |
| 342 | // assigns a key that uniquely identifies the sample pattern. The actual sample locations can be |
| 343 | // retrieved with retrieveSampleLocations(). |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 344 | int findOrAssignSamplePatternKey(GrRenderTarget*); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 345 | |
| 346 | // Retrieves the per-pixel HW sample locations for the given sample pattern key, and, as a |
| 347 | // by-product, the actual number of samples in use. (This may differ from the number of samples |
| 348 | // requested by the render target.) Sample locations are returned as 0..1 offsets relative to |
| 349 | // the top-left corner of the pixel. |
| 350 | const SkTArray<SkPoint>& retrieveSampleLocations(int samplePatternKey) const { |
| 351 | return fSamplePatternDictionary.retrieveSampleLocations(samplePatternKey); |
| 352 | } |
| 353 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 354 | // Returns a GrOpsRenderPass which GrOpsTasks send draw commands to instead of directly |
| 355 | // to the Gpu object. The 'bounds' rect is the content rect of the renderTarget. |
Robert Phillips | 96f2237 | 2020-05-20 12:31:18 -0400 | [diff] [blame] | 356 | // If a 'stencil' is provided it will be the one bound to 'renderTarget'. If one is not |
| 357 | // provided but 'renderTarget' has a stencil buffer then that is a signal that the |
| 358 | // render target's stencil buffer should be ignored. |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 359 | GrOpsRenderPass* getOpsRenderPass(GrRenderTarget* renderTarget, |
| 360 | GrAttachment* stencil, |
| 361 | GrSurfaceOrigin, |
| 362 | const SkIRect& bounds, |
| 363 | const GrOpsRenderPass::LoadAndStoreInfo&, |
| 364 | const GrOpsRenderPass::StencilLoadAndStoreInfo&, |
| 365 | const SkTArray<GrSurfaceProxy*, true>& sampledProxies, |
| 366 | GrXferBarrierFlags renderPassXferBarriers); |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 367 | |
Robert Phillips | 18e9484 | 2017-05-15 13:06:44 -0400 | [diff] [blame] | 368 | // Called by GrDrawingManager when flushing. |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 369 | // Provides a hook for post-flush actions (e.g. Vulkan command buffer submits). This will also |
| 370 | // insert any numSemaphore semaphores on the gpu and set the backendSemaphores to match the |
| 371 | // inserted semaphores. |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 372 | void executeFlushInfo(SkSpan<GrSurfaceProxy*>, |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 373 | SkSurface::BackendSurfaceAccess access, |
| 374 | const GrFlushInfo&, |
| 375 | const GrBackendSurfaceMutableState* newState); |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 376 | |
| 377 | bool submitToGpu(bool syncCpu); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 378 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 379 | virtual void submit(GrOpsRenderPass*) = 0; |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 380 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 381 | virtual GrFence SK_WARN_UNUSED_RESULT insertFence() = 0; |
Stephen White | b353c9b | 2020-04-16 14:14:13 -0400 | [diff] [blame] | 382 | virtual bool waitFence(GrFence) = 0; |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 383 | virtual void deleteFence(GrFence) const = 0; |
| 384 | |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 385 | virtual std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore( |
| 386 | bool isOwned = true) = 0; |
| 387 | virtual std::unique_ptr<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore, |
| 388 | GrResourceProvider::SemaphoreWrapType wrapType, GrWrapOwnership ownership) = 0; |
| 389 | virtual void insertSemaphore(GrSemaphore* semaphore) = 0; |
| 390 | virtual void waitSemaphore(GrSemaphore* semaphore) = 0; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 391 | |
Jim Van Verth | 1aaf41b | 2020-07-29 09:24:29 -0400 | [diff] [blame] | 392 | virtual void addFinishedProc(GrGpuFinishedProc finishedProc, |
| 393 | GrGpuFinishedContext finishedContext) = 0; |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 394 | virtual void checkFinishProcs() = 0; |
| 395 | |
Jim Van Verth | 1aaf41b | 2020-07-29 09:24:29 -0400 | [diff] [blame] | 396 | virtual void takeOwnershipOfBuffer(sk_sp<GrGpuBuffer>) {} |
Greg Daniel | a58db7f | 2020-07-15 09:17:59 -0400 | [diff] [blame] | 397 | |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 398 | /** |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 399 | * Checks if we detected an OOM from the underlying 3D API and if so returns true and resets |
| 400 | * the internal OOM state to false. Otherwise, returns false. |
| 401 | */ |
| 402 | bool checkAndResetOOMed(); |
| 403 | |
| 404 | /** |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 405 | * Put this texture in a safe and known state for use across multiple contexts. Depending on |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 406 | * the backend, this may return a GrSemaphore. If so, other contexts should wait on that |
| 407 | * semaphore before using this texture. |
| 408 | */ |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 409 | virtual std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) = 0; |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 410 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 411 | /////////////////////////////////////////////////////////////////////////// |
| 412 | // Debugging and Stats |
| 413 | |
| 414 | class Stats { |
| 415 | public: |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 416 | enum class ProgramCacheResult { |
| 417 | kHit, // the program was found in the cache |
| 418 | kMiss, // the program was not found in the cache (and was, thus, compiled) |
| 419 | kPartial, // a precompiled version was found in the persistent cache |
| 420 | |
| 421 | kLast = kPartial |
| 422 | }; |
| 423 | |
| 424 | static const int kNumProgramCacheResults = (int)ProgramCacheResult::kLast + 1; |
| 425 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 426 | #if GR_GPU_STATS |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 427 | Stats() = default; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 428 | |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 429 | void reset() { *this = {}; } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 430 | |
| 431 | int renderTargetBinds() const { return fRenderTargetBinds; } |
| 432 | void incRenderTargetBinds() { fRenderTargetBinds++; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 433 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 434 | int shaderCompilations() const { return fShaderCompilations; } |
| 435 | void incShaderCompilations() { fShaderCompilations++; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 436 | |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 437 | int textureCreates() const { return fTextureCreates; } |
| 438 | void incTextureCreates() { fTextureCreates++; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 439 | |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 440 | int textureUploads() const { return fTextureUploads; } |
| 441 | void incTextureUploads() { fTextureUploads++; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 442 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 443 | int transfersToTexture() const { return fTransfersToTexture; } |
| 444 | void incTransfersToTexture() { fTransfersToTexture++; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 445 | |
| 446 | int transfersFromSurface() const { return fTransfersFromSurface; } |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 447 | void incTransfersFromSurface() { fTransfersFromSurface++; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 448 | |
| 449 | int stencilAttachmentCreates() const { return fStencilAttachmentCreates; } |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 450 | void incStencilAttachmentCreates() { fStencilAttachmentCreates++; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 451 | |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 452 | int msaaAttachmentCreates() const { return fMSAAAttachmentCreates; } |
| 453 | void incMSAAAttachmentCreates() { fMSAAAttachmentCreates++; } |
| 454 | |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 455 | int numDraws() const { return fNumDraws; } |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 456 | void incNumDraws() { fNumDraws++; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 457 | |
| 458 | int numFailedDraws() const { return fNumFailedDraws; } |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 459 | void incNumFailedDraws() { ++fNumFailedDraws; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 460 | |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 461 | int numSubmitToGpus() const { return fNumSubmitToGpus; } |
| 462 | void incNumSubmitToGpus() { ++fNumSubmitToGpus; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 463 | |
| 464 | int numScratchTexturesReused() const { return fNumScratchTexturesReused; } |
| 465 | void incNumScratchTexturesReused() { ++fNumScratchTexturesReused; } |
| 466 | |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 467 | int numScratchMSAAAttachmentsReused() const { return fNumScratchMSAAAttachmentsReused; } |
| 468 | void incNumScratchMSAAAttachmentsReused() { ++fNumScratchMSAAAttachmentsReused; } |
| 469 | |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 470 | int numInlineCompilationFailures() const { return fNumInlineCompilationFailures; } |
| 471 | void incNumInlineCompilationFailures() { ++fNumInlineCompilationFailures; } |
| 472 | |
| 473 | int numInlineProgramCacheResult(ProgramCacheResult stat) const { |
| 474 | return fInlineProgramCacheStats[(int) stat]; |
| 475 | } |
| 476 | void incNumInlineProgramCacheResult(ProgramCacheResult stat) { |
| 477 | ++fInlineProgramCacheStats[(int) stat]; |
| 478 | } |
| 479 | |
| 480 | int numPreCompilationFailures() const { return fNumPreCompilationFailures; } |
| 481 | void incNumPreCompilationFailures() { ++fNumPreCompilationFailures; } |
| 482 | |
| 483 | int numPreProgramCacheResult(ProgramCacheResult stat) const { |
| 484 | return fPreProgramCacheStats[(int) stat]; |
| 485 | } |
| 486 | void incNumPreProgramCacheResult(ProgramCacheResult stat) { |
| 487 | ++fPreProgramCacheStats[(int) stat]; |
| 488 | } |
| 489 | |
| 490 | int numCompilationFailures() const { return fNumCompilationFailures; } |
| 491 | void incNumCompilationFailures() { ++fNumCompilationFailures; } |
| 492 | |
| 493 | int numPartialCompilationSuccesses() const { return fNumPartialCompilationSuccesses; } |
| 494 | void incNumPartialCompilationSuccesses() { ++fNumPartialCompilationSuccesses; } |
| 495 | |
| 496 | int numCompilationSuccesses() const { return fNumCompilationSuccesses; } |
| 497 | void incNumCompilationSuccesses() { ++fNumCompilationSuccesses; } |
| 498 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 499 | #if GR_TEST_UTILS |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 500 | void dump(SkString*); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 501 | void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 502 | #endif |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 503 | private: |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 504 | int fRenderTargetBinds = 0; |
| 505 | int fShaderCompilations = 0; |
| 506 | int fTextureCreates = 0; |
| 507 | int fTextureUploads = 0; |
| 508 | int fTransfersToTexture = 0; |
| 509 | int fTransfersFromSurface = 0; |
| 510 | int fStencilAttachmentCreates = 0; |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 511 | int fMSAAAttachmentCreates = 0; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 512 | int fNumDraws = 0; |
| 513 | int fNumFailedDraws = 0; |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 514 | int fNumSubmitToGpus = 0; |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 515 | int fNumScratchTexturesReused = 0; |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 516 | int fNumScratchMSAAAttachmentsReused = 0; |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 517 | |
| 518 | int fNumInlineCompilationFailures = 0; |
| 519 | int fInlineProgramCacheStats[kNumProgramCacheResults] = { 0 }; |
| 520 | |
| 521 | int fNumPreCompilationFailures = 0; |
| 522 | int fPreProgramCacheStats[kNumProgramCacheResults] = { 0 }; |
| 523 | |
| 524 | int fNumCompilationFailures = 0; |
| 525 | int fNumPartialCompilationSuccesses = 0; |
| 526 | int fNumCompilationSuccesses = 0; |
| 527 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 528 | #else |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 529 | |
| 530 | #if GR_TEST_UTILS |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 531 | void dump(SkString*) {} |
| 532 | void dumpKeyValuePairs(SkTArray<SkString>*, SkTArray<double>*) {} |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 533 | #endif |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 534 | void incRenderTargetBinds() {} |
| 535 | void incShaderCompilations() {} |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 536 | void incTextureCreates() {} |
| 537 | void incTextureUploads() {} |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 538 | void incTransfersToTexture() {} |
Greg Daniel | a28ea67 | 2020-09-25 11:12:56 -0400 | [diff] [blame] | 539 | void incTransfersFromSurface() {} |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 540 | void incStencilAttachmentCreates() {} |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 541 | void incMSAAAttachmentCreates() {} |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 542 | void incNumDraws() {} |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 543 | void incNumFailedDraws() {} |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 544 | void incNumSubmitToGpus() {} |
Greg Daniel | a28ea67 | 2020-09-25 11:12:56 -0400 | [diff] [blame] | 545 | void incNumScratchTexturesReused() {} |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 546 | void incNumScratchMSAAAttachmentsReused() {} |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 547 | void incNumInlineCompilationFailures() {} |
| 548 | void incNumInlineProgramCacheResult(ProgramCacheResult stat) {} |
| 549 | void incNumPreCompilationFailures() {} |
| 550 | void incNumPreProgramCacheResult(ProgramCacheResult stat) {} |
| 551 | void incNumCompilationFailures() {} |
| 552 | void incNumPartialCompilationSuccesses() {} |
| 553 | void incNumCompilationSuccesses() {} |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 554 | #endif |
| 555 | }; |
| 556 | |
| 557 | Stats* stats() { return &fStats; } |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 558 | void dumpJSON(SkJSONWriter*) const; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 559 | |
Robert Phillips | 42716d4 | 2019-12-16 12:19:54 -0500 | [diff] [blame] | 560 | /** Used to initialize a backend texture with either a constant color, pixmaps or |
| 561 | * compressed data. |
| 562 | */ |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 563 | class BackendTextureData { |
| 564 | public: |
Robert Phillips | 42716d4 | 2019-12-16 12:19:54 -0500 | [diff] [blame] | 565 | enum class Type { kColor, kPixmaps, kCompressed }; |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 566 | BackendTextureData() = default; |
| 567 | BackendTextureData(const SkColor4f& color) : fType(Type::kColor), fColor(color) {} |
Brian Salomon | 05487ab | 2020-12-23 20:32:22 -0500 | [diff] [blame] | 568 | BackendTextureData(const GrPixmap pixmaps[]) : fType(Type::kPixmaps), fPixmaps(pixmaps) { |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 569 | SkASSERT(pixmaps); |
| 570 | } |
Robert Phillips | 42716d4 | 2019-12-16 12:19:54 -0500 | [diff] [blame] | 571 | BackendTextureData(const void* data, size_t size) : fType(Type::kCompressed) { |
| 572 | SkASSERT(data); |
| 573 | fCompressed.fData = data; |
| 574 | fCompressed.fSize = size; |
| 575 | } |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 576 | |
| 577 | Type type() const { return fType; } |
| 578 | SkColor4f color() const { |
| 579 | SkASSERT(this->type() == Type::kColor); |
| 580 | return fColor; |
| 581 | } |
| 582 | |
Brian Salomon | 05487ab | 2020-12-23 20:32:22 -0500 | [diff] [blame] | 583 | const GrPixmap& pixmap(int i) const { |
Robert Phillips | 42716d4 | 2019-12-16 12:19:54 -0500 | [diff] [blame] | 584 | SkASSERT(this->type() == Type::kPixmaps); |
| 585 | return fPixmaps[i]; |
| 586 | } |
Brian Salomon | 05487ab | 2020-12-23 20:32:22 -0500 | [diff] [blame] | 587 | const GrPixmap* pixmaps() const { |
Robert Phillips | 42716d4 | 2019-12-16 12:19:54 -0500 | [diff] [blame] | 588 | SkASSERT(this->type() == Type::kPixmaps); |
| 589 | return fPixmaps; |
| 590 | } |
| 591 | |
| 592 | const void* compressedData() const { |
| 593 | SkASSERT(this->type() == Type::kCompressed); |
| 594 | return fCompressed.fData; |
| 595 | } |
| 596 | size_t compressedSize() const { |
| 597 | SkASSERT(this->type() == Type::kCompressed); |
| 598 | return fCompressed.fSize; |
| 599 | } |
| 600 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 601 | private: |
| 602 | Type fType = Type::kColor; |
| 603 | union { |
| 604 | SkColor4f fColor = {0, 0, 0, 0}; |
Brian Salomon | 05487ab | 2020-12-23 20:32:22 -0500 | [diff] [blame] | 605 | const GrPixmap* fPixmaps; |
Robert Phillips | 42716d4 | 2019-12-16 12:19:54 -0500 | [diff] [blame] | 606 | struct { |
| 607 | const void* fData; |
| 608 | size_t fSize; |
| 609 | } fCompressed; |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 610 | }; |
| 611 | }; |
| 612 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 613 | /** |
| 614 | * Creates a texture directly in the backend API without wrapping it in a GrTexture. |
| 615 | * Must be matched with a call to deleteBackendTexture(). |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 616 | * |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 617 | * If data is null the texture is uninitialized. |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 618 | * |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 619 | * If data represents a color then all texture levels are cleared to that color. |
| 620 | * |
Robert Phillips | ba5c7ad | 2020-01-24 11:03:33 -0500 | [diff] [blame] | 621 | * If data represents pixmaps then it must have a either one pixmap or, if mipmapping |
| 622 | * is specified, a complete MIP hierarchy of pixmaps. Additionally, if provided, the mip |
| 623 | * levels must be sized correctly according to the MIP sizes implied by dimensions. They |
| 624 | * must all have the same color type and that color type must be compatible with the |
| 625 | * texture format. |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 626 | */ |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 627 | GrBackendTexture createBackendTexture(SkISize dimensions, |
| 628 | const GrBackendFormat&, |
| 629 | GrRenderable, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 630 | GrMipmapped, |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 631 | GrProtected); |
| 632 | |
| 633 | bool updateBackendTexture(const GrBackendTexture&, |
Greg Daniel | 2559778 | 2020-06-11 13:15:08 -0400 | [diff] [blame] | 634 | sk_sp<GrRefCntedCallback> finishedCallback, |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 635 | const BackendTextureData*); |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 636 | |
Robert Phillips | ba5c7ad | 2020-01-24 11:03:33 -0500 | [diff] [blame] | 637 | /** |
| 638 | * Same as the createBackendTexture case except compressed backend textures can |
| 639 | * never be renderable. |
| 640 | */ |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 641 | GrBackendTexture createCompressedBackendTexture(SkISize dimensions, |
| 642 | const GrBackendFormat&, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 643 | GrMipmapped, |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 644 | GrProtected); |
| 645 | |
| 646 | bool updateCompressedBackendTexture(const GrBackendTexture&, |
| 647 | sk_sp<GrRefCntedCallback> finishedCallback, |
| 648 | const BackendTextureData*); |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 649 | |
Greg Daniel | 1db8e79 | 2020-06-09 17:29:32 -0400 | [diff] [blame] | 650 | virtual bool setBackendTextureState(const GrBackendTexture&, |
| 651 | const GrBackendSurfaceMutableState&, |
Greg Daniel | 1d3c8c1 | 2020-09-23 14:23:36 -0400 | [diff] [blame] | 652 | GrBackendSurfaceMutableState* previousState, |
Greg Daniel | 1db8e79 | 2020-06-09 17:29:32 -0400 | [diff] [blame] | 653 | sk_sp<GrRefCntedCallback> finishedCallback) { |
| 654 | return false; |
| 655 | } |
| 656 | |
| 657 | virtual bool setBackendRenderTargetState(const GrBackendRenderTarget&, |
| 658 | const GrBackendSurfaceMutableState&, |
Greg Daniel | 1d3c8c1 | 2020-09-23 14:23:36 -0400 | [diff] [blame] | 659 | GrBackendSurfaceMutableState* previousState, |
Greg Daniel | 1db8e79 | 2020-06-09 17:29:32 -0400 | [diff] [blame] | 660 | sk_sp<GrRefCntedCallback> finishedCallback) { |
| 661 | return false; |
| 662 | } |
| 663 | |
Brian Salomon | e64b064 | 2018-03-07 11:47:54 -0500 | [diff] [blame] | 664 | /** |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 665 | * Frees a texture created by createBackendTexture(). If ownership of the backend |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 666 | * texture has been transferred to a context using adopt semantics this should not be called. |
Brian Salomon | e64b064 | 2018-03-07 11:47:54 -0500 | [diff] [blame] | 667 | */ |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 668 | virtual void deleteBackendTexture(const GrBackendTexture&) = 0; |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 669 | |
Robert Phillips | 979b223 | 2020-02-20 10:47:29 -0500 | [diff] [blame] | 670 | /** |
| 671 | * In this case we have a program descriptor and a program info but no render target. |
| 672 | */ |
| 673 | virtual bool compile(const GrProgramDesc&, const GrProgramInfo&) = 0; |
| 674 | |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 675 | virtual bool precompileShader(const SkData& key, const SkData& data) { return false; } |
| 676 | |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 677 | #if GR_TEST_UTILS |
| 678 | /** Check a handle represents an actual texture in the backend API that has not been freed. */ |
| 679 | virtual bool isTestingOnlyBackendTexture(const GrBackendTexture&) const = 0; |
| 680 | |
Brian Salomon | 72c7b98 | 2020-10-06 10:07:38 -0400 | [diff] [blame] | 681 | /** |
| 682 | * Creates a GrBackendRenderTarget that can be wrapped using |
| 683 | * SkSurface::MakeFromBackendRenderTarget. Ideally this is a non-textureable allocation to |
| 684 | * differentiate from testing with SkSurface::MakeFromBackendTexture. When sampleCnt > 1 this |
| 685 | * is used to test client wrapped allocations with MSAA where Skia does not allocate a separate |
| 686 | * buffer for resolving. If the color is non-null the backing store should be cleared to the |
| 687 | * passed in color. |
| 688 | */ |
Brian Salomon | f9b0042 | 2020-10-08 16:00:14 -0400 | [diff] [blame] | 689 | virtual GrBackendRenderTarget createTestingOnlyBackendRenderTarget( |
| 690 | SkISize dimensions, |
| 691 | GrColorType, |
| 692 | int sampleCount = 1, |
| 693 | GrProtected = GrProtected::kNo) = 0; |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 694 | |
Brian Salomon | 72c7b98 | 2020-10-06 10:07:38 -0400 | [diff] [blame] | 695 | /** |
| 696 | * Deletes a GrBackendRenderTarget allocated with the above. Synchronization to make this safe |
| 697 | * is up to the caller. |
| 698 | */ |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 699 | virtual void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) = 0; |
| 700 | |
| 701 | // This is only to be used in GL-specific tests. |
| 702 | virtual const GrGLContext* glContextForTesting() const { return nullptr; } |
| 703 | |
| 704 | // This is only to be used by testing code |
| 705 | virtual void resetShaderCacheForTesting() const {} |
| 706 | |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 707 | /** |
| 708 | * Flushes all work to the gpu and forces the GPU to wait until all the gpu work has completed. |
| 709 | * This is for testing purposes only. |
| 710 | */ |
| 711 | virtual void testingOnly_flushGpuAndSync() = 0; |
Jim Van Verth | 052761f | 2019-09-27 15:05:51 -0400 | [diff] [blame] | 712 | |
| 713 | /** |
| 714 | * Inserted as a pair around a block of code to do a GPU frame capture. |
| 715 | * Currently only works with the Metal backend. |
| 716 | */ |
| 717 | virtual void testingOnly_startCapture() {} |
| 718 | virtual void testingOnly_endCapture() {} |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 719 | #endif |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 720 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 721 | // width and height may be larger than rt (if underlying API allows it). |
| 722 | // Returns nullptr if compatible sb could not be created, otherwise the caller owns the ref on |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 723 | // the GrAttachment. |
| 724 | virtual sk_sp<GrAttachment> makeStencilAttachmentForRenderTarget(const GrRenderTarget*, |
| 725 | SkISize dimensions, |
| 726 | int numStencilSamples) = 0; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 727 | |
Greg Daniel | b8949bd | 2020-10-12 15:21:02 -0400 | [diff] [blame] | 728 | virtual GrBackendFormat getPreferredStencilFormat(const GrBackendFormat&) = 0; |
| 729 | |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 730 | // Creates an MSAA surface to be used as an MSAA attachment on a framebuffer. |
| 731 | virtual sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions, |
| 732 | const GrBackendFormat& format, |
| 733 | int numSamples, |
| 734 | GrProtected isProtected) = 0; |
| 735 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 736 | void handleDirtyContext() { |
| 737 | if (fResetBits) { |
| 738 | this->resetContext(); |
| 739 | } |
| 740 | } |
| 741 | |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 742 | virtual void storeVkPipelineCacheData() {} |
| 743 | |
Chris Dalton | e1196c5 | 2019-12-28 14:31:09 -0700 | [diff] [blame] | 744 | // http://skbug.com/9739 |
| 745 | virtual void insertManualFramebufferBarrier() { |
| 746 | SkASSERT(!this->caps()->requiresManualFBBarrierAfterTessellatedStencilDraw()); |
| 747 | SK_ABORT("Manual framebuffer barrier not supported."); |
| 748 | } |
| 749 | |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 750 | // Called before certain draws in order to guarantee coherent results from dst reads. |
| 751 | virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0; |
| 752 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 753 | protected: |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 754 | static bool MipMapsAreCorrect(SkISize dimensions, GrMipmapped, const BackendTextureData*); |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 755 | static bool CompressedDataIsCorrect(SkISize dimensions, SkImage::CompressionType, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 756 | GrMipmapped, const BackendTextureData*); |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 757 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 758 | // Handles cases where a surface will be updated without a call to flushRenderTarget. |
| 759 | void didWriteToSurface(GrSurface* surface, GrSurfaceOrigin origin, const SkIRect* bounds, |
| 760 | uint32_t mipLevels = 1) const; |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 761 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 762 | void setOOMed() { fOOMed = true; } |
| 763 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 764 | Stats fStats; |
| 765 | std::unique_ptr<GrPathRendering> fPathRendering; |
Brian Osman | cbdc261 | 2020-11-23 15:30:48 -0500 | [diff] [blame] | 766 | |
| 767 | // Subclass must call this to initialize caps & compiler in its constructor. |
| 768 | void initCapsAndCompiler(sk_sp<const GrCaps> caps); |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 769 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 770 | private: |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 771 | virtual GrBackendTexture onCreateBackendTexture(SkISize dimensions, |
| 772 | const GrBackendFormat&, |
| 773 | GrRenderable, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 774 | GrMipmapped, |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 775 | GrProtected) = 0; |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 776 | |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 777 | virtual GrBackendTexture onCreateCompressedBackendTexture( |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 778 | SkISize dimensions, const GrBackendFormat&, GrMipmapped, GrProtected) = 0; |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 779 | |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 780 | virtual bool onUpdateBackendTexture(const GrBackendTexture&, |
| 781 | sk_sp<GrRefCntedCallback> finishedCallback, |
| 782 | const BackendTextureData*) = 0; |
| 783 | |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 784 | virtual bool onUpdateCompressedBackendTexture(const GrBackendTexture&, |
| 785 | sk_sp<GrRefCntedCallback> finishedCallback, |
| 786 | const BackendTextureData*) = 0; |
| 787 | |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 788 | // called when the 3D context state is unknown. Subclass should emit any |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 789 | // assumed 3D context state and dirty any state cache. |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 790 | virtual void onResetContext(uint32_t resetBits) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 791 | |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 792 | // Implementation of resetTextureBindings. |
| 793 | virtual void onResetTextureBindings() {} |
| 794 | |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 795 | // Queries the effective number of samples in use by the hardware for the given render target, |
| 796 | // and queries the individual sample locations. |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 797 | virtual void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>*) = 0; |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 798 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 799 | // overridden by backend-specific derived class to create objects. |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 800 | // Texture size, renderablility, format support, sample count will have already been validated |
| 801 | // in base class before onCreateTexture is called. |
| 802 | // If the ith bit is set in levelClearMask then the ith MIP level should be cleared. |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 803 | virtual sk_sp<GrTexture> onCreateTexture(SkISize dimensions, |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 804 | const GrBackendFormat&, |
| 805 | GrRenderable, |
| 806 | int renderTargetSampleCnt, |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 807 | SkBudgeted, |
| 808 | GrProtected, |
| 809 | int mipLevelCoont, |
| 810 | uint32_t levelClearMask) = 0; |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame] | 811 | virtual sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions, |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 812 | const GrBackendFormat&, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 813 | SkBudgeted, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 814 | GrMipmapped, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 815 | GrProtected, |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame] | 816 | const void* data, size_t dataSize) = 0; |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 817 | virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, |
| 818 | GrWrapOwnership, |
| 819 | GrWrapCacheable, |
| 820 | GrIOType) = 0; |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 821 | |
| 822 | virtual sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&, |
| 823 | GrWrapOwnership, |
| 824 | GrWrapCacheable) = 0; |
| 825 | |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 826 | virtual sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, |
| 827 | int sampleCnt, |
| 828 | GrWrapOwnership, |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 829 | GrWrapCacheable) = 0; |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 830 | virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) = 0; |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 831 | virtual sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&, |
| 832 | const GrVkDrawableInfo&); |
| 833 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 834 | virtual sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType intendedType, |
| 835 | GrAccessPattern, const void* data) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 836 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 837 | // overridden by backend-specific derived class to perform the surface read |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 838 | virtual bool onReadPixels(GrSurface*, int left, int top, int width, int height, |
| 839 | GrColorType surfaceColorType, GrColorType dstColorType, void* buffer, |
| 840 | size_t rowBytes) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 841 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 842 | // overridden by backend-specific derived class to perform the surface write |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 843 | virtual bool onWritePixels(GrSurface*, int left, int top, int width, int height, |
| 844 | GrColorType surfaceColorType, GrColorType srcColorType, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 845 | const GrMipLevel texels[], int mipLevelCount, |
| 846 | bool prepForTexSampling) = 0; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 847 | |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 848 | // overridden by backend-specific derived class to perform the texture transfer |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 849 | virtual bool onTransferPixelsTo(GrTexture*, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 850 | GrColorType textiueColorType, GrColorType bufferColorType, |
| 851 | GrGpuBuffer* transferBuffer, size_t offset, |
| 852 | size_t rowBytes) = 0; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 853 | // overridden by backend-specific derived class to perform the surface transfer |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 854 | virtual bool onTransferPixelsFrom(GrSurface*, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 855 | GrColorType surfaceColorType, GrColorType bufferColorType, |
| 856 | GrGpuBuffer* transferBuffer, size_t offset) = 0; |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 857 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 858 | // overridden by backend-specific derived class to perform the resolve |
Jim Van Verth | bb61fe3 | 2020-07-07 16:39:04 -0400 | [diff] [blame] | 859 | virtual void onResolveRenderTarget(GrRenderTarget* target, const SkIRect& resolveRect) = 0; |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 860 | |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 861 | // overridden by backend specific derived class to perform mip map level regeneration. |
| 862 | virtual bool onRegenerateMipMapLevels(GrTexture*) = 0; |
| 863 | |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 864 | // overridden by backend specific derived class to perform the copy surface |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 865 | virtual bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 866 | const SkIPoint& dstPoint) = 0; |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 867 | |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 868 | virtual GrOpsRenderPass* onGetOpsRenderPass( |
| 869 | GrRenderTarget* renderTarget, |
| 870 | GrAttachment* stencil, |
| 871 | GrSurfaceOrigin, |
| 872 | const SkIRect& bounds, |
| 873 | const GrOpsRenderPass::LoadAndStoreInfo&, |
| 874 | const GrOpsRenderPass::StencilLoadAndStoreInfo&, |
| 875 | const SkTArray<GrSurfaceProxy*, true>& sampledProxies, |
| 876 | GrXferBarrierFlags renderPassXferBarriers) = 0; |
| 877 | |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 878 | virtual void prepareSurfacesForBackendAccessAndStateUpdates( |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 879 | SkSpan<GrSurfaceProxy*> proxies, |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 880 | SkSurface::BackendSurfaceAccess access, |
| 881 | const GrBackendSurfaceMutableState* newState) {} |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 882 | |
| 883 | virtual bool onSubmitToGpu(bool syncCpu) = 0; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 884 | |
Greg Daniel | b432754 | 2020-11-20 10:50:50 -0500 | [diff] [blame] | 885 | void reportSubmitHistograms(); |
| 886 | virtual void onReportSubmitHistograms() {} |
| 887 | |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 888 | #ifdef SK_ENABLE_DUMP_GPU |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 889 | virtual void onDumpJSON(SkJSONWriter*) const {} |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 890 | #endif |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 891 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 892 | sk_sp<GrTexture> createTextureCommon(SkISize, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 893 | const GrBackendFormat&, |
| 894 | GrRenderable, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 895 | int renderTargetSampleCnt, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 896 | SkBudgeted, |
| 897 | GrProtected, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 898 | int mipLevelCnt, |
| 899 | uint32_t levelClearMask); |
| 900 | |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 901 | void resetContext() { |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 902 | this->onResetContext(fResetBits); |
| 903 | fResetBits = 0; |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Greg Daniel | 55822f1 | 2020-05-26 11:26:45 -0400 | [diff] [blame] | 906 | void callSubmittedProcs(bool success); |
| 907 | |
Brian Osman | cbdc261 | 2020-11-23 15:30:48 -0500 | [diff] [blame] | 908 | sk_sp<const GrCaps> fCaps; |
| 909 | // Compiler used for compiling SkSL into backend shader code. We only want to create the |
| 910 | // compiler once, as there is significant overhead to the first compile. |
| 911 | std::unique_ptr<SkSL::Compiler> fCompiler; |
| 912 | |
Chris Dalton | 535ba8d | 2018-02-20 09:51:59 -0700 | [diff] [blame] | 913 | uint32_t fResetBits; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 914 | // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 915 | GrDirectContext* fContext; |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 916 | GrSamplePatternDictionary fSamplePatternDictionary; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 917 | |
Greg Daniel | 55822f1 | 2020-05-26 11:26:45 -0400 | [diff] [blame] | 918 | struct SubmittedProc { |
| 919 | SubmittedProc(GrGpuSubmittedProc proc, GrGpuSubmittedContext context) |
| 920 | : fProc(proc), fContext(context) {} |
| 921 | |
| 922 | GrGpuSubmittedProc fProc; |
| 923 | GrGpuSubmittedContext fContext; |
| 924 | }; |
| 925 | SkSTArray<4, SubmittedProc> fSubmittedProcs; |
| 926 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 927 | bool fOOMed = false; |
| 928 | |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 929 | #if SK_HISTOGRAMS_ENABLED |
| 930 | int fCurrentSubmitRenderPassCount = 0; |
| 931 | #endif |
| 932 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 933 | friend class GrPathRendering; |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 934 | using INHERITED = SkRefCnt; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 935 | }; |
| 936 | |
| 937 | #endif |