Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | #ifndef GrMockTexture_DEFINED |
| 8 | #define GrMockTexture_DEFINED |
| 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/gpu/GrTexture.h" |
| 11 | #include "include/gpu/mock/GrMockTypes.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrRenderTargetPriv.h" |
Hal Canary | 02eefbe | 2019-06-26 13:54:14 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrStencilAttachment.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrTexturePriv.h" |
| 16 | #include "src/gpu/mock/GrMockGpu.h" |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 17 | |
| 18 | class GrMockTexture : public GrTexture { |
| 19 | public: |
Greg Daniel | 0fc4d2d | 2017-10-12 11:23:36 -0400 | [diff] [blame] | 20 | GrMockTexture(GrMockGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc, |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 21 | GrProtected isProtected, GrMipMapsStatus mipMapsStatus, |
| 22 | const GrMockTextureInfo& info) |
| 23 | : GrMockTexture(gpu, desc, isProtected, mipMapsStatus, info) { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 24 | this->registerWithCache(budgeted); |
| 25 | } |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 26 | |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 27 | GrMockTexture(GrMockGpu* gpu, const GrSurfaceDesc& desc, GrProtected isProtected, |
| 28 | GrMipMapsStatus mipMapsStatus, const GrMockTextureInfo& info, |
| 29 | GrWrapCacheable cacheable, GrIOType ioType) |
| 30 | : GrMockTexture(gpu, desc, isProtected, mipMapsStatus, info) { |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 31 | if (ioType == kRead_GrIOType) { |
| 32 | this->setReadOnly(); |
| 33 | } |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 34 | this->registerWithCacheWrapped(cacheable); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 35 | } |
| 36 | |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 37 | ~GrMockTexture() override {} |
| 38 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 39 | GrBackendTexture getBackendTexture() const override { |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 40 | return GrBackendTexture(this->width(), this->height(), this->texturePriv().mipMapped(), |
| 41 | fInfo); |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 42 | } |
| 43 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 44 | GrBackendFormat backendFormat() const override { |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 45 | return fInfo.getBackendFormat(); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 46 | } |
| 47 | |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 48 | void textureParamsModified() override {} |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 49 | |
| 50 | protected: |
| 51 | // constructor for subclasses |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 52 | GrMockTexture(GrMockGpu* gpu, const GrSurfaceDesc& desc, GrProtected isProtected, |
| 53 | GrMipMapsStatus mipMapsStatus, const GrMockTextureInfo& info) |
Brian Salomon | a9c2257 | 2019-08-05 12:57:09 -0400 | [diff] [blame] | 54 | : GrSurface(gpu, {desc.fWidth, desc.fHeight}, desc.fConfig, isProtected) |
| 55 | , INHERITED(gpu, {desc.fWidth, desc.fHeight}, desc.fConfig, isProtected, |
| 56 | GrTextureType::k2D, mipMapsStatus) |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 57 | , fInfo(info) {} |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 58 | |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 59 | void onRelease() override { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 60 | INHERITED::onRelease(); |
| 61 | } |
| 62 | |
| 63 | void onAbandon() override { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 64 | INHERITED::onAbandon(); |
| 65 | } |
| 66 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 67 | bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override { |
| 68 | return false; |
| 69 | } |
| 70 | |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 71 | private: |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 72 | GrMockTextureInfo fInfo; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 73 | |
| 74 | typedef GrTexture INHERITED; |
| 75 | }; |
| 76 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 77 | class GrMockRenderTarget : public GrRenderTarget { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 78 | public: |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 79 | GrMockRenderTarget(GrMockGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 80 | int sampleCnt, GrProtected isProtected, const GrMockRenderTargetInfo& info) |
Brian Salomon | a9c2257 | 2019-08-05 12:57:09 -0400 | [diff] [blame] | 81 | : GrSurface(gpu, {desc.fWidth, desc.fHeight}, desc.fConfig, isProtected) |
| 82 | , INHERITED(gpu, {desc.fWidth, desc.fHeight}, desc.fConfig, sampleCnt, isProtected) |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 83 | , fInfo(info) { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 84 | this->registerWithCache(budgeted); |
| 85 | } |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 86 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 87 | enum Wrapped { kWrapped }; |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 88 | GrMockRenderTarget(GrMockGpu* gpu, Wrapped, const GrSurfaceDesc& desc, int sampleCnt, |
| 89 | GrProtected isProtected, const GrMockRenderTargetInfo& info) |
Brian Salomon | a9c2257 | 2019-08-05 12:57:09 -0400 | [diff] [blame] | 90 | : GrSurface(gpu, {desc.fWidth, desc.fHeight}, desc.fConfig, isProtected) |
| 91 | , INHERITED(gpu, {desc.fWidth, desc.fHeight}, desc.fConfig, sampleCnt, isProtected) |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 92 | , fInfo(info) { |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 93 | this->registerWithCacheWrapped(GrWrapCacheable::kNo); |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 94 | } |
| 95 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 96 | ResolveType getResolveType() const override { return kCanResolve_ResolveType; } |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 97 | bool canAttemptStencilAttachment() const override { return true; } |
| 98 | bool completeStencilAttachment() override { return true; } |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 99 | |
| 100 | size_t onGpuMemorySize() const override { |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 101 | int numColorSamples = this->numSamples(); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 102 | if (numColorSamples > 1) { |
| 103 | // Add one to account for the resolve buffer. |
| 104 | ++numColorSamples; |
| 105 | } |
| 106 | return GrSurface::ComputeSize(this->config(), this->width(), this->height(), |
| 107 | numColorSamples, GrMipMapped::kNo); |
| 108 | } |
| 109 | |
| 110 | GrBackendRenderTarget getBackendRenderTarget() const override { |
| 111 | int numStencilBits = 0; |
| 112 | if (GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAttachment()) { |
| 113 | numStencilBits = stencil->bits(); |
| 114 | } |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 115 | return {this->width(), this->height(), this->numSamples(), numStencilBits, fInfo}; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 116 | } |
| 117 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 118 | GrBackendFormat backendFormat() const override { |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 119 | return fInfo.getBackendFormat(); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 120 | } |
| 121 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 122 | protected: |
| 123 | // constructor for subclasses |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 124 | GrMockRenderTarget(GrMockGpu* gpu, const GrSurfaceDesc& desc, int sampleCnt, |
| 125 | GrProtected isProtected, const GrMockRenderTargetInfo& info) |
Brian Salomon | a9c2257 | 2019-08-05 12:57:09 -0400 | [diff] [blame] | 126 | : GrSurface(gpu, {desc.fWidth, desc.fHeight}, desc.fConfig, isProtected) |
| 127 | , INHERITED(gpu, {desc.fWidth, desc.fHeight}, desc.fConfig, sampleCnt, isProtected) |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 128 | , fInfo(info) {} |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 129 | |
| 130 | private: |
| 131 | GrMockRenderTargetInfo fInfo; |
| 132 | |
| 133 | typedef GrRenderTarget INHERITED; |
| 134 | }; |
| 135 | |
| 136 | class GrMockTextureRenderTarget : public GrMockTexture, public GrMockRenderTarget { |
| 137 | public: |
| 138 | // Internally created. |
| 139 | GrMockTextureRenderTarget(GrMockGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 140 | int sampleCnt, GrProtected isProtected, GrMipMapsStatus mipMapsStatus, |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 141 | const GrMockTextureInfo& texInfo, |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 142 | const GrMockRenderTargetInfo& rtInfo) |
Brian Salomon | a9c2257 | 2019-08-05 12:57:09 -0400 | [diff] [blame] | 143 | : GrSurface(gpu, {desc.fWidth, desc.fHeight}, desc.fConfig, isProtected) |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 144 | , GrMockTexture(gpu, desc, isProtected, mipMapsStatus, texInfo) |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 145 | , GrMockRenderTarget(gpu, desc, sampleCnt, isProtected, rtInfo) { |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 146 | this->registerWithCache(budgeted); |
| 147 | } |
| 148 | |
| 149 | // Renderable wrapped backend texture. |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 150 | GrMockTextureRenderTarget(GrMockGpu* gpu, const GrSurfaceDesc& desc, int sampleCnt, |
| 151 | GrProtected isProtected, GrMipMapsStatus mipMapsStatus, |
| 152 | const GrMockTextureInfo& texInfo, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 153 | const GrMockRenderTargetInfo& rtInfo, GrWrapCacheable cacheble) |
Brian Salomon | a9c2257 | 2019-08-05 12:57:09 -0400 | [diff] [blame] | 154 | : GrSurface(gpu, {desc.fWidth, desc.fHeight}, desc.fConfig, isProtected) |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 155 | , GrMockTexture(gpu, desc, isProtected, mipMapsStatus, texInfo) |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 156 | , GrMockRenderTarget(gpu, desc, sampleCnt, isProtected, rtInfo) { |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 157 | this->registerWithCacheWrapped(cacheble); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 158 | } |
| 159 | |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 160 | GrTexture* asTexture() override { return this; } |
| 161 | GrRenderTarget* asRenderTarget() override { return this; } |
| 162 | const GrTexture* asTexture() const override { return this; } |
| 163 | const GrRenderTarget* asRenderTarget() const override { return this; } |
| 164 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 165 | GrBackendFormat backendFormat() const override { |
| 166 | return GrMockTexture::backendFormat(); |
| 167 | } |
| 168 | |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 169 | protected: |
| 170 | // This avoids an inherits via dominance warning on MSVC. |
| 171 | void willRemoveLastRefOrPendingIO() override { GrTexture::willRemoveLastRefOrPendingIO(); } |
| 172 | |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 173 | private: |
| 174 | void onAbandon() override { |
| 175 | GrRenderTarget::onAbandon(); |
| 176 | GrMockTexture::onAbandon(); |
| 177 | } |
| 178 | |
| 179 | void onRelease() override { |
| 180 | GrRenderTarget::onRelease(); |
| 181 | GrMockTexture::onRelease(); |
| 182 | } |
| 183 | |
| 184 | size_t onGpuMemorySize() const override { |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 185 | int numColorSamples = this->numSamples(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 186 | if (numColorSamples > 1) { |
| 187 | // Add one to account for the resolve buffer. |
| 188 | ++numColorSamples; |
| 189 | } |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 190 | return GrSurface::ComputeSize(this->config(), this->width(), this->height(), |
Brian Salomon | 57b0430 | 2018-01-30 15:43:49 -0500 | [diff] [blame] | 191 | numColorSamples, |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 192 | this->texturePriv().mipMapped()); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | void computeScratchKey(GrScratchKey* key) const override { |
| 196 | GrTexturePriv::ComputeScratchKey(this->config(), this->width(), this->height(), |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 197 | GrRenderable::kYes, this->numSamples(), |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 198 | this->texturePriv().mipMapped(), key); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 199 | } |
| 200 | }; |
| 201 | |
| 202 | #endif |