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 | |
| 10 | #include "GrMockGpu.h" |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 11 | #include "GrRenderTarget.h" |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 12 | #include "GrTexture.h" |
| 13 | #include "GrTexturePriv.h" |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 14 | #include "mock/GrMockTypes.h" |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 15 | |
| 16 | class GrMockTexture : public GrTexture { |
| 17 | public: |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 18 | GrMockTexture(GrMockGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc, bool hasMipLevels, |
| 19 | const GrMockTextureInfo& info) |
| 20 | : GrMockTexture(gpu, desc, hasMipLevels, info) { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 21 | this->registerWithCache(budgeted); |
| 22 | } |
| 23 | ~GrMockTexture() override { |
| 24 | if (fReleaseProc) { |
| 25 | fReleaseProc(fReleaseCtx); |
| 26 | } |
| 27 | } |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 28 | GrBackendObject getTextureHandle() const override { |
| 29 | return reinterpret_cast<GrBackendObject>(&fInfo); |
| 30 | } |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 31 | void textureParamsModified() override {} |
| 32 | void setRelease(ReleaseProc proc, ReleaseCtx ctx) override { |
| 33 | fReleaseProc = proc; |
| 34 | fReleaseCtx = ctx; |
| 35 | } |
| 36 | |
| 37 | protected: |
| 38 | // constructor for subclasses |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 39 | GrMockTexture(GrMockGpu* gpu, const GrSurfaceDesc& desc, bool hasMipLevels, |
| 40 | const GrMockTextureInfo& info) |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 41 | : GrSurface(gpu, desc) |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 42 | , INHERITED(gpu, desc, kITexture2DSampler_GrSLType, GrSamplerState::Filter::kMipMap, |
Greg Daniel | 834f120 | 2017-10-09 15:06:20 -0400 | [diff] [blame^] | 43 | hasMipLevels, hasMipLevels) |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 44 | , fInfo(info) |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 45 | , fReleaseProc(nullptr) |
| 46 | , fReleaseCtx(nullptr) {} |
| 47 | |
| 48 | private: |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 49 | GrMockTextureInfo fInfo; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 50 | ReleaseProc fReleaseProc; |
| 51 | ReleaseCtx fReleaseCtx; |
| 52 | |
| 53 | typedef GrTexture INHERITED; |
| 54 | }; |
| 55 | |
| 56 | class GrMockTextureRenderTarget : public GrMockTexture, public GrRenderTarget { |
| 57 | public: |
| 58 | GrMockTextureRenderTarget(GrMockGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc, |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 59 | bool hasMipLevels, const GrMockTextureInfo& texInfo) |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 60 | : GrSurface(gpu, desc) |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 61 | , GrMockTexture(gpu, desc, hasMipLevels, texInfo) |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 62 | , GrRenderTarget(gpu, desc) { |
| 63 | this->registerWithCache(budgeted); |
| 64 | } |
| 65 | ResolveType getResolveType() const override { return kCanResolve_ResolveType; } |
| 66 | GrBackendObject getRenderTargetHandle() const override { return 0; } |
| 67 | bool canAttemptStencilAttachment() const override { return true; } |
| 68 | bool completeStencilAttachment() override { return true; } |
| 69 | GrTexture* asTexture() override { return this; } |
| 70 | GrRenderTarget* asRenderTarget() override { return this; } |
| 71 | const GrTexture* asTexture() const override { return this; } |
| 72 | const GrRenderTarget* asRenderTarget() const override { return this; } |
| 73 | |
| 74 | private: |
| 75 | void onAbandon() override { |
| 76 | GrRenderTarget::onAbandon(); |
| 77 | GrMockTexture::onAbandon(); |
| 78 | } |
| 79 | |
| 80 | void onRelease() override { |
| 81 | GrRenderTarget::onRelease(); |
| 82 | GrMockTexture::onRelease(); |
| 83 | } |
| 84 | |
| 85 | size_t onGpuMemorySize() const override { |
| 86 | return GrSurface::ComputeSize(this->config(), this->width(), this->height(), |
| 87 | this->numStencilSamples(), |
| 88 | this->texturePriv().hasMipMaps()); |
| 89 | } |
| 90 | |
| 91 | void computeScratchKey(GrScratchKey* key) const override { |
| 92 | GrTexturePriv::ComputeScratchKey(this->config(), this->width(), this->height(), |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 93 | true, this->numStencilSamples(), |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 94 | this->texturePriv().hasMipMaps(), key); |
| 95 | } |
| 96 | }; |
| 97 | |
| 98 | #endif |