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