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: GrMockTexture(GrMockGpu * gpu,SkBudgeted budgeted,const GrSurfaceDesc & desc,bool hasMipLevels,const GrMockTextureInfo & info)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 } ~GrMockTexture()22 ~GrMockTexture() override { 23 if (fReleaseProc) { 24 fReleaseProc(fReleaseCtx); 25 } 26 } getTextureHandle()27 GrBackendObject getTextureHandle() const override { 28 return reinterpret_cast<GrBackendObject>(&fInfo); 29 } textureParamsModified()30 void textureParamsModified() override {} setRelease(ReleaseProc proc,ReleaseCtx ctx)31 void setRelease(ReleaseProc proc, ReleaseCtx ctx) override { 32 fReleaseProc = proc; 33 fReleaseCtx = ctx; 34 } 35 36 protected: 37 // constructor for subclasses GrMockTexture(GrMockGpu * gpu,const GrSurfaceDesc & desc,bool hasMipLevels,const GrMockTextureInfo & info)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: GrMockTextureRenderTarget(GrMockGpu * gpu,SkBudgeted budgeted,const GrSurfaceDesc & desc,bool hasMipLevels,const GrMockTextureInfo & texInfo)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 } getResolveType()64 ResolveType getResolveType() const override { return kCanResolve_ResolveType; } getRenderTargetHandle()65 GrBackendObject getRenderTargetHandle() const override { return 0; } canAttemptStencilAttachment()66 bool canAttemptStencilAttachment() const override { return true; } completeStencilAttachment()67 bool completeStencilAttachment() override { return true; } asTexture()68 GrTexture* asTexture() override { return this; } asRenderTarget()69 GrRenderTarget* asRenderTarget() override { return this; } asTexture()70 const GrTexture* asTexture() const override { return this; } asRenderTarget()71 const GrRenderTarget* asRenderTarget() const override { return this; } 72 73 private: onAbandon()74 void onAbandon() override { 75 GrRenderTarget::onAbandon(); 76 GrMockTexture::onAbandon(); 77 } 78 onRelease()79 void onRelease() override { 80 GrRenderTarget::onRelease(); 81 GrMockTexture::onRelease(); 82 } 83 onGpuMemorySize()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 computeScratchKey(GrScratchKey * key)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