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