blob: 21f0eeca1a7445bd88958f5c6c5a6497c3bf12c5 [file] [log] [blame]
Brian Salomoncfe910d2017-07-06 16:40:18 -04001/*
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 Phillips2890fbf2017-07-26 15:48:41 -040011#include "GrRenderTarget.h"
Brian Salomoncfe910d2017-07-06 16:40:18 -040012#include "GrTexture.h"
13#include "GrTexturePriv.h"
Brian Salomon8fe24272017-07-07 12:56:11 -040014#include "mock/GrMockTypes.h"
Brian Salomoncfe910d2017-07-06 16:40:18 -040015
16class GrMockTexture : public GrTexture {
17public:
Brian Salomon8fe24272017-07-07 12:56:11 -040018 GrMockTexture(GrMockGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc, bool hasMipLevels,
19 const GrMockTextureInfo& info)
20 : GrMockTexture(gpu, desc, hasMipLevels, info) {
Brian Salomoncfe910d2017-07-06 16:40:18 -040021 this->registerWithCache(budgeted);
22 }
23 ~GrMockTexture() override {
24 if (fReleaseProc) {
25 fReleaseProc(fReleaseCtx);
26 }
27 }
Brian Salomon8fe24272017-07-07 12:56:11 -040028 GrBackendObject getTextureHandle() const override {
29 return reinterpret_cast<GrBackendObject>(&fInfo);
30 }
Brian Salomoncfe910d2017-07-06 16:40:18 -040031 void textureParamsModified() override {}
32 void setRelease(ReleaseProc proc, ReleaseCtx ctx) override {
33 fReleaseProc = proc;
34 fReleaseCtx = ctx;
35 }
36
37protected:
38 // constructor for subclasses
Brian Salomon8fe24272017-07-07 12:56:11 -040039 GrMockTexture(GrMockGpu* gpu, const GrSurfaceDesc& desc, bool hasMipLevels,
40 const GrMockTextureInfo& info)
Brian Salomoncfe910d2017-07-06 16:40:18 -040041 : GrSurface(gpu, desc)
Brian Salomon2bbdcc42017-09-07 12:36:34 -040042 , INHERITED(gpu, desc, kITexture2DSampler_GrSLType, GrSamplerState::Filter::kMipMap,
Greg Daniel834f1202017-10-09 15:06:20 -040043 hasMipLevels, hasMipLevels)
Brian Salomon8fe24272017-07-07 12:56:11 -040044 , fInfo(info)
Brian Salomoncfe910d2017-07-06 16:40:18 -040045 , fReleaseProc(nullptr)
46 , fReleaseCtx(nullptr) {}
47
48private:
Brian Salomon8fe24272017-07-07 12:56:11 -040049 GrMockTextureInfo fInfo;
Brian Salomoncfe910d2017-07-06 16:40:18 -040050 ReleaseProc fReleaseProc;
51 ReleaseCtx fReleaseCtx;
52
53 typedef GrTexture INHERITED;
54};
55
56class GrMockTextureRenderTarget : public GrMockTexture, public GrRenderTarget {
57public:
58 GrMockTextureRenderTarget(GrMockGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc,
Brian Salomon8fe24272017-07-07 12:56:11 -040059 bool hasMipLevels, const GrMockTextureInfo& texInfo)
Brian Salomoncfe910d2017-07-06 16:40:18 -040060 : GrSurface(gpu, desc)
Brian Salomon8fe24272017-07-07 12:56:11 -040061 , GrMockTexture(gpu, desc, hasMipLevels, texInfo)
Brian Salomoncfe910d2017-07-06 16:40:18 -040062 , 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
74private:
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 Phillipsb0e93a22017-08-29 08:26:54 -040093 true, this->numStencilSamples(),
Brian Salomoncfe910d2017-07-06 16:40:18 -040094 this->texturePriv().hasMipMaps(), key);
95 }
96};
97
98#endif