Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrMockTexture.h
Go to the documentation of this file.
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/core/SkSize.h"
23
24#include <cstddef>
25#include <string_view>
26
27namespace skgpu { class ScratchKey; }
28
29class GrMockTexture : public GrTexture {
30public:
32 skgpu::Budgeted budgeted,
36 std::string_view label)
37 : GrMockTexture(gpu, dimensions, mipmapStatus, info, label) {
38 this->registerWithCache(budgeted);
39 }
40
45 GrWrapCacheable cacheable,
46 GrIOType ioType,
47 std::string_view label)
48 : GrMockTexture(gpu, dimensions, mipmapStatus, info, label) {
49 if (ioType == kRead_GrIOType) {
50 this->setReadOnly();
51 }
52 this->registerWithCacheWrapped(cacheable);
53 }
54
55 ~GrMockTexture() override {}
56
58 return GrBackendTexture(this->width(), this->height(), this->mipmapped(), fInfo);
59 }
60
61 GrBackendFormat backendFormat() const override {
62 return fInfo.getBackendFormat();
63 }
64
65 void textureParamsModified() override {}
66
67protected:
68 // constructor for subclasses
70 const SkISize& dims,
73 std::string_view label)
74 : GrSurface(gpu, dims, info.getProtected(), label)
75 , GrTexture(gpu, dims, info.getProtected(), GrTextureType::k2D, mipmapStatus, label)
76 , fInfo(info) {}
77
78 void onRelease() override {
80 }
81
82 void onAbandon() override {
84 }
85
89
90private:
91 void onSetLabel() override{}
92
94
95 using INHERITED = GrTexture;
96};
97
99public:
101 skgpu::Budgeted budgeted,
103 int sampleCnt,
105 std::string_view label)
106 : GrSurface(gpu, dimensions, info.getProtected(), label)
107 , GrRenderTarget(gpu, dimensions, sampleCnt, info.getProtected(), label)
108 , fInfo(info) {
109 this->registerWithCache(budgeted);
110 }
111
115 std::string_view label)
116 : GrSurface(gpu, dimensions, info.getProtected(), label)
117 , GrRenderTarget(gpu, dimensions, sampleCnt, info.getProtected(), label)
118 , fInfo(info) {
120 }
121
122 bool canAttemptStencilAttachment(bool useMSAASurface) const override {
123 SkASSERT(useMSAASurface == (this->numSamples() > 1));
124 return true;
125 }
126
127 bool completeStencilAttachment(GrAttachment*, bool useMSAASurface) override {
128 SkASSERT(useMSAASurface == (this->numSamples() > 1));
129 return true;
130 }
131
132 size_t onGpuMemorySize() const override {
133 int numColorSamples = this->numSamples();
134 if (numColorSamples > 1) {
135 // Add one to account for the resolve buffer.
136 ++numColorSamples;
137 }
139 this->backendFormat(), this->dimensions(), numColorSamples, skgpu::Mipmapped::kNo);
140 }
141
143 int numStencilBits = 0;
144 if (GrAttachment* stencil = this->getStencilAttachment()) {
145 numStencilBits = GrBackendFormatStencilBits(stencil->backendFormat());
146 }
147 return {this->width(), this->height(), this->numSamples(), numStencilBits, fInfo};
148 }
149
151 return fInfo.getBackendFormat();
152 }
153
154protected:
155 // constructor for subclasses
158 int sampleCnt,
160 std::string_view label)
161 : GrSurface(gpu, dimensions, info.getProtected(), label)
162 , GrRenderTarget(gpu, dimensions, sampleCnt, info.getProtected(), label)
163 , fInfo(info) {}
164
165private:
166 void onSetLabel() override{}
167
169
170 using INHERITED = GrRenderTarget;
171};
172
174public:
175 // Internally created.
177 skgpu::Budgeted budgeted,
179 int sampleCnt,
181 const GrMockTextureInfo& texInfo,
182 const GrMockRenderTargetInfo& rtInfo,
183 std::string_view label)
184 : GrSurface(gpu, dimensions, texInfo.getProtected(), label)
185 , GrMockTexture(gpu, dimensions, mipmapStatus, texInfo, label)
186 , GrMockRenderTarget(gpu, dimensions, sampleCnt, rtInfo, label) {
187 SkASSERT(texInfo.getProtected() == rtInfo.getProtected());
188 this->registerWithCache(budgeted);
189 }
190
191 // Renderable wrapped backend texture.
194 int sampleCnt,
196 const GrMockTextureInfo& texInfo,
197 const GrMockRenderTargetInfo& rtInfo,
198 GrWrapCacheable cacheable,
199 std::string_view label)
200 : GrSurface(gpu, dimensions, texInfo.getProtected(), label)
201 , GrMockTexture(gpu, dimensions, mipmapStatus, texInfo, label)
202 , GrMockRenderTarget(gpu, dimensions, sampleCnt, rtInfo, label) {
203 SkASSERT(texInfo.getProtected() == rtInfo.getProtected());
204 this->registerWithCacheWrapped(cacheable);
205 }
206
207 GrTexture* asTexture() override { return this; }
208 GrRenderTarget* asRenderTarget() override { return this; }
209 const GrTexture* asTexture() const override { return this; }
210 const GrRenderTarget* asRenderTarget() const override { return this; }
211
214 }
215
216private:
217 void onAbandon() override {
220 }
221
222 void onRelease() override {
225 }
226
227 size_t onGpuMemorySize() const override {
228 int numColorSamples = this->numSamples();
229 if (numColorSamples > 1) {
230 // Add one to account for the resolve buffer.
231 ++numColorSamples;
232 }
233 return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(),
234 numColorSamples, this->mipmapped());
235 }
236
237 void onSetLabel() override{}
238
239 // This avoids an inherits via dominance warning on MSVC.
243};
244
245#endif
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
int GrBackendFormatStencilBits(const GrBackendFormat &format)
GrWrapCacheable
Definition GrTypesPriv.h:84
GrIOType
@ kRead_GrIOType
GrMipmapStatus
GrTextureType
#define SkASSERT(cond)
Definition SkAssert.h:116
virtual void onAbandon()
void registerWithCacheWrapped(GrWrapCacheable)
void registerWithCache(skgpu::Budgeted)
virtual void onRelease()
GrMockRenderTarget(GrMockGpu *gpu, Wrapped, SkISize dimensions, int sampleCnt, const GrMockRenderTargetInfo &info, std::string_view label)
size_t onGpuMemorySize() const override
void onSetLabel() override
GrBackendRenderTarget getBackendRenderTarget() const override
bool completeStencilAttachment(GrAttachment *, bool useMSAASurface) override
bool canAttemptStencilAttachment(bool useMSAASurface) const override
GrMockRenderTarget(GrMockGpu *gpu, SkISize dimensions, int sampleCnt, const GrMockRenderTargetInfo &info, std::string_view label)
GrBackendFormat backendFormat() const override
GrMockRenderTarget(GrMockGpu *gpu, skgpu::Budgeted budgeted, SkISize dimensions, int sampleCnt, const GrMockRenderTargetInfo &info, std::string_view label)
const GrTexture * asTexture() const override
GrTexture * asTexture() override
GrMockTextureRenderTarget(GrMockGpu *gpu, skgpu::Budgeted budgeted, SkISize dimensions, int sampleCnt, GrMipmapStatus mipmapStatus, const GrMockTextureInfo &texInfo, const GrMockRenderTargetInfo &rtInfo, std::string_view label)
GrBackendFormat backendFormat() const override
size_t onGpuMemorySize() const override
GrRenderTarget * asRenderTarget() override
const GrRenderTarget * asRenderTarget() const override
void computeScratchKey(skgpu::ScratchKey *key) const override
GrMockTextureRenderTarget(GrMockGpu *gpu, SkISize dimensions, int sampleCnt, GrMipmapStatus mipmapStatus, const GrMockTextureInfo &texInfo, const GrMockRenderTargetInfo &rtInfo, GrWrapCacheable cacheable, std::string_view label)
GrBackendTexture getBackendTexture() const override
GrMockTexture(GrMockGpu *gpu, const SkISize &dims, GrMipmapStatus mipmapStatus, const GrMockTextureInfo &info, std::string_view label)
void textureParamsModified() override
bool onStealBackendTexture(GrBackendTexture *, SkImages::BackendTextureReleaseProc *) override
GrMockTexture(GrMockGpu *gpu, SkISize dimensions, GrMipmapStatus mipmapStatus, const GrMockTextureInfo &info, GrWrapCacheable cacheable, GrIOType ioType, std::string_view label)
GrBackendFormat backendFormat() const override
void onAbandon() override
void onRelease() override
GrMockTexture(GrMockGpu *gpu, skgpu::Budgeted budgeted, SkISize dimensions, GrMipmapStatus mipmapStatus, const GrMockTextureInfo &info, std::string_view label)
~GrMockTexture() override
void onSetLabel() override
GrAttachment * getStencilAttachment() const
void onAbandon() override
void onRelease() override
int numSamples() const
int numStencilBits(bool useMSAASurface) const
SkISize dimensions() const
Definition GrSurface.h:27
int height() const
Definition GrSurface.h:37
static size_t ComputeSize(const GrBackendFormat &, SkISize dimensions, int colorSamplesPerPixel, skgpu::Mipmapped, bool binSize=false)
Definition GrSurface.cpp:21
void setReadOnly()
Definition GrSurface.h:130
int width() const
Definition GrSurface.h:32
skgpu::Mipmapped mipmapped() const
Definition GrTexture.h:62
GrMipmapStatus mipmapStatus() const
Definition GrTexture.h:66
void computeScratchKey(skgpu::ScratchKey *) const override
Definition GrTexture.cpp:91
std::function< void(GrBackendTexture)> BackendTextureReleaseProc
Budgeted
Definition GpuTypes.h:35
GrBackendFormat getBackendFormat() const
skgpu::Protected getProtected() const
Definition GrMockTypes.h:92
GrBackendFormat getBackendFormat() const
skgpu::Protected getProtected() const
Definition GrMockTypes.h:58