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 | |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 96 | ResolveType getResolveType() const override { |
| 97 | return (this->requiresManualMSAAResolve()) ? |
| 98 | kCanResolve_ResolveType : kAutoResolves_ResolveType; |
| 99 | } |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 100 | bool canAttemptStencilAttachment() const override { return true; } |
| 101 | bool completeStencilAttachment() override { return true; } |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 102 | |
| 103 | size_t onGpuMemorySize() const override { |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 104 | int numColorSamples = this->numSamples(); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 105 | if (numColorSamples > 1) { |
| 106 | // Add one to account for the resolve buffer. |
| 107 | ++numColorSamples; |
| 108 | } |
| 109 | return GrSurface::ComputeSize(this->config(), this->width(), this->height(), |
| 110 | numColorSamples, GrMipMapped::kNo); |
| 111 | } |
| 112 | |
| 113 | GrBackendRenderTarget getBackendRenderTarget() const override { |
| 114 | int numStencilBits = 0; |
| 115 | if (GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAttachment()) { |
| 116 | numStencilBits = stencil->bits(); |
| 117 | } |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 118 | return {this->width(), this->height(), this->numSamples(), numStencilBits, fInfo}; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 119 | } |
| 120 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 121 | GrBackendFormat backendFormat() const override { |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 122 | return fInfo.getBackendFormat(); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 123 | } |
| 124 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 125 | protected: |
| 126 | // constructor for subclasses |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 127 | GrMockRenderTarget(GrMockGpu* gpu, const GrSurfaceDesc& desc, int sampleCnt, |
| 128 | GrProtected isProtected, const GrMockRenderTargetInfo& info) |
Brian Salomon | a9c2257 | 2019-08-05 12:57:09 -0400 | [diff] [blame] | 129 | : GrSurface(gpu, {desc.fWidth, desc.fHeight}, desc.fConfig, isProtected) |
| 130 | , INHERITED(gpu, {desc.fWidth, desc.fHeight}, desc.fConfig, sampleCnt, isProtected) |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 131 | , fInfo(info) {} |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 132 | |
| 133 | private: |
| 134 | GrMockRenderTargetInfo fInfo; |
| 135 | |
| 136 | typedef GrRenderTarget INHERITED; |
| 137 | }; |
| 138 | |
| 139 | class GrMockTextureRenderTarget : public GrMockTexture, public GrMockRenderTarget { |
| 140 | public: |
| 141 | // Internally created. |
| 142 | GrMockTextureRenderTarget(GrMockGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 143 | int sampleCnt, GrProtected isProtected, GrMipMapsStatus mipMapsStatus, |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 144 | const GrMockTextureInfo& texInfo, |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 145 | const GrMockRenderTargetInfo& rtInfo) |
Brian Salomon | a9c2257 | 2019-08-05 12:57:09 -0400 | [diff] [blame] | 146 | : GrSurface(gpu, {desc.fWidth, desc.fHeight}, desc.fConfig, isProtected) |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 147 | , GrMockTexture(gpu, desc, isProtected, mipMapsStatus, texInfo) |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 148 | , GrMockRenderTarget(gpu, desc, sampleCnt, isProtected, rtInfo) { |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 149 | this->registerWithCache(budgeted); |
| 150 | } |
| 151 | |
| 152 | // Renderable wrapped backend texture. |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 153 | GrMockTextureRenderTarget(GrMockGpu* gpu, const GrSurfaceDesc& desc, int sampleCnt, |
| 154 | GrProtected isProtected, GrMipMapsStatus mipMapsStatus, |
| 155 | const GrMockTextureInfo& texInfo, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 156 | const GrMockRenderTargetInfo& rtInfo, GrWrapCacheable cacheble) |
Brian Salomon | a9c2257 | 2019-08-05 12:57:09 -0400 | [diff] [blame] | 157 | : GrSurface(gpu, {desc.fWidth, desc.fHeight}, desc.fConfig, isProtected) |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 158 | , GrMockTexture(gpu, desc, isProtected, mipMapsStatus, texInfo) |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 159 | , GrMockRenderTarget(gpu, desc, sampleCnt, isProtected, rtInfo) { |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 160 | this->registerWithCacheWrapped(cacheble); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 161 | } |
| 162 | |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 163 | GrTexture* asTexture() override { return this; } |
| 164 | GrRenderTarget* asRenderTarget() override { return this; } |
| 165 | const GrTexture* asTexture() const override { return this; } |
| 166 | const GrRenderTarget* asRenderTarget() const override { return this; } |
| 167 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 168 | GrBackendFormat backendFormat() const override { |
| 169 | return GrMockTexture::backendFormat(); |
| 170 | } |
| 171 | |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 172 | protected: |
| 173 | // This avoids an inherits via dominance warning on MSVC. |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame] | 174 | void willRemoveLastRef() override { GrTexture::willRemoveLastRef(); } |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 175 | |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 176 | private: |
| 177 | void onAbandon() override { |
| 178 | GrRenderTarget::onAbandon(); |
| 179 | GrMockTexture::onAbandon(); |
| 180 | } |
| 181 | |
| 182 | void onRelease() override { |
| 183 | GrRenderTarget::onRelease(); |
| 184 | GrMockTexture::onRelease(); |
| 185 | } |
| 186 | |
| 187 | size_t onGpuMemorySize() const override { |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 188 | int numColorSamples = this->numSamples(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 189 | if (numColorSamples > 1) { |
| 190 | // Add one to account for the resolve buffer. |
| 191 | ++numColorSamples; |
| 192 | } |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 193 | return GrSurface::ComputeSize(this->config(), this->width(), this->height(), |
Brian Salomon | 57b0430 | 2018-01-30 15:43:49 -0500 | [diff] [blame] | 194 | numColorSamples, |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 195 | this->texturePriv().mipMapped()); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 196 | } |
| 197 | |
Brian Salomon | 14cb413 | 2019-09-16 13:14:47 -0400 | [diff] [blame] | 198 | // This avoids an inherits via dominance warning on MSVC. |
| 199 | void computeScratchKey(GrScratchKey* key) const override { GrTexture::computeScratchKey(key); } |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | #endif |