/src/skia/src/gpu/mock/GrMockTexture.h
Line | Count | Source (jump to first uncovered line) |
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 "include/gpu/mock/GrMockTypes.h" |
11 | | #include "src/gpu/GrAttachment.h" |
12 | | #include "src/gpu/GrRenderTarget.h" |
13 | | #include "src/gpu/GrTexture.h" |
14 | | #include "src/gpu/mock/GrMockGpu.h" |
15 | | |
16 | | class GrMockTexture : public GrTexture { |
17 | | public: |
18 | | GrMockTexture(GrMockGpu* gpu, |
19 | | SkBudgeted budgeted, |
20 | | SkISize dimensions, |
21 | | GrProtected isProtected, |
22 | | GrMipmapStatus mipmapStatus, |
23 | | const GrMockTextureInfo& info) |
24 | 43.2k | : GrMockTexture(gpu, dimensions, isProtected, mipmapStatus, info) { |
25 | 43.2k | this->registerWithCache(budgeted); |
26 | 43.2k | } |
27 | | |
28 | | GrMockTexture(GrMockGpu* gpu, |
29 | | SkISize dimensions, |
30 | | GrProtected isProtected, |
31 | | GrMipmapStatus mipmapStatus, |
32 | | const GrMockTextureInfo& info, |
33 | | GrWrapCacheable cacheable, |
34 | | GrIOType ioType) |
35 | 0 | : GrMockTexture(gpu, dimensions, isProtected, mipmapStatus, info) { |
36 | 0 | if (ioType == kRead_GrIOType) { |
37 | 0 | this->setReadOnly(); |
38 | 0 | } |
39 | 0 | this->registerWithCacheWrapped(cacheable); |
40 | 0 | } |
41 | | |
42 | 54.1k | ~GrMockTexture() override {} |
43 | | |
44 | 0 | GrBackendTexture getBackendTexture() const override { |
45 | 0 | return GrBackendTexture(this->width(), this->height(), this->mipmapped(), fInfo); |
46 | 0 | } |
47 | | |
48 | 212k | GrBackendFormat backendFormat() const override { |
49 | 212k | return fInfo.getBackendFormat(); |
50 | 212k | } |
51 | | |
52 | 0 | void textureParamsModified() override {} |
53 | | |
54 | | protected: |
55 | | // constructor for subclasses |
56 | | GrMockTexture(GrMockGpu* gpu, const SkISize& dimensions, GrProtected isProtected, |
57 | | GrMipmapStatus mipmapStatus, const GrMockTextureInfo& info) |
58 | | : GrSurface(gpu, dimensions, isProtected) |
59 | | , INHERITED(gpu, dimensions, isProtected, GrTextureType::k2D, mipmapStatus) |
60 | 54.1k | , fInfo(info) {} GrMockTexture::GrMockTexture(GrMockGpu*, SkISize const&, GrProtected, GrMipmapStatus, GrMockTextureInfo const&) Line | Count | Source | 60 | 10.9k | , fInfo(info) {} |
GrMockTexture::GrMockTexture(GrMockGpu*, SkISize const&, GrProtected, GrMipmapStatus, GrMockTextureInfo const&) Line | Count | Source | 60 | 43.2k | , fInfo(info) {} |
|
61 | | |
62 | 54.1k | void onRelease() override { |
63 | 54.1k | INHERITED::onRelease(); |
64 | 54.1k | } |
65 | | |
66 | 0 | void onAbandon() override { |
67 | 0 | INHERITED::onAbandon(); |
68 | 0 | } |
69 | | |
70 | 0 | bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override { |
71 | 0 | return false; |
72 | 0 | } |
73 | | |
74 | | private: |
75 | | GrMockTextureInfo fInfo; |
76 | | |
77 | | using INHERITED = GrTexture; |
78 | | }; |
79 | | |
80 | | class GrMockRenderTarget : public GrRenderTarget { |
81 | | public: |
82 | | GrMockRenderTarget(GrMockGpu* gpu, |
83 | | SkBudgeted budgeted, |
84 | | SkISize dimensions, |
85 | | int sampleCnt, |
86 | | GrProtected isProtected, |
87 | | const GrMockRenderTargetInfo& info) |
88 | | : GrSurface(gpu, dimensions, isProtected) |
89 | | , INHERITED(gpu, dimensions, sampleCnt, isProtected) |
90 | 0 | , fInfo(info) { |
91 | 0 | this->registerWithCache(budgeted); |
92 | 0 | } |
93 | | |
94 | | enum Wrapped { kWrapped }; |
95 | | GrMockRenderTarget(GrMockGpu* gpu, Wrapped, SkISize dimensions, int sampleCnt, |
96 | | GrProtected isProtected, const GrMockRenderTargetInfo& info) |
97 | | : GrSurface(gpu, dimensions, isProtected) |
98 | | , INHERITED(gpu, dimensions, sampleCnt, isProtected) |
99 | 0 | , fInfo(info) { |
100 | 0 | this->registerWithCacheWrapped(GrWrapCacheable::kNo); |
101 | 0 | } |
102 | | |
103 | 1.11k | bool canAttemptStencilAttachment(bool useMSAASurface) const override { |
104 | 1.11k | SkASSERT(useMSAASurface == (this->numSamples() > 1)); |
105 | 1.11k | return true; |
106 | 1.11k | } |
107 | | |
108 | 136 | bool completeStencilAttachment(GrAttachment*, bool useMSAASurface) override { |
109 | 136 | SkASSERT(useMSAASurface == (this->numSamples() > 1)); |
110 | 136 | return true; |
111 | 136 | } |
112 | | |
113 | 0 | size_t onGpuMemorySize() const override { |
114 | 0 | int numColorSamples = this->numSamples(); |
115 | 0 | if (numColorSamples > 1) { |
116 | | // Add one to account for the resolve buffer. |
117 | 0 | ++numColorSamples; |
118 | 0 | } |
119 | 0 | return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(), |
120 | 0 | numColorSamples, GrMipmapped::kNo); |
121 | 0 | } |
122 | | |
123 | 0 | GrBackendRenderTarget getBackendRenderTarget() const override { |
124 | 0 | int numStencilBits = 0; |
125 | 0 | if (GrAttachment* stencil = this->getStencilAttachment()) { |
126 | 0 | numStencilBits = GrBackendFormatStencilBits(stencil->backendFormat()); |
127 | 0 | } |
128 | 0 | return {this->width(), this->height(), this->numSamples(), numStencilBits, fInfo}; |
129 | 0 | } |
130 | | |
131 | 0 | GrBackendFormat backendFormat() const override { |
132 | 0 | return fInfo.getBackendFormat(); |
133 | 0 | } |
134 | | |
135 | | protected: |
136 | | // constructor for subclasses |
137 | | GrMockRenderTarget(GrMockGpu* gpu, |
138 | | SkISize dimensions, |
139 | | int sampleCnt, |
140 | | GrProtected isProtected, |
141 | | const GrMockRenderTargetInfo& info) |
142 | | : GrSurface(gpu, dimensions, isProtected) |
143 | | , INHERITED(gpu, dimensions, sampleCnt, isProtected) |
144 | 10.9k | , fInfo(info) {} |
145 | | |
146 | | private: |
147 | | GrMockRenderTargetInfo fInfo; |
148 | | |
149 | | using INHERITED = GrRenderTarget; |
150 | | }; |
151 | | |
152 | | class GrMockTextureRenderTarget : public GrMockTexture, public GrMockRenderTarget { |
153 | | public: |
154 | | // Internally created. |
155 | | GrMockTextureRenderTarget(GrMockGpu* gpu, |
156 | | SkBudgeted budgeted, |
157 | | SkISize dimensions, |
158 | | int sampleCnt, |
159 | | GrProtected isProtected, |
160 | | GrMipmapStatus mipmapStatus, |
161 | | const GrMockTextureInfo& texInfo, |
162 | | const GrMockRenderTargetInfo& rtInfo) |
163 | | : GrSurface(gpu, dimensions, isProtected) |
164 | | , GrMockTexture(gpu, dimensions, isProtected, mipmapStatus, texInfo) |
165 | 10.9k | , GrMockRenderTarget(gpu, dimensions, sampleCnt, isProtected, rtInfo) { |
166 | 10.9k | this->registerWithCache(budgeted); |
167 | 10.9k | } |
168 | | |
169 | | // Renderable wrapped backend texture. |
170 | | GrMockTextureRenderTarget(GrMockGpu* gpu, |
171 | | SkISize dimensions, |
172 | | int sampleCnt, |
173 | | GrProtected isProtected, |
174 | | GrMipmapStatus mipmapStatus, |
175 | | const GrMockTextureInfo& texInfo, |
176 | | const GrMockRenderTargetInfo& rtInfo, |
177 | | GrWrapCacheable cacheable) |
178 | | : GrSurface(gpu, dimensions, isProtected) |
179 | | , GrMockTexture(gpu, dimensions, isProtected, mipmapStatus, texInfo) |
180 | 0 | , GrMockRenderTarget(gpu, dimensions, sampleCnt, isProtected, rtInfo) { |
181 | 0 | this->registerWithCacheWrapped(cacheable); |
182 | 0 | } |
183 | | |
184 | 144k | GrTexture* asTexture() override { return this; } |
185 | 158k | GrRenderTarget* asRenderTarget() override { return this; } |
186 | 0 | const GrTexture* asTexture() const override { return this; } |
187 | 10.9k | const GrRenderTarget* asRenderTarget() const override { return this; } |
188 | | |
189 | 33.1k | GrBackendFormat backendFormat() const override { |
190 | 33.1k | return GrMockTexture::backendFormat(); |
191 | 33.1k | } |
192 | | |
193 | | private: |
194 | 0 | void onAbandon() override { |
195 | 0 | GrRenderTarget::onAbandon(); |
196 | 0 | GrMockTexture::onAbandon(); |
197 | 0 | } |
198 | | |
199 | 10.9k | void onRelease() override { |
200 | 10.9k | GrRenderTarget::onRelease(); |
201 | 10.9k | GrMockTexture::onRelease(); |
202 | 10.9k | } |
203 | | |
204 | 10.9k | size_t onGpuMemorySize() const override { |
205 | 10.9k | int numColorSamples = this->numSamples(); |
206 | 10.9k | if (numColorSamples > 1) { |
207 | | // Add one to account for the resolve buffer. |
208 | 0 | ++numColorSamples; |
209 | 0 | } |
210 | 10.9k | return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(), |
211 | 10.9k | numColorSamples, this->mipmapped()); |
212 | 10.9k | } |
213 | | |
214 | | // This avoids an inherits via dominance warning on MSVC. |
215 | 10.9k | void computeScratchKey(GrScratchKey* key) const override { GrTexture::computeScratchKey(key); } |
216 | | }; |
217 | | |
218 | | #endif |